@atlaskit/eslint-plugin-design-system 10.12.2 → 10.12.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 +17 -0
- package/dist/cjs/rules/no-legacy-icons/checks.js +13 -12
- package/dist/cjs/rules/no-legacy-icons/helpers.js +70 -24
- package/dist/cjs/rules/no-legacy-icons/upcoming-icons.js +7 -0
- package/dist/es2019/rules/no-legacy-icons/checks.js +11 -10
- package/dist/es2019/rules/no-legacy-icons/helpers.js +52 -11
- package/dist/es2019/rules/no-legacy-icons/upcoming-icons.js +1 -0
- package/dist/esm/rules/no-legacy-icons/checks.js +11 -10
- package/dist/esm/rules/no-legacy-icons/helpers.js +69 -23
- package/dist/esm/rules/no-legacy-icons/upcoming-icons.js +1 -0
- package/dist/types/rules/no-legacy-icons/helpers.d.ts +8 -13
- package/dist/types/rules/no-legacy-icons/upcoming-icons.d.ts +1 -0
- package/dist/types-ts4.5/rules/no-legacy-icons/helpers.d.ts +13 -13
- package/dist/types-ts4.5/rules/no-legacy-icons/upcoming-icons.d.ts +1 -0
- package/package.json +2 -1
- package/dist/cjs/rules/no-legacy-icons/migration-map-temp.js +0 -4090
- package/dist/es2019/rules/no-legacy-icons/migration-map-temp.js +0 -4082
- package/dist/esm/rules/no-legacy-icons/migration-map-temp.js +0 -4084
- package/dist/types/rules/no-legacy-icons/migration-map-temp.d.ts +0 -22
- package/dist/types-ts4.5/rules/no-legacy-icons/migration-map-temp.d.ts +0 -27
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# @atlaskit/eslint-plugin-design-system
|
|
2
2
|
|
|
3
|
+
## 10.12.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#126974](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/126974)
|
|
8
|
+
[`bf10ab6817404`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/bf10ab6817404) -
|
|
9
|
+
Updates the no-legacy-icons eslint rule to account for upcoming icons.
|
|
10
|
+
|
|
11
|
+
## 10.12.3
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- [#126553](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/126553)
|
|
16
|
+
[`a8d7e60d3b69d`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/a8d7e60d3b69d) -
|
|
17
|
+
Update `no-legacy-icons` rule to use icon migration map from `@atlaskit/icon`.
|
|
18
|
+
- Updated dependencies
|
|
19
|
+
|
|
3
20
|
## 10.12.2
|
|
4
21
|
|
|
5
22
|
### Patch Changes
|
|
@@ -8,7 +8,6 @@ exports.createChecks = void 0;
|
|
|
8
8
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
9
9
|
var _eslintCodemodUtils = require("eslint-codemod-utils");
|
|
10
10
|
var _helpers = require("./helpers");
|
|
11
|
-
var _migrationMapTemp = require("./migration-map-temp");
|
|
12
11
|
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
13
12
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
14
13
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
@@ -233,13 +232,14 @@ var createChecks = exports.createChecks = function createChecks(context) {
|
|
|
233
232
|
if (node.name in legacyIconImports && (0, _eslintCodemodUtils.isNodeOfType)(node.parent.parent.name, 'JSXIdentifier') && node.parent.parent.name.name !== 'LEGACY_fallbackIcon') {
|
|
234
233
|
var _migrationMapObject$s;
|
|
235
234
|
var migrationMapObject = (0, _helpers.getMigrationMapObject)(legacyIconImports[node.name].packageName);
|
|
235
|
+
var upcomingIcon = (0, _helpers.getUpcomingIcons)(legacyIconImports[node.name].packageName);
|
|
236
236
|
var newIcon = migrationMapObject === null || migrationMapObject === void 0 ? void 0 : migrationMapObject.newIcon;
|
|
237
|
-
var isNewIconMigratable = (0, _helpers.canAutoMigrateNewIconBasedOnSize)(migrationMapObject === null || migrationMapObject === void 0 || (_migrationMapObject$s = migrationMapObject.sizeGuidance) === null || _migrationMapObject$s === void 0 ? void 0 : _migrationMapObject$s.medium);
|
|
237
|
+
var isNewIconMigratable = (0, _helpers.canAutoMigrateNewIconBasedOnSize)(upcomingIcon ? upcomingIcon.sizeGuidance.medium : migrationMapObject === null || migrationMapObject === void 0 || (_migrationMapObject$s = migrationMapObject.sizeGuidance) === null || _migrationMapObject$s === void 0 ? void 0 : _migrationMapObject$s.medium);
|
|
238
238
|
var isInNewButton = (0, _eslintCodemodUtils.isNodeOfType)(node.parent.parent.parent.name, 'JSXIdentifier') && newButtonImports.has(node.parent.parent.parent.name.name);
|
|
239
|
-
if (newIcon && isInNewButton && isNewIconMigratable) {
|
|
239
|
+
if (newIcon && isInNewButton && isNewIconMigratable || upcomingIcon && isInNewButton && isNewIconMigratable) {
|
|
240
240
|
(0, _helpers.createAutoMigrationError)(node, legacyIconImports[node.name].packageName, node.name, errorsAuto);
|
|
241
241
|
guidance[(0, _helpers.locToString)(node)] = (0, _helpers.createGuidance)(legacyIconImports[node.name].packageName, isInNewButton, 'medium');
|
|
242
|
-
} else if (!newIcon || !isNewIconMigratable) {
|
|
242
|
+
} else if (!newIcon && !upcomingIcon || !isNewIconMigratable) {
|
|
243
243
|
(0, _helpers.createCantFindSuitableReplacementError)(node, legacyIconImports[node.name].packageName, node.name, errorsManual);
|
|
244
244
|
guidance[(0, _helpers.locToString)(node)] = (0, _helpers.createGuidance)(legacyIconImports[node.name].packageName, isInNewButton);
|
|
245
245
|
} else if (!isInNewButton) {
|
|
@@ -266,7 +266,7 @@ var createChecks = exports.createChecks = function createChecks(context) {
|
|
|
266
266
|
var name = node.openingElement.name.name;
|
|
267
267
|
// Legacy icons rendered as JSX elements
|
|
268
268
|
if (name in legacyIconImports) {
|
|
269
|
-
var _node$parent2, _node$parent3, _size;
|
|
269
|
+
var _node$parent2, _node$parent3, _size, _size2;
|
|
270
270
|
// Determine if inside a new button - if so:
|
|
271
271
|
// - Assume spread props are safe - still error if props explicitly set to unmigratable values
|
|
272
272
|
var insideNewButton = false;
|
|
@@ -303,9 +303,9 @@ var createChecks = exports.createChecks = function createChecks(context) {
|
|
|
303
303
|
// Extract values of props
|
|
304
304
|
switch (attr.name.name) {
|
|
305
305
|
case 'size':
|
|
306
|
-
if ((0, _eslintCodemodUtils.isNodeOfType)(attr.value, 'Literal') && (0,
|
|
306
|
+
if ((0, _eslintCodemodUtils.isNodeOfType)(attr.value, 'Literal') && (0, _helpers.isSize)(attr.value.value)) {
|
|
307
307
|
size = attr.value.value;
|
|
308
|
-
} else if ((0, _eslintCodemodUtils.isNodeOfType)(attr.value, 'JSXExpressionContainer') && (0, _eslintCodemodUtils.isNodeOfType)(attr.value.expression, 'Literal') && (0,
|
|
308
|
+
} else if ((0, _eslintCodemodUtils.isNodeOfType)(attr.value, 'JSXExpressionContainer') && (0, _eslintCodemodUtils.isNodeOfType)(attr.value.expression, 'Literal') && (0, _helpers.isSize)(attr.value.expression.value)) {
|
|
309
309
|
size = attr.value.expression.value;
|
|
310
310
|
} else {
|
|
311
311
|
size = null;
|
|
@@ -350,14 +350,15 @@ var createChecks = exports.createChecks = function createChecks(context) {
|
|
|
350
350
|
hasManualMigration = true;
|
|
351
351
|
}
|
|
352
352
|
var migrationMapObject = (0, _helpers.getMigrationMapObject)(legacyIconImports[name].packageName);
|
|
353
|
+
var upcomingIcon = (0, _helpers.getUpcomingIcons)(legacyIconImports[name].packageName);
|
|
353
354
|
var newIcon = migrationMapObject === null || migrationMapObject === void 0 ? void 0 : migrationMapObject.newIcon;
|
|
354
|
-
var isNewIconMigratable = (0, _helpers.canAutoMigrateNewIconBasedOnSize)(migrationMapObject === null || migrationMapObject === void 0 ? void 0 : migrationMapObject.sizeGuidance[(
|
|
355
|
-
if (!hasManualMigration && newIcon && isNewIconMigratable) {
|
|
355
|
+
var isNewIconMigratable = (0, _helpers.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']);
|
|
356
|
+
if (!hasManualMigration && (newIcon || upcomingIcon) && isNewIconMigratable) {
|
|
356
357
|
(0, _helpers.createAutoMigrationError)(node, legacyIconImports[name].packageName, name, errorsAuto);
|
|
357
|
-
} else if ((!newIcon || !isNewIconMigratable) && size) {
|
|
358
|
-
(0, _helpers.createCantFindSuitableReplacementError)(node, legacyIconImports[name].packageName, name, errorsManual, migrationMapObject ? true : false);
|
|
358
|
+
} else if ((!newIcon && !upcomingIcon || !isNewIconMigratable) && size) {
|
|
359
|
+
(0, _helpers.createCantFindSuitableReplacementError)(node, legacyIconImports[name].packageName, name, errorsManual, upcomingIcon ? true : migrationMapObject ? true : false);
|
|
359
360
|
}
|
|
360
|
-
guidance[(0, _helpers.locToString)(node)] = (0, _helpers.createGuidance)(legacyIconImports[name].packageName, insideNewButton, size && (0,
|
|
361
|
+
guidance[(0, _helpers.locToString)(node)] = (0, _helpers.createGuidance)(legacyIconImports[name].packageName, insideNewButton, size && (0, _helpers.isSize)(size) ? size : undefined);
|
|
361
362
|
}
|
|
362
363
|
};
|
|
363
364
|
|
|
@@ -5,13 +5,19 @@ var _typeof = require("@babel/runtime/helpers/typeof");
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
-
exports.locToString = exports.getMigrationMapObject = exports.getLiteralStringValue = exports.createHelpers = exports.createGuidance = exports.createCantMigrateSpreadPropsError = exports.createCantMigrateSizeUnknown = exports.createCantMigrateReExportError = exports.createCantMigrateIdentifierError = exports.createCantMigrateFunctionUnknownError = exports.createCantMigrateColorError = exports.createCantFindSuitableReplacementError = exports.createAutoMigrationError = exports.canMigrateColor = exports.canAutoMigrateNewIconBasedOnSize = void 0;
|
|
8
|
+
exports.locToString = exports.isSize = exports.getUpcomingIcons = exports.getMigrationMapObject = exports.getLiteralStringValue = exports.createHelpers = exports.createGuidance = exports.createCantMigrateSpreadPropsError = exports.createCantMigrateSizeUnknown = exports.createCantMigrateReExportError = exports.createCantMigrateIdentifierError = exports.createCantMigrateFunctionUnknownError = exports.createCantMigrateColorError = exports.createCantFindSuitableReplacementError = exports.createAutoMigrationError = exports.canMigrateColor = exports.canAutoMigrateNewIconBasedOnSize = void 0;
|
|
9
9
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
10
10
|
var _eslintCodemodUtils = require("eslint-codemod-utils");
|
|
11
|
+
var _UNSAFE_migrationMap = _interopRequireWildcard(require("@atlaskit/icon/UNSAFE_migration-map"));
|
|
11
12
|
var _getImportName = require("../utils/get-import-name");
|
|
12
|
-
var
|
|
13
|
+
var _upcomingIcons = require("./upcoming-icons");
|
|
13
14
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
14
15
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
16
|
+
var sizes = ['small', 'medium', 'large', 'xlarge'];
|
|
17
|
+
var isSize = exports.isSize = function isSize(size) {
|
|
18
|
+
return sizes.includes(size);
|
|
19
|
+
};
|
|
20
|
+
|
|
15
21
|
/**
|
|
16
22
|
* Returns the migration map object for a legacy icon or null if not found
|
|
17
23
|
* @param iconPackage The name of the legacy icon package
|
|
@@ -19,8 +25,23 @@ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e;
|
|
|
19
25
|
*/
|
|
20
26
|
var getMigrationMapObject = exports.getMigrationMapObject = function getMigrationMapObject(iconPackage) {
|
|
21
27
|
var key = getIconKey(iconPackage);
|
|
22
|
-
if (
|
|
23
|
-
return
|
|
28
|
+
if (Object.keys(_UNSAFE_migrationMap.default).includes(key)) {
|
|
29
|
+
return _UNSAFE_migrationMap.default[key];
|
|
30
|
+
}
|
|
31
|
+
return null;
|
|
32
|
+
};
|
|
33
|
+
var getUpcomingIcons = exports.getUpcomingIcons = function getUpcomingIcons(iconPackage) {
|
|
34
|
+
var key = getIconKey(iconPackage);
|
|
35
|
+
if (_upcomingIcons.upcomingIcons.includes(key)) {
|
|
36
|
+
var retval = {
|
|
37
|
+
sizeGuidance: {
|
|
38
|
+
small: 'swap',
|
|
39
|
+
medium: 'swap',
|
|
40
|
+
large: 'icon-tile',
|
|
41
|
+
xlarge: 'icon-tile'
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
return retval;
|
|
24
45
|
}
|
|
25
46
|
return null;
|
|
26
47
|
};
|
|
@@ -49,42 +70,67 @@ var createGuidance = exports.createGuidance = function createGuidance(iconPackag
|
|
|
49
70
|
var insideNewButton = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
50
71
|
var size = arguments.length > 2 ? arguments[2] : undefined;
|
|
51
72
|
var migrationMapObject = getMigrationMapObject(iconPackage);
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
if (!newIcon) {
|
|
55
|
-
return 'No equivalent icon in new set. An option is to contribute a custom icon into icon-labs package instead.\n';
|
|
56
|
-
}
|
|
57
|
-
var buttonGuidanceStr = "Please set 'spacing' property of the new icon to 'none', to ensure appropriate spacing inside `@atlaskit/button`.\n";
|
|
73
|
+
var upcomingIcon = getUpcomingIcons(iconPackage);
|
|
74
|
+
if (upcomingIcon) {
|
|
58
75
|
var guidance = '';
|
|
59
76
|
if (size) {
|
|
60
|
-
if (
|
|
61
|
-
guidance += "Fix:
|
|
77
|
+
if (upcomingIcon.sizeGuidance[size] && canAutoMigrateNewIconBasedOnSize(upcomingIcon.sizeGuidance[size])) {
|
|
78
|
+
guidance += "Fix: An upcoming icon release is planned to migrate this legacy icon.";
|
|
62
79
|
} else {
|
|
63
|
-
guidance += "No equivalent icon for this size, ".concat(size, ", in
|
|
80
|
+
guidance += "No equivalent icon for this size, ".concat(size, ", in the current or upcoming set of icons.");
|
|
64
81
|
}
|
|
65
|
-
guidance += "".concat(
|
|
82
|
+
guidance += "".concat(Object.keys(_UNSAFE_migrationMap.migrationOutcomeDescriptionMap).includes(upcomingIcon.sizeGuidance[size]) ? " Once the upcoming icons are released, please: ".concat(_UNSAFE_migrationMap.migrationOutcomeDescriptionMap[upcomingIcon.sizeGuidance[size]]) : ' No migration size advice given.', "\n");
|
|
66
83
|
} else {
|
|
67
|
-
guidance = "
|
|
68
|
-
for (var _i = 0, _Object$entries = Object.entries(
|
|
84
|
+
guidance = "Please wait for the upcoming icons released, as it will contain an alternative for this legacy icon.\nMigration suggestions, depending on the legacy icon size:\n";
|
|
85
|
+
for (var _i = 0, _Object$entries = Object.entries(upcomingIcon.sizeGuidance); _i < _Object$entries.length; _i++) {
|
|
69
86
|
var _Object$entries$_i = (0, _slicedToArray2.default)(_Object$entries[_i], 2),
|
|
70
87
|
_size = _Object$entries$_i[0],
|
|
71
88
|
value = _Object$entries$_i[1];
|
|
72
89
|
guidance += "\t- ".concat(_size, ": ");
|
|
73
|
-
if (!(
|
|
90
|
+
if (!Object.keys(_UNSAFE_migrationMap.migrationOutcomeDescriptionMap).includes(value)) {
|
|
74
91
|
guidance += 'No migration advice given.\n';
|
|
75
92
|
} else {
|
|
76
|
-
guidance += "".concat(
|
|
93
|
+
guidance += "".concat(_UNSAFE_migrationMap.migrationOutcomeDescriptionMap[value], ".\n");
|
|
77
94
|
}
|
|
78
95
|
}
|
|
79
96
|
}
|
|
97
|
+
return guidance;
|
|
98
|
+
} else if (migrationMapObject) {
|
|
99
|
+
var newIcon = migrationMapObject.newIcon;
|
|
100
|
+
if (!newIcon) {
|
|
101
|
+
return 'No equivalent icon in new set. An option is to contribute a custom icon into icon-labs package instead.\n';
|
|
102
|
+
}
|
|
103
|
+
var buttonGuidanceStr = "Please set 'spacing' property of the new icon to 'none', to ensure appropriate spacing inside `@atlaskit/button`.\n";
|
|
104
|
+
var _guidance = '';
|
|
105
|
+
if (size) {
|
|
106
|
+
if (migrationMapObject.sizeGuidance[size] && canAutoMigrateNewIconBasedOnSize(migrationMapObject.sizeGuidance[size])) {
|
|
107
|
+
_guidance += "Fix: Use ".concat(newIcon.name, " from ").concat(newIcon.package, "/").concat(newIcon.type, "/").concat(newIcon.name, " instead.");
|
|
108
|
+
} else {
|
|
109
|
+
_guidance += "No equivalent icon for this size, ".concat(size, ", in new set.");
|
|
110
|
+
}
|
|
111
|
+
_guidance += "".concat(migrationMapObject.sizeGuidance[size] in _UNSAFE_migrationMap.migrationOutcomeDescriptionMap ? " Please: ".concat(_UNSAFE_migrationMap.migrationOutcomeDescriptionMap[migrationMapObject.sizeGuidance[size]]) : ' No migration size advice given.', "\n");
|
|
112
|
+
} else {
|
|
113
|
+
_guidance = "Use ".concat(newIcon.name, " from ").concat(newIcon.package, "/").concat(newIcon.type, "/").concat(newIcon.name, " instead.\nMigration suggestions, depending on the legacy icon size:\n");
|
|
114
|
+
Object.entries(migrationMapObject.sizeGuidance).forEach(function (_ref) {
|
|
115
|
+
var _ref2 = (0, _slicedToArray2.default)(_ref, 2),
|
|
116
|
+
size = _ref2[0],
|
|
117
|
+
value = _ref2[1];
|
|
118
|
+
_guidance += "\t- ".concat(size, ": ");
|
|
119
|
+
if (!(value in _UNSAFE_migrationMap.migrationOutcomeDescriptionMap)) {
|
|
120
|
+
_guidance += 'No migration advice given.\n';
|
|
121
|
+
} else {
|
|
122
|
+
_guidance += "".concat(_UNSAFE_migrationMap.migrationOutcomeDescriptionMap[value], ".\n");
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
}
|
|
80
126
|
if (insideNewButton) {
|
|
81
|
-
|
|
127
|
+
_guidance += buttonGuidanceStr;
|
|
82
128
|
} else if (size && size === 'medium') {
|
|
83
|
-
|
|
129
|
+
_guidance += "Setting the spacing property to 'spacious' will maintain the icon's box dimensions - but consider setting spacing='none' as it allows for easier control of spacing by parent elements.\n";
|
|
84
130
|
} else if (size) {
|
|
85
|
-
|
|
131
|
+
_guidance += "In the new icon, please use spacing='none'.\n";
|
|
86
132
|
}
|
|
87
|
-
return
|
|
133
|
+
return _guidance;
|
|
88
134
|
} else {
|
|
89
135
|
return "Migration suggestions not found for \"".concat(iconPackage, "\".\n");
|
|
90
136
|
}
|
|
@@ -254,9 +300,9 @@ var createHelpers = exports.createHelpers = function createHelpers(context) {
|
|
|
254
300
|
* Extracts the primaryColor value from a JSXAttribute
|
|
255
301
|
*/
|
|
256
302
|
getPrimaryColor: function getPrimaryColor(attr) {
|
|
257
|
-
var
|
|
303
|
+
var _ref3, _getLiteralStringValu;
|
|
258
304
|
var value = attr.value;
|
|
259
|
-
return (
|
|
305
|
+
return (_ref3 = (_getLiteralStringValu = getLiteralStringValue(value)) !== null && _getLiteralStringValu !== void 0 ? _getLiteralStringValu : getTokenCallValue(value)) !== null && _ref3 !== void 0 ? _ref3 : null;
|
|
260
306
|
},
|
|
261
307
|
getTokenCallValue: getTokenCallValue,
|
|
262
308
|
getConfigFlag: getConfigFlag
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.upcomingIcons = void 0;
|
|
7
|
+
var upcomingIcons = exports.upcomingIcons = ['app-switcher', 'check-circle-outline', 'export', 'file', 'flag-filled', 'lightbulb-filled', 'lock-filled', 'menu-expand', 'menu', 'notification-direct', 'notification', 'people-group', 'people', 'refresh', 'switcher', 'editor/align-image-center', 'editor/align-image-left', 'editor/align-image-right', 'editor/background-color', 'editor/bold', 'editor/indent', 'editor/italic', 'editor/horizontal-rule', 'editor-layout-three-equal', 'editor-layout-three-with-sidebars', 'editor/layout-two-equal', 'editor/layout-two-left-sidebars', 'editor/layout-two-right-sidebar', 'editor/media-center', 'editor/media-full-width', 'editor/media-wide', 'editor/number-list', 'emoji/activity', 'editor/file', 'emoji/flags', 'emoji/food', 'emoji/nature', 'emoji/people', 'emoji/productivity', 'emoji/travel', 'bitbucket/repos'];
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { isNodeOfType } from 'eslint-codemod-utils';
|
|
2
|
-
import { canAutoMigrateNewIconBasedOnSize, canMigrateColor, createAutoMigrationError, createCantFindSuitableReplacementError, createCantMigrateColorError, createCantMigrateFunctionUnknownError, createCantMigrateIdentifierError, createCantMigrateReExportError, createCantMigrateSizeUnknown, createCantMigrateSpreadPropsError, createGuidance, createHelpers, getMigrationMapObject, locToString } from './helpers';
|
|
3
|
-
import { isSize } from './migration-map-temp';
|
|
2
|
+
import { canAutoMigrateNewIconBasedOnSize, canMigrateColor, createAutoMigrationError, createCantFindSuitableReplacementError, createCantMigrateColorError, createCantMigrateFunctionUnknownError, createCantMigrateIdentifierError, createCantMigrateReExportError, createCantMigrateSizeUnknown, createCantMigrateSpreadPropsError, createGuidance, createHelpers, getMigrationMapObject, getUpcomingIcons, isSize, locToString } from './helpers';
|
|
4
3
|
export const createChecks = context => {
|
|
5
4
|
//create global variables to be shared by the checks
|
|
6
5
|
const {
|
|
@@ -165,13 +164,14 @@ export const createChecks = context => {
|
|
|
165
164
|
if (node.name in legacyIconImports && isNodeOfType(node.parent.parent.name, 'JSXIdentifier') && node.parent.parent.name.name !== 'LEGACY_fallbackIcon') {
|
|
166
165
|
var _migrationMapObject$s;
|
|
167
166
|
const migrationMapObject = getMigrationMapObject(legacyIconImports[node.name].packageName);
|
|
167
|
+
const upcomingIcon = getUpcomingIcons(legacyIconImports[node.name].packageName);
|
|
168
168
|
const newIcon = migrationMapObject === null || migrationMapObject === void 0 ? void 0 : migrationMapObject.newIcon;
|
|
169
|
-
const isNewIconMigratable = canAutoMigrateNewIconBasedOnSize(migrationMapObject === null || migrationMapObject === void 0 ? void 0 : (_migrationMapObject$s = migrationMapObject.sizeGuidance) === null || _migrationMapObject$s === void 0 ? void 0 : _migrationMapObject$s.medium);
|
|
169
|
+
const isNewIconMigratable = canAutoMigrateNewIconBasedOnSize(upcomingIcon ? upcomingIcon.sizeGuidance.medium : migrationMapObject === null || migrationMapObject === void 0 ? void 0 : (_migrationMapObject$s = migrationMapObject.sizeGuidance) === null || _migrationMapObject$s === void 0 ? void 0 : _migrationMapObject$s.medium);
|
|
170
170
|
const isInNewButton = isNodeOfType(node.parent.parent.parent.name, 'JSXIdentifier') && newButtonImports.has(node.parent.parent.parent.name.name);
|
|
171
|
-
if (newIcon && isInNewButton && isNewIconMigratable) {
|
|
171
|
+
if (newIcon && isInNewButton && isNewIconMigratable || upcomingIcon && isInNewButton && isNewIconMigratable) {
|
|
172
172
|
createAutoMigrationError(node, legacyIconImports[node.name].packageName, node.name, errorsAuto);
|
|
173
173
|
guidance[locToString(node)] = createGuidance(legacyIconImports[node.name].packageName, isInNewButton, 'medium');
|
|
174
|
-
} else if (!newIcon || !isNewIconMigratable) {
|
|
174
|
+
} else if (!newIcon && !upcomingIcon || !isNewIconMigratable) {
|
|
175
175
|
createCantFindSuitableReplacementError(node, legacyIconImports[node.name].packageName, node.name, errorsManual);
|
|
176
176
|
guidance[locToString(node)] = createGuidance(legacyIconImports[node.name].packageName, isInNewButton);
|
|
177
177
|
} else if (!isInNewButton) {
|
|
@@ -198,7 +198,7 @@ export const createChecks = context => {
|
|
|
198
198
|
const name = node.openingElement.name.name;
|
|
199
199
|
// Legacy icons rendered as JSX elements
|
|
200
200
|
if (name in legacyIconImports) {
|
|
201
|
-
var _node$parent2, _node$parent2$parent, _node$parent3, _node$parent3$parent, _node$parent3$parent$, _size;
|
|
201
|
+
var _node$parent2, _node$parent2$parent, _node$parent3, _node$parent3$parent, _node$parent3$parent$, _size, _size2;
|
|
202
202
|
// Determine if inside a new button - if so:
|
|
203
203
|
// - Assume spread props are safe - still error if props explicitly set to unmigratable values
|
|
204
204
|
let insideNewButton = false;
|
|
@@ -269,12 +269,13 @@ export const createChecks = context => {
|
|
|
269
269
|
hasManualMigration = true;
|
|
270
270
|
}
|
|
271
271
|
const migrationMapObject = getMigrationMapObject(legacyIconImports[name].packageName);
|
|
272
|
+
const upcomingIcon = getUpcomingIcons(legacyIconImports[name].packageName);
|
|
272
273
|
const newIcon = migrationMapObject === null || migrationMapObject === void 0 ? void 0 : migrationMapObject.newIcon;
|
|
273
|
-
const isNewIconMigratable = canAutoMigrateNewIconBasedOnSize(migrationMapObject === null || migrationMapObject === void 0 ? void 0 : migrationMapObject.sizeGuidance[(
|
|
274
|
-
if (!hasManualMigration && newIcon && isNewIconMigratable) {
|
|
274
|
+
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']);
|
|
275
|
+
if (!hasManualMigration && (newIcon || upcomingIcon) && isNewIconMigratable) {
|
|
275
276
|
createAutoMigrationError(node, legacyIconImports[name].packageName, name, errorsAuto);
|
|
276
|
-
} else if ((!newIcon || !isNewIconMigratable) && size) {
|
|
277
|
-
createCantFindSuitableReplacementError(node, legacyIconImports[name].packageName, name, errorsManual, migrationMapObject ? true : false);
|
|
277
|
+
} else if ((!newIcon && !upcomingIcon || !isNewIconMigratable) && size) {
|
|
278
|
+
createCantFindSuitableReplacementError(node, legacyIconImports[name].packageName, name, errorsManual, upcomingIcon ? true : migrationMapObject ? true : false);
|
|
278
279
|
}
|
|
279
280
|
guidance[locToString(node)] = createGuidance(legacyIconImports[name].packageName, insideNewButton, size && isSize(size) ? size : undefined);
|
|
280
281
|
}
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { isNodeOfType } from 'eslint-codemod-utils';
|
|
2
|
+
import baseMigrationMap, { migrationOutcomeDescriptionMap } from '@atlaskit/icon/UNSAFE_migration-map';
|
|
2
3
|
import { getImportName } from '../utils/get-import-name';
|
|
3
|
-
import
|
|
4
|
+
import { upcomingIcons } from './upcoming-icons';
|
|
5
|
+
const sizes = ['small', 'medium', 'large', 'xlarge'];
|
|
6
|
+
export const isSize = size => sizes.includes(size);
|
|
7
|
+
|
|
4
8
|
/**
|
|
5
9
|
* Returns the migration map object for a legacy icon or null if not found
|
|
6
10
|
* @param iconPackage The name of the legacy icon package
|
|
@@ -8,8 +12,23 @@ import migrationMap, { outcomeDescriptionMap } from './migration-map-temp';
|
|
|
8
12
|
*/
|
|
9
13
|
export const getMigrationMapObject = iconPackage => {
|
|
10
14
|
const key = getIconKey(iconPackage);
|
|
11
|
-
if (key
|
|
12
|
-
return
|
|
15
|
+
if (Object.keys(baseMigrationMap).includes(key)) {
|
|
16
|
+
return baseMigrationMap[key];
|
|
17
|
+
}
|
|
18
|
+
return null;
|
|
19
|
+
};
|
|
20
|
+
export const getUpcomingIcons = iconPackage => {
|
|
21
|
+
const key = getIconKey(iconPackage);
|
|
22
|
+
if (upcomingIcons.includes(key)) {
|
|
23
|
+
const retval = {
|
|
24
|
+
sizeGuidance: {
|
|
25
|
+
small: 'swap',
|
|
26
|
+
medium: 'swap',
|
|
27
|
+
large: 'icon-tile',
|
|
28
|
+
xlarge: 'icon-tile'
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
return retval;
|
|
13
32
|
}
|
|
14
33
|
return null;
|
|
15
34
|
};
|
|
@@ -36,7 +55,29 @@ export const canAutoMigrateNewIconBasedOnSize = guidance => {
|
|
|
36
55
|
*/
|
|
37
56
|
export const createGuidance = (iconPackage, insideNewButton = false, size) => {
|
|
38
57
|
const migrationMapObject = getMigrationMapObject(iconPackage);
|
|
39
|
-
|
|
58
|
+
const upcomingIcon = getUpcomingIcons(iconPackage);
|
|
59
|
+
if (upcomingIcon) {
|
|
60
|
+
let guidance = '';
|
|
61
|
+
if (size) {
|
|
62
|
+
if (upcomingIcon.sizeGuidance[size] && canAutoMigrateNewIconBasedOnSize(upcomingIcon.sizeGuidance[size])) {
|
|
63
|
+
guidance += `Fix: An upcoming icon release is planned to migrate this legacy icon.`;
|
|
64
|
+
} else {
|
|
65
|
+
guidance += `No equivalent icon for this size, ${size}, in the current or upcoming set of icons.`;
|
|
66
|
+
}
|
|
67
|
+
guidance += `${Object.keys(migrationOutcomeDescriptionMap).includes(upcomingIcon.sizeGuidance[size]) ? ` Once the upcoming icons are released, please: ${migrationOutcomeDescriptionMap[upcomingIcon.sizeGuidance[size]]}` : ' No migration size advice given.'}\n`;
|
|
68
|
+
} else {
|
|
69
|
+
guidance = `Please wait for the upcoming icons released, as it will contain an alternative for this legacy icon.\nMigration suggestions, depending on the legacy icon size:\n`;
|
|
70
|
+
for (const [size, value] of Object.entries(upcomingIcon.sizeGuidance)) {
|
|
71
|
+
guidance += `\t- ${size}: `;
|
|
72
|
+
if (!Object.keys(migrationOutcomeDescriptionMap).includes(value)) {
|
|
73
|
+
guidance += 'No migration advice given.\n';
|
|
74
|
+
} else {
|
|
75
|
+
guidance += `${migrationOutcomeDescriptionMap[value]}.\n`;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return guidance;
|
|
80
|
+
} else if (migrationMapObject) {
|
|
40
81
|
const newIcon = migrationMapObject.newIcon;
|
|
41
82
|
if (!newIcon) {
|
|
42
83
|
return 'No equivalent icon in new set. An option is to contribute a custom icon into icon-labs package instead.\n';
|
|
@@ -45,21 +86,21 @@ export const createGuidance = (iconPackage, insideNewButton = false, size) => {
|
|
|
45
86
|
let guidance = '';
|
|
46
87
|
if (size) {
|
|
47
88
|
if (migrationMapObject.sizeGuidance[size] && canAutoMigrateNewIconBasedOnSize(migrationMapObject.sizeGuidance[size])) {
|
|
48
|
-
guidance += `Fix: Use ${newIcon.name} from
|
|
89
|
+
guidance += `Fix: Use ${newIcon.name} from ${newIcon.package}/${newIcon.type}/${newIcon.name} instead.`;
|
|
49
90
|
} else {
|
|
50
91
|
guidance += `No equivalent icon for this size, ${size}, in new set.`;
|
|
51
92
|
}
|
|
52
|
-
guidance += `${migrationMapObject.sizeGuidance[size] in
|
|
93
|
+
guidance += `${migrationMapObject.sizeGuidance[size] in migrationOutcomeDescriptionMap ? ` Please: ${migrationOutcomeDescriptionMap[migrationMapObject.sizeGuidance[size]]}` : ' No migration size advice given.'}\n`;
|
|
53
94
|
} else {
|
|
54
|
-
guidance = `Use ${newIcon.name} from
|
|
55
|
-
|
|
95
|
+
guidance = `Use ${newIcon.name} from ${newIcon.package}/${newIcon.type}/${newIcon.name} instead.\nMigration suggestions, depending on the legacy icon size:\n`;
|
|
96
|
+
Object.entries(migrationMapObject.sizeGuidance).forEach(([size, value]) => {
|
|
56
97
|
guidance += `\t- ${size}: `;
|
|
57
|
-
if (!(value in
|
|
98
|
+
if (!(value in migrationOutcomeDescriptionMap)) {
|
|
58
99
|
guidance += 'No migration advice given.\n';
|
|
59
100
|
} else {
|
|
60
|
-
guidance += `${
|
|
101
|
+
guidance += `${migrationOutcomeDescriptionMap[value]}.\n`;
|
|
61
102
|
}
|
|
62
|
-
}
|
|
103
|
+
});
|
|
63
104
|
}
|
|
64
105
|
if (insideNewButton) {
|
|
65
106
|
guidance += buttonGuidanceStr;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const upcomingIcons = ['app-switcher', 'check-circle-outline', 'export', 'file', 'flag-filled', 'lightbulb-filled', 'lock-filled', 'menu-expand', 'menu', 'notification-direct', 'notification', 'people-group', 'people', 'refresh', 'switcher', 'editor/align-image-center', 'editor/align-image-left', 'editor/align-image-right', 'editor/background-color', 'editor/bold', 'editor/indent', 'editor/italic', 'editor/horizontal-rule', 'editor-layout-three-equal', 'editor-layout-three-with-sidebars', 'editor/layout-two-equal', 'editor/layout-two-left-sidebars', 'editor/layout-two-right-sidebar', 'editor/media-center', 'editor/media-full-width', 'editor/media-wide', 'editor/number-list', 'emoji/activity', 'editor/file', 'emoji/flags', 'emoji/food', 'emoji/nature', 'emoji/people', 'emoji/productivity', 'emoji/travel', 'bitbucket/repos'];
|
|
@@ -3,8 +3,7 @@ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol
|
|
|
3
3
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
4
4
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
5
5
|
import { isNodeOfType } from 'eslint-codemod-utils';
|
|
6
|
-
import { canAutoMigrateNewIconBasedOnSize, canMigrateColor, createAutoMigrationError, createCantFindSuitableReplacementError, createCantMigrateColorError, createCantMigrateFunctionUnknownError, createCantMigrateIdentifierError, createCantMigrateReExportError, createCantMigrateSizeUnknown, createCantMigrateSpreadPropsError, createGuidance, createHelpers, getMigrationMapObject, locToString } from './helpers';
|
|
7
|
-
import { isSize } from './migration-map-temp';
|
|
6
|
+
import { canAutoMigrateNewIconBasedOnSize, canMigrateColor, createAutoMigrationError, createCantFindSuitableReplacementError, createCantMigrateColorError, createCantMigrateFunctionUnknownError, createCantMigrateIdentifierError, createCantMigrateReExportError, createCantMigrateSizeUnknown, createCantMigrateSpreadPropsError, createGuidance, createHelpers, getMigrationMapObject, getUpcomingIcons, isSize, locToString } from './helpers';
|
|
8
7
|
export var createChecks = function createChecks(context) {
|
|
9
8
|
//create global variables to be shared by the checks
|
|
10
9
|
var _createHelpers = createHelpers(context),
|
|
@@ -226,13 +225,14 @@ export var createChecks = function createChecks(context) {
|
|
|
226
225
|
if (node.name in legacyIconImports && isNodeOfType(node.parent.parent.name, 'JSXIdentifier') && node.parent.parent.name.name !== 'LEGACY_fallbackIcon') {
|
|
227
226
|
var _migrationMapObject$s;
|
|
228
227
|
var migrationMapObject = getMigrationMapObject(legacyIconImports[node.name].packageName);
|
|
228
|
+
var upcomingIcon = getUpcomingIcons(legacyIconImports[node.name].packageName);
|
|
229
229
|
var newIcon = migrationMapObject === null || migrationMapObject === void 0 ? void 0 : migrationMapObject.newIcon;
|
|
230
|
-
var isNewIconMigratable = canAutoMigrateNewIconBasedOnSize(migrationMapObject === null || migrationMapObject === void 0 || (_migrationMapObject$s = migrationMapObject.sizeGuidance) === null || _migrationMapObject$s === void 0 ? void 0 : _migrationMapObject$s.medium);
|
|
230
|
+
var isNewIconMigratable = canAutoMigrateNewIconBasedOnSize(upcomingIcon ? upcomingIcon.sizeGuidance.medium : migrationMapObject === null || migrationMapObject === void 0 || (_migrationMapObject$s = migrationMapObject.sizeGuidance) === null || _migrationMapObject$s === void 0 ? void 0 : _migrationMapObject$s.medium);
|
|
231
231
|
var isInNewButton = isNodeOfType(node.parent.parent.parent.name, 'JSXIdentifier') && newButtonImports.has(node.parent.parent.parent.name.name);
|
|
232
|
-
if (newIcon && isInNewButton && isNewIconMigratable) {
|
|
232
|
+
if (newIcon && isInNewButton && isNewIconMigratable || upcomingIcon && isInNewButton && isNewIconMigratable) {
|
|
233
233
|
createAutoMigrationError(node, legacyIconImports[node.name].packageName, node.name, errorsAuto);
|
|
234
234
|
guidance[locToString(node)] = createGuidance(legacyIconImports[node.name].packageName, isInNewButton, 'medium');
|
|
235
|
-
} else if (!newIcon || !isNewIconMigratable) {
|
|
235
|
+
} else if (!newIcon && !upcomingIcon || !isNewIconMigratable) {
|
|
236
236
|
createCantFindSuitableReplacementError(node, legacyIconImports[node.name].packageName, node.name, errorsManual);
|
|
237
237
|
guidance[locToString(node)] = createGuidance(legacyIconImports[node.name].packageName, isInNewButton);
|
|
238
238
|
} else if (!isInNewButton) {
|
|
@@ -259,7 +259,7 @@ export var createChecks = function createChecks(context) {
|
|
|
259
259
|
var name = node.openingElement.name.name;
|
|
260
260
|
// Legacy icons rendered as JSX elements
|
|
261
261
|
if (name in legacyIconImports) {
|
|
262
|
-
var _node$parent2, _node$parent3, _size;
|
|
262
|
+
var _node$parent2, _node$parent3, _size, _size2;
|
|
263
263
|
// Determine if inside a new button - if so:
|
|
264
264
|
// - Assume spread props are safe - still error if props explicitly set to unmigratable values
|
|
265
265
|
var insideNewButton = false;
|
|
@@ -343,12 +343,13 @@ export var createChecks = function createChecks(context) {
|
|
|
343
343
|
hasManualMigration = true;
|
|
344
344
|
}
|
|
345
345
|
var migrationMapObject = getMigrationMapObject(legacyIconImports[name].packageName);
|
|
346
|
+
var upcomingIcon = getUpcomingIcons(legacyIconImports[name].packageName);
|
|
346
347
|
var newIcon = migrationMapObject === null || migrationMapObject === void 0 ? void 0 : migrationMapObject.newIcon;
|
|
347
|
-
var isNewIconMigratable = canAutoMigrateNewIconBasedOnSize(migrationMapObject === null || migrationMapObject === void 0 ? void 0 : migrationMapObject.sizeGuidance[(
|
|
348
|
-
if (!hasManualMigration && newIcon && isNewIconMigratable) {
|
|
348
|
+
var isNewIconMigratable = canAutoMigrateNewIconBasedOnSize(upcomingIcon ? upcomingIcon.sizeGuidance[(_size = size) !== null && _size !== void 0 ? _size : 'medium'] : migrationMapObject === null || migrationMapObject === void 0 ? void 0 : migrationMapObject.sizeGuidance[(_size2 = size) !== null && _size2 !== void 0 ? _size2 : 'medium']);
|
|
349
|
+
if (!hasManualMigration && (newIcon || upcomingIcon) && isNewIconMigratable) {
|
|
349
350
|
createAutoMigrationError(node, legacyIconImports[name].packageName, name, errorsAuto);
|
|
350
|
-
} else if ((!newIcon || !isNewIconMigratable) && size) {
|
|
351
|
-
createCantFindSuitableReplacementError(node, legacyIconImports[name].packageName, name, errorsManual, migrationMapObject ? true : false);
|
|
351
|
+
} else if ((!newIcon && !upcomingIcon || !isNewIconMigratable) && size) {
|
|
352
|
+
createCantFindSuitableReplacementError(node, legacyIconImports[name].packageName, name, errorsManual, upcomingIcon ? true : migrationMapObject ? true : false);
|
|
352
353
|
}
|
|
353
354
|
guidance[locToString(node)] = createGuidance(legacyIconImports[name].packageName, insideNewButton, size && isSize(size) ? size : undefined);
|
|
354
355
|
}
|
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
2
|
import { isNodeOfType } from 'eslint-codemod-utils';
|
|
3
|
+
import baseMigrationMap, { migrationOutcomeDescriptionMap } from '@atlaskit/icon/UNSAFE_migration-map';
|
|
3
4
|
import { getImportName } from '../utils/get-import-name';
|
|
4
|
-
import
|
|
5
|
+
import { upcomingIcons } from './upcoming-icons';
|
|
6
|
+
var sizes = ['small', 'medium', 'large', 'xlarge'];
|
|
7
|
+
export var isSize = function isSize(size) {
|
|
8
|
+
return sizes.includes(size);
|
|
9
|
+
};
|
|
10
|
+
|
|
5
11
|
/**
|
|
6
12
|
* Returns the migration map object for a legacy icon or null if not found
|
|
7
13
|
* @param iconPackage The name of the legacy icon package
|
|
@@ -9,8 +15,23 @@ import migrationMap, { outcomeDescriptionMap } from './migration-map-temp';
|
|
|
9
15
|
*/
|
|
10
16
|
export var getMigrationMapObject = function getMigrationMapObject(iconPackage) {
|
|
11
17
|
var key = getIconKey(iconPackage);
|
|
12
|
-
if (key
|
|
13
|
-
return
|
|
18
|
+
if (Object.keys(baseMigrationMap).includes(key)) {
|
|
19
|
+
return baseMigrationMap[key];
|
|
20
|
+
}
|
|
21
|
+
return null;
|
|
22
|
+
};
|
|
23
|
+
export var getUpcomingIcons = function getUpcomingIcons(iconPackage) {
|
|
24
|
+
var key = getIconKey(iconPackage);
|
|
25
|
+
if (upcomingIcons.includes(key)) {
|
|
26
|
+
var retval = {
|
|
27
|
+
sizeGuidance: {
|
|
28
|
+
small: 'swap',
|
|
29
|
+
medium: 'swap',
|
|
30
|
+
large: 'icon-tile',
|
|
31
|
+
xlarge: 'icon-tile'
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
return retval;
|
|
14
35
|
}
|
|
15
36
|
return null;
|
|
16
37
|
};
|
|
@@ -39,42 +60,67 @@ export var createGuidance = function createGuidance(iconPackage) {
|
|
|
39
60
|
var insideNewButton = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
40
61
|
var size = arguments.length > 2 ? arguments[2] : undefined;
|
|
41
62
|
var migrationMapObject = getMigrationMapObject(iconPackage);
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
if (!newIcon) {
|
|
45
|
-
return 'No equivalent icon in new set. An option is to contribute a custom icon into icon-labs package instead.\n';
|
|
46
|
-
}
|
|
47
|
-
var buttonGuidanceStr = "Please set 'spacing' property of the new icon to 'none', to ensure appropriate spacing inside `@atlaskit/button`.\n";
|
|
63
|
+
var upcomingIcon = getUpcomingIcons(iconPackage);
|
|
64
|
+
if (upcomingIcon) {
|
|
48
65
|
var guidance = '';
|
|
49
66
|
if (size) {
|
|
50
|
-
if (
|
|
51
|
-
guidance += "Fix:
|
|
67
|
+
if (upcomingIcon.sizeGuidance[size] && canAutoMigrateNewIconBasedOnSize(upcomingIcon.sizeGuidance[size])) {
|
|
68
|
+
guidance += "Fix: An upcoming icon release is planned to migrate this legacy icon.";
|
|
52
69
|
} else {
|
|
53
|
-
guidance += "No equivalent icon for this size, ".concat(size, ", in
|
|
70
|
+
guidance += "No equivalent icon for this size, ".concat(size, ", in the current or upcoming set of icons.");
|
|
54
71
|
}
|
|
55
|
-
guidance += "".concat(
|
|
72
|
+
guidance += "".concat(Object.keys(migrationOutcomeDescriptionMap).includes(upcomingIcon.sizeGuidance[size]) ? " Once the upcoming icons are released, please: ".concat(migrationOutcomeDescriptionMap[upcomingIcon.sizeGuidance[size]]) : ' No migration size advice given.', "\n");
|
|
56
73
|
} else {
|
|
57
|
-
guidance = "
|
|
58
|
-
for (var _i = 0, _Object$entries = Object.entries(
|
|
74
|
+
guidance = "Please wait for the upcoming icons released, as it will contain an alternative for this legacy icon.\nMigration suggestions, depending on the legacy icon size:\n";
|
|
75
|
+
for (var _i = 0, _Object$entries = Object.entries(upcomingIcon.sizeGuidance); _i < _Object$entries.length; _i++) {
|
|
59
76
|
var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
|
|
60
77
|
_size = _Object$entries$_i[0],
|
|
61
78
|
value = _Object$entries$_i[1];
|
|
62
79
|
guidance += "\t- ".concat(_size, ": ");
|
|
63
|
-
if (!(value
|
|
80
|
+
if (!Object.keys(migrationOutcomeDescriptionMap).includes(value)) {
|
|
64
81
|
guidance += 'No migration advice given.\n';
|
|
65
82
|
} else {
|
|
66
|
-
guidance += "".concat(
|
|
83
|
+
guidance += "".concat(migrationOutcomeDescriptionMap[value], ".\n");
|
|
67
84
|
}
|
|
68
85
|
}
|
|
69
86
|
}
|
|
87
|
+
return guidance;
|
|
88
|
+
} else if (migrationMapObject) {
|
|
89
|
+
var newIcon = migrationMapObject.newIcon;
|
|
90
|
+
if (!newIcon) {
|
|
91
|
+
return 'No equivalent icon in new set. An option is to contribute a custom icon into icon-labs package instead.\n';
|
|
92
|
+
}
|
|
93
|
+
var buttonGuidanceStr = "Please set 'spacing' property of the new icon to 'none', to ensure appropriate spacing inside `@atlaskit/button`.\n";
|
|
94
|
+
var _guidance = '';
|
|
95
|
+
if (size) {
|
|
96
|
+
if (migrationMapObject.sizeGuidance[size] && canAutoMigrateNewIconBasedOnSize(migrationMapObject.sizeGuidance[size])) {
|
|
97
|
+
_guidance += "Fix: Use ".concat(newIcon.name, " from ").concat(newIcon.package, "/").concat(newIcon.type, "/").concat(newIcon.name, " instead.");
|
|
98
|
+
} else {
|
|
99
|
+
_guidance += "No equivalent icon for this size, ".concat(size, ", in new set.");
|
|
100
|
+
}
|
|
101
|
+
_guidance += "".concat(migrationMapObject.sizeGuidance[size] in migrationOutcomeDescriptionMap ? " Please: ".concat(migrationOutcomeDescriptionMap[migrationMapObject.sizeGuidance[size]]) : ' No migration size advice given.', "\n");
|
|
102
|
+
} else {
|
|
103
|
+
_guidance = "Use ".concat(newIcon.name, " from ").concat(newIcon.package, "/").concat(newIcon.type, "/").concat(newIcon.name, " instead.\nMigration suggestions, depending on the legacy icon size:\n");
|
|
104
|
+
Object.entries(migrationMapObject.sizeGuidance).forEach(function (_ref) {
|
|
105
|
+
var _ref2 = _slicedToArray(_ref, 2),
|
|
106
|
+
size = _ref2[0],
|
|
107
|
+
value = _ref2[1];
|
|
108
|
+
_guidance += "\t- ".concat(size, ": ");
|
|
109
|
+
if (!(value in migrationOutcomeDescriptionMap)) {
|
|
110
|
+
_guidance += 'No migration advice given.\n';
|
|
111
|
+
} else {
|
|
112
|
+
_guidance += "".concat(migrationOutcomeDescriptionMap[value], ".\n");
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
}
|
|
70
116
|
if (insideNewButton) {
|
|
71
|
-
|
|
117
|
+
_guidance += buttonGuidanceStr;
|
|
72
118
|
} else if (size && size === 'medium') {
|
|
73
|
-
|
|
119
|
+
_guidance += "Setting the spacing property to 'spacious' will maintain the icon's box dimensions - but consider setting spacing='none' as it allows for easier control of spacing by parent elements.\n";
|
|
74
120
|
} else if (size) {
|
|
75
|
-
|
|
121
|
+
_guidance += "In the new icon, please use spacing='none'.\n";
|
|
76
122
|
}
|
|
77
|
-
return
|
|
123
|
+
return _guidance;
|
|
78
124
|
} else {
|
|
79
125
|
return "Migration suggestions not found for \"".concat(iconPackage, "\".\n");
|
|
80
126
|
}
|
|
@@ -244,9 +290,9 @@ export var createHelpers = function createHelpers(context) {
|
|
|
244
290
|
* Extracts the primaryColor value from a JSXAttribute
|
|
245
291
|
*/
|
|
246
292
|
getPrimaryColor: function getPrimaryColor(attr) {
|
|
247
|
-
var
|
|
293
|
+
var _ref3, _getLiteralStringValu;
|
|
248
294
|
var value = attr.value;
|
|
249
|
-
return (
|
|
295
|
+
return (_ref3 = (_getLiteralStringValu = getLiteralStringValue(value)) !== null && _getLiteralStringValu !== void 0 ? _getLiteralStringValu : getTokenCallValue(value)) !== null && _ref3 !== void 0 ? _ref3 : null;
|
|
250
296
|
},
|
|
251
297
|
getTokenCallValue: getTokenCallValue,
|
|
252
298
|
getConfigFlag: getConfigFlag
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export var upcomingIcons = ['app-switcher', 'check-circle-outline', 'export', 'file', 'flag-filled', 'lightbulb-filled', 'lock-filled', 'menu-expand', 'menu', 'notification-direct', 'notification', 'people-group', 'people', 'refresh', 'switcher', 'editor/align-image-center', 'editor/align-image-left', 'editor/align-image-right', 'editor/background-color', 'editor/bold', 'editor/indent', 'editor/italic', 'editor/horizontal-rule', 'editor-layout-three-equal', 'editor-layout-three-with-sidebars', 'editor/layout-two-equal', 'editor/layout-two-left-sidebars', 'editor/layout-two-right-sidebar', 'editor/media-center', 'editor/media-full-width', 'editor/media-wide', 'editor/number-list', 'emoji/activity', 'editor/file', 'emoji/flags', 'emoji/food', 'emoji/nature', 'emoji/people', 'emoji/productivity', 'emoji/travel', 'bitbucket/repos'];
|