@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
package/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # @atlaskit/eslint-plugin-design-system
2
2
 
3
+ ## 8.23.3
4
+
5
+ ### Patch Changes
6
+
7
+ - [#69222](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/69222) [`a1c52086fdb9`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/a1c52086fdb9) - Address issues in consistent-css-prop-usage hoisting and naming fixers
8
+ - Updated dependencies
9
+
10
+ ## 8.23.2
11
+
12
+ ### Patch Changes
13
+
14
+ - [#65758](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/65758) [`16e6a0fbe125`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/16e6a0fbe125) - Internal refactor of `use-primitves` rule. There should be no change to consumers of the rule.
15
+
3
16
  ## 8.23.1
4
17
 
5
18
  ### Patch Changes
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.FunctionCall = void 0;
7
+ var _eslintCodemodUtils = require("eslint-codemod-utils");
8
+ /* eslint-disable @repo/internal/react/require-jsdoc */
9
+
10
+ var FunctionCall = exports.FunctionCall = {
11
+ getName: function getName(node) {
12
+ if (!(0, _eslintCodemodUtils.isNodeOfType)(node, 'CallExpression')) {
13
+ return undefined;
14
+ }
15
+ if (!(0, _eslintCodemodUtils.isNodeOfType)(node.callee, 'Identifier')) {
16
+ return undefined;
17
+ }
18
+ return node.callee.name;
19
+ },
20
+ updateName: function updateName(node, newName, fixer) {
21
+ return fixer.replaceText(node.callee, newName);
22
+ },
23
+ /**
24
+ * Function arguments can be many things:
25
+ * `css(myStyles, () => {}, undefined, 'literal', ...rest) // etc`
26
+ * They all need slightly different treatment.
27
+ *
28
+ * Currently 'getArgumentAtPos' only implements strategies for Literals and ObjectExpressions.
29
+ * If you need to support another type of arg, add it, and update the type.
30
+ */
31
+ getArgumentAtPos: function getArgumentAtPos(node, pos) {
32
+ var argument = node.arguments[pos];
33
+ if ((0, _eslintCodemodUtils.isNodeOfType)(argument, 'Literal') && argument.value) {
34
+ var _argument$value;
35
+ return {
36
+ type: 'Literal',
37
+ value: (_argument$value = argument.value) === null || _argument$value === void 0 ? void 0 : _argument$value.toString()
38
+ };
39
+ }
40
+ if ((0, _eslintCodemodUtils.isNodeOfType)(argument, 'ObjectExpression')) {
41
+ argument;
42
+ return {
43
+ type: 'ObjectExpression',
44
+ value: argument
45
+ };
46
+ }
47
+ }
48
+ };
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.Import = void 0;
7
+ var _eslintCodemodUtils = require("eslint-codemod-utils");
8
+ /* eslint-disable @repo/internal/react/require-jsdoc */
9
+
10
+ var Import = exports.Import = {
11
+ /**
12
+ * Note: fixes can't overlap, which means this will fail:
13
+ * ```
14
+ * const importNode = Root.findImportByModule('@atlaskit/primitives')
15
+ * Import.insertNamedSpecifier(importNode, 'Box')
16
+ * Import.insertNamedSpecifier(importNode, 'xcss')
17
+ * ```
18
+ *
19
+ * For this reason `insertNamedSpecifiers` accepts a `specifiers` array, so you can group all inserts together.
20
+ */
21
+ insertNamedSpecifiers: function insertNamedSpecifiers(node, specifiers, fixer) {
22
+ var _this = this;
23
+ /**
24
+ * `insertImportSpecifier()` has the unfortunate implementation detail of naively adding duplicate specifiers.
25
+ * e.g. calling
26
+ * `insertImportSpecifier(importDecl, 'xcss')`
27
+ * on
28
+ * `import { Inline, xcss } from '@atlaskit/primitives'`
29
+ * will result in:
30
+ * `import { Inline, xcss, xcss } from '@atlaskit/primitives'`.
31
+ * So, we need to filter out specifiers that are already imported.
32
+ */
33
+ var uniqueSpecifiers = specifiers.filter(function (specifier) {
34
+ return !_this.containsNamedSpecifier(node, specifier);
35
+ });
36
+ if (uniqueSpecifiers.length === 0) {
37
+ return;
38
+ }
39
+ return fixer.replaceText(node, "".concat((0, _eslintCodemodUtils.insertImportSpecifier)(node, uniqueSpecifiers.join(', ')), ";\n"));
40
+ },
41
+ containsNamedSpecifier: function containsNamedSpecifier(node, name) {
42
+ return node.specifiers.some(function (specifier) {
43
+ if (!(0, _eslintCodemodUtils.isNodeOfType)(specifier, 'ImportSpecifier')) {
44
+ return false;
45
+ }
46
+ return specifier.imported.name === name;
47
+ });
48
+ }
49
+ };
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "FunctionCall", {
7
+ enumerable: true,
8
+ get: function get() {
9
+ return _functionCall.FunctionCall;
10
+ }
11
+ });
12
+ Object.defineProperty(exports, "Import", {
13
+ enumerable: true,
14
+ get: function get() {
15
+ return _import.Import;
16
+ }
17
+ });
18
+ Object.defineProperty(exports, "JSXAttribute", {
19
+ enumerable: true,
20
+ get: function get() {
21
+ return _jsxAttribute.JSXAttribute;
22
+ }
23
+ });
24
+ Object.defineProperty(exports, "JSXElement", {
25
+ enumerable: true,
26
+ get: function get() {
27
+ return _jsxElement.JSXElement;
28
+ }
29
+ });
30
+ Object.defineProperty(exports, "Root", {
31
+ enumerable: true,
32
+ get: function get() {
33
+ return _root.Root;
34
+ }
35
+ });
36
+ var _functionCall = require("./function-call");
37
+ var _import = require("./import");
38
+ var _jsxAttribute = require("./jsx-attribute");
39
+ var _jsxElement = require("./jsx-element");
40
+ var _root = require("./root");
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.JSXAttribute = void 0;
7
+ var _eslintCodemodUtils = require("eslint-codemod-utils");
8
+ var HelperJSXAttribute = exports.JSXAttribute = {
9
+ getName: function getName(node) {
10
+ if (!(0, _eslintCodemodUtils.isNodeOfType)(node, 'JSXAttribute')) {
11
+ throw new Error('Not a JSXAttribute');
12
+ }
13
+ if (!(0, _eslintCodemodUtils.isNodeOfType)(node.name, 'JSXIdentifier')) {
14
+ throw new Error('name is not a JSXIdentifier');
15
+ }
16
+ return node.name.name;
17
+ },
18
+ updateName: function updateName(node, name, fixer) {
19
+ if (!(0, _eslintCodemodUtils.isNodeOfType)(node, 'JSXAttribute')) {
20
+ throw new Error('Not a JSXAttribute');
21
+ }
22
+ if (!(0, _eslintCodemodUtils.isNodeOfType)(node.name, 'JSXIdentifier')) {
23
+ throw new Error('name is not a JSXIdentifier');
24
+ }
25
+ return fixer.replaceText(node.name, (0, _eslintCodemodUtils.literal)(name).toString());
26
+ },
27
+ /**
28
+ * A JSXAttribute value can be many things:
29
+ * - css='myStyles'
30
+ * - css={myStyles}
31
+ * - css={[styles1, styles2]}
32
+ * - header={<></>}
33
+ * - css={styleMap.header}
34
+ * - css={...styles}
35
+ *
36
+ * Currently, `getValue` has only implemented strategies for when the value is a string, or an ExpressionStatement
37
+ * If you need additional functionality add it, and set the correct `type` on the returned object
38
+ */
39
+ getValue: function getValue(node) {
40
+ if (!(0, _eslintCodemodUtils.isNodeOfType)(node, 'JSXAttribute')) {
41
+ return;
42
+ }
43
+ if (!node.value) {
44
+ return;
45
+ }
46
+
47
+ // handle `css={myStyles}`
48
+ if ((0, _eslintCodemodUtils.isNodeOfType)(node.value, 'JSXExpressionContainer') && (0, _eslintCodemodUtils.isNodeOfType)(node.value.expression, 'Identifier')) {
49
+ return {
50
+ type: 'ExpressionStatement',
51
+ value: node.value.expression.name
52
+ };
53
+ }
54
+
55
+ // handle `css='myStyles'`
56
+ if ((0, _eslintCodemodUtils.isNodeOfType)(node.value, 'Literal') && node.value.value) {
57
+ var _node$value$value;
58
+ return {
59
+ type: 'Literal',
60
+ value: (_node$value$value = node.value.value) === null || _node$value$value === void 0 ? void 0 : _node$value$value.toString()
61
+ };
62
+ }
63
+ }
64
+ };
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.JSXElementHelper = exports.JSXElement = void 0;
7
+ var _eslintCodemodUtils = require("eslint-codemod-utils");
8
+ var JSXElementHelper = exports.JSXElement = exports.JSXElementHelper = {
9
+ /**
10
+ * Names of JSXElements can be any of:
11
+ * `<Component></Component>` - (JSXIdentifier)
12
+ * `<MyComponents.Component></MyComponents.Component>` - `MyComponents` is a namespace (JSXNamespacedName)
13
+ * `<MyComponents.Component></MyComponents.Component>` - `MyComponents` is an object (JSXMemberExpression)
14
+ *
15
+ * Getting the name of a JSXMemberExpression is difficult, because object can contain objects, which is recursively defined in the AST.
16
+ * e.g. getting the name of `<MyComponents.PresentationLayer.LeftSideBar.Header />` would require `getName` to recursively resolve all parts of the name.
17
+ * `getName` does not currently have this functionality. Add it if you need it.
18
+ */
19
+ getName: function getName(node) {
20
+ if (!(0, _eslintCodemodUtils.isNodeOfType)(node.openingElement.name, 'JSXIdentifier')) {
21
+ // TODO: We may want to log this
22
+ return '';
23
+ }
24
+ return node.openingElement.name.name;
25
+ },
26
+ updateName: function updateName(node, newName, fixer) {
27
+ var isSelfClosing = JSXElementHelper.isSelfClosing(node);
28
+ var openingElementFix = fixer.replaceText(node.openingElement.name, (0, _eslintCodemodUtils.jsxIdentifier)(newName).toString());
29
+ if (isSelfClosing || !node.closingElement) {
30
+ return [openingElementFix];
31
+ }
32
+ var closingElementFix = fixer.replaceText(node.closingElement.name, (0, _eslintCodemodUtils.jsxIdentifier)(newName).toString());
33
+ return [openingElementFix, closingElementFix];
34
+ },
35
+ isSelfClosing: function isSelfClosing(node) {
36
+ return node.openingElement.selfClosing;
37
+ },
38
+ getAttributes: function getAttributes(node) {
39
+ return node.openingElement.attributes;
40
+ },
41
+ getAttributeByName: function getAttributeByName(node, name) {
42
+ return node.openingElement.attributes.find(function (attr) {
43
+ // Ignore anything other than JSXAttribute
44
+ if (!(0, _eslintCodemodUtils.isNodeOfType)(attr, 'JSXAttribute')) {
45
+ return false;
46
+ }
47
+ return attr.name.name === name;
48
+ });
49
+ },
50
+ containsSpreadAttributes: function containsSpreadAttributes(node) {
51
+ return node.openingElement.attributes.some(function (attr) {
52
+ return (0, _eslintCodemodUtils.isNodeOfType)(attr, 'JSXSpreadAttribute');
53
+ });
54
+ }
55
+ };
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.Root = void 0;
7
+ var _eslintCodemodUtils = require("eslint-codemod-utils");
8
+ /* eslint-disable @repo/internal/react/require-jsdoc */
9
+
10
+ // Little bit unreadable, but better than duplicating the type
11
+
12
+ var Root = exports.Root = {
13
+ /**
14
+ * Note: This can return multiple ImportDeclarations for cases like:
15
+ * ```
16
+ * import { Stack } from '@atlaskit/primitives'
17
+ * import type { StackProps } from '@atlaskit/primitives'
18
+ * ```
19
+ */
20
+ findImportsByModule: function findImportsByModule(root, name) {
21
+ return root.filter(function (node) {
22
+ if (!(0, _eslintCodemodUtils.isNodeOfType)(node, 'ImportDeclaration')) {
23
+ return false;
24
+ }
25
+ if (!(0, _eslintCodemodUtils.hasImportDeclaration)(node, name)) {
26
+ return false;
27
+ }
28
+ return true;
29
+ });
30
+ },
31
+ insertImport: function insertImport(root, data, fixer) {
32
+ return fixer.insertTextBefore(root[0], "".concat((0, _eslintCodemodUtils.insertImportDeclaration)(data.module, data.specifiers), ";\n"));
33
+ }
34
+ };
@@ -13,6 +13,8 @@ var _assign = _interopRequireDefault(require("lodash/assign"));
13
13
  var _createRule = require("../utils/create-rule");
14
14
  // eslint-disable-next-line import/no-extraneous-dependencies
15
15
 
16
+ // File-level tracking of styles hoisted from the cssOnTopOfModule/cssAtBottomOfModule fixers
17
+ var hoistedCss = [];
16
18
  function isCssCallExpression(node, cssFunctions) {
17
19
  cssFunctions = [].concat((0, _toConsumableArray2.default)(cssFunctions), ['cssMap']);
18
20
  return !!((0, _eslintCodemodUtils.isNodeOfType)(node, 'CallExpression') && node.callee && node.callee.type === 'Identifier' && cssFunctions.includes(node.callee.name) && node.arguments.length && node.arguments[0].type === 'ObjectExpression');
@@ -25,11 +27,11 @@ function findSpreadProperties(node) {
25
27
  property.type === 'ExperimentalSpreadProperty';
26
28
  });
27
29
  }
