Skip to content

Commit

Permalink
Fixed: ignore less guards in `selector-descendant-combinator-no-non-s…
Browse files Browse the repository at this point in the history
…pace`.
  • Loading branch information
alexander-akait committed May 13, 2017
1 parent a579b58 commit 5267965
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 0 deletions.
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.*?\(.*?\)/).test(selector)) {
return false
}

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

0 comments on commit 5267965

Please sign in to comment.