Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

use separate flags for text-indent and direction. fixes #249

  • Loading branch information...
commit 792bb07cfd92351efd3a3a0a0c9f2cadac306771 1 parent d2e1d5b
@mahonnaise authored
Showing with 21 additions and 17 deletions.
  1. +15 −13 src/rules/text-indent.js
  2. +6 −4 tests/rules/text-indent.js
View
28 src/rules/text-indent.js
@@ -1,6 +1,6 @@
/*
- * Rule: Don't use text-indent for image replacement if you need to support rtl.
- *
+ * Rule: Don't use text-indent for image replacement if you need to support rtl.
+ *
*/
/*global CSSLint*/
CSSLint.addRule({
@@ -10,27 +10,29 @@ CSSLint.addRule({
name: "Disallow negative text-indent",
desc: "Checks for text indent less than -99px",
browsers: "All",
-
+
//initialization
init: function(parser, reporter){
var rule = this,
- textIndent = false;
-
-
+ textIndent,
+ direction;
+
+
function startRule(event){
textIndent = false;
+ direction = "inherit";
}
-
+
//event handler for end of rules
function endRule(event){
- if (textIndent){
+ if (textIndent && direction != "ltr"){
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);
}
- }
-
+ }
+
parser.addListener("startrule", startRule);
parser.addListener("startfontface", startRule);
-
+
//check for use of "font-size"
parser.addListener("property", function(event){
var name = event.property.toString().toLowerCase(),
@@ -39,12 +41,12 @@ CSSLint.addRule({
if (name == "text-indent" && value.parts[0].value < -99){
textIndent = event.property;
} else if (name == "direction" && value == "ltr"){
- textIndent = false;
+ direction = "ltr";
}
});
parser.addListener("endrule", endRule);
- parser.addListener("endfontface", endRule);
+ parser.addListener("endfontface", endRule);
}
View
10 tests/rules/text-indent.js
@@ -4,7 +4,7 @@
var Assert = YUITest.Assert;
YUITest.TestRunner.add(new YUITest.TestCase({
-
+
name: "text-indent Rule Errors",
"-100px text-indent should result in a warning": function(){
@@ -22,9 +22,11 @@
"-100px text-indent with LTR should not result in a warning": function(){
var result = CSSLint.verify(".foo{text-indent: -100px; direction: ltr; }", {"text-indent": 1 });
Assert.areEqual(0, result.messages.length);
+ result = CSSLint.verify(".foo{direction: ltr; text-indent: -100px; }", {"text-indent": 1 });
+ Assert.areEqual(0, result.messages.length);
},
- "-100px text-indent with RTL should result in a warning": function(){
+ "-100px text-indent with RTL should result in a warning": function(){
var result = CSSLint.verify(".foo{text-indent: -100px; direction: rtl; }", {"text-indent": 1 });
Assert.areEqual(1, result.messages.length);
Assert.areEqual("warning", result.messages[0].type);
@@ -35,14 +37,14 @@
var result = CSSLint.verify(".foo{text-indent: 5px;}", {"text-indent": 1 });
Assert.areEqual(0, result.messages.length);
},
-
+
"This should cause a warning, not an error": function(){
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 });
Assert.areEqual(1, result.messages.length);
Assert.areEqual("warning", result.messages[0].type);
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);
}
-
+
}));
})();
Please sign in to comment.
Something went wrong with that request. Please try again.