Skip to content

Commit

Permalink
Validate selectors consistently. Fixes #3130 (#4483)
Browse files Browse the repository at this point in the history
* Validate selectors consistently by including `isStandardSyntaxSelector` in `isStandardSyntaxRule`. Fixes #3130
  • Loading branch information
dom111 committed Dec 23, 2019
1 parent 0416635 commit 0f04539
Show file tree
Hide file tree
Showing 30 changed files with 37 additions and 103 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ testRule(rule, {
code: 'html { --custom-property-set: {} }',
description: 'custom property set in selector',
},
{
code: 'a[b=#{c}] { }',
description: 'ignore "invalid" selector (see #3130)',
},
],

reject: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,10 @@ testRule(rule, {
code: 'html { --custom-property-set: {} }',
description: 'custom property set in selector',
},
{
code: 'a[b=#{c}] { }',
description: 'ignore "invalid" selector (see #3130)',
},
],

reject: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,10 @@ testRule(rule, {
code: 'html { --custom-property-set: {} }',
description: 'custom property set in selector',
},
{
code: 'a[b=#{c}] { }',
description: 'ignore "invalid" selector (see #3130)',
},
],

reject: [
Expand Down
5 changes: 0 additions & 5 deletions lib/rules/selector-attribute-quotes/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';

const isStandardSyntaxRule = require('../../utils/isStandardSyntaxRule');
const isStandardSyntaxSelector = require('../../utils/isStandardSyntaxSelector');
const parseSelector = require('../../utils/parseSelector');
const report = require('../../utils/report');
const ruleMessages = require('../../utils/ruleMessages');
Expand Down Expand Up @@ -30,10 +29,6 @@ const rule = function(expectation) {
return;
}

if (!isStandardSyntaxSelector(rule.selector)) {
return;
}

if (!rule.selector.includes('[') || !rule.selector.includes('=')) {
return;
}
Expand Down
4 changes: 0 additions & 4 deletions lib/rules/selector-class-pattern/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,6 @@ const rule = function(pattern, options) {
return;
}

if (!isStandardSyntaxSelector(selector)) {
return;
}

if (selectors.some((s) => isKeyframeSelector(s))) {
return;
}
Expand Down
4 changes: 4 additions & 0 deletions lib/rules/selector-combinator-space-after/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ testRule(rule, {
code: '.a { &:first-child {} }',
description: 'nesting and no combinators',
},
{
code: 'a[b=#{c}] { }',
description: 'ignore "invalid" selector (see #3130)',
},
],

reject: [
Expand Down
4 changes: 4 additions & 0 deletions lib/rules/selector-combinator-space-before/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ testRule(rule, {
code: 'html { --custom-property-set: {} }',
description: 'custom property set in selector',
},
{
code: 'a[b=#{c}] { }',
description: 'ignore "invalid" selector (see #3130)',
},
{
code: 'namespace|type#id > .foo {}',
description: 'qualified ID with namespace',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ testRule(rule, {
}
`,
},
{
code: 'a[b=#{c}] { }',
description: 'ignore "invalid" selector (see #3130)',
},
],

reject: [
Expand Down
5 changes: 0 additions & 5 deletions lib/rules/selector-id-pattern/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

const _ = require('lodash');
const isStandardSyntaxRule = require('../../utils/isStandardSyntaxRule');
const isStandardSyntaxSelector = require('../../utils/isStandardSyntaxSelector');
const parseSelector = require('../../utils/parseSelector');
const report = require('../../utils/report');
const ruleMessages = require('../../utils/ruleMessages');
Expand Down Expand Up @@ -35,10 +34,6 @@ const rule = function(pattern) {

const selector = rule.selector;

if (!isStandardSyntaxSelector(selector)) {
return;
}

parseSelector(selector, result, rule, (fullSelector) => {
fullSelector.walk((selectorNode) => {
if (selectorNode.type !== 'id') {
Expand Down
5 changes: 0 additions & 5 deletions lib/rules/selector-max-attribute/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
const _ = require('lodash');
const isLogicalCombination = require('../../utils/isLogicalCombination');
const isStandardSyntaxRule = require('../../utils/isStandardSyntaxRule');
const isStandardSyntaxSelector = require('../../utils/isStandardSyntaxSelector');
const optionsMatches = require('../../utils/optionsMatches');
const parseSelector = require('../../utils/parseSelector');
const report = require('../../utils/report');
Expand Down Expand Up @@ -82,10 +81,6 @@ function rule(max, options) {
return;
}

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

ruleNode.selectors.forEach((selector) => {
resolvedNestedSelector(selector, ruleNode).forEach((resolvedSelector) => {
parseSelector(resolvedSelector, result, ruleNode, (container) =>
Expand Down
5 changes: 0 additions & 5 deletions lib/rules/selector-max-class/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

const isLogicalCombination = require('../../utils/isLogicalCombination');
const isStandardSyntaxRule = require('../../utils/isStandardSyntaxRule');
const isStandardSyntaxSelector = require('../../utils/isStandardSyntaxSelector');
const parseSelector = require('../../utils/parseSelector');
const report = require('../../utils/report');
const resolvedNestedSelector = require('postcss-resolve-nested-selector');
Expand Down Expand Up @@ -57,10 +56,6 @@ function rule(max) {
return;
}

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

ruleNode.selectors.forEach((selector) => {
resolvedNestedSelector(selector, ruleNode).forEach((resolvedSelector) => {
parseSelector(resolvedSelector, result, ruleNode, (container) =>
Expand Down
5 changes: 0 additions & 5 deletions lib/rules/selector-max-combinators/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';

const isStandardSyntaxRule = require('../../utils/isStandardSyntaxRule');
const isStandardSyntaxSelector = require('../../utils/isStandardSyntaxSelector');
const parseSelector = require('../../utils/parseSelector');
const report = require('../../utils/report');
const resolvedNestedSelector = require('postcss-resolve-nested-selector');
Expand Down Expand Up @@ -58,10 +57,6 @@ function rule(max) {
return;
}

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

ruleNode.selectors.forEach((selector) => {
resolvedNestedSelector(selector, ruleNode).forEach((resolvedSelector) => {
parseSelector(resolvedSelector, result, ruleNode, (container) =>
Expand Down
5 changes: 0 additions & 5 deletions lib/rules/selector-max-compound-selectors/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

const isLogicalCombination = require('../../utils/isLogicalCombination');
const isStandardSyntaxRule = require('../../utils/isStandardSyntaxRule');
const isStandardSyntaxSelector = require('../../utils/isStandardSyntaxSelector');
const parseSelector = require('../../utils/parseSelector');
const report = require('../../utils/report');
const resolvedNestedSelector = require('postcss-resolve-nested-selector');
Expand Down Expand Up @@ -65,10 +64,6 @@ const rule = function(max) {
return;
}

if (!isStandardSyntaxSelector(rule.selector)) {
return;
}

// Using `rule.selectors` gets us each selector if there is a comma separated set
rule.selectors.forEach((selector) => {
resolvedNestedSelector(selector, rule).forEach((resolvedSelector) => {
Expand Down
5 changes: 0 additions & 5 deletions lib/rules/selector-max-id/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

const isLogicalCombination = require('../../utils/isLogicalCombination');
const isStandardSyntaxRule = require('../../utils/isStandardSyntaxRule');
const isStandardSyntaxSelector = require('../../utils/isStandardSyntaxSelector');
const parseSelector = require('../../utils/parseSelector');
const report = require('../../utils/report');
const resolvedNestedSelector = require('postcss-resolve-nested-selector');
Expand Down Expand Up @@ -57,10 +56,6 @@ function rule(max) {
return;
}

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

ruleNode.selectors.forEach((selector) => {
resolvedNestedSelector(selector, ruleNode).forEach((resolvedSelector) => {
parseSelector(resolvedSelector, result, ruleNode, (container) =>
Expand Down
5 changes: 0 additions & 5 deletions lib/rules/selector-max-pseudo-class/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

const isLogicalCombination = require('../../utils/isLogicalCombination');
const isStandardSyntaxRule = require('../../utils/isStandardSyntaxRule');
const isStandardSyntaxSelector = require('../../utils/isStandardSyntaxSelector');
const keywordSets = require('../../reference/keywordSets');
const parseSelector = require('../../utils/parseSelector');
const report = require('../../utils/report');
Expand Down Expand Up @@ -71,10 +70,6 @@ function rule(max) {
return;
}

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

ruleNode.selectors.forEach((selector) => {
resolvedNestedSelector(selector, ruleNode).forEach((resolvedSelector) => {
parseSelector(resolvedSelector, result, rule, (selectorTree) => {
Expand Down
4 changes: 0 additions & 4 deletions lib/rules/selector-max-specificity/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,6 @@ const rule = function(max, options) {
return;
}

if (!isStandardSyntaxSelector(rule.selector)) {
return;
}

// Using rule.selectors gets us each selector in the eventuality we have a comma separated set
rule.selectors.forEach((selector) => {
resolvedNestedSelector(selector, rule).forEach((resolvedSelector) => {
Expand Down
5 changes: 0 additions & 5 deletions lib/rules/selector-max-type/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,12 @@ function rule(max, options) {
}

root.walkRules((ruleNode) => {
const selector = ruleNode.selector;
const selectors = ruleNode.selectors;

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

if (!isStandardSyntaxSelector(selector)) {
return;
}

if (selectors.some((s) => isKeyframeSelector(s))) {
return;
}
Expand Down
5 changes: 0 additions & 5 deletions lib/rules/selector-max-universal/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';

const isStandardSyntaxRule = require('../../utils/isStandardSyntaxRule');
const isStandardSyntaxSelector = require('../../utils/isStandardSyntaxSelector');
const parseSelector = require('../../utils/parseSelector');
const report = require('../../utils/report');
const resolvedNestedSelector = require('postcss-resolve-nested-selector');
Expand Down Expand Up @@ -60,10 +59,6 @@ function rule(max) {
return;
}

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

const selectors = [];

selectorParser()
Expand Down
5 changes: 0 additions & 5 deletions lib/rules/selector-nested-pattern/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

const _ = require('lodash');
const isStandardSyntaxRule = require('../../utils/isStandardSyntaxRule');
const isStandardSyntaxSelector = require('../../utils/isStandardSyntaxSelector');
const report = require('../../utils/report');
const ruleMessages = require('../../utils/ruleMessages');
const validateOptions = require('../../utils/validateOptions');
Expand Down Expand Up @@ -37,10 +36,6 @@ const rule = function(pattern) {

const selector = rule.selector;

if (!isStandardSyntaxSelector(selector)) {
return;
}

if (normalizedPattern.test(selector)) {
return;
}
Expand Down
5 changes: 0 additions & 5 deletions lib/rules/selector-no-qualifying-type/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,6 @@ const rule = function(enabled, options) {
return;
}

// Increasing performance
if (!isStandardSyntaxSelector(rule.selector)) {
return;
}

if (!isSelectorCharacters(rule.selector)) {
return;
}
Expand Down
5 changes: 0 additions & 5 deletions lib/rules/selector-no-vendor-prefix/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
const _ = require('lodash');
const isAutoprefixable = require('../../utils/isAutoprefixable');
const isStandardSyntaxRule = require('../../utils/isStandardSyntaxRule');
const isStandardSyntaxSelector = require('../../utils/isStandardSyntaxSelector');
const optionsMatches = require('../../utils/optionsMatches');
const parseSelector = require('../../utils/parseSelector');
const report = require('../../utils/report');
Expand Down Expand Up @@ -42,10 +41,6 @@ const rule = function(actual, options) {

const selector = rule.selector;

if (!isStandardSyntaxSelector(selector)) {
return;
}

parseSelector(selector, result, rule, (selectorTree) => {
selectorTree.walkPseudos((pseudoNode) => {
if (isAutoprefixable.selector(pseudoNode.value)) {
Expand Down
5 changes: 0 additions & 5 deletions lib/rules/selector-pseudo-class-blacklist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

const _ = require('lodash');
const isStandardSyntaxRule = require('../../utils/isStandardSyntaxRule');
const isStandardSyntaxSelector = require('../../utils/isStandardSyntaxSelector');
const matchesStringOrRegExp = require('../../utils/matchesStringOrRegExp');
const parseSelector = require('../../utils/parseSelector');
const postcss = require('postcss');
Expand Down Expand Up @@ -34,10 +33,6 @@ const rule = function(blacklist) {

const selector = rule.selector;

if (!isStandardSyntaxSelector(selector)) {
return;
}

if (!selector.includes(':')) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ testRule(rule, {
code: 'html { --custom-property-set: {} }',
description: 'custom property set in selector',
},
{
code: 'a[b=#{c}] { }',
description: 'ignore "invalid" selector (see #3130)',
},
],

reject: [
Expand Down
5 changes: 0 additions & 5 deletions lib/rules/selector-pseudo-class-whitelist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

const _ = require('lodash');
const isStandardSyntaxRule = require('../../utils/isStandardSyntaxRule');
const isStandardSyntaxSelector = require('../../utils/isStandardSyntaxSelector');
const matchesStringOrRegExp = require('../../utils/matchesStringOrRegExp');
const parseSelector = require('../../utils/parseSelector');
const postcss = require('postcss');
Expand Down Expand Up @@ -34,10 +33,6 @@ const rule = function(whitelist) {

const selector = rule.selector;

if (!isStandardSyntaxSelector(selector)) {
return;
}

if (!selector.includes(':')) {
return;
}
Expand Down
5 changes: 0 additions & 5 deletions lib/rules/selector-pseudo-element-blacklist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

const _ = require('lodash');
const isStandardSyntaxRule = require('../../utils/isStandardSyntaxRule');
const isStandardSyntaxSelector = require('../../utils/isStandardSyntaxSelector');
const matchesStringOrRegExp = require('../../utils/matchesStringOrRegExp');
const parseSelector = require('../../utils/parseSelector');
const postcss = require('postcss');
Expand Down Expand Up @@ -34,10 +33,6 @@ const rule = function(blacklist) {

const selector = rule.selector;

if (!isStandardSyntaxSelector(selector)) {
return;
}

if (!selector.includes('::')) {
return;
}
Expand Down

0 comments on commit 0f04539

Please sign in to comment.