Skip to content

Commit 48a199a

Browse files
authored
Merge pull request #1 from hrobertking/transparent-color
Adding transparent-color rule
2 parents f57c84c + af58e38 commit 48a199a

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

src/rules/transparent-color.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Rule: Set color to a visible value
3+
*
4+
*/
5+
6+
CSSLint.addRule({
7+
8+
// rule information
9+
id: "transparent-color",
10+
name: "Named value 'transparent' used for color",
11+
desc: "Checks for a value for color that is transparent",
12+
browsers: "All",
13+
14+
// initialization
15+
init: function(parser, reporter) {
16+
"use strict";
17+
var rule = this;
18+
19+
// check for use of "transparent" as a value for "color"
20+
parser.addListener("property", function(event) {
21+
var name = event.property.toString().toLowerCase(),
22+
parts = event.value.parts,
23+
ndx = parts.length - 1;
24+
25+
if (name === "color") {
26+
while (ndx > -1) {
27+
if (parts[ndx].type === "identifier" && parts[ndx].value === "transparent") {
28+
reporter.report("Color cannot be 'transparent'.", event.line, event.col, rule);
29+
break;
30+
}
31+
ndx -= 1;
32+
}
33+
}
34+
});
35+
}
36+
37+
});

tests/rules/transparent-color.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
(function() {
2+
"use strict";
3+
var Assert = YUITest.Assert;
4+
5+
YUITest.TestRunner.add(new YUITest.TestCase({
6+
7+
name: "transparent color Errors",
8+
9+
"A 'transparent' value for color should result in a warning": function() {
10+
var result = CSSLint.verify("h1 { color: transparent; }", { "transparent-color": 1 });
11+
Assert.areEqual(1, result.messages.length);
12+
Assert.areEqual("warning", result.messages[0].type);
13+
Assert.areEqual("Color cannot be 'transparent'.", result.messages[0].message);
14+
}
15+
}));
16+
})();

0 commit comments

Comments
 (0)