@atlaskit/eslint-plugin-design-system 10.8.1 → 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.
- package/CHANGELOG.md +9 -0
- package/dist/cjs/rules/ensure-design-token-usage/index.js +1 -1
- package/dist/cjs/rules/no-legacy-icons/checks.js +484 -0
- package/dist/cjs/rules/no-legacy-icons/helpers.js +289 -0
- package/dist/cjs/rules/no-legacy-icons/index.js +111 -131
- package/dist/cjs/rules/no-legacy-icons/migration-map-temp.js +4090 -0
- package/dist/cjs/rules/use-tokens-typography/index.js +1 -1
- package/dist/es2019/rules/ensure-design-token-usage/index.js +1 -1
- package/dist/es2019/rules/no-legacy-icons/checks.js +388 -0
- package/dist/es2019/rules/no-legacy-icons/helpers.js +275 -0
- package/dist/es2019/rules/no-legacy-icons/index.js +96 -97
- package/dist/es2019/rules/no-legacy-icons/migration-map-temp.js +4082 -0
- package/dist/es2019/rules/use-tokens-typography/index.js +1 -1
- package/dist/esm/rules/ensure-design-token-usage/index.js +1 -1
- package/dist/esm/rules/no-legacy-icons/checks.js +477 -0
- package/dist/esm/rules/no-legacy-icons/helpers.js +279 -0
- package/dist/esm/rules/no-legacy-icons/index.js +111 -131
- package/dist/esm/rules/no-legacy-icons/migration-map-temp.js +4084 -0
- package/dist/esm/rules/use-tokens-typography/index.js +1 -1
- package/dist/types/rules/no-legacy-icons/checks.d.ts +13 -0
- package/dist/types/rules/no-legacy-icons/helpers.d.ts +82 -0
- package/dist/types/rules/no-legacy-icons/index.d.ts +2 -1
- package/dist/types/rules/no-legacy-icons/migration-map-temp.d.ts +22 -0
- package/dist/{types-ts4.5/rules/use-tokens-typography → types/rules/utils}/error-boundary.d.ts +5 -1
- package/dist/types-ts4.5/rules/no-legacy-icons/checks.d.ts +13 -0
- package/dist/types-ts4.5/rules/no-legacy-icons/helpers.d.ts +82 -0
- package/dist/types-ts4.5/rules/no-legacy-icons/index.d.ts +2 -1
- package/dist/types-ts4.5/rules/no-legacy-icons/migration-map-temp.d.ts +27 -0
- package/dist/types-ts4.5/rules/{ensure-design-token-usage → utils}/error-boundary.d.ts +5 -1
- package/package.json +1 -1
- package/dist/cjs/rules/use-tokens-typography/error-boundary.js +0 -24
- package/dist/es2019/rules/use-tokens-typography/error-boundary.js +0 -19
- package/dist/esm/rules/use-tokens-typography/error-boundary.js +0 -18
- package/dist/types/rules/ensure-design-token-usage/error-boundary.d.ts +0 -11
- package/dist/types/rules/use-tokens-typography/error-boundary.d.ts +0 -11
- /package/dist/cjs/rules/{ensure-design-token-usage → utils}/error-boundary.js +0 -0
- /package/dist/es2019/rules/{ensure-design-token-usage → utils}/error-boundary.js +0 -0
- /package/dist/esm/rules/{ensure-design-token-usage → utils}/error-boundary.js +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
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
|
+
|
|
3
12
|
## 10.8.1
|
|
4
13
|
|
|
5
14
|
### Patch Changes
|
|
@@ -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");
|
|
@@ -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
|
+
};
|