Skip to content

Commit

Permalink
fix: do not erroneously assume that the last node is a not selector
Browse files Browse the repository at this point in the history
  • Loading branch information
Mouvedia committed Feb 3, 2023
1 parent f8988a1 commit 5df9f9c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
18 changes: 18 additions & 0 deletions lib/rules/selector-not-notation/__tests__/index.js
Expand Up @@ -68,6 +68,24 @@ testRule({
endLine: 1,
endColumn: 13,
},
{
code: ':not(.bar, .baz, .foo) .qux {}',
fixed: ':not(.bar):not(.baz):not(.foo) .qux {}',
message: messages.expected('simple'),
line: 1,
column: 1,
endLine: 1,
endColumn: 23,
},
{
code: ':not(.bar, .baz) .qux :not(.foo) {}',
fixed: ':not(.bar):not(.baz) .qux :not(.foo) {}',
message: messages.expected('simple'),
line: 1,
column: 1,
endLine: 1,
endColumn: 17,
},
{
code: ':not(a ,) {}',
fixed: ':not(a) {}',
Expand Down
17 changes: 16 additions & 1 deletion lib/rules/selector-not-notation/index.js
Expand Up @@ -130,6 +130,19 @@ const rule = (primary, _, context) => {
};
};

/**
* @param {Node[]} nodes
*/
const getLastConsecutiveNot = (nodes) => {
let i = 0;

for (; i < nodes.length; i++) {
if (!isNot(/** @type {Node} */ (nodes[i]))) break;
}

return nodes[i - 1];
};

/**
* @param {Pseudo} not
*/
Expand All @@ -152,7 +165,9 @@ function fixSimple(not) {
not.nodes.push(firstSelector);

for (const s of simpleSelectors) {
const last = not.parent.last;
const last = getLastConsecutiveNot(not.parent.nodes);

assert(last);

not.parent.insertAfter(last, last.clone({ nodes: [s] }));
}
Expand Down

0 comments on commit 5df9f9c

Please sign in to comment.