Permalink
Browse files

+2 rules which detected star (IE6/7) and underscore (IE6) property hacks

  • Loading branch information...
mahonnaise committed May 3, 2012
1 parent 792bb07 commit 4727030d03808c663c6ff9258b3633c1431a9f7f
@@ -0,0 +1,27 @@
+/*
+ * Rule: Don't use properties with a star prefix.
+ *
+ */
+/*global CSSLint*/
+CSSLint.addRule({
+
+ //rule information
+ id: "star-property-hack",
+ name: "Disallow properties with a star prefix",
+ desc: "Checks for the star property hack (targets IE6/7)",
+ browsers: "All",
+
+ //initialization
+ init: function(parser, reporter){
+ var rule = this;
+
+ //check if property name starts with "*"
+ parser.addListener("property", function(event){
+ var name = event.property.toString();
+
+ if (name.charAt(0) == "*"){
+ reporter.report("Property with star prefix found.", event.property.line, event.property.col, rule);
+ }
+ });
+ }
+});
@@ -0,0 +1,27 @@
+/*
+ * Rule: Don't use properties with a underscore prefix.
+ *
+ */
+/*global CSSLint*/
+CSSLint.addRule({
+
+ //rule information
+ id: "underscore-property-hack",
+ name: "Disallow properties with an underscore prefix",
+ desc: "Checks for the underscore property hack (targets IE6)",
+ browsers: "All",
+
+ //initialization
+ init: function(parser, reporter){
+ var rule = this;
+
+ //check if property name starts with "_"
+ parser.addListener("property", function(event){
+ var name = event.property.toString();
+
+ if (name.charAt(0) == "_"){
+ reporter.report("Property with underscore prefix found.", event.property.line, event.property.col, rule);
+ }
+ });
+ }
+});
@@ -0,0 +1,24 @@
+(function(){
+
+ /*global YUITest, CSSLint*/
+ var Assert = YUITest.Assert;
+
+ YUITest.TestRunner.add(new YUITest.TestCase({
+
+ name: "star-property-hack Rule Errors",
+
+ "a property with a star prefix should result in a warning": function(){
+ var result = CSSLint.verify(".foo{*width: 100px;}", {"star-property-hack": 1 });
+ Assert.areEqual(1, result.messages.length);
+ Assert.areEqual("warning", result.messages[0].type);
+ Assert.areEqual("Property with star prefix found.", result.messages[0].message);
+ },
+
+ "a property without a star prefix should not result in a warning": function(){
+ var result = CSSLint.verify(".foo{width: 100px;}", {"star-property-hack": 1 });
+ Assert.areEqual(0, result.messages.length);
+ }
+
+ }));
+
+})();
@@ -0,0 +1,24 @@
+(function(){
+
+ /*global YUITest, CSSLint*/
+ var Assert = YUITest.Assert;
+
+ YUITest.TestRunner.add(new YUITest.TestCase({
+
+ name: "underscore-property-hack Rule Errors",
+
+ "a property with an underscore prefix should result in a warning": function(){
+ var result = CSSLint.verify(".foo{_width: 100px;}", {"underscore-property-hack": 1 });
+ Assert.areEqual(1, result.messages.length);
+ Assert.areEqual("warning", result.messages[0].type);
+ Assert.areEqual("Property with underscore prefix found.", result.messages[0].message);
+ },
+
+ "a property without an underscore prefix should not result in a warning": function(){
+ var result = CSSLint.verify(".foo{width: 100px;}", {"underscore-property-hack": 1 });
+ Assert.areEqual(0, result.messages.length);
+ }
+
+ }));
+
+})();

0 comments on commit 4727030

Please sign in to comment.