-
Notifications
You must be signed in to change notification settings - Fork 476
Expand file tree
/
Copy pathvisited-styles.js
More file actions
66 lines (57 loc) · 2.05 KB
/
visited-styles.js
File metadata and controls
66 lines (57 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
* Rule: Visited styles can only differ by color.
*/
/*global CSSLint*/
CSSLint.addRule({
//rule information
id: "visited-styles",
name: "Visited Styles",
desc: ":visited and :link styles can only differ by color.",
browsers: "All",
//initialization
init: function(parser, reporter){
var rule = this,
lastRule;
function startRule(event){
if (event.selectors){
lastRule = {
line: event.line,
col: event.col,
selectors: event.selectors,
propCount: 0,
outline: false,
visitedDiffers: false
};
} else {
lastRule = null;
}
}
function endRule(event){
if (lastRule){
if (lastRule.visitedDiffers){
if (lastRule.selectors.toString().toLowerCase().indexOf(":visited") != -1) {
reporter.report(":visited and :link styles can only differ by color.", lastRule.line, lastRule.col, rule);
}
}
}
}
parser.addListener("startrule", startRule);
parser.addListener("startfontface", startRule);
parser.addListener("startpage", startRule);
parser.addListener("startpagemargin", startRule);
parser.addListener("startkeyframerule", startRule);
parser.addListener("property", function(event){
var name = event.property.text.toLowerCase();
if (lastRule){
if (name !== "color"){
lastRule.visitedDiffers = true;
}
}
});
parser.addListener("endrule", endRule);
parser.addListener("endfontface", endRule);
parser.addListener("endpage", endRule);
parser.addListener("endpagemargin", endRule);
parser.addListener("endkeyframerule", endRule);
}
});