28
- var getTopLevelNode = function getTopLevelNode(expression) {
30
+ var getProgramNode = function getProgramNode(expression) {
29
31
  while (expression.parent.type !== 'Program') {
30
32
  expression = expression.parent;
31
33
  }
32
- return expression;
34
+ return expression.parent;
33
35
  };
34
36
 
35
37
  // TODO: This can be optimised by implementing a fixer at the very end (Program:exit) and handling all validations at once
@@ -48,7 +50,7 @@ var getDeclaratorString = function getDeclaratorString(context) {
48
50
  }
49
51
  var variables = scope.variables.map(function (variable) {
50
52
  return variable.name;
51
- });
53
+ }).concat(hoistedCss);
52
54
  var count = 2;
53
55
  var declaratorName = 'styles';
54
56
 
@@ -61,6 +63,9 @@ var getDeclaratorString = function getDeclaratorString(context) {
61
63
  count++;
62
64
  }
63
65
  }
66
+
67
+ // Keep track of it by adding it to the hoistedCss global array
68
+ hoistedCss = [].concat((0, _toConsumableArray2.default)(hoistedCss), ["".concat(declaratorName).concat(count)]);
64
69
  return "".concat(declaratorName).concat(count);
65
70
  };
66
71
  function analyzeIdentifier(context, sourceIdentifier, configuration) {
@@ -123,7 +128,19 @@ function analyzeIdentifier(context, sourceIdentifier, configuration) {
123
128
  */
124
129
  var fixCssNotInModuleScope = function fixCssNotInModuleScope(fixer, context, configuration, node, cssAttributeName) {
125
130
  var sourceCode = context.getSourceCode();
126
- var topLevelNode = getTopLevelNode(node);
131
+
132
+ // Get the program node in order to properly position the hoisted styles
133
+ var programNode = getProgramNode(node);
134
+ var fixerNodePlacement = programNode;
135
+ if (configuration.stylesPlacement === 'bottom') {
136
+ // The last value is the bottom of the file
137
+ fixerNodePlacement = programNode.body[programNode.body.length - 1];
138
+ } else {
139
+ // Place after the last ImportDeclaration
140
+ fixerNodePlacement = programNode.body.length === 1 ? programNode.body[0] : programNode.body.find(function (node) {
141
+ return node.type !== 'ImportDeclaration';
142
+ });
143
+ }
127
144
  var moduleString;
128
145
  var implementFixer = [];
129
146
  if (node.type === 'Identifier') {
@@ -145,7 +162,7 @@ var fixCssNotInModuleScope = function fixCssNotInModuleScope(fixer, context, con
145
162
  }
146
163
  return [].concat(implementFixer, [
147
164
  // Insert the node either before or after
148
- configuration.stylesPlacement === 'bottom' ? fixer.insertTextAfter(topLevelNode, '\n' + moduleString) : fixer.insertTextBefore(topLevelNode, moduleString + '\n')]);
165
+ configuration.stylesPlacement === 'bottom' ? fixer.insertTextAfter(fixerNodePlacement, '\n' + moduleString) : fixer.insertTextBefore(fixerNodePlacement, moduleString + '\n')]);
149
166
  };
150
167
 
151
168
  /**
@@ -276,6 +293,9 @@ var rule = (0, _createRule.createLintRule)({
276
293
  }), (0, _defineProperty2.default)(_ref3, "JSXAttribute", function JSXAttribute(node) {
277
294
  var name = node.name,
278
295
  value = node.value;
296
+
297
+ // Always reset to empty array
298
+ hoistedCss = [];
279
299
  if (name.type === 'JSXIdentifier' && mergedConfig.cssFunctions.includes(name.name)) {
280
300
  // When not a jsx expression. For eg. css=""
281
301
  if ((value === null || value === void 0 ? void 0 : value.type) !== 'JSXExpressionContainer') {
@@ -4,11 +4,9 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- var _eslintCodemodUtils = require("eslint-codemod-utils");
8
7
  var _createRule = require("../utils/create-rule");
9
8
  var _config = require("./config");
10
9
  var _transformers = require("./transformers");
11
- var _utils = require("./utils");
12
10
  var boxDocsUrl = 'https://atlassian.design/components/primitives/box';
13
11
  var rule = (0, _createRule.createLintRule)({
14
12
  meta: {
@@ -30,113 +28,19 @@ var rule = (0, _createRule.createLintRule)({
30
28
  return {
31
29
  // transforms styled.<html>(...) usages
32
30
  CallExpression: function CallExpression(node) {
33
- if (!config.patterns.includes('compiled-styled-object')) {
34
- return;
35
- }
36
- if (!(0, _eslintCodemodUtils.isNodeOfType)(node, 'CallExpression')) {
37
- return;
38
- }
39
- var styledComponentVariableRef = (0, _utils.findValidStyledComponentCall)(node);
40
- if (!styledComponentVariableRef || !(0, _eslintCodemodUtils.isNodeOfType)(styledComponentVariableRef.id, 'Identifier') || !(0, _utils.isValidCssPropertiesToTransform)(node, config)) {
41
- return;
42
- }
43
- var styledComponentJsxRef = (0, _utils.findValidJsxUsageToTransform)(styledComponentVariableRef.id.name, context.getScope());
44
- if (!styledComponentJsxRef) {
45
- return;
46
- }
47
-
48
- // if we have both references at this point then we can offer a fix \o/
49
- context.report({
50
- node: styledComponentVariableRef,
51
- messageId: 'preferPrimitivesBox',
52
- suggest: [{
53
- desc: "Convert ".concat(styledComponentVariableRef.id.name, " to Box"),
54
- fix: (0, _transformers.styledComponentToPrimitive)({
55
- stylesRef: styledComponentVariableRef,
56
- jsxRef: styledComponentJsxRef
57
- }, context)
58
- }]
31
+ _transformers.CompiledStyled.lint(node, {
32
+ context: context,
33
+ config: config
59
34
  });
60
35
  },
61
36
  // transforms <div css={...}> usages
62
- JSXOpeningElement: function JSXOpeningElement(node) {
63
- if (!config.patterns.includes('compiled-css-function')) {
64
- return false;
65
- }
66
- if (!(0, _eslintCodemodUtils.isNodeOfType)(node, 'JSXOpeningElement')) {
67
- return;
68
- }
69
- if (!(0, _eslintCodemodUtils.isNodeOfType)(node.name, 'JSXIdentifier')) {
70
- return;
71
- }
72
- if (!(0, _eslintCodemodUtils.isNodeOfType)(node.parent, 'JSXElement')) {
73
- return;
74
- }
75
- var suggestBox = shouldSuggestBox(node.parent, context, config);
76
- if (suggestBox) {
77
- context.report({
78
- node: node,
79
- messageId: 'preferPrimitivesBox',
80
- data: {
81
- element: node.name.name
82
- },
83
- suggest: [{
84
- desc: "Convert to Box",
85
- fix: (0, _transformers.jsxElementToBoxTransformer)(node.parent, context)
86
- }]
87
- });
88
- }
37
+ JSXElement: function JSXElement(node) {
38
+ _transformers.EmotionCSS.lint(node, {
39
+ context: context,
40
+ config: config
41
+ });
89
42
  }
90
43
  };
91
44
  }
92
45
  });
93
- var shouldSuggestBox = function shouldSuggestBox(node, context, config
94
- // scope: Scope.Scope,
95
- ) {
96
- if (!node) {
97
- return false;
98
- }
99
-
100
- // Currently we only support `div`, but possibly more in future
101
- if (!(0, _utils.isValidTagName)(node)) {
102
- return false;
103
- }
104
-
105
- // Currently we only support elements that contain only a `css` attr, possibly more in future
106
- if (!(0, _utils.containsOnlySupportedAttrs)(node)) {
107
- return false;
108
- }
109
-
110
- // Get the `css` attr
111
- var cssAttr = (0, _utils.getJSXAttributeByName)(node.openingElement, 'css');
112
-
113
- // Get the prop value, e.g. `myStyles` in `css={myStyles}`
114
- var cssVariableName = (0, _utils.getAttributeValueIdentifier)(cssAttr);
115
-
116
- // `cssVariableName` could be undefined if the maker has
117
- // done something like `css={[styles1, styles2]}`, `css={...styles}`, etc
118
- if (!cssVariableName) {
119
- return false;
120
- }
121
-
122
- /**
123
- * Make sure the variable is not used in multiple JSX elements:
124
- * ```
125
- * <div css={paddingStyles}></div>
126
- * <input css={paddingStyles}></input>
127
- * ```
128
- */
129
- if ((0, _utils.getVariableUsagesCount)(cssVariableName, context) !== 1) {
130
- return false;
131
- }
132
-
133
- // Find where `cssVariableName` is defined. We're looking for `const myStyles = css({...})`
134
- var cssVariableDefinition = (0, _eslintCodemodUtils.getIdentifierInParentScope)(context.getScope(), cssVariableName);
135
- var cssVariableValue = (0, _utils.getVariableDefinitionValue)(cssVariableDefinition);
136
- // Check if `cssVariableValue` is a function called `css()`
137
- if (!cssVariableValue || !(0, _utils.isFunctionNamed)(cssVariableValue, 'css')) {
138
- return false;
139
- }
140
- return (0, _utils.isValidCssPropertiesToTransform)(cssVariableValue.node.init, config);
141
- };
142
46
  var _default = exports.default = rule;
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ var _typeof = require("@babel/runtime/helpers/typeof");
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.convertJsxCallSite = void 0;
9
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
10
+ var _eslintCodemodUtils = require("eslint-codemod-utils");
11
+ var ast = _interopRequireWildcard(require("../../../../ast-nodes"));
12
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
13
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
14
+ /**
15
+ * Transforms a JSXElement from:
16
+ * ```
17
+ * <div>
18
+ * // ...
19
+ * </div>
20
+ * ```
21
+ * to
22
+ * ```
23
+ * <Box xcss={myStyles}>
24
+ * // ...
25
+ * </Box>
26
+ * ```
27
+ */
28
+ var convertJsxCallSite = exports.convertJsxCallSite = function convertJsxCallSite(jsxElement, newStylesVariableName, fixer) {
29
+ var fixes = [];
30
+
31
+ // renames the JSX call site
32
+ if ((0, _eslintCodemodUtils.isNodeOfType)(jsxElement, 'JSXElement')) {
33
+ fixes.push.apply(fixes, (0, _toConsumableArray2.default)(ast.JSXElement.updateName(jsxElement, 'Box', fixer)));
34
+ }
35
+
36
+ // adds xcss prop
37
+ fixes.push(fixer.insertTextAfter(jsxElement.openingElement.name, " xcss={".concat(newStylesVariableName, "}")));
38
+ return fixes;
39
+ };
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.convertStyledComponentToXcss = void 0;
8
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
9
+ var _eslintCodemodUtils = require("eslint-codemod-utils");
10
+ var _cssToXcss = require("../css-to-xcss");
11
+ /**
12
+ * Transforms a variable like:
13
+ * ```
14
+ * const MyComponent = styled.div({
15
+ * padding: '8px',
16
+ * })
17
+ * ```
18
+ * to
19
+ * ```
20
+ * const myComponentStyles = xcss({
21
+ * padding: 'space.100',
22
+ * })
23
+ * ```
24
+ */
25
+ var convertStyledComponentToXcss = exports.convertStyledComponentToXcss = function convertStyledComponentToXcss(styles, newStylesVariableName, fixer) {
26
+ var fixes = [];
27
+
28
+ // renames the variable from MyComponent to myComponentStyles
29
+ fixes.push(fixer.replaceText(styles.id, newStylesVariableName));
30
+
31
+ // renames the function call from styled.<tag> to xcss
32
+ if (styles.init && (0, _eslintCodemodUtils.isNodeOfType)(styles.init, 'CallExpression')) {
33
+ fixes.push(fixer.replaceText(styles.init.callee, 'xcss'));
34
+ }
35
+
36
+ // converts CSS values to XCSS-compatible tokens
37
+ if (styles.init && (0, _eslintCodemodUtils.isNodeOfType)(styles.init, 'CallExpression')) {
38
+ var objectExpression = styles.init.arguments[0];
39
+ if ((0, _eslintCodemodUtils.isNodeOfType)(objectExpression, 'ObjectExpression')) {
40
+ fixes.push.apply(fixes, (0, _toConsumableArray2.default)((0, _cssToXcss.styledObjectToXcssTokens)(objectExpression, fixer)));
41
+ }
42
+ }
43
+ return fixes;
44
+ };
@@ -1,11 +1,14 @@
1
1
  "use strict";
