@atlaskit/eslint-plugin-design-system 10.16.0 → 10.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -0
- 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/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/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/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 +2 -2
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
|
-
import { isNodeOfType } from 'eslint-codemod-utils';
|
|
2
|
+
import { isNodeOfType, literal } 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
5
|
import { upcomingIcons } from './upcoming-icons';
|
|
@@ -53,12 +53,33 @@ export var canAutoMigrateNewIconBasedOnSize = function canAutoMigrateNewIconBase
|
|
|
53
53
|
return ['swap', 'swap-slight-visual-change', 'swap-visual-change', 'swap-size-shift-utility'].includes(guidance || '');
|
|
54
54
|
};
|
|
55
55
|
|
|
56
|
+
/**
|
|
57
|
+
*
|
|
58
|
+
* @param iconPackage string
|
|
59
|
+
* @returns object of new icon name and import path
|
|
60
|
+
*/
|
|
61
|
+
export var getNewIconNameAndImportPath = function getNewIconNameAndImportPath(iconPackage, shouldUseMigrationPath) {
|
|
62
|
+
var legacyIconName = getIconKey(iconPackage);
|
|
63
|
+
var migrationMapObject = getMigrationMapObject(iconPackage);
|
|
64
|
+
if (!migrationMapObject || !migrationMapObject.newIcon) {
|
|
65
|
+
return {};
|
|
66
|
+
}
|
|
67
|
+
var newIcon = migrationMapObject.newIcon;
|
|
68
|
+
var migrationPath = newIcon.name === legacyIconName ? "".concat(newIcon.package, "/").concat(newIcon.type, "/migration/").concat(newIcon.name) : "".concat(newIcon.package, "/").concat(newIcon.type, "/migration/").concat(newIcon.name, "--").concat(legacyIconName.replaceAll('/', '-'));
|
|
69
|
+
return {
|
|
70
|
+
iconName: newIcon.name,
|
|
71
|
+
importPath: shouldUseMigrationPath ? migrationPath : "".concat(newIcon.package, "/").concat(newIcon.type, "/").concat(newIcon.name)
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
|
|
56
75
|
/**
|
|
57
76
|
* Creates the written guidance for migrating a legacy icon to a new icon
|
|
58
77
|
*/
|
|
59
|
-
export var createGuidance = function createGuidance(
|
|
60
|
-
var
|
|
61
|
-
|
|
78
|
+
export var createGuidance = function createGuidance(_ref) {
|
|
79
|
+
var iconPackage = _ref.iconPackage,
|
|
80
|
+
insideNewButton = _ref.insideNewButton,
|
|
81
|
+
size = _ref.size,
|
|
82
|
+
shouldUseMigrationPath = _ref.shouldUseMigrationPath;
|
|
62
83
|
var migrationMapObject = getMigrationMapObject(iconPackage);
|
|
63
84
|
var upcomingIcon = getUpcomingIcons(iconPackage);
|
|
64
85
|
if (upcomingIcon) {
|
|
@@ -90,21 +111,24 @@ export var createGuidance = function createGuidance(iconPackage) {
|
|
|
90
111
|
if (!newIcon) {
|
|
91
112
|
return 'No equivalent icon in new set. An option is to contribute a custom icon into icon-labs package instead.\n';
|
|
92
113
|
}
|
|
114
|
+
var _getNewIconNameAndImp = getNewIconNameAndImportPath(iconPackage, shouldUseMigrationPath),
|
|
115
|
+
iconName = _getNewIconNameAndImp.iconName,
|
|
116
|
+
importPath = _getNewIconNameAndImp.importPath;
|
|
93
117
|
var buttonGuidanceStr = "Please set 'spacing' property of the new icon to 'none', to ensure appropriate spacing inside `@atlaskit/button`.\n";
|
|
94
118
|
var _guidance = '';
|
|
95
119
|
if (size) {
|
|
96
120
|
if (migrationMapObject.sizeGuidance[size] && canAutoMigrateNewIconBasedOnSize(migrationMapObject.sizeGuidance[size])) {
|
|
97
|
-
_guidance += "Fix: Use ".concat(
|
|
121
|
+
_guidance += "Fix: Use ".concat(iconName, " from ").concat(importPath, " instead.");
|
|
98
122
|
} else {
|
|
99
123
|
_guidance += "No equivalent icon for this size, ".concat(size, ", in new set.");
|
|
100
124
|
}
|
|
101
125
|
_guidance += "".concat(Object.keys(migrationOutcomeDescriptionMap).includes(migrationMapObject.sizeGuidance[size]) ? " Please: ".concat(migrationOutcomeDescriptionMap[migrationMapObject.sizeGuidance[size]]) : ' No migration size advice given.', "\n");
|
|
102
126
|
} else {
|
|
103
|
-
_guidance = "Use ".concat(
|
|
104
|
-
Object.entries(migrationMapObject.sizeGuidance).forEach(function (
|
|
105
|
-
var
|
|
106
|
-
size =
|
|
107
|
-
value =
|
|
127
|
+
_guidance = "Use ".concat(iconName, " from ").concat(importPath, " instead.\nMigration suggestions, depending on the legacy icon size:\n");
|
|
128
|
+
Object.entries(migrationMapObject.sizeGuidance).forEach(function (_ref2) {
|
|
129
|
+
var _ref3 = _slicedToArray(_ref2, 2),
|
|
130
|
+
size = _ref3[0],
|
|
131
|
+
value = _ref3[1];
|
|
108
132
|
_guidance += "\t- ".concat(size, ": ");
|
|
109
133
|
if (!Object.keys(migrationOutcomeDescriptionMap).includes(value)) {
|
|
110
134
|
_guidance += 'No migration advice given.\n';
|
|
@@ -234,13 +258,22 @@ export var createCantMigrateSizeUnknown = function createCantMigrateSizeUnknown(
|
|
|
234
258
|
};
|
|
235
259
|
pushManualError(locToString(node), errors, myError, importSource, iconName);
|
|
236
260
|
};
|
|
237
|
-
export var createAutoMigrationError = function createAutoMigrationError(
|
|
261
|
+
export var createAutoMigrationError = function createAutoMigrationError(_ref4) {
|
|
262
|
+
var node = _ref4.node,
|
|
263
|
+
importSource = _ref4.importSource,
|
|
264
|
+
iconName = _ref4.iconName,
|
|
265
|
+
errors = _ref4.errors,
|
|
266
|
+
shouldAddSpaciousSpacing = _ref4.shouldAddSpaciousSpacing,
|
|
267
|
+
insideNewButton = _ref4.insideNewButton;
|
|
238
268
|
var myError = {
|
|
239
269
|
node: node,
|
|
240
270
|
messageId: 'noLegacyIconsAutoMigration',
|
|
241
271
|
data: {
|
|
242
272
|
importSource: importSource,
|
|
243
|
-
iconName: iconName
|
|
273
|
+
iconName: iconName,
|
|
274
|
+
spacing: shouldAddSpaciousSpacing ? 'spacious' : '',
|
|
275
|
+
// value type need to be a string in Rule.ReportDescriptor
|
|
276
|
+
insideNewButton: String(insideNewButton)
|
|
244
277
|
}
|
|
245
278
|
};
|
|
246
279
|
errors[locToString(node)] = myError;
|
|
@@ -304,9 +337,9 @@ export var createHelpers = function createHelpers(context) {
|
|
|
304
337
|
* Extracts the primaryColor value from a JSXAttribute
|
|
305
338
|
*/
|
|
306
339
|
getPrimaryColor: function getPrimaryColor(attr) {
|
|
307
|
-
var
|
|
340
|
+
var _ref5, _getLiteralStringValu;
|
|
308
341
|
var value = attr.value;
|
|
309
|
-
return (
|
|
342
|
+
return (_ref5 = (_getLiteralStringValu = getLiteralStringValue(value)) !== null && _getLiteralStringValu !== void 0 ? _getLiteralStringValu : getTokenCallValue(value)) !== null && _ref5 !== void 0 ? _ref5 : null;
|
|
310
343
|
},
|
|
311
344
|
getTokenCallValue: getTokenCallValue,
|
|
312
345
|
getConfigFlag: getConfigFlag
|
|
@@ -329,4 +362,171 @@ export var isInRangeList = function isInRangeList(node, sortedListOfRangesForErr
|
|
|
329
362
|
return range[0] >= currRange.start && range[1] <= currRange.end;
|
|
330
363
|
});
|
|
331
364
|
return !!found;
|
|
365
|
+
};
|
|
366
|
+
|
|
367
|
+
/**
|
|
368
|
+
*
|
|
369
|
+
* @param node Icon JSXelement
|
|
370
|
+
* @param newButtonImports list of new button import specifiers
|
|
371
|
+
* @returns if Icon is inside a new button
|
|
372
|
+
*/
|
|
373
|
+
export var isInsideNewButton = function isInsideNewButton(node, newButtonImports) {
|
|
374
|
+
var _node$parent, _node$parent2;
|
|
375
|
+
var insideNewButton = false;
|
|
376
|
+
if (node.parent && 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 && isNodeOfType(node.parent.parent.parent, 'JSXAttribute') && isNodeOfType(node.parent.parent.parent.name, 'JSXIdentifier') && (_node$parent2 = node.parent) !== null && _node$parent2 !== void 0 && (_node$parent2 = _node$parent2.parent) !== null && _node$parent2 !== void 0 && (_node$parent2 = _node$parent2.parent) !== null && _node$parent2 !== void 0 && _node$parent2.parent && isNodeOfType(node.parent.parent.parent.parent, 'JSXOpeningElement') && isNodeOfType(node.parent.parent.parent.parent.name, 'JSXIdentifier') && newButtonImports.has(node.parent.parent.parent.parent.name.name)) {
|
|
377
|
+
insideNewButton = true;
|
|
378
|
+
}
|
|
379
|
+
return insideNewButton;
|
|
380
|
+
};
|
|
381
|
+
|
|
382
|
+
/**
|
|
383
|
+
*
|
|
384
|
+
* @param node Icon JSXelement
|
|
385
|
+
* @param newButtonImports list of legacy button import specifiers
|
|
386
|
+
* @returns if Icon is inside a legacy button
|
|
387
|
+
*/
|
|
388
|
+
export var isInsideLegacyButton = function isInsideLegacyButton(node, legacyButtonImports) {
|
|
389
|
+
var _node$parent3, _node$parent4, _node$parent5, _node$parent6;
|
|
390
|
+
var insideLegacyButton = false;
|
|
391
|
+
if (node.parent && isNodeOfType(node.parent, 'JSXExpressionContainer') && (_node$parent3 = node.parent) !== null && _node$parent3 !== void 0 && _node$parent3.parent && isNodeOfType(node.parent.parent, 'JSXAttribute') && (node.parent.parent.name.name === 'iconBefore' || node.parent.parent.name.name === 'iconAfter') && isNodeOfType((_node$parent4 = node.parent) === null || _node$parent4 === void 0 || (_node$parent4 = _node$parent4.parent) === null || _node$parent4 === void 0 ? void 0 : _node$parent4.parent, 'JSXOpeningElement') && isNodeOfType((_node$parent5 = node.parent) === null || _node$parent5 === void 0 || (_node$parent5 = _node$parent5.parent) === null || _node$parent5 === void 0 ? void 0 : _node$parent5.parent.name, 'JSXIdentifier') && legacyButtonImports.has((_node$parent6 = node.parent) === null || _node$parent6 === void 0 || (_node$parent6 = _node$parent6.parent) === null || _node$parent6 === void 0 ? void 0 : _node$parent6.parent.name.name)) {
|
|
392
|
+
insideLegacyButton = true;
|
|
393
|
+
}
|
|
394
|
+
return insideLegacyButton;
|
|
395
|
+
};
|
|
396
|
+
var findProp = function findProp(attributes, propName) {
|
|
397
|
+
return attributes.find(function (attr) {
|
|
398
|
+
return attr.type === 'JSXAttribute' && attr.name.name === propName;
|
|
399
|
+
});
|
|
400
|
+
};
|
|
401
|
+
|
|
402
|
+
/**
|
|
403
|
+
*
|
|
404
|
+
* Creates a list of fixers to update the icon import path
|
|
405
|
+
* @param metadata Metadata including the import source and spacing
|
|
406
|
+
* @param fixer The original fix function
|
|
407
|
+
* @param legacyImportNode The import declaration node to replace
|
|
408
|
+
* @param shouldUseMigrationPath The eslint rule config, whether to use migration entrypoint or not
|
|
409
|
+
* @param migrationImportNode The migration import declaration node to replace, only present if shouldUseMigrationPath is false
|
|
410
|
+
* @returns A list of fixers to migrate the icon
|
|
411
|
+
*/
|
|
412
|
+
export var createImportFix = function createImportFix(_ref6) {
|
|
413
|
+
var fixer = _ref6.fixer,
|
|
414
|
+
legacyImportNode = _ref6.legacyImportNode,
|
|
415
|
+
metadata = _ref6.metadata,
|
|
416
|
+
shouldUseMigrationPath = _ref6.shouldUseMigrationPath,
|
|
417
|
+
migrationImportNode = _ref6.migrationImportNode;
|
|
418
|
+
var fixes = [];
|
|
419
|
+
var importSource = metadata.importSource;
|
|
420
|
+
var importPath = migrationImportNode ? importSource.replace('/migration', '').split('--')[0] : getNewIconNameAndImportPath(importSource, shouldUseMigrationPath).importPath;
|
|
421
|
+
|
|
422
|
+
// replace old icon import with icon import
|
|
423
|
+
if (legacyImportNode && importPath) {
|
|
424
|
+
fixes.push(fixer.replaceText(legacyImportNode.source, "'".concat(literal(importPath), "'")));
|
|
425
|
+
}
|
|
426
|
+
if (migrationImportNode && !shouldUseMigrationPath && importPath) {
|
|
427
|
+
fixes.push(fixer.replaceText(migrationImportNode.source, "'".concat(literal(importPath), "'")));
|
|
428
|
+
}
|
|
429
|
+
return fixes;
|
|
430
|
+
};
|
|
431
|
+
|
|
432
|
+
/**
|
|
433
|
+
* Creates a list of fixers to update the icon props
|
|
434
|
+
* @param node The Icon element to migrate
|
|
435
|
+
* @param metadata Metadata including the import source and spacing
|
|
436
|
+
* @param fixer The original fix function
|
|
437
|
+
* @param legacyImportNode The import declaration node to replace
|
|
438
|
+
* @param shouldUseMigrationPath The eslint rule config, whether to use migration entrypoint or not
|
|
439
|
+
* @param migrationImportNode The migration import declaration node to replace, only present if shouldUseMigrationPath is false
|
|
440
|
+
* @returns A list of fixers to migrate the icon
|
|
441
|
+
*/
|
|
442
|
+
export var createPropFixes = function createPropFixes(_ref7) {
|
|
443
|
+
var node = _ref7.node,
|
|
444
|
+
fixer = _ref7.fixer,
|
|
445
|
+
legacyImportNode = _ref7.legacyImportNode,
|
|
446
|
+
metadata = _ref7.metadata,
|
|
447
|
+
shouldUseMigrationPath = _ref7.shouldUseMigrationPath,
|
|
448
|
+
migrationImportNode = _ref7.migrationImportNode;
|
|
449
|
+
var fixes = [];
|
|
450
|
+
var importSource = metadata.importSource,
|
|
451
|
+
spacing = metadata.spacing,
|
|
452
|
+
insideNewButton = metadata.insideNewButton;
|
|
453
|
+
if (shouldUseMigrationPath && !legacyImportNode) {
|
|
454
|
+
return fixes;
|
|
455
|
+
}
|
|
456
|
+
var importPath = migrationImportNode ? importSource.replace('/migration', '').split('--')[0] : getNewIconNameAndImportPath(importSource, shouldUseMigrationPath).importPath;
|
|
457
|
+
var iconType = importPath !== null && importPath !== void 0 && importPath.startsWith('@atlaskit/icon/core') ? 'core' : 'utility';
|
|
458
|
+
if (node.type === 'JSXElement') {
|
|
459
|
+
var openingElement = node.openingElement;
|
|
460
|
+
var attributes = openingElement.attributes;
|
|
461
|
+
|
|
462
|
+
// replace primaryColor prop with color
|
|
463
|
+
var primaryColor = findProp(attributes, 'primaryColor');
|
|
464
|
+
if (primaryColor && primaryColor.type === 'JSXAttribute') {
|
|
465
|
+
fixes.push(fixer.replaceText(primaryColor.name, 'color'));
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
// add color="currentColor" if
|
|
469
|
+
// 1. primaryColor prop is not set
|
|
470
|
+
// 2. icon is not imported from migration entrypoint
|
|
471
|
+
// 3. icon element is not inside a new button
|
|
472
|
+
if (legacyImportNode && !primaryColor && !migrationImportNode &&
|
|
473
|
+
// value type need to be a string in Rule.ReportDescriptor
|
|
474
|
+
insideNewButton !== 'true') {
|
|
475
|
+
fixes.push(fixer.insertTextAfter(openingElement.name, " color=\"currentColor\""));
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
// rename or remove size prop based on shouldUseMigrationPath,
|
|
479
|
+
// add spacing="spacious" if
|
|
480
|
+
// 1. it's in error metadata, which means size is medium
|
|
481
|
+
// 2. no existing spacing prop
|
|
482
|
+
// 3. iconType is "core"
|
|
483
|
+
// 4. icon is not imported from migration entrypoint
|
|
484
|
+
var sizeProp = findProp(attributes, 'size');
|
|
485
|
+
var spacingProp = findProp(attributes, 'spacing');
|
|
486
|
+
if (spacing && !spacingProp && iconType === 'core' && !migrationImportNode) {
|
|
487
|
+
fixes.push(fixer.insertTextAfter(sizeProp || openingElement.name, " spacing=\"".concat(spacing, "\"")));
|
|
488
|
+
}
|
|
489
|
+
if (sizeProp && sizeProp.type === 'JSXAttribute') {
|
|
490
|
+
fixes.push(shouldUseMigrationPath ?
|
|
491
|
+
// replace size prop with LEGACY_size,
|
|
492
|
+
fixer.replaceText(sizeProp.name, 'LEGACY_size') :
|
|
493
|
+
// remove size prop if shouldUseMigrationPath is false
|
|
494
|
+
fixer.remove(sizeProp));
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
// rename or remove secondaryColor prop based on shouldUseMigrationPath
|
|
498
|
+
var secondaryColorProp = findProp(attributes, 'secondaryColor');
|
|
499
|
+
if (secondaryColorProp && secondaryColorProp.type === 'JSXAttribute') {
|
|
500
|
+
fixes.push(shouldUseMigrationPath ?
|
|
501
|
+
// replace secondaryColor prop with LEGACY_secondaryColor
|
|
502
|
+
fixer.replaceText(secondaryColorProp.name, 'LEGACY_secondaryColor') :
|
|
503
|
+
// remove secondaryColor prop if shouldUseMigrationPath is false
|
|
504
|
+
fixer.remove(secondaryColorProp));
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
// remove LEGACY props
|
|
508
|
+
if (!shouldUseMigrationPath) {
|
|
509
|
+
['LEGACY_size', 'LEGACY_margin', 'LEGACY_fallbackIcon', 'LEGACY_secondaryColor'].forEach(function (propName) {
|
|
510
|
+
var legacyProp = findProp(attributes, propName);
|
|
511
|
+
if (legacyProp && legacyProp.type === 'JSXAttribute') {
|
|
512
|
+
fixes.push(fixer.remove(legacyProp));
|
|
513
|
+
}
|
|
514
|
+
});
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
return fixes;
|
|
518
|
+
};
|
|
519
|
+
|
|
520
|
+
/**
|
|
521
|
+
* Check if the new icon exists in the migration map
|
|
522
|
+
*/
|
|
523
|
+
export var checkIfNewIconExist = function checkIfNewIconExist(error) {
|
|
524
|
+
var _error$data;
|
|
525
|
+
if (!((_error$data = error.data) !== null && _error$data !== void 0 && _error$data.importSource)) {
|
|
526
|
+
return false;
|
|
527
|
+
}
|
|
528
|
+
var iconKey = getIconKey(error.data.importSource);
|
|
529
|
+
var _ref8 = baseMigrationMap[iconKey] || {},
|
|
530
|
+
newIcon = _ref8.newIcon;
|
|
531
|
+
return Boolean(newIcon);
|
|
332
532
|
};
|
|
@@ -5,6 +5,7 @@ import { createHelpers } from './helpers';
|
|
|
5
5
|
var rule = createLintRule({
|
|
6
6
|
meta: {
|
|
7
7
|
name: 'no-legacy-icons',
|
|
8
|
+
fixable: 'code',
|
|
8
9
|
type: 'problem',
|
|
9
10
|
docs: {
|
|
10
11
|
description: 'Enforces no legacy icons are used.',
|
|
@@ -22,6 +23,9 @@ var rule = createLintRule({
|
|
|
22
23
|
},
|
|
23
24
|
quiet: {
|
|
24
25
|
type: 'boolean'
|
|
26
|
+
},
|
|
27
|
+
shouldUseMigrationPath: {
|
|
28
|
+
type: 'boolean'
|
|
25
29
|
}
|
|
26
30
|
},
|
|
27
31
|
additionalProperties: false
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Rule } from 'eslint';
|
|
2
|
-
import { type JSXAttribute, type Node } from 'eslint-codemod-utils';
|
|
2
|
+
import { type ImportDeclaration, type JSXAttribute, type Node } from 'eslint-codemod-utils';
|
|
3
3
|
import { type IconMigrationSizeGuidance } from '@atlaskit/icon/UNSAFE_migration-map';
|
|
4
4
|
export type IconMigrationError = Rule.ReportDescriptor;
|
|
5
5
|
export type RangeList = {
|
|
@@ -47,10 +47,24 @@ export declare const getUpcomingIcons: (iconPackage: string) => {
|
|
|
47
47
|
* Checks if a new icon can be auto-migrated based on guidance from the migration map
|
|
48
48
|
*/
|
|
49
49
|
export declare const canAutoMigrateNewIconBasedOnSize: (guidance?: string) => boolean;
|
|
50
|
+
/**
|
|
51
|
+
*
|
|
52
|
+
* @param iconPackage string
|
|
53
|
+
* @returns object of new icon name and import path
|
|
54
|
+
*/
|
|
55
|
+
export declare const getNewIconNameAndImportPath: (iconPackage: string, shouldUseMigrationPath?: boolean) => {
|
|
56
|
+
iconName?: string;
|
|
57
|
+
importPath?: string;
|
|
58
|
+
};
|
|
50
59
|
/**
|
|
51
60
|
* Creates the written guidance for migrating a legacy icon to a new icon
|
|
52
61
|
*/
|
|
53
|
-
export declare const createGuidance: (iconPackage
|
|
62
|
+
export declare const createGuidance: ({ iconPackage, insideNewButton, size, shouldUseMigrationPath, }: {
|
|
63
|
+
iconPackage: string;
|
|
64
|
+
insideNewButton?: boolean | undefined;
|
|
65
|
+
size?: "small" | "medium" | "large" | "xlarge" | undefined;
|
|
66
|
+
shouldUseMigrationPath?: boolean | undefined;
|
|
67
|
+
}) => string;
|
|
54
68
|
/**
|
|
55
69
|
* Checks if the color can be migrated
|
|
56
70
|
* @param color String representing the color to check
|
|
@@ -66,7 +80,14 @@ export declare const createCantMigrateFunctionUnknownError: (node: Node, importS
|
|
|
66
80
|
export declare const createCantMigrateColorError: (node: Node, colorValue: string, errors: ErrorListManual, importSource: string, iconName: string) => void;
|
|
67
81
|
export declare const createCantMigrateSpreadPropsError: (node: Node, missingProps: string[], errors: ErrorListManual, importSource: string, iconName: string) => void;
|
|
68
82
|
export declare const createCantMigrateSizeUnknown: (node: Node, errors: ErrorListManual, importSource: string, iconName: string) => void;
|
|
69
|
-
export declare const createAutoMigrationError: (node
|
|
83
|
+
export declare const createAutoMigrationError: ({ node, importSource, iconName, errors, shouldAddSpaciousSpacing, insideNewButton, }: {
|
|
84
|
+
node: Node;
|
|
85
|
+
importSource: string;
|
|
86
|
+
iconName: string;
|
|
87
|
+
errors: ErrorListAuto;
|
|
88
|
+
shouldAddSpaciousSpacing?: boolean | undefined;
|
|
89
|
+
insideNewButton?: boolean | undefined;
|
|
90
|
+
}) => void;
|
|
70
91
|
export declare const getLiteralStringValue: (value: any) => string | undefined;
|
|
71
92
|
export declare const createHelpers: (context: Rule.RuleContext) => {
|
|
72
93
|
/**
|
|
@@ -78,4 +99,68 @@ export declare const createHelpers: (context: Rule.RuleContext) => {
|
|
|
78
99
|
};
|
|
79
100
|
export declare const addToListOfRanges: (node: Node, sortedListOfRangesForErrors: RangeList) => void;
|
|
80
101
|
export declare const isInRangeList: (node: Node, sortedListOfRangesForErrors: RangeList) => boolean;
|
|
102
|
+
/**
|
|
103
|
+
*
|
|
104
|
+
* @param node Icon JSXelement
|
|
105
|
+
* @param newButtonImports list of new button import specifiers
|
|
106
|
+
* @returns if Icon is inside a new button
|
|
107
|
+
*/
|
|
108
|
+
export declare const isInsideNewButton: (node: Rule.Node, newButtonImports: Set<string>) => boolean;
|
|
109
|
+
/**
|
|
110
|
+
*
|
|
111
|
+
* @param node Icon JSXelement
|
|
112
|
+
* @param newButtonImports list of legacy button import specifiers
|
|
113
|
+
* @returns if Icon is inside a legacy button
|
|
114
|
+
*/
|
|
115
|
+
export declare const isInsideLegacyButton: (node: Rule.Node, legacyButtonImports: Set<string>) => boolean;
|
|
116
|
+
/**
|
|
117
|
+
*
|
|
118
|
+
* Creates a list of fixers to update the icon import path
|
|
119
|
+
* @param metadata Metadata including the import source and spacing
|
|
120
|
+
* @param fixer The original fix function
|
|
121
|
+
* @param legacyImportNode The import declaration node to replace
|
|
122
|
+
* @param shouldUseMigrationPath The eslint rule config, whether to use migration entrypoint or not
|
|
123
|
+
* @param migrationImportNode The migration import declaration node to replace, only present if shouldUseMigrationPath is false
|
|
124
|
+
* @returns A list of fixers to migrate the icon
|
|
125
|
+
*/
|
|
126
|
+
export declare const createImportFix: ({ fixer, legacyImportNode, metadata, shouldUseMigrationPath, migrationImportNode, }: {
|
|
127
|
+
fixer: Rule.RuleFixer;
|
|
128
|
+
metadata: {
|
|
129
|
+
importSource: string;
|
|
130
|
+
spacing: string;
|
|
131
|
+
};
|
|
132
|
+
legacyImportNode?: ImportDeclaration | undefined;
|
|
133
|
+
shouldUseMigrationPath: boolean;
|
|
134
|
+
migrationImportNode?: ImportDeclaration | undefined;
|
|
135
|
+
}) => Rule.Fix[];
|
|
136
|
+
/**
|
|
137
|
+
* Creates a list of fixers to update the icon props
|
|
138
|
+
* @param node The Icon element to migrate
|
|
139
|
+
* @param metadata Metadata including the import source and spacing
|
|
140
|
+
* @param fixer The original fix function
|
|
141
|
+
* @param legacyImportNode The import declaration node to replace
|
|
142
|
+
* @param shouldUseMigrationPath The eslint rule config, whether to use migration entrypoint or not
|
|
143
|
+
* @param migrationImportNode The migration import declaration node to replace, only present if shouldUseMigrationPath is false
|
|
144
|
+
* @returns A list of fixers to migrate the icon
|
|
145
|
+
*/
|
|
146
|
+
export declare const createPropFixes: ({ node, fixer, legacyImportNode, metadata, shouldUseMigrationPath, migrationImportNode, }: {
|
|
147
|
+
node: Node;
|
|
148
|
+
fixer: Rule.RuleFixer;
|
|
149
|
+
metadata: {
|
|
150
|
+
importSource: string;
|
|
151
|
+
spacing: string;
|
|
152
|
+
insideNewButton: string;
|
|
153
|
+
};
|
|
154
|
+
legacyImportNode?: ImportDeclaration | undefined;
|
|
155
|
+
shouldUseMigrationPath: boolean;
|
|
156
|
+
migrationImportNode?: ImportDeclaration | undefined;
|
|
157
|
+
}) => Rule.Fix[];
|
|
158
|
+
/**
|
|
159
|
+
* Check if the new icon exists in the migration map
|
|
160
|
+
*/
|
|
161
|
+
export declare const checkIfNewIconExist: (error: {
|
|
162
|
+
data?: {
|
|
163
|
+
importSource?: string;
|
|
164
|
+
};
|
|
165
|
+
}) => boolean;
|
|
81
166
|
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Rule } from 'eslint';
|
|
2
|
-
import { type JSXAttribute, type Node } from 'eslint-codemod-utils';
|
|
2
|
+
import { type ImportDeclaration, type JSXAttribute, type Node } from 'eslint-codemod-utils';
|
|
3
3
|
import { type IconMigrationSizeGuidance } from '@atlaskit/icon/UNSAFE_migration-map';
|
|
4
4
|
export type IconMigrationError = Rule.ReportDescriptor;
|
|
5
5
|
export type RangeList = {
|
|
@@ -52,10 +52,24 @@ export declare const getUpcomingIcons: (iconPackage: string) => {
|
|
|
52
52
|
* Checks if a new icon can be auto-migrated based on guidance from the migration map
|
|
53
53
|
*/
|
|
54
54
|
export declare const canAutoMigrateNewIconBasedOnSize: (guidance?: string) => boolean;
|
|
55
|
+
/**
|
|
56
|
+
*
|
|
57
|
+
* @param iconPackage string
|
|
58
|
+
* @returns object of new icon name and import path
|
|
59
|
+
*/
|
|
60
|
+
export declare const getNewIconNameAndImportPath: (iconPackage: string, shouldUseMigrationPath?: boolean) => {
|
|
61
|
+
iconName?: string;
|
|
62
|
+
importPath?: string;
|
|
63
|
+
};
|
|
55
64
|
/**
|
|
56
65
|
* Creates the written guidance for migrating a legacy icon to a new icon
|
|
57
66
|
*/
|
|
58
|
-
export declare const createGuidance: (iconPackage
|
|
67
|
+
export declare const createGuidance: ({ iconPackage, insideNewButton, size, shouldUseMigrationPath, }: {
|
|
68
|
+
iconPackage: string;
|
|
69
|
+
insideNewButton?: boolean | undefined;
|
|
70
|
+
size?: "small" | "medium" | "large" | "xlarge" | undefined;
|
|
71
|
+
shouldUseMigrationPath?: boolean | undefined;
|
|
72
|
+
}) => string;
|
|
59
73
|
/**
|
|
60
74
|
* Checks if the color can be migrated
|
|
61
75
|
* @param color String representing the color to check
|
|
@@ -71,7 +85,14 @@ export declare const createCantMigrateFunctionUnknownError: (node: Node, importS
|
|
|
71
85
|
export declare const createCantMigrateColorError: (node: Node, colorValue: string, errors: ErrorListManual, importSource: string, iconName: string) => void;
|
|
72
86
|
export declare const createCantMigrateSpreadPropsError: (node: Node, missingProps: string[], errors: ErrorListManual, importSource: string, iconName: string) => void;
|
|
73
87
|
export declare const createCantMigrateSizeUnknown: (node: Node, errors: ErrorListManual, importSource: string, iconName: string) => void;
|
|
74
|
-
export declare const createAutoMigrationError: (node
|
|
88
|
+
export declare const createAutoMigrationError: ({ node, importSource, iconName, errors, shouldAddSpaciousSpacing, insideNewButton, }: {
|
|
89
|
+
node: Node;
|
|
90
|
+
importSource: string;
|
|
91
|
+
iconName: string;
|
|
92
|
+
errors: ErrorListAuto;
|
|
93
|
+
shouldAddSpaciousSpacing?: boolean | undefined;
|
|
94
|
+
insideNewButton?: boolean | undefined;
|
|
95
|
+
}) => void;
|
|
75
96
|
export declare const getLiteralStringValue: (value: any) => string | undefined;
|
|
76
97
|
export declare const createHelpers: (context: Rule.RuleContext) => {
|
|
77
98
|
/**
|
|
@@ -83,4 +104,68 @@ export declare const createHelpers: (context: Rule.RuleContext) => {
|
|
|
83
104
|
};
|
|
84
105
|
export declare const addToListOfRanges: (node: Node, sortedListOfRangesForErrors: RangeList) => void;
|
|
85
106
|
export declare const isInRangeList: (node: Node, sortedListOfRangesForErrors: RangeList) => boolean;
|
|
107
|
+
/**
|
|
108
|
+
*
|
|
109
|
+
* @param node Icon JSXelement
|
|
110
|
+
* @param newButtonImports list of new button import specifiers
|
|
111
|
+
* @returns if Icon is inside a new button
|
|
112
|
+
*/
|
|
113
|
+
export declare const isInsideNewButton: (node: Rule.Node, newButtonImports: Set<string>) => boolean;
|
|
114
|
+
/**
|
|
115
|
+
*
|
|
116
|
+
* @param node Icon JSXelement
|
|
117
|
+
* @param newButtonImports list of legacy button import specifiers
|
|
118
|
+
* @returns if Icon is inside a legacy button
|
|
119
|
+
*/
|
|
120
|
+
export declare const isInsideLegacyButton: (node: Rule.Node, legacyButtonImports: Set<string>) => boolean;
|
|
121
|
+
/**
|
|
122
|
+
*
|
|
123
|
+
* Creates a list of fixers to update the icon import path
|
|
124
|
+
* @param metadata Metadata including the import source and spacing
|
|
125
|
+
* @param fixer The original fix function
|
|
126
|
+
* @param legacyImportNode The import declaration node to replace
|
|
127
|
+
* @param shouldUseMigrationPath The eslint rule config, whether to use migration entrypoint or not
|
|
128
|
+
* @param migrationImportNode The migration import declaration node to replace, only present if shouldUseMigrationPath is false
|
|
129
|
+
* @returns A list of fixers to migrate the icon
|
|
130
|
+
*/
|
|
131
|
+
export declare const createImportFix: ({ fixer, legacyImportNode, metadata, shouldUseMigrationPath, migrationImportNode, }: {
|
|
132
|
+
fixer: Rule.RuleFixer;
|
|
133
|
+
metadata: {
|
|
134
|
+
importSource: string;
|
|
135
|
+
spacing: string;
|
|
136
|
+
};
|
|
137
|
+
legacyImportNode?: ImportDeclaration | undefined;
|
|
138
|
+
shouldUseMigrationPath: boolean;
|
|
139
|
+
migrationImportNode?: ImportDeclaration | undefined;
|
|
140
|
+
}) => Rule.Fix[];
|
|
141
|
+
/**
|
|
142
|
+
* Creates a list of fixers to update the icon props
|
|
143
|
+
* @param node The Icon element to migrate
|
|
144
|
+
* @param metadata Metadata including the import source and spacing
|
|
145
|
+
* @param fixer The original fix function
|
|
146
|
+
* @param legacyImportNode The import declaration node to replace
|
|
147
|
+
* @param shouldUseMigrationPath The eslint rule config, whether to use migration entrypoint or not
|
|
148
|
+
* @param migrationImportNode The migration import declaration node to replace, only present if shouldUseMigrationPath is false
|
|
149
|
+
* @returns A list of fixers to migrate the icon
|
|
150
|
+
*/
|
|
151
|
+
export declare const createPropFixes: ({ node, fixer, legacyImportNode, metadata, shouldUseMigrationPath, migrationImportNode, }: {
|
|
152
|
+
node: Node;
|
|
153
|
+
fixer: Rule.RuleFixer;
|
|
154
|
+
metadata: {
|
|
155
|
+
importSource: string;
|
|
156
|
+
spacing: string;
|
|
157
|
+
insideNewButton: string;
|
|
158
|
+
};
|
|
159
|
+
legacyImportNode?: ImportDeclaration | undefined;
|
|
160
|
+
shouldUseMigrationPath: boolean;
|
|
161
|
+
migrationImportNode?: ImportDeclaration | undefined;
|
|
162
|
+
}) => Rule.Fix[];
|
|
163
|
+
/**
|
|
164
|
+
* Check if the new icon exists in the migration map
|
|
165
|
+
*/
|
|
166
|
+
export declare const checkIfNewIconExist: (error: {
|
|
167
|
+
data?: {
|
|
168
|
+
importSource?: string;
|
|
169
|
+
};
|
|
170
|
+
}) => boolean;
|
|
86
171
|
export {};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/eslint-plugin-design-system",
|
|
3
3
|
"description": "The essential plugin for use with the Atlassian Design System.",
|
|
4
|
-
"version": "10.
|
|
4
|
+
"version": "10.17.0",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"publishConfig": {
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
57
|
"@af/formatting": "*",
|
|
58
|
-
"@atlaskit/ds-lib": "^2.
|
|
58
|
+
"@atlaskit/ds-lib": "^2.5.0",
|
|
59
59
|
"@atlaskit/theme": "^13.0.0",
|
|
60
60
|
"@atlassian/codegen": "*",
|
|
61
61
|
"@atlassian/eslint-utils": "^0.5.0",
|