UNPKG

530 BJavaScriptView Raw
1"use strict";
2
3var COMPLEX_SELECTOR_THRESHOLD = 3;
4
5/**
6 * @param { import("../lib/css-analyzer") } analyzer
7 */
8function rule(analyzer) {
9 analyzer.setMetric("complexSelectors");
10
11 // #foo .bar ul li a
12 analyzer.on("selector", function (rule, selector, expressions) {
13 if (expressions.length > COMPLEX_SELECTOR_THRESHOLD) {
14 analyzer.incrMetric("complexSelectors");
15 analyzer.addOffender("complexSelectors", selector);
16 }
17 });
18}
19
20rule.description = "Reports too complex CSS selectors";
21module.exports = rule;