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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/README.md +1 -0
  3. package/constellation/index/usage.mdx +1 -0
  4. package/constellation/use-latest-xcss-syntax-typography/usage.mdx +34 -0
  5. package/dist/cjs/ast-nodes/object-entry.js +2 -1
  6. package/dist/cjs/presets/all.codegen.js +2 -1
  7. package/dist/cjs/presets/recommended.codegen.js +2 -1
  8. package/dist/cjs/rules/ensure-design-token-usage/index.js +1 -1
  9. package/dist/cjs/rules/index.codegen.js +3 -1
  10. package/dist/cjs/rules/no-legacy-icons/checks.js +484 -0
  11. package/dist/cjs/rules/no-legacy-icons/helpers.js +289 -0
  12. package/dist/cjs/rules/no-legacy-icons/index.js +111 -131
  13. package/dist/cjs/rules/no-legacy-icons/migration-map-temp.js +4090 -0
  14. package/dist/cjs/rules/use-latest-xcss-syntax-typography/index.js +40 -0
  15. package/dist/cjs/rules/use-latest-xcss-syntax-typography/linters/banned-property/index.js +18 -0
  16. package/dist/cjs/rules/use-latest-xcss-syntax-typography/linters/index.js +12 -0
  17. package/dist/cjs/rules/use-tokens-typography/index.js +1 -1
  18. package/dist/es2019/ast-nodes/object-entry.js +2 -1
  19. package/dist/es2019/presets/all.codegen.js +2 -1
  20. package/dist/es2019/presets/recommended.codegen.js +2 -1
  21. package/dist/es2019/rules/ensure-design-token-usage/index.js +1 -1
  22. package/dist/es2019/rules/index.codegen.js +3 -1
  23. package/dist/es2019/rules/no-legacy-icons/checks.js +388 -0
  24. package/dist/es2019/rules/no-legacy-icons/helpers.js +275 -0
  25. package/dist/es2019/rules/no-legacy-icons/index.js +96 -97
  26. package/dist/es2019/rules/no-legacy-icons/migration-map-temp.js +4082 -0
  27. package/dist/es2019/rules/use-latest-xcss-syntax-typography/index.js +30 -0
  28. package/dist/es2019/rules/use-latest-xcss-syntax-typography/linters/banned-property/index.js +13 -0
  29. package/dist/es2019/rules/use-latest-xcss-syntax-typography/linters/index.js +1 -0
  30. package/dist/es2019/rules/use-tokens-typography/index.js +1 -1
  31. package/dist/esm/ast-nodes/object-entry.js +2 -1
  32. package/dist/esm/presets/all.codegen.js +2 -1
  33. package/dist/esm/presets/recommended.codegen.js +2 -1
  34. package/dist/esm/rules/ensure-design-token-usage/index.js +1 -1
  35. package/dist/esm/rules/index.codegen.js +3 -1
  36. package/dist/esm/rules/no-legacy-icons/checks.js +477 -0
  37. package/dist/esm/rules/no-legacy-icons/helpers.js +279 -0
  38. package/dist/esm/rules/no-legacy-icons/index.js +111 -131
  39. package/dist/esm/rules/no-legacy-icons/migration-map-temp.js +4084 -0
  40. package/dist/esm/rules/use-latest-xcss-syntax-typography/index.js +34 -0
  41. package/dist/esm/rules/use-latest-xcss-syntax-typography/linters/banned-property/index.js +12 -0
  42. package/dist/esm/rules/use-latest-xcss-syntax-typography/linters/index.js +1 -0
  43. package/dist/esm/rules/use-tokens-typography/index.js +1 -1
  44. package/dist/types/index.codegen.d.ts +2 -0
  45. package/dist/types/presets/all.codegen.d.ts +2 -1
  46. package/dist/types/presets/recommended.codegen.d.ts +2 -1
  47. package/dist/types/rules/index.codegen.d.ts +1 -0
  48. package/dist/types/rules/no-legacy-icons/checks.d.ts +13 -0
  49. package/dist/types/rules/no-legacy-icons/helpers.d.ts +82 -0
  50. package/dist/types/rules/no-legacy-icons/index.d.ts +2 -1
  51. package/dist/types/rules/no-legacy-icons/migration-map-temp.d.ts +22 -0
  52. package/dist/types/rules/use-latest-xcss-syntax-typography/index.d.ts +4 -0
  53. package/dist/types/rules/use-latest-xcss-syntax-typography/linters/banned-property/index.d.ts +6 -0
  54. package/dist/types/rules/use-latest-xcss-syntax-typography/linters/index.d.ts +1 -0
  55. package/dist/{types-ts4.5/rules/use-tokens-typography → types/rules/utils}/error-boundary.d.ts +5 -1
  56. package/dist/types-ts4.5/index.codegen.d.ts +2 -0
  57. package/dist/types-ts4.5/presets/all.codegen.d.ts +2 -1
  58. package/dist/types-ts4.5/presets/recommended.codegen.d.ts +2 -1
  59. package/dist/types-ts4.5/rules/index.codegen.d.ts +1 -0
  60. package/dist/types-ts4.5/rules/no-legacy-icons/checks.d.ts +13 -0
  61. package/dist/types-ts4.5/rules/no-legacy-icons/helpers.d.ts +82 -0
  62. package/dist/types-ts4.5/rules/no-legacy-icons/index.d.ts +2 -1
  63. package/dist/types-ts4.5/rules/no-legacy-icons/migration-map-temp.d.ts +27 -0
  64. package/dist/types-ts4.5/rules/use-latest-xcss-syntax-typography/index.d.ts +4 -0
  65. package/dist/types-ts4.5/rules/use-latest-xcss-syntax-typography/linters/banned-property/index.d.ts +6 -0
  66. package/dist/types-ts4.5/rules/use-latest-xcss-syntax-typography/linters/index.d.ts +1 -0
  67. package/dist/types-ts4.5/rules/{ensure-design-token-usage → utils}/error-boundary.d.ts +5 -1
  68. package/package.json +2 -2
  69. package/dist/cjs/rules/use-tokens-typography/error-boundary.js +0 -24
  70. package/dist/es2019/rules/use-tokens-typography/error-boundary.js +0 -19
  71. package/dist/esm/rules/use-tokens-typography/error-boundary.js +0 -18
  72. package/dist/types/rules/ensure-design-token-usage/error-boundary.d.ts +0 -11
  73. package/dist/types/rules/use-tokens-typography/error-boundary.d.ts +0 -11
  74. /package/dist/cjs/rules/{ensure-design-token-usage → utils}/error-boundary.js +0 -0
  75. /package/dist/es2019/rules/{ensure-design-token-usage → utils}/error-boundary.js +0 -0
  76. /package/dist/esm/rules/{ensure-design-token-usage → utils}/error-boundary.js +0 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,24 @@
