@atlaskit/eslint-plugin-design-system 8.23.2 → 8.23.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +15 -0
- package/README.md +1 -0
- package/constellation/index/usage.mdx +39 -0
- package/dist/cjs/ast-nodes/index.js +7 -0
- package/dist/cjs/ast-nodes/object.js +84 -0
- package/dist/cjs/presets/all.codegen.js +2 -1
- package/dist/cjs/presets/recommended.codegen.js +2 -1
- package/dist/cjs/rules/consistent-css-prop-usage/index.js +25 -5
- package/dist/cjs/rules/index.codegen.js +3 -1
- package/dist/cjs/rules/local-cx-xcss/index.js +51 -0
- package/dist/cjs/rules/no-css-tagged-template-expression/create-no-tagged-template-expression-rule/index.js +3 -1
- package/dist/cjs/rules/no-css-tagged-template-expression/index.js +2 -2
- package/dist/cjs/rules/use-primitives/index.js +4 -30
- package/dist/cjs/rules/use-primitives/transformers/compiled-styled/convert-jsx-call-site.js +39 -0
- package/dist/cjs/rules/use-primitives/transformers/compiled-styled/convert-styled-component-call-to-jsx.js +44 -0
- package/dist/cjs/rules/use-primitives/{utils → transformers/compiled-styled}/find-valid-styled-component-call.js +5 -2
- package/dist/cjs/rules/use-primitives/transformers/compiled-styled/index.js +117 -0
- package/dist/cjs/rules/use-primitives/transformers/compiled-styled/supported.js +10 -0
- package/dist/cjs/rules/use-primitives/transformers/compiled-styled/upsert-import-declaration.js +37 -0
- package/dist/cjs/rules/use-primitives/transformers/emotion-css/contains-only-supported-attrs.js +27 -0
- package/dist/cjs/rules/use-primitives/transformers/emotion-css/index.js +4 -47
- package/dist/cjs/rules/use-primitives/transformers/emotion-css/supported.js +2 -44
- package/dist/cjs/rules/use-primitives/transformers/emotion-css/upsert-import-declaration.js +37 -0
- package/dist/cjs/rules/use-primitives/transformers/index.js +10 -10
- package/dist/cjs/rules/use-primitives/utils/index.js +1 -43
- package/dist/cjs/rules/utils/is-supported-import.js +61 -0
- package/dist/es2019/ast-nodes/index.js +1 -0
- package/dist/es2019/ast-nodes/object.js +79 -0
- package/dist/es2019/presets/all.codegen.js +2 -1
- package/dist/es2019/presets/recommended.codegen.js +2 -1
- package/dist/es2019/rules/consistent-css-prop-usage/index.js +23 -5
- package/dist/es2019/rules/index.codegen.js +3 -1
- package/dist/es2019/rules/local-cx-xcss/index.js +45 -0
- package/dist/es2019/rules/no-css-tagged-template-expression/create-no-tagged-template-expression-rule/index.js +3 -1
- package/dist/es2019/rules/no-css-tagged-template-expression/index.js +2 -2
- package/dist/es2019/rules/use-primitives/index.js +4 -30
- package/dist/es2019/rules/use-primitives/transformers/compiled-styled/convert-jsx-call-site.js +29 -0
- package/dist/es2019/rules/use-primitives/transformers/compiled-styled/convert-styled-component-call-to-jsx.js +37 -0
- package/dist/es2019/rules/use-primitives/{utils → transformers/compiled-styled}/find-valid-styled-component-call.js +2 -2
- package/dist/es2019/rules/use-primitives/transformers/compiled-styled/index.js +107 -0
- package/dist/es2019/rules/use-primitives/transformers/compiled-styled/supported.js +4 -0
- package/dist/es2019/rules/use-primitives/transformers/compiled-styled/upsert-import-declaration.js +30 -0
- package/dist/es2019/rules/use-primitives/transformers/emotion-css/contains-only-supported-attrs.js +19 -0
- package/dist/es2019/rules/use-primitives/transformers/emotion-css/index.js +4 -48
- package/dist/es2019/rules/use-primitives/transformers/emotion-css/supported.js +1 -43
- package/dist/es2019/rules/use-primitives/transformers/emotion-css/upsert-import-declaration.js +30 -0
- package/dist/es2019/rules/use-primitives/transformers/index.js +2 -2
- package/dist/es2019/rules/use-primitives/utils/index.js +1 -7
- package/dist/es2019/rules/utils/is-supported-import.js +52 -0
- package/dist/esm/ast-nodes/index.js +1 -0
- package/dist/esm/ast-nodes/object.js +79 -0
- package/dist/esm/presets/all.codegen.js +2 -1
- package/dist/esm/presets/recommended.codegen.js +2 -1
- package/dist/esm/rules/consistent-css-prop-usage/index.js +25 -5
- package/dist/esm/rules/index.codegen.js +3 -1
- package/dist/esm/rules/local-cx-xcss/index.js +45 -0
- package/dist/esm/rules/no-css-tagged-template-expression/create-no-tagged-template-expression-rule/index.js +3 -1
- package/dist/esm/rules/no-css-tagged-template-expression/index.js +2 -2
- package/dist/esm/rules/use-primitives/index.js +4 -30
- package/dist/esm/rules/use-primitives/transformers/compiled-styled/convert-jsx-call-site.js +30 -0
- package/dist/esm/rules/use-primitives/transformers/compiled-styled/convert-styled-component-call-to-jsx.js +38 -0
- package/dist/esm/rules/use-primitives/{utils → transformers/compiled-styled}/find-valid-styled-component-call.js +2 -2
- package/dist/esm/rules/use-primitives/transformers/compiled-styled/index.js +107 -0
- package/dist/esm/rules/use-primitives/transformers/compiled-styled/supported.js +4 -0
- package/dist/esm/rules/use-primitives/transformers/compiled-styled/upsert-import-declaration.js +29 -0
- package/dist/esm/rules/use-primitives/transformers/emotion-css/contains-only-supported-attrs.js +19 -0
- package/dist/esm/rules/use-primitives/transformers/emotion-css/index.js +4 -47
- package/dist/esm/rules/use-primitives/transformers/emotion-css/supported.js +1 -43
- package/dist/esm/rules/use-primitives/transformers/emotion-css/upsert-import-declaration.js +29 -0
- package/dist/esm/rules/use-primitives/transformers/index.js +2 -2
- package/dist/esm/rules/use-primitives/utils/index.js +1 -7
- package/dist/esm/rules/utils/is-supported-import.js +54 -0
- package/dist/types/ast-nodes/index.d.ts +1 -0
- package/dist/types/ast-nodes/object.d.ts +39 -0
- package/dist/types/index.codegen.d.ts +2 -0
- package/dist/types/presets/all.codegen.d.ts +2 -1
- package/dist/types/presets/recommended.codegen.d.ts +2 -1
- package/dist/types/rules/index.codegen.d.ts +1 -0
- package/dist/types/rules/local-cx-xcss/index.d.ts +3 -0
- package/dist/types/rules/no-css-tagged-template-expression/create-no-tagged-template-expression-rule/index.d.ts +3 -4
- package/dist/types/rules/use-primitives/transformers/compiled-styled/convert-jsx-call-site.d.ts +17 -0
- package/dist/types/rules/use-primitives/transformers/compiled-styled/convert-styled-component-call-to-jsx.d.ts +17 -0
- package/dist/types/rules/use-primitives/transformers/compiled-styled/index.d.ts +25 -0
- package/dist/types/rules/use-primitives/transformers/compiled-styled/supported.d.ts +2 -0
- package/dist/types/rules/use-primitives/transformers/compiled-styled/upsert-import-declaration.d.ts +14 -0
- package/dist/types/rules/use-primitives/transformers/emotion-css/contains-only-supported-attrs.d.ts +7 -0
- package/dist/types/rules/use-primitives/transformers/emotion-css/index.d.ts +0 -19
- package/dist/types/rules/use-primitives/transformers/emotion-css/supported.d.ts +0 -7
- package/dist/types/rules/use-primitives/transformers/emotion-css/upsert-import-declaration.d.ts +14 -0
- package/dist/types/rules/use-primitives/transformers/index.d.ts +2 -2
- package/dist/types/rules/use-primitives/utils/index.d.ts +0 -6
- package/dist/types/rules/utils/is-supported-import.d.ts +16 -0
- package/dist/types-ts4.5/ast-nodes/index.d.ts +1 -0
- package/dist/types-ts4.5/ast-nodes/object.d.ts +39 -0
- package/dist/types-ts4.5/index.codegen.d.ts +2 -0
- package/dist/types-ts4.5/presets/all.codegen.d.ts +2 -1
- package/dist/types-ts4.5/presets/recommended.codegen.d.ts +2 -1
- package/dist/types-ts4.5/rules/index.codegen.d.ts +1 -0
- package/dist/types-ts4.5/rules/local-cx-xcss/index.d.ts +3 -0
- package/dist/types-ts4.5/rules/no-css-tagged-template-expression/create-no-tagged-template-expression-rule/index.d.ts +3 -4
- package/dist/types-ts4.5/rules/use-primitives/transformers/compiled-styled/convert-jsx-call-site.d.ts +17 -0
- package/dist/types-ts4.5/rules/use-primitives/transformers/compiled-styled/convert-styled-component-call-to-jsx.d.ts +17 -0
- package/dist/types-ts4.5/rules/use-primitives/transformers/compiled-styled/index.d.ts +25 -0
- package/dist/types-ts4.5/rules/use-primitives/transformers/compiled-styled/supported.d.ts +2 -0
- package/dist/types-ts4.5/rules/use-primitives/transformers/compiled-styled/upsert-import-declaration.d.ts +14 -0
- package/dist/types-ts4.5/rules/use-primitives/transformers/emotion-css/contains-only-supported-attrs.d.ts +7 -0
- package/dist/types-ts4.5/rules/use-primitives/transformers/emotion-css/index.d.ts +0 -19
- package/dist/types-ts4.5/rules/use-primitives/transformers/emotion-css/supported.d.ts +0 -7
- package/dist/types-ts4.5/rules/use-primitives/transformers/emotion-css/upsert-import-declaration.d.ts +14 -0
- package/dist/types-ts4.5/rules/use-primitives/transformers/index.d.ts +2 -2
- package/dist/types-ts4.5/rules/use-primitives/utils/index.d.ts +0 -6
- package/dist/types-ts4.5/rules/utils/is-supported-import.d.ts +16 -0
- package/package.json +1 -1
- package/dist/cjs/rules/no-css-tagged-template-expression/is-supported-import.js +0 -29
- package/dist/cjs/rules/use-primitives/transformers/jsx-element-to-box.js +0 -26
- package/dist/cjs/rules/use-primitives/transformers/styled-component-to-primitive.js +0 -68
- package/dist/cjs/rules/use-primitives/utils/contains-only-supported-attrs.js +0 -19
- package/dist/cjs/rules/use-primitives/utils/is-valid-tag-name.js +0 -13
- package/dist/cjs/rules/use-primitives/utils/update-jsx-element-name.js +0 -16
- package/dist/cjs/rules/use-primitives/utils/upsert-import-declaration.js +0 -80
- package/dist/es2019/rules/no-css-tagged-template-expression/is-supported-import.js +0 -21
- package/dist/es2019/rules/use-primitives/transformers/jsx-element-to-box.js +0 -16
- package/dist/es2019/rules/use-primitives/transformers/styled-component-to-primitive.js +0 -59
- package/dist/es2019/rules/use-primitives/utils/contains-only-supported-attrs.js +0 -13
- package/dist/es2019/rules/use-primitives/utils/is-valid-tag-name.js +0 -7
- package/dist/es2019/rules/use-primitives/utils/update-jsx-element-name.js +0 -12
- package/dist/es2019/rules/use-primitives/utils/upsert-import-declaration.js +0 -76
- package/dist/esm/rules/no-css-tagged-template-expression/is-supported-import.js +0 -23
- package/dist/esm/rules/use-primitives/transformers/jsx-element-to-box.js +0 -19
- package/dist/esm/rules/use-primitives/transformers/styled-component-to-primitive.js +0 -61
- package/dist/esm/rules/use-primitives/utils/contains-only-supported-attrs.js +0 -13
- package/dist/esm/rules/use-primitives/utils/is-valid-tag-name.js +0 -7
- package/dist/esm/rules/use-primitives/utils/update-jsx-element-name.js +0 -10
- package/dist/esm/rules/use-primitives/utils/upsert-import-declaration.js +0 -75
- package/dist/types/rules/no-css-tagged-template-expression/is-supported-import.d.ts +0 -12
- package/dist/types/rules/use-primitives/transformers/jsx-element-to-box.d.ts +0 -3
- package/dist/types/rules/use-primitives/transformers/styled-component-to-primitive.d.ts +0 -13
- package/dist/types/rules/use-primitives/utils/contains-only-supported-attrs.d.ts +0 -2
- package/dist/types/rules/use-primitives/utils/is-valid-tag-name.d.ts +0 -3
- package/dist/types/rules/use-primitives/utils/update-jsx-element-name.d.ts +0 -3
- package/dist/types/rules/use-primitives/utils/upsert-import-declaration.d.ts +0 -11
- package/dist/types-ts4.5/rules/no-css-tagged-template-expression/is-supported-import.d.ts +0 -12
- package/dist/types-ts4.5/rules/use-primitives/transformers/jsx-element-to-box.d.ts +0 -3
- package/dist/types-ts4.5/rules/use-primitives/transformers/styled-component-to-primitive.d.ts +0 -13
- package/dist/types-ts4.5/rules/use-primitives/utils/contains-only-supported-attrs.d.ts +0 -2
- package/dist/types-ts4.5/rules/use-primitives/utils/is-valid-tag-name.d.ts +0 -3
- package/dist/types-ts4.5/rules/use-primitives/utils/update-jsx-element-name.d.ts +0 -3
- package/dist/types-ts4.5/rules/use-primitives/utils/upsert-import-declaration.d.ts +0 -11
- /package/dist/cjs/rules/use-primitives/{utils → transformers/compiled-styled}/find-valid-jsx-usage-to-transform.js +0 -0
- /package/dist/es2019/rules/use-primitives/{utils → transformers/compiled-styled}/find-valid-jsx-usage-to-transform.js +0 -0
- /package/dist/esm/rules/use-primitives/{utils → transformers/compiled-styled}/find-valid-jsx-usage-to-transform.js +0 -0
- /package/dist/types/rules/use-primitives/{utils → transformers/compiled-styled}/find-valid-jsx-usage-to-transform.d.ts +0 -0
- /package/dist/types/rules/use-primitives/{utils → transformers/compiled-styled}/find-valid-styled-component-call.d.ts +0 -0
- /package/dist/types-ts4.5/rules/use-primitives/{utils → transformers/compiled-styled}/find-valid-jsx-usage-to-transform.d.ts +0 -0
- /package/dist/types-ts4.5/rules/use-primitives/{utils → transformers/compiled-styled}/find-valid-styled-component-call.d.ts +0 -0
|
@@ -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::5026ba2cb55b3c1bcacbfe7fb7728a6c>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
|
|
5
5
|
*/
|
|
6
6
|
declare const _default: {
|
|
@@ -10,6 +10,7 @@ declare const _default: {
|
|
|
10
10
|
'@atlaskit/design-system/ensure-design-token-usage': string;
|
|
11
11
|
'@atlaskit/design-system/ensure-design-token-usage/preview': string;
|
|
12
12
|
'@atlaskit/design-system/icon-label': string;
|
|
13
|
+
'@atlaskit/design-system/local-cx-xcss': string;
|
|
13
14
|
'@atlaskit/design-system/no-banned-imports': string;
|
|
14
15
|
'@atlaskit/design-system/no-css-tagged-template-expression': string;
|
|
15
16
|
'@atlaskit/design-system/no-deprecated-apis': 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::839224bfab98c1ddf6018dec5320968e>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
|
|
5
5
|
*/
|
|
6
6
|
declare const _default: {
|
|
@@ -9,6 +9,7 @@ declare const _default: {
|
|
|
9
9
|
'@atlaskit/design-system/consistent-css-prop-usage': string;
|
|
10
10
|
'@atlaskit/design-system/ensure-design-token-usage': string;
|
|
11
11
|
'@atlaskit/design-system/icon-label': string;
|
|
12
|
+
'@atlaskit/design-system/local-cx-xcss': string;
|
|
12
13
|
'@atlaskit/design-system/no-banned-imports': string;
|
|
13
14
|
'@atlaskit/design-system/no-deprecated-apis': string;
|
|
14
15
|
'@atlaskit/design-system/no-deprecated-design-token-usage': string;
|
|
@@ -3,6 +3,7 @@ declare const _default: {
|
|
|
3
3
|
'ensure-design-token-usage': import("eslint").Rule.RuleModule;
|
|
4
4
|
'ensure-design-token-usage/preview': import("eslint").Rule.RuleModule;
|
|
5
5
|
'icon-label': import("eslint").Rule.RuleModule;
|
|
6
|
+
'local-cx-xcss': import("eslint").Rule.RuleModule;
|
|
6
7
|
'no-banned-imports': import("eslint").Rule.RuleModule;
|
|
7
8
|
'no-css-tagged-template-expression': import("eslint").Rule.RuleModule;
|
|
8
9
|
'no-deprecated-apis': import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleModule<string, [
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import type { Rule
|
|
2
|
-
|
|
3
|
-
type Reference = Scope.Reference;
|
|
1
|
+
import type { Rule } from 'eslint';
|
|
2
|
+
import { SupportedNameChecker } from '../../utils/is-supported-import';
|
|
4
3
|
type RuleModule = Rule.RuleModule;
|
|
5
|
-
export declare const createNoTaggedTemplateExpressionRule: (isUsage:
|
|
4
|
+
export declare const createNoTaggedTemplateExpressionRule: (isUsage: SupportedNameChecker, messageId: string) => RuleModule['create'];
|
|
6
5
|
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Rule } from 'eslint';
|
|
2
|
+
import { JSXElement } from 'eslint-codemod-utils';
|
|
3
|
+
/**
|
|
4
|
+
* Transforms a JSXElement from:
|
|
5
|
+
* ```
|
|
6
|
+
* <div>
|
|
7
|
+
* // ...
|
|
8
|
+
* </div>
|
|
9
|
+
* ```
|
|
10
|
+
* to
|
|
11
|
+
* ```
|
|
12
|
+
* <Box xcss={myStyles}>
|
|
13
|
+
* // ...
|
|
14
|
+
* </Box>
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare const convertJsxCallSite: (jsxElement: JSXElement, newStylesVariableName: string, fixer: Rule.RuleFixer) => Rule.Fix[];
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Rule } from 'eslint';
|
|
2
|
+
import { VariableDeclarator } from 'eslint-codemod-utils';
|
|
3
|
+
/**
|
|
4
|
+
* Transforms a variable like:
|
|
5
|
+
* ```
|
|
6
|
+
* const MyComponent = styled.div({
|
|
7
|
+
* padding: '8px',
|
|
8
|
+
* })
|
|
9
|
+
* ```
|
|
10
|
+
* to
|
|
11
|
+
* ```
|
|
12
|
+
* const myComponentStyles = xcss({
|
|
13
|
+
* padding: 'space.100',
|
|
14
|
+
* })
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare const convertStyledComponentToXcss: (styles: VariableDeclarator, newStylesVariableName: string, fixer: Rule.RuleFixer) => (Rule.Fix | undefined)[];
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Rule } from 'eslint';
|
|
2
|
+
import { JSXElement, VariableDeclarator } from 'eslint-codemod-utils';
|
|
3
|
+
import { RuleConfig } from '../../config';
|
|
4
|
+
interface MetaData {
|
|
5
|
+
context: Rule.RuleContext;
|
|
6
|
+
config: RuleConfig;
|
|
7
|
+
}
|
|
8
|
+
interface Refs {
|
|
9
|
+
styles: VariableDeclarator;
|
|
10
|
+
jsxElement: JSXElement;
|
|
11
|
+
}
|
|
12
|
+
type Check = {
|
|
13
|
+
success: boolean;
|
|
14
|
+
refs?: Refs;
|
|
15
|
+
};
|
|
16
|
+
export declare const CompiledStyled: {
|
|
17
|
+
lint(node: Rule.Node, { context, config }: MetaData): void;
|
|
18
|
+
_check(node: Rule.Node, { context, config }: MetaData): Check;
|
|
19
|
+
/**
|
|
20
|
+
* All required validation steps have been taken care of before this
|
|
21
|
+
* transformer is called, so it just goes ahead providing all necessary fixes
|
|
22
|
+
*/
|
|
23
|
+
_fix(refs: Refs, context: Rule.RuleContext): (fixer: Rule.RuleFixer) => Rule.Fix[];
|
|
24
|
+
};
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Rule } from 'eslint';
|
|
2
|
+
/**
|
|
3
|
+
* Currently this is defined here because it's not very general purpose.
|
|
4
|
+
* If we were to move this to `ast-nodes`, half the implementation would be in `Root`,
|
|
5
|
+
* and the other half would be in `Import`.
|
|
6
|
+
*
|
|
7
|
+
* TODO: Refactor and move to `ast-nodes`
|
|
8
|
+
*
|
|
9
|
+
* Note: It does not handle default imports, namespace imports, or aliased imports.
|
|
10
|
+
*/
|
|
11
|
+
export declare const upsertImportDeclaration: ({ module, specifiers, }: {
|
|
12
|
+
module: string;
|
|
13
|
+
specifiers: string[];
|
|
14
|
+
}, context: Rule.RuleContext, fixer: Rule.RuleFixer) => Rule.Fix | undefined;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { JSXElement } from 'eslint-codemod-utils';
|
|
2
|
+
/**
|
|
3
|
+
* Check that every attribute in the JSXElement is something we support.
|
|
4
|
+
* We do this via a whitelist in `this.attributes`. The result is we exclude
|
|
5
|
+
* dangerous attrs like `id` and `style`.
|
|
6
|
+
*/
|
|
7
|
+
export declare const containsOnlySupportedAttrs: (node: JSXElement) => boolean;
|
|
@@ -12,24 +12,5 @@ export declare const EmotionCSS: {
|
|
|
12
12
|
_fix(node: JSXElement, { context }: {
|
|
13
13
|
context: Rule.RuleContext;
|
|
14
14
|
}): FixFunction;
|
|
15
|
-
/**
|
|
16
|
-
* Check that every attribute in the JSXElement is something we support.
|
|
17
|
-
* We do this via a whitelist in `this.attributes`. The result is we exclude
|
|
18
|
-
* dangerous attrs like `id` and `style`.
|
|
19
|
-
*/
|
|
20
|
-
_containsOnlySupportedAttributes(node: JSXElement): boolean;
|
|
21
|
-
/**
|
|
22
|
-
* Currently this is defined here because it's not very general purpose.
|
|
23
|
-
* If we were to move this to `ast-nodes`, half the implementation would be in `Root`,
|
|
24
|
-
* and the other half would be in `Import`.
|
|
25
|
-
*
|
|
26
|
-
* TODO: Refactor and move to `ast-nodes`
|
|
27
|
-
*
|
|
28
|
-
* Note: It does not handle default imports, namespace imports, or aliased imports.
|
|
29
|
-
*/
|
|
30
|
-
_upsertImportDeclaration({ module, specifiers, }: {
|
|
31
|
-
module: string;
|
|
32
|
-
specifiers: string[];
|
|
33
|
-
}, context: Rule.RuleContext, fixer: Rule.RuleFixer): Rule.Fix | undefined;
|
|
34
15
|
};
|
|
35
16
|
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Rule } from 'eslint';
|
|
2
|
+
/**
|
|
3
|
+
* Currently this is defined here because it's not very general purpose.
|
|
4
|
+
* If we were to move this to `ast-nodes`, half the implementation would be in `Root`,
|
|
5
|
+
* and the other half would be in `Import`.
|
|
6
|
+
*
|
|
7
|
+
* TODO: Refactor and move to `ast-nodes`
|
|
8
|
+
*
|
|
9
|
+
* Note: It does not handle default imports, namespace imports, or aliased imports.
|
|
10
|
+
*/
|
|
11
|
+
export declare const upsertImportDeclaration: ({ module, specifiers, }: {
|
|
12
|
+
module: string;
|
|
13
|
+
specifiers: string[];
|
|
14
|
+
}, context: Rule.RuleContext, fixer: Rule.RuleFixer) => Rule.Fix | undefined;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { cssToXcssTransformer, supportedStylesMap, spaceTokenMap, } from './css-to-xcss';
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
2
|
+
export { CompiledStyled } from './compiled-styled';
|
|
3
|
+
export { EmotionCSS } from './emotion-css';
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
export { containsOnlySupportedAttrs } from './contains-only-supported-attrs';
|
|
2
1
|
export { convertASTObjectExpressionToJSObject } from './convert-ast-object-expression-to-js-object';
|
|
3
|
-
export { findValidJsxUsageToTransform } from './find-valid-jsx-usage-to-transform';
|
|
4
|
-
export { findValidStyledComponentCall } from './find-valid-styled-component-call';
|
|
5
2
|
export { getAttributeValueIdentifier } from './get-attribute-value-identifier';
|
|
6
3
|
export { getFunctionArgumentAtPos } from './get-function-argument-at-pos';
|
|
7
4
|
export { getJSXAttributeByName } from './get-jsx-attribute-by-name';
|
|
@@ -9,7 +6,4 @@ export { getVariableDefinitionValue } from './get-variable-definition-value';
|
|
|
9
6
|
export { getVariableUsagesCount } from './get-variable-usage-count';
|
|
10
7
|
export { isFunctionNamed } from './is-function-named';
|
|
11
8
|
export { isValidCssPropertiesToTransform } from './is-valid-css-properties-to-transform';
|
|
12
|
-
export { isValidTagName } from './is-valid-tag-name';
|
|
13
9
|
export { updateJSXAttributeByName } from './update-jsx-attribute-by-name';
|
|
14
|
-
export { updateJSXElementName } from './update-jsx-element-name';
|
|
15
|
-
export { upsertImportDeclaration } from './upsert-import-declaration';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { 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
|
+
compiled: string;
|
|
7
|
+
emotionReact: string;
|
|
8
|
+
emotionCore: string;
|
|
9
|
+
styledComponents: string;
|
|
10
|
+
atlaskitCss: string;
|
|
11
|
+
};
|
|
12
|
+
type ValidImportSources = string[];
|
|
13
|
+
export type SupportedNameChecker = (nodeToCheck: Callee, referencesInScope: Reference[], importSources: ValidImportSources) => boolean;
|
|
14
|
+
export declare const isCss: SupportedNameChecker;
|
|
15
|
+
export declare const isCxFunction: SupportedNameChecker;
|
|
16
|
+
export {};
|
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.23.
|
|
4
|
+
"version": "8.23.4",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.isSupportedImport = exports.SUPPORTED_IMPORTS = void 0;
|
|
7
|
-
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
8
|
-
|
|
9
|
-
var SUPPORTED_IMPORTS = exports.SUPPORTED_IMPORTS = {
|
|
10
|
-
compiled: '@compiled/react',
|
|
11
|
-
emotionReact: '@emotion/react',
|
|
12
|
-
emotionCore: '@emotion/core',
|
|
13
|
-
styledComponents: 'styled-components'
|
|
14
|
-
};
|
|
15
|
-
var isImportSpecifierWrapper = function isImportSpecifierWrapper(name) {
|
|
16
|
-
return function (def) {
|
|
17
|
-
var _def$parent, _def$parent2, _def$parent3, _def$parent4, _def$parent5;
|
|
18
|
-
return def.node.type === 'ImportSpecifier' && def.node.imported.type === 'Identifier' && def.node.imported.name === name && ((_def$parent = def.parent) === null || _def$parent === void 0 ? void 0 : _def$parent.type) === 'ImportDeclaration' && (((_def$parent2 = def.parent) === null || _def$parent2 === void 0 ? void 0 : _def$parent2.source.value) === SUPPORTED_IMPORTS.compiled || ((_def$parent3 = def.parent) === null || _def$parent3 === void 0 ? void 0 : _def$parent3.source.value) === SUPPORTED_IMPORTS.emotionReact || ((_def$parent4 = def.parent) === null || _def$parent4 === void 0 ? void 0 : _def$parent4.source.value) === SUPPORTED_IMPORTS.emotionCore || ((_def$parent5 = def.parent) === null || _def$parent5 === void 0 ? void 0 : _def$parent5.source.value) === SUPPORTED_IMPORTS.styledComponents);
|
|
19
|
-
};
|
|
20
|
-
};
|
|
21
|
-
var isSupportedImport = exports.isSupportedImport = function isSupportedImport(name) {
|
|
22
|
-
var isImportSpecifier = isImportSpecifierWrapper(name);
|
|
23
|
-
return function (node, references) {
|
|
24
|
-
return node.type === 'Identifier' && references.some(function (reference) {
|
|
25
|
-
var _reference$resolved;
|
|
26
|
-
return reference.identifier === node && ((_reference$resolved = reference.resolved) === null || _reference$resolved === void 0 ? void 0 : _reference$resolved.defs.some(isImportSpecifier));
|
|
27
|
-
});
|
|
28
|
-
};
|
|
29
|
-
};
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.jsxElementToBoxTransformer = void 0;
|
|
8
|
-
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
9
|
-
var _utils = require("../utils");
|
|
10
|
-
var _cssToXcss = require("./css-to-xcss");
|
|
11
|
-
var jsxElementToBoxTransformer = exports.jsxElementToBoxTransformer = function jsxElementToBoxTransformer(node, context) {
|
|
12
|
-
return function (fixer) {
|
|
13
|
-
// Insert `import { Box, xcss } from '@atlaskit/primitives'`
|
|
14
|
-
// Or, if the import exists already, update it to include `Box`, and `xcss`
|
|
15
|
-
var importFixes = (0, _utils.upsertImportDeclaration)({
|
|
16
|
-
packageName: '@atlaskit/primitives',
|
|
17
|
-
specifiers: ['Box', 'xcss']
|
|
18
|
-
}, context, fixer);
|
|
19
|
-
var elementNameFixes = (0, _utils.updateJSXElementName)(node, 'Box', fixer);
|
|
20
|
-
var attributeFix = (0, _utils.updateJSXAttributeByName)('css', 'xcss', node, fixer);
|
|
21
|
-
var cssToXcssTransform = (0, _cssToXcss.cssToXcssTransformer)(node, context, fixer);
|
|
22
|
-
return [importFixes, attributeFix].concat((0, _toConsumableArray2.default)(elementNameFixes), (0, _toConsumableArray2.default)(cssToXcssTransform)).filter(function (fix) {
|
|
23
|
-
return Boolean(fix);
|
|
24
|
-
}); // Some of the transformers can return arrays with undefined, so filter them out
|
|
25
|
-
};
|
|
26
|
-
};
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.styledComponentToPrimitive = void 0;
|
|
8
|
-
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
9
|
-
var _eslintCodemodUtils = require("eslint-codemod-utils");
|
|
10
|
-
var _utils = require("../utils");
|
|
11
|
-
var _cssToXcss = require("./css-to-xcss");
|
|
12
|
-
/**
|
|
13
|
-
* All required validation steps have been taken care of before this
|
|
14
|
-
* transformer is called, so it just goes ahead providing all necessary fixes
|
|
15
|
-
*/
|
|
16
|
-
var styledComponentToPrimitive = exports.styledComponentToPrimitive = function styledComponentToPrimitive(_ref, context) {
|
|
17
|
-
var stylesRef = _ref.stylesRef,
|
|
18
|
-
jsxRef = _ref.jsxRef;
|
|
19
|
-
return function (fixer) {
|
|
20
|
-
// generates the new variable name: MyComponent -> myComponentStyles
|
|
21
|
-
var calculatedStylesVariableName = (0, _eslintCodemodUtils.isNodeOfType)(stylesRef.id, 'Identifier') && "".concat(stylesRef.id.name.replace(stylesRef.id.name[0], stylesRef.id.name[0].toLowerCase()), "Styles");
|
|
22
|
-
if (!calculatedStylesVariableName) {
|
|
23
|
-
return [];
|
|
24
|
-
}
|
|
25
|
-
var importFixes = (0, _utils.upsertImportDeclaration)({
|
|
26
|
-
packageName: '@atlaskit/primitives',
|
|
27
|
-
specifiers: ['Box', 'xcss']
|
|
28
|
-
}, context, fixer);
|
|
29
|
-
var stylesFixes = convertStyledComponentToXcss(stylesRef, calculatedStylesVariableName, fixer);
|
|
30
|
-
var jsxFixes = convertJsxCallSite(jsxRef, calculatedStylesVariableName, fixer);
|
|
31
|
-
return [importFixes].concat(stylesFixes, jsxFixes).filter(function (fix) {
|
|
32
|
-
return Boolean(fix);
|
|
33
|
-
}); // Some of the transformers can return arrays with undefined, so filter them out
|
|
34
|
-
};
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
var convertStyledComponentToXcss = function convertStyledComponentToXcss(stylesRef, newStylesVariableName, fixer) {
|
|
38
|
-
var fixes = [];
|
|
39
|
-
|
|
40
|
-
// renames the variable from MyComponent to myComponentStyles
|
|
41
|
-
fixes.push(fixer.replaceText(stylesRef.id, newStylesVariableName));
|
|
42
|
-
|
|
43
|
-
// renames the function call from styled.<tag> to xcss
|
|
44
|
-
if (stylesRef.init && (0, _eslintCodemodUtils.isNodeOfType)(stylesRef.init, 'CallExpression')) {
|
|
45
|
-
fixes.push(fixer.replaceText(stylesRef.init.callee, 'xcss'));
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// converts CSS values to XCSS-compatible tokens
|
|
49
|
-
if (stylesRef.init && (0, _eslintCodemodUtils.isNodeOfType)(stylesRef.init, 'CallExpression')) {
|
|
50
|
-
var objectExpression = stylesRef.init.arguments[0];
|
|
51
|
-
if ((0, _eslintCodemodUtils.isNodeOfType)(objectExpression, 'ObjectExpression')) {
|
|
52
|
-
fixes.push.apply(fixes, (0, _toConsumableArray2.default)((0, _cssToXcss.styledObjectToXcssTokens)(objectExpression, fixer)));
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
return fixes;
|
|
56
|
-
};
|
|
57
|
-
var convertJsxCallSite = function convertJsxCallSite(jsxRef, newStylesVariableName, fixer) {
|
|
58
|
-
var fixes = [];
|
|
59
|
-
|
|
60
|
-
// renames the JSX call site
|
|
61
|
-
if ((0, _eslintCodemodUtils.isNodeOfType)(jsxRef.parent, 'JSXElement')) {
|
|
62
|
-
fixes.push.apply(fixes, (0, _toConsumableArray2.default)((0, _utils.updateJSXElementName)(jsxRef.parent, 'Box', fixer)));
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// adds xcss prop
|
|
66
|
-
fixes.push(fixer.insertTextAfter(jsxRef.name, " xcss={".concat(newStylesVariableName, "}")));
|
|
67
|
-
return fixes;
|
|
68
|
-
};
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.containsOnlySupportedAttrs = void 0;
|
|
7
|
-
var _eslintCodemodUtils = require("eslint-codemod-utils");
|
|
8
|
-
var supportedAttributes = ['css'];
|
|
9
|
-
var containsOnlySupportedAttrs = exports.containsOnlySupportedAttrs = function containsOnlySupportedAttrs(node) {
|
|
10
|
-
return node.openingElement.attributes.every(function (attr) {
|
|
11
|
-
if (!(0, _eslintCodemodUtils.isNodeOfType)(attr, 'JSXAttribute')) {
|
|
12
|
-
return false;
|
|
13
|
-
}
|
|
14
|
-
if (!(0, _eslintCodemodUtils.isNodeOfType)(attr.name, 'JSXIdentifier')) {
|
|
15
|
-
return false;
|
|
16
|
-
}
|
|
17
|
-
return supportedAttributes.includes(attr.name.name);
|
|
18
|
-
});
|
|
19
|
-
};
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.validPrimitiveElements = exports.isValidTagName = void 0;
|
|
7
|
-
var validPrimitiveElements = exports.validPrimitiveElements = new Set(['div']);
|
|
8
|
-
var isValidTagName = exports.isValidTagName = function isValidTagName(node) {
|
|
9
|
-
if (node.openingElement.name.type !== 'JSXIdentifier') {
|
|
10
|
-
return false;
|
|
11
|
-
}
|
|
12
|
-
return validPrimitiveElements.has(node.openingElement.name.name);
|
|
13
|
-
};
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.updateJSXElementName = void 0;
|
|
7
|
-
var _eslintCodemodUtils = require("eslint-codemod-utils");
|
|
8
|
-
var updateJSXElementName = exports.updateJSXElementName = function updateJSXElementName(node, newName, fixer) {
|
|
9
|
-
var openingElement = node.openingElement,
|
|
10
|
-
closingElement = node.closingElement;
|
|
11
|
-
var newOpeningElement = fixer.replaceText(openingElement.name, (0, _eslintCodemodUtils.jsxIdentifier)(newName).toString());
|
|
12
|
-
var newClosingElement = closingElement &&
|
|
13
|
-
// Self closing tags, like `<div />` don't need to have the closing tag updated
|
|
14
|
-
fixer.replaceText(closingElement.name, (0, _eslintCodemodUtils.jsxIdentifier)(newName).toString());
|
|
15
|
-
return [newOpeningElement, newClosingElement || undefined];
|
|
16
|
-
};
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.upsertImportDeclaration = void 0;
|
|
7
|
-
var _eslintCodemodUtils = require("eslint-codemod-utils");
|
|
8
|
-
/**
|
|
9
|
-
* Note: Very naive implementation. Does not handle default imports, namespace imports, or aliased imports.
|
|
10
|
-
* Add that functionality when needed.
|
|
11
|
-
*
|
|
12
|
-
* However, does handle duplicate identifiers.
|
|
13
|
-
*/
|
|
14
|
-
var upsertImportDeclaration = exports.upsertImportDeclaration = function upsertImportDeclaration(_ref, context, fixer) {
|
|
15
|
-
var packageName = _ref.packageName,
|
|
16
|
-
specifiers = _ref.specifiers;
|
|
17
|
-
// Find any imports that match the packageName
|
|
18
|
-
var body = context.getSourceCode().ast.body;
|
|
19
|
-
var existingImports = body.filter(function (node) {
|
|
20
|
-
if (!(0, _eslintCodemodUtils.isNodeOfType)(node, 'ImportDeclaration')) {
|
|
21
|
-
return false;
|
|
22
|
-
}
|
|
23
|
-
if (!(0, _eslintCodemodUtils.hasImportDeclaration)(node, packageName)) {
|
|
24
|
-
return false;
|
|
25
|
-
}
|
|
26
|
-
return true;
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* This can happen for cases like:
|
|
31
|
-
* ```
|
|
32
|
-
* import { Stack } from '@atlaskit/primitives'
|
|
33
|
-
* import type { StackProps } from '@atlaskit/primitives'
|
|
34
|
-
* ```
|
|
35
|
-
*
|
|
36
|
-
* Ignore these cases for now to reduce scope creep
|
|
37
|
-
*
|
|
38
|
-
* TODO: Support multiple imports
|
|
39
|
-
*/
|
|
40
|
-
if (existingImports.length > 1) {
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// The import doesn't exist yet, we can just insert a whole new one
|
|
45
|
-
if (existingImports.length === 0) {
|
|
46
|
-
return fixer.insertTextBefore(body[0], "".concat((0, _eslintCodemodUtils.insertImportDeclaration)(packageName, specifiers), ";\n"));
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// The import exists so, modify the existing one
|
|
50
|
-
var existingImport = existingImports[0]; // We have already validated that only one exists
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* `insertImportSpecifier()` has the unfortunate implementation detail of naively adding duplicate specifiers.
|
|
54
|
-
* e.g. calling
|
|
55
|
-
* `insertImportSpecifier(importDecl, 'xcss')`
|
|
56
|
-
* on
|
|
57
|
-
* `import { Inline, xcss } from '@atlaskit/primitives'`
|
|
58
|
-
* will result in:
|
|
59
|
-
* `import { Inline, xcss, xcss } from '@atlaskit/primitives'`.
|
|
60
|
-
* So, we need to filter out specifiers that are already imported.
|
|
61
|
-
*/
|
|
62
|
-
var uniqueImportSpecifiers = specifiers.filter(function (specifier) {
|
|
63
|
-
return !existingImport.specifiers.find(function (existingSpecifier) {
|
|
64
|
-
if (existingSpecifier.type !== 'ImportSpecifier') {
|
|
65
|
-
return false;
|
|
66
|
-
}
|
|
67
|
-
return existingSpecifier.imported.name === specifier;
|
|
68
|
-
});
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
// Ensures the import doesn't end up like: `import { Box, xcss, } from '@atlaskit/primitives';`
|
|
72
|
-
// which can happen if the import decl already contains all import specifiers
|
|
73
|
-
if (uniqueImportSpecifiers.length === 0) {
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
return fixer.replaceText(existingImport, "".concat((0, _eslintCodemodUtils.insertImportSpecifier)(existingImport,
|
|
77
|
-
// `insertImportSpecifier` only accepts one specifier, and we can't call it multiple times on the same import, because fixes can't overlap
|
|
78
|
-
// So, join the array into a string literal, and hope for the best 🤞
|
|
79
|
-
uniqueImportSpecifiers.join(', ')), ";\n"));
|
|
80
|
-
};
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
2
|
-
|
|
3
|
-
export const SUPPORTED_IMPORTS = {
|
|
4
|
-
compiled: '@compiled/react',
|
|
5
|
-
emotionReact: '@emotion/react',
|
|
6
|
-
emotionCore: '@emotion/core',
|
|
7
|
-
styledComponents: 'styled-components'
|
|
8
|
-
};
|
|
9
|
-
const isImportSpecifierWrapper = name => {
|
|
10
|
-
return def => {
|
|
11
|
-
var _def$parent, _def$parent2, _def$parent3, _def$parent4, _def$parent5;
|
|
12
|
-
return def.node.type === 'ImportSpecifier' && def.node.imported.type === 'Identifier' && def.node.imported.name === name && ((_def$parent = def.parent) === null || _def$parent === void 0 ? void 0 : _def$parent.type) === 'ImportDeclaration' && (((_def$parent2 = def.parent) === null || _def$parent2 === void 0 ? void 0 : _def$parent2.source.value) === SUPPORTED_IMPORTS.compiled || ((_def$parent3 = def.parent) === null || _def$parent3 === void 0 ? void 0 : _def$parent3.source.value) === SUPPORTED_IMPORTS.emotionReact || ((_def$parent4 = def.parent) === null || _def$parent4 === void 0 ? void 0 : _def$parent4.source.value) === SUPPORTED_IMPORTS.emotionCore || ((_def$parent5 = def.parent) === null || _def$parent5 === void 0 ? void 0 : _def$parent5.source.value) === SUPPORTED_IMPORTS.styledComponents);
|
|
13
|
-
};
|
|
14
|
-
};
|
|
15
|
-
export const isSupportedImport = name => {
|
|
16
|
-
const isImportSpecifier = isImportSpecifierWrapper(name);
|
|
17
|
-
return (node, references) => node.type === 'Identifier' && references.some(reference => {
|
|
18
|
-
var _reference$resolved;
|
|
19
|
-
return reference.identifier === node && ((_reference$resolved = reference.resolved) === null || _reference$resolved === void 0 ? void 0 : _reference$resolved.defs.some(isImportSpecifier));
|
|
20
|
-
});
|
|
21
|
-
};
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { updateJSXAttributeByName, updateJSXElementName, upsertImportDeclaration } from '../utils';
|
|
2
|
-
import { cssToXcssTransformer } from './css-to-xcss';
|
|
3
|
-
export const jsxElementToBoxTransformer = (node, context) => {
|
|
4
|
-
return fixer => {
|
|
5
|
-
// Insert `import { Box, xcss } from '@atlaskit/primitives'`
|
|
6
|
-
// Or, if the import exists already, update it to include `Box`, and `xcss`
|
|
7
|
-
const importFixes = upsertImportDeclaration({
|
|
8
|
-
packageName: '@atlaskit/primitives',
|
|
9
|
-
specifiers: ['Box', 'xcss']
|
|
10
|
-
}, context, fixer);
|
|
11
|
-
const elementNameFixes = updateJSXElementName(node, 'Box', fixer);
|
|
12
|
-
const attributeFix = updateJSXAttributeByName('css', 'xcss', node, fixer);
|
|
13
|
-
const cssToXcssTransform = cssToXcssTransformer(node, context, fixer);
|
|
14
|
-
return [importFixes, attributeFix, ...elementNameFixes, ...cssToXcssTransform].filter(fix => Boolean(fix)); // Some of the transformers can return arrays with undefined, so filter them out
|
|
15
|
-
};
|
|
16
|
-
};
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { isNodeOfType } from 'eslint-codemod-utils';
|
|
2
|
-
import { updateJSXElementName, upsertImportDeclaration } from '../utils';
|
|
3
|
-
import { styledObjectToXcssTokens } from './css-to-xcss';
|
|
4
|
-
/**
|
|
5
|
-
* All required validation steps have been taken care of before this
|
|
6
|
-
* transformer is called, so it just goes ahead providing all necessary fixes
|
|
7
|
-
*/
|
|
8
|
-
export const styledComponentToPrimitive = ({
|
|
9
|
-
stylesRef,
|
|
10
|
-
jsxRef
|
|
11
|
-
}, context) => {
|
|
12
|
-
return fixer => {
|
|
13
|
-
// generates the new variable name: MyComponent -> myComponentStyles
|
|
14
|
-
const calculatedStylesVariableName = isNodeOfType(stylesRef.id, 'Identifier') && `${stylesRef.id.name.replace(stylesRef.id.name[0], stylesRef.id.name[0].toLowerCase())}Styles`;
|
|
15
|
-
if (!calculatedStylesVariableName) {
|
|
16
|
-
return [];
|
|
17
|
-
}
|
|
18
|
-
const importFixes = upsertImportDeclaration({
|
|
19
|
-
packageName: '@atlaskit/primitives',
|
|
20
|
-
specifiers: ['Box', 'xcss']
|
|
21
|
-
}, context, fixer);
|
|
22
|
-
const stylesFixes = convertStyledComponentToXcss(stylesRef, calculatedStylesVariableName, fixer);
|
|
23
|
-
const jsxFixes = convertJsxCallSite(jsxRef, calculatedStylesVariableName, fixer);
|
|
24
|
-
return [importFixes, ...stylesFixes, ...jsxFixes].filter(fix => Boolean(fix)); // Some of the transformers can return arrays with undefined, so filter them out
|
|
25
|
-
};
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
const convertStyledComponentToXcss = (stylesRef, newStylesVariableName, fixer) => {
|
|
29
|
-
const fixes = [];
|
|
30
|
-
|
|
31
|
-
// renames the variable from MyComponent to myComponentStyles
|
|
32
|
-
fixes.push(fixer.replaceText(stylesRef.id, newStylesVariableName));
|
|
33
|
-
|
|
34
|
-
// renames the function call from styled.<tag> to xcss
|
|
35
|
-
if (stylesRef.init && isNodeOfType(stylesRef.init, 'CallExpression')) {
|
|
36
|
-
fixes.push(fixer.replaceText(stylesRef.init.callee, 'xcss'));
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
// converts CSS values to XCSS-compatible tokens
|
|
40
|
-
if (stylesRef.init && isNodeOfType(stylesRef.init, 'CallExpression')) {
|
|
41
|
-
const objectExpression = stylesRef.init.arguments[0];
|
|
42
|
-
if (isNodeOfType(objectExpression, 'ObjectExpression')) {
|
|
43
|
-
fixes.push(...styledObjectToXcssTokens(objectExpression, fixer));
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
return fixes;
|
|
47
|
-
};
|
|
48
|
-
const convertJsxCallSite = (jsxRef, newStylesVariableName, fixer) => {
|
|
49
|
-
const fixes = [];
|
|
50
|
-
|
|
51
|
-
// renames the JSX call site
|
|
52
|
-
if (isNodeOfType(jsxRef.parent, 'JSXElement')) {
|
|
53
|
-
fixes.push(...updateJSXElementName(jsxRef.parent, 'Box', fixer));
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// adds xcss prop
|
|
57
|
-
fixes.push(fixer.insertTextAfter(jsxRef.name, ` xcss={${newStylesVariableName}}`));
|
|
58
|
-
return fixes;
|
|
59
|
-
};
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { isNodeOfType } from 'eslint-codemod-utils';
|
|
2
|
-
const supportedAttributes = ['css'];
|
|
3
|
-
export const containsOnlySupportedAttrs = node => {
|
|
4
|
-
return node.openingElement.attributes.every(attr => {
|
|
5
|
-
if (!isNodeOfType(attr, 'JSXAttribute')) {
|
|
6
|
-
return false;
|
|
7
|
-
}
|
|
8
|
-
if (!isNodeOfType(attr.name, 'JSXIdentifier')) {
|
|
9
|
-
return false;
|
|
10
|
-
}
|
|
11
|
-
return supportedAttributes.includes(attr.name.name);
|
|
12
|
-
});
|
|
13
|
-
};
|