Skip to content

Commit 6edc79a

Browse files
committed
Merge pull request #269 from mahonnaise/master
Disallow star hack rule + disallow underscore hack rule
2 parents f0af9f0 + 4a89295 commit 6edc79a

4 files changed

Lines changed: 102 additions & 0 deletions

File tree

src/rules/star-property-hack.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Rule: Don't use properties with a star prefix.
3+
*
4+
*/
5+
/*global CSSLint*/
6+
CSSLint.addRule({
7+
8+
//rule information
9+
id: "star-property-hack",
10+
name: "Disallow properties with a star prefix",
11+
desc: "Checks for the star property hack (targets IE6/7)",
12+
browsers: "All",
13+
14+
//initialization
15+
init: function(parser, reporter){
16+
var rule = this;
17+
18+
//check if property name starts with "*"
19+
parser.addListener("property", function(event){
20+
var property = event.property;
21+
22+
if (property.hack == "*") {
23+
reporter.report("Property with star prefix found.", event.property.line, event.property.col, rule);
24+
}
25+
});
26+
}
27+
});
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Rule: Don't use properties with a underscore prefix.
3+
*
4+
*/
5+
/*global CSSLint*/
6+
CSSLint.addRule({
7+
8+
//rule information
9+
id: "underscore-property-hack",
10+
name: "Disallow properties with an underscore prefix",
11+
desc: "Checks for the underscore property hack (targets IE6)",
12+
browsers: "All",
13+
14+
//initialization
15+
init: function(parser, reporter){
16+
var rule = this;
17+
18+
//check if property name starts with "_"
19+
parser.addListener("property", function(event){
20+
var property = event.property;
21+
22+
if (property.hack == "_") {
23+
reporter.report("Property with underscore prefix found.", event.property.line, event.property.col, rule);
24+
}
25+
});
26+
}
27+
});

tests/rules/star-property-hack.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
(function(){
2+
3+
/*global YUITest, CSSLint*/
4+
var Assert = YUITest.Assert;
5+
6+
YUITest.TestRunner.add(new YUITest.TestCase({
7+
8+
name: "star-property-hack Rule Errors",
9+
10+
"a property with a star prefix should result in a warning": function(){
11+
var result = CSSLint.verify(".foo{*width: 100px;}", {"star-property-hack": 1 });
12+
Assert.areEqual(1, result.messages.length);
13+
Assert.areEqual("warning", result.messages[0].type);
14+
Assert.areEqual("Property with star prefix found.", result.messages[0].message);
15+
},
16+
17+
"a property without a star prefix should not result in a warning": function(){
18+
var result = CSSLint.verify(".foo{width: 100px;}", {"star-property-hack": 1 });
19+
Assert.areEqual(0, result.messages.length);
20+
}
21+
22+
}));
23+
24+
})();
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
(function(){
2+
3+
/*global YUITest, CSSLint*/
4+
var Assert = YUITest.Assert;
5+
6+
YUITest.TestRunner.add(new YUITest.TestCase({
7+
8+
name: "underscore-property-hack Rule Errors",
9+
10+
"a property with an underscore prefix should result in a warning": function(){
11+
var result = CSSLint.verify(".foo{_width: 100px;}", {"underscore-property-hack": 1 });
12+
Assert.areEqual(1, result.messages.length);
13+
Assert.areEqual("warning", result.messages[0].type);
14+
Assert.areEqual("Property with underscore prefix found.", result.messages[0].message);
15+
},
16+
17+
"a property without an underscore prefix should not result in a warning": function(){
18+
var result = CSSLint.verify(".foo{width: 100px;}", {"underscore-property-hack": 1 });
19+
Assert.areEqual(0, result.messages.length);
20+
}
21+
22+
}));
23+
24+
})();

0 commit comments

Comments
 (0)