@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,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
|
-
};
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { hasImportDeclaration, insertImportDeclaration, insertImportSpecifier, isNodeOfType } from 'eslint-codemod-utils';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Note: Very naive implementation. Does not handle default imports, namespace imports, or aliased imports.
|
|
5
|
-
* Add that functionality when needed.
|
|
6
|
-
*
|
|
7
|
-
* However, does handle duplicate identifiers.
|
|
8
|
-
*/
|
|
9
|
-
export const upsertImportDeclaration = ({
|
|
10
|
-
packageName,
|
|
11
|
-
specifiers
|
|
12
|
-
}, context, fixer) => {
|
|
13
|
-
// Find any imports that match the packageName
|
|
14
|
-
const body = context.getSourceCode().ast.body;
|
|
15
|
-
const existingImports = body.filter(node => {
|
|
16
|
-
if (!isNodeOfType(node, 'ImportDeclaration')) {
|
|
17
|
-
return false;
|
|
18
|
-
}
|
|
19
|
-
if (!hasImportDeclaration(node, packageName)) {
|
|
20
|
-
return false;
|
|
21
|
-
}
|
|
22
|
-
return true;
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* This can happen for cases like:
|
|
27
|
-
* ```
|
|
28
|
-
* import { Stack } from '@atlaskit/primitives'
|
|
29
|
-
* import type { StackProps } from '@atlaskit/primitives'
|
|
30
|
-
* ```
|
|
31
|
-
*
|
|
32
|
-
* Ignore these cases for now to reduce scope creep
|
|
33
|
-
*
|
|
34
|
-
* TODO: Support multiple imports
|
|
35
|
-
*/
|
|
36
|
-
if (existingImports.length > 1) {
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// The import doesn't exist yet, we can just insert a whole new one
|
|
41
|
-
if (existingImports.length === 0) {
|
|
42
|
-
return fixer.insertTextBefore(body[0], `${insertImportDeclaration(packageName, specifiers)};\n`);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// The import exists so, modify the existing one
|
|
46
|
-
const existingImport = existingImports[0]; // We have already validated that only one exists
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* `insertImportSpecifier()` has the unfortunate implementation detail of naively adding duplicate specifiers.
|
|
50
|
-
* e.g. calling
|
|
51
|
-
* `insertImportSpecifier(importDecl, 'xcss')`
|
|
52
|
-
* on
|
|
53
|
-
* `import { Inline, xcss } from '@atlaskit/primitives'`
|
|
54
|
-
* will result in:
|
|
55
|
-
* `import { Inline, xcss, xcss } from '@atlaskit/primitives'`.
|
|
56
|
-
* So, we need to filter out specifiers that are already imported.
|
|
57
|
-
*/
|
|
58
|
-
const uniqueImportSpecifiers = specifiers.filter(specifier => {
|
|
59
|
-
return !existingImport.specifiers.find(existingSpecifier => {
|
|
60
|
-
if (existingSpecifier.type !== 'ImportSpecifier') {
|
|
61
|
-
return false;
|
|
62
|
-
}
|
|
63
|
-
return existingSpecifier.imported.name === specifier;
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
// Ensures the import doesn't end up like: `import { Box, xcss, } from '@atlaskit/primitives';`
|
|
68
|
-
// which can happen if the import decl already contains all import specifiers
|
|
69
|
-
if (uniqueImportSpecifiers.length === 0) {
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
return fixer.replaceText(existingImport, `${insertImportSpecifier(existingImport,
|
|
73
|
-
// `insertImportSpecifier` only accepts one specifier, and we can't call it multiple times on the same import, because fixes can't overlap
|
|
74
|
-
// So, join the array into a string literal, and hope for the best 🤞
|
|
75
|
-
uniqueImportSpecifiers.join(', '))};\n`);
|
|
76
|
-
};
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
2
|
-
|
|
3
|
-
export var SUPPORTED_IMPORTS = {
|
|
4
|
-
compiled: '@compiled/react',
|
|
5
|
-
emotionReact: '@emotion/react',
|
|
6
|
-
emotionCore: '@emotion/core',
|
|
7
|
-
styledComponents: 'styled-components'
|
|
8
|
-
};
|
|
9
|
-
var isImportSpecifierWrapper = function isImportSpecifierWrapper(name) {
|
|
10
|
-
return function (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 var isSupportedImport = function isSupportedImport(name) {
|
|
16
|
-
var isImportSpecifier = isImportSpecifierWrapper(name);
|
|
17
|
-
return function (node, references) {
|
|
18
|
-
return node.type === 'Identifier' && references.some(function (reference) {
|
|
19
|
-
var _reference$resolved;
|
|
20
|
-
return reference.identifier === node && ((_reference$resolved = reference.resolved) === null || _reference$resolved === void 0 ? void 0 : _reference$resolved.defs.some(isImportSpecifier));
|
|
21
|
-
});
|
|
22
|
-
};
|
|
23
|
-
};
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
2
|
-
import { updateJSXAttributeByName, updateJSXElementName, upsertImportDeclaration } from '../utils';
|
|
3
|
-
import { cssToXcssTransformer } from './css-to-xcss';
|
|
4
|
-
export var jsxElementToBoxTransformer = function jsxElementToBoxTransformer(node, context) {
|
|
5
|
-
return function (fixer) {
|
|
6
|
-
// Insert `import { Box, xcss } from '@atlaskit/primitives'`
|
|
7
|
-
// Or, if the import exists already, update it to include `Box`, and `xcss`
|
|
8
|
-
var importFixes = upsertImportDeclaration({
|
|
9
|
-
packageName: '@atlaskit/primitives',
|
|
10
|
-
specifiers: ['Box', 'xcss']
|
|
11
|
-
}, context, fixer);
|
|
12
|
-
var elementNameFixes = updateJSXElementName(node, 'Box', fixer);
|
|
13
|
-
var attributeFix = updateJSXAttributeByName('css', 'xcss', node, fixer);
|
|
14
|
-
var cssToXcssTransform = cssToXcssTransformer(node, context, fixer);
|
|
15
|
-
return [importFixes, attributeFix].concat(_toConsumableArray(elementNameFixes), _toConsumableArray(cssToXcssTransform)).filter(function (fix) {
|
|
16
|
-
return Boolean(fix);
|
|
17
|
-
}); // Some of the transformers can return arrays with undefined, so filter them out
|
|
18
|
-
};
|
|
19
|
-
};
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
2
|
-
import { isNodeOfType } from 'eslint-codemod-utils';
|
|
3
|
-
import { updateJSXElementName, upsertImportDeclaration } from '../utils';
|
|
4
|
-
import { styledObjectToXcssTokens } from './css-to-xcss';
|
|
5
|
-
/**
|
|
6
|
-
* All required validation steps have been taken care of before this
|
|
7
|
-
* transformer is called, so it just goes ahead providing all necessary fixes
|
|
8
|
-
*/
|
|
9
|
-
export var styledComponentToPrimitive = function styledComponentToPrimitive(_ref, context) {
|
|
10
|
-
var stylesRef = _ref.stylesRef,
|
|
11
|
-
jsxRef = _ref.jsxRef;
|
|
12
|
-
return function (fixer) {
|
|
13
|
-
// generates the new variable name: MyComponent -> myComponentStyles
|
|
14
|
-
var calculatedStylesVariableName = isNodeOfType(stylesRef.id, 'Identifier') && "".concat(stylesRef.id.name.replace(stylesRef.id.name[0], stylesRef.id.name[0].toLowerCase()), "Styles");
|
|
15
|
-
if (!calculatedStylesVariableName) {
|
|
16
|
-
return [];
|
|
17
|
-
}
|
|
18
|
-
var importFixes = upsertImportDeclaration({
|
|
19
|
-
packageName: '@atlaskit/primitives',
|
|
20
|
-
specifiers: ['Box', 'xcss']
|
|
21
|
-
}, context, fixer);
|
|
22
|
-
var stylesFixes = convertStyledComponentToXcss(stylesRef, calculatedStylesVariableName, fixer);
|
|
23
|
-
var jsxFixes = convertJsxCallSite(jsxRef, calculatedStylesVariableName, fixer);
|
|
24
|
-
return [importFixes].concat(stylesFixes, jsxFixes).filter(function (fix) {
|
|
25
|
-
return Boolean(fix);
|
|
26
|
-
}); // Some of the transformers can return arrays with undefined, so filter them out
|
|
27
|
-
};
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
var convertStyledComponentToXcss = function convertStyledComponentToXcss(stylesRef, newStylesVariableName, fixer) {
|
|
31
|
-
var fixes = [];
|
|
32
|
-
|
|
33
|
-
// renames the variable from MyComponent to myComponentStyles
|
|
34
|
-
fixes.push(fixer.replaceText(stylesRef.id, newStylesVariableName));
|
|
35
|
-
|
|
36
|
-
// renames the function call from styled.<tag> to xcss
|
|
37
|
-
if (stylesRef.init && isNodeOfType(stylesRef.init, 'CallExpression')) {
|
|
38
|
-
fixes.push(fixer.replaceText(stylesRef.init.callee, 'xcss'));
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// converts CSS values to XCSS-compatible tokens
|
|
42
|
-
if (stylesRef.init && isNodeOfType(stylesRef.init, 'CallExpression')) {
|
|
43
|
-
var objectExpression = stylesRef.init.arguments[0];
|
|
44
|
-
if (isNodeOfType(objectExpression, 'ObjectExpression')) {
|
|
45
|
-
fixes.push.apply(fixes, _toConsumableArray(styledObjectToXcssTokens(objectExpression, fixer)));
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
return fixes;
|
|
49
|
-
};
|
|
50
|
-
var convertJsxCallSite = function convertJsxCallSite(jsxRef, newStylesVariableName, fixer) {
|
|
51
|
-
var fixes = [];
|
|
52
|
-
|
|
53
|
-
// renames the JSX call site
|
|
54
|
-
if (isNodeOfType(jsxRef.parent, 'JSXElement')) {
|
|
55
|
-
fixes.push.apply(fixes, _toConsumableArray(updateJSXElementName(jsxRef.parent, 'Box', fixer)));
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// adds xcss prop
|
|
59
|
-
fixes.push(fixer.insertTextAfter(jsxRef.name, " xcss={".concat(newStylesVariableName, "}")));
|
|
60
|
-
return fixes;
|
|
61
|
-
};
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { isNodeOfType } from 'eslint-codemod-utils';
|
|
2
|
-
var supportedAttributes = ['css'];
|
|
3
|
-
export var containsOnlySupportedAttrs = function containsOnlySupportedAttrs(node) {
|
|
4
|
-
return node.openingElement.attributes.every(function (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,10 +0,0 @@
|
|
|
1
|
-
import { jsxIdentifier } from 'eslint-codemod-utils';
|
|
2
|
-
export var updateJSXElementName = function updateJSXElementName(node, newName, fixer) {
|
|
3
|
-
var openingElement = node.openingElement,
|
|
4
|
-
closingElement = node.closingElement;
|
|
5
|
-
var newOpeningElement = fixer.replaceText(openingElement.name, jsxIdentifier(newName).toString());
|
|
6
|
-
var newClosingElement = closingElement &&
|
|
7
|
-
// Self closing tags, like `<div />` don't need to have the closing tag updated
|
|
8
|
-
fixer.replaceText(closingElement.name, jsxIdentifier(newName).toString());
|
|
9
|
-
return [newOpeningElement, newClosingElement || undefined];
|
|
10
|
-
};
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { hasImportDeclaration, insertImportDeclaration, insertImportSpecifier, isNodeOfType } from 'eslint-codemod-utils';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Note: Very naive implementation. Does not handle default imports, namespace imports, or aliased imports.
|
|
5
|
-
* Add that functionality when needed.
|
|
6
|
-
*
|
|
7
|
-
* However, does handle duplicate identifiers.
|
|
8
|
-
*/
|
|
9
|
-
export var upsertImportDeclaration = function upsertImportDeclaration(_ref, context, fixer) {
|
|
10
|
-
var packageName = _ref.packageName,
|
|
11
|
-
specifiers = _ref.specifiers;
|
|
12
|
-
// Find any imports that match the packageName
|
|
13
|
-
var body = context.getSourceCode().ast.body;
|
|
14
|
-
var existingImports = body.filter(function (node) {
|
|
15
|
-
if (!isNodeOfType(node, 'ImportDeclaration')) {
|
|
16
|
-
return false;
|
|
17
|
-
}
|
|
18
|
-
if (!hasImportDeclaration(node, packageName)) {
|
|
19
|
-
return false;
|
|
20
|
-
}
|
|
21
|
-
return true;
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* This can happen for cases like:
|
|
26
|
-
* ```
|
|
27
|
-
* import { Stack } from '@atlaskit/primitives'
|
|
28
|
-
* import type { StackProps } from '@atlaskit/primitives'
|
|
29
|
-
* ```
|
|
30
|
-
*
|
|
31
|
-
* Ignore these cases for now to reduce scope creep
|
|
32
|
-
*
|
|
33
|
-
* TODO: Support multiple imports
|
|
34
|
-
*/
|
|
35
|
-
if (existingImports.length > 1) {
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
// The import doesn't exist yet, we can just insert a whole new one
|
|
40
|
-
if (existingImports.length === 0) {
|
|
41
|
-
return fixer.insertTextBefore(body[0], "".concat(insertImportDeclaration(packageName, specifiers), ";\n"));
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// The import exists so, modify the existing one
|
|
45
|
-
var existingImport = existingImports[0]; // We have already validated that only one exists
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* `insertImportSpecifier()` has the unfortunate implementation detail of naively adding duplicate specifiers.
|
|
49
|
-
* e.g. calling
|
|
50
|
-
* `insertImportSpecifier(importDecl, 'xcss')`
|
|
51
|
-
* on
|
|
52
|
-
* `import { Inline, xcss } from '@atlaskit/primitives'`
|
|
53
|
-
* will result in:
|
|
54
|
-
* `import { Inline, xcss, xcss } from '@atlaskit/primitives'`.
|
|
55
|
-
* So, we need to filter out specifiers that are already imported.
|
|
56
|
-
*/
|
|
57
|
-
var uniqueImportSpecifiers = specifiers.filter(function (specifier) {
|
|
58
|
-
return !existingImport.specifiers.find(function (existingSpecifier) {
|
|
59
|
-
if (existingSpecifier.type !== 'ImportSpecifier') {
|
|
60
|
-
return false;
|
|
61
|
-
}
|
|
62
|
-
return existingSpecifier.imported.name === specifier;
|
|
63
|
-
});
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
// Ensures the import doesn't end up like: `import { Box, xcss, } from '@atlaskit/primitives';`
|
|
67
|
-
// which can happen if the import decl already contains all import specifiers
|
|
68
|
-
if (uniqueImportSpecifiers.length === 0) {
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
return fixer.replaceText(existingImport, "".concat(insertImportSpecifier(existingImport,
|
|
72
|
-
// `insertImportSpecifier` only accepts one specifier, and we can't call it multiple times on the same import, because fixes can't overlap
|
|
73
|
-
// So, join the array into a string literal, and hope for the best 🤞
|
|
74
|
-
uniqueImportSpecifiers.join(', ')), ";\n"));
|
|
75
|
-
};
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { Rule, Scope } from 'eslint';
|
|
2
|
-
type Node = Rule.Node;
|
|
3
|
-
type Reference = Scope.Reference;
|
|
4
|
-
type SupportedNameChecker = (node: Node, references: Reference[]) => boolean;
|
|
5
|
-
export declare const SUPPORTED_IMPORTS: {
|
|
6
|
-
compiled: string;
|
|
7
|
-
emotionReact: string;
|
|
8
|
-
emotionCore: string;
|
|
9
|
-
styledComponents: string;
|
|
10
|
-
};
|
|
11
|
-
export declare const isSupportedImport: (name: string) => SupportedNameChecker;
|
|
12
|
-
export {};
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { Rule } from 'eslint';
|
|
2
|
-
import { JSXOpeningElement, VariableDeclarator } from 'eslint-codemod-utils';
|
|
3
|
-
type StylesRef = VariableDeclarator & Rule.NodeParentExtension;
|
|
4
|
-
type JSXRef = JSXOpeningElement & Rule.NodeParentExtension;
|
|
5
|
-
/**
|
|
6
|
-
* All required validation steps have been taken care of before this
|
|
7
|
-
* transformer is called, so it just goes ahead providing all necessary fixes
|
|
8
|
-
*/
|
|
9
|
-
export declare const styledComponentToPrimitive: ({ stylesRef, jsxRef, }: {
|
|
10
|
-
stylesRef: StylesRef;
|
|
11
|
-
jsxRef: JSXRef;
|
|
12
|
-
}, context: Rule.RuleContext) => (fixer: Rule.RuleFixer) => Rule.Fix[];
|
|
13
|
-
export {};
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { Rule } from 'eslint';
|
|
2
|
-
/**
|
|
3
|
-
* Note: Very naive implementation. Does not handle default imports, namespace imports, or aliased imports.
|
|
4
|
-
* Add that functionality when needed.
|
|
5
|
-
*
|
|
6
|
-
* However, does handle duplicate identifiers.
|
|
7
|
-
*/
|
|
8
|
-
export declare const upsertImportDeclaration: ({ packageName, specifiers, }: {
|
|
9
|
-
packageName: string;
|
|
10
|
-
specifiers: string[];
|
|
11
|
-
}, context: Rule.RuleContext, fixer: Rule.RuleFixer) => Rule.Fix | undefined;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { Rule, Scope } from 'eslint';
|
|
2
|
-
type Node = Rule.Node;
|
|
3
|
-
type Reference = Scope.Reference;
|
|
4
|
-
type SupportedNameChecker = (node: Node, references: Reference[]) => boolean;
|
|
5
|
-
export declare const SUPPORTED_IMPORTS: {
|
|
6
|
-
compiled: string;
|
|
7
|
-
emotionReact: string;
|
|
8
|
-
emotionCore: string;
|
|
9
|
-
styledComponents: string;
|
|
10
|
-
};
|
|
11
|
-
export declare const isSupportedImport: (name: string) => SupportedNameChecker;
|
|
12
|
-
export {};
|
package/dist/types-ts4.5/rules/use-primitives/transformers/styled-component-to-primitive.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { Rule } from 'eslint';
|
|
2
|
-
import { JSXOpeningElement, VariableDeclarator } from 'eslint-codemod-utils';
|
|
3
|
-
type StylesRef = VariableDeclarator & Rule.NodeParentExtension;
|
|
4
|
-
type JSXRef = JSXOpeningElement & Rule.NodeParentExtension;
|
|
5
|
-
/**
|
|
6
|
-
* All required validation steps have been taken care of before this
|
|
7
|
-
* transformer is called, so it just goes ahead providing all necessary fixes
|
|
8
|
-
*/
|
|
9
|
-
export declare const styledComponentToPrimitive: ({ stylesRef, jsxRef, }: {
|
|
10
|
-
stylesRef: StylesRef;
|
|
11
|
-
jsxRef: JSXRef;
|
|
12
|
-
}, context: Rule.RuleContext) => (fixer: Rule.RuleFixer) => Rule.Fix[];
|
|
13
|
-
export {};
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { Rule } from 'eslint';
|
|
2
|
-
/**
|
|
3
|
-
* Note: Very naive implementation. Does not handle default imports, namespace imports, or aliased imports.
|
|
4
|
-
* Add that functionality when needed.
|
|
5
|
-
*
|
|
6
|
-
* However, does handle duplicate identifiers.
|
|
7
|
-
*/
|
|
8
|
-
export declare const upsertImportDeclaration: ({ packageName, specifiers, }: {
|
|
9
|
-
packageName: string;
|
|
10
|
-
specifiers: string[];
|
|
11
|
-
}, context: Rule.RuleContext, fixer: Rule.RuleFixer) => Rule.Fix | undefined;
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|