@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
|
@@ -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 {
|
|
13
|
-
export { updateJSXAttributeByName } from './update-jsx-attribute-by-name';
|
|
14
|
-
export { updateJSXElementName } from './update-jsx-element-name';
|
|
15
|
-
export { upsertImportDeclaration } from './upsert-import-declaration';
|
|
9
|
+
export { updateJSXAttributeByName } from './update-jsx-attribute-by-name';
|
|
@@ -6,6 +6,8 @@ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
|
6
6
|
import { getIdentifierInParentScope, isNodeOfType } from 'eslint-codemod-utils';
|
|
7
7
|
import assign from 'lodash/assign';
|
|
8
8
|
import { createLintRule } from '../utils/create-rule';
|
|
9
|
+
// File-level tracking of styles hoisted from the cssOnTopOfModule/cssAtBottomOfModule fixers
|
|
10
|
+
var hoistedCss = [];
|
|
9
11
|
function isCssCallExpression(node, cssFunctions) {
|
|
10
12
|
cssFunctions = [].concat(_toConsumableArray(cssFunctions), ['cssMap']);
|
|
11
13
|
return !!(isNodeOfType(node, 'CallExpression') && node.callee && node.callee.type === 'Identifier' && cssFunctions.includes(node.callee.name) && node.arguments.length && node.arguments[0].type === 'ObjectExpression');
|
|
@@ -18,11 +20,11 @@ function findSpreadProperties(node) {
|
|
|
18
20
|
property.type === 'ExperimentalSpreadProperty';
|
|
19
21
|
});
|
|
20
22
|
}
|
|
21
|
-
var
|
|
23
|
+
var getProgramNode = function getProgramNode(expression) {
|
|
22
24
|
while (expression.parent.type !== 'Program') {
|
|
23
25
|
expression = expression.parent;
|
|
24
26
|
}
|
|
25
|
-
return expression;
|
|
27
|
+
return expression.parent;
|
|
26
28
|
};
|
|
27
29
|
|
|
28
30
|
// TODO: This can be optimised by implementing a fixer at the very end (Program:exit) and handling all validations at once
|
|
@@ -41,7 +43,7 @@ var getDeclaratorString = function getDeclaratorString(context) {
|
|
|
41
43
|
}
|
|
42
44
|
var variables = scope.variables.map(function (variable) {
|
|
43
45
|
return variable.name;
|
|
44
|
-
});
|
|
46
|
+
}).concat(hoistedCss);
|
|
45
47
|
var count = 2;
|
|
46
48
|
var declaratorName = 'styles';
|
|
47
49
|
|
|
@@ -54,6 +56,9 @@ var getDeclaratorString = function getDeclaratorString(context) {
|
|
|
54
56
|
count++;
|
|
55
57
|
}
|
|
56
58
|
}
|
|
59
|
+
|
|
60
|
+
// Keep track of it by adding it to the hoistedCss global array
|
|
61
|
+
hoistedCss = [].concat(_toConsumableArray(hoistedCss), ["".concat(declaratorName).concat(count)]);
|
|
57
62
|
return "".concat(declaratorName).concat(count);
|
|
58
63
|
};
|
|
59
64
|
function analyzeIdentifier(context, sourceIdentifier, configuration) {
|
|
@@ -116,7 +121,19 @@ function analyzeIdentifier(context, sourceIdentifier, configuration) {
|
|
|
116
121
|
*/
|
|
117
122
|
var fixCssNotInModuleScope = function fixCssNotInModuleScope(fixer, context, configuration, node, cssAttributeName) {
|
|
118
123
|
var sourceCode = context.getSourceCode();
|
|
119
|
-
|
|
124
|
+
|
|
125
|
+
// Get the program node in order to properly position the hoisted styles
|
|
126
|
+
var programNode = getProgramNode(node);
|
|
127
|
+
var fixerNodePlacement = programNode;
|
|
128
|
+
if (configuration.stylesPlacement === 'bottom') {
|
|
129
|
+
// The last value is the bottom of the file
|
|
130
|
+
fixerNodePlacement = programNode.body[programNode.body.length - 1];
|
|
131
|
+
} else {
|
|
132
|
+
// Place after the last ImportDeclaration
|
|
133
|
+
fixerNodePlacement = programNode.body.length === 1 ? programNode.body[0] : programNode.body.find(function (node) {
|
|
134
|
+
return node.type !== 'ImportDeclaration';
|
|
135
|
+
});
|
|
136
|
+
}
|
|
120
137
|
var moduleString;
|
|
121
138
|
var implementFixer = [];
|
|
122
139
|
if (node.type === 'Identifier') {
|
|
@@ -138,7 +155,7 @@ var fixCssNotInModuleScope = function fixCssNotInModuleScope(fixer, context, con
|
|
|
138
155
|
}
|
|
139
156
|
return [].concat(implementFixer, [
|
|
140
157
|
// Insert the node either before or after
|
|
141
|
-
configuration.stylesPlacement === 'bottom' ? fixer.insertTextAfter(
|
|
158
|
+
configuration.stylesPlacement === 'bottom' ? fixer.insertTextAfter(fixerNodePlacement, '\n' + moduleString) : fixer.insertTextBefore(fixerNodePlacement, moduleString + '\n')]);
|
|
142
159
|
};
|
|
143
160
|
|
|
144
161
|
/**
|
|
@@ -269,6 +286,9 @@ var rule = createLintRule({
|
|
|
269
286
|
}), _defineProperty(_ref3, "JSXAttribute", function JSXAttribute(node) {
|
|
270
287
|
var name = node.name,
|
|
271
288
|
value = node.value;
|
|
289
|
+
|
|
290
|
+
// Always reset to empty array
|
|
291
|
+
hoistedCss = [];
|
|
272
292
|
if (name.type === 'JSXIdentifier' && mergedConfig.cssFunctions.includes(name.name)) {
|
|
273
293
|
// When not a jsx expression. For eg. css=""
|
|
274
294
|
if ((value === null || value === void 0 ? void 0 : value.type) !== 'JSXExpressionContainer') {
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
import { isNodeOfType } from 'eslint-codemod-utils';
|
|
2
1
|
import { createLintRule } from '../utils/create-rule';
|
|
3
2
|
import { getConfig } from './config';
|
|
4
|
-
import {
|
|
5
|
-
import { EmotionCSS } from './transformers/emotion-css';
|
|
6
|
-
import { findValidJsxUsageToTransform, findValidStyledComponentCall, isValidCssPropertiesToTransform } from './utils';
|
|
3
|
+
import { CompiledStyled, EmotionCSS } from './transformers';
|
|
7
4
|
var boxDocsUrl = 'https://atlassian.design/components/primitives/box';
|
|
8
5
|
var rule = createLintRule({
|
|
9
6
|
meta: {
|
|
@@ -25,32 +22,9 @@ var rule = createLintRule({
|
|
|
25
22
|
return {
|
|
26
23
|
// transforms styled.<html>(...) usages
|
|
27
24
|
CallExpression: function CallExpression(node) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
if (!isNodeOfType(node, 'CallExpression')) {
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
var styledComponentVariableRef = findValidStyledComponentCall(node);
|
|
35
|
-
if (!styledComponentVariableRef || !isNodeOfType(styledComponentVariableRef.id, 'Identifier') || !isValidCssPropertiesToTransform(node, config)) {
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
var styledComponentJsxRef = findValidJsxUsageToTransform(styledComponentVariableRef.id.name, context.getScope());
|
|
39
|
-
if (!styledComponentJsxRef) {
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// if we have both references at this point then we can offer a fix \o/
|
|
44
|
-
context.report({
|
|
45
|
-
node: styledComponentVariableRef,
|
|
46
|
-
messageId: 'preferPrimitivesBox',
|
|
47
|
-
suggest: [{
|
|
48
|
-
desc: "Convert ".concat(styledComponentVariableRef.id.name, " to Box"),
|
|
49
|
-
fix: styledComponentToPrimitive({
|
|
50
|
-
stylesRef: styledComponentVariableRef,
|
|
51
|
-
jsxRef: styledComponentJsxRef
|
|
52
|
-
}, context)
|
|
53
|
-
}]
|
|
25
|
+
CompiledStyled.lint(node, {
|
|
26
|
+
context: context,
|
|
27
|
+
config: config
|
|
54
28
|
});
|
|
55
29
|
},
|
|
56
30
|
// transforms <div css={...}> usages
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
2
|
+
import { isNodeOfType } from 'eslint-codemod-utils';
|
|
3
|
+
import * as ast from '../../../../ast-nodes';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Transforms a JSXElement from:
|
|
7
|
+
* ```
|
|
8
|
+
* <div>
|
|
9
|
+
* // ...
|
|
10
|
+
* </div>
|
|
11
|
+
* ```
|
|
12
|
+
* to
|
|
13
|
+
* ```
|
|
14
|
+
* <Box xcss={myStyles}>
|
|
15
|
+
* // ...
|
|
16
|
+
* </Box>
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export var convertJsxCallSite = function convertJsxCallSite(jsxElement, newStylesVariableName, fixer) {
|
|
20
|
+
var fixes = [];
|
|
21
|
+
|
|
22
|
+
// renames the JSX call site
|
|
23
|
+
if (isNodeOfType(jsxElement, 'JSXElement')) {
|
|
24
|
+
fixes.push.apply(fixes, _toConsumableArray(ast.JSXElement.updateName(jsxElement, 'Box', fixer)));
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// adds xcss prop
|
|
28
|
+
fixes.push(fixer.insertTextAfter(jsxElement.openingElement.name, " xcss={".concat(newStylesVariableName, "}")));
|
|
29
|
+
return fixes;
|
|
30
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
2
|
+
import { isNodeOfType } from 'eslint-codemod-utils';
|
|
3
|
+
import { styledObjectToXcssTokens } from '../css-to-xcss';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Transforms a variable like:
|
|
7
|
+
* ```
|
|
8
|
+
* const MyComponent = styled.div({
|
|
9
|
+
* padding: '8px',
|
|
10
|
+
* })
|
|
11
|
+
* ```
|
|
12
|
+
* to
|
|
13
|
+
* ```
|
|
14
|
+
* const myComponentStyles = xcss({
|
|
15
|
+
* padding: 'space.100',
|
|
16
|
+
* })
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export var convertStyledComponentToXcss = function convertStyledComponentToXcss(styles, newStylesVariableName, fixer) {
|
|
20
|
+
var fixes = [];
|
|
21
|
+
|
|
22
|
+
// renames the variable from MyComponent to myComponentStyles
|
|
23
|
+
fixes.push(fixer.replaceText(styles.id, newStylesVariableName));
|
|
24
|
+
|
|
25
|
+
// renames the function call from styled.<tag> to xcss
|
|
26
|
+
if (styles.init && isNodeOfType(styles.init, 'CallExpression')) {
|
|
27
|
+
fixes.push(fixer.replaceText(styles.init.callee, 'xcss'));
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// converts CSS values to XCSS-compatible tokens
|
|
31
|
+
if (styles.init && isNodeOfType(styles.init, 'CallExpression')) {
|
|
32
|
+
var objectExpression = styles.init.arguments[0];
|
|
33
|
+
if (isNodeOfType(objectExpression, 'ObjectExpression')) {
|
|
34
|
+
fixes.push.apply(fixes, _toConsumableArray(styledObjectToXcssTokens(objectExpression, fixer)));
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return fixes;
|
|
38
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { closestOfType, isNodeOfType } from 'eslint-codemod-utils';
|
|
2
|
-
import
|
|
2
|
+
import * as supported from './supported';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* returns a variable reference if preconditions are favourable for
|
|
@@ -41,7 +41,7 @@ var isStyledCallExpression = function isStyledCallExpression(call) {
|
|
|
41
41
|
if (!isNodeOfType(call.callee.object, 'Identifier') || !isNodeOfType(call.callee.property, 'Identifier')) {
|
|
42
42
|
return false;
|
|
43
43
|
}
|
|
44
|
-
if (/^styled2?$/.test(call.callee.object.name) &&
|
|
44
|
+
if (/^styled2?$/.test(call.callee.object.name) && supported.elements.includes(call.callee.property.name)) {
|
|
45
45
|
return true;
|
|
46
46
|
}
|
|
47
47
|
return false;
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
2
|
+
/* eslint-disable @repo/internal/react/require-jsdoc */
|
|
3
|
+
|
|
4
|
+
import { isNodeOfType } from 'eslint-codemod-utils';
|
|
5
|
+
import * as ast from '../../../../ast-nodes';
|
|
6
|
+
import { isValidCssPropertiesToTransform } from '../../utils';
|
|
7
|
+
import { convertJsxCallSite } from './convert-jsx-call-site';
|
|
8
|
+
import { convertStyledComponentToXcss } from './convert-styled-component-call-to-jsx';
|
|
9
|
+
import { findValidJsxUsageToTransform } from './find-valid-jsx-usage-to-transform';
|
|
10
|
+
import { findValidStyledComponentCall } from './find-valid-styled-component-call';
|
|
11
|
+
import { upsertImportDeclaration } from './upsert-import-declaration';
|
|
12
|
+
export var CompiledStyled = {
|
|
13
|
+
lint: function lint(node, _ref) {
|
|
14
|
+
var context = _ref.context,
|
|
15
|
+
config = _ref.config;
|
|
16
|
+
if (!isNodeOfType(node, 'CallExpression')) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// Check whether all criteria needed to make a transformation are met
|
|
21
|
+
var _CompiledStyled$_chec = CompiledStyled._check(node, {
|
|
22
|
+
context: context,
|
|
23
|
+
config: config
|
|
24
|
+
}),
|
|
25
|
+
success = _CompiledStyled$_chec.success,
|
|
26
|
+
refs = _CompiledStyled$_chec.refs;
|
|
27
|
+
if (!success || !refs) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
context.report({
|
|
31
|
+
node: refs.styles,
|
|
32
|
+
messageId: 'preferPrimitivesBox',
|
|
33
|
+
suggest: [{
|
|
34
|
+
desc: "Convert ".concat(ast.JSXElement.getName(refs.jsxElement), " to Box"),
|
|
35
|
+
fix: CompiledStyled._fix(refs, context)
|
|
36
|
+
}]
|
|
37
|
+
});
|
|
38
|
+
},
|
|
39
|
+
_check: function _check(node, _ref2) {
|
|
40
|
+
var context = _ref2.context,
|
|
41
|
+
config = _ref2.config;
|
|
42
|
+
if (!config.patterns.includes('compiled-styled-object')) {
|
|
43
|
+
return {
|
|
44
|
+
success: false
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
if (!isNodeOfType(node, 'CallExpression')) {
|
|
48
|
+
return {
|
|
49
|
+
success: false
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
var styledComponentVariableRef = findValidStyledComponentCall(node);
|
|
53
|
+
if (!styledComponentVariableRef || !isNodeOfType(styledComponentVariableRef.id, 'Identifier') || !isValidCssPropertiesToTransform(node, config)) {
|
|
54
|
+
return {
|
|
55
|
+
success: false
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
var styledComponentJsxRef = findValidJsxUsageToTransform(styledComponentVariableRef.id.name, context.getScope());
|
|
59
|
+
if (!styledComponentJsxRef) {
|
|
60
|
+
return {
|
|
61
|
+
success: false
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
if (!isNodeOfType(styledComponentJsxRef.parent, 'JSXElement')) {
|
|
65
|
+
return {
|
|
66
|
+
success: false
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
var importDeclaration = ast.Root.findImportsByModule(context.getSourceCode().ast.body, '@atlaskit/primitives');
|
|
70
|
+
|
|
71
|
+
// If there is more than one `@atlaskit/primitives` import, then it becomes difficult to determine which import to transform
|
|
72
|
+
if (importDeclaration.length > 1) {
|
|
73
|
+
return {
|
|
74
|
+
success: false
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
return {
|
|
78
|
+
success: true,
|
|
79
|
+
refs: {
|
|
80
|
+
styles: styledComponentVariableRef,
|
|
81
|
+
jsxElement: styledComponentJsxRef.parent
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
},
|
|
85
|
+
/**
|
|
86
|
+
* All required validation steps have been taken care of before this
|
|
87
|
+
* transformer is called, so it just goes ahead providing all necessary fixes
|
|
88
|
+
*/
|
|
89
|
+
_fix: function _fix(refs, context) {
|
|
90
|
+
return function (fixer) {
|
|
91
|
+
// generates the new variable name: MyComponent -> myComponentStyles
|
|
92
|
+
var calculatedStylesVariableName = isNodeOfType(refs.styles.id, 'Identifier') && "".concat(refs.styles.id.name.replace(refs.styles.id.name[0], refs.styles.id.name[0].toLowerCase()), "Styles");
|
|
93
|
+
if (!calculatedStylesVariableName) {
|
|
94
|
+
return [];
|
|
95
|
+
}
|
|
96
|
+
var importFixes = upsertImportDeclaration({
|
|
97
|
+
module: '@atlaskit/primitives',
|
|
98
|
+
specifiers: ['Box', 'xcss']
|
|
99
|
+
}, context, fixer);
|
|
100
|
+
var stylesFixes = convertStyledComponentToXcss(refs.styles, calculatedStylesVariableName, fixer);
|
|
101
|
+
var jsxFixes = convertJsxCallSite(refs.jsxElement, calculatedStylesVariableName, fixer);
|
|
102
|
+
return [importFixes].concat(_toConsumableArray(stylesFixes), _toConsumableArray(jsxFixes)).filter(function (fix) {
|
|
103
|
+
return Boolean(fix);
|
|
104
|
+
}); // Some of the transformers can return arrays with undefined, so filter them out
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
};
|
package/dist/esm/rules/use-primitives/transformers/compiled-styled/upsert-import-declaration.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import * as ast from '../../../../ast-nodes';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Currently this is defined here because it's not very general purpose.
|
|
5
|
+
* If we were to move this to `ast-nodes`, half the implementation would be in `Root`,
|
|
6
|
+
* and the other half would be in `Import`.
|
|
7
|
+
*
|
|
8
|
+
* TODO: Refactor and move to `ast-nodes`
|
|
9
|
+
*
|
|
10
|
+
* Note: It does not handle default imports, namespace imports, or aliased imports.
|
|
11
|
+
*/
|
|
12
|
+
export var upsertImportDeclaration = function upsertImportDeclaration(_ref, context, fixer) {
|
|
13
|
+
var module = _ref.module,
|
|
14
|
+
specifiers = _ref.specifiers;
|
|
15
|
+
// Find any imports that match the packageName
|
|
16
|
+
var root = context.getSourceCode().ast.body;
|
|
17
|
+
var importDeclarations = ast.Root.findImportsByModule(root, module);
|
|
18
|
+
|
|
19
|
+
// The import doesn't exist yet, we can just insert a whole new one
|
|
20
|
+
if (importDeclarations.length === 0) {
|
|
21
|
+
return ast.Root.insertImport(root, {
|
|
22
|
+
module: module,
|
|
23
|
+
specifiers: specifiers
|
|
24
|
+
}, fixer);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// The import exists so, modify the existing one
|
|
28
|
+
return ast.Import.insertNamedSpecifiers(importDeclarations[0], specifiers, fixer);
|
|
29
|
+
};
|
package/dist/esm/rules/use-primitives/transformers/emotion-css/contains-only-supported-attrs.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { isNodeOfType } from 'eslint-codemod-utils';
|
|
2
|
+
import * as ast from '../../../../ast-nodes';
|
|
3
|
+
import * as supported from './supported';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Check that every attribute in the JSXElement is something we support.
|
|
7
|
+
* We do this via a whitelist in `this.attributes`. The result is we exclude
|
|
8
|
+
* dangerous attrs like `id` and `style`.
|
|
9
|
+
*/
|
|
10
|
+
export var containsOnlySupportedAttrs = function containsOnlySupportedAttrs(node) {
|
|
11
|
+
var attrs = ast.JSXElement.getAttributes(node);
|
|
12
|
+
return attrs.every(function (attr) {
|
|
13
|
+
if (!isNodeOfType(attr, 'JSXAttribute')) {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
var name = ast.JSXAttribute.getName(attr);
|
|
17
|
+
return supported.attributes.includes(name);
|
|
18
|
+
});
|
|
19
|
+
};
|
|
@@ -5,7 +5,9 @@ import { getIdentifierInParentScope, isNodeOfType } from 'eslint-codemod-utils';
|
|
|
5
5
|
import * as ast from '../../../../ast-nodes';
|
|
6
6
|
import { getVariableDefinitionValue, getVariableUsagesCount, isValidCssPropertiesToTransform } from '../../utils';
|
|
7
7
|
import { cssToXcssTransformer } from '../css-to-xcss';
|
|
8
|
+
import { containsOnlySupportedAttrs } from './contains-only-supported-attrs';
|
|
8
9
|
import * as supported from './supported';
|
|
10
|
+
import { upsertImportDeclaration } from './upsert-import-declaration';
|
|
9
11
|
export var EmotionCSS = {
|
|
10
12
|
lint: function lint(node, _ref) {
|
|
11
13
|
var context = _ref.context,
|
|
@@ -53,7 +55,7 @@ export var EmotionCSS = {
|
|
|
53
55
|
}
|
|
54
56
|
|
|
55
57
|
// Ignore elements that contain dangerous attributes like `id`.
|
|
56
|
-
if (!
|
|
58
|
+
if (!containsOnlySupportedAttrs(node)) {
|
|
57
59
|
return false;
|
|
58
60
|
}
|
|
59
61
|
|
|
@@ -95,10 +97,9 @@ export var EmotionCSS = {
|
|
|
95
97
|
return true;
|
|
96
98
|
},
|
|
97
99
|
_fix: function _fix(node, _ref3) {
|
|
98
|
-
var _this = this;
|
|
99
100
|
var context = _ref3.context;
|
|
100
101
|
return function (fixer) {
|
|
101
|
-
var importFix =
|
|
102
|
+
var importFix = upsertImportDeclaration({
|
|
102
103
|
module: '@atlaskit/primitives',
|
|
103
104
|
specifiers: ['Box', 'xcss']
|
|
104
105
|
}, context, fixer);
|
|
@@ -110,49 +111,5 @@ export var EmotionCSS = {
|
|
|
110
111
|
return Boolean(fix);
|
|
111
112
|
}); // Some of the transformers can return arrays with undefined, so filter them out
|
|
112
113
|
};
|
|
113
|
-
},
|
|
114
|
-
/**
|
|
115
|
-
* Check that every attribute in the JSXElement is something we support.
|
|
116
|
-
* We do this via a whitelist in `this.attributes`. The result is we exclude
|
|
117
|
-
* dangerous attrs like `id` and `style`.
|
|
118
|
-
*/
|
|
119
|
-
_containsOnlySupportedAttributes: function _containsOnlySupportedAttributes(node) {
|
|
120
|
-
var attrs = ast.JSXElement.getAttributes(node);
|
|
121
|
-
return attrs.every(function (attr) {
|
|
122
|
-
if (!isNodeOfType(attr, 'JSXAttribute')) {
|
|
123
|
-
return false;
|
|
124
|
-
}
|
|
125
|
-
if (!isNodeOfType(attr.name, 'JSXIdentifier')) {
|
|
126
|
-
return false;
|
|
127
|
-
}
|
|
128
|
-
return supported.attributes.includes(attr.name.name);
|
|
129
|
-
});
|
|
130
|
-
},
|
|
131
|
-
/**
|
|
132
|
-
* Currently this is defined here because it's not very general purpose.
|
|
133
|
-
* If we were to move this to `ast-nodes`, half the implementation would be in `Root`,
|
|
134
|
-
* and the other half would be in `Import`.
|
|
135
|
-
*
|
|
136
|
-
* TODO: Refactor and move to `ast-nodes`
|
|
137
|
-
*
|
|
138
|
-
* Note: It does not handle default imports, namespace imports, or aliased imports.
|
|
139
|
-
*/
|
|
140
|
-
_upsertImportDeclaration: function _upsertImportDeclaration(_ref4, context, fixer) {
|
|
141
|
-
var module = _ref4.module,
|
|
142
|
-
specifiers = _ref4.specifiers;
|
|
143
|
-
// Find any imports that match the packageName
|
|
144
|
-
var root = context.getSourceCode().ast.body;
|
|
145
|
-
var importDeclarations = ast.Root.findImportsByModule(root, module);
|
|
146
|
-
|
|
147
|
-
// The import doesn't exist yet, we can just insert a whole new one
|
|
148
|
-
if (importDeclarations.length === 0) {
|
|
149
|
-
return ast.Root.insertImport(root, {
|
|
150
|
-
module: module,
|
|
151
|
-
specifiers: specifiers
|
|
152
|
-
}, fixer);
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
// The import exists so, modify the existing one
|
|
156
|
-
return ast.Import.insertNamedSpecifiers(importDeclarations[0], specifiers, fixer);
|
|
157
114
|
}
|
|
158
115
|
};
|
|
@@ -1,46 +1,4 @@
|
|
|
1
1
|
export var elements = ['div'];
|
|
2
2
|
export var attributes = ['css'
|
|
3
3
|
// 'data-testid'
|
|
4
|
-
];
|
|
5
|
-
|
|
6
|
-
// TODO: https://product-fabric.atlassian.net/browse/DSP-16054
|
|
7
|
-
var spaceTokenMap = {
|
|
8
|
-
'0px': 'space.0',
|
|
9
|
-
'2px': 'space.025',
|
|
10
|
-
'4px': 'space.050',
|
|
11
|
-
'6px': 'space.075',
|
|
12
|
-
'8px': 'space.100',
|
|
13
|
-
'12px': 'space.150',
|
|
14
|
-
'16px': 'space.200',
|
|
15
|
-
'20px': 'space.250',
|
|
16
|
-
'24px': 'space.300',
|
|
17
|
-
'32px': 'space.400',
|
|
18
|
-
'40px': 'space.500',
|
|
19
|
-
'48px': 'space.600',
|
|
20
|
-
'64px': 'space.800',
|
|
21
|
-
'80px': 'space.1000'
|
|
22
|
-
};
|
|
23
|
-
export var styles = {
|
|
24
|
-
padding: spaceTokenMap,
|
|
25
|
-
paddingBlock: spaceTokenMap,
|
|
26
|
-
paddingBlockEnd: spaceTokenMap,
|
|
27
|
-
paddingBlockStart: spaceTokenMap,
|
|
28
|
-
paddingBottom: spaceTokenMap,
|
|
29
|
-
paddingInline: spaceTokenMap,
|
|
30
|
-
paddingInlineEnd: spaceTokenMap,
|
|
31
|
-
paddingInlineStart: spaceTokenMap,
|
|
32
|
-
paddingLeft: spaceTokenMap,
|
|
33
|
-
paddingRight: spaceTokenMap,
|
|
34
|
-
paddingTop: spaceTokenMap,
|
|
35
|
-
margin: spaceTokenMap,
|
|
36
|
-
marginBlock: spaceTokenMap,
|
|
37
|
-
marginBlockEnd: spaceTokenMap,
|
|
38
|
-
marginBlockStart: spaceTokenMap,
|
|
39
|
-
marginBottom: spaceTokenMap,
|
|
40
|
-
marginInline: spaceTokenMap,
|
|
41
|
-
marginInlineEnd: spaceTokenMap,
|
|
42
|
-
marginInlineStart: spaceTokenMap,
|
|
43
|
-
marginLeft: spaceTokenMap,
|
|
44
|
-
marginRight: spaceTokenMap,
|
|
45
|
-
marginTop: spaceTokenMap
|
|
46
|
-
};
|
|
4
|
+
];
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import * as ast from '../../../../ast-nodes';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Currently this is defined here because it's not very general purpose.
|
|
5
|
+
* If we were to move this to `ast-nodes`, half the implementation would be in `Root`,
|
|
6
|
+
* and the other half would be in `Import`.
|
|
7
|
+
*
|
|
8
|
+
* TODO: Refactor and move to `ast-nodes`
|
|
9
|
+
*
|
|
10
|
+
* Note: It does not handle default imports, namespace imports, or aliased imports.
|
|
11
|
+
*/
|
|
12
|
+
export var upsertImportDeclaration = function upsertImportDeclaration(_ref, context, fixer) {
|
|
13
|
+
var module = _ref.module,
|
|
14
|
+
specifiers = _ref.specifiers;
|
|
15
|
+
// Find any imports that match the packageName
|
|
16
|
+
var root = context.getSourceCode().ast.body;
|
|
17
|
+
var importDeclarations = ast.Root.findImportsByModule(root, module);
|
|
18
|
+
|
|
19
|
+
// The import doesn't exist yet, we can just insert a whole new one
|
|
20
|
+
if (importDeclarations.length === 0) {
|
|
21
|
+
return ast.Root.insertImport(root, {
|
|
22
|
+
module: module,
|
|
23
|
+
specifiers: specifiers
|
|
24
|
+
}, fixer);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// The import exists so, modify the existing one
|
|
28
|
+
return ast.Import.insertNamedSpecifiers(importDeclarations[0], specifiers, fixer);
|
|
29
|
+
};
|
|
@@ -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 {
|
|
13
|
-
export { updateJSXAttributeByName } from './update-jsx-attribute-by-name';
|
|
14
|
-
export { updateJSXElementName } from './update-jsx-element-name';
|
|
15
|
-
export { upsertImportDeclaration } from './upsert-import-declaration';
|
|
9
|
+
export { updateJSXAttributeByName } from './update-jsx-attribute-by-name';
|
package/dist/types/rules/use-primitives/transformers/compiled-styled/convert-jsx-call-site.d.ts
ADDED
|
@@ -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 {};
|
package/dist/types/rules/use-primitives/transformers/compiled-styled/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;
|