Skip to content

Commit

Permalink
Refactor code into containsVariable function
Browse files Browse the repository at this point in the history
  • Loading branch information
mattxwang committed Apr 20, 2023
1 parent 7efd26d commit 6ba5801
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions lib/rules/color-function-notation/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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}
Expand Down

0 comments on commit 6ba5801

Please sign in to comment.