@atlaskit/eslint-plugin-design-system 8.23.1 → 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.
Files changed (136) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/cjs/ast-nodes/function-call.js +48 -0
  3. package/dist/cjs/ast-nodes/import.js +49 -0
  4. package/dist/cjs/ast-nodes/index.js +40 -0
  5. package/dist/cjs/ast-nodes/jsx-attribute.js +64 -0
  6. package/dist/cjs/ast-nodes/jsx-element.js +55 -0
  7. package/dist/cjs/ast-nodes/root.js +34 -0
  8. package/dist/cjs/rules/consistent-css-prop-usage/index.js +25 -5
  9. package/dist/cjs/rules/use-primitives/index.js +8 -104
  10. package/dist/cjs/rules/use-primitives/transformers/compiled-styled/convert-jsx-call-site.js +39 -0
  11. package/dist/cjs/rules/use-primitives/transformers/compiled-styled/convert-styled-component-call-to-jsx.js +44 -0
  12. package/dist/cjs/rules/use-primitives/{utils → transformers/compiled-styled}/find-valid-styled-component-call.js +5 -2
  13. package/dist/cjs/rules/use-primitives/transformers/compiled-styled/index.js +117 -0
  14. package/dist/cjs/rules/use-primitives/transformers/compiled-styled/supported.js +10 -0
  15. package/dist/cjs/rules/use-primitives/transformers/compiled-styled/upsert-import-declaration.js +37 -0
  16. package/dist/cjs/rules/use-primitives/transformers/emotion-css/contains-only-supported-attrs.js +27 -0
  17. package/dist/cjs/rules/use-primitives/transformers/emotion-css/index.js +125 -0
  18. package/dist/cjs/rules/use-primitives/transformers/emotion-css/supported.js +10 -0
  19. package/dist/cjs/rules/use-primitives/transformers/emotion-css/upsert-import-declaration.js +37 -0
  20. package/dist/cjs/rules/use-primitives/transformers/index.js +10 -10
  21. package/dist/cjs/rules/use-primitives/utils/index.js +1 -43
  22. package/dist/cjs/rules/use-primitives/utils/is-valid-css-properties-to-transform.js +3 -0
  23. package/dist/es2019/ast-nodes/function-call.js +42 -0
  24. package/dist/es2019/ast-nodes/import.js +42 -0
  25. package/dist/es2019/ast-nodes/index.js +5 -0
  26. package/dist/es2019/ast-nodes/jsx-attribute.js +59 -0
  27. package/dist/es2019/ast-nodes/jsx-element.js +50 -0
  28. package/dist/es2019/ast-nodes/root.js +28 -0
  29. package/dist/es2019/rules/consistent-css-prop-usage/index.js +23 -5
  30. package/dist/es2019/rules/use-primitives/index.js +9 -105
  31. package/dist/es2019/rules/use-primitives/transformers/compiled-styled/convert-jsx-call-site.js +29 -0
  32. package/dist/es2019/rules/use-primitives/transformers/compiled-styled/convert-styled-component-call-to-jsx.js +37 -0
  33. package/dist/es2019/rules/use-primitives/{utils → transformers/compiled-styled}/find-valid-styled-component-call.js +2 -2
  34. package/dist/es2019/rules/use-primitives/transformers/compiled-styled/index.js +107 -0
  35. package/dist/es2019/rules/use-primitives/transformers/compiled-styled/supported.js +4 -0
  36. package/dist/es2019/rules/use-primitives/transformers/compiled-styled/upsert-import-declaration.js +30 -0
  37. package/dist/es2019/rules/use-primitives/transformers/emotion-css/contains-only-supported-attrs.js +19 -0
  38. package/dist/es2019/rules/use-primitives/transformers/emotion-css/index.js +115 -0
  39. package/dist/es2019/rules/use-primitives/transformers/emotion-css/supported.js +4 -0
  40. package/dist/es2019/rules/use-primitives/transformers/emotion-css/upsert-import-declaration.js +30 -0
  41. package/dist/es2019/rules/use-primitives/transformers/index.js +2 -2
  42. package/dist/es2019/rules/use-primitives/utils/index.js +1 -7
  43. package/dist/es2019/rules/use-primitives/utils/is-valid-css-properties-to-transform.js +3 -0
  44. package/dist/esm/ast-nodes/function-call.js +42 -0
  45. package/dist/esm/ast-nodes/import.js +43 -0
  46. package/dist/esm/ast-nodes/index.js +5 -0
  47. package/dist/esm/ast-nodes/jsx-attribute.js +59 -0
  48. package/dist/esm/ast-nodes/jsx-element.js +50 -0
  49. package/dist/esm/ast-nodes/root.js +28 -0
  50. package/dist/esm/rules/consistent-css-prop-usage/index.js +25 -5
  51. package/dist/esm/rules/use-primitives/index.js +9 -105
  52. package/dist/esm/rules/use-primitives/transformers/compiled-styled/convert-jsx-call-site.js +30 -0
  53. package/dist/esm/rules/use-primitives/transformers/compiled-styled/convert-styled-component-call-to-jsx.js +38 -0
  54. package/dist/esm/rules/use-primitives/{utils → transformers/compiled-styled}/find-valid-styled-component-call.js +2 -2
  55. package/dist/esm/rules/use-primitives/transformers/compiled-styled/index.js +107 -0
  56. package/dist/esm/rules/use-primitives/transformers/compiled-styled/supported.js +4 -0
  57. package/dist/esm/rules/use-primitives/transformers/compiled-styled/upsert-import-declaration.js +29 -0
  58. package/dist/esm/rules/use-primitives/transformers/emotion-css/contains-only-supported-attrs.js +19 -0
  59. package/dist/esm/rules/use-primitives/transformers/emotion-css/index.js +115 -0
  60. package/dist/esm/rules/use-primitives/transformers/emotion-css/supported.js +4 -0
  61. package/dist/esm/rules/use-primitives/transformers/emotion-css/upsert-import-declaration.js +29 -0
  62. package/dist/esm/rules/use-primitives/transformers/index.js +2 -2
  63. package/dist/esm/rules/use-primitives/utils/index.js +1 -7
  64. package/dist/esm/rules/use-primitives/utils/is-valid-css-properties-to-transform.js +3 -0
  65. package/dist/types/ast-nodes/function-call.d.ts +21 -0
  66. package/dist/types/ast-nodes/import.d.ts +16 -0
  67. package/dist/types/ast-nodes/index.d.ts +5 -0
  68. package/dist/types/ast-nodes/jsx-attribute.d.ts +26 -0
  69. package/dist/types/ast-nodes/jsx-element.d.ts +21 -0
  70. package/dist/types/ast-nodes/root.d.ts +19 -0
  71. package/dist/types/rules/use-primitives/transformers/compiled-styled/convert-jsx-call-site.d.ts +17 -0
  72. package/dist/types/rules/use-primitives/transformers/compiled-styled/convert-styled-component-call-to-jsx.d.ts +17 -0
  73. package/dist/types/rules/use-primitives/transformers/compiled-styled/index.d.ts +25 -0
  74. package/dist/types/rules/use-primitives/transformers/compiled-styled/supported.d.ts +2 -0
  75. package/dist/types/rules/use-primitives/transformers/compiled-styled/upsert-import-declaration.d.ts +14 -0
  76. package/dist/types/rules/use-primitives/transformers/emotion-css/contains-only-supported-attrs.d.ts +7 -0
  77. package/dist/types/rules/use-primitives/transformers/emotion-css/index.d.ts +16 -0
  78. package/dist/types/rules/use-primitives/transformers/emotion-css/supported.d.ts +2 -0
  79. package/dist/types/rules/use-primitives/transformers/emotion-css/upsert-import-declaration.d.ts +14 -0
  80. package/dist/types/rules/use-primitives/transformers/index.d.ts +2 -2
  81. package/dist/types/rules/use-primitives/utils/index.d.ts +0 -6
  82. package/dist/types-ts4.5/ast-nodes/function-call.d.ts +21 -0
  83. package/dist/types-ts4.5/ast-nodes/import.d.ts +16 -0
  84. package/dist/types-ts4.5/ast-nodes/index.d.ts +5 -0
  85. package/dist/types-ts4.5/ast-nodes/jsx-attribute.d.ts +26 -0
  86. package/dist/types-ts4.5/ast-nodes/jsx-element.d.ts +21 -0
  87. package/dist/types-ts4.5/ast-nodes/root.d.ts +19 -0
  88. package/dist/types-ts4.5/rules/use-primitives/transformers/compiled-styled/convert-jsx-call-site.d.ts +17 -0
  89. package/dist/types-ts4.5/rules/use-primitives/transformers/compiled-styled/convert-styled-component-call-to-jsx.d.ts +17 -0
  90. package/dist/types-ts4.5/rules/use-primitives/transformers/compiled-styled/index.d.ts +25 -0
  91. package/dist/types-ts4.5/rules/use-primitives/transformers/compiled-styled/supported.d.ts +2 -0
  92. package/dist/types-ts4.5/rules/use-primitives/transformers/compiled-styled/upsert-import-declaration.d.ts +14 -0
  93. package/dist/types-ts4.5/rules/use-primitives/transformers/emotion-css/contains-only-supported-attrs.d.ts +7 -0
  94. package/dist/types-ts4.5/rules/use-primitives/transformers/emotion-css/index.d.ts +16 -0
  95. package/dist/types-ts4.5/rules/use-primitives/transformers/emotion-css/supported.d.ts +2 -0
  96. package/dist/types-ts4.5/rules/use-primitives/transformers/emotion-css/upsert-import-declaration.d.ts +14 -0
  97. package/dist/types-ts4.5/rules/use-primitives/transformers/index.d.ts +2 -2
  98. package/dist/types-ts4.5/rules/use-primitives/utils/index.d.ts +0 -6
  99. package/package.json +1 -1
  100. package/dist/cjs/rules/use-primitives/transformers/jsx-element-to-box.js +0 -26
  101. package/dist/cjs/rules/use-primitives/transformers/styled-component-to-primitive.js +0 -68
  102. package/dist/cjs/rules/use-primitives/utils/contains-only-supported-attrs.js +0 -19
  103. package/dist/cjs/rules/use-primitives/utils/is-valid-tag-name.js +0 -13
  104. package/dist/cjs/rules/use-primitives/utils/update-jsx-element-name.js +0 -16
  105. package/dist/cjs/rules/use-primitives/utils/upsert-import-declaration.js +0 -80
  106. package/dist/es2019/rules/use-primitives/transformers/jsx-element-to-box.js +0 -16
  107. package/dist/es2019/rules/use-primitives/transformers/styled-component-to-primitive.js +0 -59
  108. package/dist/es2019/rules/use-primitives/utils/contains-only-supported-attrs.js +0 -13
  109. package/dist/es2019/rules/use-primitives/utils/is-valid-tag-name.js +0 -7
  110. package/dist/es2019/rules/use-primitives/utils/update-jsx-element-name.js +0 -12
  111. package/dist/es2019/rules/use-primitives/utils/upsert-import-declaration.js +0 -76
  112. package/dist/esm/rules/use-primitives/transformers/jsx-element-to-box.js +0 -19
  113. package/dist/esm/rules/use-primitives/transformers/styled-component-to-primitive.js +0 -61
  114. package/dist/esm/rules/use-primitives/utils/contains-only-supported-attrs.js +0 -13
  115. package/dist/esm/rules/use-primitives/utils/is-valid-tag-name.js +0 -7
  116. package/dist/esm/rules/use-primitives/utils/update-jsx-element-name.js +0 -10
  117. package/dist/esm/rules/use-primitives/utils/upsert-import-declaration.js +0 -75
  118. package/dist/types/rules/use-primitives/transformers/jsx-element-to-box.d.ts +0 -3
  119. package/dist/types/rules/use-primitives/transformers/styled-component-to-primitive.d.ts +0 -13
  120. package/dist/types/rules/use-primitives/utils/contains-only-supported-attrs.d.ts +0 -2
  121. package/dist/types/rules/use-primitives/utils/is-valid-tag-name.d.ts +0 -3
  122. package/dist/types/rules/use-primitives/utils/update-jsx-element-name.d.ts +0 -3
  123. package/dist/types/rules/use-primitives/utils/upsert-import-declaration.d.ts +0 -11
  124. package/dist/types-ts4.5/rules/use-primitives/transformers/jsx-element-to-box.d.ts +0 -3
  125. package/dist/types-ts4.5/rules/use-primitives/transformers/styled-component-to-primitive.d.ts +0 -13
  126. package/dist/types-ts4.5/rules/use-primitives/utils/contains-only-supported-attrs.d.ts +0 -2
  127. package/dist/types-ts4.5/rules/use-primitives/utils/is-valid-tag-name.d.ts +0 -3
  128. package/dist/types-ts4.5/rules/use-primitives/utils/update-jsx-element-name.d.ts +0 -3
  129. package/dist/types-ts4.5/rules/use-primitives/utils/upsert-import-declaration.d.ts +0 -11
  130. /package/dist/cjs/rules/use-primitives/{utils → transformers/compiled-styled}/find-valid-jsx-usage-to-transform.js +0 -0
  131. /package/dist/es2019/rules/use-primitives/{utils → transformers/compiled-styled}/find-valid-jsx-usage-to-transform.js +0 -0
  132. /package/dist/esm/rules/use-primitives/{utils → transformers/compiled-styled}/find-valid-jsx-usage-to-transform.js +0 -0
  133. /package/dist/types/rules/use-primitives/{utils → transformers/compiled-styled}/find-valid-jsx-usage-to-transform.d.ts +0 -0
  134. /package/dist/types/rules/use-primitives/{utils → transformers/compiled-styled}/find-valid-styled-component-call.d.ts +0 -0
  135. /package/dist/types-ts4.5/rules/use-primitives/{utils → transformers/compiled-styled}/find-valid-jsx-usage-to-transform.d.ts +0 -0
  136. /package/dist/types-ts4.5/rules/use-primitives/{utils → transformers/compiled-styled}/find-valid-styled-component-call.d.ts +0 -0
