Skip to content

Commit

Permalink
Added overqualified tags rule
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicholas C. Zakas committed Jun 9, 2011
1 parent 694fc9f commit fe1f5a1
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions src/rules/overqualified-elements.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Rule: Don't use classes or IDs with elements (a.foo or a#foo).
*/
CSSLint.addRule({

//rule information
id: "overqualified-elements",
name: "Overqualified Elements",
desc: "Don't use classes or IDs with elements (a.foo or a#foo).",

//initialization
init: function(parser, reporter){

parser.addListener("startrule", function(event){
var selectors = event.selectors,
selector,
part,
modifier,
i, j, k;

for (i=0; i < selectors.length; i++){
selector = selectors[i];

for (j=0; j < selector.parts.length; j++){
part = selector.parts[j];
if (part instanceof parserlib.css.SelectorPart){
if (part.elementName){
for (k=0; k < part.modifiers.length; k++){
modifier = part.modifiers[k];
if (modifier.type == "class" || modifier.type == "id"){
reporter.warn("Element (" + part + ") is overqualified, just use " + modifier + " without element name.", part.line, part.col, this);
}
}

}
}
}
}
});
}

});

0 comments on commit fe1f5a1

Please sign in to comment.