diff --git a/lib/rules/color-function-notation/index.js b/lib/rules/color-function-notation/index.js index 8fc33d19ac..2965d2d2e3 100644 --- a/lib/rules/color-function-notation/index.js +++ b/lib/rules/color-function-notation/index.js @@ -60,10 +60,7 @@ const rule = (primary, secondaryOptions, context) => { const { value, sourceIndex, sourceEndIndex, nodes } = node; - if ( - ignoreWithVarInside && - nodes.some((child) => child.type === 'function' && child.value.toLowerCase() === 'var') - ) { + if (ignoreWithVarInside && containsVariable(nodes)) { return; } @@ -133,6 +130,13 @@ function atLeastOneSpace(whitespace) { return whitespace !== '' ? whitespace : ' '; } +/** + * @param {import('postcss-value-parser').Node[]} nodes + */ +function containsVariable(nodes) { + return nodes.some(({ type, value }) => type === 'function' && value.toLowerCase() === 'var'); +} + /** * @param {import('postcss-value-parser').Node} node * @returns {node is import('postcss-value-parser').DivNode}