@atlaskit/eslint-plugin-design-system 8.26.0 → 8.28.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 +31 -0
- package/README.md +31 -29
- package/constellation/consistent-css-prop-usage/usage.mdx +193 -0
- package/constellation/ensure-design-token-usage/usage.mdx +72 -0
- package/constellation/ensure-design-token-usage-preview/usage.mdx +5 -0
- package/constellation/icon-label/usage.mdx +39 -0
- package/constellation/index/usage.mdx +31 -1474
- package/constellation/local-cx-xcss/usage.mdx +37 -0
- package/constellation/no-banned-imports/usage.mdx +17 -0
- package/constellation/no-css-tagged-template-expression/usage.mdx +66 -0
- package/constellation/no-deprecated-apis/usage.mdx +76 -0
- package/constellation/no-deprecated-design-token-usage/usage.mdx +27 -0
- package/constellation/no-deprecated-imports/usage.mdx +62 -0
- package/constellation/no-empty-styled-expression/usage.mdx +77 -0
- package/constellation/no-exported-css/usage.mdx +50 -0
- package/constellation/no-exported-keyframes/usage.mdx +50 -0
- package/constellation/no-invalid-css-map/usage.mdx +199 -0
- package/constellation/no-keyframes-tagged-template-expression/usage.mdx +76 -0
- package/constellation/no-margin/usage.mdx +20 -0
- package/constellation/no-nested-styles/usage.mdx +47 -0
- package/constellation/no-physical-properties/usage.mdx +53 -0
- package/constellation/no-styled-tagged-template-expression/usage.mdx +90 -0
- package/constellation/no-unsafe-design-token-usage/usage.mdx +49 -0
- package/constellation/no-unsafe-style-overrides/usage.mdx +49 -0
- package/constellation/no-unsupported-drag-and-drop-libraries/usage.mdx +17 -0
- package/constellation/prefer-primitives/usage.mdx +31 -0
- package/constellation/use-button-group-label/usage.mdx +58 -0
- package/constellation/use-drawer-label/usage.mdx +53 -0
- package/constellation/use-heading-level-in-spotlight-card/usage.mdx +20 -0
- package/constellation/use-href-in-link-item/usage.mdx +18 -0
- package/constellation/use-primitives/usage.mdx +77 -0
- package/constellation/use-visually-hidden/usage.mdx +34 -0
- package/dist/cjs/presets/all.codegen.js +3 -1
- package/dist/cjs/rules/consistent-css-prop-usage/index.js +254 -32
- package/dist/cjs/rules/index.codegen.js +5 -1
- package/dist/cjs/rules/no-css-tagged-template-expression/index.js +3 -2
- package/dist/cjs/rules/no-keyframes-tagged-template-expression/index.js +27 -0
- package/dist/cjs/rules/no-styled-tagged-template-expression/index.js +27 -0
- package/dist/cjs/rules/no-styled-tagged-template-expression/is-styled.js +53 -0
- package/dist/cjs/rules/utils/create-no-exported-rule/is-styled-component.js +6 -10
- package/dist/cjs/rules/{no-css-tagged-template-expression → utils}/create-no-tagged-template-expression-rule/index.js +26 -6
- package/dist/cjs/rules/{no-css-tagged-template-expression → utils}/create-no-tagged-template-expression-rule/to-arguments.js +28 -2
- package/dist/cjs/rules/utils/create-rule.js +7 -5
- package/dist/cjs/rules/utils/get-first-supported-import.js +28 -0
- package/dist/cjs/rules/utils/is-supported-import.js +9 -11
- package/dist/es2019/presets/all.codegen.js +3 -1
- package/dist/es2019/rules/consistent-css-prop-usage/index.js +251 -33
- package/dist/es2019/rules/index.codegen.js +5 -1
- package/dist/es2019/rules/no-css-tagged-template-expression/index.js +3 -2
- package/dist/es2019/rules/no-keyframes-tagged-template-expression/index.js +21 -0
- package/dist/es2019/rules/no-styled-tagged-template-expression/index.js +21 -0
- package/dist/es2019/rules/no-styled-tagged-template-expression/is-styled.js +45 -0
- package/dist/es2019/rules/utils/create-no-exported-rule/is-styled-component.js +4 -8
- package/dist/es2019/rules/utils/create-no-tagged-template-expression-rule/index.js +84 -0
- package/dist/es2019/rules/{no-css-tagged-template-expression → utils}/create-no-tagged-template-expression-rule/to-arguments.js +28 -2
- package/dist/es2019/rules/utils/create-rule.js +7 -5
- package/dist/es2019/rules/utils/get-first-supported-import.js +22 -0
- package/dist/es2019/rules/utils/is-supported-import.js +9 -9
- package/dist/esm/presets/all.codegen.js +3 -1
- package/dist/esm/rules/consistent-css-prop-usage/index.js +255 -33
- package/dist/esm/rules/index.codegen.js +5 -1
- package/dist/esm/rules/no-css-tagged-template-expression/index.js +3 -2
- package/dist/esm/rules/no-keyframes-tagged-template-expression/index.js +21 -0
- package/dist/esm/rules/no-styled-tagged-template-expression/index.js +21 -0
- package/dist/esm/rules/no-styled-tagged-template-expression/is-styled.js +47 -0
- package/dist/esm/rules/utils/create-no-exported-rule/is-styled-component.js +6 -10
- package/dist/esm/rules/{no-css-tagged-template-expression → utils}/create-no-tagged-template-expression-rule/index.js +25 -5
- package/dist/esm/rules/{no-css-tagged-template-expression → utils}/create-no-tagged-template-expression-rule/to-arguments.js +28 -2
- package/dist/esm/rules/utils/create-rule.js +7 -5
- package/dist/esm/rules/utils/get-first-supported-import.js +22 -0
- package/dist/esm/rules/utils/is-supported-import.js +9 -10
- package/dist/types/index.codegen.d.ts +2 -0
- package/dist/types/presets/all.codegen.d.ts +3 -1
- package/dist/types/rules/consistent-css-prop-usage/types.d.ts +7 -2
- package/dist/types/rules/index.codegen.d.ts +2 -0
- package/dist/types/rules/no-keyframes-tagged-template-expression/index.d.ts +2 -0
- package/dist/types/rules/no-styled-tagged-template-expression/index.d.ts +2 -0
- package/dist/types/rules/no-styled-tagged-template-expression/is-styled.d.ts +7 -0
- package/dist/types/rules/use-primitives/utils/update-jsx-attribute-by-name.d.ts +1 -1
- package/dist/types/rules/{no-css-tagged-template-expression → utils}/create-no-tagged-template-expression-rule/index.d.ts +3 -1
- package/dist/types/rules/{no-css-tagged-template-expression → utils}/create-no-tagged-template-expression-rule/types.d.ts +3 -0
- package/dist/types/rules/utils/get-first-supported-import.d.ts +17 -0
- package/dist/types/rules/utils/is-supported-import.d.ts +6 -5
- package/dist/types-ts4.5/index.codegen.d.ts +2 -0
- package/dist/types-ts4.5/presets/all.codegen.d.ts +3 -1
- package/dist/types-ts4.5/rules/consistent-css-prop-usage/types.d.ts +7 -2
- package/dist/types-ts4.5/rules/index.codegen.d.ts +2 -0
- package/dist/types-ts4.5/rules/no-keyframes-tagged-template-expression/index.d.ts +2 -0
- package/dist/types-ts4.5/rules/no-styled-tagged-template-expression/index.d.ts +2 -0
- package/dist/types-ts4.5/rules/no-styled-tagged-template-expression/is-styled.d.ts +7 -0
- package/dist/types-ts4.5/rules/use-primitives/utils/update-jsx-attribute-by-name.d.ts +1 -1
- package/dist/types-ts4.5/rules/{no-css-tagged-template-expression → utils}/create-no-tagged-template-expression-rule/index.d.ts +3 -1
- package/dist/types-ts4.5/rules/{no-css-tagged-template-expression → utils}/create-no-tagged-template-expression-rule/types.d.ts +3 -0
- package/dist/types-ts4.5/rules/utils/get-first-supported-import.d.ts +17 -0
- package/dist/types-ts4.5/rules/utils/is-supported-import.d.ts +6 -5
- package/package.json +3 -1
- package/dist/es2019/rules/no-css-tagged-template-expression/create-no-tagged-template-expression-rule/index.js +0 -62
- /package/dist/cjs/rules/{no-css-tagged-template-expression → utils}/create-no-tagged-template-expression-rule/generate.js +0 -0
- /package/dist/cjs/rules/{no-css-tagged-template-expression → utils}/create-no-tagged-template-expression-rule/get-tagged-template-expression-offset.js +0 -0
- /package/dist/cjs/rules/{no-css-tagged-template-expression → utils}/create-no-tagged-template-expression-rule/types.js +0 -0
- /package/dist/es2019/rules/{no-css-tagged-template-expression → utils}/create-no-tagged-template-expression-rule/generate.js +0 -0
- /package/dist/es2019/rules/{no-css-tagged-template-expression → utils}/create-no-tagged-template-expression-rule/get-tagged-template-expression-offset.js +0 -0
- /package/dist/es2019/rules/{no-css-tagged-template-expression → utils}/create-no-tagged-template-expression-rule/types.js +0 -0
- /package/dist/esm/rules/{no-css-tagged-template-expression → utils}/create-no-tagged-template-expression-rule/generate.js +0 -0
- /package/dist/esm/rules/{no-css-tagged-template-expression → utils}/create-no-tagged-template-expression-rule/get-tagged-template-expression-offset.js +0 -0
- /package/dist/esm/rules/{no-css-tagged-template-expression → utils}/create-no-tagged-template-expression-rule/types.js +0 -0
- /package/dist/types/rules/{no-css-tagged-template-expression → utils}/create-no-tagged-template-expression-rule/generate.d.ts +0 -0
- /package/dist/types/rules/{no-css-tagged-template-expression → utils}/create-no-tagged-template-expression-rule/get-tagged-template-expression-offset.d.ts +0 -0
- /package/dist/types/rules/{no-css-tagged-template-expression → utils}/create-no-tagged-template-expression-rule/to-arguments.d.ts +0 -0
- /package/dist/types-ts4.5/rules/{no-css-tagged-template-expression → utils}/create-no-tagged-template-expression-rule/generate.d.ts +0 -0
- /package/dist/types-ts4.5/rules/{no-css-tagged-template-expression → utils}/create-no-tagged-template-expression-rule/get-tagged-template-expression-offset.d.ts +0 -0
- /package/dist/types-ts4.5/rules/{no-css-tagged-template-expression → utils}/create-no-tagged-template-expression-rule/to-arguments.d.ts +0 -0
|
@@ -49,7 +49,30 @@ var getArguments = function getArguments(chars) {
|
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
51
|
var getValue = function getValue() {
|
|
52
|
-
|
|
52
|
+
/**
|
|
53
|
+
* This branch is required for handling interpolated functions:
|
|
54
|
+
*
|
|
55
|
+
* css`
|
|
56
|
+
* color: ${(props) => props.textColor}
|
|
57
|
+
* `
|
|
58
|
+
*
|
|
59
|
+
* But it also breaks interpolations of multiple tokens:
|
|
60
|
+
*
|
|
61
|
+
* css`
|
|
62
|
+
* padding: ${token('space.100')} ${token('space.200')}
|
|
63
|
+
* `
|
|
64
|
+
*
|
|
65
|
+
* which becomes invalid syntax:
|
|
66
|
+
*
|
|
67
|
+
* css({
|
|
68
|
+
* padding: token('space.100')token('space.200')
|
|
69
|
+
* })
|
|
70
|
+
*
|
|
71
|
+
* Limiting this branch to when `expressions.length === 1` seems
|
|
72
|
+
* to allow both cases to work. There may be other edge cases,
|
|
73
|
+
* but none were caught by the existing test suite.
|
|
74
|
+
*/
|
|
75
|
+
if (!value.trim().length && expressions.length === 1) {
|
|
53
76
|
return {
|
|
54
77
|
type: 'expression',
|
|
55
78
|
expression: expressions.map(function (e) {
|
|
@@ -177,7 +200,10 @@ export var toArguments = function toArguments(source, template) {
|
|
|
177
200
|
i = _step4$value[0],
|
|
178
201
|
quasi = _step4$value[1];
|
|
179
202
|
// Deal with selectors across multiple lines
|
|
180
|
-
var styleTemplateElement = quasi.value.raw.replace(
|
|
203
|
+
var styleTemplateElement = quasi.value.raw.replace(/\/\*(.|\n|\r)*?\*\//g, '') // Removes multi-line comments
|
|
204
|
+
// Remove single line comments
|
|
205
|
+
// Negative lookbehind to handle URL-like double slashes
|
|
206
|
+
.replace(/(?<!https?:)\/\/.*$/gm, '').replace(/(\r\n|\n|\r)/gm, ' ').replace(/\s+/g, ' ');
|
|
181
207
|
var _iterator5 = _createForOfIteratorHelper(styleTemplateElement),
|
|
182
208
|
_step5;
|
|
183
209
|
try {
|
|
@@ -11,7 +11,7 @@ import { ESLintUtils } from '@typescript-eslint/utils';
|
|
|
11
11
|
* @deprecated
|
|
12
12
|
*/
|
|
13
13
|
export var createRule = ESLintUtils.RuleCreator(function (name) {
|
|
14
|
-
return
|
|
14
|
+
return getRuleUrl(name);
|
|
15
15
|
});
|
|
16
16
|
/**
|
|
17
17
|
* Tiny wrapped over the ESLint rule module type that ensures
|
|
@@ -19,8 +19,10 @@ export var createRule = ESLintUtils.RuleCreator(function (name) {
|
|
|
19
19
|
* as well as improving type support.
|
|
20
20
|
*/
|
|
21
21
|
export var createLintRule = function createLintRule(rule) {
|
|
22
|
-
|
|
23
|
-
var url = "https://atlassian.design/components/eslint-plugin-design-system/usage#".concat(ruleName);
|
|
24
|
-
rule.meta.docs.url = url;
|
|
22
|
+
rule.meta.docs.url = getRuleUrl(rule.meta.name);
|
|
25
23
|
return rule;
|
|
26
|
-
};
|
|
24
|
+
};
|
|
25
|
+
function getRuleUrl(ruleName) {
|
|
26
|
+
var name = ruleName.replace('/', '-'); // If it's a nested rule, ensure the url is clean and matches codegen/gatsby
|
|
27
|
+
return "https://atlassian.design/components/eslint-plugin-design-system/".concat(name, "/usage");
|
|
28
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { isNodeOfType } from 'eslint-codemod-utils';
|
|
2
|
+
/**
|
|
3
|
+
* Get the first import declaration in the file that matches any of the packages
|
|
4
|
+
* in `importSources`.
|
|
5
|
+
*
|
|
6
|
+
* @param context Rule context.
|
|
7
|
+
* @param importSources The packages to check import statements for. If importSources
|
|
8
|
+
* contains more than one package, the first import statement
|
|
9
|
+
* detected in the file that matches any of the packages will be
|
|
10
|
+
* returned.
|
|
11
|
+
* @returns The first import declaration found in the file.
|
|
12
|
+
*/
|
|
13
|
+
export var getFirstSupportedImport = function getFirstSupportedImport(context, importSources) {
|
|
14
|
+
var isSupportedImport = function isSupportedImport(node) {
|
|
15
|
+
return isNodeOfType(node, 'ImportDeclaration') && typeof node.source.value === 'string' && importSources.includes(node.source.value);
|
|
16
|
+
};
|
|
17
|
+
var source = context.getSourceCode();
|
|
18
|
+
var supportedImports = source.ast.body.filter(isSupportedImport);
|
|
19
|
+
if (supportedImports.length) {
|
|
20
|
+
return supportedImports[0];
|
|
21
|
+
}
|
|
22
|
+
};
|
|
@@ -1,26 +1,25 @@
|
|
|
1
|
-
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
2
1
|
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
3
2
|
|
|
4
3
|
export var CSS_IN_JS_IMPORTS = {
|
|
5
4
|
compiled: '@compiled/react',
|
|
6
5
|
emotionReact: '@emotion/react',
|
|
7
6
|
emotionCore: '@emotion/core',
|
|
7
|
+
emotionStyled: '@emotion/styled',
|
|
8
8
|
styledComponents: 'styled-components',
|
|
9
|
-
atlaskitCss: '@atlaskit/css'
|
|
9
|
+
atlaskitCss: '@atlaskit/css',
|
|
10
|
+
atlaskitPrimitives: '@atlaskit/primitives'
|
|
10
11
|
};
|
|
11
12
|
|
|
12
13
|
// A CSS-in-JS library an import of a valid css, cx, cssMap, etc.
|
|
13
14
|
// function might originate from, e.g. @compiled/react, @emotion/core.
|
|
14
|
-
|
|
15
|
-
|
|
15
|
+
/**
|
|
16
|
+
* By default all known import sources are checked against.
|
|
17
|
+
*/
|
|
18
|
+
export var DEFAULT_IMPORT_SOURCES = Object.values(CSS_IN_JS_IMPORTS);
|
|
16
19
|
|
|
17
20
|
/**
|
|
18
21
|
* Given the ESLint rule context, extract and parse the value of the importSources rule option.
|
|
19
|
-
* The importSources option is used to
|
|
20
|
-
* should apply to.
|
|
21
|
-
*
|
|
22
|
-
* Note that `@compiled/react` and `@atlaskit/css` are always included in importSources, regardless
|
|
23
|
-
* of what importSources is configured to by the user.
|
|
22
|
+
* The importSources option is used to override which libraries an ESLint rule applies to.
|
|
24
23
|
*
|
|
25
24
|
* @param context The rule context.
|
|
26
25
|
* @returns An array of strings representing what CSS-in-JS packages that should be checked, based
|
|
@@ -32,7 +31,7 @@ export var getImportSources = function getImportSources(context) {
|
|
|
32
31
|
return DEFAULT_IMPORT_SOURCES;
|
|
33
32
|
}
|
|
34
33
|
if (options[0].importSources && Array.isArray(options[0].importSources)) {
|
|
35
|
-
return
|
|
34
|
+
return options[0].importSources;
|
|
36
35
|
}
|
|
37
36
|
return DEFAULT_IMPORT_SOURCES;
|
|
38
37
|
};
|
|
@@ -17,9 +17,11 @@ export declare const configs: {
|
|
|
17
17
|
'@atlaskit/design-system/no-exported-css': string;
|
|
18
18
|
'@atlaskit/design-system/no-exported-keyframes': string;
|
|
19
19
|
'@atlaskit/design-system/no-invalid-css-map': string;
|
|
20
|
+
'@atlaskit/design-system/no-keyframes-tagged-template-expression': string;
|
|
20
21
|
'@atlaskit/design-system/no-margin': string;
|
|
21
22
|
'@atlaskit/design-system/no-nested-styles': string;
|
|
22
23
|
'@atlaskit/design-system/no-physical-properties': string;
|
|
24
|
+
'@atlaskit/design-system/no-styled-tagged-template-expression': string;
|
|
23
25
|
'@atlaskit/design-system/no-unsafe-design-token-usage': string;
|
|
24
26
|
'@atlaskit/design-system/no-unsafe-style-overrides': string;
|
|
25
27
|
'@atlaskit/design-system/no-unsupported-drag-and-drop-libraries': string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
-
* @codegen <<SignedSource::
|
|
3
|
+
* @codegen <<SignedSource::5647ce9c10ba880cffece66b5924fd6e>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
|
|
5
5
|
*/
|
|
6
6
|
declare const _default: {
|
|
@@ -20,9 +20,11 @@ declare const _default: {
|
|
|
20
20
|
'@atlaskit/design-system/no-exported-css': string;
|
|
21
21
|
'@atlaskit/design-system/no-exported-keyframes': string;
|
|
22
22
|
'@atlaskit/design-system/no-invalid-css-map': string;
|
|
23
|
+
'@atlaskit/design-system/no-keyframes-tagged-template-expression': string;
|
|
23
24
|
'@atlaskit/design-system/no-margin': string;
|
|
24
25
|
'@atlaskit/design-system/no-nested-styles': string;
|
|
25
26
|
'@atlaskit/design-system/no-physical-properties': string;
|
|
27
|
+
'@atlaskit/design-system/no-styled-tagged-template-expression': string;
|
|
26
28
|
'@atlaskit/design-system/no-unsafe-design-token-usage': string;
|
|
27
29
|
'@atlaskit/design-system/no-unsafe-style-overrides': string;
|
|
28
30
|
'@atlaskit/design-system/no-unsupported-drag-and-drop-libraries': string;
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
+
import type { ImportSource } from '../utils/is-supported-import';
|
|
1
2
|
export type RuleConfig = {
|
|
2
|
-
cssFunctions
|
|
3
|
-
stylesPlacement
|
|
3
|
+
cssFunctions: string[];
|
|
4
|
+
stylesPlacement: 'top' | 'bottom';
|
|
5
|
+
cssImportSource: ImportSource;
|
|
6
|
+
xcssImportSource: ImportSource;
|
|
7
|
+
excludeReactComponents: boolean;
|
|
8
|
+
fixNamesOnly: boolean;
|
|
4
9
|
};
|
|
@@ -17,9 +17,11 @@ declare const _default: {
|
|
|
17
17
|
'no-exported-css': import("eslint").Rule.RuleModule;
|
|
18
18
|
'no-exported-keyframes': import("eslint").Rule.RuleModule;
|
|
19
19
|
'no-invalid-css-map': import("eslint").Rule.RuleModule;
|
|
20
|
+
'no-keyframes-tagged-template-expression': import("eslint").Rule.RuleModule;
|
|
20
21
|
'no-margin': import("eslint").Rule.RuleModule;
|
|
21
22
|
'no-nested-styles': import("eslint").Rule.RuleModule;
|
|
22
23
|
'no-physical-properties': import("eslint").Rule.RuleModule;
|
|
24
|
+
'no-styled-tagged-template-expression': import("eslint").Rule.RuleModule;
|
|
23
25
|
'no-unsafe-design-token-usage': import("eslint").Rule.RuleModule;
|
|
24
26
|
'no-unsafe-style-overrides': import("eslint").Rule.RuleModule;
|
|
25
27
|
'no-unsupported-drag-and-drop-libraries': import("eslint").Rule.RuleModule;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Scope } from 'eslint';
|
|
2
|
+
import type { CallExpression } from 'estree';
|
|
3
|
+
import { ImportSource } from '../utils/is-supported-import';
|
|
4
|
+
type Callee = CallExpression['callee'];
|
|
5
|
+
type Reference = Scope.Reference;
|
|
6
|
+
export declare const isStyled: (nodeToCheck: Callee, referencesInScope: Reference[], importSources: ImportSource[]) => boolean;
|
|
7
|
+
export {};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { Rule } from 'eslint';
|
|
2
2
|
import { JSXElement } from 'eslint-codemod-utils';
|
|
3
|
-
export declare const updateJSXAttributeByName: (oldName: string, newName: string, node: JSXElement, fixer: Rule.RuleFixer) => never[]
|
|
3
|
+
export declare const updateJSXAttributeByName: (oldName: string, newName: string, node: JSXElement, fixer: Rule.RuleFixer) => Rule.Fix | never[];
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import type { JSONSchema4 } from '@typescript-eslint/utils/dist/json-schema';
|
|
1
2
|
import type { Rule } from 'eslint';
|
|
2
|
-
import { SupportedNameChecker } from '
|
|
3
|
+
import { SupportedNameChecker } from '../is-supported-import';
|
|
3
4
|
type RuleModule = Rule.RuleModule;
|
|
5
|
+
export declare const noTaggedTemplateExpressionRuleSchema: JSONSchema4;
|
|
4
6
|
export declare const createNoTaggedTemplateExpressionRule: (isUsage: SupportedNameChecker, messageId: string) => RuleModule['create'];
|
|
5
7
|
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Rule } from 'eslint';
|
|
2
|
+
import { ImportDeclaration } from 'eslint-codemod-utils';
|
|
3
|
+
import { ImportSource } from './is-supported-import';
|
|
4
|
+
type RuleContext = Rule.RuleContext;
|
|
5
|
+
/**
|
|
6
|
+
* Get the first import declaration in the file that matches any of the packages
|
|
7
|
+
* in `importSources`.
|
|
8
|
+
*
|
|
9
|
+
* @param context Rule context.
|
|
10
|
+
* @param importSources The packages to check import statements for. If importSources
|
|
11
|
+
* contains more than one package, the first import statement
|
|
12
|
+
* detected in the file that matches any of the packages will be
|
|
13
|
+
* returned.
|
|
14
|
+
* @returns The first import declaration found in the file.
|
|
15
|
+
*/
|
|
16
|
+
export declare const getFirstSupportedImport: (context: RuleContext, importSources: ImportSource[]) => ImportDeclaration | undefined;
|
|
17
|
+
export {};
|
|
@@ -6,19 +6,20 @@ export declare const CSS_IN_JS_IMPORTS: {
|
|
|
6
6
|
readonly compiled: "@compiled/react";
|
|
7
7
|
readonly emotionReact: "@emotion/react";
|
|
8
8
|
readonly emotionCore: "@emotion/core";
|
|
9
|
+
readonly emotionStyled: "@emotion/styled";
|
|
9
10
|
readonly styledComponents: "styled-components";
|
|
10
11
|
readonly atlaskitCss: "@atlaskit/css";
|
|
12
|
+
readonly atlaskitPrimitives: "@atlaskit/primitives";
|
|
11
13
|
};
|
|
12
14
|
export type ImportSource = string;
|
|
13
15
|
export type SupportedNameChecker = (nodeToCheck: Callee, referencesInScope: Reference[], importSources: ImportSource[]) => boolean;
|
|
16
|
+
/**
|
|
17
|
+
* By default all known import sources are checked against.
|
|
18
|
+
*/
|
|
14
19
|
export declare const DEFAULT_IMPORT_SOURCES: ImportSource[];
|
|
15
20
|
/**
|
|
16
21
|
* Given the ESLint rule context, extract and parse the value of the importSources rule option.
|
|
17
|
-
* The importSources option is used to
|
|
18
|
-
* should apply to.
|
|
19
|
-
*
|
|
20
|
-
* Note that `@compiled/react` and `@atlaskit/css` are always included in importSources, regardless
|
|
21
|
-
* of what importSources is configured to by the user.
|
|
22
|
+
* The importSources option is used to override which libraries an ESLint rule applies to.
|
|
22
23
|
*
|
|
23
24
|
* @param context The rule context.
|
|
24
25
|
* @returns An array of strings representing what CSS-in-JS packages that should be checked, based
|
|
@@ -17,9 +17,11 @@ export declare const configs: {
|
|
|
17
17
|
'@atlaskit/design-system/no-exported-css': string;
|
|
18
18
|
'@atlaskit/design-system/no-exported-keyframes': string;
|
|
19
19
|
'@atlaskit/design-system/no-invalid-css-map': string;
|
|
20
|
+
'@atlaskit/design-system/no-keyframes-tagged-template-expression': string;
|
|
20
21
|
'@atlaskit/design-system/no-margin': string;
|
|
21
22
|
'@atlaskit/design-system/no-nested-styles': string;
|
|
22
23
|
'@atlaskit/design-system/no-physical-properties': string;
|
|
24
|
+
'@atlaskit/design-system/no-styled-tagged-template-expression': string;
|
|
23
25
|
'@atlaskit/design-system/no-unsafe-design-token-usage': string;
|
|
24
26
|
'@atlaskit/design-system/no-unsafe-style-overrides': string;
|
|
25
27
|
'@atlaskit/design-system/no-unsupported-drag-and-drop-libraries': string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
-
* @codegen <<SignedSource::
|
|
3
|
+
* @codegen <<SignedSource::5647ce9c10ba880cffece66b5924fd6e>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
|
|
5
5
|
*/
|
|
6
6
|
declare const _default: {
|
|
@@ -20,9 +20,11 @@ declare const _default: {
|
|
|
20
20
|
'@atlaskit/design-system/no-exported-css': string;
|
|
21
21
|
'@atlaskit/design-system/no-exported-keyframes': string;
|
|
22
22
|
'@atlaskit/design-system/no-invalid-css-map': string;
|
|
23
|
+
'@atlaskit/design-system/no-keyframes-tagged-template-expression': string;
|
|
23
24
|
'@atlaskit/design-system/no-margin': string;
|
|
24
25
|
'@atlaskit/design-system/no-nested-styles': string;
|
|
25
26
|
'@atlaskit/design-system/no-physical-properties': string;
|
|
27
|
+
'@atlaskit/design-system/no-styled-tagged-template-expression': string;
|
|
26
28
|
'@atlaskit/design-system/no-unsafe-design-token-usage': string;
|
|
27
29
|
'@atlaskit/design-system/no-unsafe-style-overrides': string;
|
|
28
30
|
'@atlaskit/design-system/no-unsupported-drag-and-drop-libraries': string;
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
+
import type { ImportSource } from '../utils/is-supported-import';
|
|
1
2
|
export type RuleConfig = {
|
|
2
|
-
cssFunctions
|
|
3
|
-
stylesPlacement
|
|
3
|
+
cssFunctions: string[];
|
|
4
|
+
stylesPlacement: 'top' | 'bottom';
|
|
5
|
+
cssImportSource: ImportSource;
|
|
6
|
+
xcssImportSource: ImportSource;
|
|
7
|
+
excludeReactComponents: boolean;
|
|
8
|
+
fixNamesOnly: boolean;
|
|
4
9
|
};
|
|
@@ -21,9 +21,11 @@ declare const _default: {
|
|
|
21
21
|
'no-exported-css': import("eslint").Rule.RuleModule;
|
|
22
22
|
'no-exported-keyframes': import("eslint").Rule.RuleModule;
|
|
23
23
|
'no-invalid-css-map': import("eslint").Rule.RuleModule;
|
|
24
|
+
'no-keyframes-tagged-template-expression': import("eslint").Rule.RuleModule;
|
|
24
25
|
'no-margin': import("eslint").Rule.RuleModule;
|
|
25
26
|
'no-nested-styles': import("eslint").Rule.RuleModule;
|
|
26
27
|
'no-physical-properties': import("eslint").Rule.RuleModule;
|
|
28
|
+
'no-styled-tagged-template-expression': import("eslint").Rule.RuleModule;
|
|
27
29
|
'no-unsafe-design-token-usage': import("eslint").Rule.RuleModule;
|
|
28
30
|
'no-unsafe-style-overrides': import("eslint").Rule.RuleModule;
|
|
29
31
|
'no-unsupported-drag-and-drop-libraries': import("eslint").Rule.RuleModule;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Scope } from 'eslint';
|
|
2
|
+
import type { CallExpression } from 'estree';
|
|
3
|
+
import { ImportSource } from '../utils/is-supported-import';
|
|
4
|
+
type Callee = CallExpression['callee'];
|
|
5
|
+
type Reference = Scope.Reference;
|
|
6
|
+
export declare const isStyled: (nodeToCheck: Callee, referencesInScope: Reference[], importSources: ImportSource[]) => boolean;
|
|
7
|
+
export {};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { Rule } from 'eslint';
|
|
2
2
|
import { JSXElement } from 'eslint-codemod-utils';
|
|
3
|
-
export declare const updateJSXAttributeByName: (oldName: string, newName: string, node: JSXElement, fixer: Rule.RuleFixer) => never[]
|
|
3
|
+
export declare const updateJSXAttributeByName: (oldName: string, newName: string, node: JSXElement, fixer: Rule.RuleFixer) => Rule.Fix | never[];
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import type { JSONSchema4 } from '@typescript-eslint/utils/dist/json-schema';
|
|
1
2
|
import type { Rule } from 'eslint';
|
|
2
|
-
import { SupportedNameChecker } from '
|
|
3
|
+
import { SupportedNameChecker } from '../is-supported-import';
|
|
3
4
|
type RuleModule = Rule.RuleModule;
|
|
5
|
+
export declare const noTaggedTemplateExpressionRuleSchema: JSONSchema4;
|
|
4
6
|
export declare const createNoTaggedTemplateExpressionRule: (isUsage: SupportedNameChecker, messageId: string) => RuleModule['create'];
|
|
5
7
|
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Rule } from 'eslint';
|
|
2
|
+
import { ImportDeclaration } from 'eslint-codemod-utils';
|
|
3
|
+
import { ImportSource } from './is-supported-import';
|
|
4
|
+
type RuleContext = Rule.RuleContext;
|
|
5
|
+
/**
|
|
6
|
+
* Get the first import declaration in the file that matches any of the packages
|
|
7
|
+
* in `importSources`.
|
|
8
|
+
*
|
|
9
|
+
* @param context Rule context.
|
|
10
|
+
* @param importSources The packages to check import statements for. If importSources
|
|
11
|
+
* contains more than one package, the first import statement
|
|
12
|
+
* detected in the file that matches any of the packages will be
|
|
13
|
+
* returned.
|
|
14
|
+
* @returns The first import declaration found in the file.
|
|
15
|
+
*/
|
|
16
|
+
export declare const getFirstSupportedImport: (context: RuleContext, importSources: ImportSource[]) => ImportDeclaration | undefined;
|
|
17
|
+
export {};
|
|
@@ -6,19 +6,20 @@ export declare const CSS_IN_JS_IMPORTS: {
|
|
|
6
6
|
readonly compiled: "@compiled/react";
|
|
7
7
|
readonly emotionReact: "@emotion/react";
|
|
8
8
|
readonly emotionCore: "@emotion/core";
|
|
9
|
+
readonly emotionStyled: "@emotion/styled";
|
|
9
10
|
readonly styledComponents: "styled-components";
|
|
10
11
|
readonly atlaskitCss: "@atlaskit/css";
|
|
12
|
+
readonly atlaskitPrimitives: "@atlaskit/primitives";
|
|
11
13
|
};
|
|
12
14
|
export type ImportSource = string;
|
|
13
15
|
export type SupportedNameChecker = (nodeToCheck: Callee, referencesInScope: Reference[], importSources: ImportSource[]) => boolean;
|
|
16
|
+
/**
|
|
17
|
+
* By default all known import sources are checked against.
|
|
18
|
+
*/
|
|
14
19
|
export declare const DEFAULT_IMPORT_SOURCES: ImportSource[];
|
|
15
20
|
/**
|
|
16
21
|
* Given the ESLint rule context, extract and parse the value of the importSources rule option.
|
|
17
|
-
* The importSources option is used to
|
|
18
|
-
* should apply to.
|
|
19
|
-
*
|
|
20
|
-
* Note that `@compiled/react` and `@atlaskit/css` are always included in importSources, regardless
|
|
21
|
-
* of what importSources is configured to by the user.
|
|
22
|
+
* The importSources option is used to override which libraries an ESLint rule applies to.
|
|
22
23
|
*
|
|
23
24
|
* @param context The rule context.
|
|
24
25
|
* @returns An array of strings representing what CSS-in-JS packages that should be checked, based
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/eslint-plugin-design-system",
|
|
3
3
|
"description": "The essential plugin for use with the Atlassian Design System.",
|
|
4
|
-
"version": "8.
|
|
4
|
+
"version": "8.28.0",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -41,6 +41,7 @@
|
|
|
41
41
|
"@typescript-eslint/utils": "^5.48.1",
|
|
42
42
|
"ajv": "^6.12.6",
|
|
43
43
|
"eslint-codemod-utils": "^1.8.6",
|
|
44
|
+
"estraverse": "^5.3.0",
|
|
44
45
|
"lodash": "^4.17.21",
|
|
45
46
|
"semver": "^7.5.2"
|
|
46
47
|
},
|
|
@@ -53,6 +54,7 @@
|
|
|
53
54
|
"@emotion/react": "^11.7.1",
|
|
54
55
|
"@emotion/styled": "^11.0.0",
|
|
55
56
|
"@types/eslint": "^8.4.5",
|
|
57
|
+
"@types/estraverse": "^5.1.7",
|
|
56
58
|
"eslint": "^7.7.0",
|
|
57
59
|
"jscodeshift": "^0.13.0",
|
|
58
60
|
"outdent": "^0.5.0",
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
// Original source from Compiled https://github.com/atlassian-labs/compiled/blob/master/packages/eslint-plugin/src/utils/create-no-tagged-template-expression-rule/index.ts
|
|
2
|
-
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
3
|
-
|
|
4
|
-
import { CSS_IN_JS_IMPORTS } from '../../utils/is-supported-import';
|
|
5
|
-
import { generate } from './generate';
|
|
6
|
-
import { getTaggedTemplateExpressionOffset } from './get-tagged-template-expression-offset';
|
|
7
|
-
import { toArguments } from './to-arguments';
|
|
8
|
-
const IMPORT_SOURCES = [CSS_IN_JS_IMPORTS.compiled, CSS_IN_JS_IMPORTS.emotionReact, CSS_IN_JS_IMPORTS.emotionCore, CSS_IN_JS_IMPORTS.styledComponents];
|
|
9
|
-
export const createNoTaggedTemplateExpressionRule = (isUsage, messageId) => context => ({
|
|
10
|
-
TaggedTemplateExpression(node) {
|
|
11
|
-
const {
|
|
12
|
-
references
|
|
13
|
-
} = context.getScope();
|
|
14
|
-
if (!isUsage(node.tag, references, IMPORT_SOURCES)) {
|
|
15
|
-
return;
|
|
16
|
-
}
|
|
17
|
-
context.report({
|
|
18
|
-
messageId,
|
|
19
|
-
node,
|
|
20
|
-
*fix(fixer) {
|
|
21
|
-
const {
|
|
22
|
-
quasi
|
|
23
|
-
} = node;
|
|
24
|
-
const source = context.getSourceCode();
|
|
25
|
-
|
|
26
|
-
// TODO Eventually handle comments instead of skipping them
|
|
27
|
-
// Skip auto-fixing comments
|
|
28
|
-
if (quasi.quasis.map(q => q.value.raw).join('').match(/\/\*[\s\S]*\*\//g)) {
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
// Replace empty tagged template expression with the equivalent object call expression
|
|
33
|
-
if (!quasi.expressions.length && quasi.quasis.length === 1 && !quasi.quasis[0].value.raw.trim()) {
|
|
34
|
-
yield fixer.replaceText(quasi, '({})');
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
const args = toArguments(source, quasi);
|
|
38
|
-
|
|
39
|
-
// Skip invalid CSS
|
|
40
|
-
if (args.length < 1) {
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
const oldCode = source.getText(node);
|
|
44
|
-
// Remove quasi:
|
|
45
|
-
// styled.div<Props>`
|
|
46
|
-
// color: red;
|
|
47
|
-
// `
|
|
48
|
-
// becomes
|
|
49
|
-
// styled.div<Props>
|
|
50
|
-
const withoutQuasi = oldCode.replace(source.getText(quasi), '');
|
|
51
|
-
const newCode = withoutQuasi +
|
|
52
|
-
// Indent the arguments after the tagged template expression range
|
|
53
|
-
generate(args, getTaggedTemplateExpressionOffset(node));
|
|
54
|
-
if (oldCode === newCode) {
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
yield fixer.insertTextBefore(node, newCode);
|
|
58
|
-
yield fixer.remove(node);
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
});
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|