-
Notifications
You must be signed in to change notification settings - Fork 482
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a rule to detect LTR properties #533
Open
lewisnyman
wants to merge
6
commits into
CSSLint:master
Choose a base branch
from
lewisnyman:ltr-detection
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d4e1eba
Added basic rule info
lewisnyman bd2ae06
Added list of LTR rules
lewisnyman a7ffef7
A rule that passes code standards
lewisnyman 7423564
Almost passing the tests, still need to check potential properties
lewisnyman c3c63e7
Passing tests!
lewisnyman e22b218
Added checks for properties that could be LTR specific with certain v…
lewisnyman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* Rule: Detects properties for LTR text styling the require equivalent RTL styling. | ||
*/ | ||
CSSLint.addRule({ | ||
|
||
//rule information | ||
id: "ltr-properties", | ||
name: "LTR properties", | ||
desc: "Detects properties for LTR text styling the require equivalent RTL styling.", | ||
browsers: "All", | ||
|
||
//initialization | ||
init: function(parser, reporter){ | ||
"use strict"; | ||
var properties = { | ||
"border-left": 1, | ||
"border-right": 1, | ||
"border-top-right-radius": 1, | ||
"border-top-left-radius": 1, | ||
"border-bottom-right-radius": 1, | ||
"border-bottom-left-radius": 1, | ||
"padding-left": 1, | ||
"padding-right": 1, | ||
"margin-left": 1, | ||
"margin-right": 1, | ||
"text-align": 1, | ||
background: 1, | ||
"background-position": 1, | ||
left: 1, | ||
right: 1 | ||
}, | ||
potentialProperties = { | ||
float: { | ||
left: 1, | ||
right: 1, | ||
}, | ||
clear: { | ||
left: 1, | ||
right: 1, | ||
}, | ||
}, | ||
potentialMultipleValueProperties = { | ||
padding: 1, | ||
margin: 1, | ||
border: 1, | ||
"border-radius": 1, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove the trailing comma. |
||
}; | ||
|
||
parser.addListener("property", function(event){ | ||
var rule = this, | ||
name = event.property.toString().toLowerCase(), | ||
value = event.value.toString(), | ||
line = event.line, | ||
col = event.col; | ||
|
||
// These properties always affect RTL. | ||
if (properties[name]){ | ||
reporter.report("Using " + name + " could require an equivalent rule for RTL styling.", line, col, rule); | ||
} | ||
// These properties could affect RTL, if they have four values. | ||
else if (potentialMultipleValueProperties[name] && event.value.parts.length === 4){ | ||
reporter.report("Using " + name + " in this way could require an equivalent rule for RTL styling.", line, col, rule); | ||
} | ||
// These properties could affect RTL, if they have certain values. | ||
else if(potentialProperties[name]) { | ||
var property = potentialProperties[name]; | ||
if(property[value]) { | ||
reporter.report("Using " + name + " in this way could require an equivalent rule for RTL styling.", line, col, rule); | ||
} | ||
} | ||
}); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
(function(){ | ||
"use strict"; | ||
var Assert = YUITest.Assert; | ||
|
||
YUITest.TestRunner.add(new YUITest.TestCase({ | ||
|
||
name: "LTR property detection", | ||
|
||
"Using padding-right should result in a warning": function(){ | ||
var result = CSSLint.verify(".foo { padding-right: 10px; }", { "ltr-properties": 1 }); | ||
Assert.areEqual(1, result.messages.length); | ||
Assert.areEqual("warning", result.messages[0].type); | ||
Assert.areEqual("Using padding-right could require an equivalent rule for RTL styling.", result.messages[0].message); | ||
}, | ||
|
||
"Using padding: 0 1px 0 2px should result in a warning": function(){ | ||
var result = CSSLint.verify(".foo { padding: 0 1px 0 2px; }", { "ltr-properties": 1 }); | ||
Assert.areEqual(1, result.messages.length); | ||
Assert.areEqual("warning", result.messages[0].type); | ||
Assert.areEqual("Using padding in this way could require an equivalent rule for RTL styling.", result.messages[0].message); | ||
}, | ||
|
||
"Using float: left should result in a warning": function(){ | ||
var result = CSSLint.verify(".foo { float: left; }", { "ltr-properties": 1 }); | ||
Assert.areEqual(1, result.messages.length); | ||
Assert.areEqual("warning", result.messages[0].type); | ||
Assert.areEqual("Using float in this way could require an equivalent rule for RTL styling.", result.messages[0].message); | ||
}, | ||
|
||
"Using font-size should result no warning": function(){ | ||
var result = CSSLint.verify(".foo { font-size: 10px; }", { "ltr-properties": 1 }); | ||
Assert.areEqual(0, result.messages.length); | ||
}, | ||
|
||
"Using padding: 10px should result no warning": function(){ | ||
var result = CSSLint.verify(".foo { padding: 0; }", { "ltr-properties": 1 }); | ||
Assert.areEqual(0, result.messages.length); | ||
}, | ||
|
||
"Using border-radius: 2px should result no warning": function(){ | ||
var result = CSSLint.verify(".foo { padding: 0; }", { "ltr-properties": 1 }); | ||
Assert.areEqual(0, result.messages.length); | ||
}, | ||
|
||
"Using margin: 0 1px should result no warning": function(){ | ||
var result = CSSLint.verify(".foo { margin: 0 1px; }", { "ltr-properties": 1 }); | ||
Assert.areEqual(0, result.messages.length); | ||
}, | ||
|
||
"Using clear: none should result no warning": function(){ | ||
var result = CSSLint.verify(".foo { float: none; }", { "ltr-properties": 1 }); | ||
Assert.areEqual(0, result.messages.length); | ||
}, | ||
})); | ||
|
||
})(); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove the trailing comma.