@atlaskit/eslint-plugin-design-system 10.8.1 → 10.8.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/dist/cjs/rules/ensure-design-token-usage/index.js +1 -1
  3. package/dist/cjs/rules/no-legacy-icons/checks.js +484 -0
  4. package/dist/cjs/rules/no-legacy-icons/helpers.js +289 -0
  5. package/dist/cjs/rules/no-legacy-icons/index.js +111 -131
  6. package/dist/cjs/rules/no-legacy-icons/migration-map-temp.js +4090 -0
  7. package/dist/cjs/rules/use-tokens-typography/index.js +1 -1
  8. package/dist/es2019/rules/ensure-design-token-usage/index.js +1 -1
  9. package/dist/es2019/rules/no-legacy-icons/checks.js +388 -0
  10. package/dist/es2019/rules/no-legacy-icons/helpers.js +275 -0
  11. package/dist/es2019/rules/no-legacy-icons/index.js +96 -97
  12. package/dist/es2019/rules/no-legacy-icons/migration-map-temp.js +4082 -0
  13. package/dist/es2019/rules/use-tokens-typography/index.js +1 -1
  14. package/dist/esm/rules/ensure-design-token-usage/index.js +1 -1
  15. package/dist/esm/rules/no-legacy-icons/checks.js +477 -0
  16. package/dist/esm/rules/no-legacy-icons/helpers.js +279 -0
  17. package/dist/esm/rules/no-legacy-icons/index.js +111 -131
  18. package/dist/esm/rules/no-legacy-icons/migration-map-temp.js +4084 -0
  19. package/dist/esm/rules/use-tokens-typography/index.js +1 -1
  20. package/dist/types/rules/no-legacy-icons/checks.d.ts +13 -0
  21. package/dist/types/rules/no-legacy-icons/helpers.d.ts +82 -0
  22. package/dist/types/rules/no-legacy-icons/index.d.ts +2 -1
  23. package/dist/types/rules/no-legacy-icons/migration-map-temp.d.ts +22 -0
  24. package/dist/{types-ts4.5/rules/use-tokens-typography → types/rules/utils}/error-boundary.d.ts +5 -1
  25. package/dist/types-ts4.5/rules/no-legacy-icons/checks.d.ts +13 -0
  26. package/dist/types-ts4.5/rules/no-legacy-icons/helpers.d.ts +82 -0
  27. package/dist/types-ts4.5/rules/no-legacy-icons/index.d.ts +2 -1
  28. package/dist/types-ts4.5/rules/no-legacy-icons/migration-map-temp.d.ts +27 -0
  29. package/dist/types-ts4.5/rules/{ensure-design-token-usage → utils}/error-boundary.d.ts +5 -1
  30. package/package.json +1 -1
  31. package/dist/cjs/rules/use-tokens-typography/error-boundary.js +0 -24
  32. package/dist/es2019/rules/use-tokens-typography/error-boundary.js +0 -19
  33. package/dist/esm/rules/use-tokens-typography/error-boundary.js +0 -18
  34. package/dist/types/rules/ensure-design-token-usage/error-boundary.d.ts +0 -11
  35. package/dist/types/rules/use-tokens-typography/error-boundary.d.ts +0 -11
  36. /package/dist/cjs/rules/{ensure-design-token-usage → utils}/error-boundary.js +0 -0
  37. /package/dist/es2019/rules/{ensure-design-token-usage → utils}/error-boundary.js +0 -0
  38. /package/dist/esm/rules/{ensure-design-token-usage → utils}/error-boundary.js +0 -0
