@atlaskit/eslint-plugin-design-system 13.14.1 → 13.15.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 +21 -0
- package/README.md +63 -63
- package/dist/cjs/rules/no-legacy-icons/checks.js +22 -5
- package/dist/cjs/rules/no-legacy-icons/helpers.js +122 -46
- package/dist/cjs/rules/utils/get-deprecated-config.js +1 -1
- package/dist/es2019/rules/no-legacy-icons/checks.js +22 -6
- package/dist/es2019/rules/no-legacy-icons/helpers.js +125 -44
- package/dist/es2019/rules/utils/get-deprecated-config.js +3 -2
- package/dist/esm/rules/no-legacy-icons/checks.js +22 -5
- package/dist/esm/rules/no-legacy-icons/helpers.js +121 -45
- package/dist/esm/rules/utils/get-deprecated-config.js +2 -2
- package/dist/types/rules/no-legacy-icons/helpers.d.ts +12 -4
- package/dist/types/rules/use-tokens-typography/transformers/banned-properties.d.ts +1 -1
- package/dist/types/rules/use-tokens-typography/transformers/font-family.d.ts +1 -1
- package/dist/types/rules/use-tokens-typography/transformers/font-weight.d.ts +1 -1
- package/dist/types/rules/use-tokens-typography/transformers/restricted-capitalisation.d.ts +1 -1
- package/dist/types/rules/use-tokens-typography/transformers/untokenized-properties.d.ts +1 -1
- package/dist/types-ts4.5/rules/no-legacy-icons/helpers.d.ts +12 -4
- package/dist/types-ts4.5/rules/use-tokens-typography/transformers/banned-properties.d.ts +1 -1
- package/dist/types-ts4.5/rules/use-tokens-typography/transformers/font-family.d.ts +1 -1
- package/dist/types-ts4.5/rules/use-tokens-typography/transformers/font-weight.d.ts +1 -1
- package/dist/types-ts4.5/rules/use-tokens-typography/transformers/restricted-capitalisation.d.ts +1 -1
- package/dist/types-ts4.5/rules/use-tokens-typography/transformers/untokenized-properties.d.ts +1 -1
- package/package.json +5 -4
|
@@ -5,7 +5,7 @@ var _typeof = require("@babel/runtime/helpers/typeof");
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
-
exports.throwManualErrors = exports.throwAutoErrors = exports.locToString = exports.isSize = exports.isInsideNewButton = exports.isInsideLegacyButton = exports.isInsideIconOnlyLegacyButton = exports.getUpcomingIcons = exports.getMigrationMapObject = exports.createHelpers = exports.createGuidance = exports.createCantMigrateSpreadPropsError = exports.createCantMigrateSizeUnknown = exports.createCantMigrateReExportError = exports.createCantMigrateIdentifierMapOrArrayError = exports.createCantMigrateIdentifierError = exports.createCantMigrateFunctionUnknownError = exports.createCantMigrateColorError = exports.createCantFindSuitableReplacementError = exports.createAutoMigrationError = exports.canMigrateColor = exports.canAutoMigrateNewIconBasedOnSize = exports.addToListOfRanges = void 0;
|
|
8
|
+
exports.throwManualErrors = exports.throwAutoErrors = exports.locToString = exports.isSize = exports.isInsideNewButton = exports.isInsideLegacyButton = exports.isInsideIconOnlyLegacyButton = exports.getUpcomingIcons = exports.getMigrationMapObject = exports.getComponentName = exports.createHelpers = exports.createGuidance = exports.createCantMigrateSpreadPropsError = exports.createCantMigrateSizeUnknown = exports.createCantMigrateReExportError = exports.createCantMigrateIdentifierMapOrArrayError = exports.createCantMigrateIdentifierError = exports.createCantMigrateFunctionUnknownError = exports.createCantMigrateColorError = exports.createCantFindSuitableReplacementError = exports.createAutoMigrationError = exports.canMigrateColor = exports.canAutoMigrateNewIconBasedOnSize = exports.addToListOfRanges = void 0;
|
|
9
9
|
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
10
10
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
11
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
@@ -66,7 +66,7 @@ var getIconKey = function getIconKey(iconPackage) {
|
|
|
66
66
|
* Checks if a new icon can be auto-migrated based on guidance from the migration map
|
|
67
67
|
*/
|
|
68
68
|
var canAutoMigrateNewIconBasedOnSize = exports.canAutoMigrateNewIconBasedOnSize = function canAutoMigrateNewIconBasedOnSize(guidance) {
|
|
69
|
-
return ['swap', 'swap-slight-visual-change', 'swap-visual-change'
|
|
69
|
+
return guidance ? ['swap', 'swap-slight-visual-change', 'swap-visual-change'].includes(guidance) : false;
|
|
70
70
|
};
|
|
71
71
|
|
|
72
72
|
/**
|
|
@@ -94,8 +94,10 @@ var getNewIconNameAndImportPath = function getNewIconNameAndImportPath(iconPacka
|
|
|
94
94
|
var createGuidance = exports.createGuidance = function createGuidance(_ref) {
|
|
95
95
|
var iconPackage = _ref.iconPackage,
|
|
96
96
|
insideNewButton = _ref.insideNewButton,
|
|
97
|
-
|
|
98
|
-
shouldUseMigrationPath = _ref.shouldUseMigrationPath
|
|
97
|
+
initialSize = _ref.size,
|
|
98
|
+
shouldUseMigrationPath = _ref.shouldUseMigrationPath,
|
|
99
|
+
shouldForceSmallIcon = _ref.shouldForceSmallIcon;
|
|
100
|
+
var size = shouldForceSmallIcon ? 'small' : initialSize;
|
|
99
101
|
var migrationMapObject = getMigrationMapObject(iconPackage);
|
|
100
102
|
var upcomingIcon = getUpcomingIcons(iconPackage);
|
|
101
103
|
if (upcomingIcon) {
|
|
@@ -155,8 +157,18 @@ var createGuidance = exports.createGuidance = function createGuidance(_ref) {
|
|
|
155
157
|
}
|
|
156
158
|
if (insideNewButton) {
|
|
157
159
|
_guidance += buttonGuidanceStr;
|
|
158
|
-
} else if (size
|
|
159
|
-
_guidance += "Setting the spacing
|
|
160
|
+
} else if (size === 'medium') {
|
|
161
|
+
_guidance += "Setting the spacing='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";
|
|
162
|
+
} else if (size === 'small') {
|
|
163
|
+
if (initialSize !== 'small' && shouldForceSmallIcon) {
|
|
164
|
+
_guidance += "For this icon, it's recommended to use a smaller size using size='small'. Alternatively, for special cases where a larger version is needed size='medium' can be used, but it is generally discouraged for this icon.\n";
|
|
165
|
+
} else if (initialSize === 'small') {
|
|
166
|
+
if (shouldForceSmallIcon) {
|
|
167
|
+
_guidance += "Setting spacing='compact' will maintain the icon's box dimensions - but consider setting spacing='none' as it allows for easier control of spacing by parent elements.\n";
|
|
168
|
+
} else {
|
|
169
|
+
_guidance += "It's recommended to upscale to a medium icon with no spacing. Alternatively for special cases where smaller icons are required, the original icon size and dimensions can be maintained by using size='small' and spacing='compact'.\n";
|
|
170
|
+
}
|
|
171
|
+
}
|
|
160
172
|
} else if (size) {
|
|
161
173
|
_guidance += "In the new icon, please use spacing='none'.\n";
|
|
162
174
|
}
|
|
@@ -280,7 +292,8 @@ var createAutoMigrationError = exports.createAutoMigrationError = function creat
|
|
|
280
292
|
iconName = _ref4.iconName,
|
|
281
293
|
errors = _ref4.errors,
|
|
282
294
|
spacing = _ref4.spacing,
|
|
283
|
-
insideNewButton = _ref4.insideNewButton
|
|
295
|
+
insideNewButton = _ref4.insideNewButton,
|
|
296
|
+
shouldForceSmallIcon = _ref4.shouldForceSmallIcon;
|
|
284
297
|
var myError = {
|
|
285
298
|
node: node,
|
|
286
299
|
messageId: 'noLegacyIconsAutoMigration',
|
|
@@ -289,7 +302,8 @@ var createAutoMigrationError = exports.createAutoMigrationError = function creat
|
|
|
289
302
|
iconName: iconName,
|
|
290
303
|
spacing: spacing !== null && spacing !== void 0 ? spacing : '',
|
|
291
304
|
// value type need to be a string in Rule.ReportDescriptor
|
|
292
|
-
insideNewButton: String(insideNewButton)
|
|
305
|
+
insideNewButton: String(insideNewButton),
|
|
306
|
+
shouldForceSmallIcon: String(shouldForceSmallIcon)
|
|
293
307
|
}
|
|
294
308
|
};
|
|
295
309
|
errors[locToString(node)] = myError;
|
|
@@ -444,7 +458,7 @@ var getNewIconNameForRenaming = function getNewIconNameForRenaming(isInManualArr
|
|
|
444
458
|
var newIconName;
|
|
445
459
|
if (isInManualArray) {
|
|
446
460
|
newIconName = getNewIconNameAndImportPath(importSource).iconName;
|
|
447
|
-
var keyToName = newIconName ?
|
|
461
|
+
var keyToName = newIconName ? getComponentName(newIconName) : undefined;
|
|
448
462
|
newIconName = keyToName;
|
|
449
463
|
if (newIconName === undefined || importSpecifier === keyToName) {
|
|
450
464
|
newIconName = "".concat(keyToName, "New");
|
|
@@ -452,6 +466,11 @@ var getNewIconNameForRenaming = function getNewIconNameForRenaming(isInManualArr
|
|
|
452
466
|
}
|
|
453
467
|
return newIconName;
|
|
454
468
|
};
|
|
469
|
+
var getComponentName = exports.getComponentName = function getComponentName(name) {
|
|
470
|
+
return name.split(/\W/).map(function (part) {
|
|
471
|
+
return "".concat(part[0].toUpperCase()).concat(part.slice(1));
|
|
472
|
+
}).join('').concat('Icon');
|
|
473
|
+
};
|
|
455
474
|
|
|
456
475
|
/**
|
|
457
476
|
*
|
|
@@ -517,7 +536,8 @@ var createPropFixes = function createPropFixes(_ref7) {
|
|
|
517
536
|
migrationImportNode = _ref7.migrationImportNode,
|
|
518
537
|
newIconName = _ref7.newIconName;
|
|
519
538
|
var fixes = [];
|
|
520
|
-
var spacing = metadata.spacing
|
|
539
|
+
var spacing = metadata.spacing,
|
|
540
|
+
size = metadata.size;
|
|
521
541
|
if (shouldUseMigrationPath && !legacyImportNode) {
|
|
522
542
|
return fixes;
|
|
523
543
|
}
|
|
@@ -533,24 +553,31 @@ var createPropFixes = function createPropFixes(_ref7) {
|
|
|
533
553
|
if (primaryColor && primaryColor.type === 'JSXAttribute') {
|
|
534
554
|
fixes.push(fixer.replaceText(primaryColor.name, 'color'));
|
|
535
555
|
}
|
|
536
|
-
|
|
537
|
-
// rename or remove size prop based on shouldUseMigrationPath,
|
|
538
|
-
// add spacing="spacious" if
|
|
539
|
-
// 1. it's in error metadata, which means size is medium
|
|
540
|
-
// 2. no existing spacing prop
|
|
541
|
-
// 3. iconType is "core"
|
|
542
|
-
// 4. icon is not imported from migration entrypoint
|
|
543
556
|
var sizeProp = findProp(attributes, 'size');
|
|
544
557
|
var spacingProp = findProp(attributes, 'spacing');
|
|
545
|
-
if (spacing && !spacingProp && !migrationImportNode) {
|
|
546
|
-
fixes.push(fixer.insertTextAfter(sizeProp || openingElement.name, " spacing=\"".concat(spacing, "\"")));
|
|
547
|
-
}
|
|
548
558
|
if (sizeProp && sizeProp.type === 'JSXAttribute') {
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
559
|
+
if (shouldUseMigrationPath) {
|
|
560
|
+
// Rename existing size prop to LEGACY_size and add new size prop if applicable
|
|
561
|
+
fixes.push(fixer.replaceText(sizeProp.name, 'LEGACY_size'));
|
|
562
|
+
if (size) {
|
|
563
|
+
fixes.push(fixer.insertTextAfter(sizeProp, " size=\"".concat(size, "\"")));
|
|
564
|
+
}
|
|
565
|
+
} else {
|
|
566
|
+
if (size && sizeProp.value) {
|
|
567
|
+
// update size prop with new replacement size
|
|
568
|
+
fixes.push(fixer.replaceText(sizeProp.value, "\"".concat(size, "\"")));
|
|
569
|
+
} else {
|
|
570
|
+
// remove size prop if no new replacement size is specified
|
|
571
|
+
fixes.push(fixer.remove(sizeProp));
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
} else if (size) {
|
|
575
|
+
fixes.push(fixer.insertTextAfter(openingElement.name, " size=\"".concat(size, "\"")));
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
// Add spacing prop if no existing spacing prop and icon is not imported from migration entrypoint
|
|
579
|
+
if (spacing && spacing !== 'none' && !spacingProp && !migrationImportNode) {
|
|
580
|
+
fixes.push(fixer.insertTextAfter(sizeProp || openingElement.name, " spacing=\"".concat(spacing, "\"")));
|
|
554
581
|
}
|
|
555
582
|
|
|
556
583
|
// rename or remove secondaryColor prop based on shouldUseMigrationPath
|
|
@@ -647,6 +674,7 @@ var throwManualErrors = exports.throwManualErrors = function throwManualErrors(_
|
|
|
647
674
|
var throwAutoErrors = exports.throwAutoErrors = function throwAutoErrors(_ref10) {
|
|
648
675
|
var errorsManual = _ref10.errorsManual,
|
|
649
676
|
errorsAuto = _ref10.errorsAuto,
|
|
677
|
+
iconSizesInfo = _ref10.iconSizesInfo,
|
|
650
678
|
legacyIconImports = _ref10.legacyIconImports,
|
|
651
679
|
guidance = _ref10.guidance,
|
|
652
680
|
migrationIconImports = _ref10.migrationIconImports,
|
|
@@ -702,7 +730,7 @@ var throwAutoErrors = exports.throwAutoErrors = function throwAutoErrors(_ref10)
|
|
|
702
730
|
_step2;
|
|
703
731
|
try {
|
|
704
732
|
var _loop2 = function _loop2() {
|
|
705
|
-
var _legacyIconImports$er, _legacyIconImports$er2, _migrationIconImports;
|
|
733
|
+
var _iconSizesInfo$import, _iconSizesInfo$import2, _iconSizesInfo$import3, _legacyIconImports$er, _error$data2, _legacyIconImports$er2, _migrationIconImports;
|
|
706
734
|
var _step2$value = (0, _slicedToArray2.default)(_step2.value, 2),
|
|
707
735
|
_ = _step2$value[0],
|
|
708
736
|
error = _step2$value[1];
|
|
@@ -712,8 +740,20 @@ var throwAutoErrors = exports.throwAutoErrors = function throwAutoErrors(_ref10)
|
|
|
712
740
|
// If that is the case we'll need to provide a suggestion instead of auto-fixing as the suggestion will
|
|
713
741
|
// add another import without removing the old import and this needs to be validated
|
|
714
742
|
var isInManualArray = allManualErrorSources.has(importSource);
|
|
743
|
+
|
|
744
|
+
// Check if the icon has size of small, if so it cannot be automatically migrated. Two suggestions will be provided
|
|
745
|
+
// 1. Use core icon with no spacing
|
|
746
|
+
// 2. Use utility icon with compact spacing
|
|
747
|
+
var isSizeSmall = (_iconSizesInfo$import = iconSizesInfo[importSource]) === null || _iconSizesInfo$import === void 0 ? void 0 : _iconSizesInfo$import.small.includes(key);
|
|
748
|
+
var isMixedSizeUsage = ((_iconSizesInfo$import2 = iconSizesInfo[importSource]) === null || _iconSizesInfo$import2 === void 0 ? void 0 : _iconSizesInfo$import2.small.length) > 0 && ((_iconSizesInfo$import3 = iconSizesInfo[importSource]) === null || _iconSizesInfo$import3 === void 0 ? void 0 : _iconSizesInfo$import3.small.length) < iconSizesInfo[importSource].usageCount;
|
|
749
|
+
|
|
750
|
+
// Icon should be renamed
|
|
751
|
+
// 1. If the icon is in the manual array OR
|
|
752
|
+
// 2. If there is mixed size usages of this icon with size small
|
|
753
|
+
var shouldRenameIcon = isInManualArray || isMixedSizeUsage;
|
|
754
|
+
|
|
715
755
|
// New icon name for renaming if the icon is in the manual array
|
|
716
|
-
var newIconName = getNewIconNameForRenaming(
|
|
756
|
+
var newIconName = getNewIconNameForRenaming(shouldRenameIcon, importSource, errorList[0].data ? (_legacyIconImports$er = legacyIconImports[errorList[0].data.iconName]) === null || _legacyIconImports$er === void 0 ? void 0 : _legacyIconImports$er.importSpecifier : undefined);
|
|
717
757
|
if (!node) {
|
|
718
758
|
return 0; // continue
|
|
719
759
|
}
|
|
@@ -721,22 +761,43 @@ var throwAutoErrors = exports.throwAutoErrors = function throwAutoErrors(_ref10)
|
|
|
721
761
|
if (Object.keys(error).includes('data') && error.data) {
|
|
722
762
|
error.data.guidance = guidanceMessage;
|
|
723
763
|
}
|
|
764
|
+
var shouldForceSmallIcon = ((_error$data2 = error.data) === null || _error$data2 === void 0 ? void 0 : _error$data2.shouldForceSmallIcon) === 'true';
|
|
724
765
|
var fixArguments = error.data ? {
|
|
725
|
-
metadata: error.data,
|
|
766
|
+
metadata: _objectSpread(_objectSpread({}, error.data), {}, {
|
|
767
|
+
spacing: error.data.isInNewButton ? 'none' : error.data.spacing,
|
|
768
|
+
size: shouldForceSmallIcon ? 'small' : error.data.size
|
|
769
|
+
}),
|
|
726
770
|
legacyImportNode: (_legacyIconImports$er2 = legacyIconImports[error.data.iconName]) === null || _legacyIconImports$er2 === void 0 ? void 0 : _legacyIconImports$er2.importNode,
|
|
727
771
|
migrationImportNode: (_migrationIconImports = migrationIconImports[error.data.iconName]) === null || _migrationIconImports === void 0 ? void 0 : _migrationIconImports.importNode,
|
|
728
772
|
shouldUseMigrationPath: shouldUseMigrationPath,
|
|
729
|
-
newIconName:
|
|
773
|
+
newIconName: shouldRenameIcon ? newIconName : undefined
|
|
730
774
|
} : null;
|
|
731
775
|
if (!error.data || shouldUseMigrationPath && !checkIfNewIconExist(error) || !fixArguments) {
|
|
732
776
|
return 0; // continue
|
|
733
777
|
}
|
|
734
|
-
|
|
735
|
-
|
|
778
|
+
var isInNewButton = fixArguments.metadata.insideNewButton === 'true';
|
|
779
|
+
if (isSizeSmall && !shouldForceSmallIcon) {
|
|
736
780
|
error.suggest = [{
|
|
737
|
-
desc: '
|
|
781
|
+
desc: isInNewButton ? 'Replace with medium core icon (Recommended)' : 'Replace with medium core icon and no spacing (Recommended)',
|
|
782
|
+
fix: function fix(fixer) {
|
|
783
|
+
return [].concat((0, _toConsumableArray2.default)(createPropFixes(_objectSpread(_objectSpread({}, fixArguments), {}, {
|
|
784
|
+
metadata: _objectSpread(_objectSpread({}, fixArguments.metadata), {}, {
|
|
785
|
+
spacing: 'none'
|
|
786
|
+
}),
|
|
787
|
+
node: node,
|
|
788
|
+
fixer: fixer
|
|
789
|
+
}))), (0, _toConsumableArray2.default)(createImportFix(_objectSpread(_objectSpread({}, fixArguments), {}, {
|
|
790
|
+
fixer: fixer
|
|
791
|
+
}))));
|
|
792
|
+
}
|
|
793
|
+
}, {
|
|
794
|
+
desc: isInNewButton ? 'Replace with small core icon' : 'Replace with small core icon and compact spacing',
|
|
738
795
|
fix: function fix(fixer) {
|
|
739
796
|
return [].concat((0, _toConsumableArray2.default)(createPropFixes(_objectSpread(_objectSpread({}, fixArguments), {}, {
|
|
797
|
+
metadata: _objectSpread(_objectSpread({}, fixArguments.metadata), {}, {
|
|
798
|
+
spacing: 'compact',
|
|
799
|
+
size: 'small'
|
|
800
|
+
}),
|
|
740
801
|
node: node,
|
|
741
802
|
fixer: fixer
|
|
742
803
|
}))), (0, _toConsumableArray2.default)(createImportFix(_objectSpread(_objectSpread({}, fixArguments), {}, {
|
|
@@ -745,25 +806,40 @@ var throwAutoErrors = exports.throwAutoErrors = function throwAutoErrors(_ref10)
|
|
|
745
806
|
}
|
|
746
807
|
}];
|
|
747
808
|
} else {
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
error.
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
809
|
+
if (isInManualArray) {
|
|
810
|
+
// provide suggestion if there is a manual error for the same import source and thus the legacy import can't be removed
|
|
811
|
+
error.suggest = [{
|
|
812
|
+
desc: 'Rename icon import, import from the new package, and update props.',
|
|
813
|
+
fix: function fix(fixer) {
|
|
814
|
+
return [].concat((0, _toConsumableArray2.default)(createPropFixes(_objectSpread(_objectSpread({}, fixArguments), {}, {
|
|
815
|
+
node: node,
|
|
816
|
+
fixer: fixer
|
|
817
|
+
}))), (0, _toConsumableArray2.default)(createImportFix(_objectSpread(_objectSpread({}, fixArguments), {}, {
|
|
818
|
+
fixer: fixer
|
|
819
|
+
}))));
|
|
820
|
+
}
|
|
821
|
+
}];
|
|
822
|
+
} else {
|
|
823
|
+
// Update Guidance message for auto-fixing
|
|
824
|
+
if (error.data) {
|
|
825
|
+
error.data.guidance = error.data.guidance + "\nTo automatically fix this icon, run the auto-fixer attached to the first use of ".concat(importSource, " in this file - either manually, or by saving this file.");
|
|
826
|
+
}
|
|
827
|
+
// There should only be 1 import fix for each import source and thus only add this at the start of the list
|
|
828
|
+
if (autoFixers.length === 0) {
|
|
829
|
+
autoFixers.push(function (fixer) {
|
|
830
|
+
return createImportFix(_objectSpread(_objectSpread({}, fixArguments), {}, {
|
|
831
|
+
fixer: fixer
|
|
832
|
+
}));
|
|
833
|
+
});
|
|
834
|
+
}
|
|
835
|
+
// Push the prop fix regardless
|
|
754
836
|
autoFixers.push(function (fixer) {
|
|
755
|
-
return
|
|
837
|
+
return createPropFixes(_objectSpread(_objectSpread({}, fixArguments), {}, {
|
|
838
|
+
node: node,
|
|
756
839
|
fixer: fixer
|
|
757
840
|
}));
|
|
758
841
|
});
|
|
759
842
|
}
|
|
760
|
-
// Push the prop fix regardless
|
|
761
|
-
autoFixers.push(function (fixer) {
|
|
762
|
-
return createPropFixes(_objectSpread(_objectSpread({}, fixArguments), {}, {
|
|
763
|
-
node: node,
|
|
764
|
-
fixer: fixer
|
|
765
|
-
}));
|
|
766
|
-
});
|
|
767
843
|
}
|
|
768
844
|
// Add the error to the appliedErrorsForImport, ready to be thrown later
|
|
769
845
|
appliedErrorsForImport.push(error);
|
|
@@ -17,7 +17,7 @@ var getConfig = exports.getConfig = function getConfig(specifier) {
|
|
|
17
17
|
var source = _fs.default.readFileSync(configPath, 'utf8');
|
|
18
18
|
var parsedConfig = JSON.parse(source);
|
|
19
19
|
var combinedConfig = _objectSpread(_objectSpread({}, parsedConfig), {}, {
|
|
20
|
-
imports: _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, parsedConfig.imports), _deprecatedMap2.deprecatedCore), _deprecatedMap2.deprecatedUtility), _deprecatedMap.deprecatedCore)
|
|
20
|
+
imports: _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({}, parsedConfig.imports), _deprecatedMap2.deprecatedCore), _deprecatedMap2.deprecatedUtility), _deprecatedMap.deprecatedCore), _deprecatedMap.deprecatedUtility)
|
|
21
21
|
});
|
|
22
22
|
return combinedConfig[specifier];
|
|
23
23
|
};
|
|
@@ -12,6 +12,8 @@ export const createChecks = context => {
|
|
|
12
12
|
const legacyButtonImports = new Set();
|
|
13
13
|
const errorsManual = {};
|
|
14
14
|
const errorsAuto = {};
|
|
15
|
+
const iconSizesInfo = {}; //Import source key, locations as value
|
|
16
|
+
|
|
15
17
|
let guidance = {};
|
|
16
18
|
|
|
17
19
|
// Extract parameters
|
|
@@ -316,7 +318,7 @@ export const createChecks = context => {
|
|
|
316
318
|
|
|
317
319
|
// Legacy icons rendered as JSX elements
|
|
318
320
|
if (Object.keys(legacyIconImports).includes(name)) {
|
|
319
|
-
var _size, _size2;
|
|
321
|
+
var _size, _size2, _sizeProp$value2;
|
|
320
322
|
// Determine if inside a new button - if so:
|
|
321
323
|
// - Assume spread props are safe - still error if props explicitly set to unmigratable values
|
|
322
324
|
const insideNewButton = isInsideNewButton(node, newButtonImports);
|
|
@@ -402,7 +404,7 @@ export const createChecks = context => {
|
|
|
402
404
|
const isNewIconMigratable = canAutoMigrateNewIconBasedOnSize(upcomingIcon ? upcomingIcon.sizeGuidance[(_size = size) !== null && _size !== void 0 ? _size : 'medium'] : migrationMapObject === null || migrationMapObject === void 0 ? void 0 : migrationMapObject.sizeGuidance[(_size2 = size) !== null && _size2 !== void 0 ? _size2 : 'medium']);
|
|
403
405
|
|
|
404
406
|
// Add spacing if:
|
|
405
|
-
// 1. size is medium for core/utility icons or
|
|
407
|
+
// 1. size is medium for core/utility icons or not set (default is medium for core and small for utility icons)
|
|
406
408
|
// 2. not inside a new or legacy button (except for icon-only legacy buttons)
|
|
407
409
|
const sizeProp = node.openingElement.attributes.find(attribute => attribute.type === 'JSXAttribute' && (attribute.name.name === 'size' || attribute.name.name === 'LEGACY_size'));
|
|
408
410
|
let spacing;
|
|
@@ -411,13 +413,24 @@ export const createChecks = context => {
|
|
|
411
413
|
if (sizeProp && sizeProp.type === 'JSXAttribute' && ((_sizeProp$value = sizeProp.value) === null || _sizeProp$value === void 0 ? void 0 : _sizeProp$value.type) === 'Literal') {
|
|
412
414
|
if (sizeProp.value.value === 'medium') {
|
|
413
415
|
spacing = 'spacious';
|
|
414
|
-
} else if (sizeProp.value.value === 'small' && (newIcon === null || newIcon === void 0 ? void 0 : newIcon.type) === 'utility') {
|
|
415
|
-
spacing = 'compact';
|
|
416
416
|
}
|
|
417
417
|
} else if (!sizeProp) {
|
|
418
418
|
spacing = 'spacious';
|
|
419
419
|
}
|
|
420
420
|
}
|
|
421
|
+
if (!iconSizesInfo[legacyIconImports[name].packageName]) {
|
|
422
|
+
iconSizesInfo[legacyIconImports[name].packageName] = {
|
|
423
|
+
small: [],
|
|
424
|
+
usageCount: 0
|
|
425
|
+
};
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
// Do not automatically migration if size is small as we cannot determine if a core icon or a scaled down utility icon should be used
|
|
429
|
+
if (sizeProp && sizeProp.type === 'JSXAttribute' && ((_sizeProp$value2 = sizeProp.value) === null || _sizeProp$value2 === void 0 ? void 0 : _sizeProp$value2.type) === 'Literal' && sizeProp.value.value === 'small') {
|
|
430
|
+
iconSizesInfo[legacyIconImports[name].packageName].small.push(locToString(node));
|
|
431
|
+
}
|
|
432
|
+
iconSizesInfo[legacyIconImports[name].packageName].usageCount++;
|
|
433
|
+
const shouldForceSmallIcon = newIcon === null || newIcon === void 0 ? void 0 : newIcon.shouldForceSmallIcon;
|
|
421
434
|
if (shouldUseSafeMigrationMode && !hasManualMigration && (newIcon !== null && newIcon !== void 0 && newIcon.isMigrationUnsafe || size !== 'medium' || hasSecondaryColorProp)) {
|
|
422
435
|
createCantFindSuitableReplacementError(node, legacyIconImports[name].packageName, name, errorsManual, upcomingIcon ? true : migrationMapObject ? true : false);
|
|
423
436
|
} else if (!hasManualMigration && (newIcon || upcomingIcon) && isNewIconMigratable) {
|
|
@@ -427,7 +440,8 @@ export const createChecks = context => {
|
|
|
427
440
|
iconName: name,
|
|
428
441
|
errors: errorsAuto,
|
|
429
442
|
spacing,
|
|
430
|
-
insideNewButton
|
|
443
|
+
insideNewButton,
|
|
444
|
+
shouldForceSmallIcon
|
|
431
445
|
});
|
|
432
446
|
} else if ((!newIcon && !upcomingIcon || !isNewIconMigratable) && size) {
|
|
433
447
|
createCantFindSuitableReplacementError(node, legacyIconImports[name].packageName, name, errorsManual, upcomingIcon ? true : migrationMapObject ? true : false);
|
|
@@ -437,7 +451,8 @@ export const createChecks = context => {
|
|
|
437
451
|
iconPackage: legacyIconImports[name].packageName,
|
|
438
452
|
insideNewButton,
|
|
439
453
|
size: size && isSize(size) ? size : undefined,
|
|
440
|
-
shouldUseMigrationPath
|
|
454
|
+
shouldUseMigrationPath,
|
|
455
|
+
shouldForceSmallIcon
|
|
441
456
|
});
|
|
442
457
|
}
|
|
443
458
|
};
|
|
@@ -479,6 +494,7 @@ export const createChecks = context => {
|
|
|
479
494
|
throwAutoErrors({
|
|
480
495
|
errorsManual,
|
|
481
496
|
errorsAuto,
|
|
497
|
+
iconSizesInfo,
|
|
482
498
|
legacyIconImports,
|
|
483
499
|
guidance,
|
|
484
500
|
migrationIconImports,
|