Skip to content

Commit 413e48e

Browse files
committed
feat: Add SCSS preset config (#96)
* feat: Add SCSS preset config * fix: Include README.md and scss.js in package.json files list * test: Add initial SCSS tests
1 parent b70ece2 commit 413e48e

4 files changed

Lines changed: 110 additions & 1 deletion

File tree

packages/stylelint-config-wordpress/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Configuration rules to ensure your CSS is compliant with the [WordPress CSS Codi
99

1010
- [Installation](#installation)
1111
- [Usage](#usage)
12+
- [Presets](#presets)
1213
- [Extending the config](#extending-the-config)
1314
- [Style Guide](#style-guide)
1415
- [Structure](#structure)
@@ -47,6 +48,20 @@ If you've globally installed `stylelint-config-wordpress` using the `-g` flag, t
4748
}
4849
```
4950

51+
## Presets
52+
53+
In addition to the default preset, there are also specific presets. All presets extend the default one.
54+
55+
### SCSS
56+
57+
```json
58+
{
59+
"extends": [
60+
"stylelint-config-wordpress/scss"
61+
]
62+
}
63+
```
64+
5065
## Extending the config
5166

5267
Simply add a `"rules"` key to your config and add your overrides there.
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import config from "../scss.js"
2+
import stylelint from "stylelint"
3+
import test from "ava"
4+
5+
/* eslint-disable */
6+
const validScss = (`
7+
@import "path/to/foo.scss";
8+
9+
@function fooBar {
10+
11+
@return 1;
12+
}
13+
14+
@mixin foo {
15+
16+
@content;
17+
}
18+
19+
a {
20+
21+
@debug 1;
22+
}
23+
24+
$map: (
25+
"foo": 1,
26+
"bar": 2,
27+
"baz": 3
28+
);
29+
30+
@if $foo == block {
31+
display: block;
32+
}
33+
34+
@else {
35+
display: inline-block;
36+
}
37+
`)
38+
39+
const invalidScss = (`
40+
@unknown {
41+
display: block;
42+
}
43+
`)
44+
/* eslint-enable */
45+
46+
test("There are no warnings with values SCSS", t => {
47+
return stylelint.lint({
48+
code: validScss,
49+
config: config,
50+
syntax: "scss",
51+
})
52+
.then(data => {
53+
const { errored, results } = data
54+
const { warnings } = results[0]
55+
t.falsy(errored, "no errored")
56+
t.is(warnings.length, 0, "flags no warnings")
57+
})
58+
})
59+
60+
test("There are warnings with invalid values SCSS", t => {
61+
return stylelint.lint({
62+
code: invalidScss,
63+
config: config,
64+
syntax: "scss",
65+
})
66+
.then(data => {
67+
const { errored, results } = data
68+
const { warnings } = results[0]
69+
t.truthy(errored, "errored")
70+
t.is(warnings.length, 1, "flags one warning")
71+
t.is(warnings[0].text, "Unexpected unknown at-rule \"@unknown\" (at-rule-no-unknown)", "correct warning text") })
72+
})

packages/stylelint-config-wordpress/package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@
2828
"files": [
2929
"CHANGELOG.md",
3030
"LICENSE",
31-
"index.js"
31+
"README.md",
32+
"index.js",
33+
"scss.js"
3234
],
3335
"engines": {
3436
"node": ">=4.2.1"
@@ -76,5 +78,8 @@
7678
"lint-recommended",
7779
"lint-consistent"
7880
]
81+
},
82+
"dependencies": {
83+
"stylelint-scss": "^1.3.4"
7984
}
8085
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module.exports = {
2+
"extends": [
3+
"./",
4+
].map(require.resolve),
5+
6+
plugins: [
7+
"stylelint-scss",
8+
],
9+
10+
rules: {
11+
12+
// stylelint-config-wordpress css overrides
13+
"at-rule-no-unknown": [ true, {
14+
ignoreAtRules: [ "extend", "at-root", "debug", "warn", "error", "if", "else", "for", "each", "while", "mixin", "include", "content", "return", "function" ],
15+
} ],
16+
},
17+
}

0 commit comments

Comments
 (0)