@atlaskit/eslint-plugin-design-system 13.41.2 → 13.42.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/README.md +0 -1
  3. package/dist/cjs/presets/all-flat.codegen.js +1 -2
  4. package/dist/cjs/presets/all.codegen.js +1 -2
  5. package/dist/cjs/rules/index.codegen.js +1 -3
  6. package/dist/cjs/rules/use-primitives/utils/is-valid-css-properties-to-transform.js +5 -4
  7. package/dist/es2019/presets/all-flat.codegen.js +1 -2
  8. package/dist/es2019/presets/all.codegen.js +1 -2
  9. package/dist/es2019/rules/index.codegen.js +1 -3
  10. package/dist/es2019/rules/use-primitives/utils/is-valid-css-properties-to-transform.js +5 -4
  11. package/dist/esm/presets/all-flat.codegen.js +1 -2
  12. package/dist/esm/presets/all.codegen.js +1 -2
  13. package/dist/esm/rules/index.codegen.js +1 -3
  14. package/dist/esm/rules/use-primitives/utils/is-valid-css-properties-to-transform.js +5 -4
  15. package/dist/types/presets/all-flat.codegen.d.ts +1 -1
  16. package/dist/types/presets/all.codegen.d.ts +1 -1
  17. package/dist/types/rules/ensure-design-token-usage/index.d.ts +1 -1
  18. package/dist/types/rules/ensure-design-token-usage/rule-meta.d.ts +1 -1
  19. package/dist/types/rules/ensure-design-token-usage/utils.d.ts +1 -1
  20. package/dist/types/rules/index.codegen.d.ts +1 -1
  21. package/dist/types/rules/no-deprecated-imports/handlers/icon.d.ts +1 -1
  22. package/dist/types/rules/use-heading/transformers/common.d.ts +2 -2
  23. package/dist/types/rules/use-latest-xcss-syntax-typography/linters/common.d.ts +1 -1
  24. package/dist/types/rules/use-latest-xcss-syntax-typography/linters/wrapped-token-value.d.ts +1 -1
  25. package/dist/types/rules/use-primitives/transformers/compiled-styled/index.d.ts +1 -1
  26. package/dist/types/rules/use-primitives/transformers/emotion-css/index.d.ts +1 -1
  27. package/dist/types/rules/use-primitives/utils/is-valid-css-properties-to-transform.d.ts +1 -1
  28. package/dist/types/rules/use-primitives/utils/validate-styles.d.ts +1 -1
  29. package/dist/types/rules/use-primitives-text/transformers/common.d.ts +1 -1
  30. package/dist/types/rules/use-primitives-text/transformers/unsafe-small-text.d.ts +1 -1
  31. package/dist/types/rules/use-tokens-typography/config/index.d.ts +1 -1
  32. package/dist/types/rules/use-tokens-typography/transformers/banned-properties.d.ts +1 -1
  33. package/dist/types/rules/use-tokens-typography/transformers/font-family.d.ts +1 -1
  34. package/dist/types/rules/use-tokens-typography/transformers/font-weight.d.ts +1 -1
  35. package/dist/types/rules/use-tokens-typography/transformers/restricted-capitalisation.d.ts +1 -1
  36. package/dist/types/rules/use-tokens-typography/transformers/style-object.d.ts +1 -1
  37. package/dist/types/rules/use-tokens-typography/transformers/untokenized-properties.d.ts +1 -1
  38. package/dist/types/rules/utils/create-no-exported-rule/check-if-supported-export.d.ts +1 -1
  39. package/dist/types/rules/utils/get-first-supported-import.d.ts +1 -1
  40. package/dist/types-ts4.5/presets/all-flat.codegen.d.ts +1 -1
  41. package/dist/types-ts4.5/presets/all.codegen.d.ts +1 -1
  42. package/dist/types-ts4.5/rules/ensure-design-token-usage/index.d.ts +1 -1
  43. package/dist/types-ts4.5/rules/ensure-design-token-usage/rule-meta.d.ts +1 -1
  44. package/dist/types-ts4.5/rules/ensure-design-token-usage/utils.d.ts +1 -1
  45. package/dist/types-ts4.5/rules/index.codegen.d.ts +1 -1
  46. package/dist/types-ts4.5/rules/no-deprecated-imports/handlers/icon.d.ts +1 -1
  47. package/dist/types-ts4.5/rules/use-heading/transformers/common.d.ts +2 -2
  48. package/dist/types-ts4.5/rules/use-latest-xcss-syntax-typography/linters/common.d.ts +1 -1
  49. package/dist/types-ts4.5/rules/use-latest-xcss-syntax-typography/linters/wrapped-token-value.d.ts +1 -1
  50. package/dist/types-ts4.5/rules/use-primitives/transformers/compiled-styled/index.d.ts +1 -1
  51. package/dist/types-ts4.5/rules/use-primitives/transformers/emotion-css/index.d.ts +1 -1
  52. package/dist/types-ts4.5/rules/use-primitives/utils/is-valid-css-properties-to-transform.d.ts +1 -1
  53. package/dist/types-ts4.5/rules/use-primitives/utils/validate-styles.d.ts +1 -1
  54. package/dist/types-ts4.5/rules/use-primitives-text/transformers/common.d.ts +1 -1
  55. package/dist/types-ts4.5/rules/use-primitives-text/transformers/unsafe-small-text.d.ts +1 -1
  56. package/dist/types-ts4.5/rules/use-tokens-typography/config/index.d.ts +1 -1
  57. package/dist/types-ts4.5/rules/use-tokens-typography/transformers/banned-properties.d.ts +1 -1
  58. package/dist/types-ts4.5/rules/use-tokens-typography/transformers/font-family.d.ts +1 -1
  59. package/dist/types-ts4.5/rules/use-tokens-typography/transformers/font-weight.d.ts +1 -1
  60. package/dist/types-ts4.5/rules/use-tokens-typography/transformers/restricted-capitalisation.d.ts +1 -1
  61. package/dist/types-ts4.5/rules/use-tokens-typography/transformers/style-object.d.ts +1 -1
  62. package/dist/types-ts4.5/rules/use-tokens-typography/transformers/untokenized-properties.d.ts +1 -1
  63. package/dist/types-ts4.5/rules/utils/create-no-exported-rule/check-if-supported-export.d.ts +1 -1
  64. package/dist/types-ts4.5/rules/utils/get-first-supported-import.d.ts +1 -1
  65. package/package.json +4 -4
  66. package/dist/cjs/rules/no-legacy-icons/checks.js +0 -619
  67. package/dist/cjs/rules/no-legacy-icons/helpers.js +0 -900
  68. package/dist/cjs/rules/no-legacy-icons/index.js +0 -91
  69. package/dist/cjs/rules/no-legacy-icons/upcoming-icons.js +0 -7
  70. package/dist/es2019/rules/no-legacy-icons/checks.js +0 -520
  71. package/dist/es2019/rules/no-legacy-icons/helpers.js +0 -853
  72. package/dist/es2019/rules/no-legacy-icons/index.js +0 -87
  73. package/dist/es2019/rules/no-legacy-icons/upcoming-icons.js +0 -1
  74. package/dist/esm/rules/no-legacy-icons/checks.js +0 -613
  75. package/dist/esm/rules/no-legacy-icons/helpers.js +0 -891
  76. package/dist/esm/rules/no-legacy-icons/index.js +0 -85
  77. package/dist/esm/rules/no-legacy-icons/upcoming-icons.js +0 -1
  78. package/dist/types/rules/no-legacy-icons/checks.d.ts +0 -16
  79. package/dist/types/rules/no-legacy-icons/helpers.d.ts +0 -151
  80. package/dist/types/rules/no-legacy-icons/index.d.ts +0 -2
  81. package/dist/types/rules/no-legacy-icons/upcoming-icons.d.ts +0 -1
  82. package/dist/types-ts4.5/rules/no-legacy-icons/checks.d.ts +0 -16
  83. package/dist/types-ts4.5/rules/no-legacy-icons/helpers.d.ts +0 -156
  84. package/dist/types-ts4.5/rules/no-legacy-icons/index.d.ts +0 -2
  85. package/dist/types-ts4.5/rules/no-legacy-icons/upcoming-icons.d.ts +0 -1