@@ -0,0 +1,289 @@
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.locToString = exports.getMigrationMapObject = exports.getLiteralStringValue = exports.getIconKey = exports.findUNSAFEProp = exports.createHelpers = exports.createGuidance = exports.createCantMigrateUnsafeProp = exports.createCantMigrateSpreadPropsError = exports.createCantMigrateSizeUnknown = exports.createCantMigrateReExportError = exports.createCantMigrateIdentifierError = exports.createCantMigrateFunctionUnknownError = exports.createCantMigrateColorError = exports.createCantFindSuitableReplacementError = exports.createAutoMigrationError = exports.canMigrateColor = exports.canAutoMigrateNewIconBasedOnSize = void 0;
9
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
10
+ var _eslintCodemodUtils = require("eslint-codemod-utils");
11
+ var _getImportName = require("../utils/get-import-name");
12
+ var _migrationMapTemp = _interopRequireWildcard(require("./migration-map-temp"));
13
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
14
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
15
+ /**
16
+ * Returns the migration map object for a legacy icon or null if not found
17
+ * @param iconPackage The name of the legacy icon package
18
+ * @returns The migration map object for the legacy icon or null if not found
19
+ */
20
+ var getMigrationMapObject = exports.getMigrationMapObject = function getMigrationMapObject(iconPackage) {
21
+ var key = getIconKey(iconPackage);
22
+ if (key in _migrationMapTemp.default) {
23
+ return _migrationMapTemp.default[key];
24
+ }
25
+ return null;
26
+ };
27
+
28
+ /**
29
+ * Returns the key of a legacy icon
30
+ * @param iconPackage The name of the legacy icon package
31
+ * @returns The unique identifier for the icon (the part after "@atlaskit/icon/glyph")
32
+ */
33
+ var getIconKey = exports.getIconKey = function getIconKey(iconPackage) {
34
+ var key = iconPackage.replace(/^@atlaskit\/icon\/glyph\//, '');
35
+ return key;
36
+ };
37
+
38
+ /**
39
+ * Checks if a new icon can be auto-migrated based on guidance from the migration map
40
+ */
41
+ var canAutoMigrateNewIconBasedOnSize = exports.canAutoMigrateNewIconBasedOnSize = function canAutoMigrateNewIconBasedOnSize(guidance) {
42
+ return ['swap', 'swap-slight-visual-change', 'swap-visual-change', 'swap-size-shift-utility'].includes(guidance || '');
43
+ };
44
+
45
+ /**
46
+ * Creates the written guidance for migrating a legacy icon to a new icon
47
+ */
48
+ var createGuidance = exports.createGuidance = function createGuidance(iconPackage, size) {
49
+ var migrationMapObject = getMigrationMapObject(iconPackage);
50
+ if (migrationMapObject) {
51
+ var newIcon = migrationMapObject.newIcon;
52
+ if (!newIcon) {
53
+ return 'No equivalent icon in new set. An option is to contribute a custom icon into icon-labs package instead.\n';
54
+ }
55
+ if (size) {
56
+ var guidance = "Fix: Use ".concat(newIcon.name, " from @atlaskit/").concat(newIcon.library, "/").concat(newIcon.type, "/").concat(newIcon.name, " instead.");
57
+ if (migrationMapObject.sizeGuidance[size] in _migrationMapTemp.outcomeDescriptionMap) {
58
+ guidance += " Please: ".concat(_migrationMapTemp.outcomeDescriptionMap[migrationMapObject.sizeGuidance[size]], "\n");
59
+ } else {
60
+ guidance += ' No migration advice given.\n';
61
+ }
62
+ return guidance;
63
+ } else {
64
+ var _guidance = "Use ".concat(newIcon.name, " from @atlaskit/").concat(newIcon.library, "/").concat(newIcon.type, "/").concat(newIcon.name, " instead.\nMigration suggestions, depending on the legacy icon size:\n");
65
+ for (var _i = 0, _Object$entries = Object.entries(migrationMapObject.sizeGuidance); _i < _Object$entries.length; _i++) {
66
+ var _Object$entries$_i = (0, _slicedToArray2.default)(_Object$entries[_i], 2),
67
+ _size = _Object$entries$_i[0],
68
+ value = _Object$entries$_i[1];
69
+ _guidance += "\t- ".concat(_size, ": ");
70
+ if (!(value in _migrationMapTemp.outcomeDescriptionMap)) {
71
+ _guidance += 'No migration advice given.\n';
72
+ } else {
73
+ _guidance += "".concat(_migrationMapTemp.outcomeDescriptionMap[value], "\n");
74
+ }
75
+ _guidance;
76
+ }
77
+ return _guidance;
78
+ }
79
+ } else {
80
+ return 'Migration suggestions not found\n';
81
+ }
82
+ };
83
+
84
+ /**
85
+ * Checks if the color can be migrated
86
+ * @param color String representing the color to check
87
+ * @returns True if the color can be migrated, false otherwise
88
+ */
89
+ var canMigrateColor = exports.canMigrateColor = function canMigrateColor(color) {
90
+ if (color.match(/^color\.text$/)) {
91
+ return true;
92
+ } else if (color.match(/^color\.icon/)) {
93
+ return true;
94
+ } else if (color.match(/^color\.link/)) {
95
+ return true;
96
+ } else if (color === 'currentColor') {
97
+ return true;
98
+ } else {
99
+ return false;
100
+ }
101
+ };
102
+ var locToString = exports.locToString = function locToString(node) {
103
+ var _node$loc, _node$loc2, _node$loc3, _node$loc4;
104
+ return "".concat((_node$loc = node.loc) === null || _node$loc === void 0 ? void 0 : _node$loc.start.line, ":").concat((_node$loc2 = node.loc) === null || _node$loc2 === void 0 ? void 0 : _node$loc2.start.column, ":").concat((_node$loc3 = node.loc) === null || _node$loc3 === void 0 ? void 0 : _node$loc3.end.line, ":").concat((_node$loc4 = node.loc) === null || _node$loc4 === void 0 ? void 0 : _node$loc4.end.column);
105
+ };
106
+ var createCantMigrateReExportError = exports.createCantMigrateReExportError = function createCantMigrateReExportError(node, packageName, exportName, errors) {
107
+ var myError = {
108
+ node: node,
109
+ messageId: 'cantMigrateReExport',
110
+ data: {
111
+ packageName: packageName,
112
+ exportName: exportName
113
+ }
114
+ };
115
+ pushManualError(locToString(node), errors, myError, packageName, exportName);
116
+ };
117
+ var createCantMigrateIdentifierError = exports.createCantMigrateIdentifierError = function createCantMigrateIdentifierError(node, packageName, exportName, errors) {
118
+ var myError = {
119
+ node: node,
120
+ messageId: 'cantMigrateIdentifier',
121
+ data: {
122
+ packageName: packageName,
123
+ exportName: exportName
124
+ }
125
+ };
126
+ pushManualError(locToString(node), errors, myError, packageName, exportName);
127
+ };
128
+ var findUNSAFEProp = exports.findUNSAFEProp = function findUNSAFEProp(iconAttr, button) {
129
+ var UNSAFE_size = null;
130
+ var propName = iconAttr.name.name === 'iconAfter' || iconAttr.name.name === 'iconBefore' || iconAttr.name.name === 'icon' ? iconAttr.name.name : null;
131
+ var buttonAttributes = button.attributes;
132
+ var UNSAFE_propName = propName === 'icon' ? "UNSAFE_size" : propName ? "UNSAFE_".concat(propName, "_size") : null;
133
+ var UNSAFE_size_index = buttonAttributes.findIndex(function (x) {
134
+ return UNSAFE_propName && 'name' in x && x.name && x.name.name === UNSAFE_propName;
135
+ });
136
+ var unsafeAttribute = UNSAFE_size_index !== -1 ? buttonAttributes[UNSAFE_size_index] : null;
137
+ if (unsafeAttribute && (0, _eslintCodemodUtils.isNodeOfType)(unsafeAttribute, 'JSXAttribute') && unsafeAttribute.value && (0, _eslintCodemodUtils.isNodeOfType)(unsafeAttribute.value, 'Literal') && unsafeAttribute.value.value && ['small', 'large', 'xlarge'].includes(unsafeAttribute.value.value)) {
138
+ UNSAFE_size = unsafeAttribute.value.value;
139
+ } else if (unsafeAttribute && (0, _eslintCodemodUtils.isNodeOfType)(unsafeAttribute, 'JSXAttribute') && unsafeAttribute.value && (0, _eslintCodemodUtils.isNodeOfType)(unsafeAttribute.value, 'JSXExpressionContainer') && (0, _eslintCodemodUtils.isNodeOfType)(unsafeAttribute.value.expression, 'Literal') && ['small', 'large', 'xlarge'].includes(unsafeAttribute.value.expression.value)) {
140
+ UNSAFE_size = unsafeAttribute.value.expression.value;
141
+ }
142
+ return {
143
+ UNSAFE_size: UNSAFE_size,
144
+ UNSAFE_propName: UNSAFE_propName
145
+ };
146
+ };
147
+ var createCantMigrateUnsafeProp = exports.createCantMigrateUnsafeProp = function createCantMigrateUnsafeProp(node, propName, value, packageName, iconName, errors) {
148
+ var myError = {
149
+ node: node,
150
+ messageId: 'cantMigrateUnsafeProp',
151
+ data: {
152
+ propName: propName,
153
+ value: value
154
+ }
155
+ };
156
+ pushManualError(locToString(node), errors, myError, packageName, iconName);
157
+ };
158
+ var createCantFindSuitableReplacementError = exports.createCantFindSuitableReplacementError = function createCantFindSuitableReplacementError(node, importSource, iconName, errors) {
159
+ var myError = {
160
+ node: node,
161
+ messageId: 'cantFindSuitableReplacement',
162
+ data: {
163
+ importSource: importSource,
164
+ iconName: iconName
165
+ }
166
+ };
167
+ pushManualError(locToString(node), errors, myError, importSource, iconName);
168
+ };
169
+ var createCantMigrateFunctionUnknownError = exports.createCantMigrateFunctionUnknownError = function createCantMigrateFunctionUnknownError(node, importSource, iconName, errors) {
170
+ var myError = {
171
+ node: node,
172
+ messageId: 'cantMigrateFunctionUnknown',
173
+ data: {
174
+ importSource: importSource,
175
+ iconName: iconName
176
+ }
177
+ };
178
+ pushManualError(locToString(node), errors, myError, importSource, iconName);
179
+ };
180
+ var createCantMigrateColorError = exports.createCantMigrateColorError = function createCantMigrateColorError(node, colorValue, errors, importSource, iconName) {
181
+ var myError = {
182
+ node: node,
183
+ messageId: 'cantMigrateColor',
184
+ data: {
185
+ colorValue: colorValue
186
+ }
187
+ };
188
+ pushManualError(locToString(node), errors, myError, importSource, iconName);
189
+ };
190
+ var createCantMigrateSpreadPropsError = exports.createCantMigrateSpreadPropsError = function createCantMigrateSpreadPropsError(node, missingProps, errors, importSource, iconName) {
191
+ var myError = {
192
+ node: node,
193
+ messageId: 'cantMigrateSpreadProps',
194
+ data: {
195
+ missingProps: missingProps.join(', ')
196
+ }
197
+ };
198
+ pushManualError(locToString(node), errors, myError, importSource, iconName);
199
+ };
200
+ var createCantMigrateSizeUnknown = exports.createCantMigrateSizeUnknown = function createCantMigrateSizeUnknown(node, errors, importSource, iconName) {
201
+ var myError = {
202
+ node: node,
203
+ messageId: 'cantMigrateSizeUnknown'
204
+ };
205
+ pushManualError(locToString(node), errors, myError, importSource, iconName);
206
+ };
207
+ var createAutoMigrationError = exports.createAutoMigrationError = function createAutoMigrationError(node, importSource, iconName, newIcon, oldIconName, errors) {
208
+ var migrationKey = newIcon.name === oldIconName ? newIcon.name : "".concat(newIcon.name, "--").concat(oldIconName);
209
+ var newMigrationIconPackage = "@atlaskit/".concat(newIcon.library, "/").concat(newIcon.type, "/migration/").concat(migrationKey);
210
+ var myError = {
211
+ node: node,
212
+ messageId: 'noLegacyIconsAutoMigration',
213
+ data: {
214
+ importSource: importSource,
215
+ iconName: iconName,
216
+ newIcon: newIcon.name,
217
+ //TODO: provide size guidance
218
+ newPackage: newMigrationIconPackage
219
+ }
220
+ };
221
+ errors[locToString(node)] = myError;
222
+ };
223
+ var pushManualError = function pushManualError(key, errors, myError, importSource, iconName) {
224
+ if (key in errors) {
225
+ errors[key].errors.push(myError);
226
+ } else {
227
+ errors[key] = {
228
+ errors: [myError],
229
+ importSource: importSource,
230
+ iconName: iconName
231
+ };
232
+ }
233
+ };
234
+ var getLiteralStringValue = exports.getLiteralStringValue = function getLiteralStringValue(value) {
235
+ if (!value) {
236
+ return;
237
+ }
238
+
239
+ // propName="value"
240
+ if ((0, _eslintCodemodUtils.isNodeOfType)(value, 'Literal') && typeof value.value === 'string') {
241
+ return value.value;
242
+ }
243
+
244
+ // propName={"value"}
245
+ if ((0, _eslintCodemodUtils.isNodeOfType)(value, 'JSXExpressionContainer') && (0, _eslintCodemodUtils.isNodeOfType)(value.expression, 'Literal') && typeof value.expression.value === 'string') {
246
+ return value.expression.value;
247
+ }
248
+ return;
249
+ };
250
+ var createHelpers = exports.createHelpers = function createHelpers(context) {
251
+ /**
252
+ * Extracts the token name of a token() call from a JSXExpressionContainer
253
+ * @param value The JSXExpressionContainer to extract the token call from
254
+ * @returns The value of the token call, or null if it could not be extracted
255
+ */
256
+ var getTokenCallValue = function getTokenCallValue(value) {
257
+ var tokenName = (0, _getImportName.getImportName)(context.sourceCode.getScope(value), '@atlaskit/tokens', 'token');
258
+ if (tokenName && (0, _eslintCodemodUtils.isNodeOfType)(value, 'JSXExpressionContainer') && (0, _eslintCodemodUtils.isNodeOfType)(value.expression, 'CallExpression') && 'name' in value.expression.callee && value.expression.callee.name === tokenName) {
259
+ // propName={token("color...."}
260
+ return getLiteralStringValue(value.expression.arguments[0]);
261
+ }
262
+ return;
263
+ };
264
+
265
+ /**
266
+ * Gets the value of a boolean configuration flag
267
+ * @param key the key of the configuration flag
268
+ * @param defaultValue The default value of the configuration flag
269
+ * @returns defaultValue if the configuration flag is not set, the defaultValue of the configuration flag otherwise
270
+ */
271
+ var getConfigFlag = function getConfigFlag(key, defaultValue) {
272
+ if (context.options.length > 0 && context.options[0] && key in context.options[0]) {
273
+ return context.options[0][key] === !defaultValue ? !defaultValue : defaultValue;
274
+ }
275
+ return defaultValue;
276
+ };
277
+ return {
278
+ /**
279
+ * Extracts the primaryColor value from a JSXAttribute
280
+ */
281
+ getPrimaryColor: function getPrimaryColor(attr) {
282
+ var _ref, _getLiteralStringValu;
283
+ var value = attr.value;
284
+ return (_ref = (_getLiteralStringValu = getLiteralStringValue(value)) !== null && _getLiteralStringValu !== void 0 ? _getLiteralStringValu : getTokenCallValue(value)) !== null && _ref !== void 0 ? _ref : null;
285
+ },
286
+ getTokenCallValue: getTokenCallValue,
287
+ getConfigFlag: getConfigFlag
288
+ };
289
+ };
@@ -4,11 +4,10 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- var _eslintCodemodUtils = require("eslint-codemod-utils");
8
7
  var _createRule = require("../utils/create-rule");
9
- function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
10
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
11
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
8
+ var _errorBoundary = require("../utils/error-boundary");
9
+ var _checks = require("./checks");
10
+ var _helpers = require("./helpers");
12
11
  var rule = (0, _createRule.createLintRule)({
13
12
  meta: {
14
13
  name: 'no-legacy-icons',
@@ -18,155 +17,136 @@ var rule = (0, _createRule.createLintRule)({
18
17
  recommended: false,
19
18
  severity: 'warn'
20
19
  },
20
+ schema: [{
21
+ type: 'object',
22
+ properties: {
23
+ shouldErrorForManualMigration: {
24
+ type: 'boolean'
25
+ },
26
+ shouldErrorForAutoMigration: {
27
+ type: 'boolean'
28
+ },
29
+ quiet: {
30
+ type: 'boolean'
31
+ }
32
+ },
33
+ additionalProperties: false
34
+ }],
21
35
  messages: {
22
- noLegacyIcons: "Legacy icon '{{iconName}}', is being rendered from import '{{importSource}}'. Migrate to an icon from '@atlaskit/icon/(core|utility)', or '@atlaskit/icon-labs/(core|utility)'.\nLearn more in our [code migration guide](https://hello.atlassian.net/wiki/spaces/DST/pages/3748692796/New+ADS+iconography+-+Code+migration+guide)."
36
+ noLegacyIconsAutoMigration: "Auto Migration:\nLegacy icon '{{iconName}}' from '{{importSource}}' detected.\nAutomatic migration is possible to '{{newIcon}}' from '{{newPackage}}.\nAtlassians: See https://go.atlassian.com/icon-migration-guide for details.'",
37
+ noLegacyIconsManualMigration: "Manual Migration:\nLegacy icon '{{iconName}}' from '{{importSource}}' detected.\nAutomatic migration not possible.{{quietModeGuidance}}.\nAtlassians: See https://go.atlassian.com/icon-migration-guide for details.",
38
+ cantFindSuitableReplacement: "No suitable replacement found for '{{iconName}}' from '{{importSource}}' at the size listed. Please manually migrate this icon.",
39
+ cantMigrateReExport: "'{{exportName}}' is a re-export of icon from '{{packageName}}' and cannot be automatically migrated. Please utilize the export from icons directly.",
40
+ cantMigrateColor: "Primary Color prop has {{colorValue}} which cannot be automatically migrated to color prop in the new Icon API. Please use either an appropriate color.icon, color.link token, or currentColor (as a last resort).",
41
+ cantMigrateSpreadProps: "This usage of Icon uses spread props in a way that can't be automatically migrated. Please explicitly define the following props after spread: '{{missingProps}}' ",
42
+ cantMigrateSizeUnknown: "This usage of Icon sets the size via a variable or function that can't be determined.",
43
+ cantMigrateFunctionUnknown: "'{{iconName}}' from legacy '{{importSource}}' is used in unknown function/component. Please manually migrate this icon.",
44
+ cantMigrateIdentifier: "This icon is passed to other components via a map or array, in a way that can't be automatically migrated. Please manually migrate wherever this expression is used and use the icon components directly.",
45
+ cantMigrateUnsafeProp: "Property '{{propName}}' with value of '{{value}}' is unable to be auto-migrated to the new button. Please manually migrate this icon.",
46
+ guidance: "Guidance:\n'{{guidance}}'"
23
47
  }
24
48
  },
25
49
  create: function create(context) {
26
- var legacyIconImports = {};
50
+ var _createHelpers = (0, _helpers.createHelpers)(context),
51
+ getConfigFlag = _createHelpers.getConfigFlag;
52
+ var failSilently = getConfigFlag('failSilently', false);
53
+ var _createChecks = (0, _checks.createChecks)(context),
54
+ checkImportDeclarations = _createChecks.checkImportDeclarations,
55
+ checkVariableDeclarations = _createChecks.checkVariableDeclarations,
56
+ checkExportDefaultDeclaration = _createChecks.checkExportDefaultDeclaration,
57
+ checkExportNamedVariables = _createChecks.checkExportNamedVariables,
58
+ checkArrayOrMap = _createChecks.checkArrayOrMap,
59
+ checkIconAsProp = _createChecks.checkIconAsProp,
60
+ checkJSXElement = _createChecks.checkJSXElement,
61
+ checkCallExpression = _createChecks.checkCallExpression,
62
+ throwErrors = _createChecks.throwErrors;
27
63
  return {
64
+ // Track imports of relevant components
28
65
  ImportDeclaration: function ImportDeclaration(node) {
29
- var moduleSource = node.source.value;
30
- if (typeof moduleSource === 'string' && ['@atlaskit/icon/glyph/', '@atlaskit/icon-object/glyph/'].find(function (val) {
31
- return moduleSource.startsWith(val);
32
- }) && node.specifiers.length) {
33
- var defaultImport = node.specifiers.find(function (spec) {
34
- return spec.type === 'ImportDefaultSpecifier';
35
- });
36
- if (!defaultImport) {
37
- return;
66
+ (0, _errorBoundary.errorBoundary)(function () {
67
+ return checkImportDeclarations(node);
68
+ }, {
69
+ config: {
70
+ failSilently: failSilently
38
71
  }
39
- var defaultImportName = defaultImport.local.name;
40
- legacyIconImports[defaultImportName] = moduleSource;
41
- }
72
+ });
42
73
  },
74
+ // Keep track of the relevant variable declarations and renames
43
75
  VariableDeclaration: function VariableDeclaration(node) {
44
- if ((0, _eslintCodemodUtils.isNodeOfType)(node, 'VariableDeclaration')) {
45
- var _iterator = _createForOfIteratorHelper(node.declarations),
46
- _step;
47
- try {
48
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
49
- var decl = _step.value;
50
- if ((0, _eslintCodemodUtils.isNodeOfType)(decl, 'VariableDeclarator') && 'init' in decl && 'id' in decl && decl.init && decl.id && 'name' in decl.id && decl.id.name && (0, _eslintCodemodUtils.isNodeOfType)(decl.init, 'Identifier') && decl.init.name in legacyIconImports) {
51
- legacyIconImports[decl.id.name] = legacyIconImports[decl.init.name];
52
- }
53
- }
54
- } catch (err) {
55
- _iterator.e(err);
56
- } finally {
57
- _iterator.f();
76
+ (0, _errorBoundary.errorBoundary)(function () {
77
+ return checkVariableDeclarations(node);
78
+ }, {
79
+ config: {
80
+ failSilently: failSilently
58
81
  }
59
- }
82
+ });
60
83
  },
84
+ // Case: default re-exports. Can't be auto-migrated
61
85
  ExportDefaultDeclaration: function ExportDefaultDeclaration(node) {
62
- if ('declaration' in node && node.declaration && (0, _eslintCodemodUtils.isNodeOfType)(node.declaration, 'Identifier') && node.declaration.name in legacyIconImports) {
63
- context.report({
64
- node: node,
65
- messageId: 'noLegacyIcons',
66
- data: {
67
- importSource: legacyIconImports[node.declaration.name],
68
- iconName: node.declaration.name
69
- }
70
- });
71
- }
86
+ (0, _errorBoundary.errorBoundary)(function () {
87
+ return checkExportDefaultDeclaration(node);
88
+ }, {
89
+ config: {
90
+ failSilently: failSilently
91
+ }
92
+ });
72
93
  },
73
94
  ExportNamedDeclaration: function ExportNamedDeclaration(node) {
74
- if ('source' in node && node.source && (0, _eslintCodemodUtils.isNodeOfType)(node.source, 'Literal') && 'value' in node.source) {
75
- var moduleSource = node.source.value;
76
- if (typeof moduleSource === 'string' && ['@atlaskit/icon/glyph/', '@atlaskit/icon-object/glyph/'].find(function (val) {
77
- return moduleSource.startsWith(val);
78
- }) && node.specifiers.length) {
79
- context.report({
80
- node: node,
81
- messageId: 'noLegacyIcons',
82
- data: {
83
- importSource: moduleSource,
84
- iconName: node.specifiers[0].exported.name
85
- }
86
- });
95
+ (0, _errorBoundary.errorBoundary)(function () {
96
+ return checkExportNamedVariables(node);
97
+ }, {
98
+ config: {
99
+ failSilently: failSilently
87
100
  }
88
- } else if ('declaration' in node && node.declaration && (0, _eslintCodemodUtils.isNodeOfType)(node.declaration, 'VariableDeclaration')) {
89
- var _iterator2 = _createForOfIteratorHelper(node.declaration.declarations),
90
- _step2;
91
- try {
92
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
93
- var decl = _step2.value;
94
- if ((0, _eslintCodemodUtils.isNodeOfType)(decl, 'VariableDeclarator') && 'init' in decl && decl.init && (0, _eslintCodemodUtils.isNodeOfType)(decl.init, 'Identifier') && decl.init.name in legacyIconImports) {
95
- context.report({
96
- node: node,
97
- messageId: 'noLegacyIcons',
98
- data: {
99
- importSource: legacyIconImports[decl.init.name],
100
- iconName: decl.init.name
101
- }
102
- });
103
- }
104
- }
105
- } catch (err) {
106
- _iterator2.e(err);
107
- } finally {
108
- _iterator2.f();
101
+ });
102
+ },
103
+ // Legacy icons found in arrays/objects
104
+ 'ObjectExpression > Property > Identifier, ArrayExpression > Identifier ': function ObjectExpressionPropertyIdentifierArrayExpressionIdentifier(node) {
105
+ (0, _errorBoundary.errorBoundary)(function () {
106
+ return checkArrayOrMap(node);
107
+ }, {
108
+ config: {
109
+ failSilently: failSilently
109
110
  }
110
- }
111
+ });
111
112
  },
112
- JSXAttribute: function JSXAttribute(node) {
113
- if (!(0, _eslintCodemodUtils.isNodeOfType)(node.value, 'JSXExpressionContainer')) {
114
- return;
115
- }
116
- if ((0, _eslintCodemodUtils.isNodeOfType)(node.value.expression, 'Identifier') && node.value.expression.name in legacyIconImports && (0, _eslintCodemodUtils.isNodeOfType)(node.name, 'JSXIdentifier') && !node.name.name.startsWith('LEGACY_')) {
117
- context.report({
118
- node: node,
119
- messageId: 'noLegacyIcons',
120
- data: {
121
- importSource: legacyIconImports[node.value.expression.name],
122
- iconName: node.value.expression.name
123
- }
124
- });
125
- }
113
+ // Legacy icons passed in via props, as JSX identifier (i.e. icon={AddIcon})
114
+ 'JSXOpeningElement > JSXAttribute > JSXExpressionContainer > Identifier': function JSXOpeningElementJSXAttributeJSXExpressionContainerIdentifier(node) {
115
+ (0, _errorBoundary.errorBoundary)(function () {
116
+ return checkIconAsProp(node);
117
+ }, {
118
+ config: {
119
+ failSilently: failSilently
120
+ }
121
+ });
126
122
  },
127
123
  JSXElement: function JSXElement(node) {
128
- if (!(0, _eslintCodemodUtils.isNodeOfType)(node, 'JSXElement')) {
129
- return;
130
- }
131
- if (!(0, _eslintCodemodUtils.isNodeOfType)(node.openingElement.name, 'JSXIdentifier')) {
132
- return;
133
- }
134
- var name = node.openingElement.name.name;
135
- if (name in legacyIconImports) {
136
- context.report({
137
- node: node,
138
- messageId: 'noLegacyIcons',
139
- data: {
140
- importSource: legacyIconImports[name],
141
- iconName: name
142
- }
143
- });
144
- }
124
+ (0, _errorBoundary.errorBoundary)(function () {
125
+ return checkJSXElement(node);
126
+ }, {
127
+ config: {
128
+ failSilently: failSilently
129
+ }
130
+ });
145
131
  },
132
+ // Icons called as an argument of a function (i.e. icon={DefaultIcon(AddIcon)})
146
133
  CallExpression: function CallExpression(node) {
147
- if ('arguments' in node && node.arguments.length) {
148
- var _iterator3 = _createForOfIteratorHelper(node.arguments),
149
- _step3;
150
- try {
151
- for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
152
- var arg = _step3.value;
153
- if ((0, _eslintCodemodUtils.isNodeOfType)(arg, 'Identifier') && arg.name in legacyIconImports) {
154
- context.report({
155
- node: arg,
156
- messageId: 'noLegacyIcons',
157
- data: {
158
- importSource: legacyIconImports[arg.name],
159
- iconName: arg.name
160
- }
161
- });
162
- }
163
- }
164
- } catch (err) {
165
- _iterator3.e(err);
166
- } finally {
167
- _iterator3.f();
134
+ (0, _errorBoundary.errorBoundary)(function () {
135
+ return checkCallExpression(node);
136
+ }, {
137
+ config: {
138
+ failSilently: failSilently
168
139
  }
169
- }
140
+ });
141
+ },
142
+ 'Program:exit': function ProgramExit() {
143
+ (0, _errorBoundary.errorBoundary)(function () {
144
+ return throwErrors();
145
+ }, {
146
+ config: {
147
+ failSilently: failSilently
148
+ }
149
+ });
170
150
  }
171
151
  };
172
152
  }