@atlaskit/eslint-plugin-design-system 10.12.4 → 10.13.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 (50) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/dist/cjs/rules/no-legacy-icons/checks.js +90 -44
  3. package/dist/cjs/rules/no-legacy-icons/helpers.js +44 -12
  4. package/dist/cjs/rules/no-legacy-icons/index.js +5 -3
  5. package/dist/cjs/rules/use-heading/config/index.js +2 -1
  6. package/dist/cjs/rules/use-heading/transformers/native-elements.js +61 -31
  7. package/dist/cjs/rules/use-primitives-text/config/index.js +2 -1
  8. package/dist/cjs/rules/use-primitives-text/transformers/emphasis-elements.js +48 -26
  9. package/dist/cjs/rules/use-primitives-text/transformers/paragraph-elements.js +62 -51
  10. package/dist/cjs/rules/use-primitives-text/transformers/span-elements.js +56 -32
  11. package/dist/cjs/rules/use-primitives-text/transformers/strong-elements.js +48 -26
  12. package/dist/es2019/rules/no-legacy-icons/checks.js +75 -33
  13. package/dist/es2019/rules/no-legacy-icons/helpers.js +43 -11
  14. package/dist/es2019/rules/no-legacy-icons/index.js +5 -3
  15. package/dist/es2019/rules/use-heading/config/index.js +2 -1
  16. package/dist/es2019/rules/use-heading/transformers/native-elements.js +60 -29
  17. package/dist/es2019/rules/use-primitives-text/config/index.js +2 -1
  18. package/dist/es2019/rules/use-primitives-text/transformers/emphasis-elements.js +47 -24
  19. package/dist/es2019/rules/use-primitives-text/transformers/paragraph-elements.js +63 -52
  20. package/dist/es2019/rules/use-primitives-text/transformers/span-elements.js +55 -30
  21. package/dist/es2019/rules/use-primitives-text/transformers/strong-elements.js +47 -24
  22. package/dist/esm/rules/no-legacy-icons/checks.js +91 -45
  23. package/dist/esm/rules/no-legacy-icons/helpers.js +43 -11
  24. package/dist/esm/rules/no-legacy-icons/index.js +5 -3
  25. package/dist/esm/rules/use-heading/config/index.js +2 -1
  26. package/dist/esm/rules/use-heading/transformers/native-elements.js +61 -31
  27. package/dist/esm/rules/use-primitives-text/config/index.js +2 -1
  28. package/dist/esm/rules/use-primitives-text/transformers/emphasis-elements.js +48 -26
  29. package/dist/esm/rules/use-primitives-text/transformers/paragraph-elements.js +62 -51
  30. package/dist/esm/rules/use-primitives-text/transformers/span-elements.js +56 -32
  31. package/dist/esm/rules/use-primitives-text/transformers/strong-elements.js +48 -26
  32. package/dist/types/rules/no-legacy-icons/checks.d.ts +4 -1
  33. package/dist/types/rules/no-legacy-icons/helpers.d.ts +21 -14
  34. package/dist/types/rules/use-heading/config/index.d.ts +2 -1
  35. package/dist/types/rules/use-heading/transformers/native-elements.d.ts +5 -1
  36. package/dist/types/rules/use-primitives-text/config/index.d.ts +1 -0
  37. package/dist/types/rules/use-primitives-text/transformers/emphasis-elements.d.ts +6 -1
  38. package/dist/types/rules/use-primitives-text/transformers/paragraph-elements.d.ts +1 -0
  39. package/dist/types/rules/use-primitives-text/transformers/span-elements.d.ts +6 -1
  40. package/dist/types/rules/use-primitives-text/transformers/strong-elements.d.ts +6 -1
  41. package/dist/types-ts4.5/rules/no-legacy-icons/checks.d.ts +4 -1
  42. package/dist/types-ts4.5/rules/no-legacy-icons/helpers.d.ts +21 -14
  43. package/dist/types-ts4.5/rules/use-heading/config/index.d.ts +2 -1
  44. package/dist/types-ts4.5/rules/use-heading/transformers/native-elements.d.ts +5 -1
  45. package/dist/types-ts4.5/rules/use-primitives-text/config/index.d.ts +1 -0
  46. package/dist/types-ts4.5/rules/use-primitives-text/transformers/emphasis-elements.d.ts +6 -1
  47. package/dist/types-ts4.5/rules/use-primitives-text/transformers/paragraph-elements.d.ts +1 -0
  48. package/dist/types-ts4.5/rules/use-primitives-text/transformers/span-elements.d.ts +6 -1
  49. package/dist/types-ts4.5/rules/use-primitives-text/transformers/strong-elements.d.ts +6 -1
  50. package/package.json +2 -2
