@atomicsmash/coding-standards 11.0.0-beta.4 → 11.0.0-beta.6

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 CHANGED
@@ -1,5 +1,25 @@
1
1
  # @atomicsmash/coding-standards
2
2
 
3
+ ## 11.0.0-beta.6
4
+
5
+ ### Minor Changes
6
+
7
+ - [`0f28480`](https://github.com/AtomicSmash/packages/commit/0f28480d58d4473404e5b2e5d7e4fd491015c031) Thanks [@mikeybinns](https://github.com/mikeybinns)! - Add beta Stylelint config
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies []:
12
+ - @atomicsmash/eslint-config@11.0.0-beta.6
13
+ - @atomicsmash/browserslist-config@11.0.0-beta.6
14
+
15
+ ## 11.0.0-beta.5
16
+
17
+ ### Patch Changes
18
+
19
+ - Updated dependencies [[`9376010`](https://github.com/AtomicSmash/packages/commit/93760109b9db51564208239f929e6261ed067d69)]:
20
+ - @atomicsmash/eslint-config@11.0.0-beta.5
21
+ - @atomicsmash/browserslist-config@11.0.0-beta.5
22
+
3
23
  ## 11.0.0-beta.4
4
24
 
5
25
  ### Minor Changes
@@ -0,0 +1,69 @@
1
+ const commonRules = {
2
+ "custom-property-pattern": null,
3
+ "function-url-quotes": ["always"],
4
+ "rule-empty-line-before": [
5
+ "always",
6
+ {
7
+ except: ["first-nested"],
8
+ ignore: ["after-comment"],
9
+ },
10
+ ],
11
+ "comment-empty-line-before": [
12
+ "always",
13
+ {
14
+ except: ["first-nested"],
15
+ ignore: ["stylelint-commands"],
16
+ },
17
+ ],
18
+ "order/order": [
19
+ "custom-properties",
20
+ "dollar-variables",
21
+ "declarations",
22
+ "rules",
23
+ "at-rules",
24
+ ],
25
+ "selector-class-pattern": [
26
+ "^([a-z][a-z0-9]*)([_-]+[a-z0-9]+)*$",
27
+ {
28
+ message:
29
+ "Selector should use lowercase and separate words with hyphens or underscores (selector-class-pattern)",
30
+ },
31
+ ],
32
+ };
33
+
34
+ /** @type {import('stylelint').Config} */
35
+ module.exports = {
36
+ reportDescriptionlessDisables: true,
37
+ reportInvalidScopeDisables: true,
38
+ reportNeedlessDisables: true,
39
+ plugins: ["stylelint-order"],
40
+ rules: commonRules,
41
+ overrides: [
42
+ {
43
+ files: ["*.css", "**/*.css"],
44
+ extends: [
45
+ "stylelint-config-standard",
46
+ "@wordpress/stylelint-config",
47
+ "stylelint-config-prettier",
48
+ ],
49
+ },
50
+ {
51
+ files: ["*.scss", "**/*.scss"],
52
+ extends: [
53
+ "stylelint-config-standard-scss",
54
+ "@wordpress/stylelint-config/scss",
55
+ "stylelint-config-prettier",
56
+ ],
57
+ rules: {
58
+ "scss/operator-no-newline-after": null,
59
+ "no-descending-specificity": null,
60
+ },
61
+ },
62
+ {
63
+ files: ["**/editor-style?(s).?(s)css"],
64
+ rules: {
65
+ "declaration-property-value-allowed-list": null,
66
+ },
67
+ },
68
+ ],
69
+ };
@@ -0,0 +1,3 @@
1
+ const baseConfig = require("./base");
2
+
3
+ module.exports = baseConfig;
@@ -0,0 +1,189 @@
1
+ const baseConfig = require("./base");
2
+
3
+ /**
4
+ *
5
+ * @param {({property: string|RegExp, varInfo: {type: "custom"|"preset", slug:string},shorthand?: 1 | 2 | 3 | 4 , additionalAllowedValues?: (string|RegExp)[]})[]} values
6
+ */
7
+ function createAllowedPropertyList(values) {
8
+ /**
9
+ * @type {Record<string,string[]>}
10
+ */
11
+ const allowedPropertyList = {};
12
+ for (const {
13
+ property,
14
+ varInfo,
15
+ shorthand = 1,
16
+ additionalAllowedValues = [],
17
+ } of values) {
18
+ const isRegexProperty = property instanceof RegExp;
19
+ const possibleValues = [];
20
+ const possibleVars = [
21
+ ...additionalAllowedValues.map((value) =>
22
+ value instanceof RegExp ? value.toString() : value,
23
+ ),
24
+ `(var\\([\\s]*--wp--${varInfo.type}--${varInfo.slug}--([a-z-0-9]+[\\s]*)\\))`,
25
+ ];
26
+ if (isRegexProperty) {
27
+ possibleVars.push(
28
+ `(var\\([\\s]*--[a-z-0-9]*${property.toString().slice(1, -1)}[a-z-0-9]*[\\s]*\\))`,
29
+ );
30
+ } else if (property) {
31
+ possibleVars.push(
32
+ `(var\\([\\s]*--[a-z-0-9]*${property}[a-z-0-9]*[\\s]*\\))`,
33
+ );
34
+ }
35
+ possibleValues.push(
36
+ // For each shorthand value, allow one of the possible values followed by a space, or allow it to be blank
37
+ `/^${shorthand > 1 ? `((${possibleVars.join("|")})[\\s]*){0,${shorthand - 1}}` : ""}(${possibleVars.join("|")})$/`,
38
+ );
39
+ allowedPropertyList[property.toString()] = possibleValues;
40
+ if (!isRegexProperty) {
41
+ allowedPropertyList[`/--[a-z-0-9]*${property}[a-z-0-9]*/`] =
42
+ possibleValues;
43
+ }
44
+ }
45
+ return allowedPropertyList;
46
+ }
47
+
48
+ const rules = {
49
+ "declaration-property-value-allowed-list": [
50
+ createAllowedPropertyList([
51
+ {
52
+ property: /border((-top|-bottom)(-left|-right))?-radius/,
53
+ varInfo: {
54
+ type: "custom",
55
+ slug: "radius",
56
+ },
57
+ },
58
+ {
59
+ property: "border-radius",
60
+ varInfo: {
61
+ type: "custom",
62
+ slug: "radius",
63
+ },
64
+ shorthand: 4,
65
+ },
66
+ {
67
+ property: "box-shadow",
68
+ varInfo: {
69
+ type: "preset",
70
+ slug: "shadow",
71
+ },
72
+ additionalAllowedValues: ["none", "unset"],
73
+ },
74
+ {
75
+ property: /color/,
76
+ varInfo: {
77
+ type: "preset",
78
+ slug: "color",
79
+ },
80
+ additionalAllowedValues: ["inherit", "currentcolor"],
81
+ },
82
+ {
83
+ property: "background-color",
84
+ varInfo: {
85
+ type: "preset",
86
+ slug: "color",
87
+ },
88
+ additionalAllowedValues: ["transparent"],
89
+ },
90
+ {
91
+ property: "font-family",
92
+ varInfo: {
93
+ type: "preset",
94
+ slug: "font-family",
95
+ },
96
+ additionalAllowedValues: ["inherit"],
97
+ },
98
+ {
99
+ property: "font-size",
100
+ varInfo: {
101
+ type: "preset",
102
+ slug: "font-size",
103
+ },
104
+ additionalAllowedValues: ["inherit"],
105
+ },
106
+ {
107
+ property: /(?<!scroll-)margin/,
108
+ varInfo: {
109
+ type: "preset",
110
+ slug: "spacing",
111
+ },
112
+ shorthand: 4,
113
+ additionalAllowedValues: ["auto", "var\\(--wp--style--block-gap\\)"],
114
+ },
115
+ {
116
+ property: /padding/,
117
+ varInfo: {
118
+ type: "preset",
119
+ slug: "spacing",
120
+ },
121
+ shorthand: 4,
122
+ },
123
+ {
124
+ property: "z-index",
125
+ varInfo: {
126
+ type: "custom",
127
+ slug: "z-index",
128
+ },
129
+ },
130
+ ]),
131
+ {
132
+ severity: "warning",
133
+ message: (property, value) => {
134
+ // Until updated, property and value will always return undefined.
135
+ return `Most values for this type of property should be defined in theme.json. (declaration-property-value-allowed-list)`;
136
+ // The following code is not complete, it has been left to show how this function could provide more helpful error
137
+ // messages once an update to stylelint is possible.
138
+ /* eslint-disable no-unreachable */
139
+ let message = `Invalid property provided for ${property}.`;
140
+ let ruleKey;
141
+ if (new RegExp(/color/).test(property)) {
142
+ ruleKey = "/color/";
143
+ } else if (new RegExp(/margin/).test(property)) {
144
+ ruleKey = "/margin/";
145
+ } else if (new RegExp(/padding/).test(property)) {
146
+ ruleKey = "/padding/";
147
+ } else {
148
+ ruleKey = property;
149
+ }
150
+ switch (ruleKey) {
151
+ case "z-index": {
152
+ message = `z-index must use one of the values specified in the theme.json file under \`settings.custom.z-index\`.`;
153
+ break;
154
+ }
155
+ case "/color/": {
156
+ message = `Colour values must use one of the values specified in the theme.json file under \`settings.color.palette\`.`;
157
+ break;
158
+ }
159
+ case "/margin/": {
160
+ message = `Margin values must use one of the values specified in the theme.json file under \`settings.spacing.spacingSizes\`.`;
161
+ break;
162
+ }
163
+ case "/padding/": {
164
+ message = `Padding values must use one of the values specified in the theme.json file under \`settings.spacing.spacingSizes\`.`;
165
+ break;
166
+ }
167
+ case "font-size": {
168
+ message = `Font size values must use one of the values specified in the theme.json file under \`settings.typography.fontSizes\`.`;
169
+ break;
170
+ }
171
+ case "font-family": {
172
+ message = `Font family values must use one of the values specified in the theme.json file under \`settings.typography.fontFamilies\`.`;
173
+ break;
174
+ }
175
+ }
176
+ return `${message} Value provided: ${value} (declaration-property-value-allowed-list)`;
177
+ /* eslint-enable no-unreachable */
178
+ },
179
+ },
180
+ ],
181
+ };
182
+
183
+ module.exports = {
184
+ ...baseConfig,
185
+ rules: {
186
+ ...baseConfig.rules,
187
+ ...rules,
188
+ },
189
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atomicsmash/coding-standards",
3
- "version": "11.0.0-beta.4",
3
+ "version": "11.0.0-beta.6",
4
4
  "description": "A collection of coding standards configurations.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -8,8 +8,8 @@
8
8
  "@cspell/cspell-types": "^8.6.0"
9
9
  },
10
10
  "peerDependencies": {
11
- "@atomicsmash/browserslist-config": "11.0.0-beta.4",
12
- "@atomicsmash/eslint-config": "11.0.0-beta.4",
11
+ "@atomicsmash/browserslist-config": "11.0.0-beta.6",
12
+ "@atomicsmash/eslint-config": "11.0.0-beta.6",
13
13
  "@commitlint/cli": "^19.0.3",
14
14
  "@commitlint/config-conventional": "^19.0.3",
15
15
  "prettier": "^3.2.5"