Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate selectors consistently. Fixes #3130 #4483

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
3 changes: 2 additions & 1 deletion lib/rules/selector-attribute-brackets-space-inside/index.js
Expand Up @@ -2,6 +2,7 @@

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 @@ -29,7 +30,7 @@ const rule = function(expectation, options, context) {
}

root.walkRules((rule) => {
if (!isStandardSyntaxRule(rule)) {
if (!isStandardSyntaxRule(rule) || !isStandardSyntaxSelector(rule.selector)) {
return;
}

Expand Down
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
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
4 changes: 4 additions & 0 deletions lib/rules/selector-combinator-space-after/__tests__/index.js
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
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
Expand Up @@ -79,6 +79,10 @@ testRule(rule, {
}
`,
},
{
code: 'a[b=#{c}] { }',
description: 'ignore "invalid" selector (see #3130)',
},
],

reject: [
Expand Down
@@ -1,6 +1,7 @@
'use strict';

const isStandardSyntaxRule = require('../../utils/isStandardSyntaxRule');
const isStandardSyntaxSelector = require('../../utils/isStandardSyntaxSelector');
const parseSelector = require('../../utils/parseSelector');
const punctuationSets = require('../../reference/punctuationSets');
const report = require('../../utils/report');
Expand Down Expand Up @@ -31,6 +32,10 @@ const rule = function(expectation, options, context) {
let hasFixed = false;
const selector = rule.raws.selector ? rule.raws.selector.raw : rule.selector;

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

const fixedSelector = parseSelector(selector, result, rule, (fullSelector) => {
fullSelector.walkCombinators((combinatorNode) => {
if (!isActuallyCombinator(combinatorNode)) {
Expand Down
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
@@ -1,6 +1,7 @@
'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 All @@ -27,7 +28,7 @@ const rule = function(expectation, options, context) {
}

root.walkRules((rule) => {
if (!isStandardSyntaxRule(rule)) {
if (!isStandardSyntaxRule(rule) || !isStandardSyntaxSelector(rule.selector)) {
return;
}

Expand Down
3 changes: 2 additions & 1 deletion lib/rules/selectorAttributeOperatorSpaceChecker.js
@@ -1,13 +1,14 @@
'use strict';

const isStandardSyntaxRule = require('../utils/isStandardSyntaxRule');
const isStandardSyntaxSelector = require('../utils/isStandardSyntaxSelector');
const parseSelector = require('../utils/parseSelector');
const report = require('../utils/report');
const styleSearch = require('style-search');

module.exports = function(options) {
options.root.walkRules((rule) => {
if (!isStandardSyntaxRule(rule)) {
if (!isStandardSyntaxRule(rule) || !isStandardSyntaxSelector(rule.selector)) {
return;
}

Expand Down
5 changes: 5 additions & 0 deletions lib/rules/selectorCombinatorSpaceChecker.js
@@ -1,6 +1,7 @@
'use strict';

const isStandardSyntaxRule = require('../utils/isStandardSyntaxRule');
const isStandardSyntaxSelector = require('../utils/isStandardSyntaxSelector');
const parseSelector = require('../utils/parseSelector');
const report = require('../utils/report');

Expand All @@ -15,6 +16,10 @@ module.exports = function(opts) {
hasFixed = false;
const selector = rule.raws.selector ? rule.raws.selector.raw : rule.selector;

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

const fixedSelector = parseSelector(selector, opts.result, rule, (selectorTree) => {
selectorTree.walkCombinators((node) => {
// Ignore spaced descendant combinator
Expand Down
4 changes: 4 additions & 0 deletions lib/rules/string-quotes/__tests__/index.js
Expand Up @@ -50,6 +50,10 @@ testRule(rule, {
code: '@charset "utf-8"',
description: 'ignore @charset rules',
},
{
code: 'a[b=#{c}][d="e"] { }',
description: 'ignore "invalid" selector (see #3130)',
},
],

reject: [
Expand Down
3 changes: 2 additions & 1 deletion lib/rules/string-quotes/index.js
Expand Up @@ -4,6 +4,7 @@ const _ = require('lodash');
const atRuleParamIndex = require('../../utils/atRuleParamIndex');
const declarationValueIndex = require('../../utils/declarationValueIndex');
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 @@ -61,7 +62,7 @@ const rule = function(expectation, secondary, context) {
});

function checkRule(rule) {
if (!isStandardSyntaxRule(rule)) {
if (!isStandardSyntaxRule(rule) || !isStandardSyntaxSelector(rule.selector)) {
return;
}

Expand Down