@atlaskit/eslint-plugin-design-system 10.12.3 → 10.12.5
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 +16 -0
- package/dist/cjs/rules/no-legacy-icons/checks.js +100 -52
- package/dist/cjs/rules/no-legacy-icons/helpers.js +95 -22
- package/dist/cjs/rules/no-legacy-icons/index.js +5 -3
- package/dist/cjs/rules/no-legacy-icons/upcoming-icons.js +7 -0
- package/dist/es2019/rules/no-legacy-icons/checks.js +85 -41
- package/dist/es2019/rules/no-legacy-icons/helpers.js +80 -10
- package/dist/es2019/rules/no-legacy-icons/index.js +5 -3
- package/dist/es2019/rules/no-legacy-icons/upcoming-icons.js +1 -0
- package/dist/esm/rules/no-legacy-icons/checks.js +101 -53
- package/dist/esm/rules/no-legacy-icons/helpers.js +94 -21
- package/dist/esm/rules/no-legacy-icons/index.js +5 -3
- package/dist/esm/rules/no-legacy-icons/upcoming-icons.js +1 -0
- package/dist/types/rules/no-legacy-icons/checks.d.ts +4 -1
- package/dist/types/rules/no-legacy-icons/helpers.d.ts +25 -14
- package/dist/types/rules/no-legacy-icons/upcoming-icons.d.ts +1 -0
- package/dist/types-ts4.5/rules/no-legacy-icons/checks.d.ts +4 -1
- package/dist/types-ts4.5/rules/no-legacy-icons/helpers.d.ts +25 -14
- package/dist/types-ts4.5/rules/no-legacy-icons/upcoming-icons.d.ts +1 -0
- package/package.json +1 -1
|
@@ -3,7 +3,7 @@ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol
|
|
|
3
3
|
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
4
|
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
5
|
import { isNodeOfType } from 'eslint-codemod-utils';
|
|
6
|
-
import { canAutoMigrateNewIconBasedOnSize, canMigrateColor, createAutoMigrationError, createCantFindSuitableReplacementError, createCantMigrateColorError, createCantMigrateFunctionUnknownError, createCantMigrateIdentifierError, createCantMigrateReExportError, createCantMigrateSizeUnknown, createCantMigrateSpreadPropsError, createGuidance, createHelpers, getMigrationMapObject, isSize, locToString } from './helpers';
|
|
6
|
+
import { addToListOfRanges, canAutoMigrateNewIconBasedOnSize, canMigrateColor, createAutoMigrationError, createCantFindSuitableReplacementError, createCantMigrateColorError, createCantMigrateFunctionUnknownError, createCantMigrateIdentifierError, createCantMigrateIdentifierMapOrArrayError, createCantMigrateReExportError, createCantMigrateSizeUnknown, createCantMigrateSpreadPropsError, createGuidance, createHelpers, getMigrationMapObject, getUpcomingIcons, isInRangeList, isSize, locToString } from './helpers';
|
|
7
7
|
export var createChecks = function createChecks(context) {
|
|
8
8
|
//create global variables to be shared by the checks
|
|
9
9
|
var _createHelpers = createHelpers(context),
|
|
@@ -20,6 +20,9 @@ export var createChecks = function createChecks(context) {
|
|
|
20
20
|
var shouldErrorForAutoMigration = getConfigFlag('shouldErrorForAutoMigration', true);
|
|
21
21
|
var isQuietMode = getConfigFlag('quiet', false);
|
|
22
22
|
|
|
23
|
+
// Sorted list of ranges
|
|
24
|
+
var errorRanges = [];
|
|
25
|
+
|
|
23
26
|
/**
|
|
24
27
|
* Adds the legacy Icon and new button imports to the correct global arrays to be used by the other checks
|
|
25
28
|
* @param node The import node found by ESLint
|
|
@@ -83,8 +86,8 @@ export var createChecks = function createChecks(context) {
|
|
|
83
86
|
try {
|
|
84
87
|
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
85
88
|
var decl = _step3.value;
|
|
86
|
-
if (isNodeOfType(decl, 'VariableDeclarator') && 'init'
|
|
87
|
-
if (decl.init.name
|
|
89
|
+
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
|
+
if (Object.keys(legacyIconImports).includes(decl.init.name)) {
|
|
88
91
|
legacyIconImports[decl.id.name] = {
|
|
89
92
|
packageName: legacyIconImports[decl.init.name].packageName,
|
|
90
93
|
exported: legacyIconImports[decl.init.name].exported || isExported
|
|
@@ -109,16 +112,17 @@ export var createChecks = function createChecks(context) {
|
|
|
109
112
|
var checkExportDefaultDeclaration = function checkExportDefaultDeclaration(node) {
|
|
110
113
|
var exportName = '';
|
|
111
114
|
var packageName = '';
|
|
112
|
-
if ('declaration'
|
|
115
|
+
if (Object.keys(node).includes('declaration') && node.declaration && isNodeOfType(node.declaration, 'Identifier') && Object.keys(legacyIconImports).includes(node.declaration.name)) {
|
|
113
116
|
packageName = legacyIconImports[node.declaration.name].packageName;
|
|
114
117
|
exportName = 'Default export';
|
|
115
|
-
} else if ('declaration'
|
|
118
|
+
} 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)) {
|
|
116
119
|
packageName = legacyIconImports[node.declaration.right.name].packageName;
|
|
117
120
|
exportName = node.declaration.left.name;
|
|
118
121
|
} else {
|
|
119
122
|
return;
|
|
120
123
|
}
|
|
121
124
|
createCantMigrateReExportError(node, packageName, exportName, errorsManual);
|
|
125
|
+
addToListOfRanges(node, errorRanges);
|
|
122
126
|
guidance[locToString(node)] = createGuidance(packageName);
|
|
123
127
|
};
|
|
124
128
|
|
|
@@ -128,7 +132,7 @@ export var createChecks = function createChecks(context) {
|
|
|
128
132
|
*/
|
|
129
133
|
var checkExportNamedVariables = function checkExportNamedVariables(node) {
|
|
130
134
|
// export {default as AddIcon} from '@atlaskit/icon/glyph/add';
|
|
131
|
-
if (node.source && isNodeOfType(node.source, 'Literal') &&
|
|
135
|
+
if (node.source && isNodeOfType(node.source, 'Literal') && Object.keys(node.source).includes('value')) {
|
|
132
136
|
var moduleSource = node.source.value;
|
|
133
137
|
if (typeof moduleSource === 'string' && ['@atlaskit/icon/glyph/', '@atlaskit/icon-object/glyph/'].find(function (val) {
|
|
134
138
|
return moduleSource.startsWith(val);
|
|
@@ -139,6 +143,7 @@ export var createChecks = function createChecks(context) {
|
|
|
139
143
|
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
140
144
|
var spec = _step4.value;
|
|
141
145
|
createCantMigrateReExportError(spec, moduleSource, spec.exported.name, errorsManual);
|
|
146
|
+
addToListOfRanges(spec, errorRanges);
|
|
142
147
|
guidance[locToString(spec)] = createGuidance(moduleSource);
|
|
143
148
|
}
|
|
144
149
|
} catch (err) {
|
|
@@ -154,8 +159,9 @@ export var createChecks = function createChecks(context) {
|
|
|
154
159
|
try {
|
|
155
160
|
for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
|
|
156
161
|
var decl = _step5.value;
|
|
157
|
-
if (isNodeOfType(decl, 'VariableDeclarator') && 'init'
|
|
162
|
+
if (isNodeOfType(decl, 'VariableDeclarator') && Object.keys(decl).includes('init') && decl.init && isNodeOfType(decl.init, 'Identifier') && Object.keys(legacyIconImports).includes(decl.init.name)) {
|
|
158
163
|
createCantMigrateReExportError(node, legacyIconImports[decl.init.name].packageName, decl.init.name, errorsManual);
|
|
164
|
+
addToListOfRanges(node, errorRanges);
|
|
159
165
|
guidance[locToString(node)] = createGuidance(legacyIconImports[decl.init.name].packageName);
|
|
160
166
|
}
|
|
161
167
|
}
|
|
@@ -176,13 +182,14 @@ export var createChecks = function createChecks(context) {
|
|
|
176
182
|
try {
|
|
177
183
|
for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
|
|
178
184
|
var _spec2 = _step6.value;
|
|
179
|
-
if (_spec2.local.name
|
|
185
|
+
if (Object.keys(legacyIconImports).includes(_spec2.local.name)) {
|
|
180
186
|
//update legacy imports to be exported
|
|
181
187
|
legacyIconImports[_spec2.local.name] = {
|
|
182
188
|
packageName: legacyIconImports[_spec2.local.name].packageName,
|
|
183
189
|
exported: true
|
|
184
190
|
};
|
|
185
191
|
createCantMigrateReExportError(_spec2, legacyIconImports[_spec2.local.name].packageName, _spec2.exported.name, errorsManual);
|
|
192
|
+
addToListOfRanges(_spec2, errorRanges);
|
|
186
193
|
guidance[locToString(_spec2)] = createGuidance(legacyIconImports[_spec2.local.name].packageName);
|
|
187
194
|
}
|
|
188
195
|
}
|
|
@@ -202,8 +209,9 @@ export var createChecks = function createChecks(context) {
|
|
|
202
209
|
if (!isNodeOfType(node, 'Identifier')) {
|
|
203
210
|
return;
|
|
204
211
|
}
|
|
205
|
-
if (node.name && node.name
|
|
206
|
-
|
|
212
|
+
if (node.name && Object.keys(legacyIconImports).includes(node.name) && legacyIconImports[node.name].packageName) {
|
|
213
|
+
createCantMigrateIdentifierMapOrArrayError(node, legacyIconImports[node.name].packageName, node.name, errorsManual);
|
|
214
|
+
addToListOfRanges(node, errorRanges);
|
|
207
215
|
guidance[locToString(node)] = createGuidance(legacyIconImports[node.name].packageName);
|
|
208
216
|
}
|
|
209
217
|
};
|
|
@@ -222,24 +230,44 @@ export var createChecks = function createChecks(context) {
|
|
|
222
230
|
if (!isNodeOfType(node.parent, 'JSXExpressionContainer') || !isNodeOfType(node.parent.parent, 'JSXAttribute') || !isNodeOfType(node.parent.parent.parent, 'JSXOpeningElement')) {
|
|
223
231
|
return;
|
|
224
232
|
}
|
|
225
|
-
if (node.name
|
|
233
|
+
if (Object.keys(legacyIconImports).includes(node.name) && isNodeOfType(node.parent.parent.name, 'JSXIdentifier') && node.parent.parent.name.name !== 'LEGACY_fallbackIcon') {
|
|
226
234
|
var _migrationMapObject$s;
|
|
227
235
|
var migrationMapObject = getMigrationMapObject(legacyIconImports[node.name].packageName);
|
|
236
|
+
var upcomingIcon = getUpcomingIcons(legacyIconImports[node.name].packageName);
|
|
228
237
|
var newIcon = migrationMapObject === null || migrationMapObject === void 0 ? void 0 : migrationMapObject.newIcon;
|
|
229
|
-
var isNewIconMigratable = canAutoMigrateNewIconBasedOnSize(migrationMapObject === null || migrationMapObject === void 0 || (_migrationMapObject$s = migrationMapObject.sizeGuidance) === null || _migrationMapObject$s === void 0 ? void 0 : _migrationMapObject$s.medium);
|
|
238
|
+
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);
|
|
230
239
|
var isInNewButton = isNodeOfType(node.parent.parent.parent.name, 'JSXIdentifier') && newButtonImports.has(node.parent.parent.parent.name.name);
|
|
231
|
-
if (newIcon && isInNewButton && isNewIconMigratable) {
|
|
240
|
+
if (newIcon && isInNewButton && isNewIconMigratable || upcomingIcon && isInNewButton && isNewIconMigratable) {
|
|
232
241
|
createAutoMigrationError(node, legacyIconImports[node.name].packageName, node.name, errorsAuto);
|
|
242
|
+
addToListOfRanges(node, errorRanges);
|
|
233
243
|
guidance[locToString(node)] = createGuidance(legacyIconImports[node.name].packageName, isInNewButton, 'medium');
|
|
234
|
-
} else if (!newIcon || !isNewIconMigratable) {
|
|
244
|
+
} else if (!newIcon && !upcomingIcon || !isNewIconMigratable) {
|
|
235
245
|
createCantFindSuitableReplacementError(node, legacyIconImports[node.name].packageName, node.name, errorsManual);
|
|
246
|
+
addToListOfRanges(node, errorRanges);
|
|
236
247
|
guidance[locToString(node)] = createGuidance(legacyIconImports[node.name].packageName, isInNewButton);
|
|
237
248
|
} else if (!isInNewButton) {
|
|
238
249
|
createCantMigrateFunctionUnknownError(node, legacyIconImports[node.name].packageName, node.name, errorsManual);
|
|
250
|
+
addToListOfRanges(node, errorRanges);
|
|
239
251
|
guidance[locToString(node)] = createGuidance(legacyIconImports[node.name].packageName, isInNewButton);
|
|
240
252
|
}
|
|
241
253
|
}
|
|
242
254
|
};
|
|
255
|
+
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
|
+
//if this is an import statement then exit early
|
|
261
|
+
if (node.parent && (isNodeOfType(node.parent, 'ImportSpecifier') || isNodeOfType(node.parent, 'ImportDefaultSpecifier'))) {
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
//if in Fallback prop, do not error
|
|
265
|
+
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
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
// manually error
|
|
269
|
+
createCantMigrateIdentifierError(node, legacyIconImports[node.name].packageName, node.name, errorsManual);
|
|
270
|
+
};
|
|
243
271
|
|
|
244
272
|
/**
|
|
245
273
|
* Checks if a legacy icon is being rendered and stores the errors in the global array
|
|
@@ -257,8 +285,8 @@ export var createChecks = function createChecks(context) {
|
|
|
257
285
|
}
|
|
258
286
|
var name = node.openingElement.name.name;
|
|
259
287
|
// Legacy icons rendered as JSX elements
|
|
260
|
-
if (
|
|
261
|
-
var _node$parent2, _node$parent3, _size;
|
|
288
|
+
if (Object.keys(legacyIconImports).includes(name)) {
|
|
289
|
+
var _node$parent2, _node$parent3, _size, _size2;
|
|
262
290
|
// Determine if inside a new button - if so:
|
|
263
291
|
// - Assume spread props are safe - still error if props explicitly set to unmigratable values
|
|
264
292
|
var insideNewButton = false;
|
|
@@ -342,13 +370,15 @@ export var createChecks = function createChecks(context) {
|
|
|
342
370
|
hasManualMigration = true;
|
|
343
371
|
}
|
|
344
372
|
var migrationMapObject = getMigrationMapObject(legacyIconImports[name].packageName);
|
|
373
|
+
var upcomingIcon = getUpcomingIcons(legacyIconImports[name].packageName);
|
|
345
374
|
var newIcon = migrationMapObject === null || migrationMapObject === void 0 ? void 0 : migrationMapObject.newIcon;
|
|
346
|
-
var isNewIconMigratable = canAutoMigrateNewIconBasedOnSize(migrationMapObject === null || migrationMapObject === void 0 ? void 0 : migrationMapObject.sizeGuidance[(
|
|
347
|
-
if (!hasManualMigration && newIcon && isNewIconMigratable) {
|
|
375
|
+
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']);
|
|
376
|
+
if (!hasManualMigration && (newIcon || upcomingIcon) && isNewIconMigratable) {
|
|
348
377
|
createAutoMigrationError(node, legacyIconImports[name].packageName, name, errorsAuto);
|
|
349
|
-
} else if ((!newIcon || !isNewIconMigratable) && size) {
|
|
350
|
-
createCantFindSuitableReplacementError(node, legacyIconImports[name].packageName, name, errorsManual, migrationMapObject ? true : false);
|
|
378
|
+
} else if ((!newIcon && !upcomingIcon || !isNewIconMigratable) && size) {
|
|
379
|
+
createCantFindSuitableReplacementError(node, legacyIconImports[name].packageName, name, errorsManual, upcomingIcon ? true : migrationMapObject ? true : false);
|
|
351
380
|
}
|
|
381
|
+
addToListOfRanges(node, errorRanges);
|
|
352
382
|
guidance[locToString(node)] = createGuidance(legacyIconImports[name].packageName, insideNewButton, size && isSize(size) ? size : undefined);
|
|
353
383
|
}
|
|
354
384
|
};
|
|
@@ -358,14 +388,15 @@ export var createChecks = function createChecks(context) {
|
|
|
358
388
|
* @param node The function call node found by ESLint
|
|
359
389
|
*/
|
|
360
390
|
var checkCallExpression = function checkCallExpression(node) {
|
|
361
|
-
if ('arguments'
|
|
391
|
+
if (Object.keys(node).includes('arguments') && node.arguments.length) {
|
|
362
392
|
var _iterator8 = _createForOfIteratorHelper(node.arguments),
|
|
363
393
|
_step8;
|
|
364
394
|
try {
|
|
365
395
|
for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
|
|
366
396
|
var arg = _step8.value;
|
|
367
|
-
if (isNodeOfType(arg, 'Identifier') && arg.name
|
|
397
|
+
if (isNodeOfType(arg, 'Identifier') && Object.keys(legacyIconImports).includes(arg.name) && legacyIconImports[arg.name].packageName) {
|
|
368
398
|
createCantMigrateFunctionUnknownError(node, legacyIconImports[arg.name].packageName, arg.name, errorsManual);
|
|
399
|
+
addToListOfRanges(node, errorRanges);
|
|
369
400
|
guidance[locToString(node)] = createGuidance(legacyIconImports[arg.name].packageName);
|
|
370
401
|
}
|
|
371
402
|
}
|
|
@@ -386,30 +417,41 @@ export var createChecks = function createChecks(context) {
|
|
|
386
417
|
var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
|
|
387
418
|
_key = _Object$entries$_i[0],
|
|
388
419
|
errorList = _Object$entries$_i[1];
|
|
389
|
-
var
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
420
|
+
var _node = 'node' in errorList.errors[0] ? errorList.errors[0].node : null;
|
|
421
|
+
var cantMigrateIdentifierError = errorList.errors.find(function (x) {
|
|
422
|
+
return 'messageId' in x && x.messageId === 'cantMigrateIdentifier';
|
|
423
|
+
});
|
|
424
|
+
if (_node) {
|
|
425
|
+
var isInRange = false;
|
|
426
|
+
if (cantMigrateIdentifierError && isInRangeList(_node, errorRanges)) {
|
|
427
|
+
isInRange = true;
|
|
428
|
+
}
|
|
429
|
+
if (isInRange && errorList.errors.length - 1 > 0 || !isInRange && errorList.errors.length > 0) {
|
|
430
|
+
var guidanceMessage = Object.keys(guidance).includes(_key) ? guidance[_key] : '';
|
|
431
|
+
context.report({
|
|
432
|
+
node: _node,
|
|
433
|
+
messageId: 'noLegacyIconsManualMigration',
|
|
434
|
+
data: {
|
|
435
|
+
iconName: errorList.iconName,
|
|
436
|
+
importSource: errorList.importSource,
|
|
437
|
+
guidance: isQuietMode ? guidanceMessage : "".concat(guidanceMessage, "For more information see the below errors.\n")
|
|
438
|
+
}
|
|
439
|
+
});
|
|
440
|
+
if (!isQuietMode) {
|
|
441
|
+
var _iterator9 = _createForOfIteratorHelper(errorList.errors),
|
|
442
|
+
_step9;
|
|
443
|
+
try {
|
|
444
|
+
for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
|
|
445
|
+
var error = _step9.value;
|
|
446
|
+
if ('messageId' in error && (error.messageId !== 'cantMigrateIdentifier' || error.messageId === 'cantMigrateIdentifier' && !isInRange)) {
|
|
447
|
+
context.report(error);
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
} catch (err) {
|
|
451
|
+
_iterator9.e(err);
|
|
452
|
+
} finally {
|
|
453
|
+
_iterator9.f();
|
|
408
454
|
}
|
|
409
|
-
} catch (err) {
|
|
410
|
-
_iterator9.e(err);
|
|
411
|
-
} finally {
|
|
412
|
-
_iterator9.f();
|
|
413
455
|
}
|
|
414
456
|
}
|
|
415
457
|
}
|
|
@@ -422,14 +464,19 @@ export var createChecks = function createChecks(context) {
|
|
|
422
464
|
_error = _Object$entries2$_i[1];
|
|
423
465
|
// If there's a manual error that exists for this same component,
|
|
424
466
|
// don't throw the auto error
|
|
425
|
-
if (
|
|
426
|
-
|
|
427
|
-
|
|
467
|
+
if (Object.keys(errorsManual).includes(_key2)) {
|
|
468
|
+
var _cantMigrateIdentifierError = errorsManual[_key2].errors.find(function (x) {
|
|
469
|
+
return 'messageId' in x && x.messageId === 'cantMigrateIdentifier';
|
|
470
|
+
});
|
|
471
|
+
if (!_cantMigrateIdentifierError || _cantMigrateIdentifierError && errorsManual[_key2].errors.length > 1) {
|
|
472
|
+
delete errorsAuto[_key2];
|
|
473
|
+
continue;
|
|
474
|
+
}
|
|
428
475
|
}
|
|
429
|
-
var
|
|
430
|
-
if (
|
|
431
|
-
var _guidanceMessage = _key2
|
|
432
|
-
if ('data'
|
|
476
|
+
var _node2 = 'node' in _error ? _error.node : null;
|
|
477
|
+
if (_node2) {
|
|
478
|
+
var _guidanceMessage = Object.keys(guidance).includes(_key2) ? guidance[_key2] : '';
|
|
479
|
+
if (Object.keys(_error).includes('data') && _error.data) {
|
|
433
480
|
_error.data.guidance = _guidanceMessage;
|
|
434
481
|
}
|
|
435
482
|
context.report(_error);
|
|
@@ -446,6 +493,7 @@ export var createChecks = function createChecks(context) {
|
|
|
446
493
|
checkIconAsProp: checkIconAsProp,
|
|
447
494
|
checkJSXElement: checkJSXElement,
|
|
448
495
|
checkCallExpression: checkCallExpression,
|
|
449
|
-
throwErrors: throwErrors
|
|
496
|
+
throwErrors: throwErrors,
|
|
497
|
+
checkIconReference: checkIconReference
|
|
450
498
|
};
|
|
451
499
|
};
|
|
@@ -2,6 +2,7 @@ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
|
2
2
|
import { isNodeOfType } from 'eslint-codemod-utils';
|
|
3
3
|
import baseMigrationMap, { migrationOutcomeDescriptionMap } from '@atlaskit/icon/UNSAFE_migration-map';
|
|
4
4
|
import { getImportName } from '../utils/get-import-name';
|
|
5
|
+
import { upcomingIcons } from './upcoming-icons';
|
|
5
6
|
var sizes = ['small', 'medium', 'large', 'xlarge'];
|
|
6
7
|
export var isSize = function isSize(size) {
|
|
7
8
|
return sizes.includes(size);
|
|
@@ -14,11 +15,26 @@ export var isSize = function isSize(size) {
|
|
|
14
15
|
*/
|
|
15
16
|
export var getMigrationMapObject = function getMigrationMapObject(iconPackage) {
|
|
16
17
|
var key = getIconKey(iconPackage);
|
|
17
|
-
if (
|
|
18
|
+
if (Object.keys(baseMigrationMap).includes(key)) {
|
|
18
19
|
return baseMigrationMap[key];
|
|
19
20
|
}
|
|
20
21
|
return null;
|
|
21
22
|
};
|
|
23
|
+
export var getUpcomingIcons = function getUpcomingIcons(iconPackage) {
|
|
24
|
+
var key = getIconKey(iconPackage);
|
|
25
|
+
if (upcomingIcons.includes(key)) {
|
|
26
|
+
var retval = {
|
|
27
|
+
sizeGuidance: {
|
|
28
|
+
small: 'swap',
|
|
29
|
+
medium: 'swap',
|
|
30
|
+
large: 'icon-tile',
|
|
31
|
+
xlarge: 'icon-tile'
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
return retval;
|
|
35
|
+
}
|
|
36
|
+
return null;
|
|
37
|
+
};
|
|
22
38
|
|
|
23
39
|
/**
|
|
24
40
|
* Returns the key of a legacy icon
|
|
@@ -44,42 +60,67 @@ export var createGuidance = function createGuidance(iconPackage) {
|
|
|
44
60
|
var insideNewButton = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
45
61
|
var size = arguments.length > 2 ? arguments[2] : undefined;
|
|
46
62
|
var migrationMapObject = getMigrationMapObject(iconPackage);
|
|
47
|
-
|
|
63
|
+
var upcomingIcon = getUpcomingIcons(iconPackage);
|
|
64
|
+
if (upcomingIcon) {
|
|
65
|
+
var guidance = '';
|
|
66
|
+
if (size) {
|
|
67
|
+
if (upcomingIcon.sizeGuidance[size] && canAutoMigrateNewIconBasedOnSize(upcomingIcon.sizeGuidance[size])) {
|
|
68
|
+
guidance += "Fix: An upcoming icon release is planned to migrate this legacy icon.";
|
|
69
|
+
} else {
|
|
70
|
+
guidance += "No equivalent icon for this size, ".concat(size, ", in the current or upcoming set of icons.");
|
|
71
|
+
}
|
|
72
|
+
guidance += "".concat(Object.keys(migrationOutcomeDescriptionMap).includes(upcomingIcon.sizeGuidance[size]) ? " Once the upcoming icons are released, please: ".concat(migrationOutcomeDescriptionMap[upcomingIcon.sizeGuidance[size]]) : ' No migration size advice given.', "\n");
|
|
73
|
+
} else {
|
|
74
|
+
guidance = "Please wait for the upcoming icons released, as it will contain an alternative for this legacy icon.\nMigration suggestions, depending on the legacy icon size:\n";
|
|
75
|
+
for (var _i = 0, _Object$entries = Object.entries(upcomingIcon.sizeGuidance); _i < _Object$entries.length; _i++) {
|
|
76
|
+
var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
|
|
77
|
+
_size = _Object$entries$_i[0],
|
|
78
|
+
value = _Object$entries$_i[1];
|
|
79
|
+
guidance += "\t- ".concat(_size, ": ");
|
|
80
|
+
if (!Object.keys(migrationOutcomeDescriptionMap).includes(value)) {
|
|
81
|
+
guidance += 'No migration advice given.\n';
|
|
82
|
+
} else {
|
|
83
|
+
guidance += "".concat(migrationOutcomeDescriptionMap[value], ".\n");
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return guidance;
|
|
88
|
+
} else if (migrationMapObject) {
|
|
48
89
|
var newIcon = migrationMapObject.newIcon;
|
|
49
90
|
if (!newIcon) {
|
|
50
91
|
return 'No equivalent icon in new set. An option is to contribute a custom icon into icon-labs package instead.\n';
|
|
51
92
|
}
|
|
52
93
|
var buttonGuidanceStr = "Please set 'spacing' property of the new icon to 'none', to ensure appropriate spacing inside `@atlaskit/button`.\n";
|
|
53
|
-
var
|
|
94
|
+
var _guidance = '';
|
|
54
95
|
if (size) {
|
|
55
96
|
if (migrationMapObject.sizeGuidance[size] && canAutoMigrateNewIconBasedOnSize(migrationMapObject.sizeGuidance[size])) {
|
|
56
|
-
|
|
97
|
+
_guidance += "Fix: Use ".concat(newIcon.name, " from ").concat(newIcon.package, "/").concat(newIcon.type, "/").concat(newIcon.name, " instead.");
|
|
57
98
|
} else {
|
|
58
|
-
|
|
99
|
+
_guidance += "No equivalent icon for this size, ".concat(size, ", in new set.");
|
|
59
100
|
}
|
|
60
|
-
|
|
101
|
+
_guidance += "".concat(Object.keys(migrationOutcomeDescriptionMap).includes(migrationMapObject.sizeGuidance[size]) ? " Please: ".concat(migrationOutcomeDescriptionMap[migrationMapObject.sizeGuidance[size]]) : ' No migration size advice given.', "\n");
|
|
61
102
|
} else {
|
|
62
|
-
|
|
103
|
+
_guidance = "Use ".concat(newIcon.name, " from ").concat(newIcon.package, "/").concat(newIcon.type, "/").concat(newIcon.name, " instead.\nMigration suggestions, depending on the legacy icon size:\n");
|
|
63
104
|
Object.entries(migrationMapObject.sizeGuidance).forEach(function (_ref) {
|
|
64
105
|
var _ref2 = _slicedToArray(_ref, 2),
|
|
65
106
|
size = _ref2[0],
|
|
66
107
|
value = _ref2[1];
|
|
67
|
-
|
|
68
|
-
if (!(
|
|
69
|
-
|
|
108
|
+
_guidance += "\t- ".concat(size, ": ");
|
|
109
|
+
if (!Object.keys(migrationOutcomeDescriptionMap).includes(value)) {
|
|
110
|
+
_guidance += 'No migration advice given.\n';
|
|
70
111
|
} else {
|
|
71
|
-
|
|
112
|
+
_guidance += "".concat(migrationOutcomeDescriptionMap[value], ".\n");
|
|
72
113
|
}
|
|
73
114
|
});
|
|
74
115
|
}
|
|
75
116
|
if (insideNewButton) {
|
|
76
|
-
|
|
117
|
+
_guidance += buttonGuidanceStr;
|
|
77
118
|
} else if (size && size === 'medium') {
|
|
78
|
-
|
|
119
|
+
_guidance += "Setting the spacing property to 'spacious' will maintain the icon's box dimensions - but consider setting spacing='none' as it allows for easier control of spacing by parent elements.\n";
|
|
79
120
|
} else if (size) {
|
|
80
|
-
|
|
121
|
+
_guidance += "In the new icon, please use spacing='none'.\n";
|
|
81
122
|
}
|
|
82
|
-
return
|
|
123
|
+
return _guidance;
|
|
83
124
|
} else {
|
|
84
125
|
return "Migration suggestions not found for \"".concat(iconPackage, "\".\n");
|
|
85
126
|
}
|
|
@@ -104,8 +145,11 @@ export var canMigrateColor = function canMigrateColor(color) {
|
|
|
104
145
|
}
|
|
105
146
|
};
|
|
106
147
|
export var locToString = function locToString(node) {
|
|
107
|
-
|
|
108
|
-
|
|
148
|
+
if (node.range && node.range.length >= 2) {
|
|
149
|
+
return "".concat(node.range[0], ":").concat(node.range[1]);
|
|
150
|
+
} else {
|
|
151
|
+
return '';
|
|
152
|
+
}
|
|
109
153
|
};
|
|
110
154
|
export var createCantMigrateReExportError = function createCantMigrateReExportError(node, packageName, exportName, errors) {
|
|
111
155
|
var myError = {
|
|
@@ -118,10 +162,10 @@ export var createCantMigrateReExportError = function createCantMigrateReExportEr
|
|
|
118
162
|
};
|
|
119
163
|
pushManualError(locToString(node), errors, myError, packageName, exportName);
|
|
120
164
|
};
|
|
121
|
-
export var
|
|
165
|
+
export var createCantMigrateIdentifierMapOrArrayError = function createCantMigrateIdentifierMapOrArrayError(node, packageName, exportName, errors) {
|
|
122
166
|
var myError = {
|
|
123
167
|
node: node,
|
|
124
|
-
messageId: '
|
|
168
|
+
messageId: 'cantMigrateIdentifierMapOrArray',
|
|
125
169
|
data: {
|
|
126
170
|
packageName: packageName,
|
|
127
171
|
exportName: exportName
|
|
@@ -129,6 +173,17 @@ export var createCantMigrateIdentifierError = function createCantMigrateIdentifi
|
|
|
129
173
|
};
|
|
130
174
|
pushManualError(locToString(node), errors, myError, packageName, exportName);
|
|
131
175
|
};
|
|
176
|
+
export var createCantMigrateIdentifierError = function createCantMigrateIdentifierError(node, packageName, exportName, errors) {
|
|
177
|
+
var myError = {
|
|
178
|
+
node: node,
|
|
179
|
+
messageId: 'cantMigrateIdentifier',
|
|
180
|
+
data: {
|
|
181
|
+
iconSource: packageName,
|
|
182
|
+
iconName: exportName
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
pushManualError(locToString(node), errors, myError, packageName, exportName);
|
|
186
|
+
};
|
|
132
187
|
export var createCantFindSuitableReplacementError = function createCantFindSuitableReplacementError(node, importSource, iconName, errors, sizeIssue) {
|
|
133
188
|
var myError = {
|
|
134
189
|
node: node,
|
|
@@ -191,7 +246,7 @@ export var createAutoMigrationError = function createAutoMigrationError(node, im
|
|
|
191
246
|
errors[locToString(node)] = myError;
|
|
192
247
|
};
|
|
193
248
|
var pushManualError = function pushManualError(key, errors, myError, importSource, iconName) {
|
|
194
|
-
if (
|
|
249
|
+
if (Object.keys(errors).includes(key)) {
|
|
195
250
|
errors[key].errors.push(myError);
|
|
196
251
|
} else {
|
|
197
252
|
errors[key] = {
|
|
@@ -239,7 +294,7 @@ export var createHelpers = function createHelpers(context) {
|
|
|
239
294
|
* @returns defaultValue if the configuration flag is not set, the defaultValue of the configuration flag otherwise
|
|
240
295
|
*/
|
|
241
296
|
var getConfigFlag = function getConfigFlag(key, defaultValue) {
|
|
242
|
-
if (context.options.length > 0 && context.options[0] &&
|
|
297
|
+
if (context.options.length > 0 && context.options[0] && Object.keys(context.options[0]).includes(key)) {
|
|
243
298
|
return context.options[0][key] === !defaultValue ? !defaultValue : defaultValue;
|
|
244
299
|
}
|
|
245
300
|
return defaultValue;
|
|
@@ -256,4 +311,22 @@ export var createHelpers = function createHelpers(context) {
|
|
|
256
311
|
getTokenCallValue: getTokenCallValue,
|
|
257
312
|
getConfigFlag: getConfigFlag
|
|
258
313
|
};
|
|
314
|
+
};
|
|
315
|
+
export var addToListOfRanges = function addToListOfRanges(node, sortedListOfRangesForErrors) {
|
|
316
|
+
if (node.range && node.range.length >= 2) {
|
|
317
|
+
sortedListOfRangesForErrors.push({
|
|
318
|
+
start: node.range[0],
|
|
319
|
+
end: node.range[1]
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
};
|
|
323
|
+
export var isInRangeList = function isInRangeList(node, sortedListOfRangesForErrors) {
|
|
324
|
+
var range = node.range;
|
|
325
|
+
if (!range || range.length < 2) {
|
|
326
|
+
return false;
|
|
327
|
+
}
|
|
328
|
+
var found = sortedListOfRangesForErrors.find(function (currRange) {
|
|
329
|
+
return range[0] >= currRange.start && range[1] <= currRange.end;
|
|
330
|
+
});
|
|
331
|
+
return !!found;
|
|
259
332
|
};
|
|
@@ -35,8 +35,8 @@ var rule = createLintRule({
|
|
|
35
35
|
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: '{{missingProps}}' ",
|
|
36
36
|
cantMigrateSizeUnknown: "This usage of Icon sets the size via a variable or function that can't be determined.",
|
|
37
37
|
cantMigrateFunctionUnknown: "'{{iconName}}' from legacy '{{importSource}}' is used in unknown function/component. Please manually migrate this icon.",
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
cantMigrateIdentifierMapOrArray: "This icon is passed to other components via a map or array, in a way that can't be automatically migrated. Please manually migrate wherever this expression is used and use the icon components directly.",
|
|
39
|
+
cantMigrateIdentifier: "This is a legacy icon, {{iconName}} from {{iconSource}}, being referenced. Please manually migrate."
|
|
40
40
|
}
|
|
41
41
|
},
|
|
42
42
|
create: function create(context) {
|
|
@@ -52,7 +52,8 @@ var rule = createLintRule({
|
|
|
52
52
|
checkIconAsProp = _createChecks.checkIconAsProp,
|
|
53
53
|
checkJSXElement = _createChecks.checkJSXElement,
|
|
54
54
|
checkCallExpression = _createChecks.checkCallExpression,
|
|
55
|
-
throwErrors = _createChecks.throwErrors
|
|
55
|
+
throwErrors = _createChecks.throwErrors,
|
|
56
|
+
checkIconReference = _createChecks.checkIconReference;
|
|
56
57
|
return errorBoundary({
|
|
57
58
|
// Track imports of relevant components
|
|
58
59
|
ImportDeclaration: checkImportDeclarations,
|
|
@@ -68,6 +69,7 @@ var rule = createLintRule({
|
|
|
68
69
|
JSXElement: checkJSXElement,
|
|
69
70
|
// Icons called as an argument of a function (i.e. icon={DefaultIcon(AddIcon)})
|
|
70
71
|
CallExpression: checkCallExpression,
|
|
72
|
+
Identifier: checkIconReference,
|
|
71
73
|
'Program:exit': throwErrors
|
|
72
74
|
}, failSilently);
|
|
73
75
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export var upcomingIcons = ['app-switcher', 'check-circle-outline', 'export', 'file', 'flag-filled', 'lightbulb-filled', 'lock-filled', 'menu-expand', 'menu', 'notification-direct', 'notification', 'people-group', 'people', 'refresh', 'switcher', 'editor/align-image-center', 'editor/align-image-left', 'editor/align-image-right', 'editor/background-color', 'editor/bold', 'editor/indent', 'editor/italic', 'editor/horizontal-rule', 'editor-layout-three-equal', 'editor-layout-three-with-sidebars', 'editor/layout-two-equal', 'editor/layout-two-left-sidebars', 'editor/layout-two-right-sidebar', 'editor/media-center', 'editor/media-full-width', 'editor/media-wide', 'editor/number-list', 'emoji/activity', 'editor/file', 'emoji/flags', 'emoji/food', 'emoji/nature', 'emoji/people', 'emoji/productivity', 'emoji/travel', 'bitbucket/repos'];
|
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import type { Rule } from 'eslint';
|
|
2
2
|
import { type CallExpression, type ExportDefaultDeclaration, type ExportNamedDeclaration, type Identifier, type ImportDeclaration, type VariableDeclaration } from 'eslint-codemod-utils';
|
|
3
|
-
|
|
3
|
+
type ReturnObject = {
|
|
4
4
|
checkImportDeclarations: (node: ImportDeclaration & Rule.NodeParentExtension) => void;
|
|
5
5
|
checkVariableDeclarations: (node: VariableDeclaration & Rule.NodeParentExtension) => void;
|
|
6
6
|
checkExportDefaultDeclaration: (node: ExportDefaultDeclaration & Rule.NodeParentExtension) => void;
|
|
7
7
|
checkExportNamedVariables: (node: ExportNamedDeclaration & Rule.NodeParentExtension) => void;
|
|
8
8
|
checkArrayOrMap: (node: Identifier) => void;
|
|
9
9
|
checkIconAsProp: (node: Identifier) => void;
|
|
10
|
+
checkIconReference: (node: Identifier & Rule.NodeParentExtension) => void;
|
|
10
11
|
checkJSXElement: (node: Rule.Node) => void;
|
|
11
12
|
checkCallExpression: (node: CallExpression & Rule.NodeParentExtension) => void;
|
|
12
13
|
throwErrors: () => void;
|
|
13
14
|
};
|
|
15
|
+
export declare const createChecks: (context: Rule.RuleContext) => ReturnObject;
|
|
16
|
+
export {};
|
|
@@ -1,17 +1,22 @@
|
|
|
1
1
|
import type { Rule } from 'eslint';
|
|
2
2
|
import { type JSXAttribute, type Node } from 'eslint-codemod-utils';
|
|
3
|
-
|
|
4
|
-
export type
|
|
3
|
+
import { type IconMigrationSizeGuidance } from '@atlaskit/icon/UNSAFE_migration-map';
|
|
4
|
+
export type IconMigrationError = Rule.ReportDescriptor;
|
|
5
|
+
export type RangeList = {
|
|
6
|
+
start: number;
|
|
7
|
+
end: number;
|
|
8
|
+
}[];
|
|
9
|
+
export type ErrorListManual = {
|
|
5
10
|
[loc: string]: {
|
|
6
|
-
errors:
|
|
11
|
+
errors: IconMigrationError[];
|
|
7
12
|
iconName: string;
|
|
8
13
|
importSource: string;
|
|
9
14
|
};
|
|
10
15
|
};
|
|
11
|
-
export type
|
|
12
|
-
[loc: string]:
|
|
16
|
+
export type ErrorListAuto = {
|
|
17
|
+
[loc: string]: IconMigrationError;
|
|
13
18
|
};
|
|
14
|
-
export type
|
|
19
|
+
export type GuidanceList = {
|
|
15
20
|
[loc: string]: string;
|
|
16
21
|
};
|
|
17
22
|
declare const sizes: readonly ["small", "medium", "large", "xlarge"];
|
|
@@ -23,6 +28,9 @@ export declare const isSize: (size: any) => size is "small" | "medium" | "large"
|
|
|
23
28
|
* @returns The migration map object for the legacy icon or null if not found
|
|
24
29
|
*/
|
|
25
30
|
export declare const getMigrationMapObject: (iconPackage: string) => any;
|
|
31
|
+
export declare const getUpcomingIcons: (iconPackage: string) => {
|
|
32
|
+
sizeGuidance: Record<Size, IconMigrationSizeGuidance>;
|
|
33
|
+
} | null;
|
|
26
34
|
/**
|
|
27
35
|
* Checks if a new icon can be auto-migrated based on guidance from the migration map
|
|
28
36
|
*/
|
|
@@ -38,14 +46,15 @@ export declare const createGuidance: (iconPackage: string, insideNewButton?: boo
|
|
|
38
46
|
*/
|
|
39
47
|
export declare const canMigrateColor: (color: string) => boolean;
|
|
40
48
|
export declare const locToString: (node: Node) => string;
|
|
41
|
-
export declare const createCantMigrateReExportError: (node: Node, packageName: string, exportName: string, errors:
|
|
42
|
-
export declare const
|
|
43
|
-
export declare const
|
|
44
|
-
export declare const
|
|
45
|
-
export declare const
|
|
46
|
-
export declare const
|
|
47
|
-
export declare const
|
|
48
|
-
export declare const
|
|
49
|
+
export declare const createCantMigrateReExportError: (node: Node, packageName: string, exportName: string, errors: ErrorListManual) => void;
|
|
50
|
+
export declare const createCantMigrateIdentifierMapOrArrayError: (node: Node, packageName: string, exportName: string, errors: ErrorListManual) => void;
|
|
51
|
+
export declare const createCantMigrateIdentifierError: (node: Node, packageName: string, exportName: string, errors: ErrorListManual) => void;
|
|
52
|
+
export declare const createCantFindSuitableReplacementError: (node: Node, importSource: string, iconName: string, errors: ErrorListManual, sizeIssue?: boolean) => void;
|
|
53
|
+
export declare const createCantMigrateFunctionUnknownError: (node: Node, importSource: string, iconName: string, errors: ErrorListManual) => void;
|
|
54
|
+
export declare const createCantMigrateColorError: (node: Node, colorValue: string, errors: ErrorListManual, importSource: string, iconName: string) => void;
|
|
55
|
+
export declare const createCantMigrateSpreadPropsError: (node: Node, missingProps: string[], errors: ErrorListManual, importSource: string, iconName: string) => void;
|
|
56
|
+
export declare const createCantMigrateSizeUnknown: (node: Node, errors: ErrorListManual, importSource: string, iconName: string) => void;
|
|
57
|
+
export declare const createAutoMigrationError: (node: Node, importSource: string, iconName: string, errors: ErrorListAuto) => void;
|
|
49
58
|
export declare const getLiteralStringValue: (value: any) => string | undefined;
|
|
50
59
|
export declare const createHelpers: (context: Rule.RuleContext) => {
|
|
51
60
|
/**
|
|
@@ -55,4 +64,6 @@ export declare const createHelpers: (context: Rule.RuleContext) => {
|
|
|
55
64
|
getTokenCallValue: (value: any) => string | undefined;
|
|
56
65
|
getConfigFlag: (key: string, defaultValue: boolean) => boolean;
|
|
57
66
|
};
|
|
67
|
+
export declare const addToListOfRanges: (node: Node, sortedListOfRangesForErrors: RangeList) => void;
|
|
68
|
+
export declare const isInRangeList: (node: Node, sortedListOfRangesForErrors: RangeList) => boolean;
|
|
58
69
|
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const upcomingIcons: string[];
|