@atlaskit/eslint-plugin-design-system 10.17.3 → 10.18.1

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 (45) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/README.md +1 -1
  3. package/dist/cjs/rules/no-legacy-icons/checks.js +29 -137
  4. package/dist/cjs/rules/no-legacy-icons/helpers.js +247 -16
  5. package/dist/cjs/rules/no-legacy-icons/index.js +1 -0
  6. package/dist/cjs/rules/use-latest-xcss-syntax-typography/config/index.js +2 -1
  7. package/dist/cjs/rules/use-latest-xcss-syntax-typography/index.js +22 -5
  8. package/dist/cjs/rules/use-latest-xcss-syntax-typography/linters/common.js +5 -0
  9. package/dist/cjs/rules/use-latest-xcss-syntax-typography/linters/index.js +10 -3
  10. package/dist/cjs/rules/use-latest-xcss-syntax-typography/linters/{banned-property/index.js → restricted-property.js} +30 -10
  11. package/dist/cjs/rules/use-latest-xcss-syntax-typography/linters/wrapped-token-value.js +50 -0
  12. package/dist/es2019/rules/no-legacy-icons/checks.js +30 -108
  13. package/dist/es2019/rules/no-legacy-icons/helpers.js +200 -15
  14. package/dist/es2019/rules/no-legacy-icons/index.js +1 -0
  15. package/dist/es2019/rules/use-latest-xcss-syntax-typography/config/index.js +2 -1
  16. package/dist/es2019/rules/use-latest-xcss-syntax-typography/index.js +19 -6
  17. package/dist/es2019/rules/use-latest-xcss-syntax-typography/linters/common.js +1 -0
  18. package/dist/es2019/rules/use-latest-xcss-syntax-typography/linters/index.js +2 -1
  19. package/dist/es2019/rules/use-latest-xcss-syntax-typography/linters/restricted-property.js +61 -0
  20. package/dist/es2019/rules/use-latest-xcss-syntax-typography/linters/wrapped-token-value.js +44 -0
  21. package/dist/esm/rules/no-legacy-icons/checks.js +30 -137
  22. package/dist/esm/rules/no-legacy-icons/helpers.js +246 -15
  23. package/dist/esm/rules/no-legacy-icons/index.js +1 -0
  24. package/dist/esm/rules/use-latest-xcss-syntax-typography/config/index.js +2 -1
  25. package/dist/esm/rules/use-latest-xcss-syntax-typography/index.js +23 -6
  26. package/dist/esm/rules/use-latest-xcss-syntax-typography/linters/common.js +1 -0
  27. package/dist/esm/rules/use-latest-xcss-syntax-typography/linters/index.js +2 -1
  28. package/dist/esm/rules/use-latest-xcss-syntax-typography/linters/{banned-property/index.js → restricted-property.js} +29 -9
  29. package/dist/esm/rules/use-latest-xcss-syntax-typography/linters/wrapped-token-value.js +44 -0
  30. package/dist/types/rules/no-legacy-icons/helpers.d.ts +31 -60
  31. package/dist/types/rules/use-latest-xcss-syntax-typography/config/index.d.ts +3 -0
  32. package/dist/types/rules/use-latest-xcss-syntax-typography/linters/common.d.ts +6 -0
  33. package/dist/types/rules/use-latest-xcss-syntax-typography/linters/index.d.ts +2 -1
  34. package/dist/types/rules/use-latest-xcss-syntax-typography/linters/restricted-property.d.ts +6 -0
  35. package/dist/types/rules/use-latest-xcss-syntax-typography/linters/wrapped-token-value.d.ts +7 -0
  36. package/dist/types-ts4.5/rules/no-legacy-icons/helpers.d.ts +31 -60
  37. package/dist/types-ts4.5/rules/use-latest-xcss-syntax-typography/config/index.d.ts +3 -0
  38. package/dist/types-ts4.5/rules/use-latest-xcss-syntax-typography/linters/common.d.ts +6 -0
  39. package/dist/types-ts4.5/rules/use-latest-xcss-syntax-typography/linters/index.d.ts +2 -1
  40. package/dist/types-ts4.5/rules/use-latest-xcss-syntax-typography/linters/restricted-property.d.ts +6 -0
  41. package/dist/types-ts4.5/rules/use-latest-xcss-syntax-typography/linters/wrapped-token-value.d.ts +7 -0
  42. package/package.json +2 -6
  43. package/dist/es2019/rules/use-latest-xcss-syntax-typography/linters/banned-property/index.js +0 -40
  44. package/dist/types/rules/use-latest-xcss-syntax-typography/linters/banned-property/index.d.ts +0 -7
  45. package/dist/types-ts4.5/rules/use-latest-xcss-syntax-typography/linters/banned-property/index.d.ts +0 -7
@@ -1,13 +1,8 @@
1
- import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
3
- import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
4
- function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
5
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
6
1
  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; } } }; }
7
2
  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); }
8
3
  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; }
9
4
  import { isNodeOfType } from 'eslint-codemod-utils';
