@atlaskit/eslint-plugin-design-system 10.8.1 → 10.8.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 (38) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/dist/cjs/rules/ensure-design-token-usage/index.js +1 -1
  3. package/dist/cjs/rules/no-legacy-icons/checks.js +484 -0
  4. package/dist/cjs/rules/no-legacy-icons/helpers.js +289 -0
  5. package/dist/cjs/rules/no-legacy-icons/index.js +111 -131
  6. package/dist/cjs/rules/no-legacy-icons/migration-map-temp.js +4090 -0
  7. package/dist/cjs/rules/use-tokens-typography/index.js +1 -1
  8. package/dist/es2019/rules/ensure-design-token-usage/index.js +1 -1
  9. package/dist/es2019/rules/no-legacy-icons/checks.js +388 -0
  10. package/dist/es2019/rules/no-legacy-icons/helpers.js +275 -0
  11. package/dist/es2019/rules/no-legacy-icons/index.js +96 -97
  12. package/dist/es2019/rules/no-legacy-icons/migration-map-temp.js +4082 -0
  13. package/dist/es2019/rules/use-tokens-typography/index.js +1 -1
  14. package/dist/esm/rules/ensure-design-token-usage/index.js +1 -1
  15. package/dist/esm/rules/no-legacy-icons/checks.js +477 -0
  16. package/dist/esm/rules/no-legacy-icons/helpers.js +279 -0
  17. package/dist/esm/rules/no-legacy-icons/index.js +111 -131
  18. package/dist/esm/rules/no-legacy-icons/migration-map-temp.js +4084 -0
  19. package/dist/esm/rules/use-tokens-typography/index.js +1 -1
  20. package/dist/types/rules/no-legacy-icons/checks.d.ts +13 -0
  21. package/dist/types/rules/no-legacy-icons/helpers.d.ts +82 -0
  22. package/dist/types/rules/no-legacy-icons/index.d.ts +2 -1
  23. package/dist/types/rules/no-legacy-icons/migration-map-temp.d.ts +22 -0
  24. package/dist/{types-ts4.5/rules/use-tokens-typography → types/rules/utils}/error-boundary.d.ts +5 -1
  25. package/dist/types-ts4.5/rules/no-legacy-icons/checks.d.ts +13 -0
  26. package/dist/types-ts4.5/rules/no-legacy-icons/helpers.d.ts +82 -0
  27. package/dist/types-ts4.5/rules/no-legacy-icons/index.d.ts +2 -1
  28. package/dist/types-ts4.5/rules/no-legacy-icons/migration-map-temp.d.ts +27 -0
  29. package/dist/types-ts4.5/rules/{ensure-design-token-usage → utils}/error-boundary.d.ts +5 -1
  30. package/package.json +1 -1
  31. package/dist/cjs/rules/use-tokens-typography/error-boundary.js +0 -24
  32. package/dist/es2019/rules/use-tokens-typography/error-boundary.js +0 -19
  33. package/dist/esm/rules/use-tokens-typography/error-boundary.js +0 -18
  34. package/dist/types/rules/ensure-design-token-usage/error-boundary.d.ts +0 -11
  35. package/dist/types/rules/use-tokens-typography/error-boundary.d.ts +0 -11
  36. /package/dist/cjs/rules/{ensure-design-token-usage → utils}/error-boundary.js +0 -0
  37. /package/dist/es2019/rules/{ensure-design-token-usage → utils}/error-boundary.js +0 -0
  38. /package/dist/esm/rules/{ensure-design-token-usage → utils}/error-boundary.js +0 -0
@@ -1,6 +1,6 @@
1
1
  import { createLintRule } from '../utils/create-rule';
2
+ import { errorBoundary } from '../utils/error-boundary';
2
3
  import { getConfig, ruleSchema } from './config';
3
- import { errorBoundary } from './error-boundary';
4
4
  import { StyleObject } from './transformers/style-object';
