1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | function rule(analyzer) {
|
7 | analyzer.setMetric("qualifiedSelectors");
|
8 |
|
9 |
|
10 | analyzer.on("selector", (_, selector, expressions) => {
|
11 | var hasId = expressions.some((expr) => expr.name === "id"),
|
12 | hasTag = expressions.some((expr) => expr.type === "tag"),
|
13 | hasClass = expressions.some((expr) => expr.name === "class");
|
14 |
|
15 |
|
16 |
|
17 | if (
|
18 |
|
19 | (hasId && hasTag) ||
|
20 |
|
21 | (hasId && hasClass) ||
|
22 |
|
23 | (hasClass && hasTag)
|
24 | ) {
|
25 | analyzer.incrMetric("qualifiedSelectors");
|
26 | analyzer.addOffender("qualifiedSelectors", selector);
|
27 | }
|
28 | });
|
29 | }
|
30 |
|
31 | rule.description = "Reports qualified selectors";
|
32 | module.exports = rule;
|