@primer/stylelint-config 12.4.2 → 12.5.0-rc.d5df50d

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,258 @@
1
+ # Changelog
2
+
3
+ ## 12.5.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#262](https://github.com/primer/stylelint-config/pull/262) [`28a4086`](https://github.com/primer/stylelint-config/commit/28a4086e8c781f76494c7e77b9437046a6f686a6) Thanks [@jonrohan](https://github.com/jonrohan)! - Writing a primer/utilities plugin to look for code that duplicates utilities
8
+
9
+ ## 12.4.2
10
+
11
+ ### Patch Changes
12
+
13
+ - [#258](https://github.com/primer/stylelint-config/pull/258) [`fa48eed`](https://github.com/primer/stylelint-config/commit/fa48eed1af84474fa49bdb7ec861d2c6a3210239) Thanks [@jonrohan](https://github.com/jonrohan)! - Fixing dependencies
14
+
15
+ * [#260](https://github.com/primer/stylelint-config/pull/260) [`4f42328`](https://github.com/primer/stylelint-config/commit/4f4232826cd3055e0e9dc49ff16925c47db21863) Thanks [@jonrohan](https://github.com/jonrohan)! - Turning off 'function-no-unknown': null,
16
+
17
+ ## 12.4.1
18
+
19
+ ### Patch Changes
20
+
21
+ - [#256](https://github.com/primer/stylelint-config/pull/256) [`37eb1cb`](https://github.com/primer/stylelint-config/commit/37eb1cbd342590f4c43e37779f657a4b19594eca) Thanks [@jonrohan](https://github.com/jonrohan)! - Remove stylelint peer
22
+
23
+ ## 12.4.0
24
+
25
+ ### Minor Changes
26
+
27
+ - [#232](https://github.com/primer/stylelint-config/pull/232) [`27ddfc9`](https://github.com/primer/stylelint-config/commit/27ddfc98f93ed898552bb62aa0926d35497dda72) Thanks [@jonrohan](https://github.com/jonrohan)! - Creating a responsive-widths plugin to keep fixed widths smaller than the minimum viewport size
28
+
29
+ * [#253](https://github.com/primer/stylelint-config/pull/253) [`0edeee0`](https://github.com/primer/stylelint-config/commit/0edeee07b1e7ef51bcd0942c65d98131ac384887) Thanks [@jonrohan](https://github.com/jonrohan)! - Changing this peerDependency to be any
30
+
31
+ ## 12.3.3
32
+
33
+ ### Patch Changes
34
+
35
+ - [#218](https://github.com/primer/stylelint-config/pull/218) [`c03be7d`](https://github.com/primer/stylelint-config/commit/c03be7da1126123c079d86e00a2158a913e015f8) Thanks [@jonrohan](https://github.com/jonrohan)! - [Bug fix] Catching values with dots in them
36
+
37
+ * [#217](https://github.com/primer/stylelint-config/pull/217) [`5bb2834`](https://github.com/primer/stylelint-config/commit/5bb28342a6194dfdd4fbf5197682367ea54792b7) Thanks [@jsoref](https://github.com/jsoref)! - Spelling fixes
38
+
39
+ ## 12.3.2
40
+
41
+ ### Patch Changes
42
+
43
+ - [#215](https://github.com/primer/stylelint-config/pull/215) [`66b16ae`](https://github.com/primer/stylelint-config/commit/66b16ae2edd81f8c8949f83c96d7011e5d395cc0) Thanks [@jonrohan](https://github.com/jonrohan)! - Making linter pick up separate function groups
44
+
45
+ ## 12.3.1
46
+
47
+ ### Patch Changes
48
+
49
+ - [#213](https://github.com/primer/stylelint-config/pull/213) [`2a27f86`](https://github.com/primer/stylelint-config/commit/2a27f86868b1f4717100a1f0897cdaefb1dd6be7) Thanks [@jonrohan](https://github.com/jonrohan)! - Fixing an issue where the new spacing plugin isn't traversing child sectors.
50
+
51
+ ## 12.3.0
52
+
53
+ ### Minor Changes
54
+
55
+ - [#191](https://github.com/primer/stylelint-config/pull/191) [`71c7985`](https://github.com/primer/stylelint-config/commit/71c79853b679b674c1d27686f8d2168660b24a45) Thanks [@jonrohan](https://github.com/jonrohan)! - Refactoring the primer/spacing plugin to better match results
56
+
57
+ ## 12.2.0
58
+
59
+ ### Minor Changes
60
+
61
+ - [#170](https://github.com/primer/stylelint-config/pull/170) [`b56fcd1`](https://github.com/primer/stylelint-config/commit/b56fcd1bce90d2e3e1621ef7af7545c52c935579) Thanks [@jonrohan](https://github.com/jonrohan)! - Moving config from primer/css's [stylelint.config.cjs](https://github.com/primer/css/blob/c65be7f0c8b0fb6e1ba406b5d35c6073df161a33/stylelint.config.cjs) file to this package.
62
+
63
+ * [#168](https://github.com/primer/stylelint-config/pull/168) [`d6ff2b9`](https://github.com/primer/stylelint-config/commit/d6ff2b94ff0d309c1b79e783e6ee1b2f87a375ff) Thanks [@jonrohan](https://github.com/jonrohan)! - Extending stylelint-config-standard and removing defaults
64
+
65
+ - [#170](https://github.com/primer/stylelint-config/pull/170) [`b56fcd1`](https://github.com/primer/stylelint-config/commit/b56fcd1bce90d2e3e1621ef7af7545c52c935579) Thanks [@jonrohan](https://github.com/jonrohan)! - Adding config from the [stylelint-scss recommended config](https://github.com/stylelint-scss/stylelint-config-recommended-scss/blob/82d51c399ddaa2f9d282e419399dd2028f47830c/index.js).
66
+
67
+ ### Patch Changes
68
+
69
+ - [#181](https://github.com/primer/stylelint-config/pull/181) [`23e438a`](https://github.com/primer/stylelint-config/commit/23e438a7a9062550baa696cafbb186dc78b723f5) Thanks [@jonrohan](https://github.com/jonrohan)! - Turning off scss/dollar-variable-default
70
+
71
+ ## 12.1.1
72
+
73
+ ### Patch Changes
74
+
75
+ - [#161](https://github.com/primer/stylelint-config/pull/161) [`48c4afc`](https://github.com/primer/stylelint-config/commit/48c4afc1913863136d62967653697323f8da57b7) Thanks [@dependabot](https://github.com/apps/dependabot)! - Bump @primer/primitives from 6.1.0 to 7.0.1
76
+
77
+ ## 12.1.0
78
+
79
+ ### Minor Changes
80
+
81
+ - [#150](https://github.com/primer/stylelint-config/pull/150) [`4af1647`](https://github.com/primer/stylelint-config/commit/4af16474148d96fba5567068280a9ffe6e7a80ba) Thanks [@jonrohan](https://github.com/jonrohan)! - Making all be first in property order
82
+
83
+ * [#151](https://github.com/primer/stylelint-config/pull/151) [`d7c8b2b`](https://github.com/primer/stylelint-config/commit/d7c8b2b908b113fa14c7637dfced34610a3bcfac) Thanks [@jonrohan](https://github.com/jonrohan)! - Adding [string-quotes](https://stylelint.io/user-guide/rules/list/string-quotes) rule to config
84
+
85
+ ### Patch Changes
86
+
87
+ - [#146](https://github.com/primer/stylelint-config/pull/146) [`214362c`](https://github.com/primer/stylelint-config/commit/214362c0e3c9449a5ff7d3bd047018493043d3c0) Thanks [@dependabot](https://github.com/apps/dependabot)! - Bump @primer/css from 13.2.0 to 16.3.0
88
+
89
+ ## 12.0.1
90
+
91
+ ### Patch Changes
92
+
93
+ - [#132](https://github.com/primer/stylelint-config/pull/132) [`b672367`](https://github.com/primer/stylelint-config/commit/b6723679606bb8d39e75025ae17ace9f1c3e2631) Thanks [@jonrohan](https://github.com/jonrohan)! - Updating no-deprecated-colors plugin for edge cases
94
+
95
+ ## 12.0.0
96
+
97
+ ### Major Changes
98
+
99
+ - [#129](https://github.com/primer/stylelint-config/pull/129) [`653d596`](https://github.com/primer/stylelint-config/commit/653d596072b897b265b093aac4cd5c143e61410e) Thanks [@jonrohan](https://github.com/jonrohan)! - Renaming the package to use org scope. This is a breaking change, you'll need to uninstall `stylelint-config-primer` and reinstall `@primer/stylelint-config`.
100
+
101
+ ### Patch Changes
102
+
103
+ - [#130](https://github.com/primer/stylelint-config/pull/130) [`f495a56`](https://github.com/primer/stylelint-config/commit/f495a563a9e809252630466088eb94177e6c0be4) Thanks [@jonrohan](https://github.com/jonrohan)! - Updating @primer/primitives to 5.0 release candidate
104
+
105
+ ## 11.1.1
106
+
107
+ ### Patch Changes
108
+
109
+ - [`3a4654b`](https://github.com/primer/stylelint-config/commit/3a4654b1b7920d71e1284ff78a3bedff932e66a3) [#111](https://github.com/primer/stylelint-config/pull/111) Thanks [@jonrohan](https://github.com/jonrohan)! - Fixing the primer/colors and primer/borders rules
110
+
111
+ ## 11.1.0
112
+
113
+ ### Minor Changes
114
+
115
+ - [`e83f61c`](https://github.com/primer/stylelint-config/commit/e83f61cef3bf1df1d9420662594040efdcb86c89) [#99](https://github.com/primer/stylelint-config/pull/99) Thanks [@jonrohan](https://github.com/jonrohan)! - Create a `no-deprecated-colors` rule that looks for deprecated css color variables from primer/primitives.
116
+
117
+ ### Patch Changes
118
+
119
+ - [`581f40a`](https://github.com/primer/stylelint-config/commit/581f40a4aacb45db5426b82d4a2434e81eb032e2) [#105](https://github.com/primer/stylelint-config/pull/105) Thanks [@jonrohan](https://github.com/jonrohan)! - Adding reporting to the linter to know how many variables are replaced
120
+
121
+ ## 10.0.1
122
+
123
+ ### Patch Changes
124
+
125
+ - [`aa76171`](https://github.com/primer/stylelint-config/commit/aa76171fc5c9c308fcd9d7f7285c8fbdb2c18a7b) [#90](https://github.com/primer/stylelint-config/pull/90) Thanks [@jonrohan](https://github.com/jonrohan)! - Updating the no-undefined-variables lint for the new color-variables mixin.
126
+
127
+ ## 10.0.0
128
+
129
+ ### Major Changes
130
+
131
+ - [`23a1f15`](https://github.com/primer/stylelint-config/commit/23a1f1599673f2a4f9f28c39da61f42871c05697) [#85](https://github.com/primer/stylelint-config/pull/85) Thanks [@koddsson](https://github.com/koddsson)! - Replace deprecated "blacklist" rules for "disallow list" rules.
132
+
133
+ See https://stylelint.io/user-guide/rules/at-rule-blacklist and http://stylelint.io/user-guide/rules/declaration-property-value-disallowed-list/
134
+
135
+ ### Patch Changes
136
+
137
+ - [`40d9bb8`](https://github.com/primer/stylelint-config/commit/40d9bb867194ae4335846953b5d8706dc7dc7d79) [#86](https://github.com/primer/stylelint-config/pull/86) Thanks [@koddsson](https://github.com/koddsson)! - Allow rules to optionally display a URL with their message.
138
+
139
+ ## 9.3.3
140
+
141
+ ### Patch Changes
142
+
143
+ - [`a339c69`](https://github.com/primer/stylelint-config/commit/a339c698b9ba7ccd01b8cb773dad7a3a14dd13a1) [#81](https://github.com/primer/stylelint-config/pull/81) Thanks [@BinaryMuse](https://github.com/BinaryMuse)! - Update globby to v11
144
+
145
+ ## 9.3.2
146
+
147
+ ### Patch Changes
148
+
149
+ - [`d18cfbf`](https://github.com/primer/stylelint-config/commit/d18cfbfefc25be6ae38f73132552d2f3c62c4d02) [#79](https://github.com/primer/stylelint-config/pull/79) Thanks [@BinaryMuse](https://github.com/BinaryMuse)! - Add additional verbose logging to `no-undefined-vars`
150
+
151
+ * [`d18cfbf`](https://github.com/primer/stylelint-config/commit/d18cfbfefc25be6ae38f73132552d2f3c62c4d02) [#79](https://github.com/primer/stylelint-config/pull/79) Thanks [@BinaryMuse](https://github.com/BinaryMuse)! - Fix handling of edge-cases in `no-undefined-vars`
152
+
153
+ - [`bb07673`](https://github.com/primer/stylelint-config/commit/bb076732aa216fcb56e411b8dd7477efc89f7f8a) [#76](https://github.com/primer/stylelint-config/pull/76) Thanks [@BinaryMuse](https://github.com/BinaryMuse)! - Set the default verbose option for `no-scale-colors` to false
154
+
155
+ ## 9.3.1
156
+
157
+ ### Patch Changes
158
+
159
+ - [`df11e2d`](https://github.com/primer/stylelint-config/commit/df11e2d912913346e0499f7eac901cdfcb83f38c) [#74](https://github.com/primer/stylelint-config/pull/74) Thanks [@BinaryMuse](https://github.com/BinaryMuse)! - Add primer/no-scale-colors to the list of exported plugins
160
+
161
+ ## 9.2.1
162
+
163
+ ### :bug: Bug fixes
164
+
165
+ - Fix slow runtime by caching variable definitions in `primer/no-undefined-vars` rule
166
+ - Fix duplicate errors in `primer/no-undefined-vars` rule
167
+
168
+ ## 9.2.0
169
+
170
+ ### :rocket: Enhancements
171
+
172
+ - New `primer/no-undefined-vars` to prohibit usages of undefined CSS variables
173
+
174
+ ## 9.1.0
175
+
176
+ ### :rocket: Enhancements
177
+
178
+ - The `primer/colors`, `primer/borders`, and `primer/box-shadow` rules now allow CSS color variables with the correct functional names (e.g. `var(--color-text-primary)`). #62
179
+
180
+ ## 9.0.0
181
+
182
+ ### :boom: Breaking Change
183
+
184
+ - `primer/variables` is no longer supported; please use the `primer/colors`, `primer/borders`, `primer/box-shadow`, `primer/spacing`, and `primer/typography` rules instead. #50
185
+
186
+ ### :rocket: Enhancements
187
+
188
+ - The new `primer/colors` rule enforces color variable usage in `color`, `background-color`, and `fill` properties
189
+ - The new `primer/borders` rule enforces border variable usage in border CSS props
190
+ - The new `primer/box-shadow` rule enforces `$box-shadow*` variables
191
+ - The new `primer/spacing` rule enforces `$spacer-*` variables in margin and padding props
192
+ - The new `primer/typography` rule enforces typography variable use in `font-family`, `line-height`, and `font-weight` props
193
+ - Variable replacements for autofixing are automatically detected in variable data from Primer CSS (see: https://github.com/primer/css/pull/949) #52
194
+ - It is now possible to define variable rules using functions that take the variables, as in:
195
+ ```js
196
+ module.exports = createVariableRule('primer/whatever', ({variables}) => {
197
+ /* do something with variables here */
198
+ })
199
+ ```
200
+ - It's also now possible to provide rule _overrides_ in local stylelint configs as functions:
201
+ ```js
202
+ module.exports = {
203
+ extends: '@primer/stylelint-config',
204
+ rules: {
205
+ 'primer/colors': [true, {
206
+ rules: ({variables, rules}) => {
207
+ /* do something with variables and/or rules here */
208
+ return rules
209
+ }]
210
+ }
211
+ })
212
+ ```
213
+ - This release adds support for an optional `singular: true` flag to rule configs, which skips the parsing of individual values in the matched properties. We use this in `primer/box-shadow` to prevent multiple warnings for a single value like `box-shadow: inset 0 1px $blue` (before there would be 4 separate ones!).
214
+
215
+ ### :bug: Bug fixes
216
+
217
+ - Use `requirePrimerFile()` when loading `dist/variables.json` so that we can access the right file when running _within_ the `@primer/css` repo.
218
+ - Walk only declarations (`prop: value`) in rules (blocks with selectors, _not_ `@rules`), and skip linting for declarations nested in `@each`, `@for`, `@function`, and `@mixin` blocks, since those can define their own variables and we can't reliably assert their values.
219
+ - Allow `$*-shadow` variable patterns in `primer/box-shadow` to match `$btn-active-shadow` and `$form-control-shadow`
220
+ - Allow `color: inherit` in `primer/colors`
221
+ - Allow `$em-spacer-*` in `padding` and `margin` properties
222
+ - Allow (and auto-fix!) negative spacer variables in `margin` properties
223
+ - Make `primer/colors` smarter re: `background` property shorthand values (allowing positions and image `url(*)` values)
224
+ - Remove `100%` from allowed values for `border-radius`, and suggest `50%` instead
225
+ - Prohibit negative spacer values in `padding` properties
226
+ - Allow `$h000-size` for marketing 😬
227
+
228
+ ## 2.0.0
229
+
230
+ :boom: **The following updates are breaking changes**, since code that disables the deprecated rule will now produce linting errors. Please update your `stylelint-disable` statements accordingly.
231
+
232
+ - Replaced `selector-no-id: true` with `selector-max-id: 0`
233
+ - Replaced `selector-no-type: true` with `selector-max-type: 0`
234
+
235
+ The rest of the changes should not introduce new linting errors:
236
+
237
+ - Updated: moved [browserslist](https://github.com/ai/browserslist) spec to `package.json`
238
+ - Updated: using the [`no-unsupported-browser-features` plugin](https://github.com/ismay/stylelint-no-unsupported-browser-features) instead of the deprecated `no-unsupported-browser-features` rule
239
+ - Removed: `media-feature-no-missing-punctuation`
240
+ - Updated: replaced `rule-nested-empty-line-before` and `rule-non-nested-empty-line-before` with `rule-empty-line-before`
241
+
242
+ ## 1.4.0
243
+
244
+ - Updated: Development dependencies are any version `*`
245
+ - Removed: `selector-class-pattern` from config. https://github.com/primer/stylelint-config/pull/11
246
+
247
+ ## 1.3.0
248
+
249
+ - Added: `length-zero-no-unit` to disallow zero values with units eg `0px`
250
+
251
+ ## 1.2.0
252
+
253
+ - Removed: We don't need `scss/at-extend-no-missing-placeholder` anymore taken care of by `at-rule-blacklist`
254
+ - Added: Adding `selector-no-type` to the rules
255
+
256
+ ## 1.0.0
257
+
258
+ - Creating a sharable config object
package/README.md CHANGED
@@ -40,6 +40,7 @@ Primer Stylelint Config extends the [stylelint-config-standard](https://github.c
40
40
  - [primer/borders](./plugins/#primerborders): Enforces the use of certain variables for border properties.
41
41
  - [primer/box-shadow](./plugins/#primerbox-shadow): Enforces the use of certain variables for `box-shadow`.
42
42
  - [primer/responsive-widths](./plugins/#primerresponsive-widths): Errors on `width` and `min-width` that is larger than the minimum browser size supported. `320px`
43
+ - [primer/utilities](./plugins/#primerutilities): Errors when someone writes custom CSS for a declaration that has an existing primer/css/utility.
43
44
 
44
45
  ## License
45
46
 
package/index.js CHANGED
@@ -9,17 +9,18 @@ module.exports = {
9
9
  'stylelint-no-unsupported-browser-features',
10
10
  'stylelint-order',
11
11
  'stylelint-scss',
12
- './plugins/no-override',
13
- './plugins/no-deprecated-colors',
14
- './plugins/no-unused-vars',
15
- './plugins/no-undefined-vars',
16
- './plugins/no-scale-colors',
17
12
  './plugins/borders',
18
13
  './plugins/box-shadow',
19
14
  './plugins/colors',
15
+ './plugins/no-deprecated-colors',
16
+ './plugins/no-override',
17
+ './plugins/no-scale-colors',
18
+ './plugins/no-undefined-vars',
19
+ './plugins/no-unused-vars',
20
20
  './plugins/responsive-widths',
21
21
  './plugins/spacing',
22
- './plugins/typography'
22
+ './plugins/typography',
23
+ './plugins/utilities'
23
24
  ],
24
25
  rules: {
25
26
  'alpha-value-notation': 'number',
@@ -69,6 +70,7 @@ module.exports = {
69
70
  'primer/responsive-widths': true,
70
71
  'primer/spacing': true,
71
72
  'primer/typography': true,
73
+ 'primer/utilities': null,
72
74
  'scss/at-extend-no-missing-placeholder': true,
73
75
  'scss/at-rule-no-unknown': true,
74
76
  'scss/declaration-nested-properties-no-divided-groups': true,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@primer/stylelint-config",
3
- "version": "12.4.2",
3
+ "version": "12.5.0-rc.d5df50d",
4
4
  "description": "Sharable stylelint config used by GitHub's CSS",
5
5
  "homepage": "http://primer.style/css/tools/linting",
6
6
  "author": "GitHub, Inc.",
@@ -39,19 +39,19 @@
39
39
  "tap-map": "^1.0.0"
40
40
  },
41
41
  "devDependencies": {
42
- "@changesets/changelog-github": "0.4.3",
42
+ "@changesets/changelog-github": "0.4.4",
43
43
  "@changesets/cli": "2.22.0",
44
44
  "@github/prettier-config": "0.0.4",
45
- "@primer/css": "^19.0.0",
45
+ "@primer/css": "^20.0.0",
46
46
  "@primer/primitives": "^7.0.1",
47
47
  "dedent": "0.7.0",
48
- "eslint": "8.11.0",
48
+ "eslint": "8.14.0",
49
49
  "eslint-plugin-github": "4.3.5",
50
- "eslint-plugin-jest": "26.1.3",
50
+ "eslint-plugin-jest": "26.1.5",
51
51
  "eslint-plugin-prettier": "4.0.0",
52
52
  "jest": "27.5.1",
53
53
  "jest-preset-stylelint": "5.0.1",
54
- "prettier": "2.6.0"
54
+ "prettier": "2.6.2"
55
55
  },
56
56
  "jest": {
57
57
  "preset": "jest-preset-stylelint",
package/plugins/README.md CHANGED
@@ -18,6 +18,7 @@ This directory contains all of our custom stylelint plugins, each of which provi
18
18
  - [`primer/borders`](#primerborders)
19
19
  - [`primer/box-shadow`](#primerbox-shadow)
20
20
  - [`primer/responsive-widths`](#primerresponsive-widths)
21
+ - [`primer/utilities`](#primerutilities)
21
22
  - [Variable rules](#variable-rules)
22
23
  - [Variable rule options](#variable-rule-options)
23
24
 
@@ -212,6 +213,31 @@ This [variable rule](#variable-rules) enforces the use of `$box-shadow*` variabl
212
213
 
213
214
  This plugin checks for `width` and `min-width` declarations that use a value less than the minimum browser size. `320px`
214
215
 
216
+ ## `primer/utilities`
217
+
218
+ Checks for selectors with single declarations that can be replaced with [primer/css utilities](https://primer.style/css/utilities/).
219
+
220
+ ```scss
221
+ .foo {
222
+ color: var(--color-fg-default);
223
+ }
224
+ /** ↑
225
+ * FAIL: --color-fg-default can be replaced with .color-fg-default */
226
+
227
+ .foo {
228
+ color: #custom;
229
+ }
230
+ /** ↑
231
+ * OK: Color value doesn't match a utility. */
232
+
233
+ .foo {
234
+ color: var(--color-fg-default);
235
+ padding: 0;
236
+ }
237
+ /** ↑
238
+ * OK: Has more than one declaration, not considered */
239
+ ```
240
+
215
241
  ## Variable rules
216
242
 
217
243
  Variable rules are created using a general-purpose helper that can validate constraints for matching CSS properties and values. In general, the Primer CSS variable rules enforce two basic principles for custom CSS:
@@ -0,0 +1,526 @@
1
+ // Meant as temp until we can move to primitives or css
2
+ const colorTypes = ['accent', 'success', 'attention', 'severe', 'danger', 'open', 'closed', 'done', 'sponsors']
3
+
4
+ module.exports = {
5
+ color: [
6
+ {
7
+ value: 'var(--color-fg-default)',
8
+ utilityClass: 'color-fg-default'
9
+ },
10
+ {
11
+ value: 'var(--color-fg-muted)',
12
+ utilityClass: 'color-fg-muted'
13
+ },
14
+ {
15
+ value: 'var(--color-fg-subtle)',
16
+ utilityClass: 'color-fg-subtle'
17
+ }
18
+ ].concat(
19
+ colorTypes.map(type => {
20
+ return {
21
+ value: `var(--color-${type}-fg)`,
22
+ utilityClass: `color-fg-${type}`
23
+ }
24
+ })
25
+ ),
26
+ 'background-color': [
27
+ {
28
+ value: 'var(--color-canvas-default)',
29
+ utilityClass: 'color-bg-default'
30
+ },
31
+ {
32
+ value: 'var(--color-canvas-overlay)',
33
+ utilityClass: 'color-bg-overlay'
34
+ },
35
+ {
36
+ value: 'var(--color-canvas-inset)',
37
+ utilityClass: 'color-bg-inset'
38
+ },
39
+ {
40
+ value: 'var(--color-canvas-subtle)',
41
+ utilityClass: 'color-bg-subtle'
42
+ },
43
+ {
44
+ value: 'transparent',
45
+ utilityClass: 'color-bg-transparent'
46
+ }
47
+ ]
48
+ .concat(
49
+ colorTypes.map(type => {
50
+ return {
51
+ value: `var(--color-${type}-subtle)`,
52
+ utilityClass: `color-bg-${type}`
53
+ }
54
+ })
55
+ )
56
+ .concat(
57
+ colorTypes.map(type => {
58
+ return {
59
+ value: `var(--color-${type}-emphasis)`,
60
+ utilityClass: `color-bg-${type}-emphasis`
61
+ }
62
+ })
63
+ ),
64
+ 'border-color': [
65
+ {
66
+ value: 'var(--color-border-default',
67
+ utilityClass: 'color-border-default'
68
+ },
69
+ {
70
+ value: 'var(--color-border-muted',
71
+ utilityClass: 'color-border-muted'
72
+ },
73
+ {
74
+ value: 'var(--color-border-subtle',
75
+ utilityClass: 'color-border-subtle'
76
+ }
77
+ ]
78
+ .concat(
79
+ colorTypes.map(type => {
80
+ return {
81
+ value: `var(--color-${type}-muted)`,
82
+ utilityClass: `color-border-${type}`
83
+ }
84
+ })
85
+ )
86
+ .concat(
87
+ colorTypes.map(type => {
88
+ return {
89
+ value: `var(--color-${type}-emphasis)`,
90
+ utilityClass: `color-border-${type}-emphasis`
91
+ }
92
+ })
93
+ ),
94
+ margin: Array.from(new Array(6)).map((_, i) => {
95
+ return {
96
+ value: `$spacer-${i + 1}`,
97
+ utilityClass: `m-${i + 1}`
98
+ }
99
+ }),
100
+ 'margin-top': Array.from(new Array(6)).map((_, i) => {
101
+ return {
102
+ value: `$spacer-${i + 1}`,
103
+ utilityClass: `mt-${i + 1}`
104
+ }
105
+ }),
106
+ 'margin-right': Array.from(new Array(6)).map((_, i) => {
107
+ return {
108
+ value: `$spacer-${i + 1}`,
109
+ utilityClass: `mr-${i + 1}`
110
+ }
111
+ }),
112
+ 'margin-bottom': Array.from(new Array(6)).map((_, i) => {
113
+ return {
114
+ value: `$spacer-${i + 1}`,
115
+ utilityClass: `mb-${i + 1}`
116
+ }
117
+ }),
118
+ 'margin-left': Array.from(new Array(6)).map((_, i) => {
119
+ return {
120
+ value: `$spacer-${i + 1}`,
121
+ utilityClass: `ml-${i + 1}`
122
+ }
123
+ }),
124
+ padding: Array.from(new Array(6)).map((_, i) => {
125
+ return {
126
+ value: `$spacer-${i + 1}`,
127
+ utilityClass: `p-${i + 1}`
128
+ }
129
+ }),
130
+ 'padding-top': Array.from(new Array(6)).map((_, i) => {
131
+ return {
132
+ value: `$spacer-${i + 1}`,
133
+ utilityClass: `pt-${i + 1}`
134
+ }
135
+ }),
136
+ 'padding-right': Array.from(new Array(6)).map((_, i) => {
137
+ return {
138
+ value: `$spacer-${i + 1}`,
139
+ utilityClass: `pr-${i + 1}`
140
+ }
141
+ }),
142
+ 'padding-bottom': Array.from(new Array(6)).map((_, i) => {
143
+ return {
144
+ value: `$spacer-${i + 1}`,
145
+ utilityClass: `pb-${i + 1}`
146
+ }
147
+ }),
148
+ 'padding-left': Array.from(new Array(6)).map((_, i) => {
149
+ return {
150
+ value: `$spacer-${i + 1}`,
151
+ utilityClass: `pl-${i + 1}`
152
+ }
153
+ }),
154
+ 'line-height': [
155
+ {
156
+ value: '$lh-condensed-ultra',
157
+ utilityClass: 'lh-condensed-ultra'
158
+ },
159
+ {
160
+ value: '$lh-condensed',
161
+ utilityClass: 'lh-condensed'
162
+ },
163
+ {
164
+ value: '$lh-default',
165
+ utilityClass: 'lh-default'
166
+ },
167
+ {
168
+ value: '0',
169
+ utilityClass: 'lh-0'
170
+ }
171
+ ],
172
+ 'text-align': [
173
+ {
174
+ value: 'left',
175
+ utilityClass: 'text-left'
176
+ },
177
+ {
178
+ value: 'right',
179
+ utilityClass: 'text-right'
180
+ },
181
+ {
182
+ value: 'center',
183
+ utilityClass: 'text-center'
184
+ }
185
+ ],
186
+ 'font-style': [
187
+ {
188
+ value: 'italic',
189
+ utilityClass: 'text-italic'
190
+ }
191
+ ],
192
+ 'text-transform': [
193
+ {
194
+ value: 'uppercase',
195
+ utilityClass: 'text-uppercase'
196
+ }
197
+ ],
198
+ 'text-decoration': [
199
+ {
200
+ value: 'underline',
201
+ utilityClass: 'text-underline'
202
+ },
203
+ {
204
+ value: 'none',
205
+ utilityClass: 'no-underline'
206
+ }
207
+ ],
208
+ 'white-space': [
209
+ {
210
+ value: 'nowrap',
211
+ utilityClass: 'no-wrap'
212
+ },
213
+ {
214
+ value: 'normal',
215
+ utilityClass: 'ws-normal'
216
+ }
217
+ ],
218
+ 'word-break': [
219
+ {
220
+ value: 'break-all',
221
+ utilityClass: 'wb-break-all'
222
+ }
223
+ ],
224
+ width: [
225
+ {
226
+ value: '100%',
227
+ utilityClass: 'width-full'
228
+ },
229
+ {
230
+ value: 'auto%',
231
+ utilityClass: 'width-auto'
232
+ }
233
+ ],
234
+ overflow: [
235
+ {
236
+ value: 'visible',
237
+ utilityClass: 'overflow-visible'
238
+ },
239
+ {
240
+ value: 'hidden',
241
+ utilityClass: 'overflow-hidden'
242
+ },
243
+ {
244
+ value: 'auto',
245
+ utilityClass: 'overflow-auto'
246
+ },
247
+ {
248
+ value: 'scroll',
249
+ utilityClass: 'overflow-scroll'
250
+ }
251
+ ],
252
+ 'overflow-x': [
253
+ {
254
+ value: 'visible',
255
+ utilityClass: 'overflow-x-visible'
256
+ },
257
+ {
258
+ value: 'hidden',
259
+ utilityClass: 'overflow-x-hidden'
260
+ },
261
+ {
262
+ value: 'auto',
263
+ utilityClass: 'overflow-x-auto'
264
+ },
265
+ {
266
+ value: 'scroll',
267
+ utilityClass: 'overflow-x-scroll'
268
+ }
269
+ ],
270
+ 'overflow-y': [
271
+ {
272
+ value: 'visible',
273
+ utilityClass: 'overflow-y-visible'
274
+ },
275
+ {
276
+ value: 'hidden',
277
+ utilityClass: 'overflow-y-hidden'
278
+ },
279
+ {
280
+ value: 'auto',
281
+ utilityClass: 'overflow-y-auto'
282
+ },
283
+ {
284
+ value: 'scroll',
285
+ utilityClass: 'overflow-y-scroll'
286
+ }
287
+ ],
288
+ height: [
289
+ {
290
+ value: '100%',
291
+ utilityClass: 'height-full'
292
+ }
293
+ ],
294
+ 'max-width': [
295
+ {
296
+ value: '100%',
297
+ utilityClass: 'width-fit'
298
+ }
299
+ ],
300
+ 'max-height': [
301
+ {
302
+ value: '100%',
303
+ utilityClass: 'height-fit'
304
+ }
305
+ ],
306
+ 'min-width': [
307
+ {
308
+ value: '0',
309
+ utilityClass: 'min-width-0'
310
+ }
311
+ ],
312
+ float: [
313
+ {
314
+ value: 'left',
315
+ utilityClass: 'float-left'
316
+ },
317
+ {
318
+ value: 'right',
319
+ utilityClass: 'float-right'
320
+ },
321
+ {
322
+ value: 'none',
323
+ utilityClass: 'float-none'
324
+ }
325
+ ],
326
+ 'list-style': [
327
+ {
328
+ value: 'none',
329
+ utilityClass: 'list-style-none'
330
+ }
331
+ ],
332
+ 'user-select': [
333
+ {
334
+ value: 'none',
335
+ utilityClass: 'user-select-none'
336
+ }
337
+ ],
338
+ visibility: [
339
+ {
340
+ value: 'hidden',
341
+ utilityClass: 'v-hidden'
342
+ },
343
+ {
344
+ value: 'visible',
345
+ utilityClass: 'v-visible'
346
+ }
347
+ ],
348
+ 'vertical-align': [
349
+ {
350
+ value: 'middle',
351
+ utilityClass: 'v-align-middle'
352
+ },
353
+ {
354
+ value: 'top',
355
+ utilityClass: 'v-align-top'
356
+ },
357
+ {
358
+ value: 'bottom',
359
+ utilityClass: 'v-align-bottom'
360
+ },
361
+ {
362
+ value: 'text-top',
363
+ utilityClass: 'v-align-text-top'
364
+ },
365
+ {
366
+ value: 'text-bottom',
367
+ utilityClass: 'v-align-text-bottom'
368
+ },
369
+ {
370
+ value: 'text-baseline',
371
+ utilityClass: 'v-align-baseline'
372
+ }
373
+ ],
374
+ 'font-weight': [
375
+ {
376
+ value: '$font-weight-normal',
377
+ utilityClass: 'text-normal'
378
+ },
379
+ {
380
+ value: '$font-weight-bold',
381
+ utilityClass: 'text-bold'
382
+ },
383
+ {
384
+ value: '$font-weight-semibold',
385
+ utilityClass: 'text-semibold'
386
+ },
387
+ {
388
+ value: '$font-weight-light',
389
+ utilityClass: 'text-light'
390
+ }
391
+ ],
392
+ top: [
393
+ {
394
+ value: '0',
395
+ utilityClass: 'top-0'
396
+ },
397
+ {
398
+ value: 'auto',
399
+ utilityClass: 'top-auto'
400
+ }
401
+ ],
402
+ right: [
403
+ {
404
+ value: '0',
405
+ utilityClass: 'right-0'
406
+ },
407
+ {
408
+ value: 'auto',
409
+ utilityClass: 'right-auto'
410
+ }
411
+ ],
412
+ bottom: [
413
+ {
414
+ value: '0',
415
+ utilityClass: 'bottom-0'
416
+ },
417
+ {
418
+ value: 'auto',
419
+ utilityClass: 'bottom-auto'
420
+ }
421
+ ],
422
+ left: [
423
+ {
424
+ value: '0',
425
+ utilityClass: 'left-0'
426
+ },
427
+ {
428
+ value: 'auto',
429
+ utilityClass: 'left-auto'
430
+ }
431
+ ],
432
+ position: [
433
+ {
434
+ value: 'static',
435
+ utilityClass: 'position-static'
436
+ },
437
+ {
438
+ value: 'relative',
439
+ utilityClass: 'position-relative'
440
+ },
441
+ {
442
+ value: 'absolute',
443
+ utilityClass: 'position-absolute'
444
+ },
445
+ {
446
+ value: 'fixed',
447
+ utilityClass: 'position-fixed'
448
+ },
449
+ {
450
+ value: 'sticky',
451
+ utilityClass: 'position-sticky'
452
+ }
453
+ ],
454
+ 'box-shadow': [
455
+ {
456
+ value: 'none',
457
+ utilityClass: 'box-shadow-none'
458
+ },
459
+ {
460
+ value: 'var(--color-shadow-small)',
461
+ utilityClass: 'box-shadow-small'
462
+ },
463
+ {
464
+ value: 'var(--color-shadow-medium)',
465
+ utilityClass: 'box-shadow-medium'
466
+ },
467
+ {
468
+ value: 'var(--color-shadow-large)',
469
+ utilityClass: 'box-shadow-large'
470
+ },
471
+ {
472
+ value: 'var(--color-shadow-extra-large)',
473
+ utilityClass: 'box-shadow-extra-large'
474
+ }
475
+ ],
476
+ border: [
477
+ {
478
+ value: '$border',
479
+ utilityClass: 'border'
480
+ },
481
+ {
482
+ value: '0',
483
+ utilityClass: 'border-0'
484
+ }
485
+ ],
486
+ 'border-top': [
487
+ {
488
+ value: '$border',
489
+ utilityClass: 'border-top'
490
+ },
491
+ {
492
+ value: '0',
493
+ utilityClass: 'border-top-0'
494
+ }
495
+ ],
496
+ 'border-right': [
497
+ {
498
+ value: '$border',
499
+ utilityClass: 'border-right'
500
+ },
501
+ {
502
+ value: '0',
503
+ utilityClass: 'border-right-0'
504
+ }
505
+ ],
506
+ 'border-bottom': [
507
+ {
508
+ value: '$border',
509
+ utilityClass: 'border-bottom'
510
+ },
511
+ {
512
+ value: '0',
513
+ utilityClass: 'border-bottom-0'
514
+ }
515
+ ],
516
+ 'border-left': [
517
+ {
518
+ value: '$border',
519
+ utilityClass: 'border-left'
520
+ },
521
+ {
522
+ value: '0',
523
+ utilityClass: 'border-left-0'
524
+ }
525
+ ]
526
+ }
@@ -0,0 +1,55 @@
1
+ const stylelint = require('stylelint')
2
+ const utilities = require('./lib/primer-utilities')
3
+
4
+ const ruleName = 'primer/utilities'
5
+
6
+ const messages = stylelint.utils.ruleMessages(ruleName, {
7
+ rejected: (selector, utilityClass) => {
8
+ return `Consider using the Primer utility '.${utilityClass}' instead of the selector '${selector}' in your html. https://primer.style/css/utilities`
9
+ }
10
+ })
11
+
12
+ // eslint-disable-next-line no-unused-vars
13
+ module.exports = stylelint.createPlugin(ruleName, (enabled, options = {}, context) => {
14
+ if (!enabled) {
15
+ return noop
16
+ }
17
+
18
+ const utilityReplacement = (declaration, value) => {
19
+ const declarationUtilities = utilities[declaration]
20
+ if (declarationUtilities) {
21
+ return declarationUtilities.find(utility => {
22
+ return utility.value === value
23
+ })
24
+ }
25
+ }
26
+
27
+ const lintResult = (root, result) => {
28
+ root.walkRules(rule => {
29
+ if (!/^\.[\w\-_]+$/.exec(rule.selector)) {
30
+ return false
31
+ }
32
+ const decls = rule.nodes.filter(decl => decl.type === 'decl')
33
+
34
+ if (decls.length === 1) {
35
+ const replacement = utilityReplacement(decls[0].prop, decls[0].value)
36
+ if (replacement) {
37
+ stylelint.utils.report({
38
+ index: rule.sourceIndex,
39
+ message: messages.rejected(rule.selector, replacement.utilityClass),
40
+ node: rule,
41
+ result,
42
+ ruleName
43
+ })
44
+ }
45
+ }
46
+ })
47
+ }
48
+
49
+ return lintResult
50
+ })
51
+
52
+ function noop() {}
53
+
54
+ module.exports.ruleName = ruleName
55
+ module.exports.messages = messages