@atlaskit/eslint-plugin-design-system 8.23.2 → 8.23.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (155) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/README.md +1 -0
  3. package/constellation/index/usage.mdx +39 -0
  4. package/dist/cjs/ast-nodes/index.js +7 -0
  5. package/dist/cjs/ast-nodes/object.js +84 -0
  6. package/dist/cjs/presets/all.codegen.js +2 -1
  7. package/dist/cjs/presets/recommended.codegen.js +2 -1
  8. package/dist/cjs/rules/consistent-css-prop-usage/index.js +25 -5
  9. package/dist/cjs/rules/index.codegen.js +3 -1
  10. package/dist/cjs/rules/local-cx-xcss/index.js +51 -0
  11. package/dist/cjs/rules/no-css-tagged-template-expression/create-no-tagged-template-expression-rule/index.js +3 -1
  12. package/dist/cjs/rules/no-css-tagged-template-expression/index.js +2 -2
  13. package/dist/cjs/rules/use-primitives/index.js +4 -30
  14. package/dist/cjs/rules/use-primitives/transformers/compiled-styled/convert-jsx-call-site.js +39 -0
  15. package/dist/cjs/rules/use-primitives/transformers/compiled-styled/convert-styled-component-call-to-jsx.js +44 -0
  16. package/dist/cjs/rules/use-primitives/{utils → transformers/compiled-styled}/find-valid-styled-component-call.js +5 -2
  17. package/dist/cjs/rules/use-primitives/transformers/compiled-styled/index.js +117 -0
  18. package/dist/cjs/rules/use-primitives/transformers/compiled-styled/supported.js +10 -0
  19. package/dist/cjs/rules/use-primitives/transformers/compiled-styled/upsert-import-declaration.js +37 -0
  20. package/dist/cjs/rules/use-primitives/transformers/emotion-css/contains-only-supported-attrs.js +27 -0
  21. package/dist/cjs/rules/use-primitives/transformers/emotion-css/index.js +4 -47
  22. package/dist/cjs/rules/use-primitives/transformers/emotion-css/supported.js +2 -44
  23. package/dist/cjs/rules/use-primitives/transformers/emotion-css/upsert-import-declaration.js +37 -0
  24. package/dist/cjs/rules/use-primitives/transformers/index.js +10 -10
  25. package/dist/cjs/rules/use-primitives/utils/index.js +1 -43
  26. package/dist/cjs/rules/utils/is-supported-import.js +61 -0
  27. package/dist/es2019/ast-nodes/index.js +1 -0
  28. package/dist/es2019/ast-nodes/object.js +79 -0
  29. package/dist/es2019/presets/all.codegen.js +2 -1
  30. package/dist/es2019/presets/recommended.codegen.js +2 -1
  31. package/dist/es2019/rules/consistent-css-prop-usage/index.js +23 -5
  32. package/dist/es2019/rules/index.codegen.js +3 -1
  33. package/dist/es2019/rules/local-cx-xcss/index.js +45 -0
  34. package/dist/es2019/rules/no-css-tagged-template-expression/create-no-tagged-template-expression-rule/index.js +3 -1
  35. package/dist/es2019/rules/no-css-tagged-template-expression/index.js +2 -2
  36. package/dist/es2019/rules/use-primitives/index.js +4 -30
  37. package/dist/es2019/rules/use-primitives/transformers/compiled-styled/convert-jsx-call-site.js +29 -0
  38. package/dist/es2019/rules/use-primitives/transformers/compiled-styled/convert-styled-component-call-to-jsx.js +37 -0
  39. package/dist/es2019/rules/use-primitives/{utils → transformers/compiled-styled}/find-valid-styled-component-call.js +2 -2
  40. package/dist/es2019/rules/use-primitives/transformers/compiled-styled/index.js +107 -0
  41. package/dist/es2019/rules/use-primitives/transformers/compiled-styled/supported.js +4 -0
  42. package/dist/es2019/rules/use-primitives/transformers/compiled-styled/upsert-import-declaration.js +30 -0
  43. package/dist/es2019/rules/use-primitives/transformers/emotion-css/contains-only-supported-attrs.js +19 -0
  44. package/dist/es2019/rules/use-primitives/transformers/emotion-css/index.js +4 -48
  45. package/dist/es2019/rules/use-primitives/transformers/emotion-css/supported.js +1 -43
  46. package/dist/es2019/rules/use-primitives/transformers/emotion-css/upsert-import-declaration.js +30 -0
  47. package/dist/es2019/rules/use-primitives/transformers/index.js +2 -2
  48. package/dist/es2019/rules/use-primitives/utils/index.js +1 -7
  49. package/dist/es2019/rules/utils/is-supported-import.js +52 -0
  50. package/dist/esm/ast-nodes/index.js +1 -0
  51. package/dist/esm/ast-nodes/object.js +79 -0
  52. package/dist/esm/presets/all.codegen.js +2 -1
  53. package/dist/esm/presets/recommended.codegen.js +2 -1
  54. package/dist/esm/rules/consistent-css-prop-usage/index.js +25 -5
  55. package/dist/esm/rules/index.codegen.js +3 -1
  56. package/dist/esm/rules/local-cx-xcss/index.js +45 -0
  57. package/dist/esm/rules/no-css-tagged-template-expression/create-no-tagged-template-expression-rule/index.js +3 -1
  58. package/dist/esm/rules/no-css-tagged-template-expression/index.js +2 -2
  59. package/dist/esm/rules/use-primitives/index.js +4 -30
  60. package/dist/esm/rules/use-primitives/transformers/compiled-styled/convert-jsx-call-site.js +30 -0
  61. package/dist/esm/rules/use-primitives/transformers/compiled-styled/convert-styled-component-call-to-jsx.js +38 -0
  62. package/dist/esm/rules/use-primitives/{utils → transformers/compiled-styled}/find-valid-styled-component-call.js +2 -2
  63. package/dist/esm/rules/use-primitives/transformers/compiled-styled/index.js +107 -0
  64. package/dist/esm/rules/use-primitives/transformers/compiled-styled/supported.js +4 -0
  65. package/dist/esm/rules/use-primitives/transformers/compiled-styled/upsert-import-declaration.js +29 -0
  66. package/dist/esm/rules/use-primitives/transformers/emotion-css/contains-only-supported-attrs.js +19 -0
  67. package/dist/esm/rules/use-primitives/transformers/emotion-css/index.js +4 -47
  68. package/dist/esm/rules/use-primitives/transformers/emotion-css/supported.js +1 -43
  69. package/dist/esm/rules/use-primitives/transformers/emotion-css/upsert-import-declaration.js +29 -0
  70. package/dist/esm/rules/use-primitives/transformers/index.js +2 -2
  71. package/dist/esm/rules/use-primitives/utils/index.js +1 -7
  72. package/dist/esm/rules/utils/is-supported-import.js +54 -0
  73. package/dist/types/ast-nodes/index.d.ts +1 -0
  74. package/dist/types/ast-nodes/object.d.ts +39 -0
  75. package/dist/types/index.codegen.d.ts +2 -0
  76. package/dist/types/presets/all.codegen.d.ts +2 -1
  77. package/dist/types/presets/recommended.codegen.d.ts +2 -1
  78. package/dist/types/rules/index.codegen.d.ts +1 -0
  79. package/dist/types/rules/local-cx-xcss/index.d.ts +3 -0
  80. package/dist/types/rules/no-css-tagged-template-expression/create-no-tagged-template-expression-rule/index.d.ts +3 -4
  81. package/dist/types/rules/use-primitives/transformers/compiled-styled/convert-jsx-call-site.d.ts +17 -0
  82. package/dist/types/rules/use-primitives/transformers/compiled-styled/convert-styled-component-call-to-jsx.d.ts +17 -0
  83. package/dist/types/rules/use-primitives/transformers/compiled-styled/index.d.ts +25 -0
  84. package/dist/types/rules/use-primitives/transformers/compiled-styled/supported.d.ts +2 -0
  85. package/dist/types/rules/use-primitives/transformers/compiled-styled/upsert-import-declaration.d.ts +14 -0
  86. package/dist/types/rules/use-primitives/transformers/emotion-css/contains-only-supported-attrs.d.ts +7 -0
  87. package/dist/types/rules/use-primitives/transformers/emotion-css/index.d.ts +0 -19
  88. package/dist/types/rules/use-primitives/transformers/emotion-css/supported.d.ts +0 -7
  89. package/dist/types/rules/use-primitives/transformers/emotion-css/upsert-import-declaration.d.ts +14 -0
  90. package/dist/types/rules/use-primitives/transformers/index.d.ts +2 -2
  91. package/dist/types/rules/use-primitives/utils/index.d.ts +0 -6
  92. package/dist/types/rules/utils/is-supported-import.d.ts +16 -0
  93. package/dist/types-ts4.5/ast-nodes/index.d.ts +1 -0
  94. package/dist/types-ts4.5/ast-nodes/object.d.ts +39 -0
  95. package/dist/types-ts4.5/index.codegen.d.ts +2 -0
  96. package/dist/types-ts4.5/presets/all.codegen.d.ts +2 -1
  97. package/dist/types-ts4.5/presets/recommended.codegen.d.ts +2 -1
  98. package/dist/types-ts4.5/rules/index.codegen.d.ts +1 -0
  99. package/dist/types-ts4.5/rules/local-cx-xcss/index.d.ts +3 -0
  100. package/dist/types-ts4.5/rules/no-css-tagged-template-expression/create-no-tagged-template-expression-rule/index.d.ts +3 -4
  101. package/dist/types-ts4.5/rules/use-primitives/transformers/compiled-styled/convert-jsx-call-site.d.ts +17 -0
  102. package/dist/types-ts4.5/rules/use-primitives/transformers/compiled-styled/convert-styled-component-call-to-jsx.d.ts +17 -0
  103. package/dist/types-ts4.5/rules/use-primitives/transformers/compiled-styled/index.d.ts +25 -0
  104. package/dist/types-ts4.5/rules/use-primitives/transformers/compiled-styled/supported.d.ts +2 -0
  105. package/dist/types-ts4.5/rules/use-primitives/transformers/compiled-styled/upsert-import-declaration.d.ts +14 -0
  106. package/dist/types-ts4.5/rules/use-primitives/transformers/emotion-css/contains-only-supported-attrs.d.ts +7 -0
  107. package/dist/types-ts4.5/rules/use-primitives/transformers/emotion-css/index.d.ts +0 -19
  108. package/dist/types-ts4.5/rules/use-primitives/transformers/emotion-css/supported.d.ts +0 -7
  109. package/dist/types-ts4.5/rules/use-primitives/transformers/emotion-css/upsert-import-declaration.d.ts +14 -0
  110. package/dist/types-ts4.5/rules/use-primitives/transformers/index.d.ts +2 -2
  111. package/dist/types-ts4.5/rules/use-primitives/utils/index.d.ts +0 -6
  112. package/dist/types-ts4.5/rules/utils/is-supported-import.d.ts +16 -0
  113. package/package.json +1 -1
  114. package/dist/cjs/rules/no-css-tagged-template-expression/is-supported-import.js +0 -29
  115. package/dist/cjs/rules/use-primitives/transformers/jsx-element-to-box.js +0 -26
  116. package/dist/cjs/rules/use-primitives/transformers/styled-component-to-primitive.js +0 -68
  117. package/dist/cjs/rules/use-primitives/utils/contains-only-supported-attrs.js +0 -19
  118. package/dist/cjs/rules/use-primitives/utils/is-valid-tag-name.js +0 -13
  119. package/dist/cjs/rules/use-primitives/utils/update-jsx-element-name.js +0 -16
  120. package/dist/cjs/rules/use-primitives/utils/upsert-import-declaration.js +0 -80
  121. package/dist/es2019/rules/no-css-tagged-template-expression/is-supported-import.js +0 -21
  122. package/dist/es2019/rules/use-primitives/transformers/jsx-element-to-box.js +0 -16
  123. package/dist/es2019/rules/use-primitives/transformers/styled-component-to-primitive.js +0 -59
  124. package/dist/es2019/rules/use-primitives/utils/contains-only-supported-attrs.js +0 -13
  125. package/dist/es2019/rules/use-primitives/utils/is-valid-tag-name.js +0 -7
  126. package/dist/es2019/rules/use-primitives/utils/update-jsx-element-name.js +0 -12
  127. package/dist/es2019/rules/use-primitives/utils/upsert-import-declaration.js +0 -76
  128. package/dist/esm/rules/no-css-tagged-template-expression/is-supported-import.js +0 -23
  129. package/dist/esm/rules/use-primitives/transformers/jsx-element-to-box.js +0 -19
  130. package/dist/esm/rules/use-primitives/transformers/styled-component-to-primitive.js +0 -61
  131. package/dist/esm/rules/use-primitives/utils/contains-only-supported-attrs.js +0 -13
  132. package/dist/esm/rules/use-primitives/utils/is-valid-tag-name.js +0 -7
  133. package/dist/esm/rules/use-primitives/utils/update-jsx-element-name.js +0 -10
  134. package/dist/esm/rules/use-primitives/utils/upsert-import-declaration.js +0 -75
  135. package/dist/types/rules/no-css-tagged-template-expression/is-supported-import.d.ts +0 -12
  136. package/dist/types/rules/use-primitives/transformers/jsx-element-to-box.d.ts +0 -3
  137. package/dist/types/rules/use-primitives/transformers/styled-component-to-primitive.d.ts +0 -13
  138. package/dist/types/rules/use-primitives/utils/contains-only-supported-attrs.d.ts +0 -2
  139. package/dist/types/rules/use-primitives/utils/is-valid-tag-name.d.ts +0 -3
  140. package/dist/types/rules/use-primitives/utils/update-jsx-element-name.d.ts +0 -3
  141. package/dist/types/rules/use-primitives/utils/upsert-import-declaration.d.ts +0 -11
  142. package/dist/types-ts4.5/rules/no-css-tagged-template-expression/is-supported-import.d.ts +0 -12
  143. package/dist/types-ts4.5/rules/use-primitives/transformers/jsx-element-to-box.d.ts +0 -3
  144. package/dist/types-ts4.5/rules/use-primitives/transformers/styled-component-to-primitive.d.ts +0 -13
  145. package/dist/types-ts4.5/rules/use-primitives/utils/contains-only-supported-attrs.d.ts +0 -2
  146. package/dist/types-ts4.5/rules/use-primitives/utils/is-valid-tag-name.d.ts +0 -3
  147. package/dist/types-ts4.5/rules/use-primitives/utils/update-jsx-element-name.d.ts +0 -3
  148. package/dist/types-ts4.5/rules/use-primitives/utils/upsert-import-declaration.d.ts +0 -11
  149. /package/dist/cjs/rules/use-primitives/{utils → transformers/compiled-styled}/find-valid-jsx-usage-to-transform.js +0 -0
  150. /package/dist/es2019/rules/use-primitives/{utils → transformers/compiled-styled}/find-valid-jsx-usage-to-transform.js +0 -0
  151. /package/dist/esm/rules/use-primitives/{utils → transformers/compiled-styled}/find-valid-jsx-usage-to-transform.js +0 -0
  152. /package/dist/types/rules/use-primitives/{utils → transformers/compiled-styled}/find-valid-jsx-usage-to-transform.d.ts +0 -0
  153. /package/dist/types/rules/use-primitives/{utils → transformers/compiled-styled}/find-valid-styled-component-call.d.ts +0 -0
  154. /package/dist/types-ts4.5/rules/use-primitives/{utils → transformers/compiled-styled}/find-valid-jsx-usage-to-transform.d.ts +0 -0
  155. /package/dist/types-ts4.5/rules/use-primitives/{utils → transformers/compiled-styled}/find-valid-styled-component-call.d.ts +0 -0
