@primer/stylelint-config 12.9.1-rc.ec47914 → 12.9.2-rc.46fe2e1

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
@@ -23,6 +23,7 @@ module.exports = {
23
23
  './plugins/typography',
24
24
  './plugins/utilities',
25
25
  './plugins/new-color-vars-have-fallback',
26
+ './plugins/no-display-colors',
26
27
  ],
27
28
  rules: {
28
29
  'alpha-value-notation': 'number',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@primer/stylelint-config",
3
- "version": "12.9.1-rc.ec47914",
3
+ "version": "12.9.2-rc.46fe2e1",
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.",
@@ -0,0 +1,53 @@
1
+ const stylelint = require('stylelint')
2
+ const matchAll = require('string.prototype.matchall')
3
+
4
+ const ruleName = 'primer/no-display-colors'
5
+ const messages = stylelint.utils.ruleMessages(ruleName, {
6
+ rejected: varName => `${varName} is in alpha and should be used with caution with approval from the Primer team`,
7
+ })
8
+
9
+ // Match CSS variable references (e.g var(--display-blue-fgColor))
10
+ // eslint-disable-next-line no-useless-escape
11
+ const variableReferenceRegex = /var\(([^\),]+)(,.*)?\)/g
12
+
13
+ module.exports = stylelint.createPlugin(ruleName, (enabled, options = {}) => {
14
+ if (!enabled) {
15
+ return noop
16
+ }
17
+
18
+ const {verbose = false} = options
19
+ // eslint-disable-next-line no-console
20
+ const log = verbose ? (...args) => console.warn(...args) : noop
21
+
22
+ // Keep track of declarations we've already seen
23
+ const seen = new WeakMap()
24
+
25
+ return (root, result) => {
26
+ root.walkRules(rule => {
27
+ rule.walkDecls(decl => {
28
+ if (seen.has(decl)) {
29
+ return
30
+ } else {
31
+ seen.set(decl, true)
32
+ }
33
+
34
+ for (const [, variableName] of matchAll(decl.value, variableReferenceRegex)) {
35
+ log(`Found variable reference ${variableName}`)
36
+ if (variableName.match(/^--display-.*/)) {
37
+ stylelint.utils.report({
38
+ message: messages.rejected(variableName),
39
+ node: decl,
40
+ result,
41
+ ruleName,
42
+ })
43
+ }
44
+ }
45
+ })
46
+ })
47
+ }
48
+ })
49
+
50
+ function noop() {}
51
+
52
+ module.exports.ruleName = ruleName
53
+ module.exports.messages = messages