@primer/stylelint-config 13.0.1-rc.bbe2b12 → 13.1.0-rc.437e7b4

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.
@@ -1,83 +0,0 @@
1
- import stylelint from 'stylelint'
2
- import declarationValidator from './decl-validator.js'
3
- import variables from '@primer/css/dist/variables.json' with {type: 'json'}
4
-
5
- export const CSS_IMPORTANT = '!important'
6
- export const CSS_DIRECTIONS = ['top', 'right', 'bottom', 'left']
7
- export const CSS_CORNERS = ['top-right', 'bottom-right', 'bottom-left', 'top-left']
8
-
9
- export function createVariableRule(ruleName, rules, url) {
10
- const plugin = stylelint.createPlugin(ruleName, (enabled, options = {}, context) => {
11
- if (enabled === false) {
12
- return noop
13
- }
14
-
15
- let actualRules = rules
16
- let overrides = options.rules
17
- if (typeof rules === 'function') {
18
- actualRules = rules({variables, options, ruleName})
19
- } else {
20
- actualRules = Object.assign({}, rules)
21
- }
22
- if (typeof overrides === 'function') {
23
- delete options.rules
24
- overrides = overrides({rules: actualRules, options, ruleName, variables})
25
- }
26
- if (overrides) {
27
- Object.assign(actualRules, overrides)
28
- }
29
- const validate = declarationValidator(actualRules, {variables})
30
-
31
- // The stylelint docs suggest respecting a "disableFix" rule option that
32
- // overrides the "global" context.fix (--fix) linting option.
33
- const {verbose = false, disableFix} = options
34
- const fixEnabled = context && context.fix && !disableFix
35
- const seen = new WeakMap()
36
-
37
- return (root, result) => {
38
- root.walkRules(rule => {
39
- rule.walkDecls(decl => {
40
- if (seen.has(decl)) {
41
- return
42
- } else {
43
- seen.set(decl, true)
44
- }
45
-
46
- const validated = validate(decl)
47
- const {valid, fixable, replacement, errors} = validated
48
- if (valid) {
49
- return
50
- } else if (fixEnabled && fixable) {
51
- decl.value = replacement
52
- } else {
53
- for (const error of errors) {
54
- const message = stylelint.utils
55
- .ruleMessages(ruleName, {
56
- rejected: m => {
57
- if (url) {
58
- return `${m}. See ${url}.`
59
- }
60
- return `${m}.`
61
- },
62
- })
63
- .rejected(error)
64
-
65
- stylelint.utils.report({
66
- message,
67
- node: decl,
68
- result,
69
- ruleName,
70
- })
71
- }
72
- }
73
- })
74
- })
75
- }
76
- })
77
-
78
- Object.assign(plugin, {rules})
79
-
80
- return plugin
81
- }
82
-
83
- function noop() {}