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

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 (58) hide show
  1. package/CHANGELOG.md +12 -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/ensure-design-token-usage/error-boundary.js +24 -0
  9. package/dist/cjs/rules/ensure-design-token-usage/index.js +208 -177
  10. package/dist/cjs/rules/use-primitives/index.js +6 -76
  11. package/dist/cjs/rules/use-primitives/transformers/emotion-css/index.js +168 -0
  12. package/dist/cjs/rules/use-primitives/transformers/emotion-css/supported.js +52 -0
  13. package/dist/cjs/rules/use-primitives/utils/is-valid-css-properties-to-transform.js +3 -0
  14. package/dist/es2019/ast-nodes/function-call.js +42 -0
  15. package/dist/es2019/ast-nodes/import.js +42 -0
  16. package/dist/es2019/ast-nodes/index.js +5 -0
  17. package/dist/es2019/ast-nodes/jsx-attribute.js +59 -0
  18. package/dist/es2019/ast-nodes/jsx-element.js +50 -0
  19. package/dist/es2019/ast-nodes/root.js +28 -0
  20. package/dist/es2019/rules/ensure-design-token-usage/error-boundary.js +19 -0
  21. package/dist/es2019/rules/ensure-design-token-usage/index.js +33 -16
  22. package/dist/es2019/rules/use-primitives/index.js +9 -79
  23. package/dist/es2019/rules/use-primitives/transformers/emotion-css/index.js +159 -0
  24. package/dist/es2019/rules/use-primitives/transformers/emotion-css/supported.js +46 -0
  25. package/dist/es2019/rules/use-primitives/utils/is-valid-css-properties-to-transform.js +3 -0
  26. package/dist/esm/ast-nodes/function-call.js +42 -0
  27. package/dist/esm/ast-nodes/import.js +43 -0
  28. package/dist/esm/ast-nodes/index.js +5 -0
  29. package/dist/esm/ast-nodes/jsx-attribute.js +59 -0
  30. package/dist/esm/ast-nodes/jsx-element.js +50 -0
  31. package/dist/esm/ast-nodes/root.js +28 -0
  32. package/dist/esm/rules/ensure-design-token-usage/error-boundary.js +18 -0
  33. package/dist/esm/rules/ensure-design-token-usage/index.js +208 -177
  34. package/dist/esm/rules/use-primitives/index.js +9 -79
  35. package/dist/esm/rules/use-primitives/transformers/emotion-css/index.js +158 -0
  36. package/dist/esm/rules/use-primitives/transformers/emotion-css/supported.js +46 -0
  37. package/dist/esm/rules/use-primitives/utils/is-valid-css-properties-to-transform.js +3 -0
  38. package/dist/types/ast-nodes/function-call.d.ts +21 -0
  39. package/dist/types/ast-nodes/import.d.ts +16 -0
  40. package/dist/types/ast-nodes/index.d.ts +5 -0
  41. package/dist/types/ast-nodes/jsx-attribute.d.ts +26 -0
  42. package/dist/types/ast-nodes/jsx-element.d.ts +21 -0
  43. package/dist/types/ast-nodes/root.d.ts +19 -0
  44. package/dist/types/rules/ensure-design-token-usage/error-boundary.d.ts +11 -0
  45. package/dist/types/rules/ensure-design-token-usage/types.d.ts +1 -0
  46. package/dist/types/rules/use-primitives/transformers/emotion-css/index.d.ts +35 -0
  47. package/dist/types/rules/use-primitives/transformers/emotion-css/supported.d.ts +9 -0
  48. package/dist/types-ts4.5/ast-nodes/function-call.d.ts +21 -0
  49. package/dist/types-ts4.5/ast-nodes/import.d.ts +16 -0
  50. package/dist/types-ts4.5/ast-nodes/index.d.ts +5 -0
  51. package/dist/types-ts4.5/ast-nodes/jsx-attribute.d.ts +26 -0
  52. package/dist/types-ts4.5/ast-nodes/jsx-element.d.ts +21 -0
  53. package/dist/types-ts4.5/ast-nodes/root.d.ts +19 -0
  54. package/dist/types-ts4.5/rules/ensure-design-token-usage/error-boundary.d.ts +11 -0
  55. package/dist/types-ts4.5/rules/ensure-design-token-usage/types.d.ts +1 -0
  56. package/dist/types-ts4.5/rules/use-primitives/transformers/emotion-css/index.d.ts +35 -0
  57. package/dist/types-ts4.5/rules/use-primitives/transformers/emotion-css/supported.d.ts +9 -0
  58. package/package.json +1 -1