@@ -0,0 +1,117 @@
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.CompiledStyled = 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
+ var _utils = require("../../utils");
13
+ var _convertJsxCallSite = require("./convert-jsx-call-site");
14
+ var _convertStyledComponentCallToJsx = require("./convert-styled-component-call-to-jsx");
15
+ var _findValidJsxUsageToTransform = require("./find-valid-jsx-usage-to-transform");
16
+ var _findValidStyledComponentCall = require("./find-valid-styled-component-call");
17
+ var _upsertImportDeclaration = require("./upsert-import-declaration");
18
+ 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); }
19
+ 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; }
20
+ /* eslint-disable @repo/internal/react/require-jsdoc */
21
+
22
+ var CompiledStyled = exports.CompiledStyled = {
23
+ lint: function lint(node, _ref) {
24
+ var context = _ref.context,
25
+ config = _ref.config;
26
+ if (!(0, _eslintCodemodUtils.isNodeOfType)(node, 'CallExpression')) {
27
+ return;
28
+ }
29
+
30
+ // Check whether all criteria needed to make a transformation are met
31
+ var _CompiledStyled$_chec = CompiledStyled._check(node, {
32
+ context: context,
33
+ config: config
34
+ }),
35
+ success = _CompiledStyled$_chec.success,
36
+ refs = _CompiledStyled$_chec.refs;
37
+ if (!success || !refs) {
38
+ return;
39
+ }
40
+ context.report({
41
+ node: refs.styles,
42
+ messageId: 'preferPrimitivesBox',
43
+ suggest: [{
44
+ desc: "Convert ".concat(ast.JSXElement.getName(refs.jsxElement), " to Box"),
45
+ fix: CompiledStyled._fix(refs, context)
46
+ }]
47
+ });
48
+ },
49
+ _check: function _check(node, _ref2) {
50
+ var context = _ref2.context,
51
+ config = _ref2.config;
52
+ if (!config.patterns.includes('compiled-styled-object')) {
53
+ return {
54
+ success: false
55
+ };
56
+ }
57
+ if (!(0, _eslintCodemodUtils.isNodeOfType)(node, 'CallExpression')) {
58
+ return {
59
+ success: false
60
+ };
61
+ }
62
+ var styledComponentVariableRef = (0, _findValidStyledComponentCall.findValidStyledComponentCall)(node);
63
+ if (!styledComponentVariableRef || !(0, _eslintCodemodUtils.isNodeOfType)(styledComponentVariableRef.id, 'Identifier') || !(0, _utils.isValidCssPropertiesToTransform)(node, config)) {
64
+ return {
65
+ success: false
66
+ };
67
+ }
68
+ var styledComponentJsxRef = (0, _findValidJsxUsageToTransform.findValidJsxUsageToTransform)(styledComponentVariableRef.id.name, context.getScope());
69
+ if (!styledComponentJsxRef) {
70
+ return {
71
+ success: false
72
+ };
73
+ }
74
+ if (!(0, _eslintCodemodUtils.isNodeOfType)(styledComponentJsxRef.parent, 'JSXElement')) {
75
+ return {
76
+ success: false
77
+ };
78
+ }
79
+ var importDeclaration = ast.Root.findImportsByModule(context.getSourceCode().ast.body, '@atlaskit/primitives');
80
+
81
+ // If there is more than one `@atlaskit/primitives` import, then it becomes difficult to determine which import to transform
82
+ if (importDeclaration.length > 1) {
83
+ return {
84
+ success: false
85
+ };
86
+ }
87
+ return {
88
+ success: true,
89
+ refs: {
90
+ styles: styledComponentVariableRef,
91
+ jsxElement: styledComponentJsxRef.parent
92
+ }
93
+ };
94
+ },
95
+ /**
96
+ * All required validation steps have been taken care of before this
97
+ * transformer is called, so it just goes ahead providing all necessary fixes
98
+ */
99
+ _fix: function _fix(refs, context) {
100
+ return function (fixer) {
101
+ // generates the new variable name: MyComponent -> myComponentStyles
102
+ var calculatedStylesVariableName = (0, _eslintCodemodUtils.isNodeOfType)(refs.styles.id, 'Identifier') && "".concat(refs.styles.id.name.replace(refs.styles.id.name[0], refs.styles.id.name[0].toLowerCase()), "Styles");
103
+ if (!calculatedStylesVariableName) {
104
+ return [];
105
+ }
106
+ var importFixes = (0, _upsertImportDeclaration.upsertImportDeclaration)({
107
+ module: '@atlaskit/primitives',
108
+ specifiers: ['Box', 'xcss']
109
+ }, context, fixer);
110
+ var stylesFixes = (0, _convertStyledComponentCallToJsx.convertStyledComponentToXcss)(refs.styles, calculatedStylesVariableName, fixer);
111
+ var jsxFixes = (0, _convertJsxCallSite.convertJsxCallSite)(refs.jsxElement, calculatedStylesVariableName, fixer);
112
+ return [importFixes].concat((0, _toConsumableArray2.default)(stylesFixes), (0, _toConsumableArray2.default)(jsxFixes)).filter(function (fix) {
113
+ return Boolean(fix);
114
+ }); // Some of the transformers can return arrays with undefined, so filter them out
115
+ };
116
+ }
117
+ };
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.elements = exports.attributes = void 0;
7
+ var elements = exports.elements = ['div'];
8
+ var attributes = exports.attributes = ['css'
9
+ // 'data-testid'
10
+ ];
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+
3
+ var _typeof = require("@babel/runtime/helpers/typeof");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.upsertImportDeclaration = void 0;
8
+ var ast = _interopRequireWildcard(require("../../../../ast-nodes"));
9
+ 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); }
10
+ 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; }
11
+ /**
12
+ * Currently this is defined here because it's not very general purpose.
13
+ * If we were to move this to `ast-nodes`, half the implementation would be in `Root`,
14
+ * and the other half would be in `Import`.
15
+ *
16
+ * TODO: Refactor and move to `ast-nodes`
17
+ *
18
+ * Note: It does not handle default imports, namespace imports, or aliased imports.
19
+ */
20
+ var upsertImportDeclaration = exports.upsertImportDeclaration = function upsertImportDeclaration(_ref, context, fixer) {
21
+ var module = _ref.module,
22
+ specifiers = _ref.specifiers;
23
+ // Find any imports that match the packageName
24
+ var root = context.getSourceCode().ast.body;
25
+ var importDeclarations = ast.Root.findImportsByModule(root, module);
26
+
27
+ // The import doesn't exist yet, we can just insert a whole new one
28
+ if (importDeclarations.length === 0) {
29
+ return ast.Root.insertImport(root, {
30
+ module: module,
31
+ specifiers: specifiers
32
+ }, fixer);
33
+ }
34
+
35
+ // The import exists so, modify the existing one
36
+ return ast.Import.insertNamedSpecifiers(importDeclarations[0], specifiers, fixer);
37
+ };
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+
3
+ var _typeof = require("@babel/runtime/helpers/typeof");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.containsOnlySupportedAttrs = void 0;
8
+ var _eslintCodemodUtils = require("eslint-codemod-utils");
9
+ var ast = _interopRequireWildcard(require("../../../../ast-nodes"));
10
+ var supported = _interopRequireWildcard(require("./supported"));
11
+ 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); }
12
+ 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; }
13
+ /**
14
+ * Check that every attribute in the JSXElement is something we support.
15
+ * We do this via a whitelist in `this.attributes`. The result is we exclude
16
+ * dangerous attrs like `id` and `style`.
17
+ */
18
+ var containsOnlySupportedAttrs = exports.containsOnlySupportedAttrs = function containsOnlySupportedAttrs(node) {
19
+ var attrs = ast.JSXElement.getAttributes(node);
20
+ return attrs.every(function (attr) {
21
+ if (!(0, _eslintCodemodUtils.isNodeOfType)(attr, 'JSXAttribute')) {
22
+ return false;
23
+ }
24
+ var name = ast.JSXAttribute.getName(attr);
25
+ return supported.attributes.includes(name);
26
+ });
27
+ };
@@ -11,7 +11,9 @@ var _eslintCodemodUtils = require("eslint-codemod-utils");
11
11
  var ast = _interopRequireWildcard(require("../../../../ast-nodes"));
