@atlaskit/eslint-plugin-design-system 10.12.3 → 10.12.5

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # @atlaskit/eslint-plugin-design-system
2
2
 
3
+ ## 10.12.5
4
+
5
+ ### Patch Changes
6
+
7
+ - [#127454](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/127454)
8
+ [`e869f31dbe200`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/e869f31dbe200) -
9
+ No-legacy-icons ESLint rule errors at all references to a legacy icon.
10
+
11
+ ## 10.12.4
12
+
13
+ ### Patch Changes
14
+
15
+ - [#126974](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/126974)
16
+ [`bf10ab6817404`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/bf10ab6817404) -
17
+ Updates the no-legacy-icons eslint rule to account for upcoming icons.
18
+
3
19
  ## 10.12.3
4
20
 
5
21
  ### Patch Changes
@@ -27,6 +27,9 @@ var createChecks = exports.createChecks = function createChecks(context) {
27
27
  var shouldErrorForAutoMigration = getConfigFlag('shouldErrorForAutoMigration', true);
28
28
  var isQuietMode = getConfigFlag('quiet', false);
29
29
 
30
+ // Sorted list of ranges
31
+ var errorRanges = [];
32
+
30
33
  /**
31
34
  * Adds the legacy Icon and new button imports to the correct global arrays to be used by the other checks
32
35
  * @param node The import node found by ESLint
@@ -90,8 +93,8 @@ var createChecks = exports.createChecks = function createChecks(context) {
90
93
  try {
91
94
  for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
92
95
  var decl = _step3.value;
93
- 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')) {
94
- if (decl.init.name in legacyIconImports) {
96
+ if ((0, _eslintCodemodUtils.isNodeOfType)(decl, 'VariableDeclarator') && Object.keys(decl).includes('init') && Object.keys(decl).includes('id') && decl.init && decl.id && 'name' in decl.id && decl.id.name && (0, _eslintCodemodUtils.isNodeOfType)(decl.init, 'Identifier')) {
97
+ if (Object.keys(legacyIconImports).includes(decl.init.name)) {
95
98
  legacyIconImports[decl.id.name] = {
96
99
  packageName: legacyIconImports[decl.init.name].packageName,
97
100
  exported: legacyIconImports[decl.init.name].exported || isExported
@@ -116,16 +119,17 @@ var createChecks = exports.createChecks = function createChecks(context) {
116
119
  var checkExportDefaultDeclaration = function checkExportDefaultDeclaration(node) {
117
120
  var exportName = '';
118
121
  var packageName = '';
119
- if ('declaration' in node && node.declaration && (0, _eslintCodemodUtils.isNodeOfType)(node.declaration, 'Identifier') && node.declaration.name in legacyIconImports) {
122
+ if (Object.keys(node).includes('declaration') && node.declaration && (0, _eslintCodemodUtils.isNodeOfType)(node.declaration, 'Identifier') && Object.keys(legacyIconImports).includes(node.declaration.name)) {
120
123
  packageName = legacyIconImports[node.declaration.name].packageName;
121
124
  exportName = 'Default export';
122
- } else if ('declaration' in node && node.declaration && (0, _eslintCodemodUtils.isNodeOfType)(node.declaration, 'AssignmentExpression') && (0, _eslintCodemodUtils.isNodeOfType)(node.declaration.left, 'Identifier') && (0, _eslintCodemodUtils.isNodeOfType)(node.declaration.right, 'Identifier') && node.declaration.right.name in legacyIconImports) {
125
+ } else if (Object.keys(node).includes('declaration') && node.declaration && (0, _eslintCodemodUtils.isNodeOfType)(node.declaration, 'AssignmentExpression') && (0, _eslintCodemodUtils.isNodeOfType)(node.declaration.left, 'Identifier') && (0, _eslintCodemodUtils.isNodeOfType)(node.declaration.right, 'Identifier') && Object.keys(legacyIconImports).includes(node.declaration.right.name)) {
123
126
  packageName = legacyIconImports[node.declaration.right.name].packageName;
124
127
  exportName = node.declaration.left.name;
125
128
  } else {
126
129
  return;
127
130
  }
128
131
  (0, _helpers.createCantMigrateReExportError)(node, packageName, exportName, errorsManual);
132
+ (0, _helpers.addToListOfRanges)(node, errorRanges);
129
133
  guidance[(0, _helpers.locToString)(node)] = (0, _helpers.createGuidance)(packageName);
130
134
  };
131
135
 
@@ -135,7 +139,7 @@ var createChecks = exports.createChecks = function createChecks(context) {
135
139
  */
136
140
  var checkExportNamedVariables = function checkExportNamedVariables(node) {
137
141
  // export {default as AddIcon} from '@atlaskit/icon/glyph/add';
138
- if (node.source && (0, _eslintCodemodUtils.isNodeOfType)(node.source, 'Literal') && 'value' in node.source) {
142
+ if (node.source && (0, _eslintCodemodUtils.isNodeOfType)(node.source, 'Literal') && Object.keys(node.source).includes('value')) {
139
143
  var moduleSource = node.source.value;
140
144
  if (typeof moduleSource === 'string' && ['@atlaskit/icon/glyph/', '@atlaskit/icon-object/glyph/'].find(function (val) {
141
145
  return moduleSource.startsWith(val);
@@ -146,6 +150,7 @@ var createChecks = exports.createChecks = function createChecks(context) {
146
150
  for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
147
151
  var spec = _step4.value;
148
152
  (0, _helpers.createCantMigrateReExportError)(spec, moduleSource, spec.exported.name, errorsManual);
153
+ (0, _helpers.addToListOfRanges)(spec, errorRanges);
149
154
  guidance[(0, _helpers.locToString)(spec)] = (0, _helpers.createGuidance)(moduleSource);
150
155
  }
151
156
  } catch (err) {
@@ -161,8 +166,9 @@ var createChecks = exports.createChecks = function createChecks(context) {
161
166
  try {
162
167
  for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
163
168
  var decl = _step5.value;
164
- if ((0, _eslintCodemodUtils.isNodeOfType)(decl, 'VariableDeclarator') && 'init' in decl && decl.init && (0, _eslintCodemodUtils.isNodeOfType)(decl.init, 'Identifier') && decl.init.name in legacyIconImports) {
169
+ if ((0, _eslintCodemodUtils.isNodeOfType)(decl, 'VariableDeclarator') && Object.keys(decl).includes('init') && decl.init && (0, _eslintCodemodUtils.isNodeOfType)(decl.init, 'Identifier') && Object.keys(legacyIconImports).includes(decl.init.name)) {
165
170
  (0, _helpers.createCantMigrateReExportError)(node, legacyIconImports[decl.init.name].packageName, decl.init.name, errorsManual);
171
+ (0, _helpers.addToListOfRanges)(node, errorRanges);
166
172
  guidance[(0, _helpers.locToString)(node)] = (0, _helpers.createGuidance)(legacyIconImports[decl.init.name].packageName);
167
173
  }
168
174
  }
@@ -183,13 +189,14 @@ var createChecks = exports.createChecks = function createChecks(context) {
183
189
  try {
184
190
  for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
185
191
  var _spec2 = _step6.value;
186
- if (_spec2.local.name in legacyIconImports) {
192
+ if (Object.keys(legacyIconImports).includes(_spec2.local.name)) {
187
193
  //update legacy imports to be exported
188
194
  legacyIconImports[_spec2.local.name] = {
189
195
  packageName: legacyIconImports[_spec2.local.name].packageName,
190
196
  exported: true
191
197
  };
192
198
  (0, _helpers.createCantMigrateReExportError)(_spec2, legacyIconImports[_spec2.local.name].packageName, _spec2.exported.name, errorsManual);
199
+ (0, _helpers.addToListOfRanges)(_spec2, errorRanges);
193
200
  guidance[(0, _helpers.locToString)(_spec2)] = (0, _helpers.createGuidance)(legacyIconImports[_spec2.local.name].packageName);
194
201
  }
195
202
  }
@@ -209,8 +216,9 @@ var createChecks = exports.createChecks = function createChecks(context) {
209
216
  if (!(0, _eslintCodemodUtils.isNodeOfType)(node, 'Identifier')) {
210
217
  return;
211
218
  }
212
- if (node.name && node.name in legacyIconImports && legacyIconImports[node.name].packageName) {
213
- (0, _helpers.createCantMigrateIdentifierError)(node, legacyIconImports[node.name].packageName, node.name, errorsManual);
219
+ if (node.name && Object.keys(legacyIconImports).includes(node.name) && legacyIconImports[node.name].packageName) {
220
+ (0, _helpers.createCantMigrateIdentifierMapOrArrayError)(node, legacyIconImports[node.name].packageName, node.name, errorsManual);
221
+ (0, _helpers.addToListOfRanges)(node, errorRanges);
214
222
  guidance[(0, _helpers.locToString)(node)] = (0, _helpers.createGuidance)(legacyIconImports[node.name].packageName);
215
223
  }
216
224
  };
@@ -229,24 +237,44 @@ var createChecks = exports.createChecks = function createChecks(context) {
229
237
  if (!(0, _eslintCodemodUtils.isNodeOfType)(node.parent, 'JSXExpressionContainer') || !(0, _eslintCodemodUtils.isNodeOfType)(node.parent.parent, 'JSXAttribute') || !(0, _eslintCodemodUtils.isNodeOfType)(node.parent.parent.parent, 'JSXOpeningElement')) {
230
238
  return;
231
239
  }
232
- if (node.name in legacyIconImports && (0, _eslintCodemodUtils.isNodeOfType)(node.parent.parent.name, 'JSXIdentifier') && node.parent.parent.name.name !== 'LEGACY_fallbackIcon') {
240
+ if (Object.keys(legacyIconImports).includes(node.name) && (0, _eslintCodemodUtils.isNodeOfType)(node.parent.parent.name, 'JSXIdentifier') && node.parent.parent.name.name !== 'LEGACY_fallbackIcon') {
233
241
  var _migrationMapObject$s;
234
242
  var migrationMapObject = (0, _helpers.getMigrationMapObject)(legacyIconImports[node.name].packageName);
243
+ var upcomingIcon = (0, _helpers.getUpcomingIcons)(legacyIconImports[node.name].packageName);
235
244
  var newIcon = migrationMapObject === null || migrationMapObject === void 0 ? void 0 : migrationMapObject.newIcon;
236
- var isNewIconMigratable = (0, _helpers.canAutoMigrateNewIconBasedOnSize)(migrationMapObject === null || migrationMapObject === void 0 || (_migrationMapObject$s = migrationMapObject.sizeGuidance) === null || _migrationMapObject$s === void 0 ? void 0 : _migrationMapObject$s.medium);
245
+ var isNewIconMigratable = (0, _helpers.canAutoMigrateNewIconBasedOnSize)(upcomingIcon ? upcomingIcon.sizeGuidance.medium : migrationMapObject === null || migrationMapObject === void 0 || (_migrationMapObject$s = migrationMapObject.sizeGuidance) === null || _migrationMapObject$s === void 0 ? void 0 : _migrationMapObject$s.medium);
237
246
  var isInNewButton = (0, _eslintCodemodUtils.isNodeOfType)(node.parent.parent.parent.name, 'JSXIdentifier') && newButtonImports.has(node.parent.parent.parent.name.name);
238
- if (newIcon && isInNewButton && isNewIconMigratable) {
247
+ if (newIcon && isInNewButton && isNewIconMigratable || upcomingIcon && isInNewButton && isNewIconMigratable) {
239
248
  (0, _helpers.createAutoMigrationError)(node, legacyIconImports[node.name].packageName, node.name, errorsAuto);
249
+ (0, _helpers.addToListOfRanges)(node, errorRanges);
240
250
  guidance[(0, _helpers.locToString)(node)] = (0, _helpers.createGuidance)(legacyIconImports[node.name].packageName, isInNewButton, 'medium');
241
- } else if (!newIcon || !isNewIconMigratable) {
251
+ } else if (!newIcon && !upcomingIcon || !isNewIconMigratable) {
242
252
  (0, _helpers.createCantFindSuitableReplacementError)(node, legacyIconImports[node.name].packageName, node.name, errorsManual);
253
+ (0, _helpers.addToListOfRanges)(node, errorRanges);
243
254
  guidance[(0, _helpers.locToString)(node)] = (0, _helpers.createGuidance)(legacyIconImports[node.name].packageName, isInNewButton);
244
255
  } else if (!isInNewButton) {
245
256
  (0, _helpers.createCantMigrateFunctionUnknownError)(node, legacyIconImports[node.name].packageName, node.name, errorsManual);
257
+ (0, _helpers.addToListOfRanges)(node, errorRanges);
246
258
  guidance[(0, _helpers.locToString)(node)] = (0, _helpers.createGuidance)(legacyIconImports[node.name].packageName, isInNewButton);
247
259
  }
248
260
  }
249
261
  };
262
+ var checkIconReference = function checkIconReference(node) {
263
+ //check the reference to see if it's a legacy icon, if not exit early
264
+ if (!Object.keys(legacyIconImports).includes(node.name)) {
265
+ return;
266
+ }
267
+ //if this is an import statement then exit early
268
+ if (node.parent && ((0, _eslintCodemodUtils.isNodeOfType)(node.parent, 'ImportSpecifier') || (0, _eslintCodemodUtils.isNodeOfType)(node.parent, 'ImportDefaultSpecifier'))) {
269
+ return;
270
+ }
271
+ //if in Fallback prop, do not error
272
+ if (node.parent && node.parent.parent && (0, _eslintCodemodUtils.isNodeOfType)(node.parent.parent, 'JSXAttribute') && (0, _eslintCodemodUtils.isNodeOfType)(node.parent.parent.name, 'JSXIdentifier') && node.parent.parent.name.name === 'LEGACY_fallbackIcon') {
273
+ return;
274
+ }
275
+ // manually error
276
+ (0, _helpers.createCantMigrateIdentifierError)(node, legacyIconImports[node.name].packageName, node.name, errorsManual);
277
+ };
250
278
 
251
279
  /**
252
280
  * Checks if a legacy icon is being rendered and stores the errors in the global array
@@ -264,8 +292,8 @@ var createChecks = exports.createChecks = function createChecks(context) {
264
292
  }
265
293
  var name = node.openingElement.name.name;
266
294
  // Legacy icons rendered as JSX elements
267
- if (name in legacyIconImports) {
268
- var _node$parent2, _node$parent3, _size;
295
+ if (Object.keys(legacyIconImports).includes(name)) {
296
+ var _node$parent2, _node$parent3, _size, _size2;
269
297
  // Determine if inside a new button - if so:
270
298
  // - Assume spread props are safe - still error if props explicitly set to unmigratable values
271
299
  var insideNewButton = false;
@@ -349,13 +377,15 @@ var createChecks = exports.createChecks = function createChecks(context) {
349
377
  hasManualMigration = true;
350
378
  }
351
379
  var migrationMapObject = (0, _helpers.getMigrationMapObject)(legacyIconImports[name].packageName);
380
+ var upcomingIcon = (0, _helpers.getUpcomingIcons)(legacyIconImports[name].packageName);
352
381
  var newIcon = migrationMapObject === null || migrationMapObject === void 0 ? void 0 : migrationMapObject.newIcon;
353
- var isNewIconMigratable = (0, _helpers.canAutoMigrateNewIconBasedOnSize)(migrationMapObject === null || migrationMapObject === void 0 ? void 0 : migrationMapObject.sizeGuidance[(_size = size) !== null && _size !== void 0 ? _size : 'medium']);
354
- if (!hasManualMigration && newIcon && isNewIconMigratable) {
382
+ var isNewIconMigratable = (0, _helpers.canAutoMigrateNewIconBasedOnSize)(upcomingIcon ? upcomingIcon.sizeGuidance[(_size = size) !== null && _size !== void 0 ? _size : 'medium'] : migrationMapObject === null || migrationMapObject === void 0 ? void 0 : migrationMapObject.sizeGuidance[(_size2 = size) !== null && _size2 !== void 0 ? _size2 : 'medium']);
383
+ if (!hasManualMigration && (newIcon || upcomingIcon) && isNewIconMigratable) {
355
384
  (0, _helpers.createAutoMigrationError)(node, legacyIconImports[name].packageName, name, errorsAuto);
356
- } else if ((!newIcon || !isNewIconMigratable) && size) {
357
- (0, _helpers.createCantFindSuitableReplacementError)(node, legacyIconImports[name].packageName, name, errorsManual, migrationMapObject ? true : false);
385
+ } else if ((!newIcon && !upcomingIcon || !isNewIconMigratable) && size) {
386
+ (0, _helpers.createCantFindSuitableReplacementError)(node, legacyIconImports[name].packageName, name, errorsManual, upcomingIcon ? true : migrationMapObject ? true : false);
358
387
  }
388
+ (0, _helpers.addToListOfRanges)(node, errorRanges);
359
389
  guidance[(0, _helpers.locToString)(node)] = (0, _helpers.createGuidance)(legacyIconImports[name].packageName, insideNewButton, size && (0, _helpers.isSize)(size) ? size : undefined);
360
390
  }
361
391
  };
@@ -365,14 +395,15 @@ var createChecks = exports.createChecks = function createChecks(context) {
365
395
  * @param node The function call node found by ESLint
366
396
  */
367
397
  var checkCallExpression = function checkCallExpression(node) {
368
- if ('arguments' in node && node.arguments.length) {
398
+ if (Object.keys(node).includes('arguments') && node.arguments.length) {
369
399
  var _iterator8 = _createForOfIteratorHelper(node.arguments),
370
400
  _step8;
371
401
  try {
372
402
  for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
373
403
  var arg = _step8.value;
374
- if ((0, _eslintCodemodUtils.isNodeOfType)(arg, 'Identifier') && arg.name in legacyIconImports && legacyIconImports[arg.name].packageName) {
404
+ if ((0, _eslintCodemodUtils.isNodeOfType)(arg, 'Identifier') && Object.keys(legacyIconImports).includes(arg.name) && legacyIconImports[arg.name].packageName) {
375
405
  (0, _helpers.createCantMigrateFunctionUnknownError)(node, legacyIconImports[arg.name].packageName, arg.name, errorsManual);
406
+ (0, _helpers.addToListOfRanges)(node, errorRanges);
376
407
  guidance[(0, _helpers.locToString)(node)] = (0, _helpers.createGuidance)(legacyIconImports[arg.name].packageName);
377
408
  }
378
409
  }
@@ -393,30 +424,41 @@ var createChecks = exports.createChecks = function createChecks(context) {
393
424
  var _Object$entries$_i = (0, _slicedToArray2.default)(_Object$entries[_i], 2),
394
425
  _key = _Object$entries$_i[0],
395
426
  errorList = _Object$entries$_i[1];
396
- var node = 'node' in errorList.errors[0] ? errorList.errors[0].node : null;
397
- if (node) {
398
- var guidanceMessage = _key in guidance ? guidance[_key] : '';
399
- context.report({
400
- node: node,
401
- messageId: 'noLegacyIconsManualMigration',
402
- data: {
403
- iconName: errorList.iconName,
404
- importSource: errorList.importSource,
405
- guidance: isQuietMode ? guidanceMessage : "".concat(guidanceMessage, "For more information see the below errors.\n")
406
- }
407
- });
408
- if (!isQuietMode) {
409
- var _iterator9 = _createForOfIteratorHelper(errorList.errors),
410
- _step9;
411
- try {
412
- for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
413
- var error = _step9.value;
414
- context.report(error);
427
+ var _node = 'node' in errorList.errors[0] ? errorList.errors[0].node : null;
428
+ var cantMigrateIdentifierError = errorList.errors.find(function (x) {
429
+ return 'messageId' in x && x.messageId === 'cantMigrateIdentifier';
430
+ });
431
+ if (_node) {
432
+ var isInRange = false;
433
+ if (cantMigrateIdentifierError && (0, _helpers.isInRangeList)(_node, errorRanges)) {
434
+ isInRange = true;
435
+ }
436
+ if (isInRange && errorList.errors.length - 1 > 0 || !isInRange && errorList.errors.length > 0) {
437
+ var guidanceMessage = Object.keys(guidance).includes(_key) ? guidance[_key] : '';
438
+ context.report({
439
+ node: _node,
440
+ messageId: 'noLegacyIconsManualMigration',
441
+ data: {
442
+ iconName: errorList.iconName,
443
+ importSource: errorList.importSource,
444
+ guidance: isQuietMode ? guidanceMessage : "".concat(guidanceMessage, "For more information see the below errors.\n")
445
+ }
446
+ });
447
+ if (!isQuietMode) {
448
+ var _iterator9 = _createForOfIteratorHelper(errorList.errors),
449
+ _step9;
450
+ try {
451
+ for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
452
+ var error = _step9.value;
453
+ if ('messageId' in error && (error.messageId !== 'cantMigrateIdentifier' || error.messageId === 'cantMigrateIdentifier' && !isInRange)) {
454
+ context.report(error);
455
+ }
456
+ }
457
+ } catch (err) {
458
+ _iterator9.e(err);
459
+ } finally {
460
+ _iterator9.f();
415
461
  }
416
- } catch (err) {
417
- _iterator9.e(err);
418
- } finally {
419
- _iterator9.f();
420
462
  }
421
463
  }
422
464
  }
@@ -429,14 +471,19 @@ var createChecks = exports.createChecks = function createChecks(context) {
429
471
  _error = _Object$entries2$_i[1];
430
472
  // If there's a manual error that exists for this same component,
431
473
  // don't throw the auto error
432
- if (_key2 in errorsManual) {
433
- delete errorsAuto[_key2];
434
- continue;
474
+ if (Object.keys(errorsManual).includes(_key2)) {
475
+ var _cantMigrateIdentifierError = errorsManual[_key2].errors.find(function (x) {
476
+ return 'messageId' in x && x.messageId === 'cantMigrateIdentifier';
477
+ });
478
+ if (!_cantMigrateIdentifierError || _cantMigrateIdentifierError && errorsManual[_key2].errors.length > 1) {
479
+ delete errorsAuto[_key2];
480
+ continue;
481
+ }
435
482
  }
436
- var _node = 'node' in _error ? _error.node : null;
437
- if (_node) {
438
- var _guidanceMessage = _key2 in guidance ? guidance[_key2] : '';
439
- if ('data' in _error && _error.data) {
483
+ var _node2 = 'node' in _error ? _error.node : null;
484
+ if (_node2) {
485
+ var _guidanceMessage = Object.keys(guidance).includes(_key2) ? guidance[_key2] : '';
486
+ if (Object.keys(_error).includes('data') && _error.data) {
440
487
  _error.data.guidance = _guidanceMessage;
441
488
  }
442
489
  context.report(_error);
@@ -453,6 +500,7 @@ var createChecks = exports.createChecks = function createChecks(context) {
453
500
  checkIconAsProp: checkIconAsProp,
454
501
  checkJSXElement: checkJSXElement,
455
502
  checkCallExpression: checkCallExpression,
456
- throwErrors: throwErrors
503
+ throwErrors: throwErrors,
504
+ checkIconReference: checkIconReference
457
505
  };
458
506
  };
@@ -5,11 +5,12 @@ var _typeof = require("@babel/runtime/helpers/typeof");
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
- exports.locToString = exports.isSize = exports.getMigrationMapObject = exports.getLiteralStringValue = exports.createHelpers = exports.createGuidance = exports.createCantMigrateSpreadPropsError = exports.createCantMigrateSizeUnknown = exports.createCantMigrateReExportError = exports.createCantMigrateIdentifierError = exports.createCantMigrateFunctionUnknownError = exports.createCantMigrateColorError = exports.createCantFindSuitableReplacementError = exports.createAutoMigrationError = exports.canMigrateColor = exports.canAutoMigrateNewIconBasedOnSize = void 0;
8
+ exports.locToString = exports.isSize = exports.isInRangeList = exports.getUpcomingIcons = exports.getMigrationMapObject = exports.getLiteralStringValue = 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
9
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
10
10
  var _eslintCodemodUtils = require("eslint-codemod-utils");
11
11
  var _UNSAFE_migrationMap = _interopRequireWildcard(require("@atlaskit/icon/UNSAFE_migration-map"));
12
12
  var _getImportName = require("../utils/get-import-name");
13
+ var _upcomingIcons = require("./upcoming-icons");
13
14
  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
15
  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
  var sizes = ['small', 'medium', 'large', 'xlarge'];
@@ -24,11 +25,26 @@ var isSize = exports.isSize = function isSize(size) {
24
25
  */
25
26
  var getMigrationMapObject = exports.getMigrationMapObject = function getMigrationMapObject(iconPackage) {
26
27
  var key = getIconKey(iconPackage);
27
- if (key in _UNSAFE_migrationMap.default) {
28
+ if (Object.keys(_UNSAFE_migrationMap.default).includes(key)) {
28
29
  return _UNSAFE_migrationMap.default[key];
29
30
  }
30
31
  return null;
31
32
  };
33
+ var getUpcomingIcons = exports.getUpcomingIcons = function getUpcomingIcons(iconPackage) {
34
+ var key = getIconKey(iconPackage);
35
+ if (_upcomingIcons.upcomingIcons.includes(key)) {
36
+ var retval = {
37
+ sizeGuidance: {
38
+ small: 'swap',
39
+ medium: 'swap',
40
+ large: 'icon-tile',
41
+ xlarge: 'icon-tile'
42
+ }
43
+ };
44
+ return retval;
45
+ }
46
+ return null;
47
+ };
32
48
 
33
49
  /**
34
50
  * Returns the key of a legacy icon
@@ -54,42 +70,67 @@ var createGuidance = exports.createGuidance = function createGuidance(iconPackag
54
70
  var insideNewButton = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
55
71
  var size = arguments.length > 2 ? arguments[2] : undefined;
56
72
  var migrationMapObject = getMigrationMapObject(iconPackage);
57
- if (migrationMapObject) {
73
+ var upcomingIcon = getUpcomingIcons(iconPackage);
74
+ if (upcomingIcon) {
75
+ var guidance = '';
76
+ if (size) {
77
+ if (upcomingIcon.sizeGuidance[size] && canAutoMigrateNewIconBasedOnSize(upcomingIcon.sizeGuidance[size])) {
78
+ guidance += "Fix: An upcoming icon release is planned to migrate this legacy icon.";
79
+ } else {
80
+ guidance += "No equivalent icon for this size, ".concat(size, ", in the current or upcoming set of icons.");
81
+ }
82
+ guidance += "".concat(Object.keys(_UNSAFE_migrationMap.migrationOutcomeDescriptionMap).includes(upcomingIcon.sizeGuidance[size]) ? " Once the upcoming icons are released, please: ".concat(_UNSAFE_migrationMap.migrationOutcomeDescriptionMap[upcomingIcon.sizeGuidance[size]]) : ' No migration size advice given.', "\n");
83
+ } else {
84
+ 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";
85
+ for (var _i = 0, _Object$entries = Object.entries(upcomingIcon.sizeGuidance); _i < _Object$entries.length; _i++) {
86
+ var _Object$entries$_i = (0, _slicedToArray2.default)(_Object$entries[_i], 2),
87
+ _size = _Object$entries$_i[0],
88
+ value = _Object$entries$_i[1];
89
+ guidance += "\t- ".concat(_size, ": ");
90
+ if (!Object.keys(_UNSAFE_migrationMap.migrationOutcomeDescriptionMap).includes(value)) {
91
+ guidance += 'No migration advice given.\n';
92
+ } else {
93
+ guidance += "".concat(_UNSAFE_migrationMap.migrationOutcomeDescriptionMap[value], ".\n");
94
+ }
95
+ }
96
+ }
97
+ return guidance;
98
+ } else if (migrationMapObject) {
58
99
  var newIcon = migrationMapObject.newIcon;
59
100
  if (!newIcon) {
60
101
  return 'No equivalent icon in new set. An option is to contribute a custom icon into icon-labs package instead.\n';
61
102
  }
62
103
  var buttonGuidanceStr = "Please set 'spacing' property of the new icon to 'none', to ensure appropriate spacing inside `@atlaskit/button`.\n";
63
- var guidance = '';
104
+ var _guidance = '';
64
105
  if (size) {
65
106
  if (migrationMapObject.sizeGuidance[size] && canAutoMigrateNewIconBasedOnSize(migrationMapObject.sizeGuidance[size])) {
66
- guidance += "Fix: Use ".concat(newIcon.name, " from ").concat(newIcon.package, "/").concat(newIcon.type, "/").concat(newIcon.name, " instead.");
107
+ _guidance += "Fix: Use ".concat(newIcon.name, " from ").concat(newIcon.package, "/").concat(newIcon.type, "/").concat(newIcon.name, " instead.");
67
108
  } else {
68
- guidance += "No equivalent icon for this size, ".concat(size, ", in new set.");
109
+ _guidance += "No equivalent icon for this size, ".concat(size, ", in new set.");
69
110
  }
70
- guidance += "".concat(migrationMapObject.sizeGuidance[size] in _UNSAFE_migrationMap.migrationOutcomeDescriptionMap ? " Please: ".concat(_UNSAFE_migrationMap.migrationOutcomeDescriptionMap[migrationMapObject.sizeGuidance[size]]) : ' No migration size advice given.', "\n");
111
+ _guidance += "".concat(Object.keys(_UNSAFE_migrationMap.migrationOutcomeDescriptionMap).includes(migrationMapObject.sizeGuidance[size]) ? " Please: ".concat(_UNSAFE_migrationMap.migrationOutcomeDescriptionMap[migrationMapObject.sizeGuidance[size]]) : ' No migration size advice given.', "\n");
71
112
  } else {
72
- guidance = "Use ".concat(newIcon.name, " from ").concat(newIcon.package, "/").concat(newIcon.type, "/").concat(newIcon.name, " instead.\nMigration suggestions, depending on the legacy icon size:\n");
113
+ _guidance = "Use ".concat(newIcon.name, " from ").concat(newIcon.package, "/").concat(newIcon.type, "/").concat(newIcon.name, " instead.\nMigration suggestions, depending on the legacy icon size:\n");
73
114
  Object.entries(migrationMapObject.sizeGuidance).forEach(function (_ref) {
74
115
  var _ref2 = (0, _slicedToArray2.default)(_ref, 2),
75
116
  size = _ref2[0],
76
117
  value = _ref2[1];
77
- guidance += "\t- ".concat(size, ": ");
78
- if (!(value in _UNSAFE_migrationMap.migrationOutcomeDescriptionMap)) {
79
- guidance += 'No migration advice given.\n';
118
+ _guidance += "\t- ".concat(size, ": ");
119
+ if (!Object.keys(_UNSAFE_migrationMap.migrationOutcomeDescriptionMap).includes(value)) {
120
+ _guidance += 'No migration advice given.\n';
80
121
  } else {
81
- guidance += "".concat(_UNSAFE_migrationMap.migrationOutcomeDescriptionMap[value], ".\n");
122
+ _guidance += "".concat(_UNSAFE_migrationMap.migrationOutcomeDescriptionMap[value], ".\n");
82
123
  }
83
124
  });
84
125
  }
85
126
  if (insideNewButton) {
86
- guidance += buttonGuidanceStr;
127
+ _guidance += buttonGuidanceStr;
87
128
  } else if (size && size === 'medium') {
88
- guidance += "Setting the spacing property to '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";
129
+ _guidance += "Setting the spacing property to '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";
89
130
  } else if (size) {
90
- guidance += "In the new icon, please use spacing='none'.\n";
131
+ _guidance += "In the new icon, please use spacing='none'.\n";
91
132
  }
92
- return guidance;
133
+ return _guidance;
93
134
  } else {
94
135
  return "Migration suggestions not found for \"".concat(iconPackage, "\".\n");
95
136
  }
@@ -114,8 +155,11 @@ var canMigrateColor = exports.canMigrateColor = function canMigrateColor(color)
114
155
  }
115
156
  };
116
157
  var locToString = exports.locToString = function locToString(node) {
117
- var _node$loc, _node$loc2, _node$loc3, _node$loc4;
118
- 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);
158
+ if (node.range && node.range.length >= 2) {
159
+ return "".concat(node.range[0], ":").concat(node.range[1]);
160
+ } else {
161
+ return '';
162
+ }
119
163
  };
120
164
  var createCantMigrateReExportError = exports.createCantMigrateReExportError = function createCantMigrateReExportError(node, packageName, exportName, errors) {
121
165
  var myError = {
@@ -128,10 +172,10 @@ var createCantMigrateReExportError = exports.createCantMigrateReExportError = fu
128
172
  };
129
173
  pushManualError(locToString(node), errors, myError, packageName, exportName);
130
174
  };
131
- var createCantMigrateIdentifierError = exports.createCantMigrateIdentifierError = function createCantMigrateIdentifierError(node, packageName, exportName, errors) {
175
+ var createCantMigrateIdentifierMapOrArrayError = exports.createCantMigrateIdentifierMapOrArrayError = function createCantMigrateIdentifierMapOrArrayError(node, packageName, exportName, errors) {
132
176
  var myError = {
133
177
  node: node,
134
- messageId: 'cantMigrateIdentifier',
178
+ messageId: 'cantMigrateIdentifierMapOrArray',
135
179
  data: {
136
180
  packageName: packageName,
137
181
  exportName: exportName
@@ -139,6 +183,17 @@ var createCantMigrateIdentifierError = exports.createCantMigrateIdentifierError
139
183
  };
140
184
  pushManualError(locToString(node), errors, myError, packageName, exportName);
141
185
  };
186
+ var createCantMigrateIdentifierError = exports.createCantMigrateIdentifierError = function createCantMigrateIdentifierError(node, packageName, exportName, errors) {
187
+ var myError = {
188
+ node: node,
189
+ messageId: 'cantMigrateIdentifier',
190
+ data: {
191
+ iconSource: packageName,
192
+ iconName: exportName
193
+ }
194
+ };
195
+ pushManualError(locToString(node), errors, myError, packageName, exportName);
196
+ };
142
197
  var createCantFindSuitableReplacementError = exports.createCantFindSuitableReplacementError = function createCantFindSuitableReplacementError(node, importSource, iconName, errors, sizeIssue) {
143
198
  var myError = {
144
199
  node: node,
@@ -201,7 +256,7 @@ var createAutoMigrationError = exports.createAutoMigrationError = function creat
201
256
  errors[locToString(node)] = myError;
202
257
  };
203
258
  var pushManualError = function pushManualError(key, errors, myError, importSource, iconName) {
204
- if (key in errors) {
259
+ if (Object.keys(errors).includes(key)) {
205
260
  errors[key].errors.push(myError);
206
261
  } else {
207
262
  errors[key] = {
@@ -249,7 +304,7 @@ var createHelpers = exports.createHelpers = function createHelpers(context) {
249
304
  * @returns defaultValue if the configuration flag is not set, the defaultValue of the configuration flag otherwise
250
305
  */
251
306
  var getConfigFlag = function getConfigFlag(key, defaultValue) {
252
- if (context.options.length > 0 && context.options[0] && key in context.options[0]) {
307
+ if (context.options.length > 0 && context.options[0] && Object.keys(context.options[0]).includes(key)) {
253
308
  return context.options[0][key] === !defaultValue ? !defaultValue : defaultValue;
254
309
  }
255
310
  return defaultValue;
@@ -266,4 +321,22 @@ var createHelpers = exports.createHelpers = function createHelpers(context) {
266
321
  getTokenCallValue: getTokenCallValue,
267
322
  getConfigFlag: getConfigFlag
268
323
  };
324
+ };
325
+ var addToListOfRanges = exports.addToListOfRanges = function addToListOfRanges(node, sortedListOfRangesForErrors) {
326
+ if (node.range && node.range.length >= 2) {
327
+ sortedListOfRangesForErrors.push({
328
+ start: node.range[0],
329
+ end: node.range[1]
330
+ });
331
+ }
332
+ };
333
+ var isInRangeList = exports.isInRangeList = function isInRangeList(node, sortedListOfRangesForErrors) {
334
+ var range = node.range;
335
+ if (!range || range.length < 2) {
336
+ return false;
337
+ }
338
+ var found = sortedListOfRangesForErrors.find(function (currRange) {
339
+ return range[0] >= currRange.start && range[1] <= currRange.end;
340
+ });
341
+ return !!found;
269
342
  };
@@ -41,8 +41,8 @@ var rule = (0, _createRule.createLintRule)({
41
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
42
  cantMigrateSizeUnknown: "This usage of Icon sets the size via a variable or function that can't be determined.",
43
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."
44
+ cantMigrateIdentifierMapOrArray: "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
+ cantMigrateIdentifier: "This is a legacy icon, {{iconName}} from {{iconSource}}, being referenced. Please manually migrate."
46
46
  }
47
47
  },
48
48
  create: function create(context) {
@@ -58,7 +58,8 @@ var rule = (0, _createRule.createLintRule)({
58
58
  checkIconAsProp = _createChecks.checkIconAsProp,
59
59
  checkJSXElement = _createChecks.checkJSXElement,
60
60
  checkCallExpression = _createChecks.checkCallExpression,
61
- throwErrors = _createChecks.throwErrors;
61
+ throwErrors = _createChecks.throwErrors,
62
+ checkIconReference = _createChecks.checkIconReference;
62
63
  return (0, _errorBoundary.errorBoundary)({
63
64
  // Track imports of relevant components
64
65
  ImportDeclaration: checkImportDeclarations,
@@ -74,6 +75,7 @@ var rule = (0, _createRule.createLintRule)({
74
75
  JSXElement: checkJSXElement,
75
76
  // Icons called as an argument of a function (i.e. icon={DefaultIcon(AddIcon)})
76
77
  CallExpression: checkCallExpression,
78
+ Identifier: checkIconReference,
77
79
  'Program:exit': throwErrors
78
80
  }, failSilently);
79
81
  }
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.upcomingIcons = void 0;
7
+ var upcomingIcons = exports.upcomingIcons = ['app-switcher', 'check-circle-outline', 'export', 'file', 'flag-filled', 'lightbulb-filled', 'lock-filled', 'menu-expand', 'menu', 'notification-direct', 'notification', 'people-group', 'people', 'refresh', 'switcher', 'editor/align-image-center', 'editor/align-image-left', 'editor/align-image-right', 'editor/background-color', 'editor/bold', 'editor/indent', 'editor/italic', 'editor/horizontal-rule', 'editor-layout-three-equal', 'editor-layout-three-with-sidebars', 'editor/layout-two-equal', 'editor/layout-two-left-sidebars', 'editor/layout-two-right-sidebar', 'editor/media-center', 'editor/media-full-width', 'editor/media-wide', 'editor/number-list', 'emoji/activity', 'editor/file', 'emoji/flags', 'emoji/food', 'emoji/nature', 'emoji/people', 'emoji/productivity', 'emoji/travel', 'bitbucket/repos'];