From 7e7624d64aa5514901e55b8c9cd9fe8eef3cc646 Mon Sep 17 00:00:00 2001 From: Stephen Edgar Date: Sat, 15 Apr 2017 21:10:59 +1000 Subject: [PATCH] Fixed: Added `stylelint-scss` plugin @if/@else placement rules. (#127) --- .../stylelint-config-wordpress/CHANGELOG.md | 1 + .../__tests__/scss-invalid.scss | 8 ++ .../__tests__/scss-valid.scss | 4 +- .../__tests__/scss.js | 124 +++++++++++++++++- packages/stylelint-config-wordpress/scss.js | 18 +++ 5 files changed, 150 insertions(+), 5 deletions(-) diff --git a/packages/stylelint-config-wordpress/CHANGELOG.md b/packages/stylelint-config-wordpress/CHANGELOG.md index e1d8cd78e633f..a13bf1333f9bb 100644 --- a/packages/stylelint-config-wordpress/CHANGELOG.md +++ b/packages/stylelint-config-wordpress/CHANGELOG.md @@ -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. diff --git a/packages/stylelint-config-wordpress/__tests__/scss-invalid.scss b/packages/stylelint-config-wordpress/__tests__/scss-invalid.scss index 4c5b12dc00561..66f8c3654048f 100644 --- a/packages/stylelint-config-wordpress/__tests__/scss-invalid.scss +++ b/packages/stylelint-config-wordpress/__tests__/scss-invalid.scss @@ -6,3 +6,11 @@ a { @debug 1; } + +@if $foo == block { + display: block; +} + +@else{ + display: inline-block; +} diff --git a/packages/stylelint-config-wordpress/__tests__/scss-valid.scss b/packages/stylelint-config-wordpress/__tests__/scss-valid.scss index f6ea40db2db8d..86c8d7da7c88c 100644 --- a/packages/stylelint-config-wordpress/__tests__/scss-valid.scss +++ b/packages/stylelint-config-wordpress/__tests__/scss-valid.scss @@ -18,8 +18,6 @@ $map: ( @if $foo == block { display: block; -} - -@else { +} @else { display: inline-block; } diff --git a/packages/stylelint-config-wordpress/__tests__/scss.js b/packages/stylelint-config-wordpress/__tests__/scss.js index f2c7cd4f0fdab..b4238e5f364b6 100644 --- a/packages/stylelint-config-wordpress/__tests__/scss.js +++ b/packages/stylelint-config-wordpress/__tests__/scss.js @@ -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) )) }) @@ -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) + )) + }) }) diff --git a/packages/stylelint-config-wordpress/scss.js b/packages/stylelint-config-wordpress/scss.js index 09a08fd6746ea..553f2fd646b25 100644 --- a/packages/stylelint-config-wordpress/scss.js +++ b/packages/stylelint-config-wordpress/scss.js @@ -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, }, }