Skip to content

Commit

Permalink
fix #4113
Browse files Browse the repository at this point in the history
  • Loading branch information
vankop committed Jul 26, 2019
1 parent 1178f2d commit a40099b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
8 changes: 8 additions & 0 deletions lib/rules/no-duplicate-selectors/__tests__/index.js
Expand Up @@ -73,6 +73,14 @@ testRule(rule, {
line: 1,
column: 1
},
{
code: ".a, .b, .a, .c, .d, .a {}",
message: messages.rejected(".a", 1),
line: 1,
column: 1,
description:
"duplicated selectors within one rule's selector list. 3 duplicates"
},
{
code: "a {} b {} a {}",
description: "duplicate simple selectors with another rule between",
Expand Down
21 changes: 14 additions & 7 deletions lib/rules/no-duplicate-selectors/index.js
Expand Up @@ -114,20 +114,27 @@ const rule = function(actual, options) {
});
}

const presentedSelectors = new Set();
const reportedSelectors = new Set();

// Or complain if one selector list contains the same selector more than one
rule.selectors.forEach((selector, i) => {
if (
_.includes(
normalizedSelectorList.slice(0, i),
normalizeSelector(selector)
)
) {
rule.selectors.forEach(selector => {
const normalized = normalizeSelector(selector);

if (presentedSelectors.has(normalized)) {
if (reportedSelectors.has(normalized)) {
return;
}

report({
result,
ruleName,
node: rule,
message: messages.rejected(selector, selectorLine)
});
reportedSelectors.add(normalized);
} else {
presentedSelectors.add(normalized);
}
});

Expand Down

0 comments on commit a40099b

Please sign in to comment.