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