@atlaskit/eslint-plugin-design-system 11.8.3 → 11.8.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +9 -0
- package/dist/cjs/rules/no-legacy-icons/checks.js +15 -23
- package/dist/cjs/rules/no-legacy-icons/helpers.js +25 -5
- package/dist/es2019/rules/no-legacy-icons/checks.js +8 -14
- package/dist/es2019/rules/no-legacy-icons/helpers.js +24 -4
- package/dist/esm/rules/no-legacy-icons/checks.js +16 -24
- package/dist/esm/rules/no-legacy-icons/helpers.js +24 -4
- package/dist/types/rules/no-legacy-icons/helpers.d.ts +7 -0
- package/dist/types-ts4.5/rules/no-legacy-icons/helpers.d.ts +7 -0
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# @atlaskit/eslint-plugin-design-system
|
|
2
2
|
|
|
3
|
+
## 11.8.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#104581](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/104581)
|
|
8
|
+
[`d7e7feee083ad`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/d7e7feee083ad) -
|
|
9
|
+
Updated behavior of no-legacy-icons autofixer to maintain appropriate sizing for legacy icon-only
|
|
10
|
+
button components
|
|
11
|
+
|
|
3
12
|
## 11.8.3
|
|
4
13
|
|
|
5
14
|
### Patch Changes
|
|
@@ -379,22 +379,13 @@ var createChecks = exports.createChecks = function createChecks(context) {
|
|
|
379
379
|
|
|
380
380
|
// Flag icons imported from migration path
|
|
381
381
|
if (!shouldUseMigrationPath && Object.keys(migrationIconImports).includes(name)) {
|
|
382
|
-
var _sizeProp$value;
|
|
383
|
-
var sizeProp = node.openingElement.attributes.find(function (attribute) {
|
|
384
|
-
return attribute.type === 'JSXAttribute' && (attribute.name.name === 'size' || attribute.name.name === 'LEGACY_size');
|
|
385
|
-
});
|
|
386
|
-
var insideNewButton = (0, _helpers.isInsideNewButton)(node, newButtonImports);
|
|
387
|
-
// Add spacious spacing if:
|
|
388
|
-
// 1. size is medium, or not set (default is medium)
|
|
389
|
-
// 2. not inside a new or legacy button
|
|
390
|
-
var shouldAddSpaciousSpacing = (sizeProp && sizeProp.type === 'JSXAttribute' && ((_sizeProp$value = sizeProp.value) === null || _sizeProp$value === void 0 ? void 0 : _sizeProp$value.type) === 'Literal' && sizeProp.value.value === 'medium' || !sizeProp) && !(0, _helpers.isInsideNewButton)(node, newButtonImports) && !(0, _helpers.isInsideLegacyButton)(node, legacyButtonImports);
|
|
391
382
|
(0, _helpers.createAutoMigrationError)({
|
|
392
383
|
node: node,
|
|
393
384
|
importSource: migrationIconImports[name].packageName,
|
|
394
385
|
iconName: name,
|
|
395
386
|
errors: errorsAuto,
|
|
396
|
-
spacing:
|
|
397
|
-
insideNewButton:
|
|
387
|
+
spacing: undefined,
|
|
388
|
+
insideNewButton: true
|
|
398
389
|
});
|
|
399
390
|
}
|
|
400
391
|
|
|
@@ -403,11 +394,12 @@ var createChecks = exports.createChecks = function createChecks(context) {
|
|
|
403
394
|
var _size, _size2;
|
|
404
395
|
// Determine if inside a new button - if so:
|
|
405
396
|
// - Assume spread props are safe - still error if props explicitly set to unmigratable values
|
|
406
|
-
var
|
|
397
|
+
var insideNewButton = (0, _helpers.isInsideNewButton)(node, newButtonImports);
|
|
407
398
|
|
|
408
399
|
// Determine if inside a legacy default button - if so:
|
|
409
400
|
// the auto fixer will add spacing prop to the medium size icon
|
|
410
401
|
var insideLegacyButton = (0, _helpers.isInsideLegacyButton)(node, legacyButtonImports);
|
|
402
|
+
var insideIconOnlyLegacyButton = (0, _helpers.isInsideIconOnlyLegacyButton)(node, legacyButtonImports);
|
|
411
403
|
|
|
412
404
|
// Find size prop on node
|
|
413
405
|
var size = 'medium';
|
|
@@ -479,7 +471,7 @@ var createChecks = exports.createChecks = function createChecks(context) {
|
|
|
479
471
|
// Do a set comparison - is requiredAttributesAfterSpread a subset of afterSpreadSet?
|
|
480
472
|
if (hasSpread === true && !Array.from(requiredAttributesAfterSpread).every(function (val) {
|
|
481
473
|
return afterSpreadSet.has(val);
|
|
482
|
-
}) && !
|
|
474
|
+
}) && !insideNewButton) {
|
|
483
475
|
var missingProps = Array.from(requiredAttributesAfterSpread).filter(function (val) {
|
|
484
476
|
return !afterSpreadSet.has(val);
|
|
485
477
|
});
|
|
@@ -499,20 +491,20 @@ var createChecks = exports.createChecks = function createChecks(context) {
|
|
|
499
491
|
|
|
500
492
|
// Add spacing if:
|
|
501
493
|
// 1. size is medium for core/utility icons or small for utility icons, or not set (default is medium for core and small for utility icons)
|
|
502
|
-
// 2. not inside a new or legacy button
|
|
503
|
-
var
|
|
494
|
+
// 2. not inside a new or legacy button (except for icon-only legacy buttons)
|
|
495
|
+
var sizeProp = node.openingElement.attributes.find(function (attribute) {
|
|
504
496
|
return attribute.type === 'JSXAttribute' && (attribute.name.name === 'size' || attribute.name.name === 'LEGACY_size');
|
|
505
497
|
});
|
|
506
498
|
var spacing;
|
|
507
|
-
if (!
|
|
508
|
-
var _sizeProp$
|
|
509
|
-
if (
|
|
510
|
-
if (
|
|
499
|
+
if (!insideNewButton && !(insideLegacyButton && !insideIconOnlyLegacyButton)) {
|
|
500
|
+
var _sizeProp$value;
|
|
501
|
+
if (sizeProp && sizeProp.type === 'JSXAttribute' && ((_sizeProp$value = sizeProp.value) === null || _sizeProp$value === void 0 ? void 0 : _sizeProp$value.type) === 'Literal') {
|
|
502
|
+
if (sizeProp.value.value === 'medium') {
|
|
511
503
|
spacing = 'spacious';
|
|
512
|
-
} else if (
|
|
504
|
+
} else if (sizeProp.value.value === 'small' && (newIcon === null || newIcon === void 0 ? void 0 : newIcon.type) === 'utility') {
|
|
513
505
|
spacing = 'compact';
|
|
514
506
|
}
|
|
515
|
-
} else if (!
|
|
507
|
+
} else if (!sizeProp) {
|
|
516
508
|
spacing = 'spacious';
|
|
517
509
|
}
|
|
518
510
|
}
|
|
@@ -525,7 +517,7 @@ var createChecks = exports.createChecks = function createChecks(context) {
|
|
|
525
517
|
iconName: name,
|
|
526
518
|
errors: errorsAuto,
|
|
527
519
|
spacing: spacing,
|
|
528
|
-
insideNewButton:
|
|
520
|
+
insideNewButton: insideNewButton
|
|
529
521
|
});
|
|
530
522
|
} else if ((!newIcon && !upcomingIcon || !isNewIconMigratable) && size) {
|
|
531
523
|
(0, _helpers.createCantFindSuitableReplacementError)(node, legacyIconImports[name].packageName, name, errorsManual, upcomingIcon ? true : migrationMapObject ? true : false);
|
|
@@ -533,7 +525,7 @@ var createChecks = exports.createChecks = function createChecks(context) {
|
|
|
533
525
|
(0, _helpers.addToListOfRanges)(node, errorRanges);
|
|
534
526
|
guidance[(0, _helpers.locToString)(node)] = (0, _helpers.createGuidance)({
|
|
535
527
|
iconPackage: legacyIconImports[name].packageName,
|
|
536
|
-
insideNewButton:
|
|
528
|
+
insideNewButton: insideNewButton,
|
|
537
529
|
size: size && (0, _helpers.isSize)(size) ? size : undefined,
|
|
538
530
|
shouldUseMigrationPath: shouldUseMigrationPath
|
|
539
531
|
});
|
|
@@ -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.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.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"));
|
|
@@ -407,11 +407,31 @@ var isInsideNewButton = exports.isInsideNewButton = function isInsideNewButton(n
|
|
|
407
407
|
*/
|
|
408
408
|
var isInsideLegacyButton = exports.isInsideLegacyButton = function isInsideLegacyButton(node, legacyButtonImports) {
|
|
409
409
|
var _node$parent3, _node$parent4, _node$parent5, _node$parent6;
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
410
|
+
return node.parent && (0, _eslintCodemodUtils.isNodeOfType)(node.parent, 'JSXExpressionContainer') && ((_node$parent3 = node.parent) === null || _node$parent3 === void 0 ? void 0 : _node$parent3.parent) && (0, _eslintCodemodUtils.isNodeOfType)(node.parent.parent, 'JSXAttribute') && (node.parent.parent.name.name === 'iconBefore' || node.parent.parent.name.name === 'iconAfter') && (0, _eslintCodemodUtils.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') && (0, _eslintCodemodUtils.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);
|
|
411
|
+
};
|
|
412
|
+
|
|
413
|
+
/**
|
|
414
|
+
*
|
|
415
|
+
* @param node Icon JSXelement
|
|
416
|
+
* @param newButtonImports list of legacy button import specifiers
|
|
417
|
+
* @returns if Icon is inside a legacy button
|
|
418
|
+
*/
|
|
419
|
+
var isInsideIconOnlyLegacyButton = exports.isInsideIconOnlyLegacyButton = function isInsideIconOnlyLegacyButton(node, legacyButtonImports) {
|
|
420
|
+
var insideIconOnlyLegacyButton = false;
|
|
421
|
+
if (isInsideLegacyButton(node, legacyButtonImports)) {
|
|
422
|
+
var _node$parent7, _node$parent8, _node$parent9, _node$parent10, _node$parent11, _node$parent12;
|
|
423
|
+
var legacyButtonAttributes = node.parent && (0, _eslintCodemodUtils.isNodeOfType)(node.parent, 'JSXExpressionContainer') && (_node$parent7 = node.parent) !== null && _node$parent7 !== void 0 && _node$parent7.parent && (0, _eslintCodemodUtils.isNodeOfType)(node.parent.parent, 'JSXAttribute') && node.parent.parent.parent && (0, _eslintCodemodUtils.isNodeOfType)((_node$parent8 = node.parent) === null || _node$parent8 === void 0 || (_node$parent8 = _node$parent8.parent) === null || _node$parent8 === void 0 ? void 0 : _node$parent8.parent, 'JSXOpeningElement') ? (_node$parent9 = node.parent) === null || _node$parent9 === void 0 || (_node$parent9 = _node$parent9.parent) === null || _node$parent9 === void 0 ? void 0 : _node$parent9.parent.attributes.map(function (attribute) {
|
|
424
|
+
var _attribute$name;
|
|
425
|
+
return (0, _eslintCodemodUtils.isNodeOfType)(attribute, 'JSXAttribute') && (0, _eslintCodemodUtils.isNodeOfType)(attribute.name, 'JSXIdentifier') && (attribute === null || attribute === void 0 || (_attribute$name = attribute.name) === null || _attribute$name === void 0 ? void 0 : _attribute$name.name);
|
|
426
|
+
}).filter(Boolean) : [];
|
|
427
|
+
var hasIconBefore = legacyButtonAttributes.includes('iconBefore');
|
|
428
|
+
var hasIconAfter = legacyButtonAttributes.includes('iconAfter');
|
|
429
|
+
var hasChildren = ((_node$parent10 = node.parent) === null || _node$parent10 === void 0 || (_node$parent10 = _node$parent10.parent) === null || _node$parent10 === void 0 || (_node$parent10 = _node$parent10.parent) === null || _node$parent10 === void 0 ? void 0 : _node$parent10.parent) && (0, _eslintCodemodUtils.isNodeOfType)((_node$parent11 = node.parent) === null || _node$parent11 === void 0 || (_node$parent11 = _node$parent11.parent) === null || _node$parent11 === void 0 || (_node$parent11 = _node$parent11.parent) === null || _node$parent11 === void 0 ? void 0 : _node$parent11.parent, 'JSXElement') && ((_node$parent12 = node.parent) === null || _node$parent12 === void 0 || (_node$parent12 = _node$parent12.parent) === null || _node$parent12 === void 0 || (_node$parent12 = _node$parent12.parent) === null || _node$parent12 === void 0 ? void 0 : _node$parent12.parent.children.length) > 0;
|
|
430
|
+
if (hasIconBefore && !hasIconAfter && !hasChildren || !hasIconBefore && hasIconAfter && !hasChildren || !hasIconBefore && !hasIconAfter && hasChildren) {
|
|
431
|
+
insideIconOnlyLegacyButton = true;
|
|
432
|
+
}
|
|
413
433
|
}
|
|
414
|
-
return
|
|
434
|
+
return insideIconOnlyLegacyButton;
|
|
415
435
|
};
|
|
416
436
|
var findProp = function findProp(attributes, propName) {
|
|
417
437
|
return attributes.find(function (attr) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isNodeOfType } from 'eslint-codemod-utils';
|
|
2
|
-
import { addToListOfRanges, canAutoMigrateNewIconBasedOnSize, canMigrateColor, createAutoMigrationError, createCantFindSuitableReplacementError, createCantMigrateColorError, createCantMigrateFunctionUnknownError, createCantMigrateIdentifierError, createCantMigrateIdentifierMapOrArrayError, createCantMigrateReExportError, createCantMigrateSizeUnknown, createCantMigrateSpreadPropsError, createGuidance, createHelpers, getMigrationMapObject, getUpcomingIcons, isInsideLegacyButton, isInsideNewButton, isSize, locToString, throwAutoErrors, throwManualErrors } from './helpers';
|
|
2
|
+
import { addToListOfRanges, canAutoMigrateNewIconBasedOnSize, canMigrateColor, createAutoMigrationError, createCantFindSuitableReplacementError, createCantMigrateColorError, createCantMigrateFunctionUnknownError, createCantMigrateIdentifierError, createCantMigrateIdentifierMapOrArrayError, createCantMigrateReExportError, createCantMigrateSizeUnknown, createCantMigrateSpreadPropsError, createGuidance, createHelpers, getMigrationMapObject, getUpcomingIcons, isInsideIconOnlyLegacyButton, isInsideLegacyButton, isInsideNewButton, isSize, locToString, throwAutoErrors, throwManualErrors } from './helpers';
|
|
3
3
|
export const createChecks = context => {
|
|
4
4
|
// Create global variables to be shared by the checks
|
|
5
5
|
const {
|
|
@@ -304,20 +304,13 @@ export const createChecks = context => {
|
|
|
304
304
|
|
|
305
305
|
// Flag icons imported from migration path
|
|
306
306
|
if (!shouldUseMigrationPath && Object.keys(migrationIconImports).includes(name)) {
|
|
307
|
-
var _sizeProp$value;
|
|
308
|
-
const sizeProp = node.openingElement.attributes.find(attribute => attribute.type === 'JSXAttribute' && (attribute.name.name === 'size' || attribute.name.name === 'LEGACY_size'));
|
|
309
|
-
const insideNewButton = isInsideNewButton(node, newButtonImports);
|
|
310
|
-
// Add spacious spacing if:
|
|
311
|
-
// 1. size is medium, or not set (default is medium)
|
|
312
|
-
// 2. not inside a new or legacy button
|
|
313
|
-
const shouldAddSpaciousSpacing = (sizeProp && sizeProp.type === 'JSXAttribute' && ((_sizeProp$value = sizeProp.value) === null || _sizeProp$value === void 0 ? void 0 : _sizeProp$value.type) === 'Literal' && sizeProp.value.value === 'medium' || !sizeProp) && !isInsideNewButton(node, newButtonImports) && !isInsideLegacyButton(node, legacyButtonImports);
|
|
314
307
|
createAutoMigrationError({
|
|
315
308
|
node,
|
|
316
309
|
importSource: migrationIconImports[name].packageName,
|
|
317
310
|
iconName: name,
|
|
318
311
|
errors: errorsAuto,
|
|
319
|
-
spacing:
|
|
320
|
-
insideNewButton
|
|
312
|
+
spacing: undefined,
|
|
313
|
+
insideNewButton: true
|
|
321
314
|
});
|
|
322
315
|
}
|
|
323
316
|
|
|
@@ -331,6 +324,7 @@ export const createChecks = context => {
|
|
|
331
324
|
// Determine if inside a legacy default button - if so:
|
|
332
325
|
// the auto fixer will add spacing prop to the medium size icon
|
|
333
326
|
const insideLegacyButton = isInsideLegacyButton(node, legacyButtonImports);
|
|
327
|
+
const insideIconOnlyLegacyButton = isInsideIconOnlyLegacyButton(node, legacyButtonImports);
|
|
334
328
|
|
|
335
329
|
// Find size prop on node
|
|
336
330
|
let size = 'medium';
|
|
@@ -409,12 +403,12 @@ export const createChecks = context => {
|
|
|
409
403
|
|
|
410
404
|
// Add spacing if:
|
|
411
405
|
// 1. size is medium for core/utility icons or small for utility icons, or not set (default is medium for core and small for utility icons)
|
|
412
|
-
// 2. not inside a new or legacy button
|
|
406
|
+
// 2. not inside a new or legacy button (except for icon-only legacy buttons)
|
|
413
407
|
const sizeProp = node.openingElement.attributes.find(attribute => attribute.type === 'JSXAttribute' && (attribute.name.name === 'size' || attribute.name.name === 'LEGACY_size'));
|
|
414
408
|
let spacing;
|
|
415
|
-
if (!insideNewButton && !insideLegacyButton) {
|
|
416
|
-
var _sizeProp$
|
|
417
|
-
if (sizeProp && sizeProp.type === 'JSXAttribute' && ((_sizeProp$
|
|
409
|
+
if (!insideNewButton && !(insideLegacyButton && !insideIconOnlyLegacyButton)) {
|
|
410
|
+
var _sizeProp$value;
|
|
411
|
+
if (sizeProp && sizeProp.type === 'JSXAttribute' && ((_sizeProp$value = sizeProp.value) === null || _sizeProp$value === void 0 ? void 0 : _sizeProp$value.type) === 'Literal') {
|
|
418
412
|
if (sizeProp.value.value === 'medium') {
|
|
419
413
|
spacing = 'spacious';
|
|
420
414
|
} else if (sizeProp.value.value === 'small' && (newIcon === null || newIcon === void 0 ? void 0 : newIcon.type) === 'utility') {
|
|
@@ -388,11 +388,31 @@ export const isInsideNewButton = (node, newButtonImports) => {
|
|
|
388
388
|
*/
|
|
389
389
|
export const isInsideLegacyButton = (node, legacyButtonImports) => {
|
|
390
390
|
var _node$parent3, _node$parent4, _node$parent4$parent, _node$parent5, _node$parent5$parent, _node$parent6, _node$parent6$parent;
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
391
|
+
return node.parent && isNodeOfType(node.parent, 'JSXExpressionContainer') && ((_node$parent3 = node.parent) === null || _node$parent3 === void 0 ? 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 ? void 0 : (_node$parent4$parent = _node$parent4.parent) === null || _node$parent4$parent === void 0 ? void 0 : _node$parent4$parent.parent, 'JSXOpeningElement') && isNodeOfType((_node$parent5 = node.parent) === null || _node$parent5 === void 0 ? void 0 : (_node$parent5$parent = _node$parent5.parent) === null || _node$parent5$parent === void 0 ? void 0 : _node$parent5$parent.parent.name, 'JSXIdentifier') && legacyButtonImports.has((_node$parent6 = node.parent) === null || _node$parent6 === void 0 ? void 0 : (_node$parent6$parent = _node$parent6.parent) === null || _node$parent6$parent === void 0 ? void 0 : _node$parent6$parent.parent.name.name);
|
|
392
|
+
};
|
|
393
|
+
|
|
394
|
+
/**
|
|
395
|
+
*
|
|
396
|
+
* @param node Icon JSXelement
|
|
397
|
+
* @param newButtonImports list of legacy button import specifiers
|
|
398
|
+
* @returns if Icon is inside a legacy button
|
|
399
|
+
*/
|
|
400
|
+
export const isInsideIconOnlyLegacyButton = (node, legacyButtonImports) => {
|
|
401
|
+
let insideIconOnlyLegacyButton = false;
|
|
402
|
+
if (isInsideLegacyButton(node, legacyButtonImports)) {
|
|
403
|
+
var _node$parent7, _node$parent8, _node$parent8$parent, _node$parent9, _node$parent9$parent, _node$parent10, _node$parent10$parent, _node$parent10$parent2, _node$parent11, _node$parent11$parent, _node$parent11$parent2, _node$parent12, _node$parent12$parent, _node$parent12$parent2;
|
|
404
|
+
const legacyButtonAttributes = node.parent && isNodeOfType(node.parent, 'JSXExpressionContainer') && (_node$parent7 = node.parent) !== null && _node$parent7 !== void 0 && _node$parent7.parent && isNodeOfType(node.parent.parent, 'JSXAttribute') && node.parent.parent.parent && isNodeOfType((_node$parent8 = node.parent) === null || _node$parent8 === void 0 ? void 0 : (_node$parent8$parent = _node$parent8.parent) === null || _node$parent8$parent === void 0 ? void 0 : _node$parent8$parent.parent, 'JSXOpeningElement') ? (_node$parent9 = node.parent) === null || _node$parent9 === void 0 ? void 0 : (_node$parent9$parent = _node$parent9.parent) === null || _node$parent9$parent === void 0 ? void 0 : _node$parent9$parent.parent.attributes.map(attribute => {
|
|
405
|
+
var _attribute$name;
|
|
406
|
+
return isNodeOfType(attribute, 'JSXAttribute') && isNodeOfType(attribute.name, 'JSXIdentifier') && (attribute === null || attribute === void 0 ? void 0 : (_attribute$name = attribute.name) === null || _attribute$name === void 0 ? void 0 : _attribute$name.name);
|
|
407
|
+
}).filter(Boolean) : [];
|
|
408
|
+
const hasIconBefore = legacyButtonAttributes.includes('iconBefore');
|
|
409
|
+
const hasIconAfter = legacyButtonAttributes.includes('iconAfter');
|
|
410
|
+
const hasChildren = ((_node$parent10 = node.parent) === null || _node$parent10 === void 0 ? void 0 : (_node$parent10$parent = _node$parent10.parent) === null || _node$parent10$parent === void 0 ? void 0 : (_node$parent10$parent2 = _node$parent10$parent.parent) === null || _node$parent10$parent2 === void 0 ? void 0 : _node$parent10$parent2.parent) && isNodeOfType((_node$parent11 = node.parent) === null || _node$parent11 === void 0 ? void 0 : (_node$parent11$parent = _node$parent11.parent) === null || _node$parent11$parent === void 0 ? void 0 : (_node$parent11$parent2 = _node$parent11$parent.parent) === null || _node$parent11$parent2 === void 0 ? void 0 : _node$parent11$parent2.parent, 'JSXElement') && ((_node$parent12 = node.parent) === null || _node$parent12 === void 0 ? void 0 : (_node$parent12$parent = _node$parent12.parent) === null || _node$parent12$parent === void 0 ? void 0 : (_node$parent12$parent2 = _node$parent12$parent.parent) === null || _node$parent12$parent2 === void 0 ? void 0 : _node$parent12$parent2.parent.children.length) > 0;
|
|
411
|
+
if (hasIconBefore && !hasIconAfter && !hasChildren || !hasIconBefore && hasIconAfter && !hasChildren || !hasIconBefore && !hasIconAfter && hasChildren) {
|
|
412
|
+
insideIconOnlyLegacyButton = true;
|
|
413
|
+
}
|
|
394
414
|
}
|
|
395
|
-
return
|
|
415
|
+
return insideIconOnlyLegacyButton;
|
|
396
416
|
};
|
|
397
417
|
const findProp = (attributes, propName) => attributes.find(attr => attr.type === 'JSXAttribute' && attr.name.name === propName);
|
|
398
418
|
const getNewIconNameForRenaming = (isInManualArray, importSource, importSpecifier) => {
|
|
@@ -2,7 +2,7 @@ function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol
|
|
|
2
2
|
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
3
3
|
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
4
4
|
import { isNodeOfType } from 'eslint-codemod-utils';
|
|
5
|
-
import { addToListOfRanges, canAutoMigrateNewIconBasedOnSize, canMigrateColor, createAutoMigrationError, createCantFindSuitableReplacementError, createCantMigrateColorError, createCantMigrateFunctionUnknownError, createCantMigrateIdentifierError, createCantMigrateIdentifierMapOrArrayError, createCantMigrateReExportError, createCantMigrateSizeUnknown, createCantMigrateSpreadPropsError, createGuidance, createHelpers, getMigrationMapObject, getUpcomingIcons, isInsideLegacyButton, isInsideNewButton, isSize, locToString, throwAutoErrors, throwManualErrors } from './helpers';
|
|
5
|
+
import { addToListOfRanges, canAutoMigrateNewIconBasedOnSize, canMigrateColor, createAutoMigrationError, createCantFindSuitableReplacementError, createCantMigrateColorError, createCantMigrateFunctionUnknownError, createCantMigrateIdentifierError, createCantMigrateIdentifierMapOrArrayError, createCantMigrateReExportError, createCantMigrateSizeUnknown, createCantMigrateSpreadPropsError, createGuidance, createHelpers, getMigrationMapObject, getUpcomingIcons, isInsideIconOnlyLegacyButton, isInsideLegacyButton, isInsideNewButton, isSize, locToString, throwAutoErrors, throwManualErrors } from './helpers';
|
|
6
6
|
export var createChecks = function createChecks(context) {
|
|
7
7
|
// Create global variables to be shared by the checks
|
|
8
8
|
var _createHelpers = createHelpers(context),
|
|
@@ -373,22 +373,13 @@ export var createChecks = function createChecks(context) {
|
|
|
373
373
|
|
|
374
374
|
// Flag icons imported from migration path
|
|
375
375
|
if (!shouldUseMigrationPath && Object.keys(migrationIconImports).includes(name)) {
|
|
376
|
-
var _sizeProp$value;
|
|
377
|
-
var sizeProp = node.openingElement.attributes.find(function (attribute) {
|
|
378
|
-
return attribute.type === 'JSXAttribute' && (attribute.name.name === 'size' || attribute.name.name === 'LEGACY_size');
|
|
379
|
-
});
|
|
380
|
-
var insideNewButton = isInsideNewButton(node, newButtonImports);
|
|
381
|
-
// Add spacious spacing if:
|
|
382
|
-
// 1. size is medium, or not set (default is medium)
|
|
383
|
-
// 2. not inside a new or legacy button
|
|
384
|
-
var shouldAddSpaciousSpacing = (sizeProp && sizeProp.type === 'JSXAttribute' && ((_sizeProp$value = sizeProp.value) === null || _sizeProp$value === void 0 ? void 0 : _sizeProp$value.type) === 'Literal' && sizeProp.value.value === 'medium' || !sizeProp) && !isInsideNewButton(node, newButtonImports) && !isInsideLegacyButton(node, legacyButtonImports);
|
|
385
376
|
createAutoMigrationError({
|
|
386
377
|
node: node,
|
|
387
378
|
importSource: migrationIconImports[name].packageName,
|
|
388
379
|
iconName: name,
|
|
389
380
|
errors: errorsAuto,
|
|
390
|
-
spacing:
|
|
391
|
-
insideNewButton:
|
|
381
|
+
spacing: undefined,
|
|
382
|
+
insideNewButton: true
|
|
392
383
|
});
|
|
393
384
|
}
|
|
394
385
|
|
|
@@ -397,11 +388,12 @@ export var createChecks = function createChecks(context) {
|
|
|
397
388
|
var _size, _size2;
|
|
398
389
|
// Determine if inside a new button - if so:
|
|
399
390
|
// - Assume spread props are safe - still error if props explicitly set to unmigratable values
|
|
400
|
-
var
|
|
391
|
+
var insideNewButton = isInsideNewButton(node, newButtonImports);
|
|
401
392
|
|
|
402
393
|
// Determine if inside a legacy default button - if so:
|
|
403
394
|
// the auto fixer will add spacing prop to the medium size icon
|
|
404
395
|
var insideLegacyButton = isInsideLegacyButton(node, legacyButtonImports);
|
|
396
|
+
var insideIconOnlyLegacyButton = isInsideIconOnlyLegacyButton(node, legacyButtonImports);
|
|
405
397
|
|
|
406
398
|
// Find size prop on node
|
|
407
399
|
var size = 'medium';
|
|
@@ -473,7 +465,7 @@ export var createChecks = function createChecks(context) {
|
|
|
473
465
|
// Do a set comparison - is requiredAttributesAfterSpread a subset of afterSpreadSet?
|
|
474
466
|
if (hasSpread === true && !Array.from(requiredAttributesAfterSpread).every(function (val) {
|
|
475
467
|
return afterSpreadSet.has(val);
|
|
476
|
-
}) && !
|
|
468
|
+
}) && !insideNewButton) {
|
|
477
469
|
var missingProps = Array.from(requiredAttributesAfterSpread).filter(function (val) {
|
|
478
470
|
return !afterSpreadSet.has(val);
|
|
479
471
|
});
|
|
@@ -493,20 +485,20 @@ export var createChecks = function createChecks(context) {
|
|
|
493
485
|
|
|
494
486
|
// Add spacing if:
|
|
495
487
|
// 1. size is medium for core/utility icons or small for utility icons, or not set (default is medium for core and small for utility icons)
|
|
496
|
-
// 2. not inside a new or legacy button
|
|
497
|
-
var
|
|
488
|
+
// 2. not inside a new or legacy button (except for icon-only legacy buttons)
|
|
489
|
+
var sizeProp = node.openingElement.attributes.find(function (attribute) {
|
|
498
490
|
return attribute.type === 'JSXAttribute' && (attribute.name.name === 'size' || attribute.name.name === 'LEGACY_size');
|
|
499
491
|
});
|
|
500
492
|
var spacing;
|
|
501
|
-
if (!
|
|
502
|
-
var _sizeProp$
|
|
503
|
-
if (
|
|
504
|
-
if (
|
|
493
|
+
if (!insideNewButton && !(insideLegacyButton && !insideIconOnlyLegacyButton)) {
|
|
494
|
+
var _sizeProp$value;
|
|
495
|
+
if (sizeProp && sizeProp.type === 'JSXAttribute' && ((_sizeProp$value = sizeProp.value) === null || _sizeProp$value === void 0 ? void 0 : _sizeProp$value.type) === 'Literal') {
|
|
496
|
+
if (sizeProp.value.value === 'medium') {
|
|
505
497
|
spacing = 'spacious';
|
|
506
|
-
} else if (
|
|
498
|
+
} else if (sizeProp.value.value === 'small' && (newIcon === null || newIcon === void 0 ? void 0 : newIcon.type) === 'utility') {
|
|
507
499
|
spacing = 'compact';
|
|
508
500
|
}
|
|
509
|
-
} else if (!
|
|
501
|
+
} else if (!sizeProp) {
|
|
510
502
|
spacing = 'spacious';
|
|
511
503
|
}
|
|
512
504
|
}
|
|
@@ -519,7 +511,7 @@ export var createChecks = function createChecks(context) {
|
|
|
519
511
|
iconName: name,
|
|
520
512
|
errors: errorsAuto,
|
|
521
513
|
spacing: spacing,
|
|
522
|
-
insideNewButton:
|
|
514
|
+
insideNewButton: insideNewButton
|
|
523
515
|
});
|
|
524
516
|
} else if ((!newIcon && !upcomingIcon || !isNewIconMigratable) && size) {
|
|
525
517
|
createCantFindSuitableReplacementError(node, legacyIconImports[name].packageName, name, errorsManual, upcomingIcon ? true : migrationMapObject ? true : false);
|
|
@@ -527,7 +519,7 @@ export var createChecks = function createChecks(context) {
|
|
|
527
519
|
addToListOfRanges(node, errorRanges);
|
|
528
520
|
guidance[locToString(node)] = createGuidance({
|
|
529
521
|
iconPackage: legacyIconImports[name].packageName,
|
|
530
|
-
insideNewButton:
|
|
522
|
+
insideNewButton: insideNewButton,
|
|
531
523
|
size: size && isSize(size) ? size : undefined,
|
|
532
524
|
shouldUseMigrationPath: shouldUseMigrationPath
|
|
533
525
|
});
|
|
@@ -397,11 +397,31 @@ export var isInsideNewButton = function isInsideNewButton(node, newButtonImports
|
|
|
397
397
|
*/
|
|
398
398
|
export var isInsideLegacyButton = function isInsideLegacyButton(node, legacyButtonImports) {
|
|
399
399
|
var _node$parent3, _node$parent4, _node$parent5, _node$parent6;
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
400
|
+
return node.parent && isNodeOfType(node.parent, 'JSXExpressionContainer') && ((_node$parent3 = node.parent) === null || _node$parent3 === void 0 ? 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);
|
|
401
|
+
};
|
|
402
|
+
|
|
403
|
+
/**
|
|
404
|
+
*
|
|
405
|
+
* @param node Icon JSXelement
|
|
406
|
+
* @param newButtonImports list of legacy button import specifiers
|
|
407
|
+
* @returns if Icon is inside a legacy button
|
|
408
|
+
*/
|
|
409
|
+
export var isInsideIconOnlyLegacyButton = function isInsideIconOnlyLegacyButton(node, legacyButtonImports) {
|
|
410
|
+
var insideIconOnlyLegacyButton = false;
|
|
411
|
+
if (isInsideLegacyButton(node, legacyButtonImports)) {
|
|
412
|
+
var _node$parent7, _node$parent8, _node$parent9, _node$parent10, _node$parent11, _node$parent12;
|
|
413
|
+
var legacyButtonAttributes = node.parent && isNodeOfType(node.parent, 'JSXExpressionContainer') && (_node$parent7 = node.parent) !== null && _node$parent7 !== void 0 && _node$parent7.parent && isNodeOfType(node.parent.parent, 'JSXAttribute') && node.parent.parent.parent && isNodeOfType((_node$parent8 = node.parent) === null || _node$parent8 === void 0 || (_node$parent8 = _node$parent8.parent) === null || _node$parent8 === void 0 ? void 0 : _node$parent8.parent, 'JSXOpeningElement') ? (_node$parent9 = node.parent) === null || _node$parent9 === void 0 || (_node$parent9 = _node$parent9.parent) === null || _node$parent9 === void 0 ? void 0 : _node$parent9.parent.attributes.map(function (attribute) {
|
|
414
|
+
var _attribute$name;
|
|
415
|
+
return isNodeOfType(attribute, 'JSXAttribute') && isNodeOfType(attribute.name, 'JSXIdentifier') && (attribute === null || attribute === void 0 || (_attribute$name = attribute.name) === null || _attribute$name === void 0 ? void 0 : _attribute$name.name);
|
|
416
|
+
}).filter(Boolean) : [];
|
|
417
|
+
var hasIconBefore = legacyButtonAttributes.includes('iconBefore');
|
|
418
|
+
var hasIconAfter = legacyButtonAttributes.includes('iconAfter');
|
|
419
|
+
var hasChildren = ((_node$parent10 = node.parent) === null || _node$parent10 === void 0 || (_node$parent10 = _node$parent10.parent) === null || _node$parent10 === void 0 || (_node$parent10 = _node$parent10.parent) === null || _node$parent10 === void 0 ? void 0 : _node$parent10.parent) && isNodeOfType((_node$parent11 = node.parent) === null || _node$parent11 === void 0 || (_node$parent11 = _node$parent11.parent) === null || _node$parent11 === void 0 || (_node$parent11 = _node$parent11.parent) === null || _node$parent11 === void 0 ? void 0 : _node$parent11.parent, 'JSXElement') && ((_node$parent12 = node.parent) === null || _node$parent12 === void 0 || (_node$parent12 = _node$parent12.parent) === null || _node$parent12 === void 0 || (_node$parent12 = _node$parent12.parent) === null || _node$parent12 === void 0 ? void 0 : _node$parent12.parent.children.length) > 0;
|
|
420
|
+
if (hasIconBefore && !hasIconAfter && !hasChildren || !hasIconBefore && hasIconAfter && !hasChildren || !hasIconBefore && !hasIconAfter && hasChildren) {
|
|
421
|
+
insideIconOnlyLegacyButton = true;
|
|
422
|
+
}
|
|
403
423
|
}
|
|
404
|
-
return
|
|
424
|
+
return insideIconOnlyLegacyButton;
|
|
405
425
|
};
|
|
406
426
|
var findProp = function findProp(attributes, propName) {
|
|
407
427
|
return attributes.find(function (attr) {
|
|
@@ -119,6 +119,13 @@ export declare const isInsideNewButton: (node: Rule.Node, newButtonImports: Set<
|
|
|
119
119
|
* @returns if Icon is inside a legacy button
|
|
120
120
|
*/
|
|
121
121
|
export declare const isInsideLegacyButton: (node: Rule.Node, legacyButtonImports: Set<string>) => boolean;
|
|
122
|
+
/**
|
|
123
|
+
*
|
|
124
|
+
* @param node Icon JSXelement
|
|
125
|
+
* @param newButtonImports list of legacy button import specifiers
|
|
126
|
+
* @returns if Icon is inside a legacy button
|
|
127
|
+
*/
|
|
128
|
+
export declare const isInsideIconOnlyLegacyButton: (node: Rule.Node, legacyButtonImports: Set<string>) => boolean;
|
|
122
129
|
export declare const throwManualErrors: ({ errorsManual, errorRanges, guidance, context, isQuietMode, }: {
|
|
123
130
|
errorsManual: ErrorListManual;
|
|
124
131
|
errorRanges: RangeList;
|
|
@@ -124,6 +124,13 @@ export declare const isInsideNewButton: (node: Rule.Node, newButtonImports: Set<
|
|
|
124
124
|
* @returns if Icon is inside a legacy button
|
|
125
125
|
*/
|
|
126
126
|
export declare const isInsideLegacyButton: (node: Rule.Node, legacyButtonImports: Set<string>) => boolean;
|
|
127
|
+
/**
|
|
128
|
+
*
|
|
129
|
+
* @param node Icon JSXelement
|
|
130
|
+
* @param newButtonImports list of legacy button import specifiers
|
|
131
|
+
* @returns if Icon is inside a legacy button
|
|
132
|
+
*/
|
|
133
|
+
export declare const isInsideIconOnlyLegacyButton: (node: Rule.Node, legacyButtonImports: Set<string>) => boolean;
|
|
127
134
|
export declare const throwManualErrors: ({ errorsManual, errorRanges, guidance, context, isQuietMode, }: {
|
|
128
135
|
errorsManual: ErrorListManual;
|
|
129
136
|
errorRanges: RangeList;
|
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": "11.8.
|
|
4
|
+
"version": "11.8.4",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"publishConfig": {
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"dependencies": {
|
|
46
46
|
"@atlaskit/eslint-utils": "^1.8.0",
|
|
47
47
|
"@atlaskit/icon": "^23.4.0",
|
|
48
|
-
"@atlaskit/icon-lab": "^2.
|
|
48
|
+
"@atlaskit/icon-lab": "^2.2.0",
|
|
49
49
|
"@atlaskit/tokens": "*",
|
|
50
50
|
"@babel/runtime": "^7.0.0",
|
|
51
51
|
"@typescript-eslint/utils": "^7.1.0",
|