5
5
  const create = context => {
6
6
  const config = getConfig(context.options[0]);
@@ -4,10 +4,10 @@ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
4
4
  import { isNodeOfType } from 'eslint-codemod-utils';
5
5
  import { getImportSources } from '@atlaskit/eslint-utils/is-supported-import';
6
6
  import { createLintRule } from '../utils/create-rule';
7
+ import { errorBoundary } from '../utils/error-boundary';
7
8
  import { includesHardCodedColor } from '../utils/is-color';
8
9
  import { isDecendantOfGlobalToken, isDecendantOfStyleBlock, isDecendantOfType, isDecendantOfXcssBlock } from '../utils/is-node';
9
10
  import { lintJSXIdentifierForColor, lintJSXLiteralForColor, lintJSXMemberForColor, lintObjectForColor, lintTemplateIdentifierForColor } from './color';
10
- import { errorBoundary } from './error-boundary';
11
11
  import ruleMeta from './rule-meta';
12
12
  import { lintObjectForSpacing } from './spacing';
13
13
  import { convertHyphenatedNameToCamelCase, emToPixels, getDomainsForProperty, getFontSizeValueInScope, getPropertyNodeFromParent, getTokenReplacement, getValueForPropertyNode, getValueFromShorthand, getValueFromTemplateLiteralRaw, includesTokenString, insertTokensImport, isAuto, isCalc, isTokenValueString, isValidSpacingValue, isZero, processCssNode, splitShorthandValues } from './utils';
@@ -0,0 +1,477 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
3
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
4
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
5
+ import { isNodeOfType } from 'eslint-codemod-utils';
6
+ import { canAutoMigrateNewIconBasedOnSize, canMigrateColor, createAutoMigrationError, createCantFindSuitableReplacementError, createCantMigrateColorError, createCantMigrateFunctionUnknownError, createCantMigrateIdentifierError, createCantMigrateReExportError, createCantMigrateSizeUnknown, createCantMigrateSpreadPropsError, createCantMigrateUnsafeProp, createGuidance, createHelpers, findUNSAFEProp, getIconKey, getMigrationMapObject, locToString } from './helpers';
7
+ import { isSize } from './migration-map-temp';
8
+ export var createChecks = function createChecks(context) {
9
+ //create global variables to be shared by the checks
10
+ var _createHelpers = createHelpers(context),
11
+ getPrimaryColor = _createHelpers.getPrimaryColor,
12
+ getConfigFlag = _createHelpers.getConfigFlag;
13
+ var legacyIconImports = {};
14
+ var newButtonImports = new Set();
15
+ var errorsManual = {};
16
+ var errorsAuto = {};
17
+ var guidance = {};
18
+
19
+ // Extract parameters
20
+ var shouldErrorForManualMigration = getConfigFlag('shouldErrorForManualMigration', true);
21
+ var shouldErrorForAutoMigration = getConfigFlag('shouldErrorForAutoMigration', true);
22
+ var isQuietMode = getConfigFlag('quiet', false);
23
+
24
+ /**
25
+ * Adds the legacy Icon and new button imports to the correct global arrays to be used by the other checks
26
+ * @param node The import node found by ESLint
27
+ */
28
+ var checkImportDeclarations = function checkImportDeclarations(node) {
29
+ var moduleSource = node.source.value;
30
+
31
+ // Find the imports for legacy icons
32
+ if (moduleSource && typeof moduleSource === 'string' && ['@atlaskit/icon/glyph/', '@atlaskit/icon-object/glyph/'].find(function (val) {
33
+ return moduleSource.startsWith(val);
34
+ }) && node.specifiers.length > 0) {
35
+ var _iterator = _createForOfIteratorHelper(node.specifiers),
36
+ _step;
37
+ try {
38
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
39
+ var spec = _step.value;
40
+ if (spec.local.name) {
41
+ legacyIconImports[spec.local.name] = {
42
+ packageName: moduleSource,
43
+ exported: false
44
+ };
45
+ }
46
+ }
47
+ } catch (err) {
48
+ _iterator.e(err);
49
+ } finally {
50
+ _iterator.f();
51
+ }
52
+ }
53
+
54
+ // Find the imports for new button and IconButton
55
+ if (typeof moduleSource === 'string' && moduleSource.startsWith('@atlaskit/button/new') && node.specifiers.length) {
56
+ var _iterator2 = _createForOfIteratorHelper(node.specifiers),
57
+ _step2;
58
+ try {
59
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
60
+ var _spec = _step2.value;
61
+ if (_spec.type === 'ImportDefaultSpecifier') {
62
+ newButtonImports.add(_spec.local.name);
63
+ } else if (_spec.type === 'ImportSpecifier' && _spec.imported.name === 'IconButton') {
64
+ newButtonImports.add(_spec.local.name);
65
+ }
66
+ }
67
+ } catch (err) {
68
+ _iterator2.e(err);
69
+ } finally {
70
+ _iterator2.f();
71
+ }
72
+ }
73
+ };
74
+
75
+ /**
76
+ * Adds the legacy Icon and new button variable reassignments to the correct global arrays to be used by the other checks
77
+ * @param node The variable reassignment node found by ESLint
78
+ */
79
+ var checkVariableDeclarations = function checkVariableDeclarations(node) {
80
+ if (isNodeOfType(node, 'VariableDeclaration')) {
81
+ var isExported = node.parent && isNodeOfType(node.parent, 'ExportNamedDeclaration');
82
+ var _iterator3 = _createForOfIteratorHelper(node.declarations),
83
+ _step3;
84
+ try {
85
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
86
+ var decl = _step3.value;
87
+ if (isNodeOfType(decl, 'VariableDeclarator') && 'init' in decl && 'id' in decl && decl.init && decl.id && 'name' in decl.id && decl.id.name && isNodeOfType(decl.init, 'Identifier')) {
88
+ if (decl.init.name in legacyIconImports) {
89
+ legacyIconImports[decl.id.name] = {
90
+ packageName: legacyIconImports[decl.init.name].packageName,
91
+ exported: legacyIconImports[decl.init.name].exported || isExported
92
+ };
93
+ } else if (newButtonImports.has(decl.init.name)) {
94
+ newButtonImports.add(decl.id.name);
95
+ }
96
+ }
97
+ }
98
+ } catch (err) {
99
+ _iterator3.e(err);
100
+ } finally {
101
+ _iterator3.f();
102
+ }
103
+ }
104
+ };
105
+
106
+ /**
107
+ * Checks if the default export is a re-export of a legacy icon and stores the errors in the global array
108
+ * @param node The default export node found by ESLint
109
+ */
110
+ var checkExportDefaultDeclaration = function checkExportDefaultDeclaration(node) {
111
+ var exportName = '';
112
+ var packageName = '';
113
+ if ('declaration' in node && node.declaration && isNodeOfType(node.declaration, 'Identifier') && node.declaration.name in legacyIconImports) {
114
+ packageName = legacyIconImports[node.declaration.name].packageName;
115
+ exportName = 'Default export';
116
+ } else if ('declaration' in node && node.declaration && isNodeOfType(node.declaration, 'AssignmentExpression') && isNodeOfType(node.declaration.left, 'Identifier') && isNodeOfType(node.declaration.right, 'Identifier') && node.declaration.right.name in legacyIconImports) {
117
+ packageName = legacyIconImports[node.declaration.right.name].packageName;
118
+ exportName = node.declaration.left.name;
119
+ } else {
120
+ return;
121
+ }
122
+ createCantMigrateReExportError(node, packageName, exportName, errorsManual);
123
+ guidance[locToString(node)] = createGuidance(packageName);
124
+ };
125
+
126
+ /**
127
+ * Checks if the named exports are re-exports of a legacy icon and stores the errors in the global array
128
+ * @param node The named export node found by ESLint
129
+ */
130
+ var checkExportNamedVariables = function checkExportNamedVariables(node) {
131
+ // export {default as AddIcon} from '@atlaskit/icon/glyph/add';
132
+ if (node.source && isNodeOfType(node.source, 'Literal') && 'value' in node.source) {
133
+ var moduleSource = node.source.value;
134
+ if (typeof moduleSource === 'string' && ['@atlaskit/icon/glyph/', '@atlaskit/icon-object/glyph/'].find(function (val) {
135
+ return moduleSource.startsWith(val);
136
+ }) && node.specifiers.length) {
137
+ createCantMigrateReExportError(node, moduleSource, node.specifiers[0].exported.name, errorsManual);
138
+ guidance[locToString(node)] = createGuidance(moduleSource);
139
+ }
140
+ } else if (node.declaration && isNodeOfType(node.declaration, 'VariableDeclaration')) {
141
+ // export const Icon = AddIcon;
142
+ var _iterator4 = _createForOfIteratorHelper(node.declaration.declarations),
143
+ _step4;
144
+ try {
145
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
146
+ var decl = _step4.value;
147
+ if (isNodeOfType(decl, 'VariableDeclarator') && 'init' in decl && decl.init && isNodeOfType(decl.init, 'Identifier') && decl.init.name in legacyIconImports) {
148
+ createCantMigrateReExportError(node, legacyIconImports[decl.init.name].packageName, decl.init.name, errorsManual);
149
+ guidance[locToString(node)] = createGuidance(createGuidance(legacyIconImports[decl.init.name].packageName));
150
+ }
151
+ }
152
+ } catch (err) {
153
+ _iterator4.e(err);
154
+ } finally {
155
+ _iterator4.f();
156
+ }
157
+ } else if (!node.source && node.specifiers && node.specifiers.length > 0) {
158
+ /**
159
+ * case where multiple consts are re-exported:
160
+ * const AddIcon = LegacyIcon;
161
+ * const crossIcon = LegacyIcon2;
162
+ * export { AddIcon, CrossIcon as default }
163
+ */
164
+ var _iterator5 = _createForOfIteratorHelper(node.specifiers),
165
+ _step5;
166
+ try {
167
+ for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
168
+ var spec = _step5.value;
169
+ if (spec.local.name in legacyIconImports) {
170
+ //update legacy imports to be exported
171
+ legacyIconImports[spec.local.name] = {
172
+ packageName: legacyIconImports[spec.local.name].packageName,
173
+ exported: true
174
+ };
175
+ createCantMigrateReExportError(spec, legacyIconImports[spec.local.name].packageName, spec.exported.name, errorsManual);
176
+ guidance[locToString(spec)] = createGuidance(legacyIconImports[spec.local.name].packageName);
177
+ }
178
+ }
179
+ } catch (err) {
180
+ _iterator5.e(err);
181
+ } finally {
182
+ _iterator5.f();
183
+ }
184
+ }
185
+ };
186
+
187
+ /**
188
+ * Checks if a legacy icon is referenced in an array or map and stores the errors in the global array
189
+ * @param node The array/map node found by ESLint
190
+ */
191
+ var checkArrayOrMap = function checkArrayOrMap(node) {
192
+ if (!isNodeOfType(node, 'Identifier')) {
193
+ return;
194
+ }
195
+ if (node.name && node.name in legacyIconImports && legacyIconImports[node.name].packageName) {
196
+ createCantMigrateIdentifierError(node, legacyIconImports[node.name].packageName, node.name, errorsManual);
197
+ guidance[locToString(node)] = createGuidance(legacyIconImports[node.name].packageName);
198
+ }
199
+ };
200
+
201
+ /**
202
+ * Checks if a legacy icon is referenced as a prop to a component and stores the errors in the global array
203
+ * @param node The property node found by ESLint
204
+ */
205
+ var checkIconAsProp = function checkIconAsProp(node) {
206
+ if (!isNodeOfType(node, 'Identifier')) {
207
+ return;
208
+ }
209
+ if (!node.parent || !node.parent.parent || !node.parent.parent.parent) {
210
+ return;
211
+ }
212
+ if (!isNodeOfType(node.parent, 'JSXExpressionContainer') || !isNodeOfType(node.parent.parent, 'JSXAttribute') || !isNodeOfType(node.parent.parent.parent, 'JSXOpeningElement')) {
213
+ return;
214
+ }
215
+ if (node.name in legacyIconImports && isNodeOfType(node.parent.parent.name, 'JSXIdentifier') && node.parent.parent.name.name !== 'LEGACY_fallbackIcon') {
216
+ var _migrationMapObject$s;
217
+ var migrationMapObject = getMigrationMapObject(legacyIconImports[node.name].packageName);
218
+ var newIcon = migrationMapObject === null || migrationMapObject === void 0 ? void 0 : migrationMapObject.newIcon;
219
+ var isNewIconMigratable = canAutoMigrateNewIconBasedOnSize(migrationMapObject === null || migrationMapObject === void 0 || (_migrationMapObject$s = migrationMapObject.sizeGuidance) === null || _migrationMapObject$s === void 0 ? void 0 : _migrationMapObject$s.medium);
220
+ var isInNewButton = isNodeOfType(node.parent.parent.parent.name, 'JSXIdentifier') && newButtonImports.has(node.parent.parent.parent.name.name);
221
+ var UNSAFE_size = null;
222
+ var UNSAFE_propName = null;
223
+ if (isInNewButton) {
224
+ var result = findUNSAFEProp(node.parent.parent, node.parent.parent.parent);
225
+ UNSAFE_size = result.UNSAFE_size;
226
+ UNSAFE_propName = result.UNSAFE_propName;
227
+ }
228
+ if (newIcon && isInNewButton && isNewIconMigratable && UNSAFE_size !== 'large' && UNSAFE_size !== 'xlarge') {
229
+ var iconKey = getIconKey(legacyIconImports[node.name].packageName);
230
+ createAutoMigrationError(node, legacyIconImports[node.name].packageName, node.name, newIcon, iconKey, errorsAuto);
231
+ guidance[locToString(node)] = createGuidance(legacyIconImports[node.name].packageName, 'medium');
232
+ } else if ((!newIcon || !isNewIconMigratable) && !UNSAFE_size) {
233
+ createCantFindSuitableReplacementError(node, legacyIconImports[node.name].packageName, node.name, errorsManual);
234
+ guidance[locToString(node)] = createGuidance(legacyIconImports[node.name].packageName);
235
+ } else if ((UNSAFE_size === 'large' || UNSAFE_size === 'xlarge') && UNSAFE_propName) {
236
+ createCantMigrateUnsafeProp(node, UNSAFE_propName, UNSAFE_size, legacyIconImports[node.name].packageName, node.name, errorsManual);
237
+ guidance[locToString(node)] = createGuidance(legacyIconImports[node.name].packageName, UNSAFE_size);
238
+ } else if (!isInNewButton) {
239
+ createCantMigrateFunctionUnknownError(node, legacyIconImports[node.name].packageName, node.name, errorsManual);
240
+ guidance[locToString(node)] = createGuidance(legacyIconImports[node.name].packageName);
241
+ }
242
+ }
243
+ };
244
+
245
+ /**
246
+ * Checks if a legacy icon is being rendered and stores the errors in the global array
247
+ * @param node The JSX node found by ESLint
248
+ */
249
+ var checkJSXElement = function checkJSXElement(node) {
250
+ var _node$parent, _node$parent$parent$p;
251
+ if (!('openingElement' in node) || !isNodeOfType(node.openingElement.name, 'JSXIdentifier')) {
252
+ return;
253
+ }
254
+
255
+ // Determine if element is rendered inside LEGACY_fallbackIcon prop - if so, don't perform any checks
256
+ if (node.parent && isNodeOfType(node.parent, 'ArrowFunctionExpression') && (_node$parent = node.parent) !== null && _node$parent !== void 0 && (_node$parent = _node$parent.parent) !== null && _node$parent !== void 0 && _node$parent.parent && isNodeOfType(node.parent.parent.parent, 'JSXAttribute') && ((_node$parent$parent$p = node.parent.parent.parent.name) === null || _node$parent$parent$p === void 0 ? void 0 : _node$parent$parent$p.name) === 'LEGACY_fallbackIcon') {
257
+ return;
258
+ }
259
+ var name = node.openingElement.name.name;
260
+ // Legacy icons rendered as JSX elements
261
+ if (name in legacyIconImports) {
262
+ var _node$parent2, _node$parent3, _size;
263
+ // Determine if inside a new button - if so:
264
+ // - Assume spread props are safe - still error if props explicitly set to unmigratable values
265
+ // - eventually: look for UNSAFE_iconBefore_size props on the parent button - if it's large/xlarge, fail
266
+ var insideNewButton = false;
267
+ var UNSAFE_propName = null;
268
+ var UNSAFE_size = null;
269
+ if (node.parent && isNodeOfType(node.parent, 'ArrowFunctionExpression') && (_node$parent2 = node.parent) !== null && _node$parent2 !== void 0 && (_node$parent2 = _node$parent2.parent) !== null && _node$parent2 !== void 0 && _node$parent2.parent && isNodeOfType(node.parent.parent.parent, 'JSXAttribute') && isNodeOfType(node.parent.parent.parent.name, 'JSXIdentifier') && (_node$parent3 = node.parent) !== null && _node$parent3 !== void 0 && (_node$parent3 = _node$parent3.parent) !== null && _node$parent3 !== void 0 && (_node$parent3 = _node$parent3.parent) !== null && _node$parent3 !== void 0 && _node$parent3.parent && isNodeOfType(node.parent.parent.parent.parent, 'JSXOpeningElement') && isNodeOfType(node.parent.parent.parent.parent.name, 'JSXIdentifier') && newButtonImports.has(node.parent.parent.parent.parent.name.name)) {
270
+ insideNewButton = true;
271
+ var result = findUNSAFEProp(node.parent.parent.parent, node.parent.parent.parent.parent);
272
+ UNSAFE_size = result.UNSAFE_size;
273
+ UNSAFE_propName = result.UNSAFE_propName;
274
+ }
275
+
276
+ // Find size prop on node
277
+ var size = 'medium';
278
+ var primaryColor = null;
279
+ var afterSpreadSet = new Set();
280
+ var requiredAttributesAfterSpread = new Set(['size', 'primaryColor', 'secondaryColor']);
281
+ var hasSpread = false;
282
+ var hasPrimaryColorProp = false;
283
+ var _iterator6 = _createForOfIteratorHelper(node.openingElement.attributes),
284
+ _step6;
285
+ try {
286
+ for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
287
+ var attr = _step6.value;
288
+ // Detect spread props
289
+ if (isNodeOfType(attr, 'JSXSpreadAttribute')) {
290
+ // In case there are more spread props
291
+ afterSpreadSet.clear();
292
+ hasSpread = true;
293
+ continue;
294
+ }
295
+ if (!isNodeOfType(attr, 'JSXAttribute') || !isNodeOfType(attr.name, 'JSXIdentifier') || !attr.value) {
296
+ continue;
297
+ }
298
+
299
+ // Register props that aren't being spread
300
+ afterSpreadSet.add(attr.name.name);
301
+
302
+ // Extract values of props
303
+ switch (attr.name.name) {
304
+ case 'size':
305
+ if (isNodeOfType(attr.value, 'Literal') && isSize(attr.value.value)) {
306
+ size = attr.value.value;
307
+ } else if (isNodeOfType(attr.value, 'JSXExpressionContainer') && isNodeOfType(attr.value.expression, 'Literal') && isSize(attr.value.expression.value)) {
308
+ size = attr.value.expression.value;
309
+ } else {
310
+ size = null;
311
+ }
312
+ break;
313
+ case 'primaryColor':
314
+ primaryColor = getPrimaryColor(attr);
315
+ hasPrimaryColorProp = true;
316
+ break;
317
+ }
318
+ }
319
+ } catch (err) {
320
+ _iterator6.e(err);
321
+ } finally {
322
+ _iterator6.f();
323
+ }
324
+ var hasManualMigration = false;
325
+ if (primaryColor && !canMigrateColor(primaryColor) || hasPrimaryColorProp && !primaryColor) {
326
+ createCantMigrateColorError(node, primaryColor ? "the value of '".concat(primaryColor, "'") : 'a statically unknown value', errorsManual, legacyIconImports[name].packageName, name);
327
+ hasManualMigration = true;
328
+ }
329
+
330
+ // If size can't be determined (i.e. size is a variable or function call, etc)
331
+ // then we need to error; icon can't be auto-migrated safely
332
+ if (size === null) {
333
+ createCantMigrateSizeUnknown(node, errorsManual, legacyIconImports[name].packageName, name);
334
+ hasManualMigration = true;
335
+ }
336
+ guidance[locToString(node)] = createGuidance(legacyIconImports[name].packageName, size ? size : undefined);
337
+ // Check for unsafe size
338
+ if ((UNSAFE_size === 'large' || UNSAFE_size === 'xlarge') && (UNSAFE_propName === 'UNSAFE_iconAfter_size' || UNSAFE_propName === 'UNSAFE_iconBefore_size' || UNSAFE_propName === 'UNSAFE_size')) {
339
+ createCantMigrateUnsafeProp(node, UNSAFE_propName, UNSAFE_size, legacyIconImports[name].packageName, name, errorsManual);
340
+ hasManualMigration = true;
341
+ }
342
+ // Do a set comparison - is requiredAttributesAfterSpread a subset of afterSpreadSet?
343
+ if (hasSpread === true && !Array.from(requiredAttributesAfterSpread).every(function (val) {
344
+ return afterSpreadSet.has(val);
345
+ }) && !insideNewButton) {
346
+ var missingProps = Array.from(requiredAttributesAfterSpread).filter(function (val) {
347
+ return !afterSpreadSet.has(val);
348
+ });
349
+ createCantMigrateSpreadPropsError(node, missingProps, errorsManual, legacyIconImports[name].packageName, name);
350
+ hasManualMigration = true;
351
+ }
352
+ // Check if it is an exported component?
353
+ if (legacyIconImports[name].exported) {
354
+ createCantMigrateReExportError(node, legacyIconImports[name].packageName, name, errorsManual);
355
+ hasManualMigration = true;
356
+ }
357
+ var migrationMapObject = getMigrationMapObject(legacyIconImports[name].packageName);
358
+ var iconKey = getIconKey(legacyIconImports[name].packageName);
359
+ var newIcon = migrationMapObject === null || migrationMapObject === void 0 ? void 0 : migrationMapObject.newIcon;
360
+ var isNewIconMigratable = canAutoMigrateNewIconBasedOnSize(migrationMapObject === null || migrationMapObject === void 0 ? void 0 : migrationMapObject.sizeGuidance[(_size = size) !== null && _size !== void 0 ? _size : 'medium']);
361
+ if (!hasManualMigration && newIcon && isNewIconMigratable) {
362
+ createAutoMigrationError(node, legacyIconImports[name].packageName, name, newIcon, iconKey, errorsAuto);
363
+ } else if ((!newIcon || !isNewIconMigratable) && size) {
364
+ createCantFindSuitableReplacementError(node, legacyIconImports[name].packageName, name, errorsManual);
365
+ }
366
+ }
367
+ };
368
+
369
+ /**
370
+ * Checks if a legacy icon is being passed into a function call and stores the errors in the global array
371
+ * @param node The function call node found by ESLint
372
+ */
373
+ var checkCallExpression = function checkCallExpression(node) {
374
+ if ('arguments' in node && node.arguments.length) {
375
+ var _iterator7 = _createForOfIteratorHelper(node.arguments),
376
+ _step7;
377
+ try {
378
+ for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
379
+ var arg = _step7.value;
380
+ if (isNodeOfType(arg, 'Identifier') && arg.name in legacyIconImports && legacyIconImports[arg.name].packageName) {
381
+ createCantMigrateFunctionUnknownError(node, legacyIconImports[arg.name].packageName, arg.name, errorsManual);
382
+ guidance[locToString(node)] = createGuidance(legacyIconImports[arg.name].packageName);
383
+ }
384
+ }
385
+ } catch (err) {
386
+ _iterator7.e(err);
387
+ } finally {
388
+ _iterator7.f();
389
+ }
390
+ }
391
+ };
392
+
393
+ /**
394
+ * Throws the relevant errors in the correct order based on configs.
395
+ */
396
+ var throwErrors = function throwErrors() {
397
+ if (shouldErrorForManualMigration) {
398
+ for (var _i = 0, _Object$entries = Object.entries(errorsManual); _i < _Object$entries.length; _i++) {
399
+ var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
400
+ _key = _Object$entries$_i[0],
401
+ errorList = _Object$entries$_i[1];
402
+ var node = 'node' in errorList.errors[0] ? errorList.errors[0].node : null;
403
+ if (node) {
404
+ context.report({
405
+ node: node,
406
+ messageId: 'noLegacyIconsManualMigration',
407
+ data: {
408
+ iconName: errorList.iconName,
409
+ importSource: errorList.importSource,
410
+ quietModeGuidance: isQuietMode ? 'For more information see the below errors:' : ''
411
+ }
412
+ });
413
+ if (!isQuietMode) {
414
+ var _iterator8 = _createForOfIteratorHelper(errorList.errors),
415
+ _step8;
416
+ try {
417
+ for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
418
+ var error = _step8.value;
419
+ context.report(error);
420
+ }
421
+ } catch (err) {
422
+ _iterator8.e(err);
423
+ } finally {
424
+ _iterator8.f();
425
+ }
426
+ if (_key in guidance) {
427
+ context.report({
428
+ node: node,
429
+ messageId: 'guidance',
430
+ data: {
431
+ guidance: guidance[_key]
432
+ }
433
+ });
434
+ }
435
+ }
436
+ }
437
+ }
438
+ }
439
+ if (shouldErrorForAutoMigration) {
440
+ for (var _i2 = 0, _Object$entries2 = Object.entries(errorsAuto); _i2 < _Object$entries2.length; _i2++) {
441
+ var _Object$entries2$_i = _slicedToArray(_Object$entries2[_i2], 2),
442
+ _key2 = _Object$entries2$_i[0],
443
+ _error = _Object$entries2$_i[1];
444
+ // If there's a manual error that exists for this same component,
445
+ // don't throw the auto error
446
+ if (_key2 in errorsManual) {
447
+ delete errorsAuto[_key2];
448
+ continue;
449
+ }
450
+ var _node = 'node' in _error ? _error.node : null;
451
+ if (_node) {
452
+ context.report(_error);
453
+ if (_key2 in guidance && !isQuietMode) {
454
+ context.report({
455
+ node: _node,
456
+ messageId: 'guidance',
457
+ data: {
458
+ guidance: guidance[_key2]
459
+ }
460
+ });
461
+ }
462
+ }
463
+ }
464
+ }
465
+ };
466
+ return {
467
+ checkImportDeclarations: checkImportDeclarations,
468
+ checkVariableDeclarations: checkVariableDeclarations,
469
+ checkExportDefaultDeclaration: checkExportDefaultDeclaration,
470
+ checkExportNamedVariables: checkExportNamedVariables,
471
+ checkArrayOrMap: checkArrayOrMap,
472
+ checkIconAsProp: checkIconAsProp,
473
+ checkJSXElement: checkJSXElement,
474
+ checkCallExpression: checkCallExpression,
475
+ throwErrors: throwErrors
476
+ };
477
+ };