@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,900 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- var _typeof = require("@babel/runtime/helpers/typeof");
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.throwManualErrors = exports.throwAutoErrors = exports.locToString = exports.isSize = exports.isInsideNewButton = exports.isInsideLegacyButton = exports.isInsideIconOnlyLegacyButton = exports.getUpcomingIcons = exports.getMigrationMapObject = exports.getComponentName = exports.createHelpers = exports.createGuidance = exports.createCantMigrateSpreadPropsError = exports.createCantMigrateSizeUnknown = exports.createCantMigrateReExportError = exports.createCantMigrateIdentifierMapOrArrayError = exports.createCantMigrateIdentifierError = exports.createCantMigrateFunctionUnknownError = exports.createCantMigrateColorError = exports.createCantFindSuitableReplacementError = exports.createAutoMigrationError = exports.canMigrateColor = exports.canAutoMigrateNewIconBasedOnSize = exports.addToListOfRanges = void 0;
9
- var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
10
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
- var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
12
- var _eslintCodemodUtils = require("eslint-codemod-utils");
13
- var _migrationMap = _interopRequireWildcard(require("@atlaskit/icon/migration-map"));
14
- var _upcomingIcons = require("./upcoming-icons");
15
- function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
16
- function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
17
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
18
- 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; } } }; }
19
- 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; } }
20
- 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; }
21
- var sizes = ['small', 'medium', 'large', 'xlarge'];
22
- var isSize = exports.isSize = function isSize(size) {
23
- return sizes.includes(size);
24
- };
25
-
26
- /**
27
- * Returns the migration map object for a legacy icon or null if not found
28
- * @param iconPackage The name of the legacy icon package
29
- * @returns The migration map object for the legacy icon or null if not found
30
- */
31
- var getMigrationMapObject = exports.getMigrationMapObject = function getMigrationMapObject(iconPackage) {
32
- var key = getIconKey(iconPackage);
33
- if (Object.keys(_migrationMap.default).includes(key)) {
34
- return _migrationMap.default[key];
35
- }
36
- return null;
37
- };
38
- var getUpcomingIcons = exports.getUpcomingIcons = function getUpcomingIcons(iconPackage) {
39
- var key = getIconKey(iconPackage);
40
- if (_upcomingIcons.upcomingIcons.includes(key)) {
41
- var retval = {
42
- sizeGuidance: {
43
- small: 'swap',
44
- medium: 'swap',
45
- large: 'icon-tile',
46
- xlarge: 'icon-tile'
47
- }
48
- };
49
- return retval;
50
- }
51
- return null;
52
- };
53
-
54
- /**
55
- * Returns the key of a legacy icon
56
- * @param iconPackage The name of the legacy icon package
57
- * @returns The unique identifier for the icon (the part after "@atlaskit/icon/glyph")
58
- */
59
- var getIconKey = function getIconKey(iconPackage) {
60
- var key = iconPackage.replace(/^@atlaskit\/icon\/glyph\//, '');
61
- return key;
62
- };
63
-
64
- /**
65
- * Checks if a new icon can be auto-migrated based on guidance from the migration map
66
- */
67
- var canAutoMigrateNewIconBasedOnSize = exports.canAutoMigrateNewIconBasedOnSize = function canAutoMigrateNewIconBasedOnSize(guidance) {
68
- return guidance ? ['swap', 'swap-slight-visual-change', 'swap-visual-change'].includes(guidance) : false;
69
- };
70
-
71
- /**
72
- *
73
- * @param iconPackage string
74
- * @returns object of new icon name and import path
75
- */
76
- var getNewIconNameAndImportPath = function getNewIconNameAndImportPath(iconPackage, shouldUseMigrationPath) {
77
- var legacyIconName = getIconKey(iconPackage);
78
- var migrationMapObject = getMigrationMapObject(iconPackage);
79
- if (!migrationMapObject || !migrationMapObject.newIcon) {
80
- return {};
81
- }
82
- var newIcon = migrationMapObject.newIcon;
83
- var migrationPath = newIcon.name === legacyIconName ? "".concat(newIcon.package, "/core/migration/").concat(newIcon.name) : "".concat(newIcon.package, "/core/migration/").concat(newIcon.name, "--").concat(legacyIconName.replaceAll('/', '-'));
84
- return {
85
- iconName: newIcon.name,
86
- importPath: shouldUseMigrationPath ? migrationPath : "".concat(newIcon.package, "/core/").concat(newIcon.name)
87
- };
88
- };
89
-
90
- /**
91
- * Creates the written guidance for migrating a legacy icon to a new icon
92
- */
93
- var createGuidance = exports.createGuidance = function createGuidance(_ref) {
94
- var iconPackage = _ref.iconPackage,
95
- insideNewButton = _ref.insideNewButton,
96
- initialSize = _ref.size,
97
- shouldUseMigrationPath = _ref.shouldUseMigrationPath,
98
- shouldForceSmallIcon = _ref.shouldForceSmallIcon;
99
- var size = shouldForceSmallIcon ? 'small' : initialSize;
100
- var migrationMapObject = getMigrationMapObject(iconPackage);
101
- var upcomingIcon = getUpcomingIcons(iconPackage);
102
- if (upcomingIcon) {
103
- var guidance = '';
104
- if (size) {
105
- if (upcomingIcon.sizeGuidance[size] && canAutoMigrateNewIconBasedOnSize(upcomingIcon.sizeGuidance[size])) {
106
- guidance += "Fix: An upcoming icon release is planned to migrate this legacy icon.";
107
- } else {
108
- guidance += "No equivalent icon for this size, ".concat(size, ", in the current or upcoming set of icons.");
109
- }
110
- guidance += "".concat(Object.keys(_migrationMap.migrationOutcomeDescriptionMap).includes(upcomingIcon.sizeGuidance[size]) ? " Once the upcoming icons are released, please: ".concat(_migrationMap.migrationOutcomeDescriptionMap[upcomingIcon.sizeGuidance[size]]) : ' No migration size advice given.', "\n");
111
- } else {
112
- guidance = "Please wait for the upcoming icons released, as it will contain an alternative for this legacy icon.\nMigration suggestions, depending on the legacy icon size:\n";
113
- for (var _i = 0, _Object$entries = Object.entries(upcomingIcon.sizeGuidance); _i < _Object$entries.length; _i++) {
114
- var _Object$entries$_i = (0, _slicedToArray2.default)(_Object$entries[_i], 2),
115
- _size = _Object$entries$_i[0],
116
- value = _Object$entries$_i[1];
117
- guidance += "\t- ".concat(_size, ": ");
118
- if (!Object.keys(_migrationMap.migrationOutcomeDescriptionMap).includes(value)) {
119
- guidance += 'No migration advice given.\n';
120
- } else {
121
- guidance += "".concat(_migrationMap.migrationOutcomeDescriptionMap[value], ".\n");
122
- }
123
- }
124
- }
125
- return guidance;
126
- } else if (migrationMapObject) {
127
- var newIcon = migrationMapObject.newIcon;
128
- if (!newIcon) {
129
- return 'No equivalent icon in new set. An option is to contribute a custom icon into icon-labs package instead.\n';
130
- }
131
- var _getNewIconNameAndImp = getNewIconNameAndImportPath(iconPackage, shouldUseMigrationPath),
132
- iconName = _getNewIconNameAndImp.iconName,
133
- importPath = _getNewIconNameAndImp.importPath;
134
- var buttonGuidanceStr = "Please set 'spacing' property of the new icon to 'none', to ensure appropriate spacing inside `@atlaskit/button`.\n";
135
- var _guidance = '';
136
- if (size) {
137
- if (migrationMapObject.sizeGuidance[size] && canAutoMigrateNewIconBasedOnSize(migrationMapObject.sizeGuidance[size])) {
138
- _guidance += "Fix: Use ".concat(iconName, " from ").concat(importPath, " instead.");
139
- } else {
140
- _guidance += "No equivalent icon for this size, ".concat(size, ", in new set.");
141
- }
142
- _guidance += "".concat(Object.keys(_migrationMap.migrationOutcomeDescriptionMap).includes(migrationMapObject.sizeGuidance[size]) ? " Please: ".concat(_migrationMap.migrationOutcomeDescriptionMap[migrationMapObject.sizeGuidance[size]]) : ' No migration size advice given.', "\n");
143
- } else {
144
- _guidance = "Use ".concat(iconName, " from ").concat(importPath, " instead.\nMigration suggestions, depending on the legacy icon size:\n");
145
- Object.entries(migrationMapObject.sizeGuidance).forEach(function (_ref2) {
146
- var _ref3 = (0, _slicedToArray2.default)(_ref2, 2),
147
- size = _ref3[0],
148
- value = _ref3[1];
149
- _guidance += "\t- ".concat(size, ": ");
150
- if (!Object.keys(_migrationMap.migrationOutcomeDescriptionMap).includes(value)) {
151
- _guidance += 'No migration advice given.\n';
152
- } else {
153
- _guidance += "".concat(_migrationMap.migrationOutcomeDescriptionMap[value], ".\n");
154
- }
155
- });
156
- }
157
- if (insideNewButton) {
158
- _guidance += buttonGuidanceStr;
159
- } else if (size === 'medium') {
160
- _guidance += "Setting the spacing='spacious' will maintain the icon's box dimensions - but consider setting spacing='none' as it allows for easier control of spacing by parent elements.\n";
161
- } else if (size === 'small') {
162
- if (initialSize !== 'small' && shouldForceSmallIcon) {
163
- _guidance += "For this icon, it's recommended to use a smaller size using size='small'. Alternatively, for special cases where a larger version is needed size='medium' can be used, but it is generally discouraged for this icon.\n";
164
- } else if (initialSize === 'small') {
165
- if (shouldForceSmallIcon) {
166
- _guidance += "Setting spacing='compact' will maintain the icon's box dimensions - but consider setting spacing='none' as it allows for easier control of spacing by parent elements.\n";
167
- } else {
168
- _guidance += "It's recommended to upscale to a medium icon with no spacing. Alternatively for special cases where smaller icons are required, the original icon size and dimensions can be maintained by using size='small' and spacing='compact'.\n";
169
- }
170
- }
171
- } else if (size) {
172
- _guidance += "In the new icon, please use spacing='none'.\n";
173
- }
174
- return _guidance;
175
- } else {
176
- return "Migration suggestions not found for \"".concat(iconPackage, "\".\n");
177
- }
178
- };
179
-
180
- /**
181
- * Checks if the color can be migrated
182
- * @param color String representing the color to check
183
- * @returns True if the color can be migrated, false otherwise
184
- */
185
- var canMigrateColor = exports.canMigrateColor = function canMigrateColor(color) {
186
- if (color.match(/^color\.icon/)) {
187
- return true;
188
- } else if (color.match(/^color\.link/)) {
189
- return true;
190
- } else if (color.match(/^color\.text/)) {
191
- return true;
192
- } else if (color === 'currentColor') {
193
- return true;
194
- } else {
195
- return false;
196
- }
197
- };
198
- var locToString = exports.locToString = function locToString(node) {
199
- if (node.range && node.range.length >= 2) {
200
- return "".concat(node.range[0], ":").concat(node.range[1]);
201
- } else {
202
- return '';
203
- }
204
- };
205
- var createCantMigrateReExportError = exports.createCantMigrateReExportError = function createCantMigrateReExportError(node, packageName, exportName, errors) {
206
- var myError = {
207
- node: node,
208
- messageId: 'cantMigrateReExport',
209
- data: {
210
- packageName: packageName,
211
- exportName: exportName
212
- }
213
- };
214
- pushManualError(locToString(node), errors, myError, packageName, exportName);
215
- };
216
- var createCantMigrateIdentifierMapOrArrayError = exports.createCantMigrateIdentifierMapOrArrayError = function createCantMigrateIdentifierMapOrArrayError(node, packageName, exportName, errors) {
217
- var myError = {
218
- node: node,
219
- messageId: 'cantMigrateIdentifierMapOrArray',
220
- data: {
221
- packageName: packageName,
222
- exportName: exportName
223
- }
224
- };
225
- pushManualError(locToString(node), errors, myError, packageName, exportName);
226
- };
227
- var createCantMigrateIdentifierError = exports.createCantMigrateIdentifierError = function createCantMigrateIdentifierError(node, packageName, exportName, errors) {
228
- var myError = {
229
- node: node,
230
- messageId: 'cantMigrateIdentifier',
231
- data: {
232
- iconSource: packageName,
233
- iconName: exportName
234
- }
235
- };
236
- pushManualError(locToString(node), errors, myError, packageName, exportName);
237
- };
238
- var createCantFindSuitableReplacementError = exports.createCantFindSuitableReplacementError = function createCantFindSuitableReplacementError(node, importSource, iconName, errors, sizeIssue) {
239
- var myError = {
240
- node: node,
241
- messageId: 'cantFindSuitableReplacement',
242
- data: {
243
- importSource: importSource,
244
- iconName: iconName,
245
- sizeGuidance: sizeIssue ? ' at the current size' : ''
246
- }
247
- };
248
- pushManualError(locToString(node), errors, myError, importSource, iconName);
249
- };
250
- var createCantMigrateFunctionUnknownError = exports.createCantMigrateFunctionUnknownError = function createCantMigrateFunctionUnknownError(node, importSource, iconName, errors) {
251
- var myError = {
252
- node: node,
253
- messageId: 'cantMigrateFunctionUnknown',
254
- data: {
255
- importSource: importSource,
256
- iconName: iconName
257
- }
258
- };
259
- pushManualError(locToString(node), errors, myError, importSource, iconName);
260
- };
261
- var createCantMigrateColorError = exports.createCantMigrateColorError = function createCantMigrateColorError(node, colorValue, errors, importSource, iconName) {
262
- var myError = {
263
- node: node,
264
- messageId: 'cantMigrateColor',
265
- data: {
266
- colorValue: colorValue
267
- }
268
- };
269
- pushManualError(locToString(node), errors, myError, importSource, iconName);
270
- };
271
- var createCantMigrateSpreadPropsError = exports.createCantMigrateSpreadPropsError = function createCantMigrateSpreadPropsError(node, missingProps, errors, importSource, iconName) {
272
- var myError = {
273
- node: node,
274
- messageId: 'cantMigrateSpreadProps',
275
- data: {
276
- missingProps: missingProps.join(', ')
277
- }
278
- };
279
- pushManualError(locToString(node), errors, myError, importSource, iconName);
280
- };
281
- var createCantMigrateSizeUnknown = exports.createCantMigrateSizeUnknown = function createCantMigrateSizeUnknown(node, errors, importSource, iconName) {
282
- var myError = {
283
- node: node,
284
- messageId: 'cantMigrateSizeUnknown'
285
- };
286
- pushManualError(locToString(node), errors, myError, importSource, iconName);
287
- };
288
- var createAutoMigrationError = exports.createAutoMigrationError = function createAutoMigrationError(_ref4) {
289
- var node = _ref4.node,
290
- importSource = _ref4.importSource,
291
- iconName = _ref4.iconName,
292
- errors = _ref4.errors,
293
- spacing = _ref4.spacing,
294
- insideNewButton = _ref4.insideNewButton,
295
- shouldForceSmallIcon = _ref4.shouldForceSmallIcon;
296
- var myError = {
297
- node: node,
298
- messageId: 'noLegacyIconsAutoMigration',
299
- data: {
300
- importSource: importSource,
301
- iconName: iconName,
302
- spacing: spacing !== null && spacing !== void 0 ? spacing : '',
303
- // value type need to be a string in Rule.ReportDescriptor
304
- insideNewButton: String(insideNewButton),
305
- shouldForceSmallIcon: String(shouldForceSmallIcon)
306
- }
307
- };
308
- errors[locToString(node)] = myError;
309
- };
310
- var pushManualError = function pushManualError(key, errors, myError, importSource, iconName) {
311
- if (Object.keys(errors).includes(key)) {
312
- errors[key].errors.push(myError);
313
- } else {
314
- errors[key] = {
315
- errors: [myError],
316
- importSource: importSource,
317
- iconName: iconName
318
- };
319
- }
320
- };
321
- var getLiteralStringValue = function getLiteralStringValue(value) {
322
- if (!value) {
323
- return;
324
- }
325
-
326
- // propName="value"
327
- if ((0, _eslintCodemodUtils.isNodeOfType)(value, 'Literal') && typeof value.value === 'string') {
328
- return value.value;
329
- }
330
-
331
- // propName={"value"}
332
- if ((0, _eslintCodemodUtils.isNodeOfType)(value, 'JSXExpressionContainer') && (0, _eslintCodemodUtils.isNodeOfType)(value.expression, 'Literal') && typeof value.expression.value === 'string') {
333
- return value.expression.value;
334
- }
335
- return;
336
- };
337
- var createHelpers = exports.createHelpers = function createHelpers(ctx) {
338
- // TODO: JFP-2823 - this type cast was added due to Jira's ESLint v9 migration
339
- var context = ctx;
340
- /**
341
- * Extracts the token name of a token() call from a JSXExpressionContainer
342
- * @param value The JSXExpressionContainer to extract the token call from
343
- * @returns The value of the token call, or null if it could not be extracted
344
- */
345
- var getTokenCallValue = function getTokenCallValue(value) {
346
- /**
347
- * Previously, we used getImportName() to extract the token name from a token() call.
348
- * However, this was failing in the Issue Automat so we are now using a simpler approach.
349
- */
350
-
351
- if ((0, _eslintCodemodUtils.isNodeOfType)(value, 'JSXExpressionContainer') && (0, _eslintCodemodUtils.isNodeOfType)(value.expression, 'CallExpression') && 'name' in value.expression.callee && value.expression.callee.name === 'token') {
352
- // propName={token("color...."}
353
- return getLiteralStringValue(value.expression.arguments[0]);
354
- }
355
- return;
356
- };
357
-
358
- /**
359
- * Gets the value of a boolean configuration flag
360
- * @param key the key of the configuration flag
361
- * @param defaultValue The default value of the configuration flag
362
- * @returns defaultValue if the configuration flag is not set, the defaultValue of the configuration flag otherwise
363
- */
364
- var getConfigFlag = function getConfigFlag(key, defaultValue) {
365
- if (context.options.length > 0 && context.options[0] && Object.keys(context.options[0]).includes(key)) {
366
- return context.options[0][key] === !defaultValue ? !defaultValue : defaultValue;
367
- }
368
- return defaultValue;
369
- };
370
- return {
371
- /**
372
- * Extracts the primaryColor value from a JSXAttribute
373
- */
374
- getPrimaryColor: function getPrimaryColor(attr) {
375
- var _ref5, _getLiteralStringValu;
376
- var value = attr.value;
377
- return (_ref5 = (_getLiteralStringValu = getLiteralStringValue(value)) !== null && _getLiteralStringValu !== void 0 ? _getLiteralStringValu : getTokenCallValue(value)) !== null && _ref5 !== void 0 ? _ref5 : null;
378
- },
379
- getTokenCallValue: getTokenCallValue,
380
- getConfigFlag: getConfigFlag
381
- };
382
- };
383
- var addToListOfRanges = exports.addToListOfRanges = function addToListOfRanges(node, sortedListOfRangesForErrors) {
384
- if (node.range && node.range.length >= 2) {
385
- sortedListOfRangesForErrors.push({
386
- start: node.range[0],
387
- end: node.range[1]
388
- });
389
- }
390
- };
391
- var isInRangeList = function isInRangeList(node, sortedListOfRangesForErrors) {
392
- var range = node.range;
393
- if (!range || range.length < 2) {
394
- return false;
395
- }
396
- var found = sortedListOfRangesForErrors.find(function (currRange) {
397
- return range[0] >= currRange.start && range[1] <= currRange.end;
398
- });
399
- return !!found;
400
- };
401
-
402
- /**
403
- *
404
- * @param node Icon JSXelement
405
- * @param newButtonImports list of new button import specifiers
406
- * @returns if Icon is inside a new button
407
- */
408
- var isInsideNewButton = exports.isInsideNewButton = function isInsideNewButton(node, newButtonImports) {
409
- var _node$parent, _node$parent2;
410
- var insideNewButton = false;
411
- 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') && (0, _eslintCodemodUtils.isNodeOfType)(node.parent.parent.parent.name, 'JSXIdentifier') && (_node$parent2 = node.parent) !== null && _node$parent2 !== void 0 && (_node$parent2 = _node$parent2.parent) !== null && _node$parent2 !== void 0 && (_node$parent2 = _node$parent2.parent) !== null && _node$parent2 !== void 0 && _node$parent2.parent && (0, _eslintCodemodUtils.isNodeOfType)(node.parent.parent.parent.parent, 'JSXOpeningElement') && (0, _eslintCodemodUtils.isNodeOfType)(node.parent.parent.parent.parent.name, 'JSXIdentifier') && newButtonImports.has(node.parent.parent.parent.parent.name.name)) {
412
- insideNewButton = true;
413
- }
414
- return insideNewButton;
415
- };
416
-
417
- /**
418
- *
419
- * @param node Icon JSXelement
420
- * @param newButtonImports list of legacy button import specifiers
421
- * @returns if Icon is inside a legacy button
422
- */
423
- var isInsideLegacyButton = exports.isInsideLegacyButton = function isInsideLegacyButton(node, legacyButtonImports) {
424
- var _node$parent3, _node$parent4, _node$parent5, _node$parent6;
425
- return node.parent && (0, _eslintCodemodUtils.isNodeOfType)(node.parent, 'JSXExpressionContainer') && ((_node$parent3 = node.parent) === null || _node$parent3 === void 0 ? void 0 : _node$parent3.parent) && (0, _eslintCodemodUtils.isNodeOfType)(node.parent.parent, 'JSXAttribute') && (node.parent.parent.name.name === 'iconBefore' || node.parent.parent.name.name === 'iconAfter') && (0, _eslintCodemodUtils.isNodeOfType)((_node$parent4 = node.parent) === null || _node$parent4 === void 0 || (_node$parent4 = _node$parent4.parent) === null || _node$parent4 === void 0 ? void 0 : _node$parent4.parent, 'JSXOpeningElement') && (0, _eslintCodemodUtils.isNodeOfType)((_node$parent5 = node.parent) === null || _node$parent5 === void 0 || (_node$parent5 = _node$parent5.parent) === null || _node$parent5 === void 0 ? void 0 : _node$parent5.parent.name, 'JSXIdentifier') && legacyButtonImports.has((_node$parent6 = node.parent) === null || _node$parent6 === void 0 || (_node$parent6 = _node$parent6.parent) === null || _node$parent6 === void 0 ? void 0 : _node$parent6.parent.name.name);
426
- };
427
-
428
- /**
429
- *
430
- * @param node Icon JSXelement
431
- * @param newButtonImports list of legacy button import specifiers
432
- * @returns if Icon is inside a legacy button
433
- */
434
- var isInsideIconOnlyLegacyButton = exports.isInsideIconOnlyLegacyButton = function isInsideIconOnlyLegacyButton(node, legacyButtonImports) {
435
- var insideIconOnlyLegacyButton = false;
436
- if (isInsideLegacyButton(node, legacyButtonImports)) {
437
- var _node$parent7, _node$parent8, _node$parent9, _node$parent0, _node$parent1, _node$parent10;
438
- var legacyButtonAttributes = node.parent && (0, _eslintCodemodUtils.isNodeOfType)(node.parent, 'JSXExpressionContainer') && (_node$parent7 = node.parent) !== null && _node$parent7 !== void 0 && _node$parent7.parent && (0, _eslintCodemodUtils.isNodeOfType)(node.parent.parent, 'JSXAttribute') && node.parent.parent.parent && (0, _eslintCodemodUtils.isNodeOfType)((_node$parent8 = node.parent) === null || _node$parent8 === void 0 || (_node$parent8 = _node$parent8.parent) === null || _node$parent8 === void 0 ? void 0 : _node$parent8.parent, 'JSXOpeningElement') ? (_node$parent9 = node.parent) === null || _node$parent9 === void 0 || (_node$parent9 = _node$parent9.parent) === null || _node$parent9 === void 0 ? void 0 : _node$parent9.parent.attributes.map(function (attribute) {
439
- var _attribute$name;
440
- return (0, _eslintCodemodUtils.isNodeOfType)(attribute, 'JSXAttribute') && (0, _eslintCodemodUtils.isNodeOfType)(attribute.name, 'JSXIdentifier') && (attribute === null || attribute === void 0 || (_attribute$name = attribute.name) === null || _attribute$name === void 0 ? void 0 : _attribute$name.name);
441
- }).filter(Boolean) : [];
442
- var hasIconBefore = legacyButtonAttributes.includes('iconBefore');
443
- var hasIconAfter = legacyButtonAttributes.includes('iconAfter');
444
- var hasChildren = ((_node$parent0 = node.parent) === null || _node$parent0 === void 0 || (_node$parent0 = _node$parent0.parent) === null || _node$parent0 === void 0 || (_node$parent0 = _node$parent0.parent) === null || _node$parent0 === void 0 ? void 0 : _node$parent0.parent) && (0, _eslintCodemodUtils.isNodeOfType)((_node$parent1 = node.parent) === null || _node$parent1 === void 0 || (_node$parent1 = _node$parent1.parent) === null || _node$parent1 === void 0 || (_node$parent1 = _node$parent1.parent) === null || _node$parent1 === void 0 ? void 0 : _node$parent1.parent, 'JSXElement') && ((_node$parent10 = node.parent) === null || _node$parent10 === void 0 || (_node$parent10 = _node$parent10.parent) === null || _node$parent10 === void 0 || (_node$parent10 = _node$parent10.parent) === null || _node$parent10 === void 0 ? void 0 : _node$parent10.parent.children.length) > 0;
445
- if (hasIconBefore && !hasIconAfter && !hasChildren || !hasIconBefore && hasIconAfter && !hasChildren || !hasIconBefore && !hasIconAfter && hasChildren) {
446
- insideIconOnlyLegacyButton = true;
447
- }
448
- }
449
- return insideIconOnlyLegacyButton;
450
- };
451
- var findProp = function findProp(attributes, propName) {
452
- return attributes.find(function (attr) {
453
- return attr.type === 'JSXAttribute' && attr.name.name === propName;
454
- });
455
- };
456
- var getNewIconNameForRenaming = function getNewIconNameForRenaming(isInManualArray, importSource, importSpecifier) {
457
- var newIconName;
458
- if (isInManualArray) {
459
- newIconName = getNewIconNameAndImportPath(importSource).iconName;
460
- var keyToName = newIconName ? getComponentName(newIconName) : undefined;
461
- newIconName = keyToName;
462
- if (newIconName === undefined || importSpecifier === keyToName) {
463
- newIconName = "".concat(keyToName, "New");
464
- }
465
- }
466
- return newIconName;
467
- };
468
- var getComponentName = exports.getComponentName = function getComponentName(name) {
469
- return name.split(/\W/).map(function (part) {
470
- return "".concat(part[0].toUpperCase()).concat(part.slice(1));
471
- }).join('').concat('Icon');
472
- };
473
-
474
- /**
475
- *
476
- * Creates a list of fixers to update the icon import path
477
- * @param metadata Metadata including the import source and spacing
478
- * @param fixer The original fix function
479
- * @param legacyImportNode The import declaration node to replace
480
- * @param shouldUseMigrationPath The eslint rule config, whether to use migration entrypoint or not
481
- * @param migrationImportNode The migration import declaration node to replace, only present if shouldUseMigrationPath is false
482
- * @returns A list of fixers to migrate the icon
483
- */
484
- var createImportFix = function createImportFix(_ref6) {
485
- var fixer = _ref6.fixer,
486
- legacyImportNode = _ref6.legacyImportNode,
487
- metadata = _ref6.metadata,
488
- shouldUseMigrationPath = _ref6.shouldUseMigrationPath,
489
- migrationImportNode = _ref6.migrationImportNode,
490
- newIconName = _ref6.newIconName;
491
- var fixes = [];
492
- var importSource = metadata.importSource;
493
- var importPath = migrationImportNode ? importSource.replace('/migration', '').split('--')[0] : getNewIconNameAndImportPath(importSource, shouldUseMigrationPath).importPath;
494
- var useMigrationPath = legacyImportNode && importPath;
495
- var useFinalPath = migrationImportNode && !shouldUseMigrationPath && importPath;
496
- var programNode = legacyImportNode && findProgramNode(legacyImportNode);
497
- if (useMigrationPath) {
498
- if (newIconName) {
499
- var isExisting = programNode ? alreadyHasImportedLocalName(programNode, newIconName, importPath) : false;
500
- if (!isExisting) {
501
- fixes.push(fixer.insertTextBefore(legacyImportNode, "import ".concat(newIconName, " from '").concat(importPath, "';\n")));
502
- }
503
- } else {
504
- fixes.push(fixer.replaceText(legacyImportNode.source, "'".concat((0, _eslintCodemodUtils.literal)(importPath), "'")));
505
- }
506
- } else if (useFinalPath) {
507
- if (newIconName) {
508
- var _isExisting = programNode ? alreadyHasImportedLocalName(programNode, newIconName, importPath) : false;
509
- if (!_isExisting) {
510
- fixes.push(fixer.insertTextBefore(migrationImportNode, "import ".concat(newIconName, " from '").concat(importPath, "';\n")));
511
- }
512
- } else {
513
- fixes.push(fixer.replaceText(migrationImportNode.source, "'".concat((0, _eslintCodemodUtils.literal)(importPath), "'")));
514
- }
515
- }
516
- return fixes;
517
- };
518
-
519
- /**
520
- * Creates a list of fixers to update the icon props
521
- * @param node The Icon element to migrate
522
- * @param metadata Metadata including the import source and spacing
523
- * @param fixer The original fix function
524
- * @param legacyImportNode The import declaration node to replace
525
- * @param shouldUseMigrationPath The eslint rule config, whether to use migration entrypoint or not
526
- * @param migrationImportNode The migration import declaration node to replace, only present if shouldUseMigrationPath is false
527
- * @returns A list of fixers to migrate the icon
528
- */
529
- var createPropFixes = function createPropFixes(_ref7) {
530
- var node = _ref7.node,
531
- fixer = _ref7.fixer,
532
- legacyImportNode = _ref7.legacyImportNode,
533
- metadata = _ref7.metadata,
534
- shouldUseMigrationPath = _ref7.shouldUseMigrationPath,
535
- migrationImportNode = _ref7.migrationImportNode,
536
- newIconName = _ref7.newIconName;
537
- var fixes = [];
538
- var spacing = metadata.spacing,
539
- size = metadata.size,
540
- importSource = metadata.importSource;
541
- if (shouldUseMigrationPath && !legacyImportNode) {
542
- return fixes;
543
- }
544
- if (node.type === 'JSXElement') {
545
- var openingElement = node.openingElement;
546
- if (newIconName) {
547
- fixes.push(fixer.replaceText(openingElement.name, newIconName));
548
- }
549
- var attributes = openingElement.attributes;
550
-
551
- // replace primaryColor prop with color
552
- var primaryColor = findProp(attributes, 'primaryColor');
553
- if (primaryColor && primaryColor.type === 'JSXAttribute') {
554
- fixes.push(fixer.replaceText(primaryColor.name, 'color'));
555
- }
556
- var sizeProp = findProp(attributes, 'size');
557
- var spacingProp = findProp(attributes, 'spacing');
558
- if (sizeProp && sizeProp.type === 'JSXAttribute') {
559
- if (shouldUseMigrationPath) {
560
- // Rename existing size prop to LEGACY_size and add new size prop if applicable
561
- fixes.push(fixer.replaceText(sizeProp.name, 'LEGACY_size'));
562
- if (size) {
563
- fixes.push(fixer.insertTextAfter(sizeProp, " size=\"".concat(size, "\"")));
564
- }
565
- } else {
566
- if (size && sizeProp.value) {
567
- // update size prop with new replacement size
568
- fixes.push(fixer.replaceText(sizeProp.value, "\"".concat(size, "\"")));
569
- } else if (importSource.startsWith('@atlaskit/icon/glyph/')) {
570
- // only remove size prop for glyph entry points if no new replacement size is specified
571
- fixes.push(fixer.remove(sizeProp));
572
- } else if (sizeProp.value && sizeProp.value.type === 'Literal' && typeof sizeProp.value.value === 'string' && sizeProp.value.value === 'medium') {
573
- // if size is medium, we can remove it as it is the default size
574
- fixes.push(fixer.remove(sizeProp));
575
- }
576
- }
577
- } else if (size) {
578
- fixes.push(fixer.insertTextAfter(openingElement.name, " size=\"".concat(size, "\"")));
579
- }
580
-
581
- // Add spacing prop if no existing spacing prop and icon is not imported from migration entrypoint
582
- if (spacing && spacing !== 'none' && !spacingProp && !migrationImportNode) {
583
- fixes.push(fixer.insertTextAfter(sizeProp || openingElement.name, " spacing=\"".concat(spacing, "\"")));
584
- }
585
-
586
- // rename or remove secondaryColor prop based on shouldUseMigrationPath
587
- var secondaryColorProp = findProp(attributes, 'secondaryColor');
588
- if (secondaryColorProp && secondaryColorProp.type === 'JSXAttribute') {
589
- fixes.push(shouldUseMigrationPath ?
590
- // replace secondaryColor prop with LEGACY_secondaryColor
591
- fixer.replaceText(secondaryColorProp.name, 'LEGACY_secondaryColor') :
592
- // remove secondaryColor prop if shouldUseMigrationPath is false
593
- fixer.remove(secondaryColorProp));
594
- }
595
-
596
- // remove LEGACY props
597
- if (!shouldUseMigrationPath) {
598
- ['LEGACY_size', 'LEGACY_margin', 'LEGACY_fallbackIcon', 'LEGACY_secondaryColor'].forEach(function (propName) {
599
- var legacyProp = findProp(attributes, propName);
600
- if (legacyProp && legacyProp.type === 'JSXAttribute') {
601
- fixes.push(fixer.remove(legacyProp));
602
- }
603
- });
604
- }
605
- } else if (node.type === 'Identifier' && newIconName) {
606
- fixes.push(fixer.replaceText(node, newIconName));
607
- }
608
- return fixes;
609
- };
610
-
611
- /**
612
- * Check if the new icon exists in the migration map
613
- */
614
- var checkIfNewIconExist = function checkIfNewIconExist(error) {
615
- var _error$data;
616
- if (!((_error$data = error.data) !== null && _error$data !== void 0 && _error$data.importSource)) {
617
- return false;
618
- }
619
- var iconKey = getIconKey(error.data.importSource);
620
- var _ref8 = _migrationMap.default[iconKey] || {},
621
- newIcon = _ref8.newIcon;
622
- return Boolean(newIcon);
623
- };
624
- var throwManualErrors = exports.throwManualErrors = function throwManualErrors(_ref9) {
625
- var errorsManual = _ref9.errorsManual,
626
- errorRanges = _ref9.errorRanges,
627
- guidance = _ref9.guidance,
628
- context = _ref9.context,
629
- isQuietMode = _ref9.isQuietMode;
630
- for (var _i2 = 0, _Object$entries2 = Object.entries(errorsManual); _i2 < _Object$entries2.length; _i2++) {
631
- var _Object$entries2$_i = (0, _slicedToArray2.default)(_Object$entries2[_i2], 2),
632
- _key = _Object$entries2$_i[0],
633
- errorList = _Object$entries2$_i[1];
634
- var node = 'node' in errorList.errors[0] ? errorList.errors[0].node : null;
635
- if (!node) {
636
- return;
637
- }
638
- var cantMigrateIdentifierError = errorList.errors.find(function (x) {
639
- return 'messageId' in x && x.messageId === 'cantMigrateIdentifier';
640
- });
641
- var isInRange = false;
642
- if (cantMigrateIdentifierError && isInRangeList(node, errorRanges)) {
643
- isInRange = true;
644
- }
645
- if (isInRange && errorList.errors.length - 1 > 0 || !isInRange && errorList.errors.length > 0) {
646
- var guidanceMessage = Object.keys(guidance).includes(_key) ? guidance[_key] : '';
647
- context.report({
648
- node: node,
649
- messageId: 'noLegacyIconsManualMigration',
650
- data: {
651
- iconName: errorList.iconName,
652
- importSource: errorList.importSource,
653
- guidance: isQuietMode ? guidanceMessage : "".concat(guidanceMessage, "For more information see the below errors.\n")
654
- }
655
- });
656
- if (!isQuietMode) {
657
- var _iterator = _createForOfIteratorHelper(errorList.errors),
658
- _step;
659
- try {
660
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
661
- var error = _step.value;
662
- if ('messageId' in error && (error.messageId !== 'cantMigrateIdentifier' || error.messageId === 'cantMigrateIdentifier' && !isInRange)) {
663
- context.report(error);
664
- }
665
- }
666
- } catch (err) {
667
- _iterator.e(err);
668
- } finally {
669
- _iterator.f();
670
- }
671
- }
672
- }
673
- }
674
- };
675
-
676
- // Loops through automatic errors and them after adding the required suggestion/fix
677
- var throwAutoErrors = exports.throwAutoErrors = function throwAutoErrors(_ref0) {
678
- var errorsManual = _ref0.errorsManual,
679
- errorsAuto = _ref0.errorsAuto,
680
- iconSizesInfo = _ref0.iconSizesInfo,
681
- legacyIconImports = _ref0.legacyIconImports,
682
- guidance = _ref0.guidance,
683
- migrationIconImports = _ref0.migrationIconImports,
684
- shouldUseMigrationPath = _ref0.shouldUseMigrationPath,
685
- context = _ref0.context;
686
- // Set of all the import sources that have manual errors (required later to check if a source has both manual and auto
687
- // errors in one file making it impossible to just remove the legacy import)
688
- var allManualErrorSources = Object.entries(errorsManual).reduce(function (result, option) {
689
- var _option = (0, _slicedToArray2.default)(option, 2),
690
- key = _option[0],
691
- errorInfo = _option[1];
692
- if (!errorsAuto.hasOwnProperty(key)) {
693
- result.add(errorInfo.importSource);
694
- }
695
- return result;
696
- }, new Set());
697
- // Group errors by import source and remove any unwanted errors
698
- var groupedErrorList = Object.entries(errorsAuto).reduce(function (result, option) {
699
- var _option2 = (0, _slicedToArray2.default)(option, 2),
700
- key = _option2[0],
701
- error = _option2[1];
702
- // Return early if no data
703
- if (!error.data) {
704
- return result;
705
- }
706
- if (Object.keys(errorsManual).includes(key)) {
707
- var cantMigrateIdentifierError = errorsManual[key].errors.find(function (x) {
708
- return 'messageId' in x && x.messageId === 'cantMigrateIdentifier';
709
- });
710
- // If cantMigrateIdentifier is the only manual error found we still want to throw the auto error
711
- if (!(cantMigrateIdentifierError && errorsManual[key].errors.length === 1)) {
712
- return result;
713
- }
714
- }
715
- var importSource = error.data.importSource;
716
- if (!result.hasOwnProperty(importSource)) {
717
- result[importSource] = [];
718
- }
719
- result[importSource].push(_objectSpread({
720
- key: key
721
- }, error));
722
- return result;
723
- }, {});
724
- var _loop = function _loop() {
725
- var _Object$entries3$_i = (0, _slicedToArray2.default)(_Object$entries3[_i3], 2),
726
- importSource = _Object$entries3$_i[0],
727
- errorList = _Object$entries3$_i[1];
728
- var autoFixers = [];
729
- // appliedErrorsForImport will contain all the errors FOR A SINGLE IMPORT and will be merged into errorListForReport
730
- var appliedErrorsForImport = [];
731
- // Loop over auto errors for a single import source
732
- var _iterator2 = _createForOfIteratorHelper(errorList.entries()),
733
- _step2;
734
- try {
735
- var _loop2 = function _loop2() {
736
- var _iconSizesInfo$import, _iconSizesInfo$import2, _iconSizesInfo$import3, _legacyIconImports$er, _error$data2, _legacyIconImports$er2, _migrationIconImports;
737
- var _step2$value = (0, _slicedToArray2.default)(_step2.value, 2),
738
- _ = _step2$value[0],
739
- error = _step2$value[1];
740
- var key = error.key;
741
- var node = 'node' in error ? error.node : null;
742
- // Check if there is a manual error for the same import source somewhere else in the same file
743
- // If that is the case we'll need to provide a suggestion instead of auto-fixing as the suggestion will
744
- // add another import without removing the old import and this needs to be validated
745
- var isInManualArray = allManualErrorSources.has(importSource);
746
-
747
- // Check if the icon has size of small, if so it cannot be automatically migrated. Two suggestions will be provided
748
- // 1. Use core icon with no spacing
749
- // 2. Use utility icon with compact spacing
750
- var isSizeSmall = (_iconSizesInfo$import = iconSizesInfo[importSource]) === null || _iconSizesInfo$import === void 0 ? void 0 : _iconSizesInfo$import.small.includes(key);
751
- var isMixedSizeUsage = ((_iconSizesInfo$import2 = iconSizesInfo[importSource]) === null || _iconSizesInfo$import2 === void 0 ? void 0 : _iconSizesInfo$import2.small.length) > 0 && ((_iconSizesInfo$import3 = iconSizesInfo[importSource]) === null || _iconSizesInfo$import3 === void 0 ? void 0 : _iconSizesInfo$import3.small.length) < iconSizesInfo[importSource].usageCount;
752
-
753
- // Icon should be renamed
754
- // 1. If the icon is in the manual array OR
755
- // 2. If there is mixed size usages of this icon with size small
756
- var shouldRenameIcon = isInManualArray || isMixedSizeUsage;
757
-
758
- // New icon name for renaming if the icon is in the manual array
759
- var newIconName = getNewIconNameForRenaming(shouldRenameIcon, importSource, errorList[0].data ? (_legacyIconImports$er = legacyIconImports[errorList[0].data.iconName]) === null || _legacyIconImports$er === void 0 ? void 0 : _legacyIconImports$er.importSpecifier : undefined);
760
- if (!node) {
761
- return 0; // continue
762
- }
763
- var guidanceMessage = guidance.hasOwnProperty(key) ? guidance[key] : '';
764
- if (Object.keys(error).includes('data') && error.data) {
765
- error.data.guidance = guidanceMessage;
766
- }
767
- var shouldForceSmallIcon = ((_error$data2 = error.data) === null || _error$data2 === void 0 ? void 0 : _error$data2.shouldForceSmallIcon) === 'true';
768
- var fixArguments = error.data ? {
769
- metadata: _objectSpread(_objectSpread({}, error.data), {}, {
770
- spacing: error.data.isInNewButton ? 'none' : error.data.spacing,
771
- size: shouldForceSmallIcon ? 'small' : error.data.size
772
- }),
773
- legacyImportNode: (_legacyIconImports$er2 = legacyIconImports[error.data.iconName]) === null || _legacyIconImports$er2 === void 0 ? void 0 : _legacyIconImports$er2.importNode,
774
- migrationImportNode: (_migrationIconImports = migrationIconImports[error.data.iconName]) === null || _migrationIconImports === void 0 ? void 0 : _migrationIconImports.importNode,
775
- shouldUseMigrationPath: shouldUseMigrationPath,
776
- newIconName: shouldRenameIcon ? newIconName : undefined
777
- } : null;
778
- if (!error.data || shouldUseMigrationPath && !checkIfNewIconExist(error) || !fixArguments) {
779
- return 0; // continue
780
- }
781
- var isInNewButton = fixArguments.metadata.insideNewButton === 'true';
782
- if (isSizeSmall && !shouldForceSmallIcon) {
783
- error.suggest = [{
784
- desc: isInNewButton ? 'Replace with medium core icon (Recommended)' : 'Replace with medium core icon and no spacing (Recommended)',
785
- fix: function fix(fixer) {
786
- return [].concat((0, _toConsumableArray2.default)(createPropFixes(_objectSpread(_objectSpread({}, fixArguments), {}, {
787
- metadata: _objectSpread(_objectSpread({}, fixArguments.metadata), {}, {
788
- spacing: 'none'
789
- }),
790
- node: node,
791
- fixer: fixer
792
- }))), (0, _toConsumableArray2.default)(createImportFix(_objectSpread(_objectSpread({}, fixArguments), {}, {
793
- fixer: fixer
794
- }))));
795
- }
796
- }, {
797
- desc: isInNewButton ? 'Replace with small core icon' : 'Replace with small core icon and compact spacing',
798
- fix: function fix(fixer) {
799
- return [].concat((0, _toConsumableArray2.default)(createPropFixes(_objectSpread(_objectSpread({}, fixArguments), {}, {
800
- metadata: _objectSpread(_objectSpread({}, fixArguments.metadata), {}, {
801
- spacing: 'compact',
802
- size: 'small'
803
- }),
804
- node: node,
805
- fixer: fixer
806
- }))), (0, _toConsumableArray2.default)(createImportFix(_objectSpread(_objectSpread({}, fixArguments), {}, {
807
- fixer: fixer
808
- }))));
809
- }
810
- }];
811
- } else {
812
- if (isInManualArray) {
813
- // provide suggestion if there is a manual error for the same import source and thus the legacy import can't be removed
814
- error.suggest = [{
815
- desc: 'Rename icon import, import from the new package, and update props.',
816
- fix: function fix(fixer) {
817
- return [].concat((0, _toConsumableArray2.default)(createPropFixes(_objectSpread(_objectSpread({}, fixArguments), {}, {
818
- node: node,
819
- fixer: fixer
820
- }))), (0, _toConsumableArray2.default)(createImportFix(_objectSpread(_objectSpread({}, fixArguments), {}, {
821
- fixer: fixer
822
- }))));
823
- }
824
- }];
825
- } else {
826
- // Update Guidance message for auto-fixing
827
- if (error.data) {
828
- error.data.guidance = error.data.guidance + "\nTo automatically fix this icon, run the auto-fixer attached to the first use of ".concat(importSource, " in this file - either manually, or by saving this file.");
829
- }
830
- // There should only be 1 import fix for each import source and thus only add this at the start of the list
831
- if (autoFixers.length === 0) {
832
- autoFixers.push(function (fixer) {
833
- return createImportFix(_objectSpread(_objectSpread({}, fixArguments), {}, {
834
- fixer: fixer
835
- }));
836
- });
837
- }
838
- // Push the prop fix regardless
839
- autoFixers.push(function (fixer) {
840
- return createPropFixes(_objectSpread(_objectSpread({}, fixArguments), {}, {
841
- node: node,
842
- fixer: fixer
843
- }));
844
- });
845
- }
846
- }
847
- // Add the error to the appliedErrorsForImport, ready to be thrown later
848
- appliedErrorsForImport.push(error);
849
- },
850
- _ret;
851
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
852
- _ret = _loop2();
853
- if (_ret === 0) continue;
854
- }
855
- // We want to have only 1 fix for each import source that is not in the manual array
856
- // NOTE: If in the manual array, suggestions have been applied above and autoFixers.length will be 0 which will mean no fix is added
857
- } catch (err) {
858
- _iterator2.e(err);
859
- } finally {
860
- _iterator2.f();
861
- }
862
- if (autoFixers.length > 0) {
863
- // Add the fix to only one of the errors in the list of errors from the current import source
864
- appliedErrorsForImport[0].fix = function (fixer) {
865
- return autoFixers.flatMap(function (autoFixer) {
866
- return autoFixer(fixer);
867
- });
868
- };
869
- }
870
- // throw errors
871
- appliedErrorsForImport.forEach(function (error) {
872
- context.report(error);
873
- });
874
- };
875
- for (var _i3 = 0, _Object$entries3 = Object.entries(groupedErrorList); _i3 < _Object$entries3.length; _i3++) {
876
- _loop();
877
- }
878
- };
879
- function findProgramNode(node) {
880
- while (node && node.parent) {
881
- if (node.parent.type === 'Program') {
882
- return node.parent;
883
- }
884
- node = node.parent;
885
- }
886
- return null;
887
- }
888
- function alreadyHasImportedLocalName(programNode, localName, importPath) {
889
- if (!(programNode !== null && programNode !== void 0 && programNode.body)) {
890
- return false;
891
- }
892
- return programNode.body.some(function (stmt) {
893
- if (stmt.type === 'ImportDeclaration' && stmt.source.value === importPath) {
894
- return stmt.specifiers.some(function (s) {
895
- return s.local.name === localName;
896
- });
897
- }
898
- return false;
899
- });
900
- }