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

False negatives for rules with nested rules at selector-max-* #4357

Merged
merged 1 commit into from Oct 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 0 additions & 6 deletions lib/rules/selector-max-attribute/index.js
@@ -1,7 +1,6 @@
'use strict';

const _ = require('lodash');
const hasUnresolvedNestedSelector = require('../../utils/hasUnresolvedNestedSelector');
const isLogicalCombination = require('../../utils/isLogicalCombination');
const isStandardSyntaxRule = require('../../utils/isStandardSyntaxRule');
const isStandardSyntaxSelector = require('../../utils/isStandardSyntaxSelector');
Expand Down Expand Up @@ -87,11 +86,6 @@ function rule(max, options) {
return;
}

if (hasUnresolvedNestedSelector(ruleNode)) {
// Skip unresolved nested selectors
return;
}

ruleNode.selectors.forEach((selector) => {
resolvedNestedSelector(selector, ruleNode).forEach((resolvedSelector) => {
parseSelector(resolvedSelector, result, ruleNode, (container) =>
Expand Down
15 changes: 12 additions & 3 deletions lib/rules/selector-max-class/__tests__/index.js
Expand Up @@ -162,13 +162,16 @@ testRule(rule, {
code: '.foo.bar #{$test} {}',
description: 'scss: ignore variable interpolation',
},
],

reject: [
{
code: '.foo { margin: { left: 0; top: 0; }; }',
description: 'scss: nested properties',
message: messages.expected('.foo', 0),
line: 1,
column: 1,
},
],

reject: [
{
code: '@include test { .foo {} }',
description: 'scss: mixin @include',
Expand All @@ -194,9 +197,15 @@ testRule(rule, {
code: '.setFont(@size) { font-size: @size; }',
description: 'less: ignore mixins',
},
],

reject: [
{
code: '.foo { .setFont(12px) }',
description: 'less: ignore called mixins',
message: messages.expected('.foo', 0),
line: 1,
column: 1,
},
],
});
5 changes: 0 additions & 5 deletions lib/rules/selector-max-class/index.js
Expand Up @@ -61,11 +61,6 @@ function rule(max) {
return;
}

if (ruleNode.nodes.some((node) => ['rule', 'atrule'].indexOf(node.type) !== -1)) {
// Skip unresolved nested selectors
return;
}

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

const hasUnresolvedNestedSelector = require('../../utils/hasUnresolvedNestedSelector');
const isStandardSyntaxRule = require('../../utils/isStandardSyntaxRule');
const isStandardSyntaxSelector = require('../../utils/isStandardSyntaxSelector');
const parseSelector = require('../../utils/parseSelector');
Expand Down Expand Up @@ -63,11 +62,6 @@ function rule(max) {
return;
}

if (hasUnresolvedNestedSelector(ruleNode)) {
// Skip unresolved nested selectors
return;
}

ruleNode.selectors.forEach((selector) => {
resolvedNestedSelector(selector, ruleNode).forEach((resolvedSelector) => {
parseSelector(resolvedSelector, result, ruleNode, (container) =>
Expand Down
32 changes: 32 additions & 0 deletions lib/rules/selector-max-type/__tests__/index.js
Expand Up @@ -211,6 +211,22 @@ testRule(rule, {
line: 1,
column: 7,
},
{
code: 'a { b { c { d { } } } }',
description: 'nested rule',
warnings: [
{
message: messages.expected('a b c', 2),
line: 1,
column: 9,
},
{
message: messages.expected('a b c d', 2),
line: 1,
column: 13,
},
],
},
],
});

Expand Down Expand Up @@ -558,6 +574,22 @@ testRule(rule, {
line: 1,
column: 1,
},
{
code: 'a { &:hover { } }',
description: 'nested rule',
warnings: [
{
message: messages.expected('a', 0),
line: 1,
column: 1,
},
{
message: messages.expected('a:hover', 0),
line: 1,
column: 5,
},
],
},
],
});

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

const _ = require('lodash');
const hasUnresolvedNestedSelector = require('../../utils/hasUnresolvedNestedSelector');
const isKeyframeSelector = require('../../utils/isKeyframeSelector');
const isLogicalCombination = require('../../utils/isLogicalCombination');
const isOnlyWhitespace = require('../../utils/isOnlyWhitespace');
Expand Down Expand Up @@ -110,11 +109,6 @@ function rule(max, options) {
return;
}

if (hasUnresolvedNestedSelector(ruleNode)) {
// Skip unresolved nested selectors
return;
}

ruleNode.selectors.forEach((selector) => {
resolvedNestedSelector(selector, ruleNode).forEach((resolvedSelector) => {
if (!isStandardSyntaxSelector(resolvedSelector)) {
Expand Down
6 changes: 0 additions & 6 deletions lib/rules/selector-max-universal/index.js
@@ -1,6 +1,5 @@
'use strict';

const hasUnresolvedNestedSelector = require('../../utils/hasUnresolvedNestedSelector');
const isStandardSyntaxRule = require('../../utils/isStandardSyntaxRule');
const isStandardSyntaxSelector = require('../../utils/isStandardSyntaxSelector');
const parseSelector = require('../../utils/parseSelector');
Expand Down Expand Up @@ -65,11 +64,6 @@ function rule(max) {
return;
}

if (hasUnresolvedNestedSelector(ruleNode)) {
// Skip unresolved nested selectors
return;
}

const selectors = [];

selectorParser()
Expand Down
64 changes: 0 additions & 64 deletions lib/utils/__tests__/hasUnresolvedNestedSelector.test.js

This file was deleted.

9 changes: 0 additions & 9 deletions lib/utils/hasUnresolvedNestedSelector.js

This file was deleted.

42 changes: 42 additions & 0 deletions system-tests/005/__snapshots__/005.test.js.snap
Expand Up @@ -16375,6 +16375,20 @@ Array [
"severity": "error",
"text": "Expected \\"[type=\\"submit\\"]\\" to have no more than 0 attribute selectors (selector-max-attribute)",
},
Object {
"column": 3,
"line": 124,
"rule": "selector-max-combinators",
"severity": "error",
"text": "Expected \\"a .foo\\" to have no more than 0 combinators (selector-max-combinators)",
},
Object {
"column": 5,
"line": 125,
"rule": "selector-max-combinators",
"severity": "error",
"text": "Expected \\"a .foo__foo\\" to have no more than 0 combinators (selector-max-combinators)",
},
Object {
"column": 7,
"line": 126,
Expand Down Expand Up @@ -16972,6 +16986,27 @@ b\\" to have no more than 0 combinators (selector-max-combinators)",
"severity": "error",
"text": "Expected \\"a\\" to have no more than 0 type selectors (selector-max-type)",
},
Object {
"column": 1,
"line": 123,
"rule": "selector-max-type",
"severity": "error",
"text": "Expected \\"a\\" to have no more than 0 type selectors (selector-max-type)",
},
Object {
"column": 3,
"line": 124,
"rule": "selector-max-type",
"severity": "error",
"text": "Expected \\"a .foo\\" to have no more than 0 type selectors (selector-max-type)",
},
Object {
"column": 5,
"line": 125,
"rule": "selector-max-type",
"severity": "error",
"text": "Expected \\"a .foo__foo\\" to have no more than 0 type selectors (selector-max-type)",
},
Object {
"column": 7,
"line": 126,
Expand Down Expand Up @@ -17191,6 +17226,13 @@ b\\" to have no more than 0 combinators (selector-max-combinators)",

b\\" to have no more than 0 type selectors (selector-max-type)",
},
Object {
"column": 1,
"line": 194,
"rule": "selector-max-type",
"severity": "error",
"text": "Expected \\"a\\" to have no more than 0 type selectors (selector-max-type)",
},
Object {
"column": 3,
"line": 195,
Expand Down