1
1
  # @atlaskit/eslint-plugin-design-system
2
2
 
3
+ ## 10.8.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [#115815](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/115815)
8
+ [`0368d6009fc75`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/0368d6009fc75) -
9
+ Adds better suggestions to the no-legacy-icons lint rule to detect manual and automatic migration
10
+ opportunities.
11
+
12
+ ## 10.8.1
13
+
14
+ ### Patch Changes
15
+
16
+ - [#113465](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/113465)
17
+ [`1b198cf33c32e`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/1b198cf33c32e) -
18
+ Create `use-latest-xcss-syntax-typography` rule. Bans the use of 'fontSize', 'lineHeight',
19
+ 'fontWeight' on xcss.
20
+ - Updated dependencies
21
+
3
22
  ## 10.8.0
4
23
 
5
24
  ### Minor Changes
package/README.md CHANGED
@@ -81,6 +81,7 @@ module.exports = {
81
81
  | <a href="./src/rules/use-heading-level-in-spotlight-card/README.md">use-heading-level-in-spotlight-card</a> | Inform developers of eventual requirement of `headingLevel` prop in `SpotlightCard` component. The heading level should be the appropriate level according to the surrounding context. | Yes | Yes | |
82
82
  | <a href="./src/rules/use-href-in-link-item/README.md">use-href-in-link-item</a> | Inform developers of eventual requirement of `href` prop in `LinkItem` component. Elements with a `link` role require an `href` attribute for users to properly navigate, particularly those using assistive technologies. If no valid `href` is required for your use case, consider using a `ButtonItem` instead. | Yes | Yes | Yes |
83
83
  | <a href="./src/rules/use-latest-xcss-syntax/README.md">use-latest-xcss-syntax</a> | Enforces usage of space design tokens rather than hard-coded values in xcss. | Yes | Yes | |
84
+ | <a href="./src/rules/use-latest-xcss-syntax-typography/README.md">use-latest-xcss-syntax-typography</a> | Prohibits use of unsafe styling properties in xcss. Please use Text/Heading primitives instead. | Yes | Yes | |
84
85
  | <a href="./src/rules/use-menu-section-title/README.md">use-menu-section-title</a> | Encourages makers to provide accessible title for Atlassian Design System Menu Section component. | Yes | | Yes |
85
86
  | <a href="./src/rules/use-popup-label/README.md">use-popup-label</a> | Encourages to provide accessible name for Atlassian Design System Popup component. | Yes | | Yes |
86
87
  | <a href="./src/rules/use-primitives/README.md">use-primitives</a> | Encourage the usage of primitives components. | | Yes | Yes |
@@ -44,6 +44,7 @@ This plugin contains rules that should be used when working with the
44
44
  | <a href="/components/eslint-plugin-design-system/use-heading-level-in-spotlight-card/usage">use-heading-level-in-spotlight-card</a> | Inform developers of eventual requirement of `headingLevel` prop in `SpotlightCard` component. The heading level should be the appropriate level according to the surrounding context. | Yes | Yes | |
45
45
  | <a href="/components/eslint-plugin-design-system/use-href-in-link-item/usage">use-href-in-link-item</a> | Inform developers of eventual requirement of `href` prop in `LinkItem` component. Elements with a `link` role require an `href` attribute for users to properly navigate, particularly those using assistive technologies. If no valid `href` is required for your use case, consider using a `ButtonItem` instead. | Yes | Yes | Yes |
46
46
  | <a href="/components/eslint-plugin-design-system/use-latest-xcss-syntax/usage">use-latest-xcss-syntax</a> | Enforces usage of space design tokens rather than hard-coded values in xcss. | Yes | Yes | |
47
+ | <a href="/components/eslint-plugin-design-system/use-latest-xcss-syntax-typography/usage">use-latest-xcss-syntax-typography</a> | Prohibits use of unsafe styling properties in xcss. Please use Text/Heading primitives instead. | Yes | Yes | |
47
48
  | <a href="/components/eslint-plugin-design-system/use-menu-section-title/usage">use-menu-section-title</a> | Encourages makers to provide accessible title for Atlassian Design System Menu Section component. | Yes | | Yes |
48
49
  | <a href="/components/eslint-plugin-design-system/use-popup-label/usage">use-popup-label</a> | Encourages to provide accessible name for Atlassian Design System Popup component. | Yes | | Yes |
49
50
  | <a href="/components/eslint-plugin-design-system/use-primitives/usage">use-primitives</a> | Encourage the usage of primitives components. | | Yes | Yes |
@@ -0,0 +1,34 @@
1
+ # use-latest-xcss-syntax-typography
2
+
3
+ ## Description
4
+
5
+ Soon, applying `fontSize`, `lineHeight`, `fontWeight` with `xcss` will be deprecated. Please refrain
6
+ from adding new usages, as you will need to remove them soon anyway. As an alternative, you can use
7
+ the `Text` and `Heading` primitives.
8
+
9
+ ## Examples
10
+
11
+ ### Incorrect
12
+
13
+ ```jsx
14
+ const myStyles = xcss({
15
+ fontSize: '14px',
16
+ ^^^^^^^^^^^^^^^^
17
+ lineHeight: '20px',
18
+ ^^^^^^^^^^^^^^^^^^
19
+ fontWeight: 500,
20
+ ^^^^^^^^^^^^^^^
21
+ });
22
+
23
+ <Box as="p" xcss={myStyles}>
24
+ ...
25
+ </Box>;
26
+ ```
27
+
28
+ ### Correct
29
+
30
+ ```jsx
31
+ import { Text } from '@atlaskit/primitives';
32
+
33
+ <Text weight="medium">...</Text>;
34
+ ```
@@ -66,7 +66,8 @@ var ObjectEntry = exports.ObjectEntry = {
66
66
  return undefined;
67
67
  }
68
68
  if ((0, _eslintCodemodUtils.isNodeOfType)(node.key, 'Literal')) {
69
- return node.key.raw;
69
+ var _node$key$value;
70
+ return (_node$key$value = node.key.value) === null || _node$key$value === void 0 ? void 0 : _node$key$value.toString();
70
71
  }
71
72
  if ((0, _eslintCodemodUtils.isNodeOfType)(node.key, 'Identifier')) {
72
73
  return node.key.name;
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.default = void 0;
7
7
  /**
8
8
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
9
- * @codegen <<SignedSource::837556032f39113ae86785a120bb9ccb>>
9
+ * @codegen <<SignedSource::9bb5329713677543f16019954484ae2f>>
10
10
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
11
11
  */
12
12
  var _default = exports.default = {
@@ -44,6 +44,7 @@ var _default = exports.default = {
44
44
  '@atlaskit/design-system/use-heading-level-in-spotlight-card': 'warn',
45
45
  '@atlaskit/design-system/use-href-in-link-item': 'warn',
46
46
  '@atlaskit/design-system/use-latest-xcss-syntax': 'error',
47
+ '@atlaskit/design-system/use-latest-xcss-syntax-typography': 'warn',
47
48
  '@atlaskit/design-system/use-menu-section-title': 'warn',
48
49
  '@atlaskit/design-system/use-popup-label': 'warn',
49
50
  '@atlaskit/design-system/use-primitives': 'warn',
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.default = void 0;
7
7
  /**
8
8
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
9
- * @codegen <<SignedSource::b7ed527a03208f0bc68f9d34e4ef2260>>
9
+ * @codegen <<SignedSource::76bee1648b1b78d3ad253f0704a9cac7>>
10
10
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
11
11
  */
12
12
  var _default = exports.default = {
@@ -34,6 +34,7 @@ var _default = exports.default = {
34
34
  '@atlaskit/design-system/use-heading-level-in-spotlight-card': 'warn',
35
35
  '@atlaskit/design-system/use-href-in-link-item': 'warn',
36
36
  '@atlaskit/design-system/use-latest-xcss-syntax': 'error',
37
+ '@atlaskit/design-system/use-latest-xcss-syntax-typography': 'warn',
37
38
  '@atlaskit/design-system/use-menu-section-title': 'warn',
38
39
  '@atlaskit/design-system/use-popup-label': 'warn',
39
40
  '@atlaskit/design-system/use-visually-hidden': 'error'
@@ -9,10 +9,10 @@ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/sli
9
9
  var _eslintCodemodUtils = require("eslint-codemod-utils");
10
10
  var _isSupportedImport = require("@atlaskit/eslint-utils/is-supported-import");
11
11
  var _createRule = require("../utils/create-rule");
12
+ var _errorBoundary = require("../utils/error-boundary");
12
13
  var _isColor = require("../utils/is-color");
13
14
  var _isNode = require("../utils/is-node");
14
15
  var _color = require("./color");
15
- var _errorBoundary = require("./error-boundary");
16
16
  var _ruleMeta = _interopRequireDefault(require("./rule-meta"));
17
17
  var _spacing = require("./spacing");
18
18
  var _utils = require("./utils");
@@ -37,6 +37,7 @@ var _useHeading = _interopRequireDefault(require("./use-heading"));
37
37
  var _useHeadingLevelInSpotlightCard = _interopRequireDefault(require("./use-heading-level-in-spotlight-card"));
38
38
  var _useHrefInLinkItem = _interopRequireDefault(require("./use-href-in-link-item"));
39
39
  var _useLatestXcssSyntax = _interopRequireDefault(require("./use-latest-xcss-syntax"));
40
+ var _useLatestXcssSyntaxTypography = _interopRequireDefault(require("./use-latest-xcss-syntax-typography"));
40
41
  var _useMenuSectionTitle = _interopRequireDefault(require("./use-menu-section-title"));
41
42
  var _usePopupLabel = _interopRequireDefault(require("./use-popup-label"));
42
43
  var _usePrimitives = _interopRequireDefault(require("./use-primitives"));
@@ -46,7 +47,7 @@ var _useTokensTypography = _interopRequireDefault(require("./use-tokens-typograp
46
47
  var _useVisuallyHidden = _interopRequireDefault(require("./use-visually-hidden"));
47
48
  /**
48
49
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
49
- * @codegen <<SignedSource::287628b11d396c2bcbcf6f4a175a3d3a>>
50
+ * @codegen <<SignedSource::b359d356c482db0087ddfce5bd105403>>
50
51
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
51
52
  */
52
53
  var _default = exports.default = {
@@ -82,6 +83,7 @@ var _default = exports.default = {
82
83
  'use-heading-level-in-spotlight-card': _useHeadingLevelInSpotlightCard.default,
83
84
  'use-href-in-link-item': _useHrefInLinkItem.default,
84
85
  'use-latest-xcss-syntax': _useLatestXcssSyntax.default,
86
+ 'use-latest-xcss-syntax-typography': _useLatestXcssSyntaxTypography.default,
85
87
  'use-menu-section-title': _useMenuSectionTitle.default,
86
88
  'use-popup-label': _usePopupLabel.default,
87
89
  'use-primitives': _usePrimitives.default,
@@ -0,0 +1,484 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.createChecks = void 0;
8
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
9
+ var _eslintCodemodUtils = require("eslint-codemod-utils");
10
+ var _helpers = require("./helpers");
11
+ var _migrationMapTemp = require("./migration-map-temp");
12
+ 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; } } }; }
13
+ 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); }
14
+ 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; }
15
+ var createChecks = exports.createChecks = function createChecks(context) {
16
+ //create global variables to be shared by the checks
17
+ var _createHelpers = (0, _helpers.createHelpers)(context),
18
+ getPrimaryColor = _createHelpers.getPrimaryColor,
19
+ getConfigFlag = _createHelpers.getConfigFlag;
20
+ var legacyIconImports = {};
21
+ var newButtonImports = new Set();
22
+ var errorsManual = {};
23
+ var errorsAuto = {};
24
+ var guidance = {};
25
+
26
+ // Extract parameters
27
+ var shouldErrorForManualMigration = getConfigFlag('shouldErrorForManualMigration', true);
28
+ var shouldErrorForAutoMigration = getConfigFlag('shouldErrorForAutoMigration', true);
29
+ var isQuietMode = getConfigFlag('quiet', false);
30
+
31
+ /**
32
+ * Adds the legacy Icon and new button imports to the correct global arrays to be used by the other checks
33
+ * @param node The import node found by ESLint
34
+ */
35
+ var checkImportDeclarations = function checkImportDeclarations(node) {
36
+ var moduleSource = node.source.value;
37
+
38
+ // Find the imports for legacy icons
39
+ if (moduleSource && typeof moduleSource === 'string' && ['@atlaskit/icon/glyph/', '@atlaskit/icon-object/glyph/'].find(function (val) {
40
+ return moduleSource.startsWith(val);
41
+ }) && node.specifiers.length > 0) {
42
+ var _iterator = _createForOfIteratorHelper(node.specifiers),
43
+ _step;
44
+ try {
45
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
46
+ var spec = _step.value;
47
+ if (spec.local.name) {
48
+ legacyIconImports[spec.local.name] = {
49
+ packageName: moduleSource,
50
+ exported: false
51
+ };
52
+ }
53
+ }
54
+ } catch (err) {
55
+ _iterator.e(err);
56
+ } finally {
57
+ _iterator.f();
58
+ }
59
+ }
60
+
61
+ // Find the imports for new button and IconButton
62
+ if (typeof moduleSource === 'string' && moduleSource.startsWith('@atlaskit/button/new') && node.specifiers.length) {
63
+ var _iterator2 = _createForOfIteratorHelper(node.specifiers),
64
+ _step2;
65
+ try {
66
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
67
+ var _spec = _step2.value;
68
+ if (_spec.type === 'ImportDefaultSpecifier') {
69
+ newButtonImports.add(_spec.local.name);
70
+ } else if (_spec.type === 'ImportSpecifier' && _spec.imported.name === 'IconButton') {
71
+ newButtonImports.add(_spec.local.name);
72
+ }
73
+ }
74
+ } catch (err) {
75
+ _iterator2.e(err);
76
+ } finally {
77
+ _iterator2.f();
78
+ }
79
+ }
80
+ };
81
+
82
+ /**
83
+ * Adds the legacy Icon and new button variable reassignments to the correct global arrays to be used by the other checks
84
+ * @param node The variable reassignment node found by ESLint
85
+ */
86
+ var checkVariableDeclarations = function checkVariableDeclarations(node) {
87
+ if ((0, _eslintCodemodUtils.isNodeOfType)(node, 'VariableDeclaration')) {
88
+ var isExported = node.parent && (0, _eslintCodemodUtils.isNodeOfType)(node.parent, 'ExportNamedDeclaration');
89
+ var _iterator3 = _createForOfIteratorHelper(node.declarations),
90
+ _step3;
91
+ try {
92
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
93
+ var decl = _step3.value;
94
+ if ((0, _eslintCodemodUtils.isNodeOfType)(decl, 'VariableDeclarator') && 'init' in decl && 'id' in decl && decl.init && decl.id && 'name' in decl.id && decl.id.name && (0, _eslintCodemodUtils.isNodeOfType)(decl.init, 'Identifier')) {
95
+ if (decl.init.name in legacyIconImports) {
96
+ legacyIconImports[decl.id.name] = {
97
+ packageName: legacyIconImports[decl.init.name].packageName,
98
+ exported: legacyIconImports[decl.init.name].exported || isExported
99
+ };
100
+ } else if (newButtonImports.has(decl.init.name)) {
101
+ newButtonImports.add(decl.id.name);
102
+ }
103
+ }
104
+ }
105
+ } catch (err) {
106
+ _iterator3.e(err);
107
+ } finally {
108
+ _iterator3.f();
109
+ }
110
+ }
111
+ };
112
+
113
+ /**
114
+ * Checks if the default export is a re-export of a legacy icon and stores the errors in the global array
115
+ * @param node The default export node found by ESLint
116
+ */
117
+ var checkExportDefaultDeclaration = function checkExportDefaultDeclaration(node) {
118
+ var exportName = '';
119
+ var packageName = '';
120
+ if ('declaration' in node && node.declaration && (0, _eslintCodemodUtils.isNodeOfType)(node.declaration, 'Identifier') && node.declaration.name in legacyIconImports) {
121
+ packageName = legacyIconImports[node.declaration.name].packageName;
122
+ exportName = 'Default export';
123
+ } else if ('declaration' in node && node.declaration && (0, _eslintCodemodUtils.isNodeOfType)(node.declaration, 'AssignmentExpression') && (0, _eslintCodemodUtils.isNodeOfType)(node.declaration.left, 'Identifier') && (0, _eslintCodemodUtils.isNodeOfType)(node.declaration.right, 'Identifier') && node.declaration.right.name in legacyIconImports) {
124
+ packageName = legacyIconImports[node.declaration.right.name].packageName;
125
+ exportName = node.declaration.left.name;
126
+ } else {
127
+ return;
128
+ }
129
+ (0, _helpers.createCantMigrateReExportError)(node, packageName, exportName, errorsManual);
130
+ guidance[(0, _helpers.locToString)(node)] = (0, _helpers.createGuidance)(packageName);
131
+ };
132
+
133
+ /**
134
+ * Checks if the named exports are re-exports of a legacy icon and stores the errors in the global array
135
+ * @param node The named export node found by ESLint
136
+ */
137
+ var checkExportNamedVariables = function checkExportNamedVariables(node) {
138
+ // export {default as AddIcon} from '@atlaskit/icon/glyph/add';
139
+ if (node.source && (0, _eslintCodemodUtils.isNodeOfType)(node.source, 'Literal') && 'value' in node.source) {
140
+ var moduleSource = node.source.value;
141
+ if (typeof moduleSource === 'string' && ['@atlaskit/icon/glyph/', '@atlaskit/icon-object/glyph/'].find(function (val) {
142
+ return moduleSource.startsWith(val);
143
+ }) && node.specifiers.length) {
144
+ (0, _helpers.createCantMigrateReExportError)(node, moduleSource, node.specifiers[0].exported.name, errorsManual);
145
+ guidance[(0, _helpers.locToString)(node)] = (0, _helpers.createGuidance)(moduleSource);
146
+ }
147
+ } else if (node.declaration && (0, _eslintCodemodUtils.isNodeOfType)(node.declaration, 'VariableDeclaration')) {
148
+ // export const Icon = AddIcon;
149
+ var _iterator4 = _createForOfIteratorHelper(node.declaration.declarations),
150
+ _step4;
151
+ try {
152
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
153
+ var decl = _step4.value;
154
+ if ((0, _eslintCodemodUtils.isNodeOfType)(decl, 'VariableDeclarator') && 'init' in decl && decl.init && (0, _eslintCodemodUtils.isNodeOfType)(decl.init, 'Identifier') && decl.init.name in legacyIconImports) {
155
+ (0, _helpers.createCantMigrateReExportError)(node, legacyIconImports[decl.init.name].packageName, decl.init.name, errorsManual);
156
+ guidance[(0, _helpers.locToString)(node)] = (0, _helpers.createGuidance)((0, _helpers.createGuidance)(legacyIconImports[decl.init.name].packageName));
157
+ }
158
+ }
159
+ } catch (err) {
160
+ _iterator4.e(err);
161
+ } finally {
162
+ _iterator4.f();
163
+ }
164
+ } else if (!node.source && node.specifiers && node.specifiers.length > 0) {
165
+ /**
166
+ * case where multiple consts are re-exported:
167
+ * const AddIcon = LegacyIcon;
168
+ * const crossIcon = LegacyIcon2;
169
+ * export { AddIcon, CrossIcon as default }
170
+ */
171
+ var _iterator5 = _createForOfIteratorHelper(node.specifiers),
172
+ _step5;
173
+ try {
174
+ for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
175
+ var spec = _step5.value;
176
+ if (spec.local.name in legacyIconImports) {
177
+ //update legacy imports to be exported
178
+ legacyIconImports[spec.local.name] = {
179
+ packageName: legacyIconImports[spec.local.name].packageName,
180
+ exported: true
181
+ };
182
+ (0, _helpers.createCantMigrateReExportError)(spec, legacyIconImports[spec.local.name].packageName, spec.exported.name, errorsManual);
183
+ guidance[(0, _helpers.locToString)(spec)] = (0, _helpers.createGuidance)(legacyIconImports[spec.local.name].packageName);
184
+ }
185
+ }
186
+ } catch (err) {
187
+ _iterator5.e(err);
188
+ } finally {
189
+ _iterator5.f();
190
+ }
191
+ }
192
+ };
193
+
194
+ /**
195
+ * Checks if a legacy icon is referenced in an array or map and stores the errors in the global array
196
+ * @param node The array/map node found by ESLint
197
+ */
198
+ var checkArrayOrMap = function checkArrayOrMap(node) {
199
+ if (!(0, _eslintCodemodUtils.isNodeOfType)(node, 'Identifier')) {
200
+ return;
201
+ }
202
+ if (node.name && node.name in legacyIconImports && legacyIconImports[node.name].packageName) {
203
+ (0, _helpers.createCantMigrateIdentifierError)(node, legacyIconImports[node.name].packageName, node.name, errorsManual);
204
+ guidance[(0, _helpers.locToString)(node)] = (0, _helpers.createGuidance)(legacyIconImports[node.name].packageName);
205
+ }
206
+ };
207
+
208
+ /**
209
+ * Checks if a legacy icon is referenced as a prop to a component and stores the errors in the global array
210
+ * @param node The property node found by ESLint
211
+ */
212
+ var checkIconAsProp = function checkIconAsProp(node) {
213
+ if (!(0, _eslintCodemodUtils.isNodeOfType)(node, 'Identifier')) {
214
+ return;
215
+ }
216
+ if (!node.parent || !node.parent.parent || !node.parent.parent.parent) {
217
+ return;
218
+ }
219
+ if (!(0, _eslintCodemodUtils.isNodeOfType)(node.parent, 'JSXExpressionContainer') || !(0, _eslintCodemodUtils.isNodeOfType)(node.parent.parent, 'JSXAttribute') || !(0, _eslintCodemodUtils.isNodeOfType)(node.parent.parent.parent, 'JSXOpeningElement')) {
220
+ return;
221
+ }
222
+ if (node.name in legacyIconImports && (0, _eslintCodemodUtils.isNodeOfType)(node.parent.parent.name, 'JSXIdentifier') && node.parent.parent.name.name !== 'LEGACY_fallbackIcon') {
223
+ var _migrationMapObject$s;
224
+ var migrationMapObject = (0, _helpers.getMigrationMapObject)(legacyIconImports[node.name].packageName);
225
+ var newIcon = migrationMapObject === null || migrationMapObject === void 0 ? void 0 : migrationMapObject.newIcon;
226
+ var isNewIconMigratable = (0, _helpers.canAutoMigrateNewIconBasedOnSize)(migrationMapObject === null || migrationMapObject === void 0 || (_migrationMapObject$s = migrationMapObject.sizeGuidance) === null || _migrationMapObject$s === void 0 ? void 0 : _migrationMapObject$s.medium);
227
+ var isInNewButton = (0, _eslintCodemodUtils.isNodeOfType)(node.parent.parent.parent.name, 'JSXIdentifier') && newButtonImports.has(node.parent.parent.parent.name.name);
228
+ var UNSAFE_size = null;
229
+ var UNSAFE_propName = null;
230
+ if (isInNewButton) {
231
+ var result = (0, _helpers.findUNSAFEProp)(node.parent.parent, node.parent.parent.parent);
232
+ UNSAFE_size = result.UNSAFE_size;
233
+ UNSAFE_propName = result.UNSAFE_propName;
234
+ }
235
+ if (newIcon && isInNewButton && isNewIconMigratable && UNSAFE_size !== 'large' && UNSAFE_size !== 'xlarge') {
236
+ var iconKey = (0, _helpers.getIconKey)(legacyIconImports[node.name].packageName);
237
+ (0, _helpers.createAutoMigrationError)(node, legacyIconImports[node.name].packageName, node.name, newIcon, iconKey, errorsAuto);
238
+ guidance[(0, _helpers.locToString)(node)] = (0, _helpers.createGuidance)(legacyIconImports[node.name].packageName, 'medium');
239
+ } else if ((!newIcon || !isNewIconMigratable) && !UNSAFE_size) {
240
+ (0, _helpers.createCantFindSuitableReplacementError)(node, legacyIconImports[node.name].packageName, node.name, errorsManual);
241
+ guidance[(0, _helpers.locToString)(node)] = (0, _helpers.createGuidance)(legacyIconImports[node.name].packageName);
242
+ } else if ((UNSAFE_size === 'large' || UNSAFE_size === 'xlarge') && UNSAFE_propName) {
243
+ (0, _helpers.createCantMigrateUnsafeProp)(node, UNSAFE_propName, UNSAFE_size, legacyIconImports[node.name].packageName, node.name, errorsManual);
244
+ guidance[(0, _helpers.locToString)(node)] = (0, _helpers.createGuidance)(legacyIconImports[node.name].packageName, UNSAFE_size);
245
+ } else if (!isInNewButton) {
246
+ (0, _helpers.createCantMigrateFunctionUnknownError)(node, legacyIconImports[node.name].packageName, node.name, errorsManual);
247
+ guidance[(0, _helpers.locToString)(node)] = (0, _helpers.createGuidance)(legacyIconImports[node.name].packageName);
248
+ }
249
+ }
250
+ };
251
+
252
+ /**
253
+ * Checks if a legacy icon is being rendered and stores the errors in the global array
254
+ * @param node The JSX node found by ESLint
255
+ */
256
+ var checkJSXElement = function checkJSXElement(node) {
257
+ var _node$parent, _node$parent$parent$p;
258
+ if (!('openingElement' in node) || !(0, _eslintCodemodUtils.isNodeOfType)(node.openingElement.name, 'JSXIdentifier')) {
259
+ return;
260
+ }
261
+
262
+ // Determine if element is rendered inside LEGACY_fallbackIcon prop - if so, don't perform any checks
263
+ if (node.parent && (0, _eslintCodemodUtils.isNodeOfType)(node.parent, 'ArrowFunctionExpression') && (_node$parent = node.parent) !== null && _node$parent !== void 0 && (_node$parent = _node$parent.parent) !== null && _node$parent !== void 0 && _node$parent.parent && (0, _eslintCodemodUtils.isNodeOfType)(node.parent.parent.parent, 'JSXAttribute') && ((_node$parent$parent$p = node.parent.parent.parent.name) === null || _node$parent$parent$p === void 0 ? void 0 : _node$parent$parent$p.name) === 'LEGACY_fallbackIcon') {
264
+ return;
265
+ }
266
+ var name = node.openingElement.name.name;
267
+ // Legacy icons rendered as JSX elements
268
+ if (name in legacyIconImports) {
269
+ var _node$parent2, _node$parent3, _size;
270
+ // Determine if inside a new button - if so:
271
+ // - Assume spread props are safe - still error if props explicitly set to unmigratable values
272
+ // - eventually: look for UNSAFE_iconBefore_size props on the parent button - if it's large/xlarge, fail
273
+ var insideNewButton = false;
274
+ var UNSAFE_propName = null;
275
+ var UNSAFE_size = null;
276
+ if (node.parent && (0, _eslintCodemodUtils.isNodeOfType)(node.parent, 'ArrowFunctionExpression') && (_node$parent2 = node.parent) !== null && _node$parent2 !== void 0 && (_node$parent2 = _node$parent2.parent) !== null && _node$parent2 !== void 0 && _node$parent2.parent && (0, _eslintCodemodUtils.isNodeOfType)(node.parent.parent.parent, 'JSXAttribute') && (0, _eslintCodemodUtils.isNodeOfType)(node.parent.parent.parent.name, 'JSXIdentifier') && (_node$parent3 = node.parent) !== null && _node$parent3 !== void 0 && (_node$parent3 = _node$parent3.parent) !== null && _node$parent3 !== void 0 && (_node$parent3 = _node$parent3.parent) !== null && _node$parent3 !== void 0 && _node$parent3.parent && (0, _eslintCodemodUtils.isNodeOfType)(node.parent.parent.parent.parent, 'JSXOpeningElement') && (0, _eslintCodemodUtils.isNodeOfType)(node.parent.parent.parent.parent.name, 'JSXIdentifier') && newButtonImports.has(node.parent.parent.parent.parent.name.name)) {
277
+ insideNewButton = true;
278
+ var result = (0, _helpers.findUNSAFEProp)(node.parent.parent.parent, node.parent.parent.parent.parent);
279
+ UNSAFE_size = result.UNSAFE_size;
280
+ UNSAFE_propName = result.UNSAFE_propName;
281
+ }
282
+
283
+ // Find size prop on node
284
+ var size = 'medium';
285
+ var primaryColor = null;
286
+ var afterSpreadSet = new Set();
287
+ var requiredAttributesAfterSpread = new Set(['size', 'primaryColor', 'secondaryColor']);
288
+ var hasSpread = false;
289
+ var hasPrimaryColorProp = false;
290
+ var _iterator6 = _createForOfIteratorHelper(node.openingElement.attributes),
291
+ _step6;
292
+ try {
293
+ for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
294
+ var attr = _step6.value;
295
+ // Detect spread props
296
+ if ((0, _eslintCodemodUtils.isNodeOfType)(attr, 'JSXSpreadAttribute')) {
297
+ // In case there are more spread props
298
+ afterSpreadSet.clear();
299
+ hasSpread = true;
300
+ continue;
301
+ }
302
+ if (!(0, _eslintCodemodUtils.isNodeOfType)(attr, 'JSXAttribute') || !(0, _eslintCodemodUtils.isNodeOfType)(attr.name, 'JSXIdentifier') || !attr.value) {
303
+ continue;
304
+ }
305
+
306
+ // Register props that aren't being spread
307
+ afterSpreadSet.add(attr.name.name);
308
+
309
+ // Extract values of props
310
+ switch (attr.name.name) {
311
+ case 'size':
312
+ if ((0, _eslintCodemodUtils.isNodeOfType)(attr.value, 'Literal') && (0, _migrationMapTemp.isSize)(attr.value.value)) {
313
+ size = attr.value.value;
314
+ } else if ((0, _eslintCodemodUtils.isNodeOfType)(attr.value, 'JSXExpressionContainer') && (0, _eslintCodemodUtils.isNodeOfType)(attr.value.expression, 'Literal') && (0, _migrationMapTemp.isSize)(attr.value.expression.value)) {
315
+ size = attr.value.expression.value;
316
+ } else {
317
+ size = null;
318
+ }
319
+ break;
320
+ case 'primaryColor':
321
+ primaryColor = getPrimaryColor(attr);
322
+ hasPrimaryColorProp = true;
323
+ break;
324
+ }
325
+ }
326
+ } catch (err) {
327
+ _iterator6.e(err);
328
+ } finally {
329
+ _iterator6.f();
330
+ }
331
+ var hasManualMigration = false;
332
+ if (primaryColor && !(0, _helpers.canMigrateColor)(primaryColor) || hasPrimaryColorProp && !primaryColor) {
333
+ (0, _helpers.createCantMigrateColorError)(node, primaryColor ? "the value of '".concat(primaryColor, "'") : 'a statically unknown value', errorsManual, legacyIconImports[name].packageName, name);
334
+ hasManualMigration = true;
335
+ }
336
+
337
+ // If size can't be determined (i.e. size is a variable or function call, etc)
338
+ // then we need to error; icon can't be auto-migrated safely
339
+ if (size === null) {
340
+ (0, _helpers.createCantMigrateSizeUnknown)(node, errorsManual, legacyIconImports[name].packageName, name);
341
+ hasManualMigration = true;
342
+ }
343
+ guidance[(0, _helpers.locToString)(node)] = (0, _helpers.createGuidance)(legacyIconImports[name].packageName, size ? size : undefined);
344
+ // Check for unsafe size
345
+ if ((UNSAFE_size === 'large' || UNSAFE_size === 'xlarge') && (UNSAFE_propName === 'UNSAFE_iconAfter_size' || UNSAFE_propName === 'UNSAFE_iconBefore_size' || UNSAFE_propName === 'UNSAFE_size')) {
346
+ (0, _helpers.createCantMigrateUnsafeProp)(node, UNSAFE_propName, UNSAFE_size, legacyIconImports[name].packageName, name, errorsManual);
347
+ hasManualMigration = true;
348
+ }
349
+ // Do a set comparison - is requiredAttributesAfterSpread a subset of afterSpreadSet?
350
+ if (hasSpread === true && !Array.from(requiredAttributesAfterSpread).every(function (val) {
351
+ return afterSpreadSet.has(val);
352
+ }) && !insideNewButton) {
353
+ var missingProps = Array.from(requiredAttributesAfterSpread).filter(function (val) {
354
+ return !afterSpreadSet.has(val);
355
+ });
356
+ (0, _helpers.createCantMigrateSpreadPropsError)(node, missingProps, errorsManual, legacyIconImports[name].packageName, name);
357
+ hasManualMigration = true;
358
+ }
359
+ // Check if it is an exported component?
360
+ if (legacyIconImports[name].exported) {
361
+ (0, _helpers.createCantMigrateReExportError)(node, legacyIconImports[name].packageName, name, errorsManual);
362
+ hasManualMigration = true;
363
+ }
364
+ var migrationMapObject = (0, _helpers.getMigrationMapObject)(legacyIconImports[name].packageName);
365
+ var iconKey = (0, _helpers.getIconKey)(legacyIconImports[name].packageName);
366
+ var newIcon = migrationMapObject === null || migrationMapObject === void 0 ? void 0 : migrationMapObject.newIcon;
367
+ var isNewIconMigratable = (0, _helpers.canAutoMigrateNewIconBasedOnSize)(migrationMapObject === null || migrationMapObject === void 0 ? void 0 : migrationMapObject.sizeGuidance[(_size = size) !== null && _size !== void 0 ? _size : 'medium']);
368
+ if (!hasManualMigration && newIcon && isNewIconMigratable) {
369
+ (0, _helpers.createAutoMigrationError)(node, legacyIconImports[name].packageName, name, newIcon, iconKey, errorsAuto);
370
+ } else if ((!newIcon || !isNewIconMigratable) && size) {
371
+ (0, _helpers.createCantFindSuitableReplacementError)(node, legacyIconImports[name].packageName, name, errorsManual);
372
+ }
373
+ }
374
+ };
375
+
376
+ /**
377
+ * Checks if a legacy icon is being passed into a function call and stores the errors in the global array
378
+ * @param node The function call node found by ESLint
379
+ */
380
+ var checkCallExpression = function checkCallExpression(node) {
381
+ if ('arguments' in node && node.arguments.length) {
382
+ var _iterator7 = _createForOfIteratorHelper(node.arguments),
383
+ _step7;
384
+ try {
385
+ for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
386
+ var arg = _step7.value;
387
+ if ((0, _eslintCodemodUtils.isNodeOfType)(arg, 'Identifier') && arg.name in legacyIconImports && legacyIconImports[arg.name].packageName) {
388
+ (0, _helpers.createCantMigrateFunctionUnknownError)(node, legacyIconImports[arg.name].packageName, arg.name, errorsManual);
389
+ guidance[(0, _helpers.locToString)(node)] = (0, _helpers.createGuidance)(legacyIconImports[arg.name].packageName);
390
+ }
391
+ }
392
+ } catch (err) {
393
+ _iterator7.e(err);
394
+ } finally {
395
+ _iterator7.f();
396
+ }
397
+ }
398
+ };
399
+
400
+ /**
401
+ * Throws the relevant errors in the correct order based on configs.
402
+ */
403
+ var throwErrors = function throwErrors() {
404
+ if (shouldErrorForManualMigration) {
405
+ for (var _i = 0, _Object$entries = Object.entries(errorsManual); _i < _Object$entries.length; _i++) {
406
+ var _Object$entries$_i = (0, _slicedToArray2.default)(_Object$entries[_i], 2),
407
+ _key = _Object$entries$_i[0],
408
+ errorList = _Object$entries$_i[1];
409
+ var node = 'node' in errorList.errors[0] ? errorList.errors[0].node : null;
410
+ if (node) {
411
+ context.report({
412
+ node: node,
413
+ messageId: 'noLegacyIconsManualMigration',
414
+ data: {
415
+ iconName: errorList.iconName,
416
+ importSource: errorList.importSource,
417
+ quietModeGuidance: isQuietMode ? 'For more information see the below errors:' : ''
418
+ }
419
+ });
420
+ if (!isQuietMode) {
421
+ var _iterator8 = _createForOfIteratorHelper(errorList.errors),
422
+ _step8;
423
+ try {
424
+ for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
425
+ var error = _step8.value;
426
+ context.report(error);
427
+ }
428
+ } catch (err) {
429
+ _iterator8.e(err);
430
+ } finally {
431
+ _iterator8.f();
432
+ }
433
+ if (_key in guidance) {
434
+ context.report({
435
+ node: node,
436
+ messageId: 'guidance',
437
+ data: {
438
+ guidance: guidance[_key]
439
+ }
440
+ });
441
+ }
442
+ }
443
+ }
444
+ }
445
+ }
446
+ if (shouldErrorForAutoMigration) {
447
+ for (var _i2 = 0, _Object$entries2 = Object.entries(errorsAuto); _i2 < _Object$entries2.length; _i2++) {
448
+ var _Object$entries2$_i = (0, _slicedToArray2.default)(_Object$entries2[_i2], 2),
449
+ _key2 = _Object$entries2$_i[0],
450
+ _error = _Object$entries2$_i[1];
451
+ // If there's a manual error that exists for this same component,
452
+ // don't throw the auto error
453
+ if (_key2 in errorsManual) {
454
+ delete errorsAuto[_key2];
455
+ continue;
456
+ }
457
+ var _node = 'node' in _error ? _error.node : null;
458
+ if (_node) {
459
+ context.report(_error);
460
+ if (_key2 in guidance && !isQuietMode) {
461
+ context.report({
462
+ node: _node,
463
+ messageId: 'guidance',
464
+ data: {
465
+ guidance: guidance[_key2]
466
+ }
467
+ });
468
+ }
469
+ }
470
+ }
471
+ }
472
+ };
473
+ return {
474
+ checkImportDeclarations: checkImportDeclarations,
475
+ checkVariableDeclarations: checkVariableDeclarations,
476
+ checkExportDefaultDeclaration: checkExportDefaultDeclaration,
477
+ checkExportNamedVariables: checkExportNamedVariables,
478
+ checkArrayOrMap: checkArrayOrMap,
479
+ checkIconAsProp: checkIconAsProp,
480
+ checkJSXElement: checkJSXElement,
481
+ checkCallExpression: checkCallExpression,
482
+ throwErrors: throwErrors
483
+ };
484
+ };