forked from CSSLint/csslint
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- 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.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
|
||
} | ||
} | ||
} | ||
} | ||
}); | ||
} | ||
|
||
}); |