12
12
  var _utils = require("../../utils");
13
13
  var _cssToXcss = require("../css-to-xcss");
14
+ var _containsOnlySupportedAttrs = require("./contains-only-supported-attrs");
14
15
  var supported = _interopRequireWildcard(require("./supported"));
16
+ var _upsertImportDeclaration = require("./upsert-import-declaration");
15
17
  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); }
16
18
  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; }
17
19
  /* eslint-disable @repo/internal/react/require-jsdoc */
@@ -63,7 +65,7 @@ var EmotionCSS = exports.EmotionCSS = {
63
65
  }
64
66
 
65
67
  // Ignore elements that contain dangerous attributes like `id`.
66
- if (!this._containsOnlySupportedAttributes(node)) {
68
+ if (!(0, _containsOnlySupportedAttrs.containsOnlySupportedAttrs)(node)) {
67
69
  return false;
68
70
  }
69
71
 
@@ -105,10 +107,9 @@ var EmotionCSS = exports.EmotionCSS = {
105
107
  return true;
106
108
  },
107
109
  _fix: function _fix(node, _ref3) {
108
- var _this = this;
109
110
  var context = _ref3.context;
110
111
  return function (fixer) {
111
- var importFix = _this._upsertImportDeclaration({
112
+ var importFix = (0, _upsertImportDeclaration.upsertImportDeclaration)({
112
113
  module: '@atlaskit/primitives',
113
114
  specifiers: ['Box', 'xcss']
114
115
  }, context, fixer);
@@ -120,49 +121,5 @@ var EmotionCSS = exports.EmotionCSS = {
120
121
  return Boolean(fix);
121
122
  }); // Some of the transformers can return arrays with undefined, so filter them out
122
123
  };
123
- },
124
- /**
125
- * Check that every attribute in the JSXElement is something we support.
126
- * We do this via a whitelist in `this.attributes`. The result is we exclude
127
- * dangerous attrs like `id` and `style`.
128
- */
129
- _containsOnlySupportedAttributes: function _containsOnlySupportedAttributes(node) {
130
- var attrs = ast.JSXElement.getAttributes(node);
131
- return attrs.every(function (attr) {
132
- if (!(0, _eslintCodemodUtils.isNodeOfType)(attr, 'JSXAttribute')) {
133
- return false;
134
- }
135
- if (!(0, _eslintCodemodUtils.isNodeOfType)(attr.name, 'JSXIdentifier')) {
136
- return false;
137
- }
138
- return supported.attributes.includes(attr.name.name);
139
- });
140
- },
141
- /**
142
- * Currently this is defined here because it's not very general purpose.
143
- * If we were to move this to `ast-nodes`, half the implementation would be in `Root`,
144
- * and the other half would be in `Import`.
145
- *
146
- * TODO: Refactor and move to `ast-nodes`
147
- *
148
- * Note: It does not handle default imports, namespace imports, or aliased imports.
149
- */
150
- _upsertImportDeclaration: function _upsertImportDeclaration(_ref4, context, fixer) {
151
- var module = _ref4.module,
152
- specifiers = _ref4.specifiers;
153
- // Find any imports that match the packageName
154
- var root = context.getSourceCode().ast.body;
155
- var importDeclarations = ast.Root.findImportsByModule(root, module);
156
-
157
- // The import doesn't exist yet, we can just insert a whole new one
158
- if (importDeclarations.length === 0) {
159
- return ast.Root.insertImport(root, {
160
- module: module,
161
- specifiers: specifiers
162
- }, fixer);
163
- }
164
-
165
- // The import exists so, modify the existing one
166
- return ast.Import.insertNamedSpecifiers(importDeclarations[0], specifiers, fixer);
167
124
  }
168
125
  };
@@ -3,50 +3,8 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.styles = exports.elements = exports.attributes = void 0;
6
+ exports.elements = exports.attributes = void 0;
7
7
  var elements = exports.elements = ['div'];
8
8
  var attributes = exports.attributes = ['css'
9
9
  // 'data-testid'
10
- ];
11
-
12
- // TODO: https://product-fabric.atlassian.net/browse/DSP-16054
13
- var spaceTokenMap = {
14
- '0px': 'space.0',
15
- '2px': 'space.025',
16
- '4px': 'space.050',
17
- '6px': 'space.075',
18
- '8px': 'space.100',
19
- '12px': 'space.150',
20
- '16px': 'space.200',
21
- '20px': 'space.250',
22
- '24px': 'space.300',
23
- '32px': 'space.400',
24
- '40px': 'space.500',
25
- '48px': 'space.600',
26
- '64px': 'space.800',
27
- '80px': 'space.1000'
28
- };
29
- var styles = exports.styles = {
30
- padding: spaceTokenMap,
31
- paddingBlock: spaceTokenMap,
32
- paddingBlockEnd: spaceTokenMap,
33
- paddingBlockStart: spaceTokenMap,
34
- paddingBottom: spaceTokenMap,
35
- paddingInline: spaceTokenMap,
36
- paddingInlineEnd: spaceTokenMap,
37
- paddingInlineStart: spaceTokenMap,
38
- paddingLeft: spaceTokenMap,
39
- paddingRight: spaceTokenMap,
40
- paddingTop: spaceTokenMap,
41
- margin: spaceTokenMap,
42
- marginBlock: spaceTokenMap,
43
- marginBlockEnd: spaceTokenMap,
44
- marginBlockStart: spaceTokenMap,
45
- marginBottom: spaceTokenMap,
46
- marginInline: spaceTokenMap,
47
- marginInlineEnd: spaceTokenMap,
48
- marginInlineStart: spaceTokenMap,
49
- marginLeft: spaceTokenMap,
50
- marginRight: spaceTokenMap,
51
- marginTop: spaceTokenMap
52
- };
10
+ ];
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+
3
+ var _typeof = require("@babel/runtime/helpers/typeof");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.upsertImportDeclaration = void 0;
8
+ var ast = _interopRequireWildcard(require("../../../../ast-nodes"));
9
+ 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); }
10
+ 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; }
11
+ /**
12
+ * Currently this is defined here because it's not very general purpose.
13
+ * If we were to move this to `ast-nodes`, half the implementation would be in `Root`,
14
+ * and the other half would be in `Import`.
15
+ *
16
+ * TODO: Refactor and move to `ast-nodes`
17
+ *
18
+ * Note: It does not handle default imports, namespace imports, or aliased imports.
19
+ */
20
+ var upsertImportDeclaration = exports.upsertImportDeclaration = function upsertImportDeclaration(_ref, context, fixer) {
21
+ var module = _ref.module,
22
+ specifiers = _ref.specifiers;
23
+ // Find any imports that match the packageName
24
+ var root = context.getSourceCode().ast.body;
25
+ var importDeclarations = ast.Root.findImportsByModule(root, module);
26
+
27
+ // The import doesn't exist yet, we can just insert a whole new one
28
+ if (importDeclarations.length === 0) {
29
+ return ast.Root.insertImport(root, {
30
+ module: module,
31
+ specifiers: specifiers
32
+ }, fixer);
33
+ }
34
+
35
+ // The import exists so, modify the existing one
36
+ return ast.Import.insertNamedSpecifiers(importDeclarations[0], specifiers, fixer);
37
+ };
@@ -3,28 +3,28 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- Object.defineProperty(exports, "cssToXcssTransformer", {
6
+ Object.defineProperty(exports, "CompiledStyled", {
7
7
  enumerable: true,
8
8
  get: function get() {
9
- return _cssToXcss.cssToXcssTransformer;
9
+ return _compiledStyled.CompiledStyled;
10
10
  }
11
11
  });
12
- Object.defineProperty(exports, "jsxElementToBoxTransformer", {
12
+ Object.defineProperty(exports, "EmotionCSS", {
13
13
  enumerable: true,
14
14
  get: function get() {
15
- return _jsxElementToBox.jsxElementToBoxTransformer;
15
+ return _emotionCss.EmotionCSS;
16
16
  }
17
17
  });
18
- Object.defineProperty(exports, "spaceTokenMap", {
18
+ Object.defineProperty(exports, "cssToXcssTransformer", {
19
19
  enumerable: true,
20
20
  get: function get() {
21
- return _cssToXcss.spaceTokenMap;
21
+ return _cssToXcss.cssToXcssTransformer;
22
22
  }
23
23
  });
24
- Object.defineProperty(exports, "styledComponentToPrimitive", {
24
+ Object.defineProperty(exports, "spaceTokenMap", {
25
25
  enumerable: true,
26
26
  get: function get() {
27
- return _styledComponentToPrimitive.styledComponentToPrimitive;
27
+ return _cssToXcss.spaceTokenMap;
28
28
  }
29
29
  });
30
30
  Object.defineProperty(exports, "supportedStylesMap", {
@@ -34,5 +34,5 @@ Object.defineProperty(exports, "supportedStylesMap", {
34
34
  }
35
35
  });
36
36
  var _cssToXcss = require("./css-to-xcss");
37
- var _jsxElementToBox = require("./jsx-element-to-box");
38
- var _styledComponentToPrimitive = require("./styled-component-to-primitive");
37
+ var _compiledStyled = require("./compiled-styled");
38
+ var _emotionCss = require("./emotion-css");
@@ -3,30 +3,12 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- Object.defineProperty(exports, "containsOnlySupportedAttrs", {
7
- enumerable: true,
8
- get: function get() {
9
- return _containsOnlySupportedAttrs.containsOnlySupportedAttrs;
10
- }
11
- });
12
6
  Object.defineProperty(exports, "convertASTObjectExpressionToJSObject", {
13
7
  enumerable: true,
14
8
  get: function get() {
15
9
  return _convertAstObjectExpressionToJsObject.convertASTObjectExpressionToJSObject;
16
10
  }
17
11
  });
18
- Object.defineProperty(exports, "findValidJsxUsageToTransform", {
19
- enumerable: true,
20
- get: function get() {
21
- return _findValidJsxUsageToTransform.findValidJsxUsageToTransform;
22
- }
23
- });
24
- Object.defineProperty(exports, "findValidStyledComponentCall", {
25
- enumerable: true,
26
- get: function get() {
27
- return _findValidStyledComponentCall.findValidStyledComponentCall;
28
- }
29
- });
30
12
  Object.defineProperty(exports, "getAttributeValueIdentifier", {
31
13
  enumerable: true,
32
14
  get: function get() {
@@ -69,34 +51,13 @@ Object.defineProperty(exports, "isValidCssPropertiesToTransform", {
69
51
  return _isValidCssPropertiesToTransform.isValidCssPropertiesToTransform;
70
52
  }
71
53
  });
72
- Object.defineProperty(exports, "isValidTagName", {
73
- enumerable: true,
74
- get: function get() {
75
- return _isValidTagName.isValidTagName;
76
- }
77
- });
78
54
  Object.defineProperty(exports, "updateJSXAttributeByName", {
79
55
  enumerable: true,
80
56
  get: function get() {
81
57
  return _updateJsxAttributeByName.updateJSXAttributeByName;
82
58
  }
83
59
  });
84
- Object.defineProperty(exports, "updateJSXElementName", {
85
- enumerable: true,
86
- get: function get() {
87
- return _updateJsxElementName.updateJSXElementName;
88
- }
89
- });
90
- Object.defineProperty(exports, "upsertImportDeclaration", {
91
- enumerable: true,
92
- get: function get() {
93
- return _upsertImportDeclaration.upsertImportDeclaration;
94
- }
95
- });
96
- var _containsOnlySupportedAttrs = require("./contains-only-supported-attrs");
97
60
  var _convertAstObjectExpressionToJsObject = require("./convert-ast-object-expression-to-js-object");
98
- var _findValidJsxUsageToTransform = require("./find-valid-jsx-usage-to-transform");
99
- var _findValidStyledComponentCall = require("./find-valid-styled-component-call");
100
61
  var _getAttributeValueIdentifier = require("./get-attribute-value-identifier");
101
62
  var _getFunctionArgumentAtPos = require("./get-function-argument-at-pos");
102
63
  var _getJsxAttributeByName = require("./get-jsx-attribute-by-name");
@@ -104,7 +65,4 @@ var _getVariableDefinitionValue = require("./get-variable-definition-value");
104
65
  var _getVariableUsageCount = require("./get-variable-usage-count");
105
66
  var _isFunctionNamed = require("./is-function-named");
106
67
  var _isValidCssPropertiesToTransform = require("./is-valid-css-properties-to-transform");
107
- var _isValidTagName = require("./is-valid-tag-name");
108
- var _updateJsxAttributeByName = require("./update-jsx-attribute-by-name");
109
- var _updateJsxElementName = require("./update-jsx-element-name");
110
- var _upsertImportDeclaration = require("./upsert-import-declaration");
68
+ var _updateJsxAttributeByName = require("./update-jsx-attribute-by-name");
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.isCxFunction = exports.isCss = exports.CSS_IN_JS_IMPORTS = void 0;
7
+ // eslint-disable-next-line import/no-extraneous-dependencies
8
+
9
+ var CSS_IN_JS_IMPORTS = exports.CSS_IN_JS_IMPORTS = {
10
+ compiled: '@compiled/react',
11
+ emotionReact: '@emotion/react',
12
+ emotionCore: '@emotion/core',
13
+ styledComponents: 'styled-components',
14
+ atlaskitCss: '@atlaskit/css'
15
+ };
16
+
17
+ // List of CSS-in-JS libraries an import of a valid css, cx, cssMap, etc.
18
+ // function might originate from, e.g. @compiled/react, @emotion/core.
19
+
20
+ var isSupportedImportWrapper = function isSupportedImportWrapper(functionName) {
21
+ // This will need to be extended to support default imports once we start
22
+ // checking cases like `import css from '@emotion/css'`
23
+ var checkDefinitionHasImport = function checkDefinitionHasImport(def, importSources) {
24
+ var _def$parent, _def$parent2;
25
+ return def.node.type === 'ImportSpecifier' && def.node.imported.type === 'Identifier' && def.node.imported.name === functionName && ((_def$parent = def.parent) === null || _def$parent === void 0 ? void 0 : _def$parent.type) === 'ImportDeclaration' && importSources.includes((_def$parent2 = def.parent) === null || _def$parent2 === void 0 ? void 0 : _def$parent2.source.value);
26
+ };
27
+
28
+ /**
29
+ * Checks whether:
30
+ *
31
+ * 1. a function name `nodeToCheck` matches the name of the function we
32
+ * want to check for (e.g. `cx`, `css`, `cssMap`, or `keyframes`), and
33
+ * 2. whether `nodeToCheck` originates from one of the libraries listed
34
+ * in `importSources`.
35
+ *
36
+ * @param nodeToCheck the function callee we are checking (e.g. the `css` in `css()`)
37
+ * @param referencesInScope list of references that are in scope. We'll use this
38
+ * to check where the function callee is imported from.
39
+ * @param importSources list of libraries that we want to ensure `nodeToCheck`
40
+ * comes from
41
+ *
42
+ * @returns whether the above conditions are true
43
+ */
44
+ var isSupportedImport = function isSupportedImport(nodeToCheck, referencesInScope, importSources) {
45
+ return nodeToCheck.type === 'Identifier' && referencesInScope.some(function (reference) {
46
+ var _reference$resolved;
47
+ return reference.identifier === nodeToCheck && ((_reference$resolved = reference.resolved) === null || _reference$resolved === void 0 ? void 0 : _reference$resolved.defs.some(function (def) {
48
+ return checkDefinitionHasImport(def, importSources);
49
+ }));
50
+ });
51
+ };
52
+ return isSupportedImport;
53
+ };
54
+
55
+ // Unused functions have been commented out until we implement corresponding
56
+ // eslint rules which use them
57
+ //
58
+ var isCss = exports.isCss = isSupportedImportWrapper('css');
59
+ var isCxFunction = exports.isCxFunction = isSupportedImportWrapper('cx');
60
+ // export const isCssMap = isLibraryImportWrapper('cssMap');
61
+ // export const isKeyframes = isLibraryImportWrapper('keyframes');
@@ -2,4 +2,5 @@ export { FunctionCall } from './function-call';
2
2
  export { Import } from './import';
3
3
  export { JSXAttribute } from './jsx-attribute';
4
4
  export { JSXElement } from './jsx-element';
5
+ export { Object } from './object';
5
6
  export { Root } from './root';
@@ -0,0 +1,79 @@
1
+ /* eslint-disable @repo/internal/react/require-jsdoc */
2
+
3
+ import { identifier, isNodeOfType, literal, property } from 'eslint-codemod-utils';
4
+ const ASTObjectExpression = {
5
+ /**
6
+ * Returns `true` if an object contains a property with the specified name, `false` otherwise.
7
+ */
8
+ hasProperty(node, name) {
9
+ return !!ASTObjectExpression.getProperty(node, name);
10
+ },
11
+ /**
12
+ * Returns a key-value pair like: `padding: '8px'` from: `{ padding: '8px' }`
13
+ */
14
+ getEntryByPropertyName(node, name) {
15
+ return node.properties.find(property => {
16
+ if (!isNodeOfType(property, 'Property')) {
17
+ return false;
18
+ }
19
+ if (!isNodeOfType(property.key, 'Identifier')) {
20
+ return false;
21
+ }
22
+ return property.key.name === name;
23
+ });
24
+ },
25
+ deleteEntry(node, name, fixer) {
26
+ const entry = ASTObjectExpression.getEntryByPropertyName(node, name);
27
+ if (!entry) {
28
+ return [];
29
+ }
30
+ return [fixer.remove(entry)];
31
+ },
32
+ /**
33
+ * Returns a only the property @type {Property['key']} like: `padding` from: `{ padding: '8px' }`
34
+ */
35
+ getProperty(node, name) {
36
+ var _ASTObjectExpression$;
37
+ return (_ASTObjectExpression$ = ASTObjectExpression.getEntryByPropertyName(node, name)) === null || _ASTObjectExpression$ === void 0 ? void 0 : _ASTObjectExpression$.key;
38
+ },
39
+ /**
40
+ * Returns a only the property @type {Property['value']} like: `'8px` from: `{ padding: '8px' }`
41
+ *
42
+ * Values can be basically anything, so be careful with this
43
+ */
44
+ getValueByPropertyName(node, name) {
45
+ var _ASTObjectExpression$2;
46
+ return (_ASTObjectExpression$2 = ASTObjectExpression.getEntryByPropertyName(node, name)) === null || _ASTObjectExpression$2 === void 0 ? void 0 : _ASTObjectExpression$2.value;
47
+ },
48
+ containsSpreadProps(node) {
49
+ return node.properties.some(property => {
50
+ return isNodeOfType(property, 'SpreadElement');
51
+ });
52
+ },
53
+ updateValue(node, propertyName, newValue, fixer) {
54
+ const value = ASTObjectExpression.getValueByPropertyName(node, propertyName);
55
+ if (value === undefined) {
56
+ throw new Error(`Object.updateValue: Could not get value of property ${propertyName}`);
57
+ }
58
+ return fixer.replaceText(value, newValue);
59
+ },
60
+ /**
61
+ * Appends a key-value pair to the end of an object. For example:
62
+ * ```
63
+ * ast.Object.appendEntry(
64
+ * node, // { padding: 'space.100' }
65
+ * key, // 'margin',
66
+ * value, // 'space.200'
67
+ * fixer,
68
+ * )
69
+ * ```
70
+ * Will result in `{ padding: 'space.100', margin: 'space.200'}`
71
+ */
72
+ appendEntry(node, key, value, fixer) {
73
+ return fixer.insertTextAfter(node.properties[node.properties.length - 1], `${property({
74
+ key: identifier(key),
75
+ value: literal(value)
76
+ }).toString()}, `);
77
+ }
78
+ };
79
+ export { ASTObjectExpression as Object };
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
3
- * @codegen <<SignedSource::d1a459e1ea71650f65b2890dc86cc398>>
3
+ * @codegen <<SignedSource::5026ba2cb55b3c1bcacbfe7fb7728a6c>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
5
5
  */
6
6
  export default {
@@ -10,6 +10,7 @@ export default {
10
10
  '@atlaskit/design-system/ensure-design-token-usage': 'error',
11
11
  '@atlaskit/design-system/ensure-design-token-usage/preview': 'warn',
12
12
  '@atlaskit/design-system/icon-label': 'warn',
13
+ '@atlaskit/design-system/local-cx-xcss': 'error',
13
14
  '@atlaskit/design-system/no-banned-imports': 'error',
14
15
  '@atlaskit/design-system/no-css-tagged-template-expression': 'error',
15
16
  '@atlaskit/design-system/no-deprecated-apis': 'error',