@atlaskit/eslint-plugin-design-system 13.41.3 → 13.42.0

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 (85) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/README.md +0 -1
  3. package/dist/cjs/presets/all-flat.codegen.js +1 -2
  4. package/dist/cjs/presets/all.codegen.js +1 -2
  5. package/dist/cjs/rules/index.codegen.js +1 -3
  6. package/dist/cjs/rules/use-primitives/utils/is-valid-css-properties-to-transform.js +5 -4
  7. package/dist/es2019/presets/all-flat.codegen.js +1 -2
  8. package/dist/es2019/presets/all.codegen.js +1 -2
  9. package/dist/es2019/rules/index.codegen.js +1 -3
  10. package/dist/es2019/rules/use-primitives/utils/is-valid-css-properties-to-transform.js +5 -4
  11. package/dist/esm/presets/all-flat.codegen.js +1 -2
  12. package/dist/esm/presets/all.codegen.js +1 -2
  13. package/dist/esm/rules/index.codegen.js +1 -3
  14. package/dist/esm/rules/use-primitives/utils/is-valid-css-properties-to-transform.js +5 -4
  15. package/dist/types/presets/all-flat.codegen.d.ts +1 -1
  16. package/dist/types/presets/all.codegen.d.ts +1 -1
  17. package/dist/types/rules/ensure-design-token-usage/index.d.ts +1 -1
  18. package/dist/types/rules/ensure-design-token-usage/rule-meta.d.ts +1 -1
  19. package/dist/types/rules/ensure-design-token-usage/utils.d.ts +1 -1
  20. package/dist/types/rules/index.codegen.d.ts +1 -1
  21. package/dist/types/rules/no-deprecated-imports/handlers/icon.d.ts +1 -1
  22. package/dist/types/rules/use-heading/transformers/common.d.ts +2 -2
  23. package/dist/types/rules/use-latest-xcss-syntax-typography/linters/common.d.ts +1 -1
  24. package/dist/types/rules/use-latest-xcss-syntax-typography/linters/wrapped-token-value.d.ts +1 -1
  25. package/dist/types/rules/use-primitives/transformers/compiled-styled/index.d.ts +1 -1
  26. package/dist/types/rules/use-primitives/transformers/emotion-css/index.d.ts +1 -1
  27. package/dist/types/rules/use-primitives/utils/is-valid-css-properties-to-transform.d.ts +1 -1
  28. package/dist/types/rules/use-primitives/utils/validate-styles.d.ts +1 -1
  29. package/dist/types/rules/use-primitives-text/transformers/common.d.ts +1 -1
  30. package/dist/types/rules/use-primitives-text/transformers/unsafe-small-text.d.ts +1 -1
  31. package/dist/types/rules/use-tokens-typography/config/index.d.ts +1 -1
  32. package/dist/types/rules/use-tokens-typography/transformers/banned-properties.d.ts +1 -1
  33. package/dist/types/rules/use-tokens-typography/transformers/font-family.d.ts +1 -1
  34. package/dist/types/rules/use-tokens-typography/transformers/font-weight.d.ts +1 -1
  35. package/dist/types/rules/use-tokens-typography/transformers/restricted-capitalisation.d.ts +1 -1
  36. package/dist/types/rules/use-tokens-typography/transformers/style-object.d.ts +1 -1
  37. package/dist/types/rules/use-tokens-typography/transformers/untokenized-properties.d.ts +1 -1
  38. package/dist/types/rules/utils/create-no-exported-rule/check-if-supported-export.d.ts +1 -1
  39. package/dist/types/rules/utils/get-first-supported-import.d.ts +1 -1
  40. package/dist/types-ts4.5/presets/all-flat.codegen.d.ts +1 -1
  41. package/dist/types-ts4.5/presets/all.codegen.d.ts +1 -1
  42. package/dist/types-ts4.5/rules/ensure-design-token-usage/index.d.ts +1 -1
  43. package/dist/types-ts4.5/rules/ensure-design-token-usage/rule-meta.d.ts +1 -1
  44. package/dist/types-ts4.5/rules/ensure-design-token-usage/utils.d.ts +1 -1
  45. package/dist/types-ts4.5/rules/index.codegen.d.ts +1 -1
  46. package/dist/types-ts4.5/rules/no-deprecated-imports/handlers/icon.d.ts +1 -1
  47. package/dist/types-ts4.5/rules/use-heading/transformers/common.d.ts +2 -2
  48. package/dist/types-ts4.5/rules/use-latest-xcss-syntax-typography/linters/common.d.ts +1 -1
  49. package/dist/types-ts4.5/rules/use-latest-xcss-syntax-typography/linters/wrapped-token-value.d.ts +1 -1
  50. package/dist/types-ts4.5/rules/use-primitives/transformers/compiled-styled/index.d.ts +1 -1
  51. package/dist/types-ts4.5/rules/use-primitives/transformers/emotion-css/index.d.ts +1 -1
  52. package/dist/types-ts4.5/rules/use-primitives/utils/is-valid-css-properties-to-transform.d.ts +1 -1
  53. package/dist/types-ts4.5/rules/use-primitives/utils/validate-styles.d.ts +1 -1
  54. package/dist/types-ts4.5/rules/use-primitives-text/transformers/common.d.ts +1 -1
  55. package/dist/types-ts4.5/rules/use-primitives-text/transformers/unsafe-small-text.d.ts +1 -1
  56. package/dist/types-ts4.5/rules/use-tokens-typography/config/index.d.ts +1 -1
  57. package/dist/types-ts4.5/rules/use-tokens-typography/transformers/banned-properties.d.ts +1 -1
  58. package/dist/types-ts4.5/rules/use-tokens-typography/transformers/font-family.d.ts +1 -1
  59. package/dist/types-ts4.5/rules/use-tokens-typography/transformers/font-weight.d.ts +1 -1
  60. package/dist/types-ts4.5/rules/use-tokens-typography/transformers/restricted-capitalisation.d.ts +1 -1
  61. package/dist/types-ts4.5/rules/use-tokens-typography/transformers/style-object.d.ts +1 -1
  62. package/dist/types-ts4.5/rules/use-tokens-typography/transformers/untokenized-properties.d.ts +1 -1
  63. package/dist/types-ts4.5/rules/utils/create-no-exported-rule/check-if-supported-export.d.ts +1 -1
  64. package/dist/types-ts4.5/rules/utils/get-first-supported-import.d.ts +1 -1
  65. package/package.json +4 -4
  66. package/dist/cjs/rules/no-legacy-icons/checks.js +0 -619
  67. package/dist/cjs/rules/no-legacy-icons/helpers.js +0 -900
  68. package/dist/cjs/rules/no-legacy-icons/index.js +0 -91
  69. package/dist/cjs/rules/no-legacy-icons/upcoming-icons.js +0 -7
  70. package/dist/es2019/rules/no-legacy-icons/checks.js +0 -520
  71. package/dist/es2019/rules/no-legacy-icons/helpers.js +0 -853
  72. package/dist/es2019/rules/no-legacy-icons/index.js +0 -87
  73. package/dist/es2019/rules/no-legacy-icons/upcoming-icons.js +0 -1
  74. package/dist/esm/rules/no-legacy-icons/checks.js +0 -613
  75. package/dist/esm/rules/no-legacy-icons/helpers.js +0 -891
  76. package/dist/esm/rules/no-legacy-icons/index.js +0 -85
  77. package/dist/esm/rules/no-legacy-icons/upcoming-icons.js +0 -1
  78. package/dist/types/rules/no-legacy-icons/checks.d.ts +0 -16
  79. package/dist/types/rules/no-legacy-icons/helpers.d.ts +0 -151
  80. package/dist/types/rules/no-legacy-icons/index.d.ts +0 -2
  81. package/dist/types/rules/no-legacy-icons/upcoming-icons.d.ts +0 -1
  82. package/dist/types-ts4.5/rules/no-legacy-icons/checks.d.ts +0 -16
  83. package/dist/types-ts4.5/rules/no-legacy-icons/helpers.d.ts +0 -156
  84. package/dist/types-ts4.5/rules/no-legacy-icons/index.d.ts +0 -2
  85. package/dist/types-ts4.5/rules/no-legacy-icons/upcoming-icons.d.ts +0 -1
