UNPKG

711 BJavaScriptView Raw
1"use strict";
2
3/**
4 * @param { import("../lib/css-analyzer") } analyzer
5 */
6function rule(analyzer) {
7 analyzer.setMetric("multiClassesSelectors");
8
9 analyzer.on("selector", (_, selector, expressions) => {
10 const expressionsWithClass = expressions.filter(
11 (expr) => expr.name === "class"
12 );
13
14 // console.log(selector, expressions, {expressionsWithClass});
15
16 if (expressionsWithClass.length > 1) {
17 analyzer.incrMetric("multiClassesSelectors");
18 analyzer.addOffender(
19 "multiClassesSelectors",
20 "." + expressionsWithClass.map((expr) => expr.value).join(".")
21 );
22 }
23 });
24}
25
26rule.description = "Reports selectors with multiple classes";
27module.exports = rule;