10
- import { addToListOfRanges, canAutoMigrateNewIconBasedOnSize, canMigrateColor, checkIfNewIconExist, createAutoMigrationError, createCantFindSuitableReplacementError, createCantMigrateColorError, createCantMigrateFunctionUnknownError, createCantMigrateIdentifierError, createCantMigrateIdentifierMapOrArrayError, createCantMigrateReExportError, createCantMigrateSizeUnknown, createCantMigrateSpreadPropsError, createGuidance, createHelpers, createImportFix, createPropFixes, getMigrationMapObject, getUpcomingIcons, isInRangeList, isInsideLegacyButton, isInsideNewButton, isSize, locToString } from './helpers';
5
+ import { addToListOfRanges, canAutoMigrateNewIconBasedOnSize, canMigrateColor, createAutoMigrationError, createCantFindSuitableReplacementError, createCantMigrateColorError, createCantMigrateFunctionUnknownError, createCantMigrateIdentifierError, createCantMigrateIdentifierMapOrArrayError, createCantMigrateReExportError, createCantMigrateSizeUnknown, createCantMigrateSpreadPropsError, createGuidance, createHelpers, getMigrationMapObject, getUpcomingIcons, isInsideLegacyButton, isInsideNewButton, isSize, locToString, throwAutoErrors, throwManualErrors } from './helpers';
11
6
  export var createChecks = function createChecks(context) {
12
7
  //create global variables to be shared by the checks
13
8
  var _createHelpers = createHelpers(context),
@@ -20,7 +15,6 @@ export var createChecks = function createChecks(context) {
20
15
  var errorsManual = {};
21
16
  var errorsAuto = {};
22
17
  var guidance = {};
23
- var autoIconJSXElementOccurrenceCount = 0;
24
18
 
25
19
  // Extract parameters
26
20
  var shouldErrorForManualMigration = getConfigFlag('shouldErrorForManualMigration', true);
@@ -51,7 +45,8 @@ export var createChecks = function createChecks(context) {
51
45
  legacyIconImports[spec.local.name] = {
52
46
  packageName: moduleSource,
53
47
  exported: false,
54
- importNode: node
48
+ importNode: node,
49
+ importSpecifier: spec.local.name
55
50
  };
56
51
  }
57
52
  }
@@ -69,7 +64,8 @@ export var createChecks = function createChecks(context) {
69
64
  migrationIconImports[spec.local.name] = {
70
65
  packageName: moduleSource,
71
66
  exported: false,
72
- importNode: node
67
+ importNode: node,
68
+ importSpecifier: spec.local.name
73
69
  };
74
70
  }
75
71
  });