@@ -11,6 +11,7 @@ var _createRule = require("../utils/create-rule");
11
11
  var _isColor = require("../utils/is-color");
12
12
  var _isNode = require("../utils/is-node");
13
13
  var _color = require("./color");
14
+ var _errorBoundary = require("./error-boundary");
14
15
  var _ruleMeta = _interopRequireDefault(require("./rule-meta"));
15
16
  var _spacing = require("./spacing");
16
17
  var _utils = require("./utils");
@@ -19,7 +20,8 @@ var _utils = require("./utils");
19
20
  var defaultConfig = {
20
21
  domains: ['color', 'spacing'],
21
22
  applyImport: true,
22
- shouldEnforceFallbacks: false
23
+ shouldEnforceFallbacks: false,
24
+ failSilently: false
23
25
  };
24
26
  var createWithConfig = exports.createWithConfig = function createWithConfig(initialConfig) {
25
27
  return function (context) {
@@ -29,18 +31,27 @@ var createWithConfig = exports.createWithConfig = function createWithConfig(init
29
31
  domains: (userConfig === null || userConfig === void 0 ? void 0 : userConfig.domains) || initialConfig.domains,
30
32
  applyImport: (userConfig === null || userConfig === void 0 ? void 0 : userConfig.applyImport) !== undefined ? userConfig.applyImport : initialConfig.applyImport,
31
33
  shouldEnforceFallbacks: (userConfig === null || userConfig === void 0 ? void 0 : userConfig.shouldEnforceFallbacks) !== undefined ? userConfig.shouldEnforceFallbacks : initialConfig.shouldEnforceFallbacks,
32
- exceptions: (userConfig === null || userConfig === void 0 ? void 0 : userConfig.exceptions) || []
34
+ exceptions: (userConfig === null || userConfig === void 0 ? void 0 : userConfig.exceptions) || [],
35
+ failSilently: (userConfig === null || userConfig === void 0 ? void 0 : userConfig.failSilently) || defaultConfig.failSilently
33
36
  };
34
37
  var tokenNode = null;
35
38
  return {
36
39
  ImportDeclaration: function ImportDeclaration(node) {
37
- if (node.source.value === '@atlaskit/tokens' && config.applyImport) {
38
- tokenNode = node;
39
- }
40
+ return (0, _errorBoundary.errorBoundary)(function () {
41
+ if (node.source.value === '@atlaskit/tokens' && config.applyImport) {
42
+ tokenNode = node;
43
+ }
44
+ }, {
45
+ config: config
46
+ });
40
47
  },
41
48
  // For expressions within template literals (e.g. `color: ${red}`) - color only
42
49
  'TemplateLiteral > Identifier': function TemplateLiteralIdentifier(node) {
43
- return (0, _color.lintTemplateIdentifierForColor)(node, context, config);
50
+ return (0, _errorBoundary.errorBoundary)(function () {
51
+ return (0, _color.lintTemplateIdentifierForColor)(node, context, config);
52
+ }, {
53
+ config: config
54
+ });
44
55
  },
45
56
  // const styles = css({ color: 'red', margin: '4px' }), styled.div({ color: 'red', margin: '4px' })
46
57
  ObjectExpression: function (_ObjectExpression) {
@@ -52,220 +63,240 @@ var createWithConfig = exports.createWithConfig = function createWithConfig(init
52
63
  };
53
64
  return ObjectExpression;
54
65
  }(function (parentNode) {
55
- // To force the correct node type
56
- if (!(0, _eslintCodemodUtils.isNodeOfType)(parentNode, 'ObjectExpression')) {
57
- return;
58
- }
59
-
60
- // Return for nested objects - these get handled automatically so without returning we'd be doubling up
61
- if (parentNode.parent.type === 'Property') {
62
- return;
63
- }
64
- if (!(0, _isNode.isDecendantOfStyleBlock)(parentNode) && !(0, _isNode.isDecendantOfType)(parentNode, 'JSXExpressionContainer')) {
65
- return;
66
- }
67
- function findObjectStyles(node) {
68
- if (!(0, _eslintCodemodUtils.isNodeOfType)(node, 'Property')) {
66
+ return (0, _errorBoundary.errorBoundary)(function () {
67
+ // To force the correct node type
68
+ if (!(0, _eslintCodemodUtils.isNodeOfType)(parentNode, 'ObjectExpression')) {
69
69
  return;
70
70
  }
71
- if ((0, _eslintCodemodUtils.isNodeOfType)(node.value, 'ObjectExpression')) {
72
- return node.value.properties.forEach(findObjectStyles);
73
- }
74
- if (!(0, _eslintCodemodUtils.isNodeOfType)(node.key, 'Identifier') && !(0, _eslintCodemodUtils.isNodeOfType)(node.key, 'Literal')) {
71
+
72
+ // Return for nested objects - these get handled automatically so without returning we'd be doubling up
73
+ if (parentNode.parent.type === 'Property') {
75
74
  return;
76
75
  }
77
- var propertyName = (0, _eslintCodemodUtils.isNodeOfType)(node.key, 'Identifier') ? node.key.name : String(node.key.value);
78
-
79
- // Returns which domains to lint against based on rule's config and current property
80
- var domains = (0, _utils.getDomainsForProperty)(propertyName, config.domains);
81
- if (domains.length === 0 || (0, _isNode.isDecendantOfGlobalToken)(node.value)) {
76
+ if (!(0, _isNode.isDecendantOfStyleBlock)(parentNode) && !(0, _isNode.isDecendantOfType)(parentNode, 'JSXExpressionContainer')) {
82
77
  return;
83
78
  }
84
- if ((0, _eslintCodemodUtils.isNodeOfType)(node.value, 'TemplateLiteral')) {
85
- var value = (0, _utils.getValueFromTemplateLiteralRaw)(node.value, context);
86
- if (Array.isArray(value) && value.some(_utils.isCalc)) {
87
- return context.report({
88
- node: node,
89
- messageId: 'noCalcUsage',
90
- data: {
91
- payload: "".concat(propertyName)
92
- }
93
- });
79
+ function findObjectStyles(node) {
80
+ if (!(0, _eslintCodemodUtils.isNodeOfType)(node, 'Property')) {
81
+ return;
94
82
  }
95
- if (node.value.expressions.some(_isNode.isDecendantOfGlobalToken)) {
83
+ if ((0, _eslintCodemodUtils.isNodeOfType)(node.value, 'ObjectExpression')) {
84
+ return node.value.properties.forEach(findObjectStyles);
85
+ }
86
+ if (!(0, _eslintCodemodUtils.isNodeOfType)(node.key, 'Identifier') && !(0, _eslintCodemodUtils.isNodeOfType)(node.key, 'Literal')) {
96
87
  return;
97
88
  }
89
+ var propertyName = (0, _eslintCodemodUtils.isNodeOfType)(node.key, 'Identifier') ? node.key.name : String(node.key.value);
90
+
91
+ // Returns which domains to lint against based on rule's config and current property
92
+ var domains = (0, _utils.getDomainsForProperty)(propertyName, config.domains);
93
+ if (domains.length === 0 || (0, _isNode.isDecendantOfGlobalToken)(node.value)) {
94
+ return;
95
+ }
96
+ if ((0, _eslintCodemodUtils.isNodeOfType)(node.value, 'TemplateLiteral')) {
97
+ var value = (0, _utils.getValueFromTemplateLiteralRaw)(node.value, context);
98
+ if (Array.isArray(value) && value.some(_utils.isCalc)) {
99
+ return context.report({
100
+ node: node,
101
+ messageId: 'noCalcUsage',
102
+ data: {
103
+ payload: "".concat(propertyName)
104
+ }
105
+ });
106
+ }
107
+ if (node.value.expressions.some(_isNode.isDecendantOfGlobalToken)) {
108
+ return;
109
+ }
110
+ }
111
+ if (domains.includes('color')) {
112
+ return (0, _color.lintObjectForColor)(node, context, config);
113
+ }
114
+ if (domains.includes('spacing') || domains.includes('shape') || domains.includes('typography')) {
115
+ /**
116
+ * We do this in case the fontSize for a style object is declared alongside the `em` or `lineHeight` declaration
117
+ */
118
+ var fontSize = (0, _utils.getFontSizeFromNode)(parentNode, context);
119
+ return (0, _spacing.lintObjectForSpacing)(node, context, config, fontSize, tokenNode);
120
+ }
98
121
  }
99
- if (domains.includes('color')) {
100
- return (0, _color.lintObjectForColor)(node, context, config);
101
- }
102
- if (domains.includes('spacing') || domains.includes('shape') || domains.includes('typography')) {
103
- /**
104
- * We do this in case the fontSize for a style object is declared alongside the `em` or `lineHeight` declaration
105
- */
106
- var fontSize = (0, _utils.getFontSizeFromNode)(parentNode, context);
107
- return (0, _spacing.lintObjectForSpacing)(node, context, config, fontSize, tokenNode);
108
- }
109
- }
110
- parentNode.properties.forEach(findObjectStyles);
122
+ parentNode.properties.forEach(findObjectStyles);
123
+ }, {
124
+ config: config
125
+ });
111
126
  }),
112
127
  // CSSTemplateLiteral and StyledTemplateLiteral
113
128
  // const cssTemplateLiteral = css`color: red; padding: 12px`;
114
129
  // const styledTemplateLiteral = styled.p`color: red; padding: 8px`;
115
130
  'TaggedTemplateExpression[tag.name="css"],TaggedTemplateExpression[tag.object.name="styled"],TaggedTemplateExpression[tag.callee.name="styled"]': function TaggedTemplateExpressionTagNameCssTaggedTemplateExpressionTagObjectNameStyledTaggedTemplateExpressionTagCalleeNameStyled(node) {
116
- // To force the correct node type
117
- if (!(0, _eslintCodemodUtils.isNodeOfType)(node, 'TaggedTemplateExpression')) {
118
- return;
119
- }
120
- var processedCssLines = (0, _utils.processCssNode)(node, context);
121
- if (!processedCssLines) {
122
- // if we can't get a processed css we bail
123
- return;
124
- }
125
- var globalFontSize = (0, _utils.getFontSizeValueInScope)(processedCssLines);
126
- var textForSource = context.getSourceCode().getText(node.quasi);
127
- var allReplacedValues = [];
128
- var completeSource = processedCssLines.reduce(function (currentSource, _ref) {
129
- var _ref2 = (0, _slicedToArray2.default)(_ref, 2),
130
- resolvedCssLine = _ref2[0],
131
- originalCssLine = _ref2[1];
132
- var _resolvedCssLine$spli = resolvedCssLine.split(':'),
133
- _resolvedCssLine$spli2 = (0, _slicedToArray2.default)(_resolvedCssLine$spli, 2),
134
- originalProperty = _resolvedCssLine$spli2[0],
135
- resolvedCssValues = _resolvedCssLine$spli2[1];
136
- var _originalCssLine$spli = originalCssLine.split(':'),
137
- _originalCssLine$spli2 = (0, _slicedToArray2.default)(_originalCssLine$spli, 2),
138
- _ = _originalCssLine$spli2[0],
139
- originalCssValues = _originalCssLine$spli2[1];
140
- var propertyName = (0, _utils.convertHyphenatedNameToCamelCase)(originalProperty);
141
- var isFontFamily = /fontFamily/.test(propertyName);
142
- var replacedValuesPerProperty = [originalProperty];
143
- var domains = (0, _utils.getDomainsForProperty)(propertyName, config.domains);
144
- if (domains.length === 0 || !resolvedCssValues) {
145
- // in both of these cases no changes should be made to the current property
146
- return currentSource;
131
+ return (0, _errorBoundary.errorBoundary)(function () {
132
+ // To force the correct node type
133
+ if (!(0, _eslintCodemodUtils.isNodeOfType)(node, 'TaggedTemplateExpression')) {
134
+ return;
147
135
  }
148
- if (domains.includes('color')) {
149
- if ((0, _utils.includesTokenString)(resolvedCssValues.trim())) {
150
- return currentSource;
151
- }
152
- if ((0, _isColor.includesHardCodedColor)(resolvedCssValues)) {
153
- context.report({
154
- messageId: 'hardCodedColor',
155
- node: node
156
- });
157
- return currentSource;
158
- }
136
+ var processedCssLines = (0, _utils.processCssNode)(node, context);
137
+ if (!processedCssLines) {
138
+ // if we can't get a processed css we bail
139
+ return;
159
140
  }
160
- if (domains.includes('spacing') || domains.includes('typography') || domains.includes('shape')) {
161
- if (!(0, _utils.isValidSpacingValue)(resolvedCssValues, globalFontSize)) {
162
- // no changes should be made to the current property
141
+ var globalFontSize = (0, _utils.getFontSizeValueInScope)(processedCssLines);
142
+ var textForSource = context.getSourceCode().getText(node.quasi);
143
+ var allReplacedValues = [];
144
+ var completeSource = processedCssLines.reduce(function (currentSource, _ref) {
145
+ var _ref2 = (0, _slicedToArray2.default)(_ref, 2),
146
+ resolvedCssLine = _ref2[0],
147
+ originalCssLine = _ref2[1];
148
+ var _resolvedCssLine$spli = resolvedCssLine.split(':'),
149
+ _resolvedCssLine$spli2 = (0, _slicedToArray2.default)(_resolvedCssLine$spli, 2),
150
+ originalProperty = _resolvedCssLine$spli2[0],
151
+ resolvedCssValues = _resolvedCssLine$spli2[1];
152
+ var _originalCssLine$spli = originalCssLine.split(':'),
153
+ _originalCssLine$spli2 = (0, _slicedToArray2.default)(_originalCssLine$spli, 2),
154
+ _ = _originalCssLine$spli2[0],
155
+ originalCssValues = _originalCssLine$spli2[1];
156
+ var propertyName = (0, _utils.convertHyphenatedNameToCamelCase)(originalProperty);
157
+ var isFontFamily = /fontFamily/.test(propertyName);
158
+ var replacedValuesPerProperty = [originalProperty];
159
+ var domains = (0, _utils.getDomainsForProperty)(propertyName, config.domains);
160
+ if (domains.length === 0 || !resolvedCssValues) {
161
+ // in both of these cases no changes should be made to the current property
163
162
  return currentSource;
164
163
  }
164
+ if (domains.includes('color')) {
165
+ if ((0, _utils.includesTokenString)(resolvedCssValues.trim())) {
166
+ return currentSource;
167
+ }
168
+ if ((0, _isColor.includesHardCodedColor)(resolvedCssValues)) {
169
+ context.report({
170
+ messageId: 'hardCodedColor',
171
+ node: node
172
+ });
173
+ return currentSource;
174
+ }
175
+ }
176
+ if (domains.includes('spacing') || domains.includes('typography') || domains.includes('shape')) {
177
+ if (!(0, _utils.isValidSpacingValue)(resolvedCssValues, globalFontSize)) {
178
+ // no changes should be made to the current property
179
+ return currentSource;
180
+ }
165
181
 
166
- // gets the values from the associated property, numeric values or NaN
167
- var processedNumericValues = (0, _utils.getValueFromShorthand)(resolvedCssValues);
168
- var processedValues = (0, _utils.splitShorthandValues)(resolvedCssValues);
169
- // only splits shorthand values but it does not transform NaNs so tokens are preserved
170
- var originalValues = (0, _utils.splitShorthandValues)(originalCssValues);
182
+ // gets the values from the associated property, numeric values or NaN
183
+ var processedNumericValues = (0, _utils.getValueFromShorthand)(resolvedCssValues);
184
+ var processedValues = (0, _utils.splitShorthandValues)(resolvedCssValues);
185
+ // only splits shorthand values but it does not transform NaNs so tokens are preserved
186
+ var originalValues = (0, _utils.splitShorthandValues)(originalCssValues);
171
187
 
172
- // reconstructing the string
173
- // should replace what it can and preserve the raw value for everything else
188
+ // reconstructing the string
189
+ // should replace what it can and preserve the raw value for everything else
174
190
 
175
- var replacementValue = processedNumericValues
176
- // put together resolved value and original value on a tuple
177
- .map(function (value, index) {
178
- return [
179
- // if emToPX conversion fails we'll default to original value
180
- (0, _utils.emToPixels)(value, globalFontSize) || value, processedValues[index], originalValues[index]];
181
- }).map(function (_ref3) {
182
- var _ref4 = (0, _slicedToArray2.default)(_ref3, 3),
183
- numericOrNanValue = _ref4[0],
184
- pxValue = _ref4[1],
185
- originalValue = _ref4[2];
186
- if (!originalValue) {
187
- return originalValue;
188
- }
189
- if ((0, _utils.isCalc)(originalValue)) {
191
+ var replacementValue = processedNumericValues
192
+ // put together resolved value and original value on a tuple
193
+ .map(function (value, index) {
194
+ return [
195
+ // if emToPX conversion fails we'll default to original value
196
+ (0, _utils.emToPixels)(value, globalFontSize) || value, processedValues[index], originalValues[index]];
197
+ }).map(function (_ref3) {
198
+ var _ref4 = (0, _slicedToArray2.default)(_ref3, 3),
199
+ numericOrNanValue = _ref4[0],
200
+ pxValue = _ref4[1],
201
+ originalValue = _ref4[2];
202
+ if (!originalValue) {
203
+ return originalValue;
204
+ }
205
+ if ((0, _utils.isCalc)(originalValue)) {
206
+ context.report({
207
+ node: node,
208
+ messageId: 'noCalcUsage',
209
+ data: {
210
+ payload: "".concat(propertyName)
211
+ }
212
+ });
213
+ return originalValue;
214
+ }
215
+ if ((0, _utils.isTokenValueString)(originalValue)) {
216
+ // if the value is already valid, nothing to report or replace
217
+ return originalValue;
218
+ }
219
+
220
+ // do not replace 0 or auto with tokens
221
+ if ((0, _utils.isZero)(pxValue) || (0, _utils.isAuto)(pxValue)) {
222
+ return originalValue;
223
+ }
224
+ if (isNaN(numericOrNanValue) && !isFontFamily) {
225
+ // do not report if we have nothing to replace with
226
+ return originalValue;
227
+ }
228
+
229
+ // value is numeric or fontFamily, and needs replacing we'll report first
190
230
  context.report({
191
231
  node: node,
192
- messageId: 'noCalcUsage',
232
+ messageId: 'noRawSpacingValues',
193
233
  data: {
194
- payload: "".concat(propertyName)
234
+ payload: "".concat(propertyName, ":").concat(numericOrNanValue)
195
235
  }
196
236
  });
197
- return originalValue;
198
- }
199
- if ((0, _utils.isTokenValueString)(originalValue)) {
200
- // if the value is already valid, nothing to report or replace
201
- return originalValue;
202
- }
203
-
204
- // do not replace 0 or auto with tokens
205
- if ((0, _utils.isZero)(pxValue) || (0, _utils.isAuto)(pxValue)) {
206
- return originalValue;
207
- }
208
- if (isNaN(numericOrNanValue) && !isFontFamily) {
209
- // do not report if we have nothing to replace with
210
- return originalValue;
211
- }
212
237
 
213
- // value is numeric or fontFamily, and needs replacing we'll report first
214
- context.report({
215
- node: node,
216
- messageId: 'noRawSpacingValues',
217
- data: {
218
- payload: "".concat(propertyName, ":").concat(numericOrNanValue)
238
+ // from here on we know value is numeric or a font family, so it might or might not have a token equivalent
239
+ var replacementNode = (0, _utils.getTokenReplacement)(propertyName, numericOrNanValue);
240
+ if (!replacementNode) {
241
+ return originalValue;
219
242
  }
220
- });
243
+ var replacementToken = '${' + replacementNode.toString() + '}';
244
+ replacedValuesPerProperty.push(isFontFamily ? numericOrNanValue.trim() : pxValue);
245
+ return replacementToken;
246
+ }).join(' ');
247
+ if (replacedValuesPerProperty.length > 1) {
248
+ // first value is the property name, so it will always have at least 1
249
+ allReplacedValues.push(replacedValuesPerProperty);
250
+ }
221
251
 
222
- // from here on we know value is numeric or a font family, so it might or might not have a token equivalent
223
- var replacementNode = (0, _utils.getTokenReplacement)(propertyName, numericOrNanValue);
224
- if (!replacementNode) {
225
- return originalValue;
252
+ // replace property:val with new property:val
253
+ var replacedCssLine = currentSource.replace(originalCssLine, // padding: ${gridSize()}px;
254
+ "".concat(originalProperty, ": ").concat(replacementValue));
255
+ if (!replacedCssLine) {
256
+ return currentSource;
226
257
  }
227
- var replacementToken = '${' + replacementNode.toString() + '}';
228
- replacedValuesPerProperty.push(isFontFamily ? numericOrNanValue.trim() : pxValue);
229
- return replacementToken;
230
- }).join(' ');
231
- if (replacedValuesPerProperty.length > 1) {
232
- // first value is the property name, so it will always have at least 1
233
- allReplacedValues.push(replacedValuesPerProperty);
258
+ return replacedCssLine;
234
259
  }
260
+ return currentSource;
261
+ }, textForSource);
262
+ if (completeSource !== textForSource) {
263
+ // means we found some replacement values, we'll give the option to fix them
235
264
 
236
- // replace property:val with new property:val
237
- var replacedCssLine = currentSource.replace(originalCssLine, // padding: ${gridSize()}px;
238
- "".concat(originalProperty, ": ").concat(replacementValue));
239
- if (!replacedCssLine) {
240
- return currentSource;
241
- }
242
- return replacedCssLine;
265
+ context.report({
266
+ node: node,
267
+ messageId: 'autofixesPossible',
268
+ fix: function fix(fixer) {
269
+ return (!tokenNode && config.applyImport ? [(0, _utils.insertTokensImport)(fixer)] : []).concat([fixer.replaceText(node.quasi, completeSource)]);
270
+ }
271
+ });
243
272
  }
244
- return currentSource;
245
- }, textForSource);
246
- if (completeSource !== textForSource) {
247
- // means we found some replacement values, we'll give the option to fix them
248
-
249
- context.report({
250
- node: node,
251
- messageId: 'autofixesPossible',
252
- fix: function fix(fixer) {
253
- return (!tokenNode && config.applyImport ? [(0, _utils.insertTokensImport)(fixer)] : []).concat([fixer.replaceText(node.quasi, completeSource)]);
254
- }
255
- });
256
- }
273
+ }, {
274
+ config: config
275
+ });
257
276
  },
258
277
  // For inline JSX styles - literals (e.g. <Test color="red"/>) - color only
259
278
  'JSXAttribute > Literal': function JSXAttributeLiteral(node) {
260
- return (0, _color.lintJSXLiteralForColor)(node, context, config);
279
+ return (0, _errorBoundary.errorBoundary)(function () {
280
+ return (0, _color.lintJSXLiteralForColor)(node, context, config);
281
+ }, {
282
+ config: config
283
+ });
261
284
  },
262
285
  // For inline JSX styles - members (e.g. <Test color={color.red}/>) - color only
263
286
  'JSXExpressionContainer > MemberExpression': function JSXExpressionContainerMemberExpression(node) {
264
- return (0, _color.lintJSXMemberForColor)(node, context, config);
287
+ return (0, _errorBoundary.errorBoundary)(function () {
288
+ return (0, _color.lintJSXMemberForColor)(node, context, config);
289
+ }, {
290
+ config: config
291
+ });
265
292
  },
266
293
  // For inline JSX styles - identifiers (e.g. <Test color={red}/>) - color only
267
294
  'JSXExpressionContainer > Identifier': function JSXExpressionContainerIdentifier(node) {
268
- return (0, _color.lintJSXIdentifierForColor)(node, context, config);
295
+ return (0, _errorBoundary.errorBoundary)(function () {
296
+ return (0, _color.lintJSXIdentifierForColor)(node, context, config);
297
+ }, {
298
+ config: config
299
+ });
269
300
  }
270
301
  };
271
302
  };
@@ -8,6 +8,7 @@ var _eslintCodemodUtils = require("eslint-codemod-utils");
8
8
  var _createRule = require("../utils/create-rule");
9
9
  var _config = require("./config");
10
10
  var _transformers = require("./transformers");
11
+ var _emotionCss = require("./transformers/emotion-css");
11
12
  var _utils = require("./utils");
12
13
  var boxDocsUrl = 'https://atlassian.design/components/primitives/box';
13
14
  var rule = (0, _createRule.createLintRule)({
@@ -59,84 +60,13 @@ var rule = (0, _createRule.createLintRule)({
59
60
  });
60
61
  },
61
62
  // 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
- }
63
+ JSXElement: function JSXElement(node) {
64
+ _emotionCss.EmotionCSS.lint(node, {
65
+ context: context,
66
+ config: config
67
+ });
89
68
  }
90
69
  };
91
70
  }
92
71
  });
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
72
  var _default = exports.default = rule;