@atomicsmash/coding-standards 13.0.0-beta.2 → 13.0.0-beta.4

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.
@@ -0,0 +1,35 @@
1
+ export default {
2
+ /* Expected defaults:
3
+ Prettier recommendation
4
+ printWidth: 80,
5
+
6
+ Single quotes are more often found in text strings (used for apostrophes) so using double quotes prevents lots of escaping characters.
7
+ singleQuote: false,
8
+
9
+ Keep very nested indentation near the left to prevent lots of horizontal scrolling.
10
+ tabWidth: 2,
11
+
12
+ Semicolons prevent AST errors and are more explicit where a line ends
13
+ semi: true,
14
+
15
+ Consistent line endings for MacOS and Windows
16
+ endOfLine: "lf",
17
+ */
18
+
19
+ // Tabs are better for visually impaired coders https://www.reddit.com/r/javascript/comments/c8drjo/nobody_talks_about_the_real_reason_to_use_tabs/
20
+ useTabs: true,
21
+
22
+ // Helps clean up git diffs by removing changes of a single comma on a line if adding a new line to the bottom
23
+ trailingComma: "all",
24
+
25
+ overrides: [
26
+ {
27
+ // yml files require specific indentation rules
28
+ files: ["*.yml", "*.yaml"],
29
+ options: {
30
+ useTabs: false,
31
+ tabWidth: 2,
32
+ },
33
+ },
34
+ ],
35
+ };
@@ -0,0 +1,74 @@
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
+ "at-rule-empty-line-before": [
33
+ "always",
34
+ {
35
+ ignore: ["blockless-after-blockless", "first-nested", "after-comment"],
36
+ },
37
+ ],
38
+ };
39
+
40
+ /** @type {import('stylelint').Config} */
41
+ module.exports = {
42
+ reportDescriptionlessDisables: true,
43
+ reportInvalidScopeDisables: true,
44
+ reportNeedlessDisables: true,
45
+ plugins: ["stylelint-order"],
46
+ rules: commonRules,
47
+ overrides: [
48
+ {
49
+ files: ["*.css", "**/*.css"],
50
+ extends: ["stylelint-config-standard", "@wordpress/stylelint-config"],
51
+ rules: {
52
+ "at-rule-no-unknown": [true, { ignoreAtRules: "context" }],
53
+ },
54
+ },
55
+ {
56
+ files: ["*.scss", "**/*.scss"],
57
+ extends: [
58
+ "stylelint-config-standard-scss",
59
+ "@wordpress/stylelint-config/scss",
60
+ ],
61
+ rules: {
62
+ "scss/operator-no-newline-after": null,
63
+ "no-descending-specificity": null,
64
+ "scss/at-rule-no-unknown": [true, { ignoreAtRules: "context" }],
65
+ },
66
+ },
67
+ {
68
+ files: ["**/editor-style?(s).?(s)css"],
69
+ rules: {
70
+ "declaration-property-value-allowed-list": null,
71
+ },
72
+ },
73
+ ],
74
+ };
package/stylelint/base.js CHANGED
@@ -1,74 +1 @@
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
- "at-rule-empty-line-before": [
33
- "always",
34
- {
35
- ignore: ["blockless-after-blockless", "first-nested", "after-comment"],
36
- },
37
- ],
38
- };
39
-
40
- /** @type {import('stylelint').Config} */
41
- module.exports = {
42
- reportDescriptionlessDisables: true,
43
- reportInvalidScopeDisables: true,
44
- reportNeedlessDisables: true,
45
- plugins: ["stylelint-order"],
46
- rules: commonRules,
47
- overrides: [
48
- {
49
- files: ["*.css", "**/*.css"],
50
- extends: ["stylelint-config-standard", "@wordpress/stylelint-config"],
51
- rules: {
52
- "at-rule-no-unknown": [true, { ignoreAtRules: "context" }],
53
- },
54
- },
55
- {
56
- files: ["*.scss", "**/*.scss"],
57
- extends: [
58
- "stylelint-config-standard-scss",
59
- "@wordpress/stylelint-config/scss",
60
- ],
61
- rules: {
62
- "scss/operator-no-newline-after": null,
63
- "no-descending-specificity": null,
64
- "scss/at-rule-no-unknown": [true, { ignoreAtRules: "context" }],
65
- },
66
- },
67
- {
68
- files: ["**/editor-style?(s).?(s)css"],
69
- rules: {
70
- "declaration-property-value-allowed-list": null,
71
- },
72
- },
73
- ],
74
- };
1
+ module.exports = require("./base.cjs");
@@ -0,0 +1,74 @@
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
+ "at-rule-empty-line-before": [
33
+ "always",
34
+ {
35
+ ignore: ["blockless-after-blockless", "first-nested", "after-comment"],
36
+ },
37
+ ],
38
+ };
39
+
40
+ /** @type {import('stylelint').Config} */
41
+ export default {
42
+ reportDescriptionlessDisables: true,
43
+ reportInvalidScopeDisables: true,
44
+ reportNeedlessDisables: true,
45
+ plugins: ["stylelint-order"],
46
+ rules: commonRules,
47
+ overrides: [
48
+ {
49
+ files: ["*.css", "**/*.css"],
50
+ extends: ["stylelint-config-standard", "@wordpress/stylelint-config"],
51
+ rules: {
52
+ "at-rule-no-unknown": [true, { ignoreAtRules: "context" }],
53
+ },
54
+ },
55
+ {
56
+ files: ["*.scss", "**/*.scss"],
57
+ extends: [
58
+ "stylelint-config-standard-scss",
59
+ "@wordpress/stylelint-config/scss",
60
+ ],
61
+ rules: {
62
+ "scss/operator-no-newline-after": null,
63
+ "no-descending-specificity": null,
64
+ "scss/at-rule-no-unknown": [true, { ignoreAtRules: "context" }],
65
+ },
66
+ },
67
+ {
68
+ files: ["**/editor-style?(s).?(s)css"],
69
+ rules: {
70
+ "declaration-property-value-allowed-list": null,
71
+ },
72
+ },
73
+ ],
74
+ };
@@ -0,0 +1,3 @@
1
+ const baseConfig = require("./base.cjs");
2
+
3
+ module.exports = baseConfig;
@@ -1,3 +1 @@
1
- const baseConfig = require("./base");
2
-
3
- module.exports = baseConfig;
1
+ module.exports = require("./classic.cjs");
@@ -0,0 +1,2 @@
1
+ import config from "./base.mjs";
2
+ export default config;
@@ -0,0 +1,4 @@
1
+ module.exports = {
2
+ classic: require("./classic.cjs"),
3
+ themeJson: require("./theme-json.cjs"),
4
+ };
@@ -0,0 +1,3 @@
1
+ import { default as classicConfig } from "./classic.mjs";
2
+ import { default as themeJsonConfig } from "./theme-json.mjs";
3
+ export default { classicConfig, themeJsonConfig };
@@ -0,0 +1,189 @@
1
+ const baseConfig = require("./base.cjs");
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 -- See above */
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
+ };
@@ -1,189 +1 @@
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 -- See above */
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
- };
1
+ module.exports = require("./theme-json.cjs");