@atlaskit/eslint-plugin-design-system 10.16.0 → 10.17.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +19 -0
- package/README.md +1 -1
- package/dist/cjs/rules/no-legacy-icons/checks.js +272 -84
- package/dist/cjs/rules/no-legacy-icons/helpers.js +214 -14
- package/dist/cjs/rules/no-legacy-icons/index.js +4 -0
- package/dist/cjs/rules/no-legacy-icons/upcoming-icons.js +1 -1
- package/dist/es2019/rules/no-legacy-icons/checks.js +190 -24
- package/dist/es2019/rules/no-legacy-icons/helpers.js +220 -6
- package/dist/es2019/rules/no-legacy-icons/index.js +4 -0
- package/dist/es2019/rules/no-legacy-icons/upcoming-icons.js +1 -1
- package/dist/esm/rules/no-legacy-icons/checks.js +273 -85
- package/dist/esm/rules/no-legacy-icons/helpers.js +214 -14
- package/dist/esm/rules/no-legacy-icons/index.js +4 -0
- package/dist/esm/rules/no-legacy-icons/upcoming-icons.js +1 -1
- package/dist/types/rules/no-legacy-icons/helpers.d.ts +88 -3
- package/dist/types-ts4.5/rules/no-legacy-icons/helpers.d.ts +88 -3
- package/package.json +3 -3
|
@@ -1,24 +1,32 @@
|
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
2
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
1
3
|
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
4
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
5
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
2
6
|
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
3
7
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
4
8
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
5
9
|
import { isNodeOfType } from 'eslint-codemod-utils';
|
|
6
|
-
import { addToListOfRanges, canAutoMigrateNewIconBasedOnSize, canMigrateColor, createAutoMigrationError, createCantFindSuitableReplacementError, createCantMigrateColorError, createCantMigrateFunctionUnknownError, createCantMigrateIdentifierError, createCantMigrateIdentifierMapOrArrayError, createCantMigrateReExportError, createCantMigrateSizeUnknown, createCantMigrateSpreadPropsError, createGuidance, createHelpers, getMigrationMapObject, getUpcomingIcons, isInRangeList, isSize, locToString } from './helpers';
|
|
10
|
+
import { addToListOfRanges, canAutoMigrateNewIconBasedOnSize, canMigrateColor, checkIfNewIconExist, createAutoMigrationError, createCantFindSuitableReplacementError, createCantMigrateColorError, createCantMigrateFunctionUnknownError, createCantMigrateIdentifierError, createCantMigrateIdentifierMapOrArrayError, createCantMigrateReExportError, createCantMigrateSizeUnknown, createCantMigrateSpreadPropsError, createGuidance, createHelpers, createImportFix, createPropFixes, getMigrationMapObject, getUpcomingIcons, isInRangeList, isInsideLegacyButton, isInsideNewButton, isSize, locToString } from './helpers';
|
|
7
11
|
export var createChecks = function createChecks(context) {
|
|
8
12
|
//create global variables to be shared by the checks
|
|
9
13
|
var _createHelpers = createHelpers(context),
|
|
10
14
|
getPrimaryColor = _createHelpers.getPrimaryColor,
|
|
11
15
|
getConfigFlag = _createHelpers.getConfigFlag;
|
|
12
16
|
var legacyIconImports = {};
|
|
17
|
+
var migrationIconImports = {};
|
|
13
18
|
var newButtonImports = new Set();
|
|
19
|
+
var legacyButtonImports = new Set();
|
|
14
20
|
var errorsManual = {};
|
|
15
21
|
var errorsAuto = {};
|
|
16
22
|
var guidance = {};
|
|
23
|
+
var autoIconJSXElementOccurrenceCount = 0;
|
|
17
24
|
|
|
18
25
|
// Extract parameters
|
|
19
26
|
var shouldErrorForManualMigration = getConfigFlag('shouldErrorForManualMigration', true);
|
|
20
27
|
var shouldErrorForAutoMigration = getConfigFlag('shouldErrorForAutoMigration', true);
|
|
21
28
|
var isQuietMode = getConfigFlag('quiet', false);
|
|
29
|
+
var shouldUseMigrationPath = getConfigFlag('shouldUseMigrationPath', true);
|
|
22
30
|
|
|
23
31
|
// Sorted list of ranges
|
|
24
32
|
var errorRanges = [];
|
|
@@ -42,7 +50,8 @@ export var createChecks = function createChecks(context) {
|
|
|
42
50
|
if (spec.local.name) {
|
|
43
51
|
legacyIconImports[spec.local.name] = {
|
|
44
52
|
packageName: moduleSource,
|
|
45
|
-
exported: false
|
|
53
|
+
exported: false,
|
|
54
|
+
importNode: node
|
|
46
55
|
};
|
|
47
56
|
}
|
|
48
57
|
}
|
|
@@ -53,6 +62,19 @@ export var createChecks = function createChecks(context) {
|
|
|
53
62
|
}
|
|
54
63
|
}
|
|
55
64
|
|
|
65
|
+
// Find the imports for icons that import from migration path
|
|
66
|
+
if (moduleSource && typeof moduleSource === 'string' && (moduleSource.startsWith('@atlaskit/icon/core/migration/') || moduleSource.startsWith('@atlaskit/icon/utility/migration/')) && node.specifiers.length) {
|
|
67
|
+
node.specifiers.forEach(function (spec) {
|
|
68
|
+
if (spec.local.name) {
|
|
69
|
+
migrationIconImports[spec.local.name] = {
|
|
70
|
+
packageName: moduleSource,
|
|
71
|
+
exported: false,
|
|
72
|
+
importNode: node
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
|
|
56
78
|
// Find the imports for new button and IconButton
|
|
57
79
|
if (typeof moduleSource === 'string' && moduleSource.startsWith('@atlaskit/button/new') && node.specifiers.length) {
|
|
58
80
|
var _iterator2 = _createForOfIteratorHelper(node.specifiers),
|
|
@@ -72,6 +94,24 @@ export var createChecks = function createChecks(context) {
|
|
|
72
94
|
_iterator2.f();
|
|
73
95
|
}
|
|
74
96
|
}
|
|
97
|
+
|
|
98
|
+
// Find the imports for legacy default button
|
|
99
|
+
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) {
|
|
100
|
+
var _iterator3 = _createForOfIteratorHelper(node.specifiers),
|
|
101
|
+
_step3;
|
|
102
|
+
try {
|
|
103
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
104
|
+
var _spec2 = _step3.value;
|
|
105
|
+
if (_spec2.type === 'ImportDefaultSpecifier') {
|
|
106
|
+
legacyButtonImports.add(_spec2.local.name);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
} catch (err) {
|
|
110
|
+
_iterator3.e(err);
|
|
111
|
+
} finally {
|
|
112
|
+
_iterator3.f();
|
|
113
|
+
}
|
|
114
|
+
}
|
|
75
115
|
};
|
|
76
116
|
|
|
77
117
|
/**
|
|
@@ -81,11 +121,11 @@ export var createChecks = function createChecks(context) {
|
|
|
81
121
|
var checkVariableDeclarations = function checkVariableDeclarations(node) {
|
|
82
122
|
if (isNodeOfType(node, 'VariableDeclaration')) {
|
|
83
123
|
var isExported = node.parent && isNodeOfType(node.parent, 'ExportNamedDeclaration');
|
|
84
|
-
var
|
|
85
|
-
|
|
124
|
+
var _iterator4 = _createForOfIteratorHelper(node.declarations),
|
|
125
|
+
_step4;
|
|
86
126
|
try {
|
|
87
|
-
for (
|
|
88
|
-
var decl =
|
|
127
|
+
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
128
|
+
var decl = _step4.value;
|
|
89
129
|
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')) {
|
|
90
130
|
if (Object.keys(legacyIconImports).includes(decl.init.name)) {
|
|
91
131
|
legacyIconImports[decl.id.name] = {
|
|
@@ -98,9 +138,9 @@ export var createChecks = function createChecks(context) {
|
|
|
98
138
|
}
|
|
99
139
|
}
|
|
100
140
|
} catch (err) {
|
|
101
|
-
|
|
141
|
+
_iterator4.e(err);
|
|
102
142
|
} finally {
|
|
103
|
-
|
|
143
|
+
_iterator4.f();
|
|
104
144
|
}
|
|
105
145
|
}
|
|
106
146
|
};
|
|
@@ -123,7 +163,10 @@ export var createChecks = function createChecks(context) {
|
|
|
123
163
|
}
|
|
124
164
|
createCantMigrateReExportError(node, packageName, exportName, errorsManual);
|
|
125
165
|
addToListOfRanges(node, errorRanges);
|
|
126
|
-
guidance[locToString(node)] = createGuidance(
|
|
166
|
+
guidance[locToString(node)] = createGuidance({
|
|
167
|
+
iconPackage: packageName,
|
|
168
|
+
shouldUseMigrationPath: shouldUseMigrationPath
|
|
169
|
+
});
|
|
127
170
|
};
|
|
128
171
|
|
|
129
172
|
/**
|
|
@@ -137,38 +180,44 @@ export var createChecks = function createChecks(context) {
|
|
|
137
180
|
if (typeof moduleSource === 'string' && ['@atlaskit/icon/glyph/', '@atlaskit/icon-object/glyph/'].find(function (val) {
|
|
138
181
|
return moduleSource.startsWith(val);
|
|
139
182
|
}) && node.specifiers.length) {
|
|
140
|
-
var
|
|
141
|
-
|
|
183
|
+
var _iterator5 = _createForOfIteratorHelper(node.specifiers),
|
|
184
|
+
_step5;
|
|
142
185
|
try {
|
|
143
|
-
for (
|
|
144
|
-
var spec =
|
|
186
|
+
for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
|
|
187
|
+
var spec = _step5.value;
|
|
145
188
|
createCantMigrateReExportError(spec, moduleSource, spec.exported.name, errorsManual);
|
|
146
189
|
addToListOfRanges(spec, errorRanges);
|
|
147
|
-
guidance[locToString(spec)] = createGuidance(
|
|
190
|
+
guidance[locToString(spec)] = createGuidance({
|
|
191
|
+
iconPackage: moduleSource,
|
|
192
|
+
shouldUseMigrationPath: shouldUseMigrationPath
|
|
193
|
+
});
|
|
148
194
|
}
|
|
149
195
|
} catch (err) {
|
|
150
|
-
|
|
196
|
+
_iterator5.e(err);
|
|
151
197
|
} finally {
|
|
152
|
-
|
|
198
|
+
_iterator5.f();
|
|
153
199
|
}
|
|
154
200
|
}
|
|
155
201
|
} else if (node.declaration && isNodeOfType(node.declaration, 'VariableDeclaration')) {
|
|
156
202
|
// export const Icon = AddIcon;
|
|
157
|
-
var
|
|
158
|
-
|
|
203
|
+
var _iterator6 = _createForOfIteratorHelper(node.declaration.declarations),
|
|
204
|
+
_step6;
|
|
159
205
|
try {
|
|
160
|
-
for (
|
|
161
|
-
var decl =
|
|
206
|
+
for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
|
|
207
|
+
var decl = _step6.value;
|
|
162
208
|
if (isNodeOfType(decl, 'VariableDeclarator') && Object.keys(decl).includes('init') && decl.init && isNodeOfType(decl.init, 'Identifier') && Object.keys(legacyIconImports).includes(decl.init.name)) {
|
|
163
209
|
createCantMigrateReExportError(node, legacyIconImports[decl.init.name].packageName, decl.init.name, errorsManual);
|
|
164
210
|
addToListOfRanges(node, errorRanges);
|
|
165
|
-
guidance[locToString(node)] = createGuidance(
|
|
211
|
+
guidance[locToString(node)] = createGuidance({
|
|
212
|
+
iconPackage: legacyIconImports[decl.init.name].packageName,
|
|
213
|
+
shouldUseMigrationPath: shouldUseMigrationPath
|
|
214
|
+
});
|
|
166
215
|
}
|
|
167
216
|
}
|
|
168
217
|
} catch (err) {
|
|
169
|
-
|
|
218
|
+
_iterator6.e(err);
|
|
170
219
|
} finally {
|
|
171
|
-
|
|
220
|
+
_iterator6.f();
|
|
172
221
|
}
|
|
173
222
|
} else if (!node.source && node.specifiers && node.specifiers.length > 0) {
|
|
174
223
|
/**
|
|
@@ -177,26 +226,29 @@ export var createChecks = function createChecks(context) {
|
|
|
177
226
|
* const crossIcon = LegacyIcon2;
|
|
178
227
|
* export { AddIcon, CrossIcon as default }
|
|
179
228
|
*/
|
|
180
|
-
var
|
|
181
|
-
|
|
229
|
+
var _iterator7 = _createForOfIteratorHelper(node.specifiers),
|
|
230
|
+
_step7;
|
|
182
231
|
try {
|
|
183
|
-
for (
|
|
184
|
-
var
|
|
185
|
-
if (Object.keys(legacyIconImports).includes(
|
|
232
|
+
for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
|
|
233
|
+
var _spec3 = _step7.value;
|
|
234
|
+
if (Object.keys(legacyIconImports).includes(_spec3.local.name)) {
|
|
186
235
|
//update legacy imports to be exported
|
|
187
|
-
legacyIconImports[
|
|
188
|
-
packageName: legacyIconImports[
|
|
236
|
+
legacyIconImports[_spec3.local.name] = {
|
|
237
|
+
packageName: legacyIconImports[_spec3.local.name].packageName,
|
|
189
238
|
exported: true
|
|
190
239
|
};
|
|
191
|
-
createCantMigrateReExportError(
|
|
192
|
-
addToListOfRanges(
|
|
193
|
-
guidance[locToString(
|
|
240
|
+
createCantMigrateReExportError(_spec3, legacyIconImports[_spec3.local.name].packageName, _spec3.exported.name, errorsManual);
|
|
241
|
+
addToListOfRanges(_spec3, errorRanges);
|
|
242
|
+
guidance[locToString(_spec3)] = createGuidance({
|
|
243
|
+
iconPackage: legacyIconImports[_spec3.local.name].packageName,
|
|
244
|
+
shouldUseMigrationPath: shouldUseMigrationPath
|
|
245
|
+
});
|
|
194
246
|
}
|
|
195
247
|
}
|
|
196
248
|
} catch (err) {
|
|
197
|
-
|
|
249
|
+
_iterator7.e(err);
|
|
198
250
|
} finally {
|
|
199
|
-
|
|
251
|
+
_iterator7.f();
|
|
200
252
|
}
|
|
201
253
|
}
|
|
202
254
|
};
|
|
@@ -212,7 +264,10 @@ export var createChecks = function createChecks(context) {
|
|
|
212
264
|
if (node.name && Object.keys(legacyIconImports).includes(node.name) && legacyIconImports[node.name].packageName) {
|
|
213
265
|
createCantMigrateIdentifierMapOrArrayError(node, legacyIconImports[node.name].packageName, node.name, errorsManual);
|
|
214
266
|
addToListOfRanges(node, errorRanges);
|
|
215
|
-
guidance[locToString(node)] = createGuidance(
|
|
267
|
+
guidance[locToString(node)] = createGuidance({
|
|
268
|
+
iconPackage: legacyIconImports[node.name].packageName,
|
|
269
|
+
shouldUseMigrationPath: shouldUseMigrationPath
|
|
270
|
+
});
|
|
216
271
|
}
|
|
217
272
|
};
|
|
218
273
|
|
|
@@ -238,29 +293,59 @@ export var createChecks = function createChecks(context) {
|
|
|
238
293
|
var isNewIconMigratable = canAutoMigrateNewIconBasedOnSize(upcomingIcon ? upcomingIcon.sizeGuidance.medium : migrationMapObject === null || migrationMapObject === void 0 || (_migrationMapObject$s = migrationMapObject.sizeGuidance) === null || _migrationMapObject$s === void 0 ? void 0 : _migrationMapObject$s.medium);
|
|
239
294
|
var isInNewButton = isNodeOfType(node.parent.parent.parent.name, 'JSXIdentifier') && newButtonImports.has(node.parent.parent.parent.name.name);
|
|
240
295
|
if (newIcon && isInNewButton && isNewIconMigratable || upcomingIcon && isInNewButton && isNewIconMigratable) {
|
|
241
|
-
createAutoMigrationError(
|
|
296
|
+
createAutoMigrationError({
|
|
297
|
+
node: node,
|
|
298
|
+
importSource: legacyIconImports[node.name].packageName,
|
|
299
|
+
iconName: node.name,
|
|
300
|
+
errors: errorsAuto
|
|
301
|
+
});
|
|
242
302
|
addToListOfRanges(node, errorRanges);
|
|
243
|
-
guidance[locToString(node)] = createGuidance(
|
|
303
|
+
guidance[locToString(node)] = createGuidance({
|
|
304
|
+
iconPackage: legacyIconImports[node.name].packageName,
|
|
305
|
+
insideNewButton: true,
|
|
306
|
+
size: 'medium',
|
|
307
|
+
shouldUseMigrationPath: shouldUseMigrationPath
|
|
308
|
+
});
|
|
244
309
|
} else if (!newIcon && !upcomingIcon || !isNewIconMigratable) {
|
|
245
310
|
createCantFindSuitableReplacementError(node, legacyIconImports[node.name].packageName, node.name, errorsManual);
|
|
246
311
|
addToListOfRanges(node, errorRanges);
|
|
247
|
-
guidance[locToString(node)] = createGuidance(
|
|
312
|
+
guidance[locToString(node)] = createGuidance({
|
|
313
|
+
iconPackage: legacyIconImports[node.name].packageName,
|
|
314
|
+
insideNewButton: isInNewButton,
|
|
315
|
+
shouldUseMigrationPath: shouldUseMigrationPath
|
|
316
|
+
});
|
|
248
317
|
} else if (!isInNewButton) {
|
|
249
318
|
createCantMigrateFunctionUnknownError(node, legacyIconImports[node.name].packageName, node.name, errorsManual);
|
|
250
319
|
addToListOfRanges(node, errorRanges);
|
|
251
|
-
guidance[locToString(node)] = createGuidance(
|
|
320
|
+
guidance[locToString(node)] = createGuidance({
|
|
321
|
+
iconPackage: legacyIconImports[node.name].packageName,
|
|
322
|
+
insideNewButton: false,
|
|
323
|
+
shouldUseMigrationPath: shouldUseMigrationPath
|
|
324
|
+
});
|
|
252
325
|
}
|
|
253
326
|
}
|
|
254
327
|
};
|
|
255
328
|
var checkIconReference = function checkIconReference(node) {
|
|
256
|
-
//check the reference to see if it's a legacy icon, if not exit early
|
|
257
|
-
if (!Object.keys(legacyIconImports).includes(node.name)) {
|
|
258
|
-
return;
|
|
259
|
-
}
|
|
260
329
|
//if this is an import statement then exit early
|
|
261
330
|
if (node.parent && (isNodeOfType(node.parent, 'ImportSpecifier') || isNodeOfType(node.parent, 'ImportDefaultSpecifier'))) {
|
|
262
331
|
return;
|
|
263
332
|
}
|
|
333
|
+
|
|
334
|
+
// Flag icons imported from migration path
|
|
335
|
+
if (!shouldUseMigrationPath && Object.keys(migrationIconImports).includes(node.name)) {
|
|
336
|
+
createAutoMigrationError({
|
|
337
|
+
node: node,
|
|
338
|
+
importSource: migrationIconImports[node.name].packageName,
|
|
339
|
+
iconName: node.name,
|
|
340
|
+
errors: errorsAuto
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
//check the reference to see if it's a legacy icon, if not exit early
|
|
345
|
+
if (!Object.keys(legacyIconImports).includes(node.name)) {
|
|
346
|
+
return;
|
|
347
|
+
}
|
|
348
|
+
|
|
264
349
|
//if in Fallback prop, do not error
|
|
265
350
|
if (node.parent && node.parent.parent && isNodeOfType(node.parent.parent, 'JSXAttribute') && isNodeOfType(node.parent.parent.name, 'JSXIdentifier') && node.parent.parent.name.name === 'LEGACY_fallbackIcon') {
|
|
266
351
|
return;
|
|
@@ -284,15 +369,38 @@ export var createChecks = function createChecks(context) {
|
|
|
284
369
|
return;
|
|
285
370
|
}
|
|
286
371
|
var name = node.openingElement.name.name;
|
|
372
|
+
|
|
373
|
+
// Flag icons imported from migration path
|
|
374
|
+
if (!shouldUseMigrationPath && Object.keys(migrationIconImports).includes(name)) {
|
|
375
|
+
var _sizeProp$value;
|
|
376
|
+
var sizeProp = node.openingElement.attributes.find(function (attribute) {
|
|
377
|
+
return attribute.type === 'JSXAttribute' && (attribute.name.name === 'size' || attribute.name.name === 'LEGACY_size');
|
|
378
|
+
});
|
|
379
|
+
var insideNewButton = isInsideNewButton(node, newButtonImports);
|
|
380
|
+
// Add spacious spacing if:
|
|
381
|
+
// 1. size is medium, or not set (default is medium)
|
|
382
|
+
// 2. not inside a new or legacy button
|
|
383
|
+
var shouldAddSpaciousSpacing = (sizeProp && sizeProp.type === 'JSXAttribute' && ((_sizeProp$value = sizeProp.value) === null || _sizeProp$value === void 0 ? void 0 : _sizeProp$value.type) === 'Literal' && sizeProp.value.value === 'medium' || !sizeProp) && !isInsideNewButton(node, newButtonImports) && !isInsideLegacyButton(node, legacyButtonImports);
|
|
384
|
+
createAutoMigrationError({
|
|
385
|
+
node: node,
|
|
386
|
+
importSource: migrationIconImports[name].packageName,
|
|
387
|
+
iconName: name,
|
|
388
|
+
errors: errorsAuto,
|
|
389
|
+
shouldAddSpaciousSpacing: shouldAddSpaciousSpacing,
|
|
390
|
+
insideNewButton: insideNewButton
|
|
391
|
+
});
|
|
392
|
+
}
|
|
393
|
+
|
|
287
394
|
// Legacy icons rendered as JSX elements
|
|
288
395
|
if (Object.keys(legacyIconImports).includes(name)) {
|
|
289
|
-
var
|
|
396
|
+
var _size, _size2, _sizeProp$value2;
|
|
290
397
|
// Determine if inside a new button - if so:
|
|
291
398
|
// - Assume spread props are safe - still error if props explicitly set to unmigratable values
|
|
292
|
-
var
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
399
|
+
var _insideNewButton = isInsideNewButton(node, newButtonImports);
|
|
400
|
+
|
|
401
|
+
// Determine if inside a legacy default button - if so:
|
|
402
|
+
// the auto fixer will add spacing prop to the medium size icon
|
|
403
|
+
var insideLegacyButton = isInsideLegacyButton(node, legacyButtonImports);
|
|
296
404
|
|
|
297
405
|
// Find size prop on node
|
|
298
406
|
var size = 'medium';
|
|
@@ -301,11 +409,11 @@ export var createChecks = function createChecks(context) {
|
|
|
301
409
|
var requiredAttributesAfterSpread = new Set(['size', 'primaryColor', 'secondaryColor']);
|
|
302
410
|
var hasSpread = false;
|
|
303
411
|
var hasPrimaryColorProp = false;
|
|
304
|
-
var
|
|
305
|
-
|
|
412
|
+
var _iterator8 = _createForOfIteratorHelper(node.openingElement.attributes),
|
|
413
|
+
_step8;
|
|
306
414
|
try {
|
|
307
|
-
for (
|
|
308
|
-
var attr =
|
|
415
|
+
for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
|
|
416
|
+
var attr = _step8.value;
|
|
309
417
|
// Detect spread props
|
|
310
418
|
if (isNodeOfType(attr, 'JSXSpreadAttribute')) {
|
|
311
419
|
// In case there are more spread props
|
|
@@ -338,9 +446,9 @@ export var createChecks = function createChecks(context) {
|
|
|
338
446
|
}
|
|
339
447
|
}
|
|
340
448
|
} catch (err) {
|
|
341
|
-
|
|
449
|
+
_iterator8.e(err);
|
|
342
450
|
} finally {
|
|
343
|
-
|
|
451
|
+
_iterator8.f();
|
|
344
452
|
}
|
|
345
453
|
var hasManualMigration = false;
|
|
346
454
|
if (primaryColor && !canMigrateColor(primaryColor) || hasPrimaryColorProp && !primaryColor) {
|
|
@@ -357,7 +465,7 @@ export var createChecks = function createChecks(context) {
|
|
|
357
465
|
// Do a set comparison - is requiredAttributesAfterSpread a subset of afterSpreadSet?
|
|
358
466
|
if (hasSpread === true && !Array.from(requiredAttributesAfterSpread).every(function (val) {
|
|
359
467
|
return afterSpreadSet.has(val);
|
|
360
|
-
}) && !
|
|
468
|
+
}) && !_insideNewButton) {
|
|
361
469
|
var missingProps = Array.from(requiredAttributesAfterSpread).filter(function (val) {
|
|
362
470
|
return !afterSpreadSet.has(val);
|
|
363
471
|
});
|
|
@@ -373,13 +481,34 @@ export var createChecks = function createChecks(context) {
|
|
|
373
481
|
var upcomingIcon = getUpcomingIcons(legacyIconImports[name].packageName);
|
|
374
482
|
var newIcon = migrationMapObject === null || migrationMapObject === void 0 ? void 0 : migrationMapObject.newIcon;
|
|
375
483
|
var 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']);
|
|
484
|
+
|
|
485
|
+
// Add spacious spacing if:
|
|
486
|
+
// 1. size is medium, or not set (default is medium)
|
|
487
|
+
// 2. not inside a new or legacy button
|
|
488
|
+
var _sizeProp = node.openingElement.attributes.find(function (attribute) {
|
|
489
|
+
return attribute.type === 'JSXAttribute' && (attribute.name.name === 'size' || attribute.name.name === 'LEGACY_size');
|
|
490
|
+
});
|
|
491
|
+
var _shouldAddSpaciousSpacing = (_sizeProp && _sizeProp.type === 'JSXAttribute' && ((_sizeProp$value2 = _sizeProp.value) === null || _sizeProp$value2 === void 0 ? void 0 : _sizeProp$value2.type) === 'Literal' && _sizeProp.value.value === 'medium' || !_sizeProp) && !_insideNewButton && !insideLegacyButton;
|
|
376
492
|
if (!hasManualMigration && (newIcon || upcomingIcon) && isNewIconMigratable) {
|
|
377
|
-
|
|
493
|
+
autoIconJSXElementOccurrenceCount++;
|
|
494
|
+
createAutoMigrationError({
|
|
495
|
+
node: node,
|
|
496
|
+
importSource: legacyIconImports[name].packageName,
|
|
497
|
+
iconName: name,
|
|
498
|
+
errors: errorsAuto,
|
|
499
|
+
shouldAddSpaciousSpacing: _shouldAddSpaciousSpacing,
|
|
500
|
+
insideNewButton: _insideNewButton
|
|
501
|
+
});
|
|
378
502
|
} else if ((!newIcon && !upcomingIcon || !isNewIconMigratable) && size) {
|
|
379
503
|
createCantFindSuitableReplacementError(node, legacyIconImports[name].packageName, name, errorsManual, upcomingIcon ? true : migrationMapObject ? true : false);
|
|
380
504
|
}
|
|
381
505
|
addToListOfRanges(node, errorRanges);
|
|
382
|
-
guidance[locToString(node)] = createGuidance(
|
|
506
|
+
guidance[locToString(node)] = createGuidance({
|
|
507
|
+
iconPackage: legacyIconImports[name].packageName,
|
|
508
|
+
insideNewButton: _insideNewButton,
|
|
509
|
+
size: size && isSize(size) ? size : undefined,
|
|
510
|
+
shouldUseMigrationPath: shouldUseMigrationPath
|
|
511
|
+
});
|
|
383
512
|
}
|
|
384
513
|
};
|
|
385
514
|
|
|
@@ -389,21 +518,24 @@ export var createChecks = function createChecks(context) {
|
|
|
389
518
|
*/
|
|
390
519
|
var checkCallExpression = function checkCallExpression(node) {
|
|
391
520
|
if (Object.keys(node).includes('arguments') && node.arguments.length) {
|
|
392
|
-
var
|
|
393
|
-
|
|
521
|
+
var _iterator9 = _createForOfIteratorHelper(node.arguments),
|
|
522
|
+
_step9;
|
|
394
523
|
try {
|
|
395
|
-
for (
|
|
396
|
-
var arg =
|
|
524
|
+
for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
|
|
525
|
+
var arg = _step9.value;
|
|
397
526
|
if (isNodeOfType(arg, 'Identifier') && Object.keys(legacyIconImports).includes(arg.name) && legacyIconImports[arg.name].packageName) {
|
|
398
527
|
createCantMigrateFunctionUnknownError(node, legacyIconImports[arg.name].packageName, arg.name, errorsManual);
|
|
399
528
|
addToListOfRanges(node, errorRanges);
|
|
400
|
-
guidance[locToString(node)] = createGuidance(
|
|
529
|
+
guidance[locToString(node)] = createGuidance({
|
|
530
|
+
iconPackage: legacyIconImports[arg.name].packageName,
|
|
531
|
+
shouldUseMigrationPath: shouldUseMigrationPath
|
|
532
|
+
});
|
|
401
533
|
}
|
|
402
534
|
}
|
|
403
535
|
} catch (err) {
|
|
404
|
-
|
|
536
|
+
_iterator9.e(err);
|
|
405
537
|
} finally {
|
|
406
|
-
|
|
538
|
+
_iterator9.f();
|
|
407
539
|
}
|
|
408
540
|
}
|
|
409
541
|
};
|
|
@@ -438,19 +570,19 @@ export var createChecks = function createChecks(context) {
|
|
|
438
570
|
}
|
|
439
571
|
});
|
|
440
572
|
if (!isQuietMode) {
|
|
441
|
-
var
|
|
442
|
-
|
|
573
|
+
var _iterator10 = _createForOfIteratorHelper(errorList.errors),
|
|
574
|
+
_step10;
|
|
443
575
|
try {
|
|
444
|
-
for (
|
|
445
|
-
var error =
|
|
576
|
+
for (_iterator10.s(); !(_step10 = _iterator10.n()).done;) {
|
|
577
|
+
var error = _step10.value;
|
|
446
578
|
if ('messageId' in error && (error.messageId !== 'cantMigrateIdentifier' || error.messageId === 'cantMigrateIdentifier' && !isInRange)) {
|
|
447
579
|
context.report(error);
|
|
448
580
|
}
|
|
449
581
|
}
|
|
450
582
|
} catch (err) {
|
|
451
|
-
|
|
583
|
+
_iterator10.e(err);
|
|
452
584
|
} finally {
|
|
453
|
-
|
|
585
|
+
_iterator10.f();
|
|
454
586
|
}
|
|
455
587
|
}
|
|
456
588
|
}
|
|
@@ -458,28 +590,84 @@ export var createChecks = function createChecks(context) {
|
|
|
458
590
|
}
|
|
459
591
|
}
|
|
460
592
|
if (shouldErrorForAutoMigration) {
|
|
461
|
-
|
|
593
|
+
var _loop = function _loop() {
|
|
462
594
|
var _Object$entries2$_i = _slicedToArray(_Object$entries2[_i2], 2),
|
|
463
|
-
|
|
464
|
-
|
|
595
|
+
key = _Object$entries2$_i[0],
|
|
596
|
+
error = _Object$entries2$_i[1];
|
|
465
597
|
// If there's a manual error that exists for this same component,
|
|
466
598
|
// don't throw the auto error
|
|
467
|
-
if (Object.keys(errorsManual).includes(
|
|
468
|
-
var _cantMigrateIdentifierError = errorsManual[
|
|
599
|
+
if (Object.keys(errorsManual).includes(key)) {
|
|
600
|
+
var _cantMigrateIdentifierError = errorsManual[key].errors.find(function (x) {
|
|
469
601
|
return 'messageId' in x && x.messageId === 'cantMigrateIdentifier';
|
|
470
602
|
});
|
|
471
|
-
if (!_cantMigrateIdentifierError || _cantMigrateIdentifierError && errorsManual[
|
|
472
|
-
delete errorsAuto[
|
|
473
|
-
continue
|
|
603
|
+
if (!_cantMigrateIdentifierError || _cantMigrateIdentifierError && errorsManual[key].errors.length > 1) {
|
|
604
|
+
delete errorsAuto[key];
|
|
605
|
+
return 1; // continue
|
|
474
606
|
}
|
|
475
607
|
}
|
|
476
|
-
var
|
|
477
|
-
if (
|
|
478
|
-
var _guidanceMessage = Object.keys(guidance).includes(
|
|
479
|
-
if (Object.keys(
|
|
480
|
-
|
|
608
|
+
var node = 'node' in error ? error.node : null;
|
|
609
|
+
if (node) {
|
|
610
|
+
var _guidanceMessage = Object.keys(guidance).includes(key) ? guidance[key] : '';
|
|
611
|
+
if (Object.keys(error).includes('data') && error.data) {
|
|
612
|
+
error.data.guidance = _guidanceMessage;
|
|
481
613
|
}
|
|
482
|
-
context.report(
|
|
614
|
+
context.report(_objectSpread(_objectSpread({}, error), {}, {
|
|
615
|
+
fix: function fix(fixer) {
|
|
616
|
+
var _legacyIconImports$er, _migrationIconImports;
|
|
617
|
+
// don't migration if the new icon is not available
|
|
618
|
+
if (!error.data || shouldUseMigrationPath && !checkIfNewIconExist(error)) {
|
|
619
|
+
return [];
|
|
620
|
+
}
|
|
621
|
+
var fixArguments = {
|
|
622
|
+
metadata: error.data,
|
|
623
|
+
legacyImportNode: (_legacyIconImports$er = legacyIconImports[error.data.iconName]) === null || _legacyIconImports$er === void 0 ? void 0 : _legacyIconImports$er.importNode,
|
|
624
|
+
migrationImportNode: (_migrationIconImports = migrationIconImports[error.data.iconName]) === null || _migrationIconImports === void 0 ? void 0 : _migrationIconImports.importNode,
|
|
625
|
+
shouldUseMigrationPath: shouldUseMigrationPath
|
|
626
|
+
};
|
|
627
|
+
var propsFixes = createPropFixes(_objectSpread(_objectSpread({}, fixArguments), {}, {
|
|
628
|
+
node: node,
|
|
629
|
+
fixer: fixer
|
|
630
|
+
}));
|
|
631
|
+
var importFixes = [];
|
|
632
|
+
// Otherwise if there are multiple occurrences of the icon, import path will be handled after the prop fix
|
|
633
|
+
if (autoIconJSXElementOccurrenceCount <= 1) {
|
|
634
|
+
importFixes = createImportFix(_objectSpread(_objectSpread({}, fixArguments), {}, {
|
|
635
|
+
fixer: fixer
|
|
636
|
+
}));
|
|
637
|
+
}
|
|
638
|
+
return [].concat(_toConsumableArray(propsFixes), _toConsumableArray(importFixes));
|
|
639
|
+
}
|
|
640
|
+
}));
|
|
641
|
+
}
|
|
642
|
+
};
|
|
643
|
+
for (var _i2 = 0, _Object$entries2 = Object.entries(errorsAuto); _i2 < _Object$entries2.length; _i2++) {
|
|
644
|
+
if (_loop()) continue;
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
// Update import path at the end if there are multiple occurrences of the icon
|
|
648
|
+
if (autoIconJSXElementOccurrenceCount > 1) {
|
|
649
|
+
var _loop2 = function _loop2() {
|
|
650
|
+
var _Object$entries3$_i = _slicedToArray(_Object$entries3[_i3], 2),
|
|
651
|
+
_ = _Object$entries3$_i[0],
|
|
652
|
+
error = _Object$entries3$_i[1];
|
|
653
|
+
context.report(_objectSpread(_objectSpread({}, error), {}, {
|
|
654
|
+
fix: function fix(fixer) {
|
|
655
|
+
var _legacyIconImports$er2, _migrationIconImports2;
|
|
656
|
+
if (!error.data || shouldUseMigrationPath && !checkIfNewIconExist(error)) {
|
|
657
|
+
return [];
|
|
658
|
+
}
|
|
659
|
+
return createImportFix({
|
|
660
|
+
metadata: error.data,
|
|
661
|
+
fixer: fixer,
|
|
662
|
+
legacyImportNode: (_legacyIconImports$er2 = legacyIconImports[error.data.iconName]) === null || _legacyIconImports$er2 === void 0 ? void 0 : _legacyIconImports$er2.importNode,
|
|
663
|
+
migrationImportNode: (_migrationIconImports2 = migrationIconImports[error.data.iconName]) === null || _migrationIconImports2 === void 0 ? void 0 : _migrationIconImports2.importNode,
|
|
664
|
+
shouldUseMigrationPath: shouldUseMigrationPath
|
|
665
|
+
});
|
|
666
|
+
}
|
|
667
|
+
}));
|
|
668
|
+
};
|
|
669
|
+
for (var _i3 = 0, _Object$entries3 = Object.entries(errorsAuto); _i3 < _Object$entries3.length; _i3++) {
|
|
670
|
+
_loop2();
|
|
483
671
|
}
|
|
484
672
|
}
|
|
485
673
|
}
|