Skip to content

Commit 51ebcb9

Browse files
authored
Enforce usage of variables for colors with stylelint-declaration-strict-value. Fix #2 (#4)
1 parent 08d92ab commit 51ebcb9

File tree

8 files changed

+53
-3
lines changed

8 files changed

+53
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
88

99
### Features
1010

11-
- Enforce accessibility-related rules with [stylelint-a11y](https://github.com/YozhikM/stylelint-a11y) ([#2](https://github.com/torchbox/stylelint-config-torchbox/issues/2)).
11+
- Enforce accessibility-related rules with [stylelint-a11y](https://github.com/YozhikM/stylelint-a11y) ([#2](https://github.com/torchbox/stylelint-config-torchbox/issues/2), [#3](https://github.com/torchbox/stylelint-config-torchbox/pull/3)).
12+
- Enforce usage of variables for colors with [stylelint-declaration-strict-value](https://github.com/AndyOGo/stylelint-declaration-strict-value) ([#2](https://github.com/torchbox/stylelint-config-torchbox/issues/2), [#4](https://github.com/torchbox/stylelint-config-torchbox/pull/4)).
1213

1314
### BREAKING CHANGES
1415

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ To get the most out of this config, it is assumed that projects have the followi
4040
> - [`stylelint-scss`](https://github.com/kristerkari/stylelint-scss)
4141
> - [`stylelint-order`](https://github.com/hudochenkov/stylelint-order)
4242
> - [`stylelint-a11y`](https://github.com/YozhikM/stylelint-a11y)
43+
> - [`stylelint-declaration-strict-value`](https://github.com/AndyOGo/stylelint-declaration-strict-value)
4344
> - [`stylelint-config-standard`](https://github.com/stylelint/stylelint-config-standard)
4445
> - [`stylelint-config-prettier`](https://github.com/prettier/stylelint-config-prettier)
4546
@@ -75,6 +76,7 @@ To get the most out of this config, it is assumed that projects have the followi
7576
- [`a11y/no-obsolete-element`](https://github.com/YozhikM/stylelint-a11y#readme)
7677
- [`a11y/no-text-align-justify`](https://github.com/YozhikM/stylelint-a11y#readme)
7778
- [`a11y/no-outline-none`](https://github.com/YozhikM/stylelint-a11y#readme)
79+
- [`scale-unlimited/declaration-strict-value`](https://github.com/AndyOGo/stylelint-declaration-strict-value#readme): `color, background-color, fill, stroke, /-color/, ignoreKeywords: currentColor, inherit, transparent, initial`
7880

7981
#### Rules of `stylelint-config-standard`
8082

@@ -256,6 +258,13 @@ To get the most out of this config, it is assumed that projects have the followi
256258
- [`scss/dollar-variable-default`](https://github.com/kristerkari/stylelint-scss#readme)
257259
- [`scss/no-dollar-variables`](https://github.com/kristerkari/stylelint-scss#readme)
258260
- [`order/properties-alphabetical-order`](https://github.com/hudochenkov/stylelint-order)
261+
- [`a11y/font-size-is-readable`](https://github.com/YozhikM/stylelint-a11y#readme)
262+
- [`a11y/line-height-is-vertical-rhythmed`](https://github.com/YozhikM/stylelint-a11y#readme)
263+
- [`a11y/media-prefers-color-scheme`](https://github.com/YozhikM/stylelint-a11y#readme)
264+
- [`a11y/media-prefers-reduced-motion`](https://github.com/YozhikM/stylelint-a11y#readme)
265+
- [`a11y/no-display-none`](https://github.com/YozhikM/stylelint-a11y#readme)
266+
- [`a11y/no-spread-text`](https://github.com/YozhikM/stylelint-a11y#readme)
267+
- [`a11y/selector-pseudo-class-focus`](https://github.com/YozhikM/stylelint-a11y#readme)
259268
- [`at-rule-blacklist`](https://stylelint.io/user-guide/rules/at-rule-blacklist/)
260269
- [`at-rule-property-requirelist`](https://stylelint.io/user-guide/rules/at-rule-property-requirelist/)
261270
- [`at-rule-whitelist`](https://stylelint.io/user-guide/rules/at-rule-whitelist/)

config.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@
33
// See https://stylelint.io/user-guide/rules/.
44
module.exports = {
55
extends: ['stylelint-config-standard', 'stylelint-config-prettier'],
6-
plugins: ['stylelint-scss', 'stylelint-order', 'stylelint-a11y'],
6+
plugins: [
7+
'stylelint-scss',
8+
'stylelint-order',
9+
'stylelint-a11y',
10+
'stylelint-declaration-strict-value',
11+
],
712
rules: {
813
'color-named': 'never',
914
'number-leading-zero': 'always',
@@ -43,5 +48,16 @@ module.exports = {
4348
'a11y/no-obsolete-element': true,
4449
'a11y/no-text-align-justify': true,
4550
'a11y/no-outline-none': true,
51+
'scale-unlimited/declaration-strict-value': [
52+
['color', 'background-color', 'fill', 'stroke', '/-color/'],
53+
{
54+
ignoreKeywords: [
55+
'currentColor',
56+
'inherit',
57+
'transparent',
58+
'initial',
59+
],
60+
},
61+
],
4662
},
4763
};

package-lock.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"stylelint-a11y": "^1.2.1",
3737
"stylelint-config-prettier": "^5.2.0",
3838
"stylelint-config-standard": "^18.3.0",
39+
"stylelint-declaration-strict-value": "^1.1.6",
3940
"stylelint-order": "^3.1.1",
4041
"stylelint-scss": "^3.10.0"
4142
},

src/__snapshots__/semver.test.js.snap

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,23 @@ Object {
220220
true,
221221
],
222222
"rule-empty-line-before": null,
223+
"scale-unlimited/declaration-strict-value": Array [
224+
Array [
225+
"color",
226+
"background-color",
227+
"fill",
228+
"stroke",
229+
"/-color/",
230+
],
231+
Object {
232+
"ignoreKeywords": Array [
233+
"currentColor",
234+
"inherit",
235+
"transparent",
236+
"initial",
237+
],
238+
},
239+
],
223240
"scss/at-mixin-argumentless-call-parentheses": Array [
224241
"always",
225242
],

src/config.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ describe('config', () => {
1313
configFile: path.join(__dirname, '..', 'config.js'),
1414
})
1515
.then((results) => {
16-
expect(results.results[0].warnings.length).toBe(6);
16+
expect(results.results[0].warnings.length).toBe(7);
1717
});
1818
});
1919
});

src/semver.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ describe('semver - should those tests break, consider releasing a new major vers
1010
"stylelint-a11y": "^1.2.1",
1111
"stylelint-config-prettier": "^5.2.0",
1212
"stylelint-config-standard": "^18.3.0",
13+
"stylelint-declaration-strict-value": "^1.1.6",
1314
"stylelint-order": "^3.1.1",
1415
"stylelint-scss": "^3.10.0",
1516
}

0 commit comments

Comments
 (0)