Skip to content

Commit

Permalink
Refactor to use return instead of break in loop
Browse files Browse the repository at this point in the history
  • Loading branch information
ybiquitous committed Apr 27, 2024
1 parent 7ab186d commit 101003d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 16 deletions.
10 changes: 2 additions & 8 deletions lib/rules/shorthand-property-no-redundant-values/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,9 @@ const rule = (primary, _secondaryOptions, context) => {
/** @type {string[]} */
const valuesToShorthand = [];

let shouldIgnore = false;

for (const valueNode of valueParser(value).nodes) {
if (typeGuards.isValueDiv(valueNode)) {
shouldIgnore = true;
break;
return;
}

// `var()` should be ignored. E.g.
Expand All @@ -146,17 +143,14 @@ const rule = (primary, _secondaryOptions, context) => {
// padding: 0 var(--padding) 0;
//
if (typeGuards.isValueFunction(valueNode) && valueNode.value.toLowerCase() === 'var') {
shouldIgnore = true;
break;
return;
}

if (typeGuards.isValueWord(valueNode) || typeGuards.isValueFunction(valueNode)) {
valuesToShorthand.push(valueParser.stringify(valueNode));
}
}

if (shouldIgnore) return;

if (valuesToShorthand.length <= 1 || valuesToShorthand.length > 4) {
return;
}
Expand Down
10 changes: 2 additions & 8 deletions lib/rules/shorthand-property-no-redundant-values/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,9 @@ const rule = (primary, _secondaryOptions, context) => {
/** @type {string[]} */
const valuesToShorthand = [];

let shouldIgnore = false;

for (const valueNode of valueParser(value).nodes) {
if (isValueDiv(valueNode)) {
shouldIgnore = true;
break;
return;
}

// `var()` should be ignored. E.g.
Expand All @@ -144,17 +141,14 @@ const rule = (primary, _secondaryOptions, context) => {
// padding: 0 var(--padding) 0;
//
if (isValueFunction(valueNode) && valueNode.value.toLowerCase() === 'var') {
shouldIgnore = true;
break;
return;
}

if (isValueWord(valueNode) || isValueFunction(valueNode)) {
valuesToShorthand.push(valueParser.stringify(valueNode));
}
}

if (shouldIgnore) return;

if (valuesToShorthand.length <= 1 || valuesToShorthand.length > 4) {
return;
}
Expand Down

0 comments on commit 101003d

Please sign in to comment.