Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Added rule for :visited and :link styles can only differ by color." #372

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions src/rules/visited-styles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,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);
}
});
19 changes: 19 additions & 0 deletions tests/rules/visited-styles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
(function(){

/*global YUITest, CSSLint*/
var Assert = YUITest.Assert;

YUITest.TestRunner.add(new YUITest.TestCase({

name: "Visited Styles Errors",

"Visited links can only differ by color.": function(){
var result = CSSLint.verify("a:visited { text-decoration: underline; }", { "visited-styles": 1 });
Assert.areEqual(1, result.messages.length);
Assert.areEqual("warning", result.messages[0].type);
Assert.areEqual(":visited and :link styles can only differ by color.", result.messages[0].message);
},

}));

})();