diff --git a/lib/rules/selector-max-universal/__tests__/index.js b/lib/rules/selector-max-universal/__tests__/index.js index 78e588a0b6..99439e99f1 100644 --- a/lib/rules/selector-max-universal/__tests__/index.js +++ b/lib/rules/selector-max-universal/__tests__/index.js @@ -321,18 +321,12 @@ testRule({ testRule({ ruleName, - config: [0, { ignoreAfterCombinators: ['~', '+', '>', 'h1', 'article'] }], + config: [0, { ignoreAfterCombinators: ['~', '+', '>'] }], accept: [ { code: '.foo {}', }, - { - code: 'article * {}', - }, - { - code: 'h1 * {}', - }, { code: '.foo ~ * {}', }, diff --git a/lib/rules/selector-max-universal/index.js b/lib/rules/selector-max-universal/index.js index 2987286a1b..2a8bda7b83 100644 --- a/lib/rules/selector-max-universal/index.js +++ b/lib/rules/selector-max-universal/index.js @@ -52,19 +52,19 @@ const rule = (primary, secondaryOptions) => { * @param {import('postcss').Rule} ruleNode */ function checkSelector(selectorNode, ruleNode) { - const count = selectorNode.reduce((total, childNode, index, nodes) => { + const count = selectorNode.reduce((total, childNode) => { // Only traverse inside actual selectors // All logical combinations will be resolved as nested selector in `postcss-resolve-nested-selector` if (childNode.type === 'selector') { checkSelector(childNode, ruleNode); } - let prevChildNode = nodes[index - 1]; + let prevChildNode = childNode.prev(); let prevChildNodeValue = prevChildNode && prevChildNode.value; // checks if previous child node is descendant combinator - if (prevChildNodeValue === ' ') { - prevChildNode = nodes[index - 2]; + if (prevChildNode && prevChildNode.type === 'combinator' && prevChildNodeValue === ' ') { + prevChildNode = prevChildNode.prev(); prevChildNodeValue = prevChildNode && prevChildNode.value; }