@primer/stylelint-config 12.3.0-rc.f3d0e89 → 12.3.2-rc.bf1f6ff
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 +12 -0
- package/package.json +7 -7
- package/plugins/spacing.js +44 -36
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 12.3.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#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
|
|
8
|
+
|
|
9
|
+
## 12.3.1
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [#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.
|
|
14
|
+
|
|
3
15
|
## 12.3.0
|
|
4
16
|
|
|
5
17
|
### Minor Changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@primer/stylelint-config",
|
|
3
|
-
"version": "12.3.
|
|
3
|
+
"version": "12.3.2-rc.bf1f6ff",
|
|
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.",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"plugins/"
|
|
21
21
|
],
|
|
22
22
|
"scripts": {
|
|
23
|
-
"test": "jest",
|
|
23
|
+
"test": "jest --coverage false",
|
|
24
24
|
"lint": "eslint .",
|
|
25
25
|
"release": "changeset publish"
|
|
26
26
|
},
|
|
@@ -44,19 +44,19 @@
|
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@changesets/changelog-github": "0.4.2",
|
|
47
|
-
"@changesets/cli": "2.
|
|
47
|
+
"@changesets/cli": "2.20.0",
|
|
48
48
|
"@github/prettier-config": "0.0.4",
|
|
49
49
|
"@primer/css": "^19.0.0",
|
|
50
50
|
"@primer/primitives": "^7.0.1",
|
|
51
51
|
"dedent": "0.7.0",
|
|
52
|
-
"eslint": "8.
|
|
52
|
+
"eslint": "8.8.0",
|
|
53
53
|
"eslint-plugin-github": "4.3.5",
|
|
54
|
-
"eslint-plugin-jest": "
|
|
54
|
+
"eslint-plugin-jest": "26.0.0",
|
|
55
55
|
"eslint-plugin-prettier": "4.0.0",
|
|
56
|
-
"jest": "27.4.
|
|
56
|
+
"jest": "27.4.7",
|
|
57
57
|
"jest-preset-stylelint": "4.2.0",
|
|
58
58
|
"prettier": "2.5.1",
|
|
59
|
-
"stylelint": "14.
|
|
59
|
+
"stylelint": "14.3.0"
|
|
60
60
|
},
|
|
61
61
|
"jest": {
|
|
62
62
|
"preset": "jest-preset-stylelint",
|
package/plugins/spacing.js
CHANGED
|
@@ -2,6 +2,7 @@ const stylelint = require('stylelint')
|
|
|
2
2
|
const declarationValueIndex = require('stylelint/lib/utils/declarationValueIndex')
|
|
3
3
|
const valueParser = require('postcss-value-parser')
|
|
4
4
|
|
|
5
|
+
// TODO: Pull this in from primer/primitives
|
|
5
6
|
const spacerValues = {
|
|
6
7
|
'$spacer-1': '4px',
|
|
7
8
|
'$spacer-2': '8px',
|
|
@@ -34,6 +35,17 @@ const messages = stylelint.utils.ruleMessages(ruleName, {
|
|
|
34
35
|
}
|
|
35
36
|
})
|
|
36
37
|
|
|
38
|
+
const walkGroups = (root, validate) => {
|
|
39
|
+
for (const node of root.nodes) {
|
|
40
|
+
if (node.type === 'function') {
|
|
41
|
+
walkGroups(node, validate)
|
|
42
|
+
} else {
|
|
43
|
+
validate(node)
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return root
|
|
47
|
+
}
|
|
48
|
+
|
|
37
49
|
// eslint-disable-next-line no-unused-vars
|
|
38
50
|
module.exports = stylelint.createPlugin(ruleName, (enabled, options = {}, context) => {
|
|
39
51
|
if (!enabled) {
|
|
@@ -41,65 +53,61 @@ module.exports = stylelint.createPlugin(ruleName, (enabled, options = {}, contex
|
|
|
41
53
|
}
|
|
42
54
|
|
|
43
55
|
const lintResult = (root, result) => {
|
|
44
|
-
root.
|
|
56
|
+
root.walk(decl => {
|
|
57
|
+
if (decl.type !== 'decl' || !decl.prop.match(/^(padding|margin)/)) {
|
|
58
|
+
return noop
|
|
59
|
+
}
|
|
60
|
+
|
|
45
61
|
const problems = []
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
62
|
+
|
|
63
|
+
const parsedValue = walkGroups(valueParser(decl.value), node => {
|
|
64
|
+
// Remove leading negative sign, if any.
|
|
65
|
+
const cleanValue = node.value.replace(/^-/g, '')
|
|
66
|
+
|
|
49
67
|
// Only check word types. https://github.com/TrySound/postcss-value-parser#word
|
|
50
|
-
if (
|
|
51
|
-
return
|
|
68
|
+
if (node.type !== 'word') {
|
|
69
|
+
return
|
|
52
70
|
}
|
|
53
71
|
|
|
54
|
-
//
|
|
55
|
-
if (['0', 'auto', 'inherit', 'initial'].includes(
|
|
56
|
-
return
|
|
72
|
+
// Exact values to ignore.
|
|
73
|
+
if (['*', '+', '-', '/', '0', 'auto', 'inherit', 'initial'].includes(node.value)) {
|
|
74
|
+
return
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const valueUnit = valueParser.unit(cleanValue)
|
|
78
|
+
|
|
79
|
+
if (valueUnit && (valueUnit.unit === '' || !/^[0-9]+$/.test(valueUnit.number))) {
|
|
80
|
+
return
|
|
57
81
|
}
|
|
58
|
-
// Remove leading negative sign, if any.
|
|
59
|
-
const cleanDeclValue = declValue.value.replace(/^-/g, '')
|
|
60
82
|
|
|
61
83
|
// If the a variable is found in the value, skip it.
|
|
62
84
|
if (
|
|
63
85
|
Object.keys(spacerValues).some(variable =>
|
|
64
|
-
new RegExp(`${variable.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}\\b`).test(
|
|
86
|
+
new RegExp(`${variable.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}\\b`).test(cleanValue)
|
|
65
87
|
)
|
|
66
88
|
) {
|
|
67
|
-
|
|
68
|
-
return false
|
|
89
|
+
return
|
|
69
90
|
}
|
|
70
91
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
containsMath = true
|
|
74
|
-
return false
|
|
75
|
-
}
|
|
92
|
+
const replacement = Object.keys(spacerValues).find(spacer => spacerValues[spacer] === cleanValue) || null
|
|
93
|
+
const valueMatch = replacement ? spacerValues[replacement] : node.value
|
|
76
94
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
declValue.value = declValue.value.replace(spacerValues[valueMatch], valueMatch)
|
|
81
|
-
} else {
|
|
82
|
-
problems.push({
|
|
83
|
-
index: declarationValueIndex(decl) + declValue.sourceIndex,
|
|
84
|
-
message: messages.rejected(spacerValues[valueMatch], valueMatch)
|
|
85
|
-
})
|
|
86
|
-
}
|
|
87
|
-
} else if (declValue.value !== '' && declValue.type !== 'function' && !containsMath) {
|
|
95
|
+
if (replacement && context.fix) {
|
|
96
|
+
node.value = node.value.replace(valueMatch, replacement)
|
|
97
|
+
} else {
|
|
88
98
|
problems.push({
|
|
89
|
-
index: declarationValueIndex(decl) +
|
|
90
|
-
message: messages.rejected(
|
|
99
|
+
index: declarationValueIndex(decl) + node.sourceIndex,
|
|
100
|
+
message: messages.rejected(valueMatch, replacement)
|
|
91
101
|
})
|
|
92
102
|
}
|
|
103
|
+
|
|
104
|
+
return
|
|
93
105
|
})
|
|
94
106
|
|
|
95
107
|
if (context.fix) {
|
|
96
108
|
decl.value = parsedValue.toString()
|
|
97
109
|
}
|
|
98
110
|
|
|
99
|
-
if (containsMath && conatinsVariable) {
|
|
100
|
-
return false
|
|
101
|
-
}
|
|
102
|
-
|
|
103
111
|
if (problems.length) {
|
|
104
112
|
for (const err of problems) {
|
|
105
113
|
stylelint.utils.report({
|