@atlaskit/eslint-plugin-ui-styling-standard 0.15.2 → 0.16.1
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 +17 -0
- package/constellation/consistent-css-prop-usage/usage.mdx +3 -1
- package/constellation/index/migration-guide.mdx +309 -0
- package/constellation/index/overview.mdx +4 -0
- package/constellation/index/props.mdx +9 -5
- package/constellation/no-css-tagged-template-expression/usage.mdx +5 -2
- package/constellation/no-empty-styled-expression/usage.mdx +5 -2
- package/constellation/no-exported-css/usage.mdx +5 -2
- package/constellation/no-exported-keyframes/usage.mdx +5 -2
- package/constellation/no-invalid-css-map/usage.mdx +5 -2
- package/constellation/no-js-xcss/usage.mdx +3 -1
- package/constellation/no-keyframes-tagged-template-expression/usage.mdx +5 -2
- package/constellation/no-styled-tagged-template-expression/usage.mdx +5 -2
- package/constellation/no-suppress-xcss/usage.mdx +6 -3
- package/dist/types/rules/no-unsafe-selectors/constants.d.ts +1 -4
- package/index.js +9 -9
- package/package.json +3 -3
- package/scripts/codegen.tsx +223 -284
- package/src/rules/__tests__/utils/_tester.tsx +24 -24
- package/src/rules/atlaskit-theme/README.md +21 -19
- package/src/rules/atlaskit-theme/__tests__/test.ts +53 -53
- package/src/rules/atlaskit-theme/index.ts +107 -115
- package/src/rules/convert-props-syntax/README.md +32 -22
- package/src/rules/convert-props-syntax/__tests__/invalid.test.tsx +46 -46
- package/src/rules/convert-props-syntax/__tests__/rule.test.tsx +175 -175
- package/src/rules/convert-props-syntax/__tests__/type-annotations.test.tsx +52 -52
- package/src/rules/convert-props-syntax/__tests__/unusual-properties.test.tsx +33 -33
- package/src/rules/convert-props-syntax/index.tsx +356 -386
- package/src/rules/enforce-style-prop/README.md +21 -18
- package/src/rules/enforce-style-prop/__tests__/rule.test.tsx +90 -96
- package/src/rules/enforce-style-prop/index.tsx +144 -160
- package/src/rules/external-rules.tsx +163 -164
- package/src/rules/local-cx-xcss/README.md +10 -6
- package/src/rules/local-cx-xcss/__tests__/rule.test.tsx +26 -26
- package/src/rules/local-cx-xcss/index.tsx +46 -56
- package/src/rules/no-array-arguments/README.md +2 -1
- package/src/rules/no-array-arguments/__tests__/rule.test.tsx +37 -46
- package/src/rules/no-array-arguments/index.tsx +68 -69
- package/src/rules/no-classname-prop/README.md +7 -4
- package/src/rules/no-classname-prop/__tests__/rule.test.tsx +22 -22
- package/src/rules/no-classname-prop/index.tsx +25 -25
- package/src/rules/no-container-queries/README.md +11 -9
- package/src/rules/no-container-queries/__tests__/rule.test.tsx +47 -50
- package/src/rules/no-container-queries/index.tsx +75 -81
- package/src/rules/no-dynamic-styles/README.md +16 -19
- package/src/rules/no-dynamic-styles/__tests__/rule.test.tsx +58 -67
- package/src/rules/no-dynamic-styles/index.tsx +45 -48
- package/src/rules/no-exported-styles/README.md +17 -12
- package/src/rules/no-exported-styles/__tests__/rule.test.tsx +102 -111
- package/src/rules/no-exported-styles/index.tsx +36 -36
- package/src/rules/no-global-styles/README.md +15 -14
- package/src/rules/no-global-styles/__tests__/no-css-modules.test.tsx +28 -28
- package/src/rules/no-global-styles/__tests__/no-global-styles.test.tsx +37 -37
- package/src/rules/no-global-styles/index.tsx +59 -62
- package/src/rules/no-important-styles/README.md +5 -3
- package/src/rules/no-important-styles/__tests__/rule.test.tsx +66 -66
- package/src/rules/no-important-styles/index.tsx +49 -49
- package/src/rules/no-imported-style-values/README.md +23 -15
- package/src/rules/no-imported-style-values/__tests__/rule.test.tsx +123 -123
- package/src/rules/no-imported-style-values/index.tsx +116 -120
- package/src/rules/no-nested-selectors/README.md +15 -13
- package/src/rules/no-nested-selectors/__tests__/rule.test.tsx +141 -128
- package/src/rules/no-styled/README.md +14 -9
- package/src/rules/no-styled/__tests__/rule.test.tsx +31 -31
- package/src/rules/no-styled/index.tsx +34 -41
- package/src/rules/no-unsafe-selectors/README.md +103 -93
- package/src/rules/no-unsafe-selectors/__tests__/no-grouped-at-rules.test.tsx +21 -24
- package/src/rules/no-unsafe-selectors/__tests__/no-increased-specificity.test.tsx +44 -44
- package/src/rules/no-unsafe-selectors/__tests__/no-keyframes-at-rules.test.tsx +21 -21
- package/src/rules/no-unsafe-selectors/__tests__/no-legacy-pseudo-element-syntax.test.tsx +57 -57
- package/src/rules/no-unsafe-selectors/__tests__/no-restricted-at-rules.test.tsx +58 -58
- package/src/rules/no-unsafe-selectors/__tests__/no-restricted-pseudos.test.tsx +85 -85
- package/src/rules/no-unsafe-selectors/__tests__/no-selectors-object.test.tsx +12 -12
- package/src/rules/no-unsafe-selectors/__tests__/no-unparsable-selectors.test.tsx +23 -23
- package/src/rules/no-unsafe-selectors/__tests__/rule.test.tsx +133 -114
- package/src/rules/no-unsafe-selectors/constants.tsx +69 -77
- package/src/rules/no-unsafe-selectors/source-position-utils.tsx +38 -38
- package/src/rules/no-unsafe-selectors/walk-css-map.tsx +178 -184
- package/src/rules/no-unsafe-values/README.md +34 -40
- package/src/rules/no-unsafe-values/__tests__/no-array-values.test.tsx +13 -13
- package/src/rules/no-unsafe-values/__tests__/no-conditional-values.test.tsx +18 -18
- package/src/rules/no-unsafe-values/__tests__/no-dynamic-keys.test.tsx +104 -104
- package/src/rules/no-unsafe-values/__tests__/no-function-calls.test.tsx +128 -128
- package/src/rules/no-unsafe-values/__tests__/no-identifier-arguments.test.tsx +23 -23
- package/src/rules/no-unsafe-values/__tests__/no-object-access.test.tsx +38 -38
- package/src/rules/no-unsafe-values/__tests__/no-object-references.test.tsx +18 -18
- package/src/rules/no-unsafe-values/__tests__/no-spread-elements.test.tsx +18 -18
- package/src/rules/no-unsafe-values/__tests__/no-unsafe-values.test.tsx +28 -28
- package/src/rules/no-unsafe-values/__tests__/no-variables.test.tsx +47 -47
- package/src/rules/no-unsafe-values/index.tsx +76 -78
- package/src/rules/no-unsafe-values/messages.tsx +12 -12
- package/src/rules/no-unsafe-values/utils.tsx +370 -382
- package/src/rules/use-compiled/README.md +11 -8
- package/src/rules/use-compiled/__tests__/can-auto-fix.test.tsx +32 -32
- package/src/rules/use-compiled/__tests__/css.test.tsx +53 -53
- package/src/rules/use-compiled/__tests__/imports.test.tsx +90 -95
- package/src/rules/use-compiled/__tests__/keyframes.test.tsx +47 -47
- package/src/rules/use-compiled/__tests__/pragma.test.tsx +64 -64
- package/src/rules/use-compiled/__tests__/styled.test.tsx +53 -53
- package/src/rules/use-compiled/__tests__/use-compiled.test.tsx +10 -10
- package/src/rules/use-compiled/index.tsx +203 -226
- package/src/rules/use-compiled/is-safe.tsx +113 -117
- package/src/rules/use-compiled/utils.tsx +14 -18
- package/src/rules/utils/create-rule-with-typed-config.tsx +62 -63
- package/src/rules/utils/create-rule.tsx +3 -6
package/scripts/codegen.tsx
CHANGED
|
@@ -8,14 +8,8 @@ import format from '@af/formatting/sync';
|
|
|
8
8
|
|
|
9
9
|
import { createSignedArtifact } from '@atlassian/codegen';
|
|
10
10
|
|
|
11
|
-
import {
|
|
12
|
-
|
|
13
|
-
getPathSafeName,
|
|
14
|
-
} from '@atlaskit/eslint-utils/create-rule';
|
|
15
|
-
import {
|
|
16
|
-
externalRules,
|
|
17
|
-
type ExternalRuleMeta,
|
|
18
|
-
} from '../src/rules/external-rules';
|
|
11
|
+
import { type LintRule, getPathSafeName } from '@atlaskit/eslint-utils/create-rule';
|
|
12
|
+
import { externalRules, type ExternalRuleMeta } from '../src/rules/external-rules';
|
|
19
13
|
|
|
20
14
|
const packagePluginName = '@atlaskit/eslint-plugin-ui-styling-standard';
|
|
21
15
|
const pluginName = '@atlaskit/ui-styling-standard';
|
|
@@ -23,15 +17,15 @@ const pluginPath = 'eslint-plugin-ui-styling-standard';
|
|
|
23
17
|
const codegenCommand = `yarn workspace ${packagePluginName} codegen`;
|
|
24
18
|
|
|
25
19
|
interface FoundRule {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
20
|
+
module: LintRule | { meta: ExternalRuleMeta };
|
|
21
|
+
/**
|
|
22
|
+
* This is used for the directory name, import path, and urls
|
|
23
|
+
*/
|
|
24
|
+
pathSafeName: string;
|
|
25
|
+
/**
|
|
26
|
+
* Friendly name that can include special characters
|
|
27
|
+
*/
|
|
28
|
+
ruleName: string;
|
|
35
29
|
}
|
|
36
30
|
|
|
37
31
|
/**
|
|
@@ -39,169 +33,139 @@ interface FoundRule {
|
|
|
39
33
|
* These come from `rules/external-rules.tsx`
|
|
40
34
|
*/
|
|
41
35
|
interface ExternalRule extends FoundRule {
|
|
42
|
-
|
|
36
|
+
module: { meta: ExternalRuleMeta };
|
|
43
37
|
}
|
|
44
38
|
interface InternalRule extends FoundRule {
|
|
45
|
-
|
|
39
|
+
module: LintRule;
|
|
46
40
|
}
|
|
47
41
|
|
|
48
42
|
interface GeneratedConfig {
|
|
49
|
-
|
|
50
|
-
|
|
43
|
+
name: string;
|
|
44
|
+
path: string;
|
|
51
45
|
}
|
|
52
46
|
|
|
53
|
-
const ignoreList = [
|
|
54
|
-
'index.codegen.tsx',
|
|
55
|
-
'TEMPLATE.md',
|
|
56
|
-
'__tests__',
|
|
57
|
-
'utils',
|
|
58
|
-
'external-rules.tsx',
|
|
59
|
-
];
|
|
47
|
+
const ignoreList = ['index.codegen.tsx', 'TEMPLATE.md', '__tests__', 'utils', 'external-rules.tsx'];
|
|
60
48
|
const srcDir = join(__dirname, '../src');
|
|
61
49
|
const rulesDir = join(srcDir, 'rules');
|
|
62
50
|
const presetsDir = join(srcDir, 'presets');
|
|
63
51
|
const generatedConfigs: GeneratedConfig[] = [];
|
|
64
52
|
|
|
65
53
|
function ruleIsExternal(rule: FoundRule | ExternalRule): rule is ExternalRule {
|
|
66
|
-
|
|
54
|
+
return 'isExternal' in rule.module.meta && !!rule.module.meta.isExternal;
|
|
67
55
|
}
|
|
68
56
|
function ruleIsInternal(rule: FoundRule | ExternalRule): rule is InternalRule {
|
|
69
|
-
|
|
57
|
+
return !ruleIsExternal(rule);
|
|
70
58
|
}
|
|
71
59
|
|
|
72
60
|
/**
|
|
73
61
|
* Get the path to, and file contents for, a rule's README.md file.
|
|
74
62
|
*/
|
|
75
63
|
async function ruleDocsPath(name: string) {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
);
|
|
86
|
-
}
|
|
64
|
+
const absolutePath = join(rulesDir, name, 'README.md');
|
|
65
|
+
const relativePath = '.' + absolutePath.replace(process.cwd(), '');
|
|
66
|
+
|
|
67
|
+
try {
|
|
68
|
+
const file = await fs.readFile(absolutePath, 'utf-8');
|
|
69
|
+
return { path: relativePath, file };
|
|
70
|
+
} catch (_) {
|
|
71
|
+
throw new Error(`invariant: rule ${name} should have docs at ${absolutePath}`);
|
|
72
|
+
}
|
|
87
73
|
}
|
|
88
74
|
|
|
89
75
|
/**
|
|
90
76
|
* Generates the preset config, eg. `src/presets/all.codegen.tsx` and `src/presets/recommended.codegen.tsx`
|
|
91
77
|
*/
|
|
92
|
-
async function generatePresetConfig(
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
) {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
const pluginList = [
|
|
106
|
-
`'${pluginName}'`,
|
|
107
|
-
...Array.from(new Set(externalScopes)),
|
|
108
|
-
];
|
|
109
|
-
|
|
110
|
-
const code = outdent`
|
|
78
|
+
async function generatePresetConfig(name: 'all' | 'recommended', rules: FoundRule[]) {
|
|
79
|
+
const externalScopes = externalRules
|
|
80
|
+
.filter((rule) => rule.name?.includes('/'))
|
|
81
|
+
.map((rule) => {
|
|
82
|
+
// Take the first part of the name, eg. `@atlaskit/design-system` and wrap it in quotes to be
|
|
83
|
+
const groups = rule.name.split('/');
|
|
84
|
+
return `'${groups.slice(0, groups.length - 1).join('/')}'`;
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
// NOTE: Given we have external plugins, we must include them as plugins as well./
|
|
88
|
+
const pluginList = [`'${pluginName}'`, ...Array.from(new Set(externalScopes))];
|
|
89
|
+
|
|
90
|
+
const code = outdent`
|
|
111
91
|
export default {
|
|
112
92
|
plugins: [
|
|
113
93
|
${pluginList.join(',\n')}],
|
|
114
94
|
rules: {
|
|
115
95
|
${rules
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
return `'${ruleName}': '${calculatedSeverity}'`;
|
|
140
|
-
})
|
|
141
|
-
.join(',')}
|
|
96
|
+
.map((rule) => {
|
|
97
|
+
const { severity, recommended, pluginConfig } = rule.module.meta?.docs || {};
|
|
98
|
+
|
|
99
|
+
// `recommended` is a snowflake at this stage ... it can be a string at runtime
|
|
100
|
+
// because of legacy `import { createRule } from 'utils/create-rule'` so we take
|
|
101
|
+
// into account this possibility (as a fallback) until everything is moved over
|
|
102
|
+
// to the new syntax
|
|
103
|
+
const calculatedSeverity =
|
|
104
|
+
severity ?? (typeof recommended === 'string' ? String(recommended) : 'error');
|
|
105
|
+
|
|
106
|
+
let ruleName = rule.ruleName;
|
|
107
|
+
if (ruleIsInternal(rule)) {
|
|
108
|
+
ruleName = `${pluginName}/${rule.ruleName}`;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (typeof pluginConfig === 'object' && pluginConfig) {
|
|
112
|
+
return `'${ruleName}': ['${calculatedSeverity}', ${JSON.stringify(pluginConfig)}]`;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return `'${ruleName}': '${calculatedSeverity}'`;
|
|
116
|
+
})
|
|
117
|
+
.join(',')}
|
|
142
118
|
},
|
|
143
119
|
}
|
|
144
120
|
`;
|
|
145
121
|
|
|
146
|
-
|
|
147
|
-
|
|
122
|
+
const filepath = join(presetsDir, `${name}.codegen.tsx`);
|
|
123
|
+
await writeFile(filepath, code);
|
|
148
124
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
125
|
+
generatedConfigs.push({
|
|
126
|
+
name: camelCase(name),
|
|
127
|
+
path: './' + relative(srcDir, join(presetsDir, `${name}.codegen`)),
|
|
128
|
+
});
|
|
153
129
|
}
|
|
154
130
|
|
|
155
131
|
/**
|
|
156
132
|
* Write contents to a given file, creating a signed artifact if it's not a markdown file.
|
|
157
133
|
*/
|
|
158
134
|
async function writeFile(filepath: string, code: string) {
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
codegenCommand,
|
|
166
|
-
),
|
|
167
|
-
);
|
|
135
|
+
await fs.writeFile(
|
|
136
|
+
filepath,
|
|
137
|
+
extname(filepath).includes('.md')
|
|
138
|
+
? format(code, 'markdown')
|
|
139
|
+
: createSignedArtifact(format(code, 'typescript'), codegenCommand),
|
|
140
|
+
);
|
|
168
141
|
}
|
|
169
142
|
|
|
170
143
|
/**
|
|
171
144
|
* Generates the `src/rules/index.codegen.tsx` entrypoint, exporting all rules.
|
|
172
145
|
*/
|
|
173
146
|
async function generateRuleIndex(rules: FoundRule[]) {
|
|
174
|
-
|
|
147
|
+
const internalRules = rules.filter(ruleIsInternal);
|
|
175
148
|
|
|
176
|
-
|
|
149
|
+
const code = outdent`
|
|
177
150
|
${internalRules
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
`import ${camelCase(rule.pathSafeName)} from './${
|
|
181
|
-
rule.pathSafeName
|
|
182
|
-
}'`,
|
|
183
|
-
)
|
|
184
|
-
.join('\n')}
|
|
151
|
+
.map((rule) => `import ${camelCase(rule.pathSafeName)} from './${rule.pathSafeName}'`)
|
|
152
|
+
.join('\n')}
|
|
185
153
|
|
|
186
154
|
export default {
|
|
187
|
-
${internalRules
|
|
188
|
-
.map((rule) => `'${rule.ruleName}': ${camelCase(rule.pathSafeName)}`)
|
|
189
|
-
.join(',')}
|
|
155
|
+
${internalRules.map((rule) => `'${rule.ruleName}': ${camelCase(rule.pathSafeName)}`).join(',')}
|
|
190
156
|
}
|
|
191
157
|
`;
|
|
192
158
|
|
|
193
|
-
|
|
194
|
-
|
|
159
|
+
const filepath = join(rulesDir, 'index.codegen.tsx');
|
|
160
|
+
await writeFile(filepath, code);
|
|
195
161
|
}
|
|
196
162
|
|
|
197
163
|
/**
|
|
198
164
|
* Generates the `src/index.codegen.tsx` entrypoint, exporting all the preset configs.
|
|
199
165
|
*/
|
|
200
166
|
async function generatePluginIndex() {
|
|
201
|
-
|
|
202
|
-
${generatedConfigs
|
|
203
|
-
.map((config) => `import ${config.name} from '${config.path}'`)
|
|
204
|
-
.join('\n')}
|
|
167
|
+
const code = outdent`
|
|
168
|
+
${generatedConfigs.map((config) => `import ${config.name} from '${config.path}'`).join('\n')}
|
|
205
169
|
|
|
206
170
|
export { default as rules } from './rules/index.codegen'
|
|
207
171
|
|
|
@@ -210,225 +174,200 @@ async function generatePluginIndex() {
|
|
|
210
174
|
}
|
|
211
175
|
`;
|
|
212
176
|
|
|
213
|
-
|
|
214
|
-
|
|
177
|
+
const filepath = join(srcDir, 'index.codegen.tsx');
|
|
178
|
+
await writeFile(filepath, code);
|
|
215
179
|
}
|
|
216
180
|
|
|
217
|
-
const conditional = (cond: string, content?: boolean | string) =>
|
|
218
|
-
content ? cond : '';
|
|
181
|
+
const conditional = (cond: string, content?: boolean | string) => (content ? cond : '');
|
|
219
182
|
const optionallyLinkTo = (content: string, url?: string) =>
|
|
220
|
-
|
|
183
|
+
url ? `<a href="${url}">${content}</a>` : content;
|
|
221
184
|
|
|
222
185
|
/**
|
|
223
186
|
* Generate each individual rules' documentation pages, eg. `constellation/icon-label/usage.mdx`
|
|
224
187
|
*/
|
|
225
188
|
async function generateRulePages(rules: FoundRule[]): Promise<void> {
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
}
|
|
242
|
-
}
|
|
189
|
+
const docsDir = join(srcDir, '../constellation');
|
|
190
|
+
|
|
191
|
+
for await (const rule of rules) {
|
|
192
|
+
const ruleDir = join(docsDir, rule.pathSafeName);
|
|
193
|
+
const destination = join(ruleDir, 'usage.mdx');
|
|
194
|
+
await fs.mkdir(ruleDir, { recursive: true });
|
|
195
|
+
|
|
196
|
+
if (ruleIsExternal(rule)) {
|
|
197
|
+
await generateExternalRulePage(rule, destination);
|
|
198
|
+
} else if (ruleIsInternal(rule)) {
|
|
199
|
+
await generateInternalRulePage(rule, destination);
|
|
200
|
+
} else {
|
|
201
|
+
throw new Error(`invariant: found an unexpected rule type ${rule.ruleName}`);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
243
204
|
}
|
|
244
205
|
|
|
245
|
-
async function generateExternalRulePage(
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
if (existsSync(destination)) {
|
|
250
|
-
return true;
|
|
251
|
-
}
|
|
206
|
+
async function generateExternalRulePage(rule: ExternalRule, destination: string) {
|
|
207
|
+
if (existsSync(destination)) {
|
|
208
|
+
return true;
|
|
209
|
+
}
|
|
252
210
|
|
|
253
|
-
|
|
211
|
+
const ruleContent = outdent`
|
|
254
212
|
# ${rule.ruleName}
|
|
255
213
|
${rule.module.meta?.docs?.description || ''}
|
|
256
214
|
|
|
257
215
|
${
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
216
|
+
rule.module.meta?.docs?.externalUrl
|
|
217
|
+
? `This rule is maintained by another package and configured here; refer to ${rule.module.meta.docs.externalUrl} for more details.`
|
|
218
|
+
: ''
|
|
219
|
+
}
|
|
262
220
|
`;
|
|
263
221
|
|
|
264
|
-
|
|
222
|
+
await writeFile(destination, ruleContent);
|
|
265
223
|
}
|
|
266
224
|
|
|
267
|
-
async function generateInternalRulePage(
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
const ruleContent = outdent`
|
|
225
|
+
async function generateInternalRulePage(rule: InternalRule, destination: string) {
|
|
226
|
+
const { file } = await ruleDocsPath(rule.pathSafeName);
|
|
227
|
+
if (file.match(/^# /)) {
|
|
228
|
+
throw new Error(
|
|
229
|
+
`invariant: ${rule.pathSafeName} README doc should not include a h1 heading as it is injected automatically.`,
|
|
230
|
+
);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
const ruleContent = outdent`
|
|
279
234
|
# ${rule.ruleName}
|
|
280
235
|
${file}
|
|
281
236
|
`;
|
|
282
237
|
|
|
283
|
-
|
|
238
|
+
await writeFile(destination, ruleContent);
|
|
284
239
|
}
|
|
285
240
|
|
|
286
241
|
/**
|
|
287
242
|
* Generates the `RULE_TABLE_CODEGEN` in `constellation/index/usage.mdx` and `README.md`.
|
|
288
243
|
* This is the list of all rules and their metadata.
|
|
289
244
|
*/
|
|
290
|
-
async function generateRuleTable(
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
) {
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
const fixable = conditional('Yes', rule.module.meta?.fixable);
|
|
314
|
-
const suggestions = conditional('Yes', rule.module.meta?.hasSuggestions);
|
|
315
|
-
|
|
316
|
-
rows.push(outdent`
|
|
245
|
+
async function generateRuleTable(filepath: string, linkTo: 'docs' | 'repo', rules: FoundRule[]) {
|
|
246
|
+
const file = await fs.readFile(filepath, 'utf-8');
|
|
247
|
+
const rows: string[] = [];
|
|
248
|
+
|
|
249
|
+
for (const rule of rules) {
|
|
250
|
+
let docsPath: string | undefined;
|
|
251
|
+
|
|
252
|
+
if (linkTo === 'docs') {
|
|
253
|
+
docsPath = `/components/${pluginPath}/${rule.pathSafeName}/usage`;
|
|
254
|
+
} else if (ruleIsInternal(rule)) {
|
|
255
|
+
const result = await ruleDocsPath(rule.pathSafeName);
|
|
256
|
+
docsPath = result.path;
|
|
257
|
+
} else {
|
|
258
|
+
docsPath = rule.module.meta?.docs?.url;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
const link = optionallyLinkTo(rule.ruleName, docsPath);
|
|
262
|
+
const description = rule.module.meta?.docs?.description || '';
|
|
263
|
+
const recommended = conditional('Yes', rule.module.meta?.docs?.recommended);
|
|
264
|
+
const fixable = conditional('Yes', rule.module.meta?.fixable);
|
|
265
|
+
const suggestions = conditional('Yes', rule.module.meta?.hasSuggestions);
|
|
266
|
+
|
|
267
|
+
rows.push(outdent`
|
|
317
268
|
| ${link} | ${description} | ${recommended} | ${fixable} | ${suggestions} |
|
|
318
269
|
`);
|
|
319
|
-
|
|
270
|
+
}
|
|
320
271
|
|
|
321
|
-
|
|
272
|
+
const code = outdent`
|
|
322
273
|
| Rule | Description | Recommended | Fixable | Suggestions |
|
|
323
274
|
| ---- | -- | -- | -- | -- |
|
|
324
275
|
${rows.join('\n')}
|
|
325
276
|
`;
|
|
326
277
|
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
);
|
|
278
|
+
const found = /<!-- START_RULE_TABLE_CODEGEN -->(.|\n)*<!-- END_RULE_TABLE_CODEGEN -->/.exec(
|
|
279
|
+
file,
|
|
280
|
+
);
|
|
331
281
|
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
);
|
|
336
|
-
}
|
|
282
|
+
if (!found) {
|
|
283
|
+
throw new Error(`invariant: could not find the partial codegen section in ${filepath}`);
|
|
284
|
+
}
|
|
337
285
|
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
286
|
+
const updatedFile = file.replace(
|
|
287
|
+
found[0],
|
|
288
|
+
outdent`
|
|
341
289
|
<!-- START_RULE_TABLE_CODEGEN -->
|
|
342
290
|
<!-- @codegenCommand ${codegenCommand} -->
|
|
343
291
|
${code}
|
|
344
292
|
<!-- END_RULE_TABLE_CODEGEN -->
|
|
345
293
|
`,
|
|
346
|
-
|
|
294
|
+
);
|
|
347
295
|
|
|
348
|
-
|
|
296
|
+
await writeFile(filepath, updatedFile);
|
|
349
297
|
}
|
|
350
298
|
|
|
351
299
|
const validateInternalRule = (rule: InternalRule) => {
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
);
|
|
368
|
-
}
|
|
300
|
+
if (typeof rule.ruleName !== 'string' || !rule.ruleName) {
|
|
301
|
+
throw new Error(
|
|
302
|
+
`invariant: The ${rule.pathSafeName} rule must use the createLintRule() function`,
|
|
303
|
+
);
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
if (ruleIsInternal(rule) && rule.pathSafeName !== rule.ruleName) {
|
|
307
|
+
throw new Error(
|
|
308
|
+
`invariant: module name ${rule.pathSafeName} does not match lint rule name ${rule.ruleName}`,
|
|
309
|
+
);
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
if (rule.pathSafeName.includes('@') || rule.pathSafeName.includes('/')) {
|
|
313
|
+
throw new Error(`invariant: name ${rule.pathSafeName} is not valid, specify a path-safe name`);
|
|
314
|
+
}
|
|
369
315
|
};
|
|
370
316
|
|
|
371
317
|
/**
|
|
372
318
|
* Fetch all rules in `rules/*` and generate all associated contents.
|
|
373
319
|
*/
|
|
374
320
|
async function generate() {
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
await generateRulePages(rules);
|
|
426
|
-
await generateRuleTable(join(srcDir, '../README.md'), 'repo', rules);
|
|
427
|
-
await generateRuleTable(
|
|
428
|
-
join(srcDir, '../constellation/index/overview.mdx'),
|
|
429
|
-
'docs',
|
|
430
|
-
rules,
|
|
431
|
-
);
|
|
321
|
+
const rulePaths = await fs.readdir(rulesDir);
|
|
322
|
+
const recommended: FoundRule[] = [];
|
|
323
|
+
const rules: FoundRule[] = [];
|
|
324
|
+
|
|
325
|
+
for (const filename of rulePaths) {
|
|
326
|
+
if (ignoreList.includes(filename)) {
|
|
327
|
+
continue;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
const dirname = filename.replace(extname(filename), '');
|
|
331
|
+
const filenameWithExt = filename.endsWith('.tsx') ? filename + '.tsx' : filename;
|
|
332
|
+
|
|
333
|
+
const rule: LintRule = (await import(join(rulesDir, filenameWithExt))).default;
|
|
334
|
+
|
|
335
|
+
const foundRule: InternalRule = {
|
|
336
|
+
module: rule,
|
|
337
|
+
pathSafeName: dirname,
|
|
338
|
+
ruleName: rule.name || rule.meta.name,
|
|
339
|
+
};
|
|
340
|
+
|
|
341
|
+
validateInternalRule(foundRule);
|
|
342
|
+
|
|
343
|
+
rules.push(foundRule);
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
for (const rule of externalRules) {
|
|
347
|
+
const foundRule: ExternalRule = {
|
|
348
|
+
module: { meta: rule },
|
|
349
|
+
pathSafeName: rule.displayName || getPathSafeName(rule.name),
|
|
350
|
+
ruleName: rule.name,
|
|
351
|
+
};
|
|
352
|
+
|
|
353
|
+
// We don't validate these; types should do their job instead.
|
|
354
|
+
rules.push(foundRule);
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
rules.forEach((rule) => {
|
|
358
|
+
if (rule.module.meta?.docs?.recommended) {
|
|
359
|
+
recommended.push(rule);
|
|
360
|
+
}
|
|
361
|
+
});
|
|
362
|
+
|
|
363
|
+
// NOTE: Some of these could be awaited in parallel, but it's not worth the complexity for <1s diff.
|
|
364
|
+
await generateRuleIndex(rules);
|
|
365
|
+
await generatePresetConfig('all', rules);
|
|
366
|
+
await generatePresetConfig('recommended', recommended);
|
|
367
|
+
await generatePluginIndex();
|
|
368
|
+
await generateRulePages(rules);
|
|
369
|
+
await generateRuleTable(join(srcDir, '../README.md'), 'repo', rules);
|
|
370
|
+
await generateRuleTable(join(srcDir, '../constellation/index/overview.mdx'), 'docs', rules);
|
|
432
371
|
}
|
|
433
372
|
|
|
434
373
|
generate();
|