@@ -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,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,7 +0,0 @@
1
- export var validPrimitiveElements = new Set(['div']);
2
- export var isValidTagName = function isValidTagName(node) {
3
- if (node.openingElement.name.type !== 'JSXIdentifier') {
4
- return false;
5
- }
6
- return validPrimitiveElements.has(node.openingElement.name.name);
7
- };
@@ -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,3 +0,0 @@
1
- import type { Rule } from 'eslint';
2
- import { JSXElement } from 'eslint-codemod-utils';
3
- export declare const jsxElementToBoxTransformer: (node: JSXElement, context: Rule.RuleContext) => (fixer: Rule.RuleFixer) => Rule.Fix[];
@@ -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,2 +0,0 @@
1
- import { type JSXElement } from 'eslint-codemod-utils';
2
- export declare const containsOnlySupportedAttrs: (node: JSXElement) => boolean;
@@ -1,3 +0,0 @@
1
- import { JSXElement } from 'eslint-codemod-utils';
2
- export declare const validPrimitiveElements: Set<string>;
3
- export declare const isValidTagName: (node: JSXElement) => boolean;
@@ -1,3 +0,0 @@
1
- import type { Rule } from 'eslint';
2
- import { JSXElement } from 'eslint-codemod-utils';
3
- export declare const updateJSXElementName: (node: JSXElement, newName: string, fixer: Rule.RuleFixer) => (Rule.Fix | undefined)[];
@@ -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,3 +0,0 @@
1
- import type { Rule } from 'eslint';
2
- import { JSXElement } from 'eslint-codemod-utils';
3
- export declare const jsxElementToBoxTransformer: (node: JSXElement, context: Rule.RuleContext) => (fixer: Rule.RuleFixer) => Rule.Fix[];
@@ -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,2 +0,0 @@
1
- import { type JSXElement } from 'eslint-codemod-utils';
2
- export declare const containsOnlySupportedAttrs: (node: JSXElement) => boolean;
@@ -1,3 +0,0 @@
1
- import { JSXElement } from 'eslint-codemod-utils';
2
- export declare const validPrimitiveElements: Set<string>;
3
- export declare const isValidTagName: (node: JSXElement) => boolean;
@@ -1,3 +0,0 @@
1
- import type { Rule } from 'eslint';
2
- import { JSXElement } from 'eslint-codemod-utils';
3
- export declare const updateJSXElementName: (node: JSXElement, newName: string, fixer: Rule.RuleFixer) => (Rule.Fix | undefined)[];
@@ -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;