@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
@@ -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
+ };
@@ -0,0 +1,4 @@
1
+ export var elements = ['div'];
2
+ export var attributes = ['css'
3
+ // 'data-testid'
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
+ };
@@ -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
+ };
@@ -0,0 +1,115 @@
1
+ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
+ /* eslint-disable @repo/internal/react/require-jsdoc */
3
+
4
+ import { getIdentifierInParentScope, isNodeOfType } from 'eslint-codemod-utils';
5
+ import * as ast from '../../../../ast-nodes';
6
+ import { getVariableDefinitionValue, getVariableUsagesCount, isValidCssPropertiesToTransform } from '../../utils';
7
+ import { cssToXcssTransformer } from '../css-to-xcss';
8
+ import { containsOnlySupportedAttrs } from './contains-only-supported-attrs';
9
+ import * as supported from './supported';
10
+ import { upsertImportDeclaration } from './upsert-import-declaration';
11
+ export var EmotionCSS = {
12
+ lint: function lint(node, _ref) {
13
+ var context = _ref.context,
14
+ config = _ref.config;
15
+ if (!isNodeOfType(node, 'JSXElement')) {
16
+ return;
17
+ }
18
+
19
+ // Check whether all criteria needed to make a transformation are met
20
+ if (!EmotionCSS._check(node, {
21
+ context: context,
22
+ config: config
23
+ })) {
24
+ return;
25
+ }
26
+ context.report({
27
+ node: node.openingElement,
28
+ messageId: 'preferPrimitivesBox',
29
+ suggest: [{
30
+ desc: "Convert to Box",
31
+ fix: EmotionCSS._fix(node, {
32
+ context: context
33
+ })
34
+ }]
35
+ });
36
+ },
37
+ _check: function _check(node, _ref2) {
38
+ var _cssVariableValue$nod, _cssVariableValue$nod2;
39
+ var context = _ref2.context,
40
+ config = _ref2.config;
41
+ if (!config.patterns.includes('compiled-css-function')) {
42
+ return false;
43
+ }
44
+ if (!isNodeOfType(node, 'JSXElement')) {
45
+ return false;
46
+ }
47
+ var elementName = ast.JSXElement.getName(node);
48
+ if (!elementName) {
49
+ return false;
50
+ }
51
+
52
+ // Currently we only support `div`. This may change in future.
53
+ if (!supported.elements.includes(elementName)) {
54
+ return false;
55
+ }
56
+
57
+ // Ignore elements that contain dangerous attributes like `id`.
58
+ if (!containsOnlySupportedAttrs(node)) {
59
+ return false;
60
+ }
61
+
62
+ // Currently we don't transform anything to `Box` unless it defines styles
63
+ var cssAttr = ast.JSXElement.getAttributeByName(node, 'css');
64
+ if (!cssAttr) {
65
+ return false;
66
+ }
67
+
68
+ // Get `myStyles` in `css={myStyles}` as a string so we can search for the `const myStyles` VariableDefinition
69
+ var cssAttrValue = ast.JSXAttribute.getValue(cssAttr);
70
+ if ((cssAttrValue === null || cssAttrValue === void 0 ? void 0 : cssAttrValue.type) !== 'ExpressionStatement') {
71
+ return false;
72
+ }
73
+
74
+ // TODO: Everything below this line could be refactored to use `ast-nodes`.
75
+
76
+ // Bail if the styles are used on multiple JSXElements
77
+ if (getVariableUsagesCount(cssAttrValue.value, context) !== 1) {
78
+ return false;
79
+ }
80
+
81
+ // Find where `myStyles` is defined. We're looking for `const myStyles = css({...})`
82
+ var cssVariableDefinition = getIdentifierInParentScope(context.getScope(), cssAttrValue.value);
83
+ var cssVariableValue = getVariableDefinitionValue(cssVariableDefinition);
84
+ // Check if `cssVariableValue` is a function called `css()`
85
+ if (ast.FunctionCall.getName(cssVariableValue === null || cssVariableValue === void 0 || (_cssVariableValue$nod = cssVariableValue.node) === null || _cssVariableValue$nod === void 0 ? void 0 : _cssVariableValue$nod.init) !== 'css') {
86
+ return false;
87
+ }
88
+ if (!isValidCssPropertiesToTransform(cssVariableValue === null || cssVariableValue === void 0 || (_cssVariableValue$nod2 = cssVariableValue.node) === null || _cssVariableValue$nod2 === void 0 ? void 0 : _cssVariableValue$nod2.init, config)) {
89
+ return false;
90
+ }
91
+ var importDeclaration = ast.Root.findImportsByModule(context.getSourceCode().ast.body, '@atlaskit/primitives');
92
+
93
+ // If there is more than one `@atlaskit/primitives` import, then it becomes difficult to determine which import to transform
94
+ if (importDeclaration.length > 1) {
95
+ return false;
96
+ }
97
+ return true;
98
+ },
99
+ _fix: function _fix(node, _ref3) {
100
+ var context = _ref3.context;
101
+ return function (fixer) {
102
+ var importFix = upsertImportDeclaration({
103
+ module: '@atlaskit/primitives',
104
+ specifiers: ['Box', 'xcss']
105
+ }, context, fixer);
106
+ var cssAttr = ast.JSXElement.getAttributeByName(node, 'css'); // Can strongly assert the type here, because we validated it exists in `check()`.
107
+ var attributeFix = ast.JSXAttribute.updateName(cssAttr, 'xcss', fixer);
108
+ var elementNameFixes = ast.JSXElement.updateName(node, 'Box', fixer);
109
+ var cssToXcssTransform = cssToXcssTransformer(node, context, fixer);
110
+ return [importFix, attributeFix].concat(_toConsumableArray(elementNameFixes), _toConsumableArray(cssToXcssTransform)).filter(function (fix) {
111
+ return Boolean(fix);
112
+ }); // Some of the transformers can return arrays with undefined, so filter them out
113
+ };
114
+ }
115
+ };
@@ -0,0 +1,4 @@
1
+ export var elements = ['div'];
2
+ export var attributes = ['css'
3
+ // 'data-testid'
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 { jsxElementToBoxTransformer } from './jsx-element-to-box';
3
- export { styledComponentToPrimitive } from './styled-component-to-primitive';
2
+ export { CompiledStyled } from './compiled-styled';
3
+ export { EmotionCSS } from './emotion-css';
@@ -1,7 +1,4 @@
1
- export { containsOnlySupportedAttrs } from './contains-only-supported-attrs';
2
1
  export { convertASTObjectExpressionToJSObject } from './convert-ast-object-expression-to-js-object';
3
- export { findValidJsxUsageToTransform } from './find-valid-jsx-usage-to-transform';
4
- export { findValidStyledComponentCall } from './find-valid-styled-component-call';
5
2
  export { getAttributeValueIdentifier } from './get-attribute-value-identifier';
6
3
  export { getFunctionArgumentAtPos } from './get-function-argument-at-pos';
7
4
  export { getJSXAttributeByName } from './get-jsx-attribute-by-name';
@@ -9,7 +6,4 @@ export { getVariableDefinitionValue } from './get-variable-definition-value';
9
6
  export { getVariableUsagesCount } from './get-variable-usage-count';
10
7
  export { isFunctionNamed } from './is-function-named';
11
8
  export { isValidCssPropertiesToTransform } from './is-valid-css-properties-to-transform';
12
- export { isValidTagName } from './is-valid-tag-name';
13
- 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';
@@ -5,6 +5,9 @@ import { isNodeOfType } from 'eslint-codemod-utils';
5
5
  import { supportedStylesMap } from '../transformers/css-to-xcss';
6
6
  import { convertASTObjectExpressionToJSObject } from './convert-ast-object-expression-to-js-object';
7
7
  export var isValidCssPropertiesToTransform = function isValidCssPropertiesToTransform(node, config) {
8
+ if (!node) {
9
+ return false;
10
+ }
8
11
  var cssObjectExpression = node.arguments[0];
9
12
  // Bail on empty object calls
10
13
  if (!cssObjectExpression || !isNodeOfType(cssObjectExpression, 'ObjectExpression')) {
@@ -0,0 +1,21 @@
1
+ import type { Rule } from 'eslint';
2
+ import { CallExpression, ObjectExpression } from 'eslint-codemod-utils';
3
+ export declare const FunctionCall: {
4
+ getName(node: CallExpression): string | undefined;
5
+ updateName(node: CallExpression, newName: string, fixer: Rule.RuleFixer): Rule.Fix;
6
+ /**
7
+ * Function arguments can be many things:
8
+ * `css(myStyles, () => {}, undefined, 'literal', ...rest) // etc`
9
+ * They all need slightly different treatment.
10
+ *
11
+ * Currently 'getArgumentAtPos' only implements strategies for Literals and ObjectExpressions.
12
+ * If you need to support another type of arg, add it, and update the type.
13
+ */
14
+ getArgumentAtPos(node: CallExpression, pos: number): {
15
+ type: 'Literal';
16
+ value: string;
17
+ } | {
18
+ type: 'ObjectExpression';
19
+ value: ObjectExpression;
20
+ } | undefined;
21
+ };
@@ -0,0 +1,16 @@
1
+ import type { Rule } from 'eslint';
2
+ import { type ImportDeclaration } from 'eslint-codemod-utils';
3
+ export declare const Import: {
4
+ /**
5
+ * Note: fixes can't overlap, which means this will fail:
6
+ * ```
7
+ * const importNode = Root.findImportByModule('@atlaskit/primitives')
8
+ * Import.insertNamedSpecifier(importNode, 'Box')
9
+ * Import.insertNamedSpecifier(importNode, 'xcss')
10
+ * ```
11
+ *
12
+ * For this reason `insertNamedSpecifiers` accepts a `specifiers` array, so you can group all inserts together.
13
+ */
14
+ insertNamedSpecifiers(node: ImportDeclaration, specifiers: string[], fixer: Rule.RuleFixer): Rule.Fix | undefined;
15
+ containsNamedSpecifier(node: ImportDeclaration, name: string): boolean;
16
+ };
@@ -0,0 +1,5 @@
1
+ export { FunctionCall } from './function-call';
2
+ export { Import } from './import';
3
+ export { JSXAttribute } from './jsx-attribute';
4
+ export { JSXElement } from './jsx-element';
5
+ export { Root } from './root';
@@ -0,0 +1,26 @@
1
+ import type { Rule } from 'eslint';
2
+ import { JSXAttribute } from 'eslint-codemod-utils';
3
+ declare const HelperJSXAttribute: {
4
+ getName(node: JSXAttribute): string;
5
+ updateName(node: JSXAttribute, name: string, fixer: Rule.RuleFixer): Rule.Fix;
6
+ /**
7
+ * A JSXAttribute value can be many things:
8
+ * - css='myStyles'
9
+ * - css={myStyles}
10
+ * - css={[styles1, styles2]}
11
+ * - header={<></>}
12
+ * - css={styleMap.header}
13
+ * - css={...styles}
14
+ *
15
+ * Currently, `getValue` has only implemented strategies for when the value is a string, or an ExpressionStatement
16
+ * If you need additional functionality add it, and set the correct `type` on the returned object
17
+ */
18
+ getValue(node: JSXAttribute): {
19
+ type: 'ExpressionStatement';
20
+ value: string;
21
+ } | {
22
+ type: 'Literal';
23
+ value: string;
24
+ } | undefined;
25
+ };
26
+ export { HelperJSXAttribute as JSXAttribute };
@@ -0,0 +1,21 @@
1
+ import type { Rule } from 'eslint';
2
+ import { JSXAttribute, JSXElement, JSXSpreadAttribute } from 'eslint-codemod-utils';
3
+ export declare const JSXElementHelper: {
4
+ /**
5
+ * Names of JSXElements can be any of:
6
+ * `<Component></Component>` - (JSXIdentifier)
7
+ * `<MyComponents.Component></MyComponents.Component>` - `MyComponents` is a namespace (JSXNamespacedName)
8
+ * `<MyComponents.Component></MyComponents.Component>` - `MyComponents` is an object (JSXMemberExpression)
9
+ *
10
+ * Getting the name of a JSXMemberExpression is difficult, because object can contain objects, which is recursively defined in the AST.
11
+ * e.g. getting the name of `<MyComponents.PresentationLayer.LeftSideBar.Header />` would require `getName` to recursively resolve all parts of the name.
12
+ * `getName` does not currently have this functionality. Add it if you need it.
13
+ */
14
+ getName(node: JSXElement): string;
15
+ updateName(node: JSXElement, newName: string, fixer: Rule.RuleFixer): Rule.Fix[];
16
+ isSelfClosing(node: JSXElement): boolean;
17
+ getAttributes(node: JSXElement): (JSXAttribute | JSXSpreadAttribute)[];
18
+ getAttributeByName(node: JSXElement, name: string): JSXAttribute | undefined;
19
+ containsSpreadAttributes(node: JSXElement): boolean;
20
+ };
21
+ export { JSXElementHelper as JSXElement };
@@ -0,0 +1,19 @@
1
+ /// <reference types="node" />
2
+ import type { Rule } from 'eslint';
3
+ import { Directive, ImportDeclaration, insertImportDeclaration, ModuleDeclaration, Statement } from 'eslint-codemod-utils';
4
+ type ImportData = Parameters<typeof insertImportDeclaration>[1];
5
+ export declare const Root: {
6
+ /**
7
+ * Note: This can return multiple ImportDeclarations for cases like:
8
+ * ```
9
+ * import { Stack } from '@atlaskit/primitives'
10
+ * import type { StackProps } from '@atlaskit/primitives'
11
+ * ```
12
+ */
13
+ findImportsByModule(root: (Directive | Statement | ModuleDeclaration)[], name: string): ImportDeclaration[];
14
+ insertImport(root: (Directive | Statement | ModuleDeclaration)[], data: {
15
+ module: string;
16
+ specifiers: ImportData;
17
+ }, fixer: Rule.RuleFixer): Rule.Fix;
18
+ };
19
+ export {};
@@ -0,0 +1,17 @@
1
+ import type { Rule } from 'eslint';
2
+ import { JSXElement } from 'eslint-codemod-utils';
3
+ /**
4
+ * Transforms a JSXElement from:
5
+ * ```
6
+ * <div>
7
+ * // ...
8
+ * </div>
9
+ * ```
10
+ * to
11
+ * ```
12
+ * <Box xcss={myStyles}>
13
+ * // ...
14
+ * </Box>
15
+ * ```
16
+ */
17
+ export declare const convertJsxCallSite: (jsxElement: JSXElement, newStylesVariableName: string, fixer: Rule.RuleFixer) => Rule.Fix[];
@@ -0,0 +1,17 @@
1
+ import type { Rule } from 'eslint';
2
+ import { VariableDeclarator } from 'eslint-codemod-utils';
3
+ /**
4
+ * Transforms a variable like:
5
+ * ```
6
+ * const MyComponent = styled.div({
7
+ * padding: '8px',
8
+ * })
9
+ * ```
10
+ * to
11
+ * ```
12
+ * const myComponentStyles = xcss({
13
+ * padding: 'space.100',
14
+ * })
15
+ * ```
16
+ */
17
+ export declare const convertStyledComponentToXcss: (styles: VariableDeclarator, newStylesVariableName: string, fixer: Rule.RuleFixer) => (Rule.Fix | undefined)[];
@@ -0,0 +1,25 @@
1
+ import type { Rule } from 'eslint';
2
+ import { JSXElement, VariableDeclarator } from 'eslint-codemod-utils';
3
+ import { RuleConfig } from '../../config';
4
+ interface MetaData {
5
+ context: Rule.RuleContext;
6
+ config: RuleConfig;
7
+ }
8
+ interface Refs {
9
+ styles: VariableDeclarator;
10
+ jsxElement: JSXElement;
11
+ }
12
+ type Check = {
13
+ success: boolean;
14
+ refs?: Refs;
15
+ };
16
+ export declare const CompiledStyled: {
17
+ lint(node: Rule.Node, { context, config }: MetaData): void;
18
+ _check(node: Rule.Node, { context, config }: MetaData): Check;
19
+ /**
20
+ * All required validation steps have been taken care of before this
21
+ * transformer is called, so it just goes ahead providing all necessary fixes
22
+ */
23
+ _fix(refs: Refs, context: Rule.RuleContext): (fixer: Rule.RuleFixer) => Rule.Fix[];
24
+ };
25
+ export {};
@@ -0,0 +1,2 @@
1
+ export declare const elements: string[];
2
+ export declare const attributes: string[];
@@ -0,0 +1,14 @@
1
+ import type { Rule } from 'eslint';
2
+ /**
3
+ * Currently this is defined here because it's not very general purpose.
4
+ * If we were to move this to `ast-nodes`, half the implementation would be in `Root`,
5
+ * and the other half would be in `Import`.
6
+ *
7
+ * TODO: Refactor and move to `ast-nodes`
8
+ *
9
+ * Note: It does not handle default imports, namespace imports, or aliased imports.
10
+ */
11
+ export declare const upsertImportDeclaration: ({ module, specifiers, }: {
12
+ module: string;
13
+ specifiers: string[];
14
+ }, context: Rule.RuleContext, fixer: Rule.RuleFixer) => Rule.Fix | undefined;
@@ -0,0 +1,7 @@
1
+ import { JSXElement } from 'eslint-codemod-utils';
2
+ /**
3
+ * Check that every attribute in the JSXElement is something we support.
4
+ * We do this via a whitelist in `this.attributes`. The result is we exclude
5
+ * dangerous attrs like `id` and `style`.
6
+ */
7
+ export declare const containsOnlySupportedAttrs: (node: JSXElement) => boolean;
@@ -0,0 +1,16 @@
1
+ import type { Rule } from 'eslint';
2
+ import { JSXElement } from 'eslint-codemod-utils';
3
+ import { RuleConfig } from '../../config';
4
+ interface MetaData {
5
+ context: Rule.RuleContext;
6
+ config: RuleConfig;
7
+ }
8
+ type FixFunction = (fixer: Rule.RuleFixer) => Rule.Fix[];
9
+ export declare const EmotionCSS: {
10
+ lint(node: Rule.Node, { context, config }: MetaData): void;
11
+ _check(node: Rule.Node, { context, config }: MetaData): boolean;
12
+ _fix(node: JSXElement, { context }: {
13
+ context: Rule.RuleContext;
14
+ }): FixFunction;
15
+ };
16
+ export {};
@@ -0,0 +1,2 @@
1
+ export declare const elements: string[];
2
+ export declare const attributes: string[];
@@ -0,0 +1,14 @@
1
+ import type { Rule } from 'eslint';
2
+ /**
3
+ * Currently this is defined here because it's not very general purpose.
4
+ * If we were to move this to `ast-nodes`, half the implementation would be in `Root`,
5
+ * and the other half would be in `Import`.
6
+ *
7
+ * TODO: Refactor and move to `ast-nodes`
8
+ *
9
+ * Note: It does not handle default imports, namespace imports, or aliased imports.
10
+ */
11
+ export declare const upsertImportDeclaration: ({ module, specifiers, }: {
12
+ module: string;
13
+ specifiers: string[];
14
+ }, context: Rule.RuleContext, fixer: Rule.RuleFixer) => Rule.Fix | undefined;
@@ -1,3 +1,3 @@
1
1
  export { cssToXcssTransformer, supportedStylesMap, spaceTokenMap, } from './css-to-xcss';
2
- export { jsxElementToBoxTransformer } from './jsx-element-to-box';
3
- export { styledComponentToPrimitive } from './styled-component-to-primitive';
2
+ export { CompiledStyled } from './compiled-styled';
3
+ export { EmotionCSS } from './emotion-css';
@@ -1,7 +1,4 @@
1
- export { containsOnlySupportedAttrs } from './contains-only-supported-attrs';
2
1
  export { convertASTObjectExpressionToJSObject } from './convert-ast-object-expression-to-js-object';
3
- export { findValidJsxUsageToTransform } from './find-valid-jsx-usage-to-transform';
4
- export { findValidStyledComponentCall } from './find-valid-styled-component-call';
5
2
  export { getAttributeValueIdentifier } from './get-attribute-value-identifier';
6
3
  export { getFunctionArgumentAtPos } from './get-function-argument-at-pos';
7
4
  export { getJSXAttributeByName } from './get-jsx-attribute-by-name';
@@ -9,7 +6,4 @@ export { getVariableDefinitionValue } from './get-variable-definition-value';
9
6
  export { getVariableUsagesCount } from './get-variable-usage-count';
10
7
  export { isFunctionNamed } from './is-function-named';
11
8
  export { isValidCssPropertiesToTransform } from './is-valid-css-properties-to-transform';
12
- export { isValidTagName } from './is-valid-tag-name';
13
9
  export { updateJSXAttributeByName } from './update-jsx-attribute-by-name';
14
- export { updateJSXElementName } from './update-jsx-element-name';
15
- export { upsertImportDeclaration } from './upsert-import-declaration';
@@ -0,0 +1,21 @@
1
+ import type { Rule } from 'eslint';
2
+ import { CallExpression, ObjectExpression } from 'eslint-codemod-utils';
3
+ export declare const FunctionCall: {
4
+ getName(node: CallExpression): string | undefined;
5
+ updateName(node: CallExpression, newName: string, fixer: Rule.RuleFixer): Rule.Fix;
6
+ /**
7
+ * Function arguments can be many things:
8
+ * `css(myStyles, () => {}, undefined, 'literal', ...rest) // etc`
9
+ * They all need slightly different treatment.
10
+ *
11
+ * Currently 'getArgumentAtPos' only implements strategies for Literals and ObjectExpressions.
12
+ * If you need to support another type of arg, add it, and update the type.
13
+ */
14
+ getArgumentAtPos(node: CallExpression, pos: number): {
15
+ type: 'Literal';
16
+ value: string;
17
+ } | {
18
+ type: 'ObjectExpression';
19
+ value: ObjectExpression;
20
+ } | undefined;
21
+ };