Skip to content

Commit

Permalink
Fixed: Added stylelint-scss plugin @if/@else placement rules. (#127)
Browse files Browse the repository at this point in the history
  • Loading branch information
ntwb committed May 31, 2020
1 parent 8fb34e4 commit 7e7624d
Show file tree
Hide file tree
Showing 5 changed files with 150 additions and 5 deletions.
1 change: 1 addition & 0 deletions packages/stylelint-config-wordpress/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- Removed: NodeJS 4.x support, `stylelint` and `stylelint-config-wordpress` now require NodeJS > 6.9.1 LTS or greater
- Added: NodeJS 7.x.x support
- Added: `selector-no-empty` rule.
- Fixed: Added `stylelint-scss` plugin @if/@else placement rules.
- Fixed: Removed `@debug` from `ignoreAtRules` array of `at-rule-no-unknown` rule in `stylelint-config-wordpress/scss` chared config.
- Added: `scss/selector-no-redundant-nesting-selector` rule in `stylelint-config-wordpress/scss` chared config.
- Deprecated `blockless-group` option for `at-rule-empty-line-before` rule. Use the new `blockless-after-blockless` option instead.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,11 @@ a {

@debug 1;
}

@if $foo == block {
display: block;
}

@else{
display: inline-block;
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ $map: (

@if $foo == block {
display: block;
}

@else {
} @else {
display: inline-block;
}
124 changes: 122 additions & 2 deletions packages/stylelint-config-wordpress/__tests__/scss.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ describe("flags warnings with invalid scss", () => {
))
})

it("flags two warnings", () => {
it("flags six warnings", () => {
return result.then(data => (
expect(data.results[0].warnings.length).toBe(2)
expect(data.results[0].warnings.length).toBe(6)
))
})

Expand Down Expand Up @@ -111,4 +111,124 @@ describe("flags warnings with invalid scss", () => {
expect(data.results[0].warnings[1].column).toBe(2)
))
})

it("correct third warning text", () => {
return result.then(data => (
expect(data.results[0].warnings[2].text).toBe("Expected single space before \"{\" (block-opening-brace-space-before)")
))
})

it("correct third warning rule flagged", () => {
return result.then(data => (
expect(data.results[0].warnings[2].rule).toBe("block-opening-brace-space-before")
))
})

it("correct third warning severity flagged", () => {
return result.then(data => (
expect(data.results[0].warnings[2].severity).toBe("error")
))
})

it("correct third warning line number", () => {
return result.then(data => (
expect(data.results[0].warnings[2].line).toBe(14)
))
})

it("correct third warning column number", () => {
return result.then(data => (
expect(data.results[0].warnings[2].column).toBe(5)
))
})

it("correct forth warning text", () => {
return result.then(data => (
expect(data.results[0].warnings[3].text).toBe("Unxpected empty line before @else (scss/at-else-empty-line-before)")
))
})

it("correct forth warning rule flagged", () => {
return result.then(data => (
expect(data.results[0].warnings[3].rule).toBe("scss/at-else-empty-line-before")
))
})

it("correct forth warning severity flagged", () => {
return result.then(data => (
expect(data.results[0].warnings[3].severity).toBe("error")
))
})

it("correct forth warning line number", () => {
return result.then(data => (
expect(data.results[0].warnings[3].line).toBe(14)
))
})

it("correct forth warning column number", () => {
return result.then(data => (
expect(data.results[0].warnings[3].column).toBe(1)
))
})

it("correct fifth warning text", () => {
return result.then(data => (
expect(data.results[0].warnings[4].text).toBe("Unexpected newline after \"}\" of @if statement (scss/at-if-closing-brace-newline-after)")
))
})

it("correct fifth warning rule flagged", () => {
return result.then(data => (
expect(data.results[0].warnings[4].rule).toBe("scss/at-if-closing-brace-newline-after")
))
})

it("correct fifth warning severity flagged", () => {
return result.then(data => (
expect(data.results[0].warnings[4].severity).toBe("error")
))
})

it("correct fifth warning line number", () => {
return result.then(data => (
expect(data.results[0].warnings[4].line).toBe(12)
))
})

it("correct fifth warning column number", () => {
return result.then(data => (
expect(data.results[0].warnings[4].column).toBe(2)
))
})

it("correct sixth warning text", () => {
return result.then(data => (
expect(data.results[0].warnings[5].text).toBe("Expected single space after \"}\" of @if statement (scss/at-if-closing-brace-space-after)")
))
})

it("correct sixth warning rule flagged", () => {
return result.then(data => (
expect(data.results[0].warnings[5].rule).toBe("scss/at-if-closing-brace-space-after")
))
})

it("correct sixth warning severity flagged", () => {
return result.then(data => (
expect(data.results[0].warnings[5].severity).toBe("error")
))
})

it("correct sixth warning line number", () => {
return result.then(data => (
expect(data.results[0].warnings[5].line).toBe(12)
))
})

it("correct sixth warning column number", () => {
return result.then(data => (
expect(data.results[0].warnings[5].column).toBe(2)
))
})
})
18 changes: 18 additions & 0 deletions packages/stylelint-config-wordpress/scss.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,24 @@ module.exports = {
"at-rule-no-unknown": [ true, {
ignoreAtRules: [ "extend", "at-root", "warn", "error", "if", "else", "for", "each", "while", "mixin", "include", "content", "return", "function" ],
} ],
"at-rule-empty-line-before": [
"always", {
"ignoreAtRules": ["else"],
},
],
"block-opening-brace-space-before": "always",
"block-closing-brace-newline-after": [
"always", {
"ignoreAtRules": [ "if", "else" ],
},
],
"at-rule-name-space-after": "always",
"rule-non-nested-empty-line-before": "always",
"scss/at-else-closing-brace-newline-after": "always-last-in-chain",
"scss/at-else-closing-brace-space-after": "always-intermediate",
"scss/at-else-empty-line-before": "never",
"scss/at-if-closing-brace-newline-after": "always-last-in-chain",
"scss/at-if-closing-brace-space-after": "always-intermediate",
"scss/selector-no-redundant-nesting-selector": true,
},
}

0 comments on commit 7e7624d

Please sign in to comment.