Skip to content

Commit

Permalink
Refactor to remove redundant calls to isStandardSyntaxSelector (#7687)
Browse files Browse the repository at this point in the history
refactor to remove redudant calls to `isStandardSyntaxSelector`
  • Loading branch information
romainmenke committed May 11, 2024
1 parent 21f336d commit 22f2884
Show file tree
Hide file tree
Showing 18 changed files with 6 additions and 72 deletions.
3 changes: 0 additions & 3 deletions lib/rules/selector-max-attribute/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const flattenNestedSelectorsForRule = require('../../utils/flattenNestedSelector
const isContextFunctionalPseudoClass = require('../../utils/isContextFunctionalPseudoClass.cjs');
const isNonNegativeInteger = require('../../utils/isNonNegativeInteger.cjs');
const isStandardSyntaxRule = require('../../utils/isStandardSyntaxRule.cjs');
const isStandardSyntaxSelector = require('../../utils/isStandardSyntaxSelector.cjs');
const optionsMatches = require('../../utils/optionsMatches.cjs');
const report = require('../../utils/report.cjs');
const ruleMessages = require('../../utils/ruleMessages.cjs');
Expand Down Expand Up @@ -95,8 +94,6 @@ const rule = (primary, secondaryOptions) => {
root.walkRules((ruleNode) => {
if (!isStandardSyntaxRule(ruleNode)) return;

if (!isStandardSyntaxSelector(ruleNode.selector)) return;

flattenNestedSelectorsForRule(ruleNode, result).forEach(({ selector, resolvedSelectors }) => {
resolvedSelectors.forEach((resolvedSelector) => {
checkSelector(resolvedSelector, selector, ruleNode);
Expand Down
3 changes: 0 additions & 3 deletions lib/rules/selector-max-attribute/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import flattenNestedSelectorsForRule from '../../utils/flattenNestedSelectorsFor
import isContextFunctionalPseudoClass from '../../utils/isContextFunctionalPseudoClass.mjs';
import isNonNegativeInteger from '../../utils/isNonNegativeInteger.mjs';
import isStandardSyntaxRule from '../../utils/isStandardSyntaxRule.mjs';
import isStandardSyntaxSelector from '../../utils/isStandardSyntaxSelector.mjs';
import optionsMatches from '../../utils/optionsMatches.mjs';
import report from '../../utils/report.mjs';
import ruleMessages from '../../utils/ruleMessages.mjs';
Expand Down Expand Up @@ -91,8 +90,6 @@ const rule = (primary, secondaryOptions) => {
root.walkRules((ruleNode) => {
if (!isStandardSyntaxRule(ruleNode)) return;

if (!isStandardSyntaxSelector(ruleNode.selector)) return;

flattenNestedSelectorsForRule(ruleNode, result).forEach(({ selector, resolvedSelectors }) => {
resolvedSelectors.forEach((resolvedSelector) => {
checkSelector(resolvedSelector, selector, ruleNode);
Expand Down
7 changes: 1 addition & 6 deletions lib/rules/selector-max-class/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const flattenNestedSelectorsForRule = require('../../utils/flattenNestedSelector
const isContextFunctionalPseudoClass = require('../../utils/isContextFunctionalPseudoClass.cjs');
const isNonNegativeInteger = require('../../utils/isNonNegativeInteger.cjs');
const isStandardSyntaxRule = require('../../utils/isStandardSyntaxRule.cjs');
const isStandardSyntaxSelector = require('../../utils/isStandardSyntaxSelector.cjs');
const report = require('../../utils/report.cjs');
const ruleMessages = require('../../utils/ruleMessages.cjs');
const validateOptions = require('../../utils/validateOptions.cjs');
Expand Down Expand Up @@ -68,11 +67,7 @@ const rule = (primary) => {
}

root.walkRules((ruleNode) => {
if (!isStandardSyntaxRule(ruleNode)) {
return;
}

if (!isStandardSyntaxSelector(ruleNode.selector)) return;
if (!isStandardSyntaxRule(ruleNode)) return;

flattenNestedSelectorsForRule(ruleNode, result).forEach(({ selector, resolvedSelectors }) => {
resolvedSelectors.forEach((resolvedSelector) => {
Expand Down
7 changes: 1 addition & 6 deletions lib/rules/selector-max-class/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import flattenNestedSelectorsForRule from '../../utils/flattenNestedSelectorsFor
import isContextFunctionalPseudoClass from '../../utils/isContextFunctionalPseudoClass.mjs';
import isNonNegativeInteger from '../../utils/isNonNegativeInteger.mjs';
import isStandardSyntaxRule from '../../utils/isStandardSyntaxRule.mjs';
import isStandardSyntaxSelector from '../../utils/isStandardSyntaxSelector.mjs';
import report from '../../utils/report.mjs';
import ruleMessages from '../../utils/ruleMessages.mjs';
import validateOptions from '../../utils/validateOptions.mjs';
Expand Down Expand Up @@ -64,11 +63,7 @@ const rule = (primary) => {
}

root.walkRules((ruleNode) => {
if (!isStandardSyntaxRule(ruleNode)) {
return;
}

if (!isStandardSyntaxSelector(ruleNode.selector)) return;
if (!isStandardSyntaxRule(ruleNode)) return;

flattenNestedSelectorsForRule(ruleNode, result).forEach(({ selector, resolvedSelectors }) => {
resolvedSelectors.forEach((resolvedSelector) => {
Expand Down
3 changes: 0 additions & 3 deletions lib/rules/selector-max-combinators/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
const flattenNestedSelectorsForRule = require('../../utils/flattenNestedSelectorsForRule.cjs');
const isNonNegativeInteger = require('../../utils/isNonNegativeInteger.cjs');
const isStandardSyntaxRule = require('../../utils/isStandardSyntaxRule.cjs');
const isStandardSyntaxSelector = require('../../utils/isStandardSyntaxSelector.cjs');
const report = require('../../utils/report.cjs');
const ruleMessages = require('../../utils/ruleMessages.cjs');
const validateOptions = require('../../utils/validateOptions.cjs');
Expand Down Expand Up @@ -71,8 +70,6 @@ const rule = (primary) => {
root.walkRules((ruleNode) => {
if (!isStandardSyntaxRule(ruleNode)) return;

if (!isStandardSyntaxSelector(ruleNode.selector)) return;

flattenNestedSelectorsForRule(ruleNode, result).forEach(({ selector, resolvedSelectors }) => {
resolvedSelectors.forEach((resolvedSelector) => {
checkSelector(resolvedSelector, selector, ruleNode);
Expand Down
3 changes: 0 additions & 3 deletions lib/rules/selector-max-combinators/index.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import flattenNestedSelectorsForRule from '../../utils/flattenNestedSelectorsForRule.mjs';
import isNonNegativeInteger from '../../utils/isNonNegativeInteger.mjs';
import isStandardSyntaxRule from '../../utils/isStandardSyntaxRule.mjs';
import isStandardSyntaxSelector from '../../utils/isStandardSyntaxSelector.mjs';
import report from '../../utils/report.mjs';
import ruleMessages from '../../utils/ruleMessages.mjs';
import validateOptions from '../../utils/validateOptions.mjs';
Expand Down Expand Up @@ -67,8 +66,6 @@ const rule = (primary) => {
root.walkRules((ruleNode) => {
if (!isStandardSyntaxRule(ruleNode)) return;

if (!isStandardSyntaxSelector(ruleNode.selector)) return;

flattenNestedSelectorsForRule(ruleNode, result).forEach(({ selector, resolvedSelectors }) => {
resolvedSelectors.forEach((resolvedSelector) => {
checkSelector(resolvedSelector, selector, ruleNode);
Expand Down
3 changes: 0 additions & 3 deletions lib/rules/selector-max-compound-selectors/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const flattenNestedSelectorsForRule = require('../../utils/flattenNestedSelector
const isContextFunctionalPseudoClass = require('../../utils/isContextFunctionalPseudoClass.cjs');
const isNonNegativeInteger = require('../../utils/isNonNegativeInteger.cjs');
const isStandardSyntaxRule = require('../../utils/isStandardSyntaxRule.cjs');
const isStandardSyntaxSelector = require('../../utils/isStandardSyntaxSelector.cjs');
const optionsMatches = require('../../utils/optionsMatches.cjs');
const pluralize = require('../../utils/pluralize.cjs');
const report = require('../../utils/report.cjs');
Expand Down Expand Up @@ -118,8 +117,6 @@ const rule = (primary, secondaryOptions) => {
root.walkRules((ruleNode) => {
if (!isStandardSyntaxRule(ruleNode)) return;

if (!isStandardSyntaxSelector(ruleNode.selector)) return;

flattenNestedSelectorsForRule(ruleNode, result).forEach(({ selector, resolvedSelectors }) => {
resolvedSelectors.forEach((resolvedSelector) => {
checkSelector(resolvedSelector, selector, ruleNode);
Expand Down
3 changes: 0 additions & 3 deletions lib/rules/selector-max-compound-selectors/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import flattenNestedSelectorsForRule from '../../utils/flattenNestedSelectorsFor
import isContextFunctionalPseudoClass from '../../utils/isContextFunctionalPseudoClass.mjs';
import isNonNegativeInteger from '../../utils/isNonNegativeInteger.mjs';
import isStandardSyntaxRule from '../../utils/isStandardSyntaxRule.mjs';
import isStandardSyntaxSelector from '../../utils/isStandardSyntaxSelector.mjs';
import optionsMatches from '../../utils/optionsMatches.mjs';
import pluralize from '../../utils/pluralize.mjs';
import report from '../../utils/report.mjs';
Expand Down Expand Up @@ -114,8 +113,6 @@ const rule = (primary, secondaryOptions) => {
root.walkRules((ruleNode) => {
if (!isStandardSyntaxRule(ruleNode)) return;

if (!isStandardSyntaxSelector(ruleNode.selector)) return;

flattenNestedSelectorsForRule(ruleNode, result).forEach(({ selector, resolvedSelectors }) => {
resolvedSelectors.forEach((resolvedSelector) => {
checkSelector(resolvedSelector, selector, ruleNode);
Expand Down
3 changes: 0 additions & 3 deletions lib/rules/selector-max-id/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const flattenNestedSelectorsForRule = require('../../utils/flattenNestedSelector
const isContextFunctionalPseudoClass = require('../../utils/isContextFunctionalPseudoClass.cjs');
const isNonNegativeInteger = require('../../utils/isNonNegativeInteger.cjs');
const isStandardSyntaxRule = require('../../utils/isStandardSyntaxRule.cjs');
const isStandardSyntaxSelector = require('../../utils/isStandardSyntaxSelector.cjs');
const optionsMatches = require('../../utils/optionsMatches.cjs');
const report = require('../../utils/report.cjs');
const ruleMessages = require('../../utils/ruleMessages.cjs');
Expand Down Expand Up @@ -110,8 +109,6 @@ const rule = (primary, secondaryOptions) => {
root.walkRules((ruleNode) => {
if (!isStandardSyntaxRule(ruleNode)) return;

if (!isStandardSyntaxSelector(ruleNode.selector)) return;

flattenNestedSelectorsForRule(ruleNode, result).forEach(({ selector, resolvedSelectors }) => {
resolvedSelectors.forEach((resolvedSelector) => {
checkSelector(resolvedSelector, selector, ruleNode);
Expand Down
3 changes: 0 additions & 3 deletions lib/rules/selector-max-id/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import flattenNestedSelectorsForRule from '../../utils/flattenNestedSelectorsFor
import isContextFunctionalPseudoClass from '../../utils/isContextFunctionalPseudoClass.mjs';
import isNonNegativeInteger from '../../utils/isNonNegativeInteger.mjs';
import isStandardSyntaxRule from '../../utils/isStandardSyntaxRule.mjs';
import isStandardSyntaxSelector from '../../utils/isStandardSyntaxSelector.mjs';
import optionsMatches from '../../utils/optionsMatches.mjs';
import report from '../../utils/report.mjs';
import ruleMessages from '../../utils/ruleMessages.mjs';
Expand Down Expand Up @@ -106,8 +105,6 @@ const rule = (primary, secondaryOptions) => {
root.walkRules((ruleNode) => {
if (!isStandardSyntaxRule(ruleNode)) return;

if (!isStandardSyntaxSelector(ruleNode.selector)) return;

flattenNestedSelectorsForRule(ruleNode, result).forEach(({ selector, resolvedSelectors }) => {
resolvedSelectors.forEach((resolvedSelector) => {
checkSelector(resolvedSelector, selector, ruleNode);
Expand Down
3 changes: 0 additions & 3 deletions lib/rules/selector-max-pseudo-class/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const flattenNestedSelectorsForRule = require('../../utils/flattenNestedSelector
const isContextFunctionalPseudoClass = require('../../utils/isContextFunctionalPseudoClass.cjs');
const isNonNegativeInteger = require('../../utils/isNonNegativeInteger.cjs');
const isStandardSyntaxRule = require('../../utils/isStandardSyntaxRule.cjs');
const isStandardSyntaxSelector = require('../../utils/isStandardSyntaxSelector.cjs');
const selectors = require('../../reference/selectors.cjs');
const report = require('../../utils/report.cjs');
const ruleMessages = require('../../utils/ruleMessages.cjs');
Expand Down Expand Up @@ -82,8 +81,6 @@ const rule = (primary) => {
root.walkRules((ruleNode) => {
if (!isStandardSyntaxRule(ruleNode)) return;

if (!isStandardSyntaxSelector(ruleNode.selector)) return;

flattenNestedSelectorsForRule(ruleNode, result).forEach(({ selector, resolvedSelectors }) => {
resolvedSelectors.forEach((resolvedSelector) => {
checkSelector(resolvedSelector, selector, ruleNode);
Expand Down
3 changes: 0 additions & 3 deletions lib/rules/selector-max-pseudo-class/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import flattenNestedSelectorsForRule from '../../utils/flattenNestedSelectorsFor
import isContextFunctionalPseudoClass from '../../utils/isContextFunctionalPseudoClass.mjs';
import isNonNegativeInteger from '../../utils/isNonNegativeInteger.mjs';
import isStandardSyntaxRule from '../../utils/isStandardSyntaxRule.mjs';
import isStandardSyntaxSelector from '../../utils/isStandardSyntaxSelector.mjs';
import { levelOneAndTwoPseudoElements } from '../../reference/selectors.mjs';
import report from '../../utils/report.mjs';
import ruleMessages from '../../utils/ruleMessages.mjs';
Expand Down Expand Up @@ -78,8 +77,6 @@ const rule = (primary) => {
root.walkRules((ruleNode) => {
if (!isStandardSyntaxRule(ruleNode)) return;

if (!isStandardSyntaxSelector(ruleNode.selector)) return;

flattenNestedSelectorsForRule(ruleNode, result).forEach(({ selector, resolvedSelectors }) => {
resolvedSelectors.forEach((resolvedSelector) => {
checkSelector(resolvedSelector, selector, ruleNode);
Expand Down
11 changes: 2 additions & 9 deletions lib/rules/selector-max-type/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ const isKeyframeSelector = require('../../utils/isKeyframeSelector.cjs');
const isNonNegativeInteger = require('../../utils/isNonNegativeInteger.cjs');
const isOnlyWhitespace = require('../../utils/isOnlyWhitespace.cjs');
const isStandardSyntaxRule = require('../../utils/isStandardSyntaxRule.cjs');
const isStandardSyntaxSelector = require('../../utils/isStandardSyntaxSelector.cjs');
const isStandardSyntaxTypeSelector = require('../../utils/isStandardSyntaxTypeSelector.cjs');
const optionsMatches = require('../../utils/optionsMatches.cjs');
const report = require('../../utils/report.cjs');
Expand Down Expand Up @@ -122,15 +121,9 @@ const rule = (primary, secondaryOptions) => {
root.walkRules((ruleNode) => {
const selectors = ruleNode.selectors;

if (!isStandardSyntaxRule(ruleNode)) {
return;
}

if (selectors.some((s) => isKeyframeSelector(s))) {
return;
}
if (!isStandardSyntaxRule(ruleNode)) return;

if (!isStandardSyntaxSelector(ruleNode.selector)) return;
if (selectors.some((s) => isKeyframeSelector(s))) return;

flattenNestedSelectorsForRule(ruleNode, result).forEach(({ selector, resolvedSelectors }) => {
resolvedSelectors.forEach((resolvedSelector) => {
Expand Down
11 changes: 2 additions & 9 deletions lib/rules/selector-max-type/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import isKeyframeSelector from '../../utils/isKeyframeSelector.mjs';
import isNonNegativeInteger from '../../utils/isNonNegativeInteger.mjs';
import isOnlyWhitespace from '../../utils/isOnlyWhitespace.mjs';
import isStandardSyntaxRule from '../../utils/isStandardSyntaxRule.mjs';
import isStandardSyntaxSelector from '../../utils/isStandardSyntaxSelector.mjs';
import isStandardSyntaxTypeSelector from '../../utils/isStandardSyntaxTypeSelector.mjs';
import optionsMatches from '../../utils/optionsMatches.mjs';
import report from '../../utils/report.mjs';
Expand Down Expand Up @@ -118,15 +117,9 @@ const rule = (primary, secondaryOptions) => {
root.walkRules((ruleNode) => {
const selectors = ruleNode.selectors;

if (!isStandardSyntaxRule(ruleNode)) {
return;
}

if (selectors.some((s) => isKeyframeSelector(s))) {
return;
}
if (!isStandardSyntaxRule(ruleNode)) return;

if (!isStandardSyntaxSelector(ruleNode.selector)) return;
if (selectors.some((s) => isKeyframeSelector(s))) return;

flattenNestedSelectorsForRule(ruleNode, result).forEach(({ selector, resolvedSelectors }) => {
resolvedSelectors.forEach((resolvedSelector) => {
Expand Down
3 changes: 0 additions & 3 deletions lib/rules/selector-max-universal/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
const flattenNestedSelectorsForRule = require('../../utils/flattenNestedSelectorsForRule.cjs');
const isNonNegativeInteger = require('../../utils/isNonNegativeInteger.cjs');
const isStandardSyntaxRule = require('../../utils/isStandardSyntaxRule.cjs');
const isStandardSyntaxSelector = require('../../utils/isStandardSyntaxSelector.cjs');
const validateTypes = require('../../utils/validateTypes.cjs');
const optionsMatches = require('../../utils/optionsMatches.cjs');
const report = require('../../utils/report.cjs');
Expand Down Expand Up @@ -92,8 +91,6 @@ const rule = (primary, secondaryOptions) => {
root.walkRules((ruleNode) => {
if (!isStandardSyntaxRule(ruleNode)) return;

if (!isStandardSyntaxSelector(ruleNode.selector)) return;

flattenNestedSelectorsForRule(ruleNode, result).forEach(({ selector, resolvedSelectors }) => {
resolvedSelectors.forEach((resolvedSelector) => {
checkSelector(resolvedSelector, selector, ruleNode);
Expand Down
3 changes: 0 additions & 3 deletions lib/rules/selector-max-universal/index.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import flattenNestedSelectorsForRule from '../../utils/flattenNestedSelectorsForRule.mjs';
import isNonNegativeInteger from '../../utils/isNonNegativeInteger.mjs';
import isStandardSyntaxRule from '../../utils/isStandardSyntaxRule.mjs';
import isStandardSyntaxSelector from '../../utils/isStandardSyntaxSelector.mjs';
import { isString } from '../../utils/validateTypes.mjs';
import optionsMatches from '../../utils/optionsMatches.mjs';
import report from '../../utils/report.mjs';
Expand Down Expand Up @@ -88,8 +87,6 @@ const rule = (primary, secondaryOptions) => {
root.walkRules((ruleNode) => {
if (!isStandardSyntaxRule(ruleNode)) return;

if (!isStandardSyntaxSelector(ruleNode.selector)) return;

flattenNestedSelectorsForRule(ruleNode, result).forEach(({ selector, resolvedSelectors }) => {
resolvedSelectors.forEach((resolvedSelector) => {
checkSelector(resolvedSelector, selector, ruleNode);
Expand Down
3 changes: 0 additions & 3 deletions lib/rules/selector-not-notation/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
const selectorParser = require('postcss-selector-parser');
const validateTypes = require('../../utils/validateTypes.cjs');
const isStandardSyntaxRule = require('../../utils/isStandardSyntaxRule.cjs');
const isStandardSyntaxSelector = require('../../utils/isStandardSyntaxSelector.cjs');
const parseSelector = require('../../utils/parseSelector.cjs');
const report = require('../../utils/report.cjs');
const ruleMessages = require('../../utils/ruleMessages.cjs');
Expand Down Expand Up @@ -80,8 +79,6 @@ const rule = (primary, _, context) => {

if (!selector.includes(':not(')) return;

if (!isStandardSyntaxSelector(selector)) return;

const selectorRoot = parseSelector(selector, result, ruleNode);

if (!selectorRoot) return;
Expand Down
3 changes: 0 additions & 3 deletions lib/rules/selector-not-notation/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const { isAttribute, isClassName, isIdentifier, isPseudoClass, isTag, isUniversa

import { assert } from '../../utils/validateTypes.mjs';
import isStandardSyntaxRule from '../../utils/isStandardSyntaxRule.mjs';
import isStandardSyntaxSelector from '../../utils/isStandardSyntaxSelector.mjs';
import parseSelector from '../../utils/parseSelector.mjs';
import report from '../../utils/report.mjs';
import ruleMessages from '../../utils/ruleMessages.mjs';
Expand Down Expand Up @@ -76,8 +75,6 @@ const rule = (primary, _, context) => {

if (!selector.includes(':not(')) return;

if (!isStandardSyntaxSelector(selector)) return;

const selectorRoot = parseSelector(selector, result, ruleNode);

if (!selectorRoot) return;
Expand Down

0 comments on commit 22f2884

Please sign in to comment.