@atlaskit/eslint-plugin-design-system 10.8.1 → 10.9.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 +18 -0
- package/constellation/consistent-css-prop-usage/usage.mdx +9 -0
- package/dist/cjs/rules/consistent-css-prop-usage/index.js +19 -2
- package/dist/cjs/rules/ensure-design-token-usage/index.js +1 -1
- package/dist/cjs/rules/no-legacy-icons/checks.js +484 -0
- package/dist/cjs/rules/no-legacy-icons/helpers.js +289 -0
- package/dist/cjs/rules/no-legacy-icons/index.js +111 -131
- package/dist/cjs/rules/no-legacy-icons/migration-map-temp.js +4090 -0
- package/dist/cjs/rules/use-tokens-typography/index.js +1 -1
- package/dist/es2019/rules/consistent-css-prop-usage/index.js +19 -2
- package/dist/es2019/rules/ensure-design-token-usage/index.js +1 -1
- package/dist/es2019/rules/no-legacy-icons/checks.js +388 -0
- package/dist/es2019/rules/no-legacy-icons/helpers.js +275 -0
- package/dist/es2019/rules/no-legacy-icons/index.js +96 -97
- package/dist/es2019/rules/no-legacy-icons/migration-map-temp.js +4082 -0
- package/dist/es2019/rules/use-tokens-typography/index.js +1 -1
- package/dist/esm/rules/consistent-css-prop-usage/index.js +19 -2
- package/dist/esm/rules/ensure-design-token-usage/index.js +1 -1
- package/dist/esm/rules/no-legacy-icons/checks.js +477 -0
- package/dist/esm/rules/no-legacy-icons/helpers.js +279 -0
- package/dist/esm/rules/no-legacy-icons/index.js +111 -131
- package/dist/esm/rules/no-legacy-icons/migration-map-temp.js +4084 -0
- package/dist/esm/rules/use-tokens-typography/index.js +1 -1
- package/dist/types/rules/consistent-css-prop-usage/types.d.ts +1 -0
- package/dist/types/rules/no-legacy-icons/checks.d.ts +13 -0
- package/dist/types/rules/no-legacy-icons/helpers.d.ts +82 -0
- package/dist/types/rules/no-legacy-icons/index.d.ts +2 -1
- package/dist/types/rules/no-legacy-icons/migration-map-temp.d.ts +22 -0
- package/dist/{types-ts4.5/rules/use-tokens-typography → types/rules/utils}/error-boundary.d.ts +5 -1
- package/dist/types-ts4.5/rules/consistent-css-prop-usage/types.d.ts +1 -0
- package/dist/types-ts4.5/rules/no-legacy-icons/checks.d.ts +13 -0
- package/dist/types-ts4.5/rules/no-legacy-icons/helpers.d.ts +82 -0
- package/dist/types-ts4.5/rules/no-legacy-icons/index.d.ts +2 -1
- package/dist/types-ts4.5/rules/no-legacy-icons/migration-map-temp.d.ts +27 -0
- package/dist/types-ts4.5/rules/{ensure-design-token-usage → utils}/error-boundary.d.ts +5 -1
- package/package.json +1 -1
- package/dist/cjs/rules/use-tokens-typography/error-boundary.js +0 -24
- package/dist/es2019/rules/use-tokens-typography/error-boundary.js +0 -19
- package/dist/esm/rules/use-tokens-typography/error-boundary.js +0 -18
- package/dist/types/rules/ensure-design-token-usage/error-boundary.d.ts +0 -11
- package/dist/types/rules/use-tokens-typography/error-boundary.d.ts +0 -11
- /package/dist/cjs/rules/{ensure-design-token-usage → utils}/error-boundary.js +0 -0
- /package/dist/es2019/rules/{ensure-design-token-usage → utils}/error-boundary.js +0 -0
- /package/dist/esm/rules/{ensure-design-token-usage → utils}/error-boundary.js +0 -0
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
|
+
import { isNodeOfType } from 'eslint-codemod-utils';
|
|
3
|
+
import { getImportName } from '../utils/get-import-name';
|
|
4
|
+
import migrationMap, { outcomeDescriptionMap } from './migration-map-temp';
|
|
5
|
+
/**
|
|
6
|
+
* Returns the migration map object for a legacy icon or null if not found
|
|
7
|
+
* @param iconPackage The name of the legacy icon package
|
|
8
|
+
* @returns The migration map object for the legacy icon or null if not found
|
|
9
|
+
*/
|
|
10
|
+
export var getMigrationMapObject = function getMigrationMapObject(iconPackage) {
|
|
11
|
+
var key = getIconKey(iconPackage);
|
|
12
|
+
if (key in migrationMap) {
|
|
13
|
+
return migrationMap[key];
|
|
14
|
+
}
|
|
15
|
+
return null;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Returns the key of a legacy icon
|
|
20
|
+
* @param iconPackage The name of the legacy icon package
|
|
21
|
+
* @returns The unique identifier for the icon (the part after "@atlaskit/icon/glyph")
|
|
22
|
+
*/
|
|
23
|
+
export var getIconKey = function getIconKey(iconPackage) {
|
|
24
|
+
var key = iconPackage.replace(/^@atlaskit\/icon\/glyph\//, '');
|
|
25
|
+
return key;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Checks if a new icon can be auto-migrated based on guidance from the migration map
|
|
30
|
+
*/
|
|
31
|
+
export var canAutoMigrateNewIconBasedOnSize = function canAutoMigrateNewIconBasedOnSize(guidance) {
|
|
32
|
+
return ['swap', 'swap-slight-visual-change', 'swap-visual-change', 'swap-size-shift-utility'].includes(guidance || '');
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Creates the written guidance for migrating a legacy icon to a new icon
|
|
37
|
+
*/
|
|
38
|
+
export var createGuidance = function createGuidance(iconPackage, size) {
|
|
39
|
+
var migrationMapObject = getMigrationMapObject(iconPackage);
|
|
40
|
+
if (migrationMapObject) {
|
|
41
|
+
var newIcon = migrationMapObject.newIcon;
|
|
42
|
+
if (!newIcon) {
|
|
43
|
+
return 'No equivalent icon in new set. An option is to contribute a custom icon into icon-labs package instead.\n';
|
|
44
|
+
}
|
|
45
|
+
if (size) {
|
|
46
|
+
var guidance = "Fix: Use ".concat(newIcon.name, " from @atlaskit/").concat(newIcon.library, "/").concat(newIcon.type, "/").concat(newIcon.name, " instead.");
|
|
47
|
+
if (migrationMapObject.sizeGuidance[size] in outcomeDescriptionMap) {
|
|
48
|
+
guidance += " Please: ".concat(outcomeDescriptionMap[migrationMapObject.sizeGuidance[size]], "\n");
|
|
49
|
+
} else {
|
|
50
|
+
guidance += ' No migration advice given.\n';
|
|
51
|
+
}
|
|
52
|
+
return guidance;
|
|
53
|
+
} else {
|
|
54
|
+
var _guidance = "Use ".concat(newIcon.name, " from @atlaskit/").concat(newIcon.library, "/").concat(newIcon.type, "/").concat(newIcon.name, " instead.\nMigration suggestions, depending on the legacy icon size:\n");
|
|
55
|
+
for (var _i = 0, _Object$entries = Object.entries(migrationMapObject.sizeGuidance); _i < _Object$entries.length; _i++) {
|
|
56
|
+
var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
|
|
57
|
+
_size = _Object$entries$_i[0],
|
|
58
|
+
value = _Object$entries$_i[1];
|
|
59
|
+
_guidance += "\t- ".concat(_size, ": ");
|
|
60
|
+
if (!(value in outcomeDescriptionMap)) {
|
|
61
|
+
_guidance += 'No migration advice given.\n';
|
|
62
|
+
} else {
|
|
63
|
+
_guidance += "".concat(outcomeDescriptionMap[value], "\n");
|
|
64
|
+
}
|
|
65
|
+
_guidance;
|
|
66
|
+
}
|
|
67
|
+
return _guidance;
|
|
68
|
+
}
|
|
69
|
+
} else {
|
|
70
|
+
return 'Migration suggestions not found\n';
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Checks if the color can be migrated
|
|
76
|
+
* @param color String representing the color to check
|
|
77
|
+
* @returns True if the color can be migrated, false otherwise
|
|
78
|
+
*/
|
|
79
|
+
export var canMigrateColor = function canMigrateColor(color) {
|
|
80
|
+
if (color.match(/^color\.text$/)) {
|
|
81
|
+
return true;
|
|
82
|
+
} else if (color.match(/^color\.icon/)) {
|
|
83
|
+
return true;
|
|
84
|
+
} else if (color.match(/^color\.link/)) {
|
|
85
|
+
return true;
|
|
86
|
+
} else if (color === 'currentColor') {
|
|
87
|
+
return true;
|
|
88
|
+
} else {
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
export var locToString = function locToString(node) {
|
|
93
|
+
var _node$loc, _node$loc2, _node$loc3, _node$loc4;
|
|
94
|
+
return "".concat((_node$loc = node.loc) === null || _node$loc === void 0 ? void 0 : _node$loc.start.line, ":").concat((_node$loc2 = node.loc) === null || _node$loc2 === void 0 ? void 0 : _node$loc2.start.column, ":").concat((_node$loc3 = node.loc) === null || _node$loc3 === void 0 ? void 0 : _node$loc3.end.line, ":").concat((_node$loc4 = node.loc) === null || _node$loc4 === void 0 ? void 0 : _node$loc4.end.column);
|
|
95
|
+
};
|
|
96
|
+
export var createCantMigrateReExportError = function createCantMigrateReExportError(node, packageName, exportName, errors) {
|
|
97
|
+
var myError = {
|
|
98
|
+
node: node,
|
|
99
|
+
messageId: 'cantMigrateReExport',
|
|
100
|
+
data: {
|
|
101
|
+
packageName: packageName,
|
|
102
|
+
exportName: exportName
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
pushManualError(locToString(node), errors, myError, packageName, exportName);
|
|
106
|
+
};
|
|
107
|
+
export var createCantMigrateIdentifierError = function createCantMigrateIdentifierError(node, packageName, exportName, errors) {
|
|
108
|
+
var myError = {
|
|
109
|
+
node: node,
|
|
110
|
+
messageId: 'cantMigrateIdentifier',
|
|
111
|
+
data: {
|
|
112
|
+
packageName: packageName,
|
|
113
|
+
exportName: exportName
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
pushManualError(locToString(node), errors, myError, packageName, exportName);
|
|
117
|
+
};
|
|
118
|
+
export var findUNSAFEProp = function findUNSAFEProp(iconAttr, button) {
|
|
119
|
+
var UNSAFE_size = null;
|
|
120
|
+
var propName = iconAttr.name.name === 'iconAfter' || iconAttr.name.name === 'iconBefore' || iconAttr.name.name === 'icon' ? iconAttr.name.name : null;
|
|
121
|
+
var buttonAttributes = button.attributes;
|
|
122
|
+
var UNSAFE_propName = propName === 'icon' ? "UNSAFE_size" : propName ? "UNSAFE_".concat(propName, "_size") : null;
|
|
123
|
+
var UNSAFE_size_index = buttonAttributes.findIndex(function (x) {
|
|
124
|
+
return UNSAFE_propName && 'name' in x && x.name && x.name.name === UNSAFE_propName;
|
|
125
|
+
});
|
|
126
|
+
var unsafeAttribute = UNSAFE_size_index !== -1 ? buttonAttributes[UNSAFE_size_index] : null;
|
|
127
|
+
if (unsafeAttribute && isNodeOfType(unsafeAttribute, 'JSXAttribute') && unsafeAttribute.value && isNodeOfType(unsafeAttribute.value, 'Literal') && unsafeAttribute.value.value && ['small', 'large', 'xlarge'].includes(unsafeAttribute.value.value)) {
|
|
128
|
+
UNSAFE_size = unsafeAttribute.value.value;
|
|
129
|
+
} else if (unsafeAttribute && isNodeOfType(unsafeAttribute, 'JSXAttribute') && unsafeAttribute.value && isNodeOfType(unsafeAttribute.value, 'JSXExpressionContainer') && isNodeOfType(unsafeAttribute.value.expression, 'Literal') && ['small', 'large', 'xlarge'].includes(unsafeAttribute.value.expression.value)) {
|
|
130
|
+
UNSAFE_size = unsafeAttribute.value.expression.value;
|
|
131
|
+
}
|
|
132
|
+
return {
|
|
133
|
+
UNSAFE_size: UNSAFE_size,
|
|
134
|
+
UNSAFE_propName: UNSAFE_propName
|
|
135
|
+
};
|
|
136
|
+
};
|
|
137
|
+
export var createCantMigrateUnsafeProp = function createCantMigrateUnsafeProp(node, propName, value, packageName, iconName, errors) {
|
|
138
|
+
var myError = {
|
|
139
|
+
node: node,
|
|
140
|
+
messageId: 'cantMigrateUnsafeProp',
|
|
141
|
+
data: {
|
|
142
|
+
propName: propName,
|
|
143
|
+
value: value
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
pushManualError(locToString(node), errors, myError, packageName, iconName);
|
|
147
|
+
};
|
|
148
|
+
export var createCantFindSuitableReplacementError = function createCantFindSuitableReplacementError(node, importSource, iconName, errors) {
|
|
149
|
+
var myError = {
|
|
150
|
+
node: node,
|
|
151
|
+
messageId: 'cantFindSuitableReplacement',
|
|
152
|
+
data: {
|
|
153
|
+
importSource: importSource,
|
|
154
|
+
iconName: iconName
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
pushManualError(locToString(node), errors, myError, importSource, iconName);
|
|
158
|
+
};
|
|
159
|
+
export var createCantMigrateFunctionUnknownError = function createCantMigrateFunctionUnknownError(node, importSource, iconName, errors) {
|
|
160
|
+
var myError = {
|
|
161
|
+
node: node,
|
|
162
|
+
messageId: 'cantMigrateFunctionUnknown',
|
|
163
|
+
data: {
|
|
164
|
+
importSource: importSource,
|
|
165
|
+
iconName: iconName
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
pushManualError(locToString(node), errors, myError, importSource, iconName);
|
|
169
|
+
};
|
|
170
|
+
export var createCantMigrateColorError = function createCantMigrateColorError(node, colorValue, errors, importSource, iconName) {
|
|
171
|
+
var myError = {
|
|
172
|
+
node: node,
|
|
173
|
+
messageId: 'cantMigrateColor',
|
|
174
|
+
data: {
|
|
175
|
+
colorValue: colorValue
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
pushManualError(locToString(node), errors, myError, importSource, iconName);
|
|
179
|
+
};
|
|
180
|
+
export var createCantMigrateSpreadPropsError = function createCantMigrateSpreadPropsError(node, missingProps, errors, importSource, iconName) {
|
|
181
|
+
var myError = {
|
|
182
|
+
node: node,
|
|
183
|
+
messageId: 'cantMigrateSpreadProps',
|
|
184
|
+
data: {
|
|
185
|
+
missingProps: missingProps.join(', ')
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
pushManualError(locToString(node), errors, myError, importSource, iconName);
|
|
189
|
+
};
|
|
190
|
+
export var createCantMigrateSizeUnknown = function createCantMigrateSizeUnknown(node, errors, importSource, iconName) {
|
|
191
|
+
var myError = {
|
|
192
|
+
node: node,
|
|
193
|
+
messageId: 'cantMigrateSizeUnknown'
|
|
194
|
+
};
|
|
195
|
+
pushManualError(locToString(node), errors, myError, importSource, iconName);
|
|
196
|
+
};
|
|
197
|
+
export var createAutoMigrationError = function createAutoMigrationError(node, importSource, iconName, newIcon, oldIconName, errors) {
|
|
198
|
+
var migrationKey = newIcon.name === oldIconName ? newIcon.name : "".concat(newIcon.name, "--").concat(oldIconName);
|
|
199
|
+
var newMigrationIconPackage = "@atlaskit/".concat(newIcon.library, "/").concat(newIcon.type, "/migration/").concat(migrationKey);
|
|
200
|
+
var myError = {
|
|
201
|
+
node: node,
|
|
202
|
+
messageId: 'noLegacyIconsAutoMigration',
|
|
203
|
+
data: {
|
|
204
|
+
importSource: importSource,
|
|
205
|
+
iconName: iconName,
|
|
206
|
+
newIcon: newIcon.name,
|
|
207
|
+
//TODO: provide size guidance
|
|
208
|
+
newPackage: newMigrationIconPackage
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
errors[locToString(node)] = myError;
|
|
212
|
+
};
|
|
213
|
+
var pushManualError = function pushManualError(key, errors, myError, importSource, iconName) {
|
|
214
|
+
if (key in errors) {
|
|
215
|
+
errors[key].errors.push(myError);
|
|
216
|
+
} else {
|
|
217
|
+
errors[key] = {
|
|
218
|
+
errors: [myError],
|
|
219
|
+
importSource: importSource,
|
|
220
|
+
iconName: iconName
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
export var getLiteralStringValue = function getLiteralStringValue(value) {
|
|
225
|
+
if (!value) {
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// propName="value"
|
|
230
|
+
if (isNodeOfType(value, 'Literal') && typeof value.value === 'string') {
|
|
231
|
+
return value.value;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
// propName={"value"}
|
|
235
|
+
if (isNodeOfType(value, 'JSXExpressionContainer') && isNodeOfType(value.expression, 'Literal') && typeof value.expression.value === 'string') {
|
|
236
|
+
return value.expression.value;
|
|
237
|
+
}
|
|
238
|
+
return;
|
|
239
|
+
};
|
|
240
|
+
export var createHelpers = function createHelpers(context) {
|
|
241
|
+
/**
|
|
242
|
+
* Extracts the token name of a token() call from a JSXExpressionContainer
|
|
243
|
+
* @param value The JSXExpressionContainer to extract the token call from
|
|
244
|
+
* @returns The value of the token call, or null if it could not be extracted
|
|
245
|
+
*/
|
|
246
|
+
var getTokenCallValue = function getTokenCallValue(value) {
|
|
247
|
+
var tokenName = getImportName(context.sourceCode.getScope(value), '@atlaskit/tokens', 'token');
|
|
248
|
+
if (tokenName && isNodeOfType(value, 'JSXExpressionContainer') && isNodeOfType(value.expression, 'CallExpression') && 'name' in value.expression.callee && value.expression.callee.name === tokenName) {
|
|
249
|
+
// propName={token("color...."}
|
|
250
|
+
return getLiteralStringValue(value.expression.arguments[0]);
|
|
251
|
+
}
|
|
252
|
+
return;
|
|
253
|
+
};
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* Gets the value of a boolean configuration flag
|
|
257
|
+
* @param key the key of the configuration flag
|
|
258
|
+
* @param defaultValue The default value of the configuration flag
|
|
259
|
+
* @returns defaultValue if the configuration flag is not set, the defaultValue of the configuration flag otherwise
|
|
260
|
+
*/
|
|
261
|
+
var getConfigFlag = function getConfigFlag(key, defaultValue) {
|
|
262
|
+
if (context.options.length > 0 && context.options[0] && key in context.options[0]) {
|
|
263
|
+
return context.options[0][key] === !defaultValue ? !defaultValue : defaultValue;
|
|
264
|
+
}
|
|
265
|
+
return defaultValue;
|
|
266
|
+
};
|
|
267
|
+
return {
|
|
268
|
+
/**
|
|
269
|
+
* Extracts the primaryColor value from a JSXAttribute
|
|
270
|
+
*/
|
|
271
|
+
getPrimaryColor: function getPrimaryColor(attr) {
|
|
272
|
+
var _ref, _getLiteralStringValu;
|
|
273
|
+
var value = attr.value;
|
|
274
|
+
return (_ref = (_getLiteralStringValu = getLiteralStringValue(value)) !== null && _getLiteralStringValu !== void 0 ? _getLiteralStringValu : getTokenCallValue(value)) !== null && _ref !== void 0 ? _ref : null;
|
|
275
|
+
},
|
|
276
|
+
getTokenCallValue: getTokenCallValue,
|
|
277
|
+
getConfigFlag: getConfigFlag
|
|
278
|
+
};
|
|
279
|
+
};
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
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; } } }; }
|
|
2
|
-
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); }
|
|
3
|
-
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; }
|
|
4
|
-
import { isNodeOfType } from 'eslint-codemod-utils';
|
|
5
1
|
import { createLintRule } from '../utils/create-rule';
|
|
2
|
+
import { errorBoundary } from '../utils/error-boundary';
|
|
3
|
+
import { createChecks } from './checks';
|
|
4
|
+
import { createHelpers } from './helpers';
|
|
6
5
|
var rule = createLintRule({
|
|
7
6
|
meta: {
|
|
8
7
|
name: 'no-legacy-icons',
|
|
@@ -12,155 +11,136 @@ var rule = createLintRule({
|
|
|
12
11
|
recommended: false,
|
|
13
12
|
severity: 'warn'
|
|
14
13
|
},
|
|
14
|
+
schema: [{
|
|
15
|
+
type: 'object',
|
|
16
|
+
properties: {
|
|
17
|
+
shouldErrorForManualMigration: {
|
|
18
|
+
type: 'boolean'
|
|
19
|
+
},
|
|
20
|
+
shouldErrorForAutoMigration: {
|
|
21
|
+
type: 'boolean'
|
|
22
|
+
},
|
|
23
|
+
quiet: {
|
|
24
|
+
type: 'boolean'
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
additionalProperties: false
|
|
28
|
+
}],
|
|
15
29
|
messages: {
|
|
16
|
-
|
|
30
|
+
noLegacyIconsAutoMigration: "Auto Migration:\nLegacy icon '{{iconName}}' from '{{importSource}}' detected.\nAutomatic migration is possible to '{{newIcon}}' from '{{newPackage}}.\nAtlassians: See https://go.atlassian.com/icon-migration-guide for details.'",
|
|
31
|
+
noLegacyIconsManualMigration: "Manual Migration:\nLegacy icon '{{iconName}}' from '{{importSource}}' detected.\nAutomatic migration not possible.{{quietModeGuidance}}.\nAtlassians: See https://go.atlassian.com/icon-migration-guide for details.",
|
|
32
|
+
cantFindSuitableReplacement: "No suitable replacement found for '{{iconName}}' from '{{importSource}}' at the size listed. Please manually migrate this icon.",
|
|
33
|
+
cantMigrateReExport: "'{{exportName}}' is a re-export of icon from '{{packageName}}' and cannot be automatically migrated. Please utilize the export from icons directly.",
|
|
34
|
+
cantMigrateColor: "Primary Color prop has {{colorValue}} which cannot be automatically migrated to color prop in the new Icon API. Please use either an appropriate color.icon, color.link token, or currentColor (as a last resort).",
|
|
35
|
+
cantMigrateSpreadProps: "This usage of Icon uses spread props in a way that can't be automatically migrated. Please explicitly define the following props after spread: '{{missingProps}}' ",
|
|
36
|
+
cantMigrateSizeUnknown: "This usage of Icon sets the size via a variable or function that can't be determined.",
|
|
37
|
+
cantMigrateFunctionUnknown: "'{{iconName}}' from legacy '{{importSource}}' is used in unknown function/component. Please manually migrate this icon.",
|
|
38
|
+
cantMigrateIdentifier: "This icon is passed to other components via a map or array, in a way that can't be automatically migrated. Please manually migrate wherever this expression is used and use the icon components directly.",
|
|
39
|
+
cantMigrateUnsafeProp: "Property '{{propName}}' with value of '{{value}}' is unable to be auto-migrated to the new button. Please manually migrate this icon.",
|
|
40
|
+
guidance: "Guidance:\n'{{guidance}}'"
|
|
17
41
|
}
|
|
18
42
|
},
|
|
19
43
|
create: function create(context) {
|
|
20
|
-
var
|
|
44
|
+
var _createHelpers = createHelpers(context),
|
|
45
|
+
getConfigFlag = _createHelpers.getConfigFlag;
|
|
46
|
+
var failSilently = getConfigFlag('failSilently', false);
|
|
47
|
+
var _createChecks = createChecks(context),
|
|
48
|
+
checkImportDeclarations = _createChecks.checkImportDeclarations,
|
|
49
|
+
checkVariableDeclarations = _createChecks.checkVariableDeclarations,
|
|
50
|
+
checkExportDefaultDeclaration = _createChecks.checkExportDefaultDeclaration,
|
|
51
|
+
checkExportNamedVariables = _createChecks.checkExportNamedVariables,
|
|
52
|
+
checkArrayOrMap = _createChecks.checkArrayOrMap,
|
|
53
|
+
checkIconAsProp = _createChecks.checkIconAsProp,
|
|
54
|
+
checkJSXElement = _createChecks.checkJSXElement,
|
|
55
|
+
checkCallExpression = _createChecks.checkCallExpression,
|
|
56
|
+
throwErrors = _createChecks.throwErrors;
|
|
21
57
|
return {
|
|
58
|
+
// Track imports of relevant components
|
|
22
59
|
ImportDeclaration: function ImportDeclaration(node) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
return spec.type === 'ImportDefaultSpecifier';
|
|
29
|
-
});
|
|
30
|
-
if (!defaultImport) {
|
|
31
|
-
return;
|
|
60
|
+
errorBoundary(function () {
|
|
61
|
+
return checkImportDeclarations(node);
|
|
62
|
+
}, {
|
|
63
|
+
config: {
|
|
64
|
+
failSilently: failSilently
|
|
32
65
|
}
|
|
33
|
-
|
|
34
|
-
legacyIconImports[defaultImportName] = moduleSource;
|
|
35
|
-
}
|
|
66
|
+
});
|
|
36
67
|
},
|
|
68
|
+
// Keep track of the relevant variable declarations and renames
|
|
37
69
|
VariableDeclaration: function VariableDeclaration(node) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
var decl = _step.value;
|
|
44
|
-
if (isNodeOfType(decl, 'VariableDeclarator') && 'init' in decl && 'id' in decl && decl.init && decl.id && 'name' in decl.id && decl.id.name && isNodeOfType(decl.init, 'Identifier') && decl.init.name in legacyIconImports) {
|
|
45
|
-
legacyIconImports[decl.id.name] = legacyIconImports[decl.init.name];
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
} catch (err) {
|
|
49
|
-
_iterator.e(err);
|
|
50
|
-
} finally {
|
|
51
|
-
_iterator.f();
|
|
70
|
+
errorBoundary(function () {
|
|
71
|
+
return checkVariableDeclarations(node);
|
|
72
|
+
}, {
|
|
73
|
+
config: {
|
|
74
|
+
failSilently: failSilently
|
|
52
75
|
}
|
|
53
|
-
}
|
|
76
|
+
});
|
|
54
77
|
},
|
|
78
|
+
// Case: default re-exports. Can't be auto-migrated
|
|
55
79
|
ExportDefaultDeclaration: function ExportDefaultDeclaration(node) {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
}
|
|
80
|
+
errorBoundary(function () {
|
|
81
|
+
return checkExportDefaultDeclaration(node);
|
|
82
|
+
}, {
|
|
83
|
+
config: {
|
|
84
|
+
failSilently: failSilently
|
|
85
|
+
}
|
|
86
|
+
});
|
|
66
87
|
},
|
|
67
88
|
ExportNamedDeclaration: function ExportNamedDeclaration(node) {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
context.report({
|
|
74
|
-
node: node,
|
|
75
|
-
messageId: 'noLegacyIcons',
|
|
76
|
-
data: {
|
|
77
|
-
importSource: moduleSource,
|
|
78
|
-
iconName: node.specifiers[0].exported.name
|
|
79
|
-
}
|
|
80
|
-
});
|
|
89
|
+
errorBoundary(function () {
|
|
90
|
+
return checkExportNamedVariables(node);
|
|
91
|
+
}, {
|
|
92
|
+
config: {
|
|
93
|
+
failSilently: failSilently
|
|
81
94
|
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
messageId: 'noLegacyIcons',
|
|
92
|
-
data: {
|
|
93
|
-
importSource: legacyIconImports[decl.init.name],
|
|
94
|
-
iconName: decl.init.name
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
} catch (err) {
|
|
100
|
-
_iterator2.e(err);
|
|
101
|
-
} finally {
|
|
102
|
-
_iterator2.f();
|
|
95
|
+
});
|
|
96
|
+
},
|
|
97
|
+
// Legacy icons found in arrays/objects
|
|
98
|
+
'ObjectExpression > Property > Identifier, ArrayExpression > Identifier ': function ObjectExpressionPropertyIdentifierArrayExpressionIdentifier(node) {
|
|
99
|
+
errorBoundary(function () {
|
|
100
|
+
return checkArrayOrMap(node);
|
|
101
|
+
}, {
|
|
102
|
+
config: {
|
|
103
|
+
failSilently: failSilently
|
|
103
104
|
}
|
|
104
|
-
}
|
|
105
|
+
});
|
|
105
106
|
},
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
importSource: legacyIconImports[node.value.expression.name],
|
|
116
|
-
iconName: node.value.expression.name
|
|
117
|
-
}
|
|
118
|
-
});
|
|
119
|
-
}
|
|
107
|
+
// Legacy icons passed in via props, as JSX identifier (i.e. icon={AddIcon})
|
|
108
|
+
'JSXOpeningElement > JSXAttribute > JSXExpressionContainer > Identifier': function JSXOpeningElementJSXAttributeJSXExpressionContainerIdentifier(node) {
|
|
109
|
+
errorBoundary(function () {
|
|
110
|
+
return checkIconAsProp(node);
|
|
111
|
+
}, {
|
|
112
|
+
config: {
|
|
113
|
+
failSilently: failSilently
|
|
114
|
+
}
|
|
115
|
+
});
|
|
120
116
|
},
|
|
121
117
|
JSXElement: function JSXElement(node) {
|
|
122
|
-
|
|
123
|
-
return;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
if (name in legacyIconImports) {
|
|
130
|
-
context.report({
|
|
131
|
-
node: node,
|
|
132
|
-
messageId: 'noLegacyIcons',
|
|
133
|
-
data: {
|
|
134
|
-
importSource: legacyIconImports[name],
|
|
135
|
-
iconName: name
|
|
136
|
-
}
|
|
137
|
-
});
|
|
138
|
-
}
|
|
118
|
+
errorBoundary(function () {
|
|
119
|
+
return checkJSXElement(node);
|
|
120
|
+
}, {
|
|
121
|
+
config: {
|
|
122
|
+
failSilently: failSilently
|
|
123
|
+
}
|
|
124
|
+
});
|
|
139
125
|
},
|
|
126
|
+
// Icons called as an argument of a function (i.e. icon={DefaultIcon(AddIcon)})
|
|
140
127
|
CallExpression: function CallExpression(node) {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
var arg = _step3.value;
|
|
147
|
-
if (isNodeOfType(arg, 'Identifier') && arg.name in legacyIconImports) {
|
|
148
|
-
context.report({
|
|
149
|
-
node: arg,
|
|
150
|
-
messageId: 'noLegacyIcons',
|
|
151
|
-
data: {
|
|
152
|
-
importSource: legacyIconImports[arg.name],
|
|
153
|
-
iconName: arg.name
|
|
154
|
-
}
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
} catch (err) {
|
|
159
|
-
_iterator3.e(err);
|
|
160
|
-
} finally {
|
|
161
|
-
_iterator3.f();
|
|
128
|
+
errorBoundary(function () {
|
|
129
|
+
return checkCallExpression(node);
|
|
130
|
+
}, {
|
|
131
|
+
config: {
|
|
132
|
+
failSilently: failSilently
|
|
162
133
|
}
|
|
163
|
-
}
|
|
134
|
+
});
|
|
135
|
+
},
|
|
136
|
+
'Program:exit': function ProgramExit() {
|
|
137
|
+
errorBoundary(function () {
|
|
138
|
+
return throwErrors();
|
|
139
|
+
}, {
|
|
140
|
+
config: {
|
|
141
|
+
failSilently: failSilently
|
|
142
|
+
}
|
|
143
|
+
});
|
|
164
144
|
}
|
|
165
145
|
};
|
|
166
146
|
}
|