@@ -1,91 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- var _createRule = require("../utils/create-rule");
8
- var _errorBoundary = require("../utils/error-boundary");
9
- var _checks = require("./checks");
10
- var _helpers = require("./helpers");
11
- var rule = (0, _createRule.createLintRule)({
12
- meta: {
13
- name: 'no-legacy-icons',
14
- fixable: 'code',
15
- hasSuggestions: true,
16
- type: 'problem',
17
- docs: {
18
- description: 'Enforces no legacy icons are used.',
19
- recommended: false,
20
- severity: 'warn'
21
- },
22
- schema: [{
23
- type: 'object',
24
- properties: {
25
- shouldErrorForManualMigration: {
26
- type: 'boolean'
27
- },
28
- shouldErrorForAutoMigration: {
29
- type: 'boolean'
30
- },
31
- shouldUseSafeMigrationMode: {
32
- type: 'boolean'
33
- },
34
- quiet: {
35
- type: 'boolean'
36
- },
37
- shouldUseMigrationPath: {
38
- type: 'boolean'
39
- }
40
- },
41
- additionalProperties: false
42
- }],
43
- messages: {
44
- noLegacyIconsAutoMigration: "Auto Migration:\nLegacy icon '{{iconName}}' from '{{importSource}}' detected.\nAutomatic migration is possible.\n\n{{guidance}}\nAtlassians: See https://go.atlassian.com/icon-migration-guide for details.'",
45
- noLegacyIconsManualMigration: "Manual Migration:\nLegacy icon '{{iconName}}' from '{{importSource}}' detected.\nAutomatic migration not possible.\n\n{{guidance}}\nAtlassians: See https://go.atlassian.com/icon-migration-guide for details.",
46
- cantFindSuitableReplacement: "No suitable replacement found for '{{iconName}}' from '{{importSource}}'{{sizeGuidance}}. Please manually migrate this icon.",
47
- cantMigrateReExport: "'{{exportName}}' is a re-export of icon from '{{packageName}}' and cannot be automatically migrated. Please remove this re-export, and migrate any usages to the new icon APIs.",
48
- cantMigrateColor: "This icon's `primaryColor` prop is set to {{colorValue}}, which isn't a design token supported in the new Icon API. Please switch to an appropriate `color.icon`, `color.link` or `color.text` token, or currentColor in buttons and menus.",
49
- cantMigrateSpreadProps: "This usage of Icon uses spread props in a way that can't be automatically migrated. Please explicitly define the following props after spread in order to auto-migrate: '{{missingProps}}' ",
50
- cantMigrateSizeUnknown: "This usage of Icon sets the size via a variable or function that can't be automatically migrated. Please migrate manually to the correct `LEGACY_size` and `spacing` props.",
51
- cantMigrateFunctionUnknown: "Icon '{{iconName}}', from entrypoint '{{importSource}}', is passed into a function/component and can't be migrated automatically. Please manually migrate this icon.",
52
- cantMigrateIdentifierMapOrArray: "This icon is passed to other components via a map or array, and can't be migrated automatically. Please manually migrate wherever this expression is used to the new API, or use the icon components directly.",
53
- cantMigrateIdentifier: "This reference to {{iconName}} from {{iconSource}} can't be migrated automatically to the new components and API. Please manually migrate this and any other references."
54
- }
55
- },
56
- create: function create(context) {
57
- var _createHelpers = (0, _helpers.createHelpers)(context),
58
- getConfigFlag = _createHelpers.getConfigFlag;
59
- var failSilently = getConfigFlag('failSilently', false);
60
- var _createChecks = (0, _checks.createChecks)(context),
61
- checkImportDeclarations = _createChecks.checkImportDeclarations,
62
- checkVariableDeclarations = _createChecks.checkVariableDeclarations,
63
- checkExportDefaultDeclaration = _createChecks.checkExportDefaultDeclaration,
64
- checkExportNamedVariables = _createChecks.checkExportNamedVariables,
65
- checkArrayOrMap = _createChecks.checkArrayOrMap,
66
- checkIconAsProp = _createChecks.checkIconAsProp,
67
- checkJSXElement = _createChecks.checkJSXElement,
68
- checkCallExpression = _createChecks.checkCallExpression,
69
- throwErrors = _createChecks.throwErrors,
70
- checkIconReference = _createChecks.checkIconReference;
71
- return (0, _errorBoundary.errorBoundary)({
72
- // Track imports of relevant components
73
- ImportDeclaration: checkImportDeclarations,
74
- // Keep track of the relevant variable declarations and renames
75
- VariableDeclaration: checkVariableDeclarations,
76
- // Case: default re-exports. Can't be auto-migrated
77
- ExportDefaultDeclaration: checkExportDefaultDeclaration,
78
- ExportNamedDeclaration: checkExportNamedVariables,
79
- // Legacy icons found in arrays/objects
80
- 'ObjectExpression > Property > Identifier, ArrayExpression > Identifier ': checkArrayOrMap,
81
- // Legacy icons passed in via props, as JSX identifier (i.e. icon={AddIcon})
82
- 'JSXOpeningElement > JSXAttribute > JSXExpressionContainer > Identifier': checkIconAsProp,
83
- JSXElement: checkJSXElement,
84
- // Icons called as an argument of a function (i.e. icon={DefaultIcon(AddIcon)})
85
- CallExpression: checkCallExpression,
86
- Identifier: checkIconReference,
87
- 'Program:exit': throwErrors
88
- }, failSilently);
89
- }
90
- });
91
- var _default = exports.default = rule;
@@ -1,7 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.upcomingIcons = void 0;
7
- var upcomingIcons = exports.upcomingIcons = [];
@@ -1,520 +0,0 @@
1
- import { isNodeOfType } from 'eslint-codemod-utils';
2
- import { addToListOfRanges, canAutoMigrateNewIconBasedOnSize, canMigrateColor, createAutoMigrationError, createCantFindSuitableReplacementError, createCantMigrateColorError, createCantMigrateFunctionUnknownError, createCantMigrateIdentifierError, createCantMigrateIdentifierMapOrArrayError, createCantMigrateReExportError, createCantMigrateSizeUnknown, createCantMigrateSpreadPropsError, createGuidance, createHelpers, getMigrationMapObject, getUpcomingIcons, isInsideIconOnlyLegacyButton, isInsideLegacyButton, isInsideNewButton, isSize, locToString, throwAutoErrors, throwManualErrors } from './helpers';
3
- export const createChecks = context => {
4
- // Create global variables to be shared by the checks
5
- const {
6
- getPrimaryColor,
7
- getConfigFlag
8
- } = createHelpers(context);
9
- const legacyIconImports = {};
10
- const migrationIconImports = {};
11
- const newButtonImports = new Set();
12
- const legacyButtonImports = new Set();
13
- const errorsManual = {};
14
- const errorsAuto = {};
15
- const iconSizesInfo = {}; //Import source key, locations as value
16
-
17
- let guidance = {};
18
-
19
- // Extract parameters
20
- const shouldErrorForManualMigration = getConfigFlag('shouldErrorForManualMigration', true);
21
- const shouldErrorForAutoMigration = getConfigFlag('shouldErrorForAutoMigration', true);
22
- const isQuietMode = getConfigFlag('quiet', false);
23
- const shouldUseMigrationPath = getConfigFlag('shouldUseMigrationPath', true);
24
- const shouldUseSafeMigrationMode = getConfigFlag('shouldUseSafeMigrationMode', false);
25
-
26
- // Sorted list of ranges
27
- let errorRanges = [];
28
-
29
- /**
30
- * Adds the legacy Icon and new button imports to the correct global arrays to be used by the other checks
31
- * @param node The import node found by ESLint
32
- */
33
- const checkImportDeclarations = node => {
34
- const moduleSource = node.source.value;
35
-
36
- // Find the imports for legacy icons
37
- if (moduleSource && typeof moduleSource === 'string' && ['@atlaskit/icon/glyph/'].find(val => moduleSource.startsWith(val)) && node.specifiers.length > 0) {
38
- for (const spec of node.specifiers) {
39
- if (spec.local.name) {
40
- legacyIconImports[spec.local.name] = {
41
- packageName: moduleSource,
42
- exported: false,
43
- importNode: node,
44
- importSpecifier: spec.local.name
45
- };
46
- }
47
- }
48
- }
49
-
50
- // Find the imports for icons that import from migration path
51
- if (moduleSource && typeof moduleSource === 'string' && (moduleSource.startsWith('@atlaskit/icon/core/migration/') || moduleSource.startsWith('@atlaskit/icon/utility/migration/')) && node.specifiers.length) {
52
- node.specifiers.forEach(spec => {
53
- if (spec.local.name) {
54
- migrationIconImports[spec.local.name] = {
55
- packageName: moduleSource,
56
- exported: false,
57
- importNode: node,
58
- importSpecifier: spec.local.name
59
- };
60
- }
61
- });
62
- }
63
-
64
- // Find the imports for new button and IconButton
65
- if (typeof moduleSource === 'string' && moduleSource.startsWith('@atlaskit/button/new') && node.specifiers.length) {
66
- for (const spec of node.specifiers) {
67
- if (spec.type === 'ImportDefaultSpecifier') {
68
- newButtonImports.add(spec.local.name);
69
- } else if (spec.type === 'ImportSpecifier' && 'name' in spec.imported && spec.imported.name === 'IconButton') {
70
- newButtonImports.add(spec.local.name);
71
- }
72
- }
73
- }
74
-
75
- // Find the imports for legacy default button
76
- if (typeof moduleSource === 'string' && (moduleSource === '@atlaskit/button' || moduleSource === '@atlaskit/button/standard-button' || moduleSource === '@atlaskit/button/loading-button' || moduleSource === '@atlaskit/button/custom-theme-button') && node.specifiers.length) {
77
- for (const spec of node.specifiers) {
78
- if (spec.type === 'ImportDefaultSpecifier') {
79
- legacyButtonImports.add(spec.local.name);
80
- }
81
- }
82
- }
83
- };
84
-
85
- /**
86
- * Adds the legacy Icon and new button variable reassignments to the correct global arrays to be used by the other checks
87
- * @param node The variable reassignment node found by ESLint
88
- */
89
- const checkVariableDeclarations = node => {
90
- if (isNodeOfType(node, 'VariableDeclaration')) {
91
- const isExported = node.parent && isNodeOfType(node.parent, 'ExportNamedDeclaration');
92
- for (const decl of node.declarations) {
93
- if (isNodeOfType(decl, 'VariableDeclarator') && Object.keys(decl).includes('init') && Object.keys(decl).includes('id') && decl.init && decl.id && 'name' in decl.id && decl.id.name && isNodeOfType(decl.init, 'Identifier')) {
94
- if (Object.keys(legacyIconImports).includes(decl.init.name)) {
95
- legacyIconImports[decl.id.name] = {
96
- packageName: legacyIconImports[decl.init.name].packageName,
97
- exported: legacyIconImports[decl.init.name].exported || isExported,
98
- importNode: legacyIconImports[decl.init.name].importNode,
99
- importSpecifier: legacyIconImports[decl.init.name].importSpecifier
100
- };
101
- } else if (newButtonImports.has(decl.init.name)) {
102
- newButtonImports.add(decl.id.name);
103
- }
104
- }
105
- }
106
- }
107
- };
108
-
109
- /**
110
- * Checks if the default export is a re-export of a legacy icon and stores the errors in the global array
111
- * @param node The default export node found by ESLint
112
- */
113
- const checkExportDefaultDeclaration = node => {
114
- let exportName = '';
115
- let packageName = '';
116
- if (Object.keys(node).includes('declaration') && node.declaration && isNodeOfType(node.declaration, 'Identifier') && Object.keys(legacyIconImports).includes(node.declaration.name)) {
117
- packageName = legacyIconImports[node.declaration.name].packageName;
118
- exportName = 'Default export';
119
- } else if (Object.keys(node).includes('declaration') && node.declaration && isNodeOfType(node.declaration, 'AssignmentExpression') && isNodeOfType(node.declaration.left, 'Identifier') && isNodeOfType(node.declaration.right, 'Identifier') && Object.keys(legacyIconImports).includes(node.declaration.right.name)) {
120
- packageName = legacyIconImports[node.declaration.right.name].packageName;
121
- exportName = node.declaration.left.name;
122
- } else {
123
- return;
124
- }
125
- createCantMigrateReExportError(node, packageName, exportName, errorsManual);
126
- addToListOfRanges(node, errorRanges);
127
- guidance[locToString(node)] = createGuidance({
128
- iconPackage: packageName,
129
- shouldUseMigrationPath
130
- });
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
- const checkExportNamedVariables = node => {
138
- // Case: export {default as AddIcon} from '@atlaskit/icon/glyph/add';
139
- if (node.source && isNodeOfType(node.source, 'Literal') && Object.keys(node.source).includes('value')) {
140
- const moduleSource = node.source.value;
141
- if (typeof moduleSource === 'string' && ['@atlaskit/icon/glyph/'].find(val => moduleSource.startsWith(val)) && node.specifiers.length) {
142
- for (const spec of node.specifiers) {
143
- if ('name' in spec.exported) {
144
- createCantMigrateReExportError(spec, moduleSource, spec.exported.name, errorsManual);
145
- addToListOfRanges(spec, errorRanges);
146
- guidance[locToString(spec)] = createGuidance({
147
- iconPackage: moduleSource,
148
- shouldUseMigrationPath
149
- });
150
- }
151
- }
152
- }
153
- } else if (node.declaration && isNodeOfType(node.declaration, 'VariableDeclaration')) {
154
- // Case: export const Icon = AddIcon;
155
- for (const decl of node.declaration.declarations) {
156
- if (isNodeOfType(decl, 'VariableDeclarator') && Object.keys(decl).includes('init') && decl.init && isNodeOfType(decl.init, 'Identifier') && Object.keys(legacyIconImports).includes(decl.init.name)) {
157
- createCantMigrateReExportError(node, legacyIconImports[decl.init.name].packageName, decl.init.name, errorsManual);
158
- addToListOfRanges(node, errorRanges);
159
- guidance[locToString(node)] = createGuidance({
160
- iconPackage: legacyIconImports[decl.init.name].packageName,
161
- shouldUseMigrationPath
162
- });
163
- }
164
- }
165
- } else if (!node.source && node.specifiers && node.specifiers.length > 0) {
166
- /**
167
- * case where multiple consts are re-exported:
168
- * const AddIcon = LegacyIcon;
169
- * const crossIcon = LegacyIcon2;
170
- * export { AddIcon, CrossIcon as default }
171
- */
172
- for (const spec of node.specifiers) {
173
- if ('name' in spec.local && 'name' in spec.exported && Object.keys(legacyIconImports).includes(spec.local.name)) {
174
- //update legacy imports to be exported
175
- legacyIconImports[spec.local.name] = {
176
- packageName: legacyIconImports[spec.local.name].packageName,
177
- exported: true,
178
- importNode: legacyIconImports[spec.local.name].importNode,
179
- importSpecifier: legacyIconImports[spec.local.name].importSpecifier
180
- };
181
- createCantMigrateReExportError(spec, legacyIconImports[spec.local.name].packageName, spec.exported.name, errorsManual);
182
- addToListOfRanges(spec, errorRanges);
183
- guidance[locToString(spec)] = createGuidance({
184
- iconPackage: legacyIconImports[spec.local.name].packageName,
185
- shouldUseMigrationPath
186
- });
187
- }
188
- }
189
- }
190
- };
191
-
192
- /**
193
- * Checks if a legacy icon is referenced in an array or map and stores the errors in the global array
194
- * @param node The array/map node found by ESLint
195
- */
196
- const checkArrayOrMap = node => {
197
- if (!isNodeOfType(node, 'Identifier')) {
198
- return;
199
- }
200
- if (node.name && Object.keys(legacyIconImports).includes(node.name) && legacyIconImports[node.name].packageName) {
201
- createCantMigrateIdentifierMapOrArrayError(node, legacyIconImports[node.name].packageName, node.name, errorsManual);
202
- addToListOfRanges(node, errorRanges);
203
- guidance[locToString(node)] = createGuidance({
204
- iconPackage: legacyIconImports[node.name].packageName,
205
- shouldUseMigrationPath
206
- });
207
- }
208
- };
209
-
210
- /**
211
- * Checks if a legacy icon is referenced as a prop to a component and stores the errors in the global array
212
- * @param node The property node found by ESLint
213
- */
214
- const checkIconAsProp = node => {
215
- if (!isNodeOfType(node, 'Identifier')) {
216
- return;
217
- }
218
- if (!node.parent || !node.parent.parent || !node.parent.parent.parent) {
219
- return;
220
- }
221
- if (!isNodeOfType(node.parent, 'JSXExpressionContainer') || !isNodeOfType(node.parent.parent, 'JSXAttribute') || !isNodeOfType(node.parent.parent.parent, 'JSXOpeningElement')) {
222
- return;
223
- }
224
- if (Object.keys(legacyIconImports).includes(node.name) && isNodeOfType(node.parent.parent.name, 'JSXIdentifier') && node.parent.parent.name.name !== 'LEGACY_fallbackIcon') {
225
- var _migrationMapObject$s;
226
- const migrationMapObject = getMigrationMapObject(legacyIconImports[node.name].packageName);
227
- const upcomingIcon = getUpcomingIcons(legacyIconImports[node.name].packageName);
228
- const newIcon = migrationMapObject === null || migrationMapObject === void 0 ? void 0 : migrationMapObject.newIcon;
229
- const isNewIconMigratable = canAutoMigrateNewIconBasedOnSize(upcomingIcon ? upcomingIcon.sizeGuidance.medium : migrationMapObject === null || migrationMapObject === void 0 ? void 0 : (_migrationMapObject$s = migrationMapObject.sizeGuidance) === null || _migrationMapObject$s === void 0 ? void 0 : _migrationMapObject$s.medium);
230
- const isInNewButton = isNodeOfType(node.parent.parent.parent.name, 'JSXIdentifier') && newButtonImports.has(node.parent.parent.parent.name.name);
231
- if (newIcon && isInNewButton && isNewIconMigratable || upcomingIcon && isInNewButton && isNewIconMigratable) {
232
- createAutoMigrationError({
233
- node,
234
- importSource: legacyIconImports[node.name].packageName,
235
- iconName: node.name,
236
- errors: errorsAuto
237
- });
238
- addToListOfRanges(node, errorRanges);
239
- guidance[locToString(node)] = createGuidance({
240
- iconPackage: legacyIconImports[node.name].packageName,
241
- insideNewButton: true,
242
- size: 'medium',
243
- shouldUseMigrationPath
244
- });
245
- } else if (!newIcon && !upcomingIcon || !isNewIconMigratable) {
246
- createCantFindSuitableReplacementError(node, legacyIconImports[node.name].packageName, node.name, errorsManual);
247
- addToListOfRanges(node, errorRanges);
248
- guidance[locToString(node)] = createGuidance({
249
- iconPackage: legacyIconImports[node.name].packageName,
250
- insideNewButton: isInNewButton,
251
- shouldUseMigrationPath
252
- });
253
- } else if (!isInNewButton) {
254
- createCantMigrateFunctionUnknownError(node, legacyIconImports[node.name].packageName, node.name, errorsManual);
255
- addToListOfRanges(node, errorRanges);
256
- guidance[locToString(node)] = createGuidance({
257
- iconPackage: legacyIconImports[node.name].packageName,
258
- insideNewButton: false,
259
- shouldUseMigrationPath
260
- });
261
- }
262
- }
263
- };
264
- const checkIconReference = node => {
265
- //if this is an import statement then exit early
266
- if (node.parent && (isNodeOfType(node.parent, 'ImportSpecifier') || isNodeOfType(node.parent, 'ImportDefaultSpecifier'))) {
267
- return;
268
- }
269
-
270
- // Flag icons imported from migration path
271
- if (!shouldUseMigrationPath && Object.keys(migrationIconImports).includes(node.name)) {
272
- createAutoMigrationError({
273
- node,
274
- importSource: migrationIconImports[node.name].packageName,
275
- iconName: node.name,
276
- errors: errorsAuto
277
- });
278
- }
279
-
280
- //check the reference to see if it's a legacy icon, if not exit early
281
- if (!Object.keys(legacyIconImports).includes(node.name)) {
282
- return;
283
- }
284
-
285
- //if in Fallback prop, do not error
286
- if (node.parent && node.parent.parent && isNodeOfType(node.parent.parent, 'JSXAttribute') && isNodeOfType(node.parent.parent.name, 'JSXIdentifier') && node.parent.parent.name.name === 'LEGACY_fallbackIcon') {
287
- return;
288
- }
289
- // manually error
290
- createCantMigrateIdentifierError(node, legacyIconImports[node.name].packageName, node.name, errorsManual);
291
- };
292
-
293
- /**
294
- * Checks if a legacy icon is being rendered and stores the errors in the global array
295
- * @param node The JSX node found by ESLint
296
- */
297
- const checkJSXElement = node => {
298
- var _node$parent, _node$parent$parent, _node$parent$parent$p;
299
- if (!('openingElement' in node) || !isNodeOfType(node.openingElement.name, 'JSXIdentifier')) {
300
- return;
301
- }
302
-
303
- // Determine if element is rendered inside LEGACY_fallbackIcon prop - if so, don't perform any checks
304
- if (node.parent && isNodeOfType(node.parent, 'ArrowFunctionExpression') && (_node$parent = node.parent) !== null && _node$parent !== void 0 && (_node$parent$parent = _node$parent.parent) !== null && _node$parent$parent !== void 0 && _node$parent$parent.parent && 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') {
305
- return;
306
- }
307
- const name = node.openingElement.name.name;
308
-
309
- // Flag icons imported from migration path
310
- if (!shouldUseMigrationPath && Object.keys(migrationIconImports).includes(name)) {
311
- createAutoMigrationError({
312
- node,
313
- importSource: migrationIconImports[name].packageName,
314
- iconName: name,
315
- errors: errorsAuto,
316
- spacing: undefined,
317
- insideNewButton: true
318
- });
319
- }
320
-
321
- // Legacy icons rendered as JSX elements
322
- if (Object.keys(legacyIconImports).includes(name)) {
323
- var _size, _size2, _sizeProp$value2;
324
- // Determine if inside a new button - if so:
325
- // - Assume spread props are safe - still error if props explicitly set to unmigratable values
326
- const insideNewButton = isInsideNewButton(node, newButtonImports);
327
-
328
- // Determine if inside a legacy default button - if so:
329
- // the auto fixer will add spacing prop to the medium size icon
330
- const insideLegacyButton = isInsideLegacyButton(node, legacyButtonImports);
331
- const insideIconOnlyLegacyButton = isInsideIconOnlyLegacyButton(node, legacyButtonImports);
332
-
333
- // Find size prop on node
334
- let size = 'medium';
335
- let primaryColor = null;
336
- let hasPrimaryColorProp = false;
337
- let hasSecondaryColorProp = false;
338
- let afterSpreadSet = new Set();
339
- let requiredAttributesAfterSpread = new Set(['size', 'primaryColor', 'secondaryColor']);
340
- let hasSpread = false;
341
- for (const attr of node.openingElement.attributes) {
342
- // Detect spread props
343
- if (isNodeOfType(attr, 'JSXSpreadAttribute')) {
344
- // In case there are more spread props
345
- afterSpreadSet.clear();
346
- hasSpread = true;
347
- continue;
348
- }
349
- if (!isNodeOfType(attr, 'JSXAttribute') || !isNodeOfType(attr.name, 'JSXIdentifier') || !attr.value) {
350
- continue;
351
- }
352
-
353
- // Register props that aren't being spread
354
- afterSpreadSet.add(attr.name.name);
355
-
356
- // Extract values of props
357
- switch (attr.name.name) {
358
- case 'size':
359
- if (isNodeOfType(attr.value, 'Literal') && isSize(attr.value.value)) {
360
- size = attr.value.value;
361
- } else if (isNodeOfType(attr.value, 'JSXExpressionContainer') && isNodeOfType(attr.value.expression, 'Literal') && isSize(attr.value.expression.value)) {
362
- size = attr.value.expression.value;
363
- } else {
364
- size = null;
365
- }
366
- break;
367
- case 'primaryColor':
368
- primaryColor = getPrimaryColor(attr);
369
- hasPrimaryColorProp = true;
370
- break;
371
- case 'secondaryColor':
372
- hasSecondaryColorProp = true;
373
- break;
374
- }
375
- }
376
- let hasManualMigration = false;
377
-
378
- // Flag manual migration if primary color cannot be migrated
379
- if (primaryColor && !canMigrateColor(primaryColor) || hasPrimaryColorProp && !primaryColor) {
380
- createCantMigrateColorError(node, primaryColor ? `the value of '${primaryColor}'` : 'a statically unknown value', errorsManual, legacyIconImports[name].packageName, name);
381
- hasManualMigration = true;
382
- }
383
-
384
- // If size can't be determined (i.e. size is a variable or function call, etc)
385
- // then we need to error; icon can't be auto-migrated safely
386
- if (size === null) {
387
- createCantMigrateSizeUnknown(node, errorsManual, legacyIconImports[name].packageName, name);
388
- hasManualMigration = true;
389
- }
390
-
391
- // Do a set comparison - is requiredAttributesAfterSpread a subset of afterSpreadSet?
392
- if (hasSpread === true && !Array.from(requiredAttributesAfterSpread).every(val => afterSpreadSet.has(val)) && !insideNewButton) {
393
- const missingProps = Array.from(requiredAttributesAfterSpread).filter(val => !afterSpreadSet.has(val));
394
- createCantMigrateSpreadPropsError(node, missingProps, errorsManual, legacyIconImports[name].packageName, name);
395
- hasManualMigration = true;
396
- }
397
-
398
- // Check if it is an exported component?
399
- if (legacyIconImports[name].exported) {
400
- createCantMigrateReExportError(node, legacyIconImports[name].packageName, name, errorsManual);
401
- hasManualMigration = true;
402
- }
403
- const migrationMapObject = getMigrationMapObject(legacyIconImports[name].packageName);
404
- const upcomingIcon = getUpcomingIcons(legacyIconImports[name].packageName);
405
- const newIcon = migrationMapObject === null || migrationMapObject === void 0 ? void 0 : migrationMapObject.newIcon;
406
- const isNewIconMigratable = canAutoMigrateNewIconBasedOnSize(upcomingIcon ? upcomingIcon.sizeGuidance[(_size = size) !== null && _size !== void 0 ? _size : 'medium'] : migrationMapObject === null || migrationMapObject === void 0 ? void 0 : migrationMapObject.sizeGuidance[(_size2 = size) !== null && _size2 !== void 0 ? _size2 : 'medium']);
407
-
408
- // Add spacing if:
409
- // 1. size is medium for core/utility icons or not set (default is medium for core and small for utility icons)
410
- // 2. not inside a new or legacy button (except for icon-only legacy buttons)
411
- const sizeProp = node.openingElement.attributes.find(attribute => attribute.type === 'JSXAttribute' && (attribute.name.name === 'size' || attribute.name.name === 'LEGACY_size'));
412
- let spacing;
413
- if (!insideNewButton && !(insideLegacyButton && !insideIconOnlyLegacyButton)) {
414
- var _sizeProp$value;
415
- if (sizeProp && sizeProp.type === 'JSXAttribute' && ((_sizeProp$value = sizeProp.value) === null || _sizeProp$value === void 0 ? void 0 : _sizeProp$value.type) === 'Literal') {
416
- if (sizeProp.value.value === 'medium') {
417
- spacing = 'spacious';
418
- }
419
- } else if (!sizeProp) {
420
- spacing = 'spacious';
421
- }
422
- }
423
- if (!iconSizesInfo[legacyIconImports[name].packageName]) {
424
- iconSizesInfo[legacyIconImports[name].packageName] = {
425
- small: [],
426
- usageCount: 0
427
- };
428
- }
429
-
430
- // Do not automatically migration if size is small as we cannot determine if a core icon or a scaled down utility icon should be used
431
- if (sizeProp && sizeProp.type === 'JSXAttribute' && ((_sizeProp$value2 = sizeProp.value) === null || _sizeProp$value2 === void 0 ? void 0 : _sizeProp$value2.type) === 'Literal' && sizeProp.value.value === 'small') {
432
- iconSizesInfo[legacyIconImports[name].packageName].small.push(locToString(node));
433
- }
434
- iconSizesInfo[legacyIconImports[name].packageName].usageCount++;
435
- const shouldForceSmallIcon = newIcon === null || newIcon === void 0 ? void 0 : newIcon.shouldForceSmallIcon;
436
- if (shouldUseSafeMigrationMode && !hasManualMigration && (newIcon !== null && newIcon !== void 0 && newIcon.isMigrationUnsafe || size !== 'medium' || hasSecondaryColorProp)) {
437
- createCantFindSuitableReplacementError(node, legacyIconImports[name].packageName, name, errorsManual, upcomingIcon ? true : migrationMapObject ? true : false);
438
- } else if (!hasManualMigration && (newIcon || upcomingIcon) && isNewIconMigratable) {
439
- createAutoMigrationError({
440
- node,
441
- importSource: legacyIconImports[name].packageName,
442
- iconName: name,
443
- errors: errorsAuto,
444
- spacing,
445
- insideNewButton,
446
- shouldForceSmallIcon
447
- });
448
- } else if ((!newIcon && !upcomingIcon || !isNewIconMigratable) && size) {
449
- createCantFindSuitableReplacementError(node, legacyIconImports[name].packageName, name, errorsManual, upcomingIcon ? true : migrationMapObject ? true : false);
450
- }
451
- addToListOfRanges(node, errorRanges);
452
- guidance[locToString(node)] = createGuidance({
453
- iconPackage: legacyIconImports[name].packageName,
454
- insideNewButton,
455
- size: size && isSize(size) ? size : undefined,
456
- shouldUseMigrationPath,
457
- shouldForceSmallIcon
458
- });
459
- }
460
- };
461
-
462
- /**
463
- * Checks if a legacy icon is being passed into a function call and stores the errors in the global array
464
- * @param node The function call node found by ESLint
465
- */
466
- const checkCallExpression = node => {
467
- if (Object.keys(node).includes('arguments') && node.arguments.length) {
468
- for (const arg of node.arguments) {
469
- if (isNodeOfType(arg, 'Identifier') && Object.keys(legacyIconImports).includes(arg.name) && legacyIconImports[arg.name].packageName) {
470
- createCantMigrateFunctionUnknownError(node, legacyIconImports[arg.name].packageName, arg.name, errorsManual);
471
- addToListOfRanges(node, errorRanges);
472
- guidance[locToString(node)] = createGuidance({
473
- iconPackage: legacyIconImports[arg.name].packageName,
474
- shouldUseMigrationPath
475
- });
476
- }
477
- }
478
- }
479
- };
480
-
481
- /**
482
- * Throws the relevant errors in the correct order based on configs.
483
- */
484
- const throwErrors = () => {
485
- // Throw manual errors
486
- if (shouldErrorForManualMigration) {
487
- throwManualErrors({
488
- errorsManual,
489
- errorRanges,
490
- guidance,
491
- context,
492
- isQuietMode
493
- });
494
- }
495
- if (shouldErrorForAutoMigration) {
496
- throwAutoErrors({
497
- errorsManual,
498
- errorsAuto,
499
- iconSizesInfo,
500
- legacyIconImports,
501
- guidance,
502
- migrationIconImports,
503
- shouldUseMigrationPath,
504
- context
505
- });
506
- }
507
- };
508
- return {
509
- checkImportDeclarations,
510
- checkVariableDeclarations,
511
- checkExportDefaultDeclaration,
512
- checkExportNamedVariables,
513
- checkArrayOrMap,
514
- checkIconAsProp,
515
- checkJSXElement,
516
- checkCallExpression,
517
- throwErrors,
518
- checkIconReference
519
- };
520
- };