@atlaskit/eslint-plugin-ui-styling-standard 0.3.0 → 0.4.0
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 +6 -0
- package/README.md +18 -5
- package/build/tsconfig.json +2 -4
- package/constellation/consistent-css-prop-usage/usage.mdx +5 -0
- package/constellation/index/overview.mdx +21 -0
- package/constellation/local-cx-xcss/usage.mdx +37 -0
- package/constellation/no-css-tagged-template-expression/usage.mdx +5 -0
- package/constellation/no-empty-styled-expression/usage.mdx +5 -0
- package/constellation/no-exported-css/usage.mdx +5 -0
- package/constellation/no-exported-keyframes/usage.mdx +5 -0
- package/constellation/no-invalid-css-map/usage.mdx +5 -0
- package/constellation/no-js-xcss/usage.mdx +23 -0
- package/constellation/no-keyframes-tagged-template-expression/usage.mdx +5 -0
- package/constellation/no-styled-tagged-template-expression/usage.mdx +5 -0
- package/constellation/no-suppress-xcss/usage.mdx +25 -0
- package/dist/cjs/index.codegen.js +26 -0
- package/dist/cjs/index.js +12 -33
- package/dist/cjs/presets/all.codegen.js +37 -0
- package/dist/cjs/presets/recommended.codegen.js +37 -0
- package/dist/cjs/rules/external-rules.js +143 -0
- package/dist/cjs/rules/index.codegen.js +16 -0
- package/dist/cjs/rules/local-cx-xcss/index.js +51 -0
- package/dist/cjs/rules/utils/create-rule.js +43 -0
- package/dist/cjs/rules/utils/is-supported-import.js +98 -0
- package/dist/es2019/index.codegen.js +12 -0
- package/dist/es2019/index.js +1 -33
- package/dist/es2019/presets/all.codegen.js +31 -0
- package/dist/es2019/presets/recommended.codegen.js +31 -0
- package/dist/es2019/rules/external-rules.js +138 -0
- package/dist/es2019/rules/index.codegen.js +9 -0
- package/dist/es2019/rules/local-cx-xcss/index.js +45 -0
- package/dist/es2019/rules/utils/create-rule.js +33 -0
- package/dist/es2019/rules/utils/is-supported-import.js +87 -0
- package/dist/esm/index.codegen.js +12 -0
- package/dist/esm/index.js +1 -33
- package/dist/esm/presets/all.codegen.js +31 -0
- package/dist/esm/presets/recommended.codegen.js +31 -0
- package/dist/esm/rules/external-rules.js +138 -0
- package/dist/esm/rules/index.codegen.js +9 -0
- package/dist/esm/rules/local-cx-xcss/index.js +45 -0
- package/dist/esm/rules/utils/create-rule.js +35 -0
- package/dist/esm/rules/utils/is-supported-import.js +90 -0
- package/dist/types/index.codegen.d.ts +55 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/presets/all.codegen.d.ts +32 -0
- package/dist/types/presets/recommended.codegen.d.ts +32 -0
- package/dist/types/rules/external-rules.d.ts +11 -0
- package/dist/types/rules/index.codegen.d.ts +4 -0
- package/dist/types/rules/local-cx-xcss/index.d.ts +3 -0
- package/dist/types/rules/utils/create-rule.d.ts +64 -0
- package/dist/types/rules/utils/is-supported-import.d.ts +34 -0
- package/dist/types-ts4.5/index.codegen.d.ts +55 -0
- package/dist/types-ts4.5/index.d.ts +1 -0
- package/dist/types-ts4.5/presets/all.codegen.d.ts +32 -0
- package/dist/types-ts4.5/presets/recommended.codegen.d.ts +32 -0
- package/dist/types-ts4.5/rules/external-rules.d.ts +11 -0
- package/dist/types-ts4.5/rules/index.codegen.d.ts +4 -0
- package/dist/types-ts4.5/rules/local-cx-xcss/index.d.ts +3 -0
- package/dist/types-ts4.5/rules/utils/create-rule.d.ts +64 -0
- package/dist/types-ts4.5/rules/utils/is-supported-import.d.ts +34 -0
- package/package.json +13 -4
- package/scripts/codegen.tsx +439 -0
- package/src/index.codegen.tsx +14 -0
- package/src/index.tsx +1 -51
- package/src/presets/all.codegen.tsx +67 -0
- package/src/presets/recommended.codegen.tsx +67 -0
- package/src/rules/TEMPLATE.md +29 -0
- package/src/rules/__tests__/utils/_tester.tsx +40 -0
- package/src/rules/external-rules.tsx +175 -0
- package/src/rules/index.codegen.tsx +10 -0
- package/src/rules/local-cx-xcss/README.md +35 -0
- package/src/rules/local-cx-xcss/__tests__/rule.test.tsx +102 -0
- package/src/rules/local-cx-xcss/index.tsx +69 -0
- package/src/rules/utils/create-rule.tsx +80 -0
- package/src/rules/utils/is-supported-import.tsx +130 -0
- package/tsconfig.app.json +5 -1
- package/tsconfig.dev.json +5 -1
- package/tsconfig.json +7 -6
- package/dist/types/src/index.d.ts +0 -29
- package/dist/types-ts4.5/src/index.d.ts +0 -29
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
+
* @codegen <<SignedSource::6b1418e07df6af9ad4cae4baf66739c1>>
|
|
4
|
+
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
|
+
*/
|
|
6
|
+
declare const _default: {
|
|
7
|
+
plugins: string[];
|
|
8
|
+
rules: {
|
|
9
|
+
'@atlaskit/ui-styling-standard/local-cx-xcss': string;
|
|
10
|
+
'@atlaskit/design-system/consistent-css-prop-usage': (string | {
|
|
11
|
+
excludeReactComponents: boolean;
|
|
12
|
+
})[];
|
|
13
|
+
'@atlaskit/design-system/no-css-tagged-template-expression': string;
|
|
14
|
+
'@atlaskit/design-system/no-keyframes-tagged-template-expression': string;
|
|
15
|
+
'@atlaskit/design-system/no-styled-tagged-template-expression': string;
|
|
16
|
+
'@compiled/no-suppress-xcss': string;
|
|
17
|
+
'@compiled/no-js-xcss': string;
|
|
18
|
+
'@atlaskit/design-system/no-empty-styled-expression': (string | {
|
|
19
|
+
importSources: string[];
|
|
20
|
+
})[];
|
|
21
|
+
'@atlaskit/design-system/no-exported-css': (string | {
|
|
22
|
+
importSources: string[];
|
|
23
|
+
})[];
|
|
24
|
+
'@atlaskit/design-system/no-exported-keyframes': (string | {
|
|
25
|
+
importSources: string[];
|
|
26
|
+
})[];
|
|
27
|
+
'@atlaskit/design-system/no-invalid-css-map': (string | {
|
|
28
|
+
allowedFunctionCalls: string[][];
|
|
29
|
+
})[];
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
export default _default;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
+
* @codegen <<SignedSource::6b1418e07df6af9ad4cae4baf66739c1>>
|
|
4
|
+
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
|
+
*/
|
|
6
|
+
declare const _default: {
|
|
7
|
+
plugins: string[];
|
|
8
|
+
rules: {
|
|
9
|
+
'@atlaskit/ui-styling-standard/local-cx-xcss': string;
|
|
10
|
+
'@atlaskit/design-system/consistent-css-prop-usage': (string | {
|
|
11
|
+
excludeReactComponents: boolean;
|
|
12
|
+
})[];
|
|
13
|
+
'@atlaskit/design-system/no-css-tagged-template-expression': string;
|
|
14
|
+
'@atlaskit/design-system/no-keyframes-tagged-template-expression': string;
|
|
15
|
+
'@atlaskit/design-system/no-styled-tagged-template-expression': string;
|
|
16
|
+
'@compiled/no-suppress-xcss': string;
|
|
17
|
+
'@compiled/no-js-xcss': string;
|
|
18
|
+
'@atlaskit/design-system/no-empty-styled-expression': (string | {
|
|
19
|
+
importSources: string[];
|
|
20
|
+
})[];
|
|
21
|
+
'@atlaskit/design-system/no-exported-css': (string | {
|
|
22
|
+
importSources: string[];
|
|
23
|
+
})[];
|
|
24
|
+
'@atlaskit/design-system/no-exported-keyframes': (string | {
|
|
25
|
+
importSources: string[];
|
|
26
|
+
})[];
|
|
27
|
+
'@atlaskit/design-system/no-invalid-css-map': (string | {
|
|
28
|
+
allowedFunctionCalls: string[][];
|
|
29
|
+
})[];
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
export default _default;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type LintRuleMeta } from './utils/create-rule';
|
|
2
|
+
/** External rules must be scoped, have a display name, and external urls. */
|
|
3
|
+
export type ExternalRuleMeta = LintRuleMeta & {
|
|
4
|
+
isExternal: true;
|
|
5
|
+
name: `@${string}/${string}`;
|
|
6
|
+
displayName: string;
|
|
7
|
+
docs: {
|
|
8
|
+
externalUrl: `https://${string}`;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
export declare const externalRules: ExternalRuleMeta[];
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { ESLintUtils } from '@typescript-eslint/utils';
|
|
2
|
+
import type { Rule } from 'eslint';
|
|
3
|
+
/**
|
|
4
|
+
* We are moving to our own small abstraction to create a lint rule that we have the power
|
|
5
|
+
* to change and mold to our own needs.
|
|
6
|
+
*
|
|
7
|
+
* @see createLintRule
|
|
8
|
+
*
|
|
9
|
+
* @private
|
|
10
|
+
* @deprecated
|
|
11
|
+
*/
|
|
12
|
+
export declare const createRule: <TOptions extends readonly unknown[], TMessageIds extends string, TRuleListener extends import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleListener = import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleListener>({ name, meta, ...rule }: Readonly<ESLintUtils.RuleWithMetaAndName<TOptions, TMessageIds, TRuleListener>>) => import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleModule<TMessageIds, TOptions, TRuleListener>;
|
|
13
|
+
export interface LintRule extends Omit<Rule.RuleModule, 'meta'> {
|
|
14
|
+
/**
|
|
15
|
+
* Including this for backwards compat moving from the typescript-eslint util.
|
|
16
|
+
*/
|
|
17
|
+
name?: never;
|
|
18
|
+
meta: LintRuleMeta;
|
|
19
|
+
}
|
|
20
|
+
export interface LintRuleMeta extends Omit<Rule.RuleMetaData, 'docs'> {
|
|
21
|
+
/**
|
|
22
|
+
* Name of the rule.
|
|
23
|
+
* Must match the folder it is in exactly else build will throw.
|
|
24
|
+
* Add an exception in codegen.tsx for nested rules.
|
|
25
|
+
*/
|
|
26
|
+
name: string;
|
|
27
|
+
docs: {
|
|
28
|
+
/**
|
|
29
|
+
* Short description of what this rule does.
|
|
30
|
+
*/
|
|
31
|
+
description: string;
|
|
32
|
+
/**
|
|
33
|
+
* Specifies the URL at which the full documentation can be accessed.
|
|
34
|
+
*/
|
|
35
|
+
url?: string | undefined;
|
|
36
|
+
/**
|
|
37
|
+
* If this rule should be in the recommended preset or not.
|
|
38
|
+
* Set to `false` to exclude it from the recommended preset.
|
|
39
|
+
*/
|
|
40
|
+
recommended: boolean;
|
|
41
|
+
/**
|
|
42
|
+
* The severity level to be applied to this rule.
|
|
43
|
+
* When setting to `"error"` it will mean releasing a breaking change.
|
|
44
|
+
*/
|
|
45
|
+
severity: 'error' | 'warn';
|
|
46
|
+
/**
|
|
47
|
+
* This is configuration passed into the plugin to configure the rule.
|
|
48
|
+
*
|
|
49
|
+
* Eg. `{ excludeReactComponents: true }` would be passed into the plugin config
|
|
50
|
+
*/
|
|
51
|
+
pluginConfig?: Record<string, any>;
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Tiny wrapped over the ESLint rule module type that ensures
|
|
56
|
+
* there is a docs link to our ESLint plugin documentation page,
|
|
57
|
+
* as well as improving type support.
|
|
58
|
+
*/
|
|
59
|
+
export declare const createLintRule: (rule: LintRule) => Rule.RuleModule;
|
|
60
|
+
export declare function getRuleUrl(ruleName: string): string;
|
|
61
|
+
/**
|
|
62
|
+
* If it's a nested rule, ensure the url is clean and safe for urls, file paths, etc.
|
|
63
|
+
*/
|
|
64
|
+
export declare function getPathSafeName(ruleName: string): string;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { Rule, Scope } from 'eslint';
|
|
2
|
+
import type { CallExpression } from 'estree';
|
|
3
|
+
type Callee = CallExpression['callee'];
|
|
4
|
+
type Reference = Scope.Reference;
|
|
5
|
+
export declare const CSS_IN_JS_IMPORTS: {
|
|
6
|
+
readonly compiled: "@compiled/react";
|
|
7
|
+
readonly emotionReact: "@emotion/react";
|
|
8
|
+
readonly emotionCore: "@emotion/core";
|
|
9
|
+
readonly styledComponents: "styled-components";
|
|
10
|
+
readonly atlaskitCss: "@atlaskit/css";
|
|
11
|
+
readonly atlaskitPrimitives: "@atlaskit/primitives";
|
|
12
|
+
};
|
|
13
|
+
export type ImportSource = string;
|
|
14
|
+
export type SupportedNameChecker = (nodeToCheck: Callee, referencesInScope: Reference[], importSources: ImportSource[]) => boolean;
|
|
15
|
+
export declare const DEFAULT_IMPORT_SOURCES: ImportSource[];
|
|
16
|
+
/**
|
|
17
|
+
* Given the ESLint rule context, extract and parse the value of the importSources rule option.
|
|
18
|
+
* The importSources option is used to define additional libraries for which an ESLint rule
|
|
19
|
+
* should apply to.
|
|
20
|
+
*
|
|
21
|
+
* Note that `@compiled/react` and `@atlaskit/css` are always included in importSources, regardless
|
|
22
|
+
* of what importSources is configured to by the user.
|
|
23
|
+
*
|
|
24
|
+
* @param context The rule context.
|
|
25
|
+
* @returns An array of strings representing what CSS-in-JS packages that should be checked, based
|
|
26
|
+
* on the rule options configuration.
|
|
27
|
+
*/
|
|
28
|
+
export declare const getImportSources: (context: Rule.RuleContext) => ImportSource[];
|
|
29
|
+
export declare const isCss: SupportedNameChecker;
|
|
30
|
+
export declare const isCxFunction: SupportedNameChecker;
|
|
31
|
+
export declare const isCssMap: SupportedNameChecker;
|
|
32
|
+
export declare const isKeyframes: SupportedNameChecker;
|
|
33
|
+
export declare const isStyled: SupportedNameChecker;
|
|
34
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/eslint-plugin-ui-styling-standard",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"author": "Atlassian Pty Ltd",
|
|
5
5
|
"description": "The eslint plugin to enforce and educate on Atlassian's UI Styling Standard",
|
|
6
6
|
"license": "UNLICENSED",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"main": "dist/cjs/index.js",
|
|
22
22
|
"module": "dist/esm/index.js",
|
|
23
23
|
"module:es2019": "dist/es2019/index.js",
|
|
24
|
-
"types": "dist/types/
|
|
24
|
+
"types": "dist/types/index.d.ts",
|
|
25
25
|
"typesVersions": {
|
|
26
26
|
">=4.5 <4.9": {
|
|
27
27
|
"*": [
|
|
@@ -36,16 +36,25 @@
|
|
|
36
36
|
".": "./src/index.tsx"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@babel/runtime": "^7.0.0"
|
|
39
|
+
"@babel/runtime": "^7.0.0",
|
|
40
|
+
"@typescript-eslint/utils": "^5.48.1"
|
|
40
41
|
},
|
|
41
42
|
"devDependencies": {
|
|
42
|
-
"@atlaskit/
|
|
43
|
+
"@atlaskit/ds-lib": "^2.2.0",
|
|
44
|
+
"@atlaskit/eslint-plugin-design-system": "^8.31.0",
|
|
43
45
|
"@atlassian/atlassian-frontend-prettier-config-1.0.1": "npm:@atlassian/atlassian-frontend-prettier-config@1.0.1",
|
|
46
|
+
"@atlassian/codegen": "*",
|
|
44
47
|
"@compiled/eslint-plugin": "^0.13.3",
|
|
45
48
|
"@types/eslint": "^8.4.5",
|
|
46
49
|
"eslint": "^7.7.0",
|
|
50
|
+
"lodash": "^4.17.21",
|
|
51
|
+
"outdent": "^0.5.0",
|
|
52
|
+
"prettier": "^2.8.0",
|
|
47
53
|
"tsconfig-paths": "^4.2.0",
|
|
48
54
|
"typescript": "~4.9.5"
|
|
49
55
|
},
|
|
56
|
+
"scripts": {
|
|
57
|
+
"codegen": "ts-node -r tsconfig-paths/register ./scripts/codegen.tsx"
|
|
58
|
+
},
|
|
50
59
|
"prettier": "@atlassian/atlassian-frontend-prettier-config-1.0.1"
|
|
51
60
|
}
|
|
@@ -0,0 +1,439 @@
|
|
|
1
|
+
import { existsSync } from 'fs';
|
|
2
|
+
import fs from 'fs/promises';
|
|
3
|
+
import { extname, join, relative } from 'path';
|
|
4
|
+
|
|
5
|
+
import camelCase from 'lodash/camelCase';
|
|
6
|
+
import outdent from 'outdent';
|
|
7
|
+
import { format, resolveConfig } from 'prettier';
|
|
8
|
+
|
|
9
|
+
import { createSignedArtifact } from '@atlassian/codegen';
|
|
10
|
+
|
|
11
|
+
import { type LintRule, getPathSafeName } from '../src/rules/utils/create-rule';
|
|
12
|
+
import {
|
|
13
|
+
externalRules,
|
|
14
|
+
type ExternalRuleMeta,
|
|
15
|
+
} from '../src/rules/external-rules';
|
|
16
|
+
|
|
17
|
+
const packagePluginName = '@atlaskit/eslint-plugin-ui-styling-standard';
|
|
18
|
+
const pluginName = packagePluginName.replace('/eslint-plugin-', '/');
|
|
19
|
+
const codegenCommand = `yarn workspace ${packagePluginName} codegen`;
|
|
20
|
+
|
|
21
|
+
interface FoundRule {
|
|
22
|
+
module: LintRule | { meta: ExternalRuleMeta };
|
|
23
|
+
/**
|
|
24
|
+
* This is used for the directory name, import path, and urls
|
|
25
|
+
*/
|
|
26
|
+
pathSafeName: string;
|
|
27
|
+
/**
|
|
28
|
+
* Friendly name that can include special characters
|
|
29
|
+
*/
|
|
30
|
+
ruleName: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* A rule that is externally referenced and distributed via dependencies rather than local.
|
|
35
|
+
* These come from `rules/external-rules.tsx`
|
|
36
|
+
*/
|
|
37
|
+
interface ExternalRule extends FoundRule {
|
|
38
|
+
module: { meta: ExternalRuleMeta };
|
|
39
|
+
}
|
|
40
|
+
interface InternalRule extends FoundRule {
|
|
41
|
+
module: LintRule;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
interface GeneratedConfig {
|
|
45
|
+
name: string;
|
|
46
|
+
path: string;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const ignoreList = [
|
|
50
|
+
'index.codegen.tsx',
|
|
51
|
+
'TEMPLATE.md',
|
|
52
|
+
'__tests__',
|
|
53
|
+
'utils',
|
|
54
|
+
'external-rules.tsx',
|
|
55
|
+
];
|
|
56
|
+
const srcDir = join(__dirname, '../src');
|
|
57
|
+
const rulesDir = join(srcDir, 'rules');
|
|
58
|
+
const presetsDir = join(srcDir, 'presets');
|
|
59
|
+
const generatedConfigs: GeneratedConfig[] = [];
|
|
60
|
+
|
|
61
|
+
function ruleIsExternal(rule: FoundRule | ExternalRule): rule is ExternalRule {
|
|
62
|
+
return 'isExternal' in rule.module.meta && !!rule.module.meta.isExternal;
|
|
63
|
+
}
|
|
64
|
+
function ruleIsInternal(rule: FoundRule | ExternalRule): rule is InternalRule {
|
|
65
|
+
return !ruleIsExternal(rule);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Get the path to, and file contents for, a rule's README.md file.
|
|
70
|
+
*/
|
|
71
|
+
async function ruleDocsPath(name: string) {
|
|
72
|
+
const absolutePath = join(rulesDir, name, 'README.md');
|
|
73
|
+
const relativePath = '.' + absolutePath.replace(process.cwd(), '');
|
|
74
|
+
|
|
75
|
+
try {
|
|
76
|
+
const file = await fs.readFile(absolutePath, 'utf-8');
|
|
77
|
+
return { path: relativePath, file };
|
|
78
|
+
} catch (_) {
|
|
79
|
+
throw new Error(
|
|
80
|
+
`invariant: rule ${name} should have docs at ${absolutePath}`,
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Generates the preset config, eg. `src/presets/all.codegen.tsx` and `src/presets/recommended.codegen.tsx`
|
|
87
|
+
*/
|
|
88
|
+
async function generatePresetConfig(
|
|
89
|
+
name: 'all' | 'recommended',
|
|
90
|
+
rules: FoundRule[],
|
|
91
|
+
) {
|
|
92
|
+
const externalScopes = externalRules
|
|
93
|
+
.filter((rule) => rule.name?.includes('/'))
|
|
94
|
+
.map((rule) => {
|
|
95
|
+
// Take the first part of the name, eg. `@atlaskit/design-system` and wrap it in quotes to be
|
|
96
|
+
const groups = rule.name.split('/');
|
|
97
|
+
return `'${groups.slice(0, groups.length - 1).join('/')}'`;
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
// NOTE: Given we have external plugins, we must include them as plugins as well./
|
|
101
|
+
const pluginList = [
|
|
102
|
+
`'${pluginName}'`,
|
|
103
|
+
...Array.from(new Set(externalScopes)),
|
|
104
|
+
];
|
|
105
|
+
|
|
106
|
+
const code = outdent`
|
|
107
|
+
export default {
|
|
108
|
+
plugins: [
|
|
109
|
+
${pluginList.join(',\n')}],
|
|
110
|
+
rules: {
|
|
111
|
+
${rules
|
|
112
|
+
.map((rule) => {
|
|
113
|
+
const { severity, recommended, pluginConfig } =
|
|
114
|
+
rule.module.meta?.docs || {};
|
|
115
|
+
|
|
116
|
+
// `recommended` is a snowflake at this stage ... it can be a string at runtime
|
|
117
|
+
// because of legacy `import { createRule } from 'utils/create-rule'` so we take
|
|
118
|
+
// into account this possibility (as a fallback) until everything is moved over
|
|
119
|
+
// to the new syntax
|
|
120
|
+
const calculatedSeverity =
|
|
121
|
+
severity ??
|
|
122
|
+
(typeof recommended === 'string' ? String(recommended) : 'error');
|
|
123
|
+
|
|
124
|
+
let ruleName = rule.ruleName;
|
|
125
|
+
if (ruleIsInternal(rule)) {
|
|
126
|
+
ruleName = `${pluginName}/${rule.ruleName}`;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if (typeof pluginConfig === 'object' && pluginConfig) {
|
|
130
|
+
return `'${ruleName}': ['${calculatedSeverity}', ${JSON.stringify(
|
|
131
|
+
pluginConfig,
|
|
132
|
+
)}]`;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
return `'${ruleName}': '${calculatedSeverity}'`;
|
|
136
|
+
})
|
|
137
|
+
.join(',')}
|
|
138
|
+
},
|
|
139
|
+
}
|
|
140
|
+
`;
|
|
141
|
+
|
|
142
|
+
const filepath = join(presetsDir, `${name}.codegen.tsx`);
|
|
143
|
+
await writeFile(filepath, code);
|
|
144
|
+
|
|
145
|
+
generatedConfigs.push({
|
|
146
|
+
name: camelCase(name),
|
|
147
|
+
path: './' + relative(srcDir, join(presetsDir, `${name}.codegen`)),
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Write contents to a given file, creating a signed artifact if it's not a markdown file.
|
|
153
|
+
*/
|
|
154
|
+
async function writeFile(filepath: string, code: string) {
|
|
155
|
+
const config = await resolveConfig(filepath);
|
|
156
|
+
await fs.writeFile(
|
|
157
|
+
filepath,
|
|
158
|
+
extname(filepath).includes('.md')
|
|
159
|
+
? format(code, {
|
|
160
|
+
...config,
|
|
161
|
+
filepath,
|
|
162
|
+
})
|
|
163
|
+
: createSignedArtifact(
|
|
164
|
+
format(code, {
|
|
165
|
+
...config,
|
|
166
|
+
filepath,
|
|
167
|
+
}),
|
|
168
|
+
codegenCommand,
|
|
169
|
+
),
|
|
170
|
+
);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Generates the `src/rules/index.codegen.tsx` entrypoint, exporting all rules.
|
|
175
|
+
*/
|
|
176
|
+
async function generateRuleIndex(rules: FoundRule[]) {
|
|
177
|
+
const internalRules = rules.filter(ruleIsInternal);
|
|
178
|
+
|
|
179
|
+
const code = outdent`
|
|
180
|
+
${internalRules
|
|
181
|
+
.map(
|
|
182
|
+
(rule) =>
|
|
183
|
+
`import ${camelCase(rule.pathSafeName)} from './${
|
|
184
|
+
rule.pathSafeName
|
|
185
|
+
}'`,
|
|
186
|
+
)
|
|
187
|
+
.join('\n')}
|
|
188
|
+
|
|
189
|
+
export default {
|
|
190
|
+
${internalRules
|
|
191
|
+
.map((rule) => `'${rule.ruleName}': ${camelCase(rule.pathSafeName)}`)
|
|
192
|
+
.join(',')}
|
|
193
|
+
}
|
|
194
|
+
`;
|
|
195
|
+
|
|
196
|
+
const filepath = join(rulesDir, 'index.codegen.tsx');
|
|
197
|
+
await writeFile(filepath, code);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Generates the `src/index.codegen.tsx` entrypoint, exporting all the preset configs.
|
|
202
|
+
*/
|
|
203
|
+
async function generatePluginIndex() {
|
|
204
|
+
const code = outdent`
|
|
205
|
+
${generatedConfigs
|
|
206
|
+
.map((config) => `import ${config.name} from '${config.path}'`)
|
|
207
|
+
.join('\n')}
|
|
208
|
+
|
|
209
|
+
export { default as rules } from './rules/index.codegen'
|
|
210
|
+
|
|
211
|
+
export const configs = {
|
|
212
|
+
${generatedConfigs.map((config) => `${config.name}`).join(',')}
|
|
213
|
+
}
|
|
214
|
+
`;
|
|
215
|
+
|
|
216
|
+
const filepath = join(srcDir, 'index.codegen.tsx');
|
|
217
|
+
await writeFile(filepath, code);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
const conditional = (cond: string, content?: boolean | string) =>
|
|
221
|
+
content ? cond : '';
|
|
222
|
+
const optionallyLinkTo = (content: string, url?: string) =>
|
|
223
|
+
url ? `<a href="${url}">${content}</a>` : content;
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Generate each individual rules' documentation pages, eg. `constellation/icon-label/usage.mdx`
|
|
227
|
+
*/
|
|
228
|
+
async function generateRulePages(rules: FoundRule[]): Promise<void> {
|
|
229
|
+
const docsDir = join(srcDir, '../constellation');
|
|
230
|
+
|
|
231
|
+
for await (const rule of rules) {
|
|
232
|
+
const ruleDir = join(docsDir, rule.pathSafeName);
|
|
233
|
+
const destination = join(ruleDir, 'usage.mdx');
|
|
234
|
+
await fs.mkdir(ruleDir, { recursive: true });
|
|
235
|
+
|
|
236
|
+
if (ruleIsExternal(rule)) {
|
|
237
|
+
await generateExternalRulePage(rule, destination);
|
|
238
|
+
} else if (ruleIsInternal(rule)) {
|
|
239
|
+
await generateInternalRulePage(rule, destination);
|
|
240
|
+
} else {
|
|
241
|
+
throw new Error(
|
|
242
|
+
`invariant: found an unexpected rule type ${rule.ruleName}`,
|
|
243
|
+
);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
async function generateExternalRulePage(
|
|
249
|
+
rule: ExternalRule,
|
|
250
|
+
destination: string,
|
|
251
|
+
) {
|
|
252
|
+
if (existsSync(destination)) {
|
|
253
|
+
return true;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
const ruleContent = outdent`
|
|
257
|
+
# ${rule.ruleName}
|
|
258
|
+
${rule.module.meta?.docs?.description || ''}
|
|
259
|
+
|
|
260
|
+
${
|
|
261
|
+
rule.module.meta?.docs?.externalUrl
|
|
262
|
+
? `This rule is maintained by another package and configured here, refer to ${rule.module.meta.docs.externalUrl} for more details`
|
|
263
|
+
: ''
|
|
264
|
+
}
|
|
265
|
+
`;
|
|
266
|
+
|
|
267
|
+
await writeFile(destination, ruleContent);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
async function generateInternalRulePage(
|
|
271
|
+
rule: InternalRule,
|
|
272
|
+
destination: string,
|
|
273
|
+
) {
|
|
274
|
+
const { file } = await ruleDocsPath(rule.pathSafeName);
|
|
275
|
+
if (file.match(/^# /)) {
|
|
276
|
+
throw new Error(
|
|
277
|
+
`invariant: ${rule.pathSafeName} README doc should not include a h1 heading as it is injected automatically.`,
|
|
278
|
+
);
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
const ruleContent = outdent`
|
|
282
|
+
# ${rule.ruleName}
|
|
283
|
+
${file}
|
|
284
|
+
`;
|
|
285
|
+
|
|
286
|
+
await writeFile(destination, ruleContent);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* Generates the `RULE_TABLE_CODEGEN` in `constellation/index/usage.mdx` and `README.md`.
|
|
291
|
+
* This is the list of all rules and their metadata.
|
|
292
|
+
*/
|
|
293
|
+
async function generateRuleTable(
|
|
294
|
+
filepath: string,
|
|
295
|
+
linkTo: 'docs' | 'repo',
|
|
296
|
+
rules: FoundRule[],
|
|
297
|
+
) {
|
|
298
|
+
const file = await fs.readFile(filepath, 'utf-8');
|
|
299
|
+
const rows: string[] = [];
|
|
300
|
+
|
|
301
|
+
for (const rule of rules) {
|
|
302
|
+
let docsPath: string | undefined;
|
|
303
|
+
|
|
304
|
+
if (linkTo === 'docs') {
|
|
305
|
+
// We want `<a href="consistent-css-prop-usage/usage">consistent-css-prop-usage</a>` for the link
|
|
306
|
+
// to resolve to `/components/eslint-plugin-design-system/consistent-css-prop-usage/usage`
|
|
307
|
+
docsPath = `${rule.pathSafeName}/usage`;
|
|
308
|
+
} else if (ruleIsInternal(rule)) {
|
|
309
|
+
const result = await ruleDocsPath(rule.pathSafeName);
|
|
310
|
+
docsPath = result.path;
|
|
311
|
+
} else {
|
|
312
|
+
docsPath = rule.module.meta?.docs?.url;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
const link = optionallyLinkTo(rule.ruleName, docsPath);
|
|
316
|
+
const description = rule.module.meta?.docs?.description || '';
|
|
317
|
+
const recommended = conditional('Yes', rule.module.meta?.docs?.recommended);
|
|
318
|
+
const fixable = conditional('Yes', rule.module.meta?.fixable);
|
|
319
|
+
const suggestions = conditional('Yes', rule.module.meta?.hasSuggestions);
|
|
320
|
+
|
|
321
|
+
rows.push(outdent`
|
|
322
|
+
| ${link} | ${description} | ${recommended} | ${fixable} | ${suggestions} |
|
|
323
|
+
`);
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
const code = outdent`
|
|
327
|
+
| Rule | Description | Recommended | Fixable | Suggestions |
|
|
328
|
+
| ---- | -- | -- | -- | -- |
|
|
329
|
+
${rows.join('\n')}
|
|
330
|
+
`;
|
|
331
|
+
|
|
332
|
+
const found =
|
|
333
|
+
/<!-- START_RULE_TABLE_CODEGEN -->(.|\n)*<!-- END_RULE_TABLE_CODEGEN -->/.exec(
|
|
334
|
+
file,
|
|
335
|
+
);
|
|
336
|
+
|
|
337
|
+
if (!found) {
|
|
338
|
+
throw new Error(
|
|
339
|
+
`invariant: could not find the partial codegen section in ${filepath}`,
|
|
340
|
+
);
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
const updatedFile = file.replace(
|
|
344
|
+
found[0],
|
|
345
|
+
outdent`
|
|
346
|
+
<!-- START_RULE_TABLE_CODEGEN -->
|
|
347
|
+
<!-- @codegenCommand ${codegenCommand} -->
|
|
348
|
+
${code}
|
|
349
|
+
<!-- END_RULE_TABLE_CODEGEN -->
|
|
350
|
+
`,
|
|
351
|
+
);
|
|
352
|
+
|
|
353
|
+
await writeFile(filepath, updatedFile);
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
const validateInternalRule = (rule: InternalRule) => {
|
|
357
|
+
if (typeof rule.ruleName !== 'string' || !rule.ruleName) {
|
|
358
|
+
throw new Error(
|
|
359
|
+
`invariant: The ${rule.pathSafeName} rule must use the createLintRule() function`,
|
|
360
|
+
);
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
if (ruleIsInternal(rule) && rule.pathSafeName !== rule.ruleName) {
|
|
364
|
+
throw new Error(
|
|
365
|
+
`invariant: module name ${rule.pathSafeName} does not match lint rule name ${rule.ruleName}`,
|
|
366
|
+
);
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
if (rule.pathSafeName.includes('@') || rule.pathSafeName.includes('/')) {
|
|
370
|
+
throw new Error(
|
|
371
|
+
`invariant: name ${rule.pathSafeName} is not valid, specify a path-safe name`,
|
|
372
|
+
);
|
|
373
|
+
}
|
|
374
|
+
};
|
|
375
|
+
|
|
376
|
+
/**
|
|
377
|
+
* Fetch all rules in `rules/*` and generate all associated contents.
|
|
378
|
+
*/
|
|
379
|
+
async function generate() {
|
|
380
|
+
const rulePaths = await fs.readdir(rulesDir);
|
|
381
|
+
const recommended: FoundRule[] = [];
|
|
382
|
+
const rules: FoundRule[] = [];
|
|
383
|
+
|
|
384
|
+
for (const filename of rulePaths) {
|
|
385
|
+
if (ignoreList.includes(filename)) {
|
|
386
|
+
continue;
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
const dirname = filename.replace(extname(filename), '');
|
|
390
|
+
const filenameWithExt = filename.endsWith('.tsx')
|
|
391
|
+
? filename + '.tsx'
|
|
392
|
+
: filename;
|
|
393
|
+
|
|
394
|
+
const rule: LintRule = (await import(join(rulesDir, filenameWithExt)))
|
|
395
|
+
.default;
|
|
396
|
+
|
|
397
|
+
const foundRule: InternalRule = {
|
|
398
|
+
module: rule,
|
|
399
|
+
pathSafeName: dirname,
|
|
400
|
+
ruleName: rule.name || rule.meta.name,
|
|
401
|
+
};
|
|
402
|
+
|
|
403
|
+
validateInternalRule(foundRule);
|
|
404
|
+
|
|
405
|
+
rules.push(foundRule);
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
for (const rule of externalRules) {
|
|
409
|
+
const foundRule: ExternalRule = {
|
|
410
|
+
module: { meta: rule },
|
|
411
|
+
pathSafeName: rule.displayName || getPathSafeName(rule.name),
|
|
412
|
+
ruleName: rule.name,
|
|
413
|
+
};
|
|
414
|
+
|
|
415
|
+
// We don't validate these; types should do their job instead.
|
|
416
|
+
rules.push(foundRule);
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
rules.forEach((rule) => {
|
|
420
|
+
if (rule.module.meta?.docs?.recommended) {
|
|
421
|
+
recommended.push(rule);
|
|
422
|
+
}
|
|
423
|
+
});
|
|
424
|
+
|
|
425
|
+
// NOTE: Some of these could be awaited in parallel, but it's not worth the complexity for <1s diff.
|
|
426
|
+
await generateRuleIndex(rules);
|
|
427
|
+
await generatePresetConfig('all', rules);
|
|
428
|
+
await generatePresetConfig('recommended', recommended);
|
|
429
|
+
await generatePluginIndex();
|
|
430
|
+
await generateRulePages(rules);
|
|
431
|
+
await generateRuleTable(join(srcDir, '../README.md'), 'repo', rules);
|
|
432
|
+
await generateRuleTable(
|
|
433
|
+
join(srcDir, '../constellation/index/overview.mdx'),
|
|
434
|
+
'docs',
|
|
435
|
+
rules,
|
|
436
|
+
);
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
generate();
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
+
* @codegen <<SignedSource::3fd41935576c9346ca1f1e0c787a0a48>>
|
|
4
|
+
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
|
+
*/
|
|
6
|
+
import all from './presets/all.codegen';
|
|
7
|
+
import recommended from './presets/recommended.codegen';
|
|
8
|
+
|
|
9
|
+
export { default as rules } from './rules/index.codegen';
|
|
10
|
+
|
|
11
|
+
export const configs = {
|
|
12
|
+
all,
|
|
13
|
+
recommended,
|
|
14
|
+
};
|