@primer/stylelint-config 12.8.0 → 12.9.0-rc.ea3b36b

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/index.js CHANGED
@@ -22,6 +22,7 @@ module.exports = {
22
22
  './plugins/spacing',
23
23
  './plugins/typography',
24
24
  './plugins/utilities',
25
+ './plugins/new-color-vars-have-fallback',
25
26
  ],
26
27
  rules: {
27
28
  'alpha-value-notation': 'number',
@@ -75,6 +76,7 @@ module.exports = {
75
76
  'primer/spacing': true,
76
77
  'primer/typography': true,
77
78
  'primer/utilities': null,
79
+ 'primer/new-color-vars-have-fallback': [true, {severity: 'error'}],
78
80
  'scss/at-extend-no-missing-placeholder': true,
79
81
  'scss/at-rule-no-unknown': true,
80
82
  '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.8.0",
3
+ "version": "12.9.0-rc.ea3b36b",
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.",
@@ -41,9 +41,9 @@
41
41
  "@changesets/changelog-github": "0.4.7",
42
42
  "@changesets/cli": "2.26.1",
43
43
  "@github/prettier-config": "0.0.6",
44
- "@primer/css": "^20.0.0",
44
+ "@primer/css": "^21.0.8",
45
45
  "@primer/primitives": "^7.11.11",
46
- "dedent": "0.7.0",
46
+ "dedent": "1.5.1",
47
47
  "eslint": "8.39.0",
48
48
  "eslint-plugin-github": "4.8.0",
49
49
  "eslint-plugin-jest": "27.2.3",
@@ -0,0 +1,52 @@
1
+ const stylelint = require('stylelint')
2
+
3
+ const ruleName = 'primer/new-color-vars-have-fallback'
4
+ const messages = stylelint.utils.ruleMessages(ruleName, {
5
+ expectedFallback: variable =>
6
+ `Expected a fallback value for CSS variable ${variable}. New color variables fallbacks, check primer.style/primitives to find the correct value`,
7
+ })
8
+
9
+ const fs = require('fs')
10
+ const path = require('path')
11
+
12
+ const jsonFilePath = 'node_modules/@primer/primitives/tokens-next-private/docs/functional/themes/light.json'
13
+ let jsonContent
14
+
15
+ try {
16
+ const fileContent = fs.readFileSync(path.resolve(jsonFilePath), 'utf8')
17
+ jsonContent = JSON.parse(fileContent)
18
+ // console.log('JSON content:', jsonContent) // Log to see the content
19
+ } catch (error) {
20
+ // eslint-disable-next-line no-console
21
+ console.error('Error reading JSON file:', error)
22
+ }
23
+
24
+ module.exports = stylelint.createPlugin(ruleName, enabled => {
25
+ if (!enabled) {
26
+ return noop
27
+ }
28
+
29
+ return (root, result) => {
30
+ root.walkDecls(decl => {
31
+ for (const key of Object.keys(jsonContent)) {
32
+ if (decl.value.includes(`var(--${key})`)) {
33
+ // Check if the declaration uses a CSS variable from the JSON
34
+ const match = decl.value.match(/var\(--\w+,(.*)\)/)
35
+ if (!match || match[1].trim() === '') {
36
+ stylelint.utils.report({
37
+ ruleName,
38
+ result,
39
+ node: decl,
40
+ message: messages.expectedFallback(`--${key}`),
41
+ })
42
+ }
43
+ }
44
+ }
45
+ })
46
+ }
47
+ })
48
+
49
+ function noop() {}
50
+
51
+ module.exports.ruleName = ruleName
52
+ module.exports.messages = messages