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

Fixed: ignore less guards in selector-descendant-combinator-no-non-space. #2557

Merged
merged 1 commit into from
Jun 5, 2017
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,15 @@ testRule(rule, {
column: 5,
} ],
})

testRule(rule, {
ruleName,
config: [true],
syntax: "less",

accept: [ {
code: ":hover when (@variable = true) { color: red; }",
}, {
code: "a:hover when (@variable = true) { color: red; }",
} ],
})
55 changes: 55 additions & 0 deletions lib/utils/__tests__/isStandardSyntaxRule.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ describe("isStandardSyntaxRule", () => {
expect(isStandardSyntaxRule(rule)).toBeTruthy()
})
})
it("when type selector before selector", () => {
return rules("when a {}", rule => {
expect(isStandardSyntaxRule(rule)).toBeTruthy()
})
})
it("when type selector after selector", () => {
return rules("a when {}", rule => {
expect(isStandardSyntaxRule(rule)).toBeTruthy()
})
})
it("pseudo-class", () => {
return rules("a:last-child {}", rule => {
expect(isStandardSyntaxRule(rule)).toBeTruthy()
Expand Down Expand Up @@ -100,6 +110,51 @@ describe("isStandardSyntaxRule", () => {
expect(isStandardSyntaxRule(rule)).toBeFalsy()
})
})
it("less guarded namespaces", () => {
return lessRules("#namespace when (@mode=huge) {}", rule => {
expect(isStandardSyntaxRule(rule)).toBeFalsy()
})
})
it("mixin guards", () => {
return lessRules(".mixin (@variable) when (@variable = 10px) {}", rule => {
expect(isStandardSyntaxRule(rule)).toBeFalsy()
})
})
it("css guards", () => {
return lessRules(".foo() when (@variable = true) {}", rule => {
expect(isStandardSyntaxRule(rule)).toBeFalsy()
})
})
it("css guards without spaces", () => {
return lessRules(".foo()when(@variable = true) {}", rule => {
expect(isStandardSyntaxRule(rule)).toBeFalsy()
})
})
it("css guards with multiple spaces", () => {
return lessRules(".foo() when (@variable = true) {}", rule => {
expect(isStandardSyntaxRule(rule)).toBeFalsy()
})
})
it("css guards with newlines", () => {
return lessRules(".foo()\nwhen\n(@variable = true) {}", rule => {
expect(isStandardSyntaxRule(rule)).toBeFalsy()
})
})
it("css guards with CLRF", () => {
return lessRules(".foo()\r\nwhen\r\n(@variable = true) {}", rule => {
expect(isStandardSyntaxRule(rule)).toBeFalsy()
})
})
it("css guards with parenthesis", () => {
return lessRules(".foo() when (default()) {}", rule => {
expect(isStandardSyntaxRule(rule)).toBeFalsy()
})
})
it("css guards with not", () => {
return lessRules(".foo() when not (@variable = true) {}", rule => {
expect(isStandardSyntaxRule(rule)).toBeFalsy()
})
})
})

function rules(css, cb) {
Expand Down
5 changes: 5 additions & 0 deletions lib/utils/isStandardSyntaxRule.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ module.exports = function (rule/*: Object*/)/*: boolean*/ {
return false
}

// Less guards
if ((/when\s+(not\s+)*\(/).test(selector)) {
return false
}

// Ignore Scss nested properties
if (selector.slice(-1) === ":") {
return false
Expand Down