@@ -1,619 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.createChecks = void 0;
7
- var _eslintCodemodUtils = require("eslint-codemod-utils");
8
- var _helpers = require("./helpers");
9
- function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, 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 o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
10
- function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
11
- function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
12
- var createChecks = exports.createChecks = function createChecks(context) {
13
- // Create global variables to be shared by the checks
14
- var _createHelpers = (0, _helpers.createHelpers)(context),
15
- getPrimaryColor = _createHelpers.getPrimaryColor,
16
- getConfigFlag = _createHelpers.getConfigFlag;
17
- var legacyIconImports = {};
18
- var migrationIconImports = {};
19
- var newButtonImports = new Set();
20
- var legacyButtonImports = new Set();
21
- var errorsManual = {};
22
- var errorsAuto = {};
23
- var iconSizesInfo = {}; //Import source key, locations as value
24
-
25
- var guidance = {};
26
-
27
- // Extract parameters
28
- var shouldErrorForManualMigration = getConfigFlag('shouldErrorForManualMigration', true);
29
- var shouldErrorForAutoMigration = getConfigFlag('shouldErrorForAutoMigration', true);
30
- var isQuietMode = getConfigFlag('quiet', false);
31
- var shouldUseMigrationPath = getConfigFlag('shouldUseMigrationPath', true);
32
- var shouldUseSafeMigrationMode = getConfigFlag('shouldUseSafeMigrationMode', false);
33
-
34
- // Sorted list of ranges
35
- var errorRanges = [];
36
-
37
- /**
38
- * Adds the legacy Icon and new button imports to the correct global arrays to be used by the other checks
39
- * @param node The import node found by ESLint
40
- */
41
- var checkImportDeclarations = function checkImportDeclarations(node) {
42
- var moduleSource = node.source.value;
43
-
44
- // Find the imports for legacy icons
45
- if (moduleSource && typeof moduleSource === 'string' && ['@atlaskit/icon/glyph/'].find(function (val) {
46
- return moduleSource.startsWith(val);
47
- }) && node.specifiers.length > 0) {
48
- var _iterator = _createForOfIteratorHelper(node.specifiers),
49
- _step;
50
- try {
51
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
52
- var spec = _step.value;
53
- if (spec.local.name) {
54
- legacyIconImports[spec.local.name] = {
55
- packageName: moduleSource,
56
- exported: false,
57
- importNode: node,
58
- importSpecifier: spec.local.name
59
- };
60
- }
61
- }
62
- } catch (err) {
63
- _iterator.e(err);
64
- } finally {
65
- _iterator.f();
66
- }
67
- }
68
-
69
- // Find the imports for icons that import from migration path
70
- if (moduleSource && typeof moduleSource === 'string' && (moduleSource.startsWith('@atlaskit/icon/core/migration/') || moduleSource.startsWith('@atlaskit/icon/utility/migration/')) && node.specifiers.length) {
71
- node.specifiers.forEach(function (spec) {
72
- if (spec.local.name) {
73
- migrationIconImports[spec.local.name] = {
74
- packageName: moduleSource,
75
- exported: false,
76
- importNode: node,
77
- importSpecifier: spec.local.name
78
- };
79
- }
80
- });
81
- }
82
-
83
- // Find the imports for new button and IconButton
84
- if (typeof moduleSource === 'string' && moduleSource.startsWith('@atlaskit/button/new') && node.specifiers.length) {
85
- var _iterator2 = _createForOfIteratorHelper(node.specifiers),
86
- _step2;
87
- try {
88
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
89
- var _spec = _step2.value;
90
- if (_spec.type === 'ImportDefaultSpecifier') {
91
- newButtonImports.add(_spec.local.name);
92
- } else if (_spec.type === 'ImportSpecifier' && 'name' in _spec.imported && _spec.imported.name === 'IconButton') {
93
- newButtonImports.add(_spec.local.name);
94
- }
95
- }
96
- } catch (err) {
97
- _iterator2.e(err);
98
- } finally {
99
- _iterator2.f();
100
- }
101
- }
102
-
103
- // Find the imports for legacy default button
104
- if (typeof moduleSource === 'string' && (moduleSource === '@atlaskit/button' || moduleSource === '@atlaskit/button/standard-button' || moduleSource === '@atlaskit/button/loading-button' || moduleSource === '@atlaskit/button/custom-theme-button') && node.specifiers.length) {
105
- var _iterator3 = _createForOfIteratorHelper(node.specifiers),
106
- _step3;
107
- try {
108
- for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
109
- var _spec2 = _step3.value;
110
- if (_spec2.type === 'ImportDefaultSpecifier') {
111
- legacyButtonImports.add(_spec2.local.name);
112
- }
113
- }
114
- } catch (err) {
115
- _iterator3.e(err);
116
- } finally {
117
- _iterator3.f();
118
- }
119
- }
120
- };
121
-
122
- /**
123
- * Adds the legacy Icon and new button variable reassignments to the correct global arrays to be used by the other checks
124
- * @param node The variable reassignment node found by ESLint
125
- */
126
- var checkVariableDeclarations = function checkVariableDeclarations(node) {
127
- if ((0, _eslintCodemodUtils.isNodeOfType)(node, 'VariableDeclaration')) {
128
- var isExported = node.parent && (0, _eslintCodemodUtils.isNodeOfType)(node.parent, 'ExportNamedDeclaration');
129
- var _iterator4 = _createForOfIteratorHelper(node.declarations),
130
- _step4;
131
- try {
132
- for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
133
- var decl = _step4.value;
134
- if ((0, _eslintCodemodUtils.isNodeOfType)(decl, 'VariableDeclarator') && Object.keys(decl).includes('init') && Object.keys(decl).includes('id') && decl.init && decl.id && 'name' in decl.id && decl.id.name && (0, _eslintCodemodUtils.isNodeOfType)(decl.init, 'Identifier')) {
135
- if (Object.keys(legacyIconImports).includes(decl.init.name)) {
136
- legacyIconImports[decl.id.name] = {
137
- packageName: legacyIconImports[decl.init.name].packageName,
138
- exported: legacyIconImports[decl.init.name].exported || isExported,
139
- importNode: legacyIconImports[decl.init.name].importNode,
140
- importSpecifier: legacyIconImports[decl.init.name].importSpecifier
141
- };
142
- } else if (newButtonImports.has(decl.init.name)) {
143
- newButtonImports.add(decl.id.name);
144
- }
145
- }
146
- }
147
- } catch (err) {
148
- _iterator4.e(err);
149
- } finally {
150
- _iterator4.f();
151
- }
152
- }
153
- };
154
-
155
- /**
156
- * Checks if the default export is a re-export of a legacy icon and stores the errors in the global array
157
- * @param node The default export node found by ESLint
158
- */
159
- var checkExportDefaultDeclaration = function checkExportDefaultDeclaration(node) {
160
- var exportName = '';
161
- var packageName = '';
162
- if (Object.keys(node).includes('declaration') && node.declaration && (0, _eslintCodemodUtils.isNodeOfType)(node.declaration, 'Identifier') && Object.keys(legacyIconImports).includes(node.declaration.name)) {
163
- packageName = legacyIconImports[node.declaration.name].packageName;
164
- exportName = 'Default export';
165
- } else if (Object.keys(node).includes('declaration') && node.declaration && (0, _eslintCodemodUtils.isNodeOfType)(node.declaration, 'AssignmentExpression') && (0, _eslintCodemodUtils.isNodeOfType)(node.declaration.left, 'Identifier') && (0, _eslintCodemodUtils.isNodeOfType)(node.declaration.right, 'Identifier') && Object.keys(legacyIconImports).includes(node.declaration.right.name)) {
166
- packageName = legacyIconImports[node.declaration.right.name].packageName;
167
- exportName = node.declaration.left.name;
168
- } else {
169
- return;
170
- }
171
- (0, _helpers.createCantMigrateReExportError)(node, packageName, exportName, errorsManual);
172
- (0, _helpers.addToListOfRanges)(node, errorRanges);
173
- guidance[(0, _helpers.locToString)(node)] = (0, _helpers.createGuidance)({
174
- iconPackage: packageName,
175
- shouldUseMigrationPath: shouldUseMigrationPath
176
- });
177
- };
178
-
179
- /**
180
- * Checks if the named exports are re-exports of a legacy icon and stores the errors in the global array
181
- * @param node The named export node found by ESLint
182
- */
183
- var checkExportNamedVariables = function checkExportNamedVariables(node) {
184
- // Case: export {default as AddIcon} from '@atlaskit/icon/glyph/add';
185
- if (node.source && (0, _eslintCodemodUtils.isNodeOfType)(node.source, 'Literal') && Object.keys(node.source).includes('value')) {
186
- var moduleSource = node.source.value;
187
- if (typeof moduleSource === 'string' && ['@atlaskit/icon/glyph/'].find(function (val) {
188
- return moduleSource.startsWith(val);
189
- }) && node.specifiers.length) {
190
- var _iterator5 = _createForOfIteratorHelper(node.specifiers),
191
- _step5;
192
- try {
193
- for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
194
- var spec = _step5.value;
195
- if ('name' in spec.exported) {
196
- (0, _helpers.createCantMigrateReExportError)(spec, moduleSource, spec.exported.name, errorsManual);
197
- (0, _helpers.addToListOfRanges)(spec, errorRanges);
198
- guidance[(0, _helpers.locToString)(spec)] = (0, _helpers.createGuidance)({
199
- iconPackage: moduleSource,
200
- shouldUseMigrationPath: shouldUseMigrationPath
201
- });
202
- }
203
- }
204
- } catch (err) {
205
- _iterator5.e(err);
206
- } finally {
207
- _iterator5.f();
208
- }
209
- }
210
- } else if (node.declaration && (0, _eslintCodemodUtils.isNodeOfType)(node.declaration, 'VariableDeclaration')) {
211
- // Case: export const Icon = AddIcon;
212
- var _iterator6 = _createForOfIteratorHelper(node.declaration.declarations),
213
- _step6;
214
- try {
215
- for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
216
- var decl = _step6.value;
217
- if ((0, _eslintCodemodUtils.isNodeOfType)(decl, 'VariableDeclarator') && Object.keys(decl).includes('init') && decl.init && (0, _eslintCodemodUtils.isNodeOfType)(decl.init, 'Identifier') && Object.keys(legacyIconImports).includes(decl.init.name)) {
218
- (0, _helpers.createCantMigrateReExportError)(node, legacyIconImports[decl.init.name].packageName, decl.init.name, errorsManual);
219
- (0, _helpers.addToListOfRanges)(node, errorRanges);
220
- guidance[(0, _helpers.locToString)(node)] = (0, _helpers.createGuidance)({
221
- iconPackage: legacyIconImports[decl.init.name].packageName,
222
- shouldUseMigrationPath: shouldUseMigrationPath
223
- });
224
- }
225
- }
226
- } catch (err) {
227
- _iterator6.e(err);
228
- } finally {
229
- _iterator6.f();
230
- }
231
- } else if (!node.source && node.specifiers && node.specifiers.length > 0) {
232
- /**
233
- * case where multiple consts are re-exported:
234
- * const AddIcon = LegacyIcon;
235
- * const crossIcon = LegacyIcon2;
236
- * export { AddIcon, CrossIcon as default }
237
- */
238
- var _iterator7 = _createForOfIteratorHelper(node.specifiers),
239
- _step7;
240
- try {
241
- for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
242
- var _spec3 = _step7.value;
243
- if ('name' in _spec3.local && 'name' in _spec3.exported && Object.keys(legacyIconImports).includes(_spec3.local.name)) {
244
- //update legacy imports to be exported
245
- legacyIconImports[_spec3.local.name] = {
246
- packageName: legacyIconImports[_spec3.local.name].packageName,
247
- exported: true,
248
- importNode: legacyIconImports[_spec3.local.name].importNode,
249
- importSpecifier: legacyIconImports[_spec3.local.name].importSpecifier
250
- };
251
- (0, _helpers.createCantMigrateReExportError)(_spec3, legacyIconImports[_spec3.local.name].packageName, _spec3.exported.name, errorsManual);
252
- (0, _helpers.addToListOfRanges)(_spec3, errorRanges);
253
- guidance[(0, _helpers.locToString)(_spec3)] = (0, _helpers.createGuidance)({
254
- iconPackage: legacyIconImports[_spec3.local.name].packageName,
255
- shouldUseMigrationPath: shouldUseMigrationPath
256
- });
257
- }
258
- }
259
- } catch (err) {
260
- _iterator7.e(err);
261
- } finally {
262
- _iterator7.f();
263
- }
264
- }
265
- };
266
-
267
- /**
268
- * Checks if a legacy icon is referenced in an array or map and stores the errors in the global array
269
- * @param node The array/map node found by ESLint
270
- */
271
- var checkArrayOrMap = function checkArrayOrMap(node) {
272
- if (!(0, _eslintCodemodUtils.isNodeOfType)(node, 'Identifier')) {
273
- return;
274
- }
275
- if (node.name && Object.keys(legacyIconImports).includes(node.name) && legacyIconImports[node.name].packageName) {
276
- (0, _helpers.createCantMigrateIdentifierMapOrArrayError)(node, legacyIconImports[node.name].packageName, node.name, errorsManual);
277
- (0, _helpers.addToListOfRanges)(node, errorRanges);
278
- guidance[(0, _helpers.locToString)(node)] = (0, _helpers.createGuidance)({
279
- iconPackage: legacyIconImports[node.name].packageName,
280
- shouldUseMigrationPath: shouldUseMigrationPath
281
- });
282
- }
283
- };
284
-
285
- /**
286
- * Checks if a legacy icon is referenced as a prop to a component and stores the errors in the global array
287
- * @param node The property node found by ESLint
288
- */
289
- var checkIconAsProp = function checkIconAsProp(node) {
290
- if (!(0, _eslintCodemodUtils.isNodeOfType)(node, 'Identifier')) {
291
- return;
292
- }
293
- if (!node.parent || !node.parent.parent || !node.parent.parent.parent) {
294
- return;
295
- }
296
- if (!(0, _eslintCodemodUtils.isNodeOfType)(node.parent, 'JSXExpressionContainer') || !(0, _eslintCodemodUtils.isNodeOfType)(node.parent.parent, 'JSXAttribute') || !(0, _eslintCodemodUtils.isNodeOfType)(node.parent.parent.parent, 'JSXOpeningElement')) {
297
- return;
298
- }
299
- if (Object.keys(legacyIconImports).includes(node.name) && (0, _eslintCodemodUtils.isNodeOfType)(node.parent.parent.name, 'JSXIdentifier') && node.parent.parent.name.name !== 'LEGACY_fallbackIcon') {
300
- var _migrationMapObject$s;
301
- var migrationMapObject = (0, _helpers.getMigrationMapObject)(legacyIconImports[node.name].packageName);
302
- var upcomingIcon = (0, _helpers.getUpcomingIcons)(legacyIconImports[node.name].packageName);
303
- var newIcon = migrationMapObject === null || migrationMapObject === void 0 ? void 0 : migrationMapObject.newIcon;
304
- var isNewIconMigratable = (0, _helpers.canAutoMigrateNewIconBasedOnSize)(upcomingIcon ? upcomingIcon.sizeGuidance.medium : migrationMapObject === null || migrationMapObject === void 0 || (_migrationMapObject$s = migrationMapObject.sizeGuidance) === null || _migrationMapObject$s === void 0 ? void 0 : _migrationMapObject$s.medium);
305
- var isInNewButton = (0, _eslintCodemodUtils.isNodeOfType)(node.parent.parent.parent.name, 'JSXIdentifier') && newButtonImports.has(node.parent.parent.parent.name.name);
306
- if (newIcon && isInNewButton && isNewIconMigratable || upcomingIcon && isInNewButton && isNewIconMigratable) {
307
- (0, _helpers.createAutoMigrationError)({
308
- node: node,
309
- importSource: legacyIconImports[node.name].packageName,
310
- iconName: node.name,
311
- errors: errorsAuto
312
- });
313
- (0, _helpers.addToListOfRanges)(node, errorRanges);
314
- guidance[(0, _helpers.locToString)(node)] = (0, _helpers.createGuidance)({
315
- iconPackage: legacyIconImports[node.name].packageName,
316
- insideNewButton: true,
317
- size: 'medium',
318
- shouldUseMigrationPath: shouldUseMigrationPath
319
- });
320
- } else if (!newIcon && !upcomingIcon || !isNewIconMigratable) {
321
- (0, _helpers.createCantFindSuitableReplacementError)(node, legacyIconImports[node.name].packageName, node.name, errorsManual);
322
- (0, _helpers.addToListOfRanges)(node, errorRanges);
323
- guidance[(0, _helpers.locToString)(node)] = (0, _helpers.createGuidance)({
324
- iconPackage: legacyIconImports[node.name].packageName,
325
- insideNewButton: isInNewButton,
326
- shouldUseMigrationPath: shouldUseMigrationPath
327
- });
328
- } else if (!isInNewButton) {
329
- (0, _helpers.createCantMigrateFunctionUnknownError)(node, legacyIconImports[node.name].packageName, node.name, errorsManual);
330
- (0, _helpers.addToListOfRanges)(node, errorRanges);
331
- guidance[(0, _helpers.locToString)(node)] = (0, _helpers.createGuidance)({
332
- iconPackage: legacyIconImports[node.name].packageName,
333
- insideNewButton: false,
334
- shouldUseMigrationPath: shouldUseMigrationPath
335
- });
336
- }
337
- }
338
- };
339
- var checkIconReference = function checkIconReference(node) {
340
- //if this is an import statement then exit early
341
- if (node.parent && ((0, _eslintCodemodUtils.isNodeOfType)(node.parent, 'ImportSpecifier') || (0, _eslintCodemodUtils.isNodeOfType)(node.parent, 'ImportDefaultSpecifier'))) {
342
- return;
343
- }
344
-
345
- // Flag icons imported from migration path
346
- if (!shouldUseMigrationPath && Object.keys(migrationIconImports).includes(node.name)) {
347
- (0, _helpers.createAutoMigrationError)({
348
- node: node,
349
- importSource: migrationIconImports[node.name].packageName,
350
- iconName: node.name,
351
- errors: errorsAuto
352
- });
353
- }
354
-
355
- //check the reference to see if it's a legacy icon, if not exit early
356
- if (!Object.keys(legacyIconImports).includes(node.name)) {
357
- return;
358
- }
359
-
360
- //if in Fallback prop, do not error
361
- if (node.parent && node.parent.parent && (0, _eslintCodemodUtils.isNodeOfType)(node.parent.parent, 'JSXAttribute') && (0, _eslintCodemodUtils.isNodeOfType)(node.parent.parent.name, 'JSXIdentifier') && node.parent.parent.name.name === 'LEGACY_fallbackIcon') {
362
- return;
363
- }
364
- // manually error
365
- (0, _helpers.createCantMigrateIdentifierError)(node, legacyIconImports[node.name].packageName, node.name, errorsManual);
366
- };
367
-
368
- /**
369
- * Checks if a legacy icon is being rendered and stores the errors in the global array
370
- * @param node The JSX node found by ESLint
371
- */
372
- var checkJSXElement = function checkJSXElement(node) {
373
- var _node$parent, _node$parent$parent$p;
374
- if (!('openingElement' in node) || !(0, _eslintCodemodUtils.isNodeOfType)(node.openingElement.name, 'JSXIdentifier')) {
375
- return;
376
- }
377
-
378
- // Determine if element is rendered inside LEGACY_fallbackIcon prop - if so, don't perform any checks
379
- if (node.parent && (0, _eslintCodemodUtils.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 && (0, _eslintCodemodUtils.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') {
380
- return;
381
- }
382
- var name = node.openingElement.name.name;
383
-
384
- // Flag icons imported from migration path
385
- if (!shouldUseMigrationPath && Object.keys(migrationIconImports).includes(name)) {
386
- (0, _helpers.createAutoMigrationError)({
387
- node: node,
388
- importSource: migrationIconImports[name].packageName,
389
- iconName: name,
390
- errors: errorsAuto,
391
- spacing: undefined,
392
- insideNewButton: true
393
- });
394
- }
395
-
396
- // Legacy icons rendered as JSX elements
397
- if (Object.keys(legacyIconImports).includes(name)) {
398
- var _sizeProp$value2;
399
- // Determine if inside a new button - if so:
400
- // - Assume spread props are safe - still error if props explicitly set to unmigratable values
401
- var insideNewButton = (0, _helpers.isInsideNewButton)(node, newButtonImports);
402
-
403
- // Determine if inside a legacy default button - if so:
404
- // the auto fixer will add spacing prop to the medium size icon
405
- var insideLegacyButton = (0, _helpers.isInsideLegacyButton)(node, legacyButtonImports);
406
- var insideIconOnlyLegacyButton = (0, _helpers.isInsideIconOnlyLegacyButton)(node, legacyButtonImports);
407
-
408
- // Find size prop on node
409
- var size = 'medium';
410
- var primaryColor = null;
411
- var hasPrimaryColorProp = false;
412
- var hasSecondaryColorProp = false;
413
- var afterSpreadSet = new Set();
414
- var requiredAttributesAfterSpread = new Set(['size', 'primaryColor', 'secondaryColor']);
415
- var hasSpread = false;
416
- var _iterator8 = _createForOfIteratorHelper(node.openingElement.attributes),
417
- _step8;
418
- try {
419
- for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
420
- var attr = _step8.value;
421
- // Detect spread props
422
- if ((0, _eslintCodemodUtils.isNodeOfType)(attr, 'JSXSpreadAttribute')) {
423
- // In case there are more spread props
424
- afterSpreadSet.clear();
425
- hasSpread = true;
426
- continue;
427
- }
428
- if (!(0, _eslintCodemodUtils.isNodeOfType)(attr, 'JSXAttribute') || !(0, _eslintCodemodUtils.isNodeOfType)(attr.name, 'JSXIdentifier') || !attr.value) {
429
- continue;
430
- }
431
-
432
- // Register props that aren't being spread
433
- afterSpreadSet.add(attr.name.name);
434
-
435
- // Extract values of props
436
- switch (attr.name.name) {
437
- case 'size':
438
- if ((0, _eslintCodemodUtils.isNodeOfType)(attr.value, 'Literal') && (0, _helpers.isSize)(attr.value.value)) {
439
- size = attr.value.value;
440
- } else if ((0, _eslintCodemodUtils.isNodeOfType)(attr.value, 'JSXExpressionContainer') && (0, _eslintCodemodUtils.isNodeOfType)(attr.value.expression, 'Literal') && (0, _helpers.isSize)(attr.value.expression.value)) {
441
- size = attr.value.expression.value;
442
- } else {
443
- size = null;
444
- }
445
- break;
446
- case 'primaryColor':
447
- primaryColor = getPrimaryColor(attr);
448
- hasPrimaryColorProp = true;
449
- break;
450
- case 'secondaryColor':
451
- hasSecondaryColorProp = true;
452
- break;
453
- }
454
- }
455
- } catch (err) {
456
- _iterator8.e(err);
457
- } finally {
458
- _iterator8.f();
459
- }
460
- var hasManualMigration = false;
461
-
462
- // Flag manual migration if primary color cannot be migrated
463
- if (primaryColor && !(0, _helpers.canMigrateColor)(primaryColor) || hasPrimaryColorProp && !primaryColor) {
464
- (0, _helpers.createCantMigrateColorError)(node, primaryColor ? "the value of '".concat(primaryColor, "'") : 'a statically unknown value', errorsManual, legacyIconImports[name].packageName, name);
465
- hasManualMigration = true;
466
- }
467
-
468
- // If size can't be determined (i.e. size is a variable or function call, etc)
469
- // then we need to error; icon can't be auto-migrated safely
470
- if (size === null) {
471
- (0, _helpers.createCantMigrateSizeUnknown)(node, errorsManual, legacyIconImports[name].packageName, name);
472
- hasManualMigration = true;
473
- }
474
-
475
- // Do a set comparison - is requiredAttributesAfterSpread a subset of afterSpreadSet?
476
- if (hasSpread === true && !Array.from(requiredAttributesAfterSpread).every(function (val) {
477
- return afterSpreadSet.has(val);
478
- }) && !insideNewButton) {
479
- var missingProps = Array.from(requiredAttributesAfterSpread).filter(function (val) {
480
- return !afterSpreadSet.has(val);
481
- });
482
- (0, _helpers.createCantMigrateSpreadPropsError)(node, missingProps, errorsManual, legacyIconImports[name].packageName, name);
483
- hasManualMigration = true;
484
- }
485
-
486
- // Check if it is an exported component?
487
- if (legacyIconImports[name].exported) {
488
- (0, _helpers.createCantMigrateReExportError)(node, legacyIconImports[name].packageName, name, errorsManual);
489
- hasManualMigration = true;
490
- }
491
- var migrationMapObject = (0, _helpers.getMigrationMapObject)(legacyIconImports[name].packageName);
492
- var upcomingIcon = (0, _helpers.getUpcomingIcons)(legacyIconImports[name].packageName);
493
- var newIcon = migrationMapObject === null || migrationMapObject === void 0 ? void 0 : migrationMapObject.newIcon;
494
- var isNewIconMigratable = (0, _helpers.canAutoMigrateNewIconBasedOnSize)(upcomingIcon ? upcomingIcon.sizeGuidance[size !== null && size !== void 0 ? size : 'medium'] : migrationMapObject === null || migrationMapObject === void 0 ? void 0 : migrationMapObject.sizeGuidance[size !== null && size !== void 0 ? size : 'medium']);
495
-
496
- // Add spacing if:
497
- // 1. size is medium for core/utility icons or not set (default is medium for core and small for utility icons)
498
- // 2. not inside a new or legacy button (except for icon-only legacy buttons)
499
- var sizeProp = node.openingElement.attributes.find(function (attribute) {
500
- return attribute.type === 'JSXAttribute' && (attribute.name.name === 'size' || attribute.name.name === 'LEGACY_size');
501
- });
502
- var spacing;
503
- if (!insideNewButton && !(insideLegacyButton && !insideIconOnlyLegacyButton)) {
504
- var _sizeProp$value;
505
- if (sizeProp && sizeProp.type === 'JSXAttribute' && ((_sizeProp$value = sizeProp.value) === null || _sizeProp$value === void 0 ? void 0 : _sizeProp$value.type) === 'Literal') {
506
- if (sizeProp.value.value === 'medium') {
507
- spacing = 'spacious';
508
- }
509
- } else if (!sizeProp) {
510
- spacing = 'spacious';
511
- }
512
- }
513
- if (!iconSizesInfo[legacyIconImports[name].packageName]) {
514
- iconSizesInfo[legacyIconImports[name].packageName] = {
515
- small: [],
516
- usageCount: 0
517
- };
518
- }
519
-
520
- // Do not automatically migration if size is small as we cannot determine if a core icon or a scaled down utility icon should be used
521
- if (sizeProp && sizeProp.type === 'JSXAttribute' && ((_sizeProp$value2 = sizeProp.value) === null || _sizeProp$value2 === void 0 ? void 0 : _sizeProp$value2.type) === 'Literal' && sizeProp.value.value === 'small') {
522
- iconSizesInfo[legacyIconImports[name].packageName].small.push((0, _helpers.locToString)(node));
523
- }
524
- iconSizesInfo[legacyIconImports[name].packageName].usageCount++;
525
- var shouldForceSmallIcon = newIcon === null || newIcon === void 0 ? void 0 : newIcon.shouldForceSmallIcon;
526
- if (shouldUseSafeMigrationMode && !hasManualMigration && (newIcon !== null && newIcon !== void 0 && newIcon.isMigrationUnsafe || size !== 'medium' || hasSecondaryColorProp)) {
527
- (0, _helpers.createCantFindSuitableReplacementError)(node, legacyIconImports[name].packageName, name, errorsManual, upcomingIcon ? true : migrationMapObject ? true : false);
528
- } else if (!hasManualMigration && (newIcon || upcomingIcon) && isNewIconMigratable) {
529
- (0, _helpers.createAutoMigrationError)({
530
- node: node,
531
- importSource: legacyIconImports[name].packageName,
532
- iconName: name,
533
- errors: errorsAuto,
534
- spacing: spacing,
535
- insideNewButton: insideNewButton,
536
- shouldForceSmallIcon: shouldForceSmallIcon
537
- });
538
- } else if ((!newIcon && !upcomingIcon || !isNewIconMigratable) && size) {
539
- (0, _helpers.createCantFindSuitableReplacementError)(node, legacyIconImports[name].packageName, name, errorsManual, upcomingIcon ? true : migrationMapObject ? true : false);
540
- }
541
- (0, _helpers.addToListOfRanges)(node, errorRanges);
542
- guidance[(0, _helpers.locToString)(node)] = (0, _helpers.createGuidance)({
543
- iconPackage: legacyIconImports[name].packageName,
544
- insideNewButton: insideNewButton,
545
- size: size && (0, _helpers.isSize)(size) ? size : undefined,
546
- shouldUseMigrationPath: shouldUseMigrationPath,
547
- shouldForceSmallIcon: shouldForceSmallIcon
548
- });
549
- }
550
- };
551
-
552
- /**
553
- * Checks if a legacy icon is being passed into a function call and stores the errors in the global array
554
- * @param node The function call node found by ESLint
555
- */
556
- var checkCallExpression = function checkCallExpression(node) {
557
- if (Object.keys(node).includes('arguments') && node.arguments.length) {
558
- var _iterator9 = _createForOfIteratorHelper(node.arguments),
559
- _step9;
560
- try {
561
- for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
562
- var arg = _step9.value;
563
- if ((0, _eslintCodemodUtils.isNodeOfType)(arg, 'Identifier') && Object.keys(legacyIconImports).includes(arg.name) && legacyIconImports[arg.name].packageName) {
564
- (0, _helpers.createCantMigrateFunctionUnknownError)(node, legacyIconImports[arg.name].packageName, arg.name, errorsManual);
565
- (0, _helpers.addToListOfRanges)(node, errorRanges);
566
- guidance[(0, _helpers.locToString)(node)] = (0, _helpers.createGuidance)({
567
- iconPackage: legacyIconImports[arg.name].packageName,
568
- shouldUseMigrationPath: shouldUseMigrationPath
569
- });
570
- }
571
- }
572
- } catch (err) {
573
- _iterator9.e(err);
574
- } finally {
575
- _iterator9.f();
576
- }
577
- }
578
- };
579
-
580
- /**
581
- * Throws the relevant errors in the correct order based on configs.
582
- */
583
- var throwErrors = function throwErrors() {
584
- // Throw manual errors
585
- if (shouldErrorForManualMigration) {
586
- (0, _helpers.throwManualErrors)({
587
- errorsManual: errorsManual,
588
- errorRanges: errorRanges,
589
- guidance: guidance,
590
- context: context,
591
- isQuietMode: isQuietMode
592
- });
593
- }
594
- if (shouldErrorForAutoMigration) {
595
- (0, _helpers.throwAutoErrors)({
596
- errorsManual: errorsManual,
597
- errorsAuto: errorsAuto,
598
- iconSizesInfo: iconSizesInfo,
599
- legacyIconImports: legacyIconImports,
600
- guidance: guidance,
601
- migrationIconImports: migrationIconImports,
602
- shouldUseMigrationPath: shouldUseMigrationPath,
603
- context: context
604
- });
605
- }
606
- };
607
- return {
608
- checkImportDeclarations: checkImportDeclarations,
609
- checkVariableDeclarations: checkVariableDeclarations,
610
- checkExportDefaultDeclaration: checkExportDefaultDeclaration,
611
- checkExportNamedVariables: checkExportNamedVariables,
612
- checkArrayOrMap: checkArrayOrMap,
613
- checkIconAsProp: checkIconAsProp,
614
- checkJSXElement: checkJSXElement,
615
- checkCallExpression: checkCallExpression,
616
- throwErrors: throwErrors,
617
- checkIconReference: checkIconReference
618
- };
619
- };