@@ -130,7 +126,9 @@ export var createChecks = function createChecks(context) {
130
126
  if (Object.keys(legacyIconImports).includes(decl.init.name)) {
131
127
  legacyIconImports[decl.id.name] = {
132
128
  packageName: legacyIconImports[decl.init.name].packageName,
133
- exported: legacyIconImports[decl.init.name].exported || isExported
129
+ exported: legacyIconImports[decl.init.name].exported || isExported,
130
+ importNode: legacyIconImports[decl.init.name].importNode,
131
+ importSpecifier: legacyIconImports[decl.init.name].importSpecifier
134
132
  };
135
133
  } else if (newButtonImports.has(decl.init.name)) {
136
134
  newButtonImports.add(decl.id.name);
@@ -174,7 +172,7 @@ export var createChecks = function createChecks(context) {
174
172
  * @param node The named export node found by ESLint
175
173
  */
176
174
  var checkExportNamedVariables = function checkExportNamedVariables(node) {
177
- // export {default as AddIcon} from '@atlaskit/icon/glyph/add';
175
+ // Case: export {default as AddIcon} from '@atlaskit/icon/glyph/add';
178
176
  if (node.source && isNodeOfType(node.source, 'Literal') && Object.keys(node.source).includes('value')) {
179
177
  var moduleSource = node.source.value;
180
178
  if (typeof moduleSource === 'string' && ['@atlaskit/icon/glyph/', '@atlaskit/icon-object/glyph/'].find(function (val) {
@@ -199,7 +197,7 @@ export var createChecks = function createChecks(context) {
199
197
  }
200
198
  }
201
199
  } else if (node.declaration && isNodeOfType(node.declaration, 'VariableDeclaration')) {
202
- // export const Icon = AddIcon;
200
+ // Case: export const Icon = AddIcon;
203
201
  var _iterator6 = _createForOfIteratorHelper(node.declaration.declarations),
204
202
  _step6;
205
203
  try {
@@ -235,7 +233,9 @@ export var createChecks = function createChecks(context) {
235
233
  //update legacy imports to be exported
236
234
  legacyIconImports[_spec3.local.name] = {
237
235
  packageName: legacyIconImports[_spec3.local.name].packageName,
238
- exported: true
236
+ exported: true,
237
+ importNode: legacyIconImports[_spec3.local.name].importNode,
238
+ importSpecifier: legacyIconImports[_spec3.local.name].importSpecifier
239
239
  };
240
240
  createCantMigrateReExportError(_spec3, legacyIconImports[_spec3.local.name].packageName, _spec3.exported.name, errorsManual);
241
241
  addToListOfRanges(_spec3, errorRanges);
@@ -490,7 +490,6 @@ export var createChecks = function createChecks(context) {
490
490
  });
491
491
  var _shouldAddSpaciousSpacing = (_sizeProp && _sizeProp.type === 'JSXAttribute' && ((_sizeProp$value2 = _sizeProp.value) === null || _sizeProp$value2 === void 0 ? void 0 : _sizeProp$value2.type) === 'Literal' && _sizeProp.value.value === 'medium' || !_sizeProp) && !_insideNewButton && !insideLegacyButton;
492
492
  if (!hasManualMigration && (newIcon || upcomingIcon) && isNewIconMigratable) {
493
- autoIconJSXElementOccurrenceCount++;
494
493
  createAutoMigrationError({
495
494
  node: node,
496
495
  importSource: legacyIconImports[name].packageName,
@@ -544,132 +543,26 @@ export var createChecks = function createChecks(context) {
544
543
  * Throws the relevant errors in the correct order based on configs.
545
544
  */
546
545
  var throwErrors = function throwErrors() {
546
+ // Throw manual errors
547
547
  if (shouldErrorForManualMigration) {
548
- for (var _i = 0, _Object$entries = Object.entries(errorsManual); _i < _Object$entries.length; _i++) {
549
- var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
550
- _key = _Object$entries$_i[0],
551
- errorList = _Object$entries$_i[1];
552
- var _node = 'node' in errorList.errors[0] ? errorList.errors[0].node : null;
553
- var cantMigrateIdentifierError = errorList.errors.find(function (x) {
554
- return 'messageId' in x && x.messageId === 'cantMigrateIdentifier';
555
- });
556
- if (_node) {
557
- var isInRange = false;
558
- if (cantMigrateIdentifierError && isInRangeList(_node, errorRanges)) {
559
- isInRange = true;
560
- }
561
- if (isInRange && errorList.errors.length - 1 > 0 || !isInRange && errorList.errors.length > 0) {
562
- var guidanceMessage = Object.keys(guidance).includes(_key) ? guidance[_key] : '';
563
- context.report({
564
- node: _node,
565
- messageId: 'noLegacyIconsManualMigration',
566
- data: {
567
- iconName: errorList.iconName,
568
- importSource: errorList.importSource,
569
- guidance: isQuietMode ? guidanceMessage : "".concat(guidanceMessage, "For more information see the below errors.\n")
570
- }
571
- });
572
- if (!isQuietMode) {
573
- var _iterator10 = _createForOfIteratorHelper(errorList.errors),
574
- _step10;
575
- try {
576
- for (_iterator10.s(); !(_step10 = _iterator10.n()).done;) {
577
- var error = _step10.value;
578
- if ('messageId' in error && (error.messageId !== 'cantMigrateIdentifier' || error.messageId === 'cantMigrateIdentifier' && !isInRange)) {
579
- context.report(error);
580
- }
581
- }
582
- } catch (err) {
583
- _iterator10.e(err);
584
- } finally {
585
- _iterator10.f();
586
- }
587
- }
588
- }
589
- }
590
- }
548
+ throwManualErrors({
549
+ errorsManual: errorsManual,
550
+ errorRanges: errorRanges,
551
+ guidance: guidance,
552
+ context: context,
553
+ isQuietMode: isQuietMode
554
+ });
591
555
  }
592
556
  if (shouldErrorForAutoMigration) {
593
- var _loop = function _loop() {
594
- var _Object$entries2$_i = _slicedToArray(_Object$entries2[_i2], 2),
595
- key = _Object$entries2$_i[0],
596
- error = _Object$entries2$_i[1];
597
- // If there's a manual error that exists for this same component,
598
- // don't throw the auto error
599
- if (Object.keys(errorsManual).includes(key)) {
600
- var _cantMigrateIdentifierError = errorsManual[key].errors.find(function (x) {
601
- return 'messageId' in x && x.messageId === 'cantMigrateIdentifier';
602
- });
603
- if (!_cantMigrateIdentifierError || _cantMigrateIdentifierError && errorsManual[key].errors.length > 1) {
604
- delete errorsAuto[key];
605
- return 1; // continue
606
- }
607
- }
608
- var node = 'node' in error ? error.node : null;
609
- if (node) {
610
- var _guidanceMessage = Object.keys(guidance).includes(key) ? guidance[key] : '';
611
- if (Object.keys(error).includes('data') && error.data) {
612
- error.data.guidance = _guidanceMessage;
613
- }
614
- context.report(_objectSpread(_objectSpread({}, error), {}, {
615
- fix: function fix(fixer) {
616
- var _legacyIconImports$er, _migrationIconImports;
617
- // don't migration if the new icon is not available
618
- if (!error.data || shouldUseMigrationPath && !checkIfNewIconExist(error)) {
619
- return [];
620
- }
621
- var fixArguments = {
622
- metadata: error.data,
623
- legacyImportNode: (_legacyIconImports$er = legacyIconImports[error.data.iconName]) === null || _legacyIconImports$er === void 0 ? void 0 : _legacyIconImports$er.importNode,
624
- migrationImportNode: (_migrationIconImports = migrationIconImports[error.data.iconName]) === null || _migrationIconImports === void 0 ? void 0 : _migrationIconImports.importNode,
625
- shouldUseMigrationPath: shouldUseMigrationPath
626
- };
627
- var propsFixes = createPropFixes(_objectSpread(_objectSpread({}, fixArguments), {}, {
628
- node: node,
629
- fixer: fixer
630
- }));
631
- var importFixes = [];
632
- // Otherwise if there are multiple occurrences of the icon, import path will be handled after the prop fix
633
- if (autoIconJSXElementOccurrenceCount <= 1) {
634
- importFixes = createImportFix(_objectSpread(_objectSpread({}, fixArguments), {}, {
635
- fixer: fixer
636
- }));
637
- }
638
- return [].concat(_toConsumableArray(propsFixes), _toConsumableArray(importFixes));
639
- }
640
- }));
641
- }
642
- };
643
- for (var _i2 = 0, _Object$entries2 = Object.entries(errorsAuto); _i2 < _Object$entries2.length; _i2++) {
644
- if (_loop()) continue;
645
- }
646
-
647
- // Update import path at the end if there are multiple occurrences of the icon
648
- if (autoIconJSXElementOccurrenceCount > 1) {
649
- var _loop2 = function _loop2() {
650
- var _Object$entries3$_i = _slicedToArray(_Object$entries3[_i3], 2),
651
- _ = _Object$entries3$_i[0],
652
- error = _Object$entries3$_i[1];
653
- context.report(_objectSpread(_objectSpread({}, error), {}, {
654
- fix: function fix(fixer) {
655
- var _legacyIconImports$er2, _migrationIconImports2;
656
- if (!error.data || shouldUseMigrationPath && !checkIfNewIconExist(error)) {
657
- return [];
658
- }
659
- return createImportFix({
660
- metadata: error.data,
661
- fixer: fixer,
662
- legacyImportNode: (_legacyIconImports$er2 = legacyIconImports[error.data.iconName]) === null || _legacyIconImports$er2 === void 0 ? void 0 : _legacyIconImports$er2.importNode,
663
- migrationImportNode: (_migrationIconImports2 = migrationIconImports[error.data.iconName]) === null || _migrationIconImports2 === void 0 ? void 0 : _migrationIconImports2.importNode,
664
- shouldUseMigrationPath: shouldUseMigrationPath
665
- });
666
- }
667
- }));
668
- };
669
- for (var _i3 = 0, _Object$entries3 = Object.entries(errorsAuto); _i3 < _Object$entries3.length; _i3++) {
670
- _loop2();
671
- }
672
- }
557
+ throwAutoErrors({
558
+ errorsManual: errorsManual,
559
+ errorsAuto: errorsAuto,
560
+ legacyIconImports: legacyIconImports,
561
+ guidance: guidance,
562
+ migrationIconImports: migrationIconImports,
563
+ shouldUseMigrationPath: shouldUseMigrationPath,
564
+ context: context
565
+ });
673
566
  }
674
567
  };
675
568
  return {
@@ -1,4 +1,11 @@
1
+ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
1
3
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
4
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
5
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
6
+ 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; } } }; }
7
+ 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); }
8
+ 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; }
2
9
  import { isNodeOfType, literal } from 'eslint-codemod-utils';
3
10
  import baseMigrationMap, { migrationOutcomeDescriptionMap } from '@atlaskit/icon/UNSAFE_migration-map';
4
11
  import { upcomingIcons } from './upcoming-icons';
@@ -57,7 +64,7 @@ export var canAutoMigrateNewIconBasedOnSize = function canAutoMigrateNewIconBase
57
64
  * @param iconPackage string
58
65
  * @returns object of new icon name and import path
59
66
  */
60
- export var getNewIconNameAndImportPath = function getNewIconNameAndImportPath(iconPackage, shouldUseMigrationPath) {
67
+ var getNewIconNameAndImportPath = function getNewIconNameAndImportPath(iconPackage, shouldUseMigrationPath) {
61
68
  var legacyIconName = getIconKey(iconPackage);
62
69
  var migrationMapObject = getMigrationMapObject(iconPackage);
63
70
  if (!migrationMapObject || !migrationMapObject.newIcon) {
@@ -288,7 +295,7 @@ var pushManualError = function pushManualError(key, errors, myError, importSourc
288
295
  };
289
296
  }
290
297
  };
291
- export var getLiteralStringValue = function getLiteralStringValue(value) {
298
+ var getLiteralStringValue = function getLiteralStringValue(value) {
292
299
  if (!value) {
293
300
  return;
294
301
  }
@@ -356,7 +363,7 @@ export var addToListOfRanges = function addToListOfRanges(node, sortedListOfRang
356
363
  });
357
364
  }
358
365
  };
359
- export var isInRangeList = function isInRangeList(node, sortedListOfRangesForErrors) {
366
+ var isInRangeList = function isInRangeList(node, sortedListOfRangesForErrors) {
360
367
  var range = node.range;
361
368
  if (!range || range.length < 2) {
362
369
  return false;
@@ -401,6 +408,18 @@ var findProp = function findProp(attributes, propName) {
401
408
  return attr.type === 'JSXAttribute' && attr.name.name === propName;
402
409
  });
403
410
  };
411
+ var getNewIconNameForRenaming = function getNewIconNameForRenaming(isInManualArray, importSource, importSpecifier) {
412
+ var newIconName;
413
+ if (isInManualArray) {
414
+ newIconName = getNewIconNameAndImportPath(importSource).iconName;
415
+ var keyToName = newIconName ? newIconName[0].toUpperCase() + newIconName.slice(1) + 'Icon' : undefined;
416
+ newIconName = keyToName;
417
+ if (newIconName === undefined || importSpecifier === keyToName) {
418
+ newIconName = "".concat(keyToName, "New");
419
+ }
420
+ }
421
+ return newIconName;
422
+ };
404
423
 
405
424
  /**
406
425
  *
@@ -412,22 +431,22 @@ var findProp = function findProp(attributes, propName) {
412
431
  * @param migrationImportNode The migration import declaration node to replace, only present if shouldUseMigrationPath is false
413
432
  * @returns A list of fixers to migrate the icon
414
433
  */
415
- export var createImportFix = function createImportFix(_ref6) {
434
+ var createImportFix = function createImportFix(_ref6) {
416
435
  var fixer = _ref6.fixer,
417
436
  legacyImportNode = _ref6.legacyImportNode,
418
437
  metadata = _ref6.metadata,
419
438
  shouldUseMigrationPath = _ref6.shouldUseMigrationPath,
420
- migrationImportNode = _ref6.migrationImportNode;
439
+ migrationImportNode = _ref6.migrationImportNode,
440
+ newIconName = _ref6.newIconName;
421
441
  var fixes = [];
422
442
  var importSource = metadata.importSource;
423
443
  var importPath = migrationImportNode ? importSource.replace('/migration', '').split('--')[0] : getNewIconNameAndImportPath(importSource, shouldUseMigrationPath).importPath;
424
-
425
- // replace old icon import with icon import
426
- if (legacyImportNode && importPath) {
427
- fixes.push(fixer.replaceText(legacyImportNode.source, "'".concat(literal(importPath), "'")));
428
- }
429
- if (migrationImportNode && !shouldUseMigrationPath && importPath) {
430
- fixes.push(fixer.replaceText(migrationImportNode.source, "'".concat(literal(importPath), "'")));
444
+ var useMigrationPath = legacyImportNode && importPath;
445
+ var useFinalPath = migrationImportNode && !shouldUseMigrationPath && importPath;
446
+ if (useMigrationPath) {
447
+ fixes.push(newIconName ? fixer.insertTextBefore(legacyImportNode, "import ".concat(newIconName, " from '").concat(importPath, "';\n")) : fixer.replaceText(legacyImportNode.source, "'".concat(literal(importPath), "'")));
448
+ } else if (useFinalPath) {
449
+ fixes.push(newIconName ? fixer.insertTextBefore(migrationImportNode, "import ".concat(newIconName, " from '").concat(importPath, "';\n")) : fixer.replaceText(migrationImportNode.source, "'".concat(literal(importPath), "'")));
431
450
  }
432
451
  return fixes;
433
452
  };
@@ -442,13 +461,14 @@ export var createImportFix = function createImportFix(_ref6) {
442
461
  * @param migrationImportNode The migration import declaration node to replace, only present if shouldUseMigrationPath is false
443
462
  * @returns A list of fixers to migrate the icon
444
463
  */
445
- export var createPropFixes = function createPropFixes(_ref7) {
464
+ var createPropFixes = function createPropFixes(_ref7) {
446
465
  var node = _ref7.node,
447
466
  fixer = _ref7.fixer,
448
467
  legacyImportNode = _ref7.legacyImportNode,
449
468
  metadata = _ref7.metadata,
450
469
  shouldUseMigrationPath = _ref7.shouldUseMigrationPath,
451
- migrationImportNode = _ref7.migrationImportNode;
470
+ migrationImportNode = _ref7.migrationImportNode,
471
+ newIconName = _ref7.newIconName;
452
472
  var fixes = [];
453
473
  var importSource = metadata.importSource,
454
474
  spacing = metadata.spacing,
@@ -460,6 +480,9 @@ export var createPropFixes = function createPropFixes(_ref7) {
460
480
  var iconType = importPath !== null && importPath !== void 0 && importPath.startsWith('@atlaskit/icon/core') ? 'core' : 'utility';
461
481
  if (node.type === 'JSXElement') {
462
482
  var openingElement = node.openingElement;
483
+ if (newIconName) {
484
+ fixes.push(fixer.replaceText(openingElement.name, newIconName));
485
+ }
463
486
  var attributes = openingElement.attributes;
464
487
 
465
488
  // replace primaryColor prop with color
@@ -516,6 +539,8 @@ export var createPropFixes = function createPropFixes(_ref7) {
516
539
  }
517
540
  });
518
541
  }
542
+ } else if (node.type === 'Identifier' && newIconName) {
543
+ fixes.push(fixer.replaceText(node, newIconName));
519
544
  }
520
545
  return fixes;
521
546
  };
@@ -523,7 +548,7 @@ export var createPropFixes = function createPropFixes(_ref7) {
523
548
  /**
524
549
  * Check if the new icon exists in the migration map
525
550
  */
526
- export var checkIfNewIconExist = function checkIfNewIconExist(error) {
551
+ var checkIfNewIconExist = function checkIfNewIconExist(error) {
527
552
  var _error$data;
528
553
  if (!((_error$data = error.data) !== null && _error$data !== void 0 && _error$data.importSource)) {
529
554
  return false;
@@ -532,4 +557,210 @@ export var checkIfNewIconExist = function checkIfNewIconExist(error) {
532
557
  var _ref8 = baseMigrationMap[iconKey] || {},
533
558
  newIcon = _ref8.newIcon;
534
559
  return Boolean(newIcon);
560
+ };
561
+ export var throwManualErrors = function throwManualErrors(_ref9) {
562
+ var errorsManual = _ref9.errorsManual,
563
+ errorRanges = _ref9.errorRanges,
564
+ guidance = _ref9.guidance,
565
+ context = _ref9.context,
566
+ isQuietMode = _ref9.isQuietMode;
567
+ for (var _i2 = 0, _Object$entries2 = Object.entries(errorsManual); _i2 < _Object$entries2.length; _i2++) {
568
+ var _Object$entries2$_i = _slicedToArray(_Object$entries2[_i2], 2),
569
+ _key = _Object$entries2$_i[0],
570
+ errorList = _Object$entries2$_i[1];
571
+ var node = 'node' in errorList.errors[0] ? errorList.errors[0].node : null;
572
+ if (!node) {
573
+ return;
574
+ }
575
+ var cantMigrateIdentifierError = errorList.errors.find(function (x) {
576
+ return 'messageId' in x && x.messageId === 'cantMigrateIdentifier';
577
+ });
578
+ var isInRange = false;
579
+ if (cantMigrateIdentifierError && isInRangeList(node, errorRanges)) {
580
+ isInRange = true;
581
+ }
582
+ if (isInRange && errorList.errors.length - 1 > 0 || !isInRange && errorList.errors.length > 0) {
583
+ var guidanceMessage = Object.keys(guidance).includes(_key) ? guidance[_key] : '';
584
+ context.report({
585
+ node: node,
586
+ messageId: 'noLegacyIconsManualMigration',
587
+ data: {
588
+ iconName: errorList.iconName,
589
+ importSource: errorList.importSource,
590
+ guidance: isQuietMode ? guidanceMessage : "".concat(guidanceMessage, "For more information see the below errors.\n")
591
+ }
592
+ });
593
+ if (!isQuietMode) {
594
+ var _iterator = _createForOfIteratorHelper(errorList.errors),
595
+ _step;
596
+ try {
597
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
598
+ var error = _step.value;
599
+ if ('messageId' in error && (error.messageId !== 'cantMigrateIdentifier' || error.messageId === 'cantMigrateIdentifier' && !isInRange)) {
600
+ context.report(error);
601
+ }
602
+ }
603
+ } catch (err) {
604
+ _iterator.e(err);
605
+ } finally {
606
+ _iterator.f();
607
+ }
608
+ }
609
+ }
610
+ }
611
+ };
612
+
613
+ // Loops through automatic errors and them after adding the required suggestion/fix
614
+ export var throwAutoErrors = function throwAutoErrors(_ref10) {
615
+ var errorsManual = _ref10.errorsManual,
616
+ errorsAuto = _ref10.errorsAuto,
617
+ legacyIconImports = _ref10.legacyIconImports,
618
+ guidance = _ref10.guidance,
619
+ migrationIconImports = _ref10.migrationIconImports,
620
+ shouldUseMigrationPath = _ref10.shouldUseMigrationPath,
621
+ context = _ref10.context;
622
+ // Set of all the import sources that have manual errors (required later to check if a source has both manual and auto
623
+ // errors in one file making it impossible to just remove the legacy import)
624
+ var allManualErrorSources = Object.entries(errorsManual).reduce(function (result, option) {
625
+ var _option = _slicedToArray(option, 2),
626
+ key = _option[0],
627
+ errorInfo = _option[1];
628
+ if (!errorsAuto.hasOwnProperty(key)) {
629
+ result.add(errorInfo.importSource);
630
+ }
631
+ return result;
632
+ }, new Set());
633
+ //group errors by import source and remove any unwanted errors
634
+ var groupedErrorList = Object.entries(errorsAuto).reduce(function (result, option) {
635
+ var _option2 = _slicedToArray(option, 2),
636
+ key = _option2[0],
637
+ error = _option2[1];
638
+ //return early if no data
639
+ if (!error.data) {
640
+ return result;
641
+ }
642
+ if (Object.keys(errorsManual).includes(key)) {
643
+ var cantMigrateIdentifierError = errorsManual[key].errors.find(function (x) {
644
+ return 'messageId' in x && x.messageId === 'cantMigrateIdentifier';
645
+ });
646
+ // If cantMigrateIdentifier is the only manual error found we still want to throw the auto error
647
+ if (!(cantMigrateIdentifierError && errorsManual[key].errors.length === 1)) {
648
+ return result;
649
+ }
650
+ }
651
+ var importSource = error.data.importSource;
652
+ if (!result.hasOwnProperty(importSource)) {
653
+ result[importSource] = [];
654
+ }
655
+ result[importSource].push(_objectSpread({
656
+ key: key
657
+ }, error));
658
+ return result;
659
+ }, {});
660
+ var _loop = function _loop() {
661
+ var _Object$entries3$_i = _slicedToArray(_Object$entries3[_i3], 2),
662
+ importSource = _Object$entries3$_i[0],
663
+ errorList = _Object$entries3$_i[1];
664
+ var autoFixers = [];
665
+ // appliedErrorsForImport will contain all the errors FOR A SINGLE IMPORT and will be merged into errorListForReport
666
+ var appliedErrorsForImport = [];
667
+ // Loop over auto errors for a single import source
668
+ var _iterator2 = _createForOfIteratorHelper(errorList.entries()),
669
+ _step2;
670
+ try {
671
+ var _loop2 = function _loop2() {
672
+ var _legacyIconImports$er, _legacyIconImports$er2, _migrationIconImports;
673
+ var _step2$value = _slicedToArray(_step2.value, 2),
674
+ _ = _step2$value[0],
675
+ error = _step2$value[1];
676
+ var key = error.key;
677
+ var node = 'node' in error ? error.node : null;
678
+ // Check if there is a manual error for the same import source somewhere else in the same file
679
+ // If that is the case we'll need to provide a suggestion instead of auto-fixing as the suggestion will
680
+ // add another import without removing the old import and this needs to be validated
681
+ var isInManualArray = allManualErrorSources.has(importSource);
682
+ // New icon name for renaming if the icon is in the manual array
683
+ var newIconName = getNewIconNameForRenaming(isInManualArray, importSource, errorList[0].data ? (_legacyIconImports$er = legacyIconImports[errorList[0].data.iconName]) === null || _legacyIconImports$er === void 0 ? void 0 : _legacyIconImports$er.importSpecifier : undefined);
684
+ if (!node) {
685
+ return 0; // continue
686
+ }
687
+ var guidanceMessage = guidance.hasOwnProperty(key) ? guidance[key] : '';
688
+ if (Object.keys(error).includes('data') && error.data) {
689
+ error.data.guidance = guidanceMessage;
690
+ }
691
+ var fixArguments = error.data ? {
692
+ metadata: error.data,
693
+ legacyImportNode: (_legacyIconImports$er2 = legacyIconImports[error.data.iconName]) === null || _legacyIconImports$er2 === void 0 ? void 0 : _legacyIconImports$er2.importNode,
694
+ migrationImportNode: (_migrationIconImports = migrationIconImports[error.data.iconName]) === null || _migrationIconImports === void 0 ? void 0 : _migrationIconImports.importNode,
695
+ shouldUseMigrationPath: shouldUseMigrationPath,
696
+ newIconName: isInManualArray ? newIconName : undefined
697
+ } : null;
698
+ if (!error.data || shouldUseMigrationPath && !checkIfNewIconExist(error) || !fixArguments) {
699
+ return 0; // continue
700
+ }
701
+ if (isInManualArray) {
702
+ // provide suggestion if there is a manual error for the same import source and thus the legacy import can't be removed
703
+ error.suggest = [{
704
+ desc: 'Rename icon import, import from the new package, and update props.',
705
+ fix: function fix(fixer) {
706
+ return [].concat(_toConsumableArray(createPropFixes(_objectSpread(_objectSpread({}, fixArguments), {}, {
707
+ node: node,
708
+ fixer: fixer
709
+ }))), _toConsumableArray(createImportFix(_objectSpread(_objectSpread({}, fixArguments), {}, {
710
+ fixer: fixer
711
+ }))));
712
+ }
713
+ }];
714
+ } else {
715
+ // Update Guidance message for auto-fixing
716
+ if (error.data) {
717
+ error.data.guidance = error.data.guidance + "\nTo automatically fix this icon, run the auto-fixer attached to the first use of ".concat(importSource, " in this file - either manually, or by saving this file.");
718
+ }
719
+ // There should only be 1 import fix for each import source and thus only add this at the start of the list
720
+ if (autoFixers.length === 0) {
721
+ autoFixers.push(function (fixer) {
722
+ return createImportFix(_objectSpread(_objectSpread({}, fixArguments), {}, {
723
+ fixer: fixer
724
+ }));
725
+ });
726
+ }
727
+ // Push the prop fix regardless
728
+ autoFixers.push(function (fixer) {
729
+ return createPropFixes(_objectSpread(_objectSpread({}, fixArguments), {}, {
730
+ node: node,
731
+ fixer: fixer
732
+ }));
733
+ });
734
+ }
735
+ // Add the error to the appliedErrorsForImport, ready to be thrown later
736
+ appliedErrorsForImport.push(error);
737
+ },
738
+ _ret;
739
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
740
+ _ret = _loop2();
741
+ if (_ret === 0) continue;
742
+ }
743
+ // We want to have only 1 fix for each import source that is not in the manual array
744
+ // NOTE: If in the manual array, suggestions have been applied above and autoFixers.length will be 0 which will mean no fix is added
745
+ } catch (err) {
746
+ _iterator2.e(err);
747
+ } finally {
748
+ _iterator2.f();
749
+ }
750
+ if (autoFixers.length > 0) {
751
+ // Add the fix to only one of the errors in the list of errors from the current import source
752
+ appliedErrorsForImport[0].fix = function (fixer) {
753
+ return autoFixers.flatMap(function (autoFixer) {
754
+ return autoFixer(fixer);
755
+ });
756
+ };
757
+ }
758
+ // throw errors
759
+ appliedErrorsForImport.forEach(function (error) {
760
+ context.report(error);
761
+ });
762
+ };
763
+ for (var _i3 = 0, _Object$entries3 = Object.entries(groupedErrorList); _i3 < _Object$entries3.length; _i3++) {
764
+ _loop();
765
+ }
535
766
  };
@@ -6,6 +6,7 @@ var rule = createLintRule({
6
6
  meta: {
7
7
  name: 'no-legacy-icons',
8
8
  fixable: 'code',
9
+ hasSuggestions: true,
9
10
  type: 'problem',
10
11
  docs: {
11
12
  description: 'Enforces no legacy icons are used.',
@@ -1,5 +1,6 @@
1
1
  var defaults = {
2
- failSilently: false
2
+ failSilently: false,
3
+ patterns: ['restricted-property', 'wrapped-token-value']
3
4
  };
4
5
  export var getConfig = function getConfig(overrides) {
5
6
  return Object.assign({}, defaults, overrides);
@@ -1,7 +1,8 @@
1
1
  import { createLintRule } from '../utils/create-rule';
2
2
  import { errorBoundary } from '../utils/error-boundary';
3
3
  import { getConfig } from './config';
4
- import { BannedProperty } from './linters';
4
+ import { RestrictedProperty, WrappedTokenValue } from './linters';
5
+ var typescriptErrorMessage = 'There is ongoing work to make this a TypeScript error. Once that happens, you will have to delete/refactor anyway.';
5
6
  var rule = createLintRule({
6
7
  meta: {
7
8
  name: 'use-latest-xcss-syntax-typography',
@@ -14,20 +15,36 @@ var rule = createLintRule({
14
15
  severity: 'warn'
15
16
  },
16
17
  messages: {
17
- noUnsafeTypographyProperties: "Don't set '{{ property }}' on xcss. They are unsafe as they allow invalid combinations of typography tokens. There is ongoing work to make this a TypeScript error. Once that happens, you will have to delete/refactor anyway."
18
+ noRestrictedTypographyProperties: "Don't set '{{ property }}' on xcss as it allows invalid combinations of typography tokens. ".concat(typescriptErrorMessage),
19
+ noRestrictedTypographyPropertiesHeading: "Don't set '{{ property }}' on xcss in combination with 'font' heading tokens. ".concat(typescriptErrorMessage),
20
+ noWrappedTokenTypographyValues: "Don't wrap typography tokens in xcss. ".concat(typescriptErrorMessage)
18
21
  }
19
22
  },
20
23
  create: function create(context) {
21
24
  var config = getConfig(context.options[0]);
22
25
  return errorBoundary({
23
26
  'CallExpression[callee.name="xcss"] ObjectExpression > Property > Identifier[name=/(fontSize|lineHeight|fontWeight|letterSpacing)/]': function CallExpressionCalleeNameXcssObjectExpressionPropertyIdentifierNameFontSizeLineHeightFontWeightLetterSpacing(node) {
24
- return BannedProperty.lint(node, {
25
- context: context
27
+ return RestrictedProperty.lint(node, {
28
+ context: context,
29
+ config: config
26
30
  });
27
31
  },
28
32
  'CallExpression[callee.name="xcss"] ObjectExpression > Property > Literal[value=/(fontSize|lineHeight|fontWeight|letterSpacing)/]': function CallExpressionCalleeNameXcssObjectExpressionPropertyLiteralValueFontSizeLineHeightFontWeightLetterSpacing(node) {
29
- return BannedProperty.lint(node, {
30
- context: context
33
+ return RestrictedProperty.lint(node, {
34
+ context: context,
35
+ config: config
36
+ });
37
+ },
38
+ 'CallExpression[callee.name="xcss"] ObjectExpression > Property > Identifier[name=/(font|fontFamily|fontWeight)/]': function CallExpressionCalleeNameXcssObjectExpressionPropertyIdentifierNameFontFontFamilyFontWeight(node) {
39
+ return WrappedTokenValue.lint(node, {
40
+ context: context,
41
+ config: config
42
+ });
43
+ },
44
+ 'CallExpression[callee.name="xcss"] ObjectExpression > Property > Literal[value=/(font|fontFamily|fontWeight)/]': function CallExpressionCalleeNameXcssObjectExpressionPropertyLiteralValueFontFontFamilyFontWeight(node) {
45
+ return WrappedTokenValue.lint(node, {
46
+ context: context,
47
+ config: config
31
48
  });
32
49
  }
33
50
  }, config);