@atlaskit/eslint-plugin-design-system 8.23.2 → 8.23.3
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 +7 -0
- package/dist/cjs/rules/consistent-css-prop-usage/index.js +25 -5
- 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/es2019/rules/consistent-css-prop-usage/index.js +23 -5
- 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/esm/rules/consistent-css-prop-usage/index.js +25 -5
- 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/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-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/package.json +1 -1
- 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/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/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/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/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
package/dist/types/rules/use-primitives/transformers/emotion-css/contains-only-supported-attrs.d.ts
ADDED
|
@@ -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 {};
|
package/dist/types/rules/use-primitives/transformers/emotion-css/upsert-import-declaration.d.ts
ADDED
|
@@ -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,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';
|
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.3",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -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,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
|
-
};
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { jsxIdentifier } from 'eslint-codemod-utils';
|
|
2
|
-
export const updateJSXElementName = (node, newName, fixer) => {
|
|
3
|
-
const {
|
|
4
|
-
openingElement,
|
|
5
|
-
closingElement
|
|
6
|
-
} = node;
|
|
7
|
-
const newOpeningElement = fixer.replaceText(openingElement.name, jsxIdentifier(newName).toString());
|
|
8
|
-
const newClosingElement = closingElement &&
|
|
9
|
-
// Self closing tags, like `<div />` don't need to have the closing tag updated
|
|
10
|
-
fixer.replaceText(closingElement.name, jsxIdentifier(newName).toString());
|
|
11
|
-
return [newOpeningElement, newClosingElement || undefined];
|
|
12
|
-
};
|