Skip to content

Commit 792bb07

Browse files
committed
use separate flags for text-indent and direction. fixes #249
1 parent d2e1d5b commit 792bb07

2 files changed

Lines changed: 21 additions & 17 deletions

File tree

src/rules/text-indent.js

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
2-
* Rule: Don't use text-indent for image replacement if you need to support rtl.
3-
*
2+
* Rule: Don't use text-indent for image replacement if you need to support rtl.
3+
*
44
*/
55
/*global CSSLint*/
66
CSSLint.addRule({
@@ -10,27 +10,29 @@ CSSLint.addRule({
1010
name: "Disallow negative text-indent",
1111
desc: "Checks for text indent less than -99px",
1212
browsers: "All",
13-
13+
1414
//initialization
1515
init: function(parser, reporter){
1616
var rule = this,
17-
textIndent = false;
18-
19-
17+
textIndent,
18+
direction;
19+
20+
2021
function startRule(event){
2122
textIndent = false;
23+
direction = "inherit";
2224
}
23-
25+
2426
//event handler for end of rules
2527
function endRule(event){
26-
if (textIndent){
28+
if (textIndent && direction != "ltr"){
2729
reporter.report("Negative text-indent doesn't work well with RTL. If you use text-indent for image replacement explicitly set direction for that item to ltr.", textIndent.line, textIndent.col, rule);
2830
}
29-
}
30-
31+
}
32+
3133
parser.addListener("startrule", startRule);
3234
parser.addListener("startfontface", startRule);
33-
35+
3436
//check for use of "font-size"
3537
parser.addListener("property", function(event){
3638
var name = event.property.toString().toLowerCase(),
@@ -39,12 +41,12 @@ CSSLint.addRule({
3941
if (name == "text-indent" && value.parts[0].value < -99){
4042
textIndent = event.property;
4143
} else if (name == "direction" && value == "ltr"){
42-
textIndent = false;
44+
direction = "ltr";
4345
}
4446
});
4547

4648
parser.addListener("endrule", endRule);
47-
parser.addListener("endfontface", endRule);
49+
parser.addListener("endfontface", endRule);
4850

4951
}
5052

tests/rules/text-indent.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
var Assert = YUITest.Assert;
55

66
YUITest.TestRunner.add(new YUITest.TestCase({
7-
7+
88
name: "text-indent Rule Errors",
99

1010
"-100px text-indent should result in a warning": function(){
@@ -22,9 +22,11 @@
2222
"-100px text-indent with LTR should not result in a warning": function(){
2323
var result = CSSLint.verify(".foo{text-indent: -100px; direction: ltr; }", {"text-indent": 1 });
2424
Assert.areEqual(0, result.messages.length);
25+
result = CSSLint.verify(".foo{direction: ltr; text-indent: -100px; }", {"text-indent": 1 });
26+
Assert.areEqual(0, result.messages.length);
2527
},
2628

27-
"-100px text-indent with RTL should result in a warning": function(){
29+
"-100px text-indent with RTL should result in a warning": function(){
2830
var result = CSSLint.verify(".foo{text-indent: -100px; direction: rtl; }", {"text-indent": 1 });
2931
Assert.areEqual(1, result.messages.length);
3032
Assert.areEqual("warning", result.messages[0].type);
@@ -35,14 +37,14 @@
3537
var result = CSSLint.verify(".foo{text-indent: 5px;}", {"text-indent": 1 });
3638
Assert.areEqual(0, result.messages.length);
3739
},
38-
40+
3941
"This should cause a warning, not an error": function(){
4042
var result = CSSLint.verify(".top h1 a { background: url(../images/background/logo.png) no-repeat; display: block; height: 44px; position: relative; text-indent: -9999px; width: 250px; }", { "text-indent": 1 });
4143
Assert.areEqual(1, result.messages.length);
4244
Assert.areEqual("warning", result.messages[0].type);
4345
Assert.areEqual("Negative text-indent doesn't work well with RTL. If you use text-indent for image replacement explicitly set direction for that item to ltr.", result.messages[0].message);
4446
}
45-
47+
4648
}));
4749

4850
})();

0 commit comments

Comments
 (0)