@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
@@ -5,7 +5,8 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.getConfig = void 0;
7
7
  var defaults = {
8
- failSilently: false
8
+ failSilently: false,
9
+ patterns: ['restricted-property', 'wrapped-token-value']
9
10
  };
10
11
  var getConfig = exports.getConfig = function getConfig(overrides) {
11
12
  return Object.assign({}, defaults, overrides);
@@ -8,6 +8,7 @@ var _createRule = require("../utils/create-rule");
8
8
  var _errorBoundary = require("../utils/error-boundary");
9
9
  var _config = require("./config");
10
10
  var _linters = require("./linters");
11
+ var typescriptErrorMessage = 'There is ongoing work to make this a TypeScript error. Once that happens, you will have to delete/refactor anyway.';
11
12
  var rule = (0, _createRule.createLintRule)({
12
13
  meta: {
13
14
  name: 'use-latest-xcss-syntax-typography',
@@ -20,20 +21,36 @@ var rule = (0, _createRule.createLintRule)({
20
21
  severity: 'warn'
21
22
  },
22
23
  messages: {
23
- 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."
24
+ noRestrictedTypographyProperties: "Don't set '{{ property }}' on xcss as it allows invalid combinations of typography tokens. ".concat(typescriptErrorMessage),
25
+ noRestrictedTypographyPropertiesHeading: "Don't set '{{ property }}' on xcss in combination with 'font' heading tokens. ".concat(typescriptErrorMessage),
26
+ noWrappedTokenTypographyValues: "Don't wrap typography tokens in xcss. ".concat(typescriptErrorMessage)
24
27
  }
25
28
  },
26
29
  create: function create(context) {
27
30
  var config = (0, _config.getConfig)(context.options[0]);
28
31
  return (0, _errorBoundary.errorBoundary)({
29
32
  'CallExpression[callee.name="xcss"] ObjectExpression > Property > Identifier[name=/(fontSize|lineHeight|fontWeight|letterSpacing)/]': function CallExpressionCalleeNameXcssObjectExpressionPropertyIdentifierNameFontSizeLineHeightFontWeightLetterSpacing(node) {
30
- return _linters.BannedProperty.lint(node, {
31
- context: context
33
+ return _linters.RestrictedProperty.lint(node, {
34
+ context: context,
35
+ config: config
32
36
  });
33
37
  },
34
38
  'CallExpression[callee.name="xcss"] ObjectExpression > Property > Literal[value=/(fontSize|lineHeight|fontWeight|letterSpacing)/]': function CallExpressionCalleeNameXcssObjectExpressionPropertyLiteralValueFontSizeLineHeightFontWeightLetterSpacing(node) {
35
- return _linters.BannedProperty.lint(node, {
36
- context: context
39
+ return _linters.RestrictedProperty.lint(node, {
40
+ context: context,
41
+ config: config
42
+ });
43
+ },
44
+ 'CallExpression[callee.name="xcss"] ObjectExpression > Property > Identifier[name=/(font|fontFamily|fontWeight)/]': function CallExpressionCalleeNameXcssObjectExpressionPropertyIdentifierNameFontFontFamilyFontWeight(node) {
45
+ return _linters.WrappedTokenValue.lint(node, {
46
+ context: context,
47
+ config: config
48
+ });
49
+ },
50
+ 'CallExpression[callee.name="xcss"] ObjectExpression > Property > Literal[value=/(font|fontFamily|fontWeight)/]': function CallExpressionCalleeNameXcssObjectExpressionPropertyLiteralValueFontFontFamilyFontWeight(node) {
51
+ return _linters.WrappedTokenValue.lint(node, {
52
+ context: context,
53
+ config: config
37
54
  });
38
55
  }
39
56
  }, config);
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
@@ -3,10 +3,17 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- Object.defineProperty(exports, "BannedProperty", {
6
+ Object.defineProperty(exports, "RestrictedProperty", {
7
7
  enumerable: true,
8
8
  get: function get() {
9
- return _bannedProperty.BannedProperty;
9
+ return _restrictedProperty.RestrictedProperty;
10
10
  }
11
11
  });
12
- var _bannedProperty = require("./banned-property");
12
+ Object.defineProperty(exports, "WrappedTokenValue", {
13
+ enumerable: true,
14
+ get: function get() {
15
+ return _wrappedTokenValue.WrappedTokenValue;
16
+ }
17
+ });
18
+ var _restrictedProperty = require("./restricted-property");
19
+ var _wrappedTokenValue = require("./wrapped-token-value");
@@ -3,15 +3,19 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.BannedProperty = void 0;
6
+ exports.RestrictedProperty = void 0;
7
7
  var _eslintCodemodUtils = require("eslint-codemod-utils");
8
8
  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; } } }; }
9
9
  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); }
10
10
  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; } /* eslint-disable @repo/internal/react/require-jsdoc */
11
- var BannedProperty = exports.BannedProperty = {
11
+ var RestrictedProperty = exports.RestrictedProperty = {
12
12
  lint: function lint(node, _ref) {
13
- var context = _ref.context;
14
- if (BannedProperty._check(node)) {
13
+ var context = _ref.context,
14
+ config = _ref.config;
15
+ if (RestrictedProperty._check(node, {
16
+ context: context,
17
+ config: config
18
+ })) {
15
19
  var property = 'fontSize, lineHeight, fontWeight or letterSpacing';
16
20
  if ((0, _eslintCodemodUtils.isNodeOfType)(node, 'Identifier')) {
17
21
  property = node.name;
@@ -20,14 +24,19 @@ var BannedProperty = exports.BannedProperty = {
20
24
  }
21
25
  context.report({
22
26
  node: node,
23
- messageId: 'noUnsafeTypographyProperties',
27
+ messageId: property === 'fontWeight' ? 'noRestrictedTypographyPropertiesHeading' : 'noRestrictedTypographyProperties',
24
28
  data: {
25
29
  property: property
26
30
  }
27
31
  });
28
32
  }
29
33
  },
30
- _check: function _check(node) {
34
+ _check: function _check(node, _ref2) {
35
+ var config = _ref2.config;
36
+ if (!config.patterns.includes('restricted-property')) {
37
+ return false;
38
+ }
39
+
31
40
  // Prevent font weight being used in combination with heading tokens
32
41
  if ((0, _eslintCodemodUtils.isNodeOfType)(node, 'Identifier') && node.name === 'fontWeight' || (0, _eslintCodemodUtils.isNodeOfType)(node, 'Literal') && node.value === 'fontWeight') {
33
42
  if ((0, _eslintCodemodUtils.isNodeOfType)(node.parent.parent, 'ObjectExpression')) {
@@ -35,11 +44,22 @@ var BannedProperty = exports.BannedProperty = {
35
44
  _step;
36
45
  try {
37
46
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
47
+ var _property$value$value;
38
48
  var property = _step.value;
39
- if ((0, _eslintCodemodUtils.isNodeOfType)(property, 'Property') && (0, _eslintCodemodUtils.isNodeOfType)(property.value, 'CallExpression') && (0, _eslintCodemodUtils.isNodeOfType)(property.value.callee, 'Identifier') && (0, _eslintCodemodUtils.isNodeOfType)(property.value.arguments[0], 'Literal')) {
40
- if (property.value.callee.name === 'token' && typeof property.value.arguments[0].value === 'string' && property.value.arguments[0].value.includes('font.heading')) {
41
- return true;
42
- }
49
+ // Only looking for heading token on `font` property
50
+ var isFontProperty = (0, _eslintCodemodUtils.isNodeOfType)(property, 'Property') && ((0, _eslintCodemodUtils.isNodeOfType)(property.key, 'Literal') && property.key.value === 'font' || (0, _eslintCodemodUtils.isNodeOfType)(property.key, 'Identifier') && property.key.name === 'font');
51
+ if (!isFontProperty) {
52
+ continue;
53
+ }
54
+
55
+ // Checking for heading token string, for example xcss({ font: 'font.heading.medium' })
56
+ if ((0, _eslintCodemodUtils.isNodeOfType)(property.value, 'Literal') && typeof property.value.value === 'string' && (_property$value$value = property.value.value) !== null && _property$value$value !== void 0 && _property$value$value.startsWith('font.heading')) {
57
+ return true;
58
+ }
59
+
60
+ // Checking for wrapped heading token, for example xcss({ font: token('font.heading.medium') })
61
+ if ((0, _eslintCodemodUtils.isNodeOfType)(property.value, 'CallExpression') && (0, _eslintCodemodUtils.isNodeOfType)(property.value.callee, 'Identifier') && property.value.callee.name === 'token' && (0, _eslintCodemodUtils.isNodeOfType)(property.value.arguments[0], 'Literal') && typeof property.value.arguments[0].value === 'string' && property.value.arguments[0].value.startsWith('font.heading')) {
62
+ return true;
43
63
  }
44
64
  }
45
65
  } catch (err) {
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.WrappedTokenValue = void 0;
7
+ var _eslintCodemodUtils = require("eslint-codemod-utils");
8
+ /* eslint-disable @repo/internal/react/require-jsdoc */
9
+
10
+ var messageId = 'noWrappedTokenTypographyValues';
11
+ var WrappedTokenValue = exports.WrappedTokenValue = {
12
+ lint: function lint(node, _ref) {
13
+ var context = _ref.context,
14
+ config = _ref.config;
15
+ if (WrappedTokenValue._check(node, {
16
+ context: context,
17
+ config: config
18
+ })) {
19
+ context.report({
20
+ node: node,
21
+ messageId: messageId,
22
+ fix: WrappedTokenValue._fix(node)
23
+ });
24
+ }
25
+ },
26
+ _check: function _check(node, _ref2) {
27
+ var config = _ref2.config;
28
+ if (!config.patterns.includes('wrapped-token-value')) {
29
+ return false;
30
+ }
31
+ if ((0, _eslintCodemodUtils.isNodeOfType)(node.parent, 'Property') && (0, _eslintCodemodUtils.isNodeOfType)(node.parent.value, 'CallExpression') && (0, _eslintCodemodUtils.isNodeOfType)(node.parent.value.callee, 'Identifier') && node.parent.value.callee.name === 'token' && node.parent.value.arguments.length >= 1) {
32
+ return true;
33
+ }
34
+ return false;
35
+ },
36
+ _fix: function _fix(node) {
37
+ return function (fixer) {
38
+ var wrappedTokenFix;
39
+ if ((0, _eslintCodemodUtils.isNodeOfType)(node.parent, 'Property') && (0, _eslintCodemodUtils.isNodeOfType)(node.parent.value, 'CallExpression') && node.parent.value.arguments.length >= 1) {
40
+ var firstArg = node.parent.value.arguments[0];
41
+ if ((0, _eslintCodemodUtils.isNodeOfType)(firstArg, 'Literal') && typeof firstArg.value === 'string') {
42
+ wrappedTokenFix = fixer.replaceText(node.parent.value, "'".concat(firstArg.value, "'"));
43
+ }
44
+ }
45
+ return [wrappedTokenFix].filter(function (fix) {
46
+ return Boolean(fix);
47
+ }); // Some of the transformers can return arrays with undefined, so filter them out
48
+ };
49
+ }
50
+ };
@@ -1,5 +1,5 @@
1
1
  import { isNodeOfType } from 'eslint-codemod-utils';
2
- 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';
2
+ 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';
3
3
  export const createChecks = context => {
4
4
  //create global variables to be shared by the checks
5
5
  const {
@@ -13,7 +13,6 @@ export const createChecks = context => {
13
13
  const errorsManual = {};
14
14
  const errorsAuto = {};
15
15
  let guidance = {};
16
- let autoIconJSXElementOccurrenceCount = 0;
17
16
 
18
17
  // Extract parameters
19
18
  const shouldErrorForManualMigration = getConfigFlag('shouldErrorForManualMigration', true);
@@ -38,7 +37,8 @@ export const createChecks = context => {
38
37
  legacyIconImports[spec.local.name] = {
39
38
  packageName: moduleSource,
40
39
  exported: false,
41
- importNode: node
40
+ importNode: node,
41
+ importSpecifier: spec.local.name
42
42
  };
43
43
  }
44
44
  }
@@ -51,7 +51,8 @@ export const createChecks = context => {
51
51
  migrationIconImports[spec.local.name] = {
52
52
  packageName: moduleSource,
53
53
  exported: false,
54
- importNode: node
54
+ importNode: node,
55
+ importSpecifier: spec.local.name
55
56
  };
56
57
  }
57
58
  });
@@ -90,7 +91,9 @@ export const createChecks = context => {
90
91
  if (Object.keys(legacyIconImports).includes(decl.init.name)) {
91
92
  legacyIconImports[decl.id.name] = {
92
93
  packageName: legacyIconImports[decl.init.name].packageName,
93
- exported: legacyIconImports[decl.init.name].exported || isExported
94
+ exported: legacyIconImports[decl.init.name].exported || isExported,
95
+ importNode: legacyIconImports[decl.init.name].importNode,
96
+ importSpecifier: legacyIconImports[decl.init.name].importSpecifier
94
97
  };
95
98
  } else if (newButtonImports.has(decl.init.name)) {
96
99
  newButtonImports.add(decl.id.name);
@@ -129,7 +132,7 @@ export const createChecks = context => {
129
132
  * @param node The named export node found by ESLint
130
133
  */
131
134
  const checkExportNamedVariables = node => {
132
- // export {default as AddIcon} from '@atlaskit/icon/glyph/add';
135
+ // Case: export {default as AddIcon} from '@atlaskit/icon/glyph/add';
133
136
  if (node.source && isNodeOfType(node.source, 'Literal') && Object.keys(node.source).includes('value')) {
134
137
  const moduleSource = node.source.value;
135
138
  if (typeof moduleSource === 'string' && ['@atlaskit/icon/glyph/', '@atlaskit/icon-object/glyph/'].find(val => moduleSource.startsWith(val)) && node.specifiers.length) {
@@ -143,7 +146,7 @@ export const createChecks = context => {
143
146
  }
144
147
  }
145
148
  } else if (node.declaration && isNodeOfType(node.declaration, 'VariableDeclaration')) {
146
- // export const Icon = AddIcon;
149
+ // Case: export const Icon = AddIcon;
147
150
  for (const decl of node.declaration.declarations) {
148
151
  if (isNodeOfType(decl, 'VariableDeclarator') && Object.keys(decl).includes('init') && decl.init && isNodeOfType(decl.init, 'Identifier') && Object.keys(legacyIconImports).includes(decl.init.name)) {
149
152
  createCantMigrateReExportError(node, legacyIconImports[decl.init.name].packageName, decl.init.name, errorsManual);
@@ -166,7 +169,9 @@ export const createChecks = context => {
166
169
  //update legacy imports to be exported
167
170
  legacyIconImports[spec.local.name] = {
168
171
  packageName: legacyIconImports[spec.local.name].packageName,
169
- exported: true
172
+ exported: true,
173
+ importNode: legacyIconImports[spec.local.name].importNode,
174
+ importSpecifier: legacyIconImports[spec.local.name].importSpecifier
170
175
  };
171
176
  createCantMigrateReExportError(spec, legacyIconImports[spec.local.name].packageName, spec.exported.name, errorsManual);
172
177
  addToListOfRanges(spec, errorRanges);
@@ -399,7 +404,6 @@ export const createChecks = context => {
399
404
  const sizeProp = node.openingElement.attributes.find(attribute => attribute.type === 'JSXAttribute' && (attribute.name.name === 'size' || attribute.name.name === 'LEGACY_size'));
400
405
  const 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;
401
406
  if (!hasManualMigration && (newIcon || upcomingIcon) && isNewIconMigratable) {
402
- autoIconJSXElementOccurrenceCount++;
403
407
  createAutoMigrationError({
404
408
  node,
405
409
  importSource: legacyIconImports[name].packageName,
@@ -444,108 +448,26 @@ export const createChecks = context => {
444
448
  * Throws the relevant errors in the correct order based on configs.
445
449
  */
446
450
  const throwErrors = () => {
451
+ // Throw manual errors
447
452
  if (shouldErrorForManualMigration) {
448
- for (const [key, errorList] of Object.entries(errorsManual)) {
449
- const node = 'node' in errorList.errors[0] ? errorList.errors[0].node : null;
450
- const cantMigrateIdentifierError = errorList.errors.find(x => 'messageId' in x && x.messageId === 'cantMigrateIdentifier');
451
- if (node) {
452
- let isInRange = false;
453
- if (cantMigrateIdentifierError && isInRangeList(node, errorRanges)) {
454
- isInRange = true;
455
- }
456
- if (isInRange && errorList.errors.length - 1 > 0 || !isInRange && errorList.errors.length > 0) {
457
- const guidanceMessage = Object.keys(guidance).includes(key) ? guidance[key] : '';
458
- context.report({
459
- node,
460
- messageId: 'noLegacyIconsManualMigration',
461
- data: {
462
- iconName: errorList.iconName,
463
- importSource: errorList.importSource,
464
- guidance: isQuietMode ? guidanceMessage : `${guidanceMessage}For more information see the below errors.\n`
465
- }
466
- });
467
- if (!isQuietMode) {
468
- for (const error of errorList.errors) {
469
- if ('messageId' in error && (error.messageId !== 'cantMigrateIdentifier' || error.messageId === 'cantMigrateIdentifier' && !isInRange)) {
470
- context.report(error);
471
- }
472
- }
473
- }
474
- }
475
- }
476
- }
453
+ throwManualErrors({
454
+ errorsManual,
455
+ errorRanges,
456
+ guidance,
457
+ context,
458
+ isQuietMode
459
+ });
477
460
  }
478
461
  if (shouldErrorForAutoMigration) {
479
- for (const [key, error] of Object.entries(errorsAuto)) {
480
- // If there's a manual error that exists for this same component,
481
- // don't throw the auto error
482
- if (Object.keys(errorsManual).includes(key)) {
483
- const cantMigrateIdentifierError = errorsManual[key].errors.find(x => 'messageId' in x && x.messageId === 'cantMigrateIdentifier');
484
- if (!cantMigrateIdentifierError || cantMigrateIdentifierError && errorsManual[key].errors.length > 1) {
485
- delete errorsAuto[key];
486
- continue;
487
- }
488
- }
489
- const node = 'node' in error ? error.node : null;
490
- if (node) {
491
- const guidanceMessage = Object.keys(guidance).includes(key) ? guidance[key] : '';
492
- if (Object.keys(error).includes('data') && error.data) {
493
- error.data.guidance = guidanceMessage;
494
- }
495
- context.report({
496
- ...error,
497
- fix: fixer => {
498
- var _legacyIconImports$er, _migrationIconImports;
499
- // don't migration if the new icon is not available
500
- if (!error.data || shouldUseMigrationPath && !checkIfNewIconExist(error)) {
501
- return [];
502
- }
503
- const fixArguments = {
504
- metadata: error.data,
505
- legacyImportNode: (_legacyIconImports$er = legacyIconImports[error.data.iconName]) === null || _legacyIconImports$er === void 0 ? void 0 : _legacyIconImports$er.importNode,
506
- migrationImportNode: (_migrationIconImports = migrationIconImports[error.data.iconName]) === null || _migrationIconImports === void 0 ? void 0 : _migrationIconImports.importNode,
507
- shouldUseMigrationPath
508
- };
509
- const propsFixes = createPropFixes({
510
- ...fixArguments,
511
- node,
512
- fixer
513
- });
514
- let importFixes = [];
515
- // Otherwise if there are multiple occurrences of the icon, import path will be handled after the prop fix
516
- if (autoIconJSXElementOccurrenceCount <= 1) {
517
- importFixes = createImportFix({
518
- ...fixArguments,
519
- fixer
520
- });
521
- }
522
- return [...propsFixes, ...importFixes];
523
- }
524
- });
525
- }
526
- }
527
-
528
- // Update import path at the end if there are multiple occurrences of the icon
529
- if (autoIconJSXElementOccurrenceCount > 1) {
530
- for (const [_, error] of Object.entries(errorsAuto)) {
531
- context.report({
532
- ...error,
533
- fix: fixer => {
534
- var _legacyIconImports$er2, _migrationIconImports2;
535
- if (!error.data || shouldUseMigrationPath && !checkIfNewIconExist(error)) {
536
- return [];
537
- }
538
- return createImportFix({
539
- metadata: error.data,
540
- fixer,
541
- legacyImportNode: (_legacyIconImports$er2 = legacyIconImports[error.data.iconName]) === null || _legacyIconImports$er2 === void 0 ? void 0 : _legacyIconImports$er2.importNode,
542
- migrationImportNode: (_migrationIconImports2 = migrationIconImports[error.data.iconName]) === null || _migrationIconImports2 === void 0 ? void 0 : _migrationIconImports2.importNode,
543
- shouldUseMigrationPath
544
- });
545
- }
546
- });
547
- }
548
- }
462
+ throwAutoErrors({
463
+ errorsManual,
464
+ errorsAuto,
465
+ legacyIconImports,
466
+ guidance,
467
+ migrationIconImports,
468
+ shouldUseMigrationPath,
469
+ context
470
+ });
549
471
  }
550
472
  };
551
473
  return {