@@ -3,7 +3,7 @@ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol
3
3
  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); }
4
4
  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; }
5
5
  import { isNodeOfType } from 'eslint-codemod-utils';
6
- import { canAutoMigrateNewIconBasedOnSize, canMigrateColor, createAutoMigrationError, createCantFindSuitableReplacementError, createCantMigrateColorError, createCantMigrateFunctionUnknownError, createCantMigrateIdentifierError, createCantMigrateReExportError, createCantMigrateSizeUnknown, createCantMigrateSpreadPropsError, createGuidance, createHelpers, getMigrationMapObject, getUpcomingIcons, isSize, locToString } from './helpers';
6
+ import { addToListOfRanges, canAutoMigrateNewIconBasedOnSize, canMigrateColor, createAutoMigrationError, createCantFindSuitableReplacementError, createCantMigrateColorError, createCantMigrateFunctionUnknownError, createCantMigrateIdentifierError, createCantMigrateIdentifierMapOrArrayError, createCantMigrateReExportError, createCantMigrateSizeUnknown, createCantMigrateSpreadPropsError, createGuidance, createHelpers, getMigrationMapObject, getUpcomingIcons, isInRangeList, isSize, locToString } from './helpers';
7
7
  export var createChecks = function createChecks(context) {
8
8
  //create global variables to be shared by the checks
9
9
  var _createHelpers = createHelpers(context),
@@ -20,6 +20,9 @@ export var createChecks = function createChecks(context) {
20
20
  var shouldErrorForAutoMigration = getConfigFlag('shouldErrorForAutoMigration', true);
21
21
  var isQuietMode = getConfigFlag('quiet', false);
22
22
 
23
+ // Sorted list of ranges
24
+ var errorRanges = [];
25
+
23
26
  /**
24
27
  * Adds the legacy Icon and new button imports to the correct global arrays to be used by the other checks
25
28
  * @param node The import node found by ESLint
@@ -83,8 +86,8 @@ export var createChecks = function createChecks(context) {
83
86
  try {
84
87
  for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
85
88
  var decl = _step3.value;
86
- if (isNodeOfType(decl, 'VariableDeclarator') && 'init' in decl && 'id' in decl && decl.init && decl.id && 'name' in decl.id && decl.id.name && isNodeOfType(decl.init, 'Identifier')) {
87
- if (decl.init.name in legacyIconImports) {
89
+ if (isNodeOfType(decl, 'VariableDeclarator') && Object.keys(decl).includes('init') && Object.keys(decl).includes('id') && decl.init && decl.id && 'name' in decl.id && decl.id.name && isNodeOfType(decl.init, 'Identifier')) {
90
+ if (Object.keys(legacyIconImports).includes(decl.init.name)) {
88
91
  legacyIconImports[decl.id.name] = {
89
92
  packageName: legacyIconImports[decl.init.name].packageName,
90
93
  exported: legacyIconImports[decl.init.name].exported || isExported
@@ -109,16 +112,17 @@ export var createChecks = function createChecks(context) {
109
112
  var checkExportDefaultDeclaration = function checkExportDefaultDeclaration(node) {
110
113
  var exportName = '';
111
114
  var packageName = '';
112
- if ('declaration' in node && node.declaration && isNodeOfType(node.declaration, 'Identifier') && node.declaration.name in legacyIconImports) {
115
+ if (Object.keys(node).includes('declaration') && node.declaration && isNodeOfType(node.declaration, 'Identifier') && Object.keys(legacyIconImports).includes(node.declaration.name)) {
113
116
  packageName = legacyIconImports[node.declaration.name].packageName;
114
117
  exportName = 'Default export';
115
- } else if ('declaration' in node && node.declaration && isNodeOfType(node.declaration, 'AssignmentExpression') && isNodeOfType(node.declaration.left, 'Identifier') && isNodeOfType(node.declaration.right, 'Identifier') && node.declaration.right.name in legacyIconImports) {
118
+ } else if (Object.keys(node).includes('declaration') && node.declaration && isNodeOfType(node.declaration, 'AssignmentExpression') && isNodeOfType(node.declaration.left, 'Identifier') && isNodeOfType(node.declaration.right, 'Identifier') && Object.keys(legacyIconImports).includes(node.declaration.right.name)) {
116
119
  packageName = legacyIconImports[node.declaration.right.name].packageName;
117
120
  exportName = node.declaration.left.name;
118
121
  } else {
119
122
  return;
120
123
  }
121
124
  createCantMigrateReExportError(node, packageName, exportName, errorsManual);
125
+ addToListOfRanges(node, errorRanges);
122
126
  guidance[locToString(node)] = createGuidance(packageName);
123
127
  };
124
128
 
@@ -128,7 +132,7 @@ export var createChecks = function createChecks(context) {
128
132
  */
129
133
  var checkExportNamedVariables = function checkExportNamedVariables(node) {
130
134
  // export {default as AddIcon} from '@atlaskit/icon/glyph/add';
131
- if (node.source && isNodeOfType(node.source, 'Literal') && 'value' in node.source) {
135
+ if (node.source && isNodeOfType(node.source, 'Literal') && Object.keys(node.source).includes('value')) {
132
136
  var moduleSource = node.source.value;
133
137
  if (typeof moduleSource === 'string' && ['@atlaskit/icon/glyph/', '@atlaskit/icon-object/glyph/'].find(function (val) {
134
138
  return moduleSource.startsWith(val);
@@ -139,6 +143,7 @@ export var createChecks = function createChecks(context) {
139
143
  for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
140
144
  var spec = _step4.value;
141
145
  createCantMigrateReExportError(spec, moduleSource, spec.exported.name, errorsManual);
146
+ addToListOfRanges(spec, errorRanges);
142
147
  guidance[locToString(spec)] = createGuidance(moduleSource);
143
148
  }
144
149
  } catch (err) {
@@ -154,8 +159,9 @@ export var createChecks = function createChecks(context) {
154
159
  try {
155
160
  for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
156
161
  var decl = _step5.value;
157
- if (isNodeOfType(decl, 'VariableDeclarator') && 'init' in decl && decl.init && isNodeOfType(decl.init, 'Identifier') && decl.init.name in legacyIconImports) {
162
+ if (isNodeOfType(decl, 'VariableDeclarator') && Object.keys(decl).includes('init') && decl.init && isNodeOfType(decl.init, 'Identifier') && Object.keys(legacyIconImports).includes(decl.init.name)) {
158
163
  createCantMigrateReExportError(node, legacyIconImports[decl.init.name].packageName, decl.init.name, errorsManual);
164
+ addToListOfRanges(node, errorRanges);
159
165
  guidance[locToString(node)] = createGuidance(legacyIconImports[decl.init.name].packageName);
160
166
  }
161
167
  }
@@ -176,13 +182,14 @@ export var createChecks = function createChecks(context) {
176
182
  try {
177
183
  for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
178
184
  var _spec2 = _step6.value;
179
- if (_spec2.local.name in legacyIconImports) {
185
+ if (Object.keys(legacyIconImports).includes(_spec2.local.name)) {
180
186
  //update legacy imports to be exported
181
187
  legacyIconImports[_spec2.local.name] = {
182
188
  packageName: legacyIconImports[_spec2.local.name].packageName,
183
189
  exported: true
184
190
  };
185
191
  createCantMigrateReExportError(_spec2, legacyIconImports[_spec2.local.name].packageName, _spec2.exported.name, errorsManual);
192
+ addToListOfRanges(_spec2, errorRanges);
186
193
  guidance[locToString(_spec2)] = createGuidance(legacyIconImports[_spec2.local.name].packageName);
187
194
  }
188
195
  }
@@ -202,8 +209,9 @@ export var createChecks = function createChecks(context) {
202
209
  if (!isNodeOfType(node, 'Identifier')) {
203
210
  return;
204
211
  }
205
- if (node.name && node.name in legacyIconImports && legacyIconImports[node.name].packageName) {
206
- createCantMigrateIdentifierError(node, legacyIconImports[node.name].packageName, node.name, errorsManual);
212
+ if (node.name && Object.keys(legacyIconImports).includes(node.name) && legacyIconImports[node.name].packageName) {
213
+ createCantMigrateIdentifierMapOrArrayError(node, legacyIconImports[node.name].packageName, node.name, errorsManual);
214
+ addToListOfRanges(node, errorRanges);
207
215
  guidance[locToString(node)] = createGuidance(legacyIconImports[node.name].packageName);
208
216
  }
209
217
  };
@@ -222,7 +230,7 @@ export var createChecks = function createChecks(context) {
222
230
  if (!isNodeOfType(node.parent, 'JSXExpressionContainer') || !isNodeOfType(node.parent.parent, 'JSXAttribute') || !isNodeOfType(node.parent.parent.parent, 'JSXOpeningElement')) {
223
231
  return;
224
232
  }
225
- if (node.name in legacyIconImports && isNodeOfType(node.parent.parent.name, 'JSXIdentifier') && node.parent.parent.name.name !== 'LEGACY_fallbackIcon') {
233
+ if (Object.keys(legacyIconImports).includes(node.name) && isNodeOfType(node.parent.parent.name, 'JSXIdentifier') && node.parent.parent.name.name !== 'LEGACY_fallbackIcon') {
226
234
  var _migrationMapObject$s;
227
235
  var migrationMapObject = getMigrationMapObject(legacyIconImports[node.name].packageName);
228
236
  var upcomingIcon = getUpcomingIcons(legacyIconImports[node.name].packageName);
@@ -231,16 +239,35 @@ export var createChecks = function createChecks(context) {
231
239
  var isInNewButton = isNodeOfType(node.parent.parent.parent.name, 'JSXIdentifier') && newButtonImports.has(node.parent.parent.parent.name.name);
232
240
  if (newIcon && isInNewButton && isNewIconMigratable || upcomingIcon && isInNewButton && isNewIconMigratable) {
233
241
  createAutoMigrationError(node, legacyIconImports[node.name].packageName, node.name, errorsAuto);
242
+ addToListOfRanges(node, errorRanges);
234
243
  guidance[locToString(node)] = createGuidance(legacyIconImports[node.name].packageName, isInNewButton, 'medium');
235
244
  } else if (!newIcon && !upcomingIcon || !isNewIconMigratable) {
236
245
  createCantFindSuitableReplacementError(node, legacyIconImports[node.name].packageName, node.name, errorsManual);
246
+ addToListOfRanges(node, errorRanges);
237
247
  guidance[locToString(node)] = createGuidance(legacyIconImports[node.name].packageName, isInNewButton);
238
248
  } else if (!isInNewButton) {
239
249
  createCantMigrateFunctionUnknownError(node, legacyIconImports[node.name].packageName, node.name, errorsManual);
250
+ addToListOfRanges(node, errorRanges);
240
251
  guidance[locToString(node)] = createGuidance(legacyIconImports[node.name].packageName, isInNewButton);
241
252
  }
242
253
  }
243
254
  };
255
+ var checkIconReference = function checkIconReference(node) {
256
+ //check the reference to see if it's a legacy icon, if not exit early
257
+ if (!Object.keys(legacyIconImports).includes(node.name)) {
258
+ return;
259
+ }
260
+ //if this is an import statement then exit early
261
+ if (node.parent && (isNodeOfType(node.parent, 'ImportSpecifier') || isNodeOfType(node.parent, 'ImportDefaultSpecifier'))) {
262
+ return;
263
+ }
264
+ //if in Fallback prop, do not error
265
+ if (node.parent && node.parent.parent && isNodeOfType(node.parent.parent, 'JSXAttribute') && isNodeOfType(node.parent.parent.name, 'JSXIdentifier') && node.parent.parent.name.name === 'LEGACY_fallbackIcon') {
266
+ return;
267
+ }
268
+ // manually error
269
+ createCantMigrateIdentifierError(node, legacyIconImports[node.name].packageName, node.name, errorsManual);
270
+ };
244
271
 
245
272
  /**
246
273
  * Checks if a legacy icon is being rendered and stores the errors in the global array
@@ -258,7 +285,7 @@ export var createChecks = function createChecks(context) {
258
285
  }
259
286
  var name = node.openingElement.name.name;
260
287
  // Legacy icons rendered as JSX elements
261
- if (name in legacyIconImports) {
288
+ if (Object.keys(legacyIconImports).includes(name)) {
262
289
  var _node$parent2, _node$parent3, _size, _size2;
263
290
  // Determine if inside a new button - if so:
264
291
  // - Assume spread props are safe - still error if props explicitly set to unmigratable values
@@ -351,6 +378,7 @@ export var createChecks = function createChecks(context) {
351
378
  } else if ((!newIcon && !upcomingIcon || !isNewIconMigratable) && size) {
352
379
  createCantFindSuitableReplacementError(node, legacyIconImports[name].packageName, name, errorsManual, upcomingIcon ? true : migrationMapObject ? true : false);
353
380
  }
381
+ addToListOfRanges(node, errorRanges);
354
382
  guidance[locToString(node)] = createGuidance(legacyIconImports[name].packageName, insideNewButton, size && isSize(size) ? size : undefined);
355
383
  }
356
384
  };
@@ -360,14 +388,15 @@ export var createChecks = function createChecks(context) {
360
388
  * @param node The function call node found by ESLint
361
389
  */
362
390
  var checkCallExpression = function checkCallExpression(node) {
363
- if ('arguments' in node && node.arguments.length) {
391
+ if (Object.keys(node).includes('arguments') && node.arguments.length) {
364
392
  var _iterator8 = _createForOfIteratorHelper(node.arguments),
365
393
  _step8;
366
394
  try {
367
395
  for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
368
396
  var arg = _step8.value;
369
- if (isNodeOfType(arg, 'Identifier') && arg.name in legacyIconImports && legacyIconImports[arg.name].packageName) {
397
+ if (isNodeOfType(arg, 'Identifier') && Object.keys(legacyIconImports).includes(arg.name) && legacyIconImports[arg.name].packageName) {
370
398
  createCantMigrateFunctionUnknownError(node, legacyIconImports[arg.name].packageName, arg.name, errorsManual);
399
+ addToListOfRanges(node, errorRanges);
371
400
  guidance[locToString(node)] = createGuidance(legacyIconImports[arg.name].packageName);
372
401
  }
373
402
  }
@@ -388,30 +417,41 @@ export var createChecks = function createChecks(context) {
388
417
  var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
389
418
  _key = _Object$entries$_i[0],
390
419
  errorList = _Object$entries$_i[1];
391
- var node = 'node' in errorList.errors[0] ? errorList.errors[0].node : null;
392
- if (node) {
393
- var guidanceMessage = _key in guidance ? guidance[_key] : '';
394
- context.report({
395
- node: node,
396
- messageId: 'noLegacyIconsManualMigration',
397
- data: {
398
- iconName: errorList.iconName,
399
- importSource: errorList.importSource,
400
- guidance: isQuietMode ? guidanceMessage : "".concat(guidanceMessage, "For more information see the below errors.\n")
401
- }
402
- });
403
- if (!isQuietMode) {
404
- var _iterator9 = _createForOfIteratorHelper(errorList.errors),
405
- _step9;
406
- try {
407
- for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
408
- var error = _step9.value;
409
- context.report(error);
420
+ var _node = 'node' in errorList.errors[0] ? errorList.errors[0].node : null;
421
+ var cantMigrateIdentifierError = errorList.errors.find(function (x) {
422
+ return 'messageId' in x && x.messageId === 'cantMigrateIdentifier';
423
+ });
424
+ if (_node) {
425
+ var isInRange = false;
426
+ if (cantMigrateIdentifierError && isInRangeList(_node, errorRanges)) {
427
+ isInRange = true;
428
+ }
429
+ if (isInRange && errorList.errors.length - 1 > 0 || !isInRange && errorList.errors.length > 0) {
430
+ var guidanceMessage = Object.keys(guidance).includes(_key) ? guidance[_key] : '';
431
+ context.report({
432
+ node: _node,
433
+ messageId: 'noLegacyIconsManualMigration',
434
+ data: {
435
+ iconName: errorList.iconName,
436
+ importSource: errorList.importSource,
437
+ guidance: isQuietMode ? guidanceMessage : "".concat(guidanceMessage, "For more information see the below errors.\n")
438
+ }
439
+ });
440
+ if (!isQuietMode) {
441
+ var _iterator9 = _createForOfIteratorHelper(errorList.errors),
442
+ _step9;
443
+ try {
444
+ for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
445
+ var error = _step9.value;
446
+ if ('messageId' in error && (error.messageId !== 'cantMigrateIdentifier' || error.messageId === 'cantMigrateIdentifier' && !isInRange)) {
447
+ context.report(error);
448
+ }
449
+ }
450
+ } catch (err) {
451
+ _iterator9.e(err);
452
+ } finally {
453
+ _iterator9.f();
410
454
  }
411
- } catch (err) {
412
- _iterator9.e(err);
413
- } finally {
414
- _iterator9.f();
415
455
  }
416
456
  }
417
457
  }
@@ -424,14 +464,19 @@ export var createChecks = function createChecks(context) {
424
464
  _error = _Object$entries2$_i[1];
425
465
  // If there's a manual error that exists for this same component,
426
466
  // don't throw the auto error
427
- if (_key2 in errorsManual) {
428
- delete errorsAuto[_key2];
429
- continue;
467
+ if (Object.keys(errorsManual).includes(_key2)) {
468
+ var _cantMigrateIdentifierError = errorsManual[_key2].errors.find(function (x) {
469
+ return 'messageId' in x && x.messageId === 'cantMigrateIdentifier';
470
+ });
471
+ if (!_cantMigrateIdentifierError || _cantMigrateIdentifierError && errorsManual[_key2].errors.length > 1) {
472
+ delete errorsAuto[_key2];
473
+ continue;
474
+ }
430
475
  }
431
- var _node = 'node' in _error ? _error.node : null;
432
- if (_node) {
433
- var _guidanceMessage = _key2 in guidance ? guidance[_key2] : '';
434
- if ('data' in _error && _error.data) {
476
+ var _node2 = 'node' in _error ? _error.node : null;
477
+ if (_node2) {
478
+ var _guidanceMessage = Object.keys(guidance).includes(_key2) ? guidance[_key2] : '';
479
+ if (Object.keys(_error).includes('data') && _error.data) {
435
480
  _error.data.guidance = _guidanceMessage;
436
481
  }
437
482
  context.report(_error);
@@ -448,6 +493,7 @@ export var createChecks = function createChecks(context) {
448
493
  checkIconAsProp: checkIconAsProp,
449
494
  checkJSXElement: checkJSXElement,
450
495
  checkCallExpression: checkCallExpression,
451
- throwErrors: throwErrors
496
+ throwErrors: throwErrors,
497
+ checkIconReference: checkIconReference
452
498
  };
453
499
  };
@@ -98,7 +98,7 @@ export var createGuidance = function createGuidance(iconPackage) {
98
98
  } else {
99
99
  _guidance += "No equivalent icon for this size, ".concat(size, ", in new set.");
100
100
  }
101
- _guidance += "".concat(migrationMapObject.sizeGuidance[size] in migrationOutcomeDescriptionMap ? " Please: ".concat(migrationOutcomeDescriptionMap[migrationMapObject.sizeGuidance[size]]) : ' No migration size advice given.', "\n");
101
+ _guidance += "".concat(Object.keys(migrationOutcomeDescriptionMap).includes(migrationMapObject.sizeGuidance[size]) ? " Please: ".concat(migrationOutcomeDescriptionMap[migrationMapObject.sizeGuidance[size]]) : ' No migration size advice given.', "\n");
102
102
  } else {
103
103
  _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");
104
104
  Object.entries(migrationMapObject.sizeGuidance).forEach(function (_ref) {
@@ -106,7 +106,7 @@ export var createGuidance = function createGuidance(iconPackage) {
106
106
  size = _ref2[0],
107
107
  value = _ref2[1];
108
108
  _guidance += "\t- ".concat(size, ": ");
109
- if (!(value in migrationOutcomeDescriptionMap)) {
109
+ if (!Object.keys(migrationOutcomeDescriptionMap).includes(value)) {
110
110
  _guidance += 'No migration advice given.\n';
111
111
  } else {
112
112
  _guidance += "".concat(migrationOutcomeDescriptionMap[value], ".\n");
@@ -132,12 +132,12 @@ export var createGuidance = function createGuidance(iconPackage) {
132
132
  * @returns True if the color can be migrated, false otherwise
133
133
  */
134
134
  export var canMigrateColor = function canMigrateColor(color) {
135
- if (color.match(/^color\.text$/)) {
136
- return true;
137
- } else if (color.match(/^color\.icon/)) {
135
+ if (color.match(/^color\.icon/)) {
138
136
  return true;
139
137
  } else if (color.match(/^color\.link/)) {
140
138
  return true;
139
+ } else if (color.match(/^color\.text/)) {
140
+ return true;
141
141
  } else if (color === 'currentColor') {
142
142
  return true;
143
143
  } else {
@@ -145,8 +145,11 @@ export var canMigrateColor = function canMigrateColor(color) {
145
145
  }
146
146
  };
147
147
  export var locToString = function locToString(node) {
148
- var _node$loc, _node$loc2, _node$loc3, _node$loc4;
149
- 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);
148
+ if (node.range && node.range.length >= 2) {
149
+ return "".concat(node.range[0], ":").concat(node.range[1]);
150
+ } else {
151
+ return '';
152
+ }
150
153
  };
151
154
  export var createCantMigrateReExportError = function createCantMigrateReExportError(node, packageName, exportName, errors) {
152
155
  var myError = {
@@ -159,10 +162,10 @@ export var createCantMigrateReExportError = function createCantMigrateReExportEr
159
162
  };
160
163
  pushManualError(locToString(node), errors, myError, packageName, exportName);
161
164
  };
162
- export var createCantMigrateIdentifierError = function createCantMigrateIdentifierError(node, packageName, exportName, errors) {
165
+ export var createCantMigrateIdentifierMapOrArrayError = function createCantMigrateIdentifierMapOrArrayError(node, packageName, exportName, errors) {
163
166
  var myError = {
164
167
  node: node,
165
- messageId: 'cantMigrateIdentifier',
168
+ messageId: 'cantMigrateIdentifierMapOrArray',
166
169
  data: {
167
170
  packageName: packageName,
168
171
  exportName: exportName
@@ -170,6 +173,17 @@ export var createCantMigrateIdentifierError = function createCantMigrateIdentifi
170
173
  };
171
174
  pushManualError(locToString(node), errors, myError, packageName, exportName);
172
175
  };
176
+ export var createCantMigrateIdentifierError = function createCantMigrateIdentifierError(node, packageName, exportName, errors) {
177
+ var myError = {
178
+ node: node,
179
+ messageId: 'cantMigrateIdentifier',
180
+ data: {
181
+ iconSource: packageName,
182
+ iconName: exportName
183
+ }
184
+ };
185
+ pushManualError(locToString(node), errors, myError, packageName, exportName);
186
+ };
173
187
  export var createCantFindSuitableReplacementError = function createCantFindSuitableReplacementError(node, importSource, iconName, errors, sizeIssue) {
174
188
  var myError = {
175
189
  node: node,
@@ -232,7 +246,7 @@ export var createAutoMigrationError = function createAutoMigrationError(node, im
232
246
  errors[locToString(node)] = myError;
233
247
  };
234
248
  var pushManualError = function pushManualError(key, errors, myError, importSource, iconName) {
235
- if (key in errors) {
249
+ if (Object.keys(errors).includes(key)) {
236
250
  errors[key].errors.push(myError);
237
251
  } else {
238
252
  errors[key] = {
@@ -280,7 +294,7 @@ export var createHelpers = function createHelpers(context) {
280
294
  * @returns defaultValue if the configuration flag is not set, the defaultValue of the configuration flag otherwise
281
295
  */
282
296
  var getConfigFlag = function getConfigFlag(key, defaultValue) {
283
- if (context.options.length > 0 && context.options[0] && key in context.options[0]) {
297
+ if (context.options.length > 0 && context.options[0] && Object.keys(context.options[0]).includes(key)) {
284
298
  return context.options[0][key] === !defaultValue ? !defaultValue : defaultValue;
285
299
  }
286
300
  return defaultValue;
@@ -297,4 +311,22 @@ export var createHelpers = function createHelpers(context) {
297
311
  getTokenCallValue: getTokenCallValue,
298
312
  getConfigFlag: getConfigFlag
299
313
  };
314
+ };
315
+ export var addToListOfRanges = function addToListOfRanges(node, sortedListOfRangesForErrors) {
316
+ if (node.range && node.range.length >= 2) {
317
+ sortedListOfRangesForErrors.push({
318
+ start: node.range[0],
319
+ end: node.range[1]
320
+ });
321
+ }
322
+ };
323
+ export var isInRangeList = function isInRangeList(node, sortedListOfRangesForErrors) {
324
+ var range = node.range;
325
+ if (!range || range.length < 2) {
326
+ return false;
327
+ }
328
+ var found = sortedListOfRangesForErrors.find(function (currRange) {
329
+ return range[0] >= currRange.start && range[1] <= currRange.end;
330
+ });
331
+ return !!found;
300
332
  };
@@ -35,8 +35,8 @@ var rule = createLintRule({
35
35
  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}}' ",
36
36
  cantMigrateSizeUnknown: "This usage of Icon sets the size via a variable or function that can't be determined.",
37
37
  cantMigrateFunctionUnknown: "'{{iconName}}' from legacy '{{importSource}}' is used in unknown function/component. Please manually migrate this icon.",
38
- 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.",
39
- cantMigrateUnsafeProp: "Property '{{propName}}' with value of '{{value}}' is unable to be auto-migrated to the new button. Please manually migrate this icon."
38
+ 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.",
39
+ cantMigrateIdentifier: "This is a legacy icon, {{iconName}} from {{iconSource}}, being referenced. Please manually migrate."
40
40
  }
41
41
  },
42
42
  create: function create(context) {
@@ -52,7 +52,8 @@ var rule = createLintRule({
52
52
  checkIconAsProp = _createChecks.checkIconAsProp,
53
53
  checkJSXElement = _createChecks.checkJSXElement,
54
54
  checkCallExpression = _createChecks.checkCallExpression,
55
- throwErrors = _createChecks.throwErrors;
55
+ throwErrors = _createChecks.throwErrors,
56
+ checkIconReference = _createChecks.checkIconReference;
56
57
  return errorBoundary({
57
58
  // Track imports of relevant components
58
59
  ImportDeclaration: checkImportDeclarations,
@@ -68,6 +69,7 @@ var rule = createLintRule({
68
69
  JSXElement: checkJSXElement,
69
70
  // Icons called as an argument of a function (i.e. icon={DefaultIcon(AddIcon)})
70
71
  CallExpression: checkCallExpression,
72
+ Identifier: checkIconReference,
71
73
  'Program:exit': throwErrors
72
74
  }, failSilently);
73
75
  }
@@ -1,7 +1,8 @@
1
1
  var defaults = {
2
2
  failSilently: false,
3
3
  patterns: ['native-elements'],
4
- enableUnsafeAutofix: false
4
+ enableUnsafeAutofix: false,
5
+ enableUnsafeReport: false
5
6
  };
6
7
  export var getConfig = function getConfig(overrides) {
7
8
  return Object.assign({}, defaults, overrides);
@@ -20,63 +20,93 @@ export var NativeElements = {
20
20
  var context = _ref.context,
21
21
  config = _ref.config;
22
22
  // Check whether all criteria needed to make a transformation are met
23
- if (!NativeElements._check(node, {
24
- context: context,
25
- config: config
26
- })) {
27
- return;
28
- }
29
- var fix = NativeElements._fix(node, {
30
- context: context,
31
- config: config
32
- });
33
- context.report(_objectSpread({
34
- node: node,
35
- messageId: 'preferHeading'
36
- }, config.enableUnsafeAutofix ? {
37
- fix: fix
38
- } : {
39
- suggest: [{
40
- desc: "Convert to Heading",
23
+ var _NativeElements$_chec = NativeElements._check(node, {
24
+ context: context,
25
+ config: config
26
+ }),
27
+ success = _NativeElements$_chec.success,
28
+ autoFixable = _NativeElements$_chec.autoFixable;
29
+ if (success && autoFixable) {
30
+ var fix = NativeElements._fix(node, {
31
+ context: context,
32
+ config: config
33
+ });
34
+ context.report(_objectSpread({
35
+ node: node,
36
+ messageId: 'preferHeading'
37
+ }, config.enableUnsafeAutofix ? {
41
38
  fix: fix
42
- }]
43
- }));
39
+ } : {
40
+ suggest: [{
41
+ desc: "Convert to Heading",
42
+ fix: fix
43
+ }]
44
+ }));
45
+ } else if (success && config.enableUnsafeReport) {
46
+ context.report({
47
+ node: node,
48
+ messageId: 'preferHeading'
49
+ });
50
+ }
44
51
  },
45
52
  _check: function _check(node, _ref2) {
46
53
  var config = _ref2.config;
47
54
  if (!config.patterns.includes('native-elements')) {
48
- return false;
55
+ return {
56
+ success: false
57
+ };
49
58
  }
50
59
  if (!isNodeOfType(node, 'JSXElement')) {
51
- return false;
60
+ return {
61
+ success: false
62
+ };
52
63
  }
53
64
  if (!node.children.length) {
54
- return false;
55
- }
56
- if (!node.parent) {
57
- return false;
65
+ return {
66
+ success: false
67
+ };
58
68
  }
59
69
  var elementName = ast.JSXElement.getName(node);
60
70
  if (!Object.keys(tagSizeMap).includes(elementName)) {
61
- return false;
71
+ return {
72
+ success: false
73
+ };
74
+ }
75
+ if (!node.parent) {
76
+ return {
77
+ success: true,
78
+ autoFixable: false
79
+ };
62
80
  }
63
81
 
64
82
  // Element has to be first element of its siblings
65
83
  if (!(isNodeOfType(node.parent, 'JSXElement') || isNodeOfType(node.parent, 'JSXFragment'))) {
66
- return false;
84
+ return {
85
+ success: true,
86
+ autoFixable: false
87
+ };
67
88
  }
68
89
  var siblings = ast.JSXElement.getChildren(node.parent);
69
90
  if (siblings.length > 1) {
70
91
  var _siblings$0$range, _node$range, _siblings$0$range2, _node$range2;
71
92
  // Only report if element is first child element
72
93
  if (((_siblings$0$range = siblings[0].range) === null || _siblings$0$range === void 0 ? void 0 : _siblings$0$range[0]) !== ((_node$range = node.range) === null || _node$range === void 0 ? void 0 : _node$range[0]) || ((_siblings$0$range2 = siblings[0].range) === null || _siblings$0$range2 === void 0 ? void 0 : _siblings$0$range2[1]) !== ((_node$range2 = node.range) === null || _node$range2 === void 0 ? void 0 : _node$range2[1])) {
73
- return false;
94
+ return {
95
+ success: true,
96
+ autoFixable: false
97
+ };
74
98
  }
75
99
  }
76
100
  if (!ast.JSXElement.hasAllowedAttrsOnly(node, allowedAttrs)) {
77
- return false;
101
+ return {
102
+ success: true,
103
+ autoFixable: false
104
+ };
78
105
  }
79
- return true;
106
+ return {
107
+ success: true,
108
+ autoFixable: true
109
+ };
80
110
  },
81
111
  _fix: function _fix(node, _ref3) {
82
112
  var context = _ref3.context;
@@ -2,7 +2,8 @@ var defaults = {
2
2
  failSilently: false,
3
3
  patterns: ['paragraph-elements', 'span-elements', 'strong-elements', 'emphasis-elements'],
4
4
  inheritColor: false,
5
- enableUnsafeAutofix: false
5
+ enableUnsafeAutofix: false,
6
+ enableUnsafeReport: false
6
7
  };
7
8
  export var getConfig = function getConfig(overrides) {
8
9
  return Object.assign({}, defaults, overrides);