2
2
 
3
+ var _typeof = require("@babel/runtime/helpers/typeof");
3
4
  Object.defineProperty(exports, "__esModule", {
4
5
  value: true
5
6
  });
6
7
  exports.findValidStyledComponentCall = void 0;
7
8
  var _eslintCodemodUtils = require("eslint-codemod-utils");
8
- var _isValidTagName = require("./is-valid-tag-name");
9
+ var supported = _interopRequireWildcard(require("./supported"));
10
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
11
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
9
12
  /**
10
13
  * returns a variable reference if preconditions are favourable for
11
14
  * the transformation to proceed, undefined otherwise.
@@ -46,7 +49,7 @@ var isStyledCallExpression = function isStyledCallExpression(call) {
46
49
  if (!(0, _eslintCodemodUtils.isNodeOfType)(call.callee.object, 'Identifier') || !(0, _eslintCodemodUtils.isNodeOfType)(call.callee.property, 'Identifier')) {
47
50
  return false;
48
51
  }
49
- if (/^styled2?$/.test(call.callee.object.name) && _isValidTagName.validPrimitiveElements.has(call.callee.property.name)) {
52
+ if (/^styled2?$/.test(call.callee.object.name) && supported.elements.includes(call.callee.property.name)) {
50
53
  return true;
51
54
  }
52
55
  return false;