@atlaskit/eslint-plugin-design-system 10.9.0 → 10.10.1
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 +19 -0
- package/README.md +1 -0
- package/dist/cjs/presets/all.codegen.js +2 -1
- package/dist/cjs/rules/ensure-design-token-usage/index.js +199 -227
- package/dist/cjs/rules/index.codegen.js +3 -1
- package/dist/cjs/rules/no-custom-icons/checks/has-prop.js +12 -0
- package/dist/cjs/rules/no-custom-icons/checks/is-from-import-source.js +42 -0
- package/dist/cjs/rules/no-custom-icons/checks/is-imported-jsx-element.js +10 -0
- package/dist/cjs/rules/no-custom-icons/index.js +67 -0
- package/dist/cjs/rules/no-legacy-icons/checks.js +63 -67
- package/dist/cjs/rules/no-legacy-icons/helpers.js +29 -24
- package/dist/cjs/rules/no-legacy-icons/index.js +15 -88
- package/dist/cjs/rules/use-tokens-typography/index.js +4 -8
- package/dist/cjs/rules/utils/error-boundary.js +58 -11
- package/dist/es2019/presets/all.codegen.js +2 -1
- package/dist/es2019/rules/ensure-design-token-usage/index.js +16 -30
- package/dist/es2019/rules/index.codegen.js +3 -1
- package/dist/es2019/rules/no-custom-icons/checks/has-prop.js +4 -0
- package/dist/es2019/rules/no-custom-icons/checks/is-from-import-source.js +23 -0
- package/dist/es2019/rules/no-custom-icons/checks/is-imported-jsx-element.js +4 -0
- package/dist/es2019/rules/no-custom-icons/index.js +61 -0
- package/dist/es2019/rules/no-legacy-icons/checks.js +20 -33
- package/dist/es2019/rules/no-legacy-icons/helpers.js +24 -21
- package/dist/es2019/rules/no-legacy-icons/index.js +15 -70
- package/dist/es2019/rules/use-tokens-typography/index.js +3 -7
- package/dist/es2019/rules/utils/error-boundary.js +55 -11
- package/dist/esm/presets/all.codegen.js +2 -1
- package/dist/esm/rules/ensure-design-token-usage/index.js +199 -227
- package/dist/esm/rules/index.codegen.js +3 -1
- package/dist/esm/rules/no-custom-icons/checks/has-prop.js +6 -0
- package/dist/esm/rules/no-custom-icons/checks/is-from-import-source.js +36 -0
- package/dist/esm/rules/no-custom-icons/checks/is-imported-jsx-element.js +4 -0
- package/dist/esm/rules/no-custom-icons/index.js +61 -0
- package/dist/esm/rules/no-legacy-icons/checks.js +64 -68
- package/dist/esm/rules/no-legacy-icons/helpers.js +28 -23
- package/dist/esm/rules/no-legacy-icons/index.js +15 -88
- package/dist/esm/rules/use-tokens-typography/index.js +4 -8
- package/dist/esm/rules/utils/error-boundary.js +56 -10
- package/dist/types/index.codegen.d.ts +1 -0
- package/dist/types/presets/all.codegen.d.ts +2 -1
- package/dist/types/rules/index.codegen.d.ts +1 -0
- package/dist/types/rules/no-custom-icons/checks/has-prop.d.ts +2 -0
- package/dist/types/rules/no-custom-icons/checks/is-from-import-source.d.ts +8 -0
- package/dist/types/rules/no-custom-icons/checks/is-imported-jsx-element.d.ts +8 -0
- package/dist/types/rules/no-custom-icons/index.d.ts +3 -0
- package/dist/types/rules/no-legacy-icons/helpers.d.ts +3 -13
- package/dist/types/rules/no-legacy-icons/index.d.ts +1 -2
- package/dist/types/rules/utils/error-boundary.d.ts +8 -5
- package/dist/types-ts4.5/index.codegen.d.ts +1 -0
- package/dist/types-ts4.5/presets/all.codegen.d.ts +2 -1
- package/dist/types-ts4.5/rules/index.codegen.d.ts +1 -0
- package/dist/types-ts4.5/rules/no-custom-icons/checks/has-prop.d.ts +2 -0
- package/dist/types-ts4.5/rules/no-custom-icons/checks/is-from-import-source.d.ts +8 -0
- package/dist/types-ts4.5/rules/no-custom-icons/checks/is-imported-jsx-element.d.ts +8 -0
- package/dist/types-ts4.5/rules/no-custom-icons/index.d.ts +3 -0
- package/dist/types-ts4.5/rules/no-legacy-icons/helpers.d.ts +3 -13
- package/dist/types-ts4.5/rules/no-legacy-icons/index.d.ts +1 -2
- package/dist/types-ts4.5/rules/utils/error-boundary.d.ts +8 -5
- package/package.json +2 -2
- package/constellation/consistent-css-prop-usage/usage.mdx +0 -210
- package/constellation/ensure-design-token-usage/usage.mdx +0 -77
- package/constellation/ensure-design-token-usage-preview/usage.mdx +0 -6
- package/constellation/icon-label/usage.mdx +0 -41
- package/constellation/index/props.mdx +0 -30
- package/constellation/index/usage.mdx +0 -56
- package/constellation/no-banned-imports/usage.mdx +0 -19
- package/constellation/no-css-tagged-template-expression/usage.mdx +0 -71
- package/constellation/no-deprecated-apis/usage.mdx +0 -82
- package/constellation/no-deprecated-design-token-usage/usage.mdx +0 -30
- package/constellation/no-deprecated-imports/usage.mdx +0 -66
- package/constellation/no-direct-use-of-web-platform-drag-and-drop/usage.mdx +0 -149
- package/constellation/no-empty-styled-expression/usage.mdx +0 -82
- package/constellation/no-exported-css/usage.mdx +0 -55
- package/constellation/no-exported-keyframes/usage.mdx +0 -55
- package/constellation/no-html-anchor/usage.mdx +0 -46
- package/constellation/no-html-button/usage.mdx +0 -52
- package/constellation/no-invalid-css-map/usage.mdx +0 -210
- package/constellation/no-keyframes-tagged-template-expression/usage.mdx +0 -80
- package/constellation/no-legacy-icons/usage.mdx +0 -42
- package/constellation/no-margin/usage.mdx +0 -21
- package/constellation/no-nested-styles/usage.mdx +0 -47
- package/constellation/no-physical-properties/usage.mdx +0 -53
- package/constellation/no-styled-tagged-template-expression/usage.mdx +0 -135
- package/constellation/no-unsafe-design-token-usage/usage.mdx +0 -50
- package/constellation/no-unsafe-style-overrides/usage.mdx +0 -52
- package/constellation/no-unsupported-drag-and-drop-libraries/usage.mdx +0 -23
- package/constellation/prefer-primitives/usage.mdx +0 -32
- package/constellation/use-button-group-label/usage.mdx +0 -60
- package/constellation/use-drawer-label/usage.mdx +0 -55
- package/constellation/use-heading/usage.mdx +0 -31
- package/constellation/use-heading-level-in-spotlight-card/usage.mdx +0 -21
- package/constellation/use-href-in-link-item/usage.mdx +0 -19
- package/constellation/use-latest-xcss-syntax/usage.mdx +0 -33
- package/constellation/use-latest-xcss-syntax-typography/usage.mdx +0 -34
- package/constellation/use-menu-section-title/usage.mdx +0 -55
- package/constellation/use-popup-label/usage.mdx +0 -56
- package/constellation/use-primitives/usage.mdx +0 -78
- package/constellation/use-primitives-text/usage.mdx +0 -35
- package/constellation/use-tokens-space/usage.mdx +0 -34
- package/constellation/use-tokens-typography/usage.mdx +0 -55
- package/constellation/use-visually-hidden/usage.mdx +0 -35
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _createRule = require("../utils/create-rule");
|
|
8
|
+
var _errorBoundary = require("../utils/error-boundary");
|
|
9
|
+
var _hasProp = require("./checks/has-prop");
|
|
10
|
+
var _isFromImportSource = require("./checks/is-from-import-source");
|
|
11
|
+
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
12
|
+
|
|
13
|
+
var rule = (0, _createRule.createLintRule)({
|
|
14
|
+
meta: {
|
|
15
|
+
name: 'no-custom-icons',
|
|
16
|
+
type: 'problem',
|
|
17
|
+
docs: {
|
|
18
|
+
description: 'Enforces custom glyph icons are used.',
|
|
19
|
+
recommended: false,
|
|
20
|
+
severity: 'warn'
|
|
21
|
+
},
|
|
22
|
+
schema: [{
|
|
23
|
+
type: 'object',
|
|
24
|
+
properties: {
|
|
25
|
+
centralLocation: {
|
|
26
|
+
type: 'string'
|
|
27
|
+
},
|
|
28
|
+
failSilently: {
|
|
29
|
+
type: 'boolean'
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
additionalProperties: false
|
|
33
|
+
}],
|
|
34
|
+
messages: {
|
|
35
|
+
noCustomIcons: "Custom icons from {{importSource}} are no longer supported. Migrate to an icon from '@atlaskit/(icon-labs|icon/core|icon/utility)'{{locationMessage}}.\n[Migration guide](https://hello.atlassian.net/wiki/spaces/DST/pages/3748692796/New+ADS+iconography+-+Code+migration+guide)."
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
create: function create(context) {
|
|
39
|
+
var _context$options$;
|
|
40
|
+
var isIconBase = (0, _isFromImportSource.createIsFromImportSourceFor)('@atlaskit/icon', '@atlaskit/icon/base');
|
|
41
|
+
var _ref = (_context$options$ = context.options[0]) !== null && _context$options$ !== void 0 ? _context$options$ : {},
|
|
42
|
+
_ref$centralLocation = _ref.centralLocation,
|
|
43
|
+
centralLocation = _ref$centralLocation === void 0 ? '' : _ref$centralLocation,
|
|
44
|
+
_ref$failSilently = _ref.failSilently,
|
|
45
|
+
failSilently = _ref$failSilently === void 0 ? false : _ref$failSilently;
|
|
46
|
+
var locationMessage = centralLocation ? " or move the icon to '".concat(centralLocation, "'") : '';
|
|
47
|
+
return (0, _errorBoundary.errorBoundary)({
|
|
48
|
+
JSXElement: function JSXElement(node) {
|
|
49
|
+
var _isIconBase$getImport;
|
|
50
|
+
if (!isIconBase(node) || !(0, _hasProp.hasProp)(node, 'glyph')) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
var importSource = (_isIconBase$getImport = isIconBase.getImportSource(node)) !== null && _isIconBase$getImport !== void 0 ? _isIconBase$getImport : '';
|
|
54
|
+
context.report({
|
|
55
|
+
node: node.openingElement,
|
|
56
|
+
messageId: 'noCustomIcons',
|
|
57
|
+
data: {
|
|
58
|
+
importSource: importSource,
|
|
59
|
+
locationMessage: locationMessage
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
},
|
|
63
|
+
ImportDeclaration: isIconBase.importDeclarationHook
|
|
64
|
+
}, failSilently);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
var _default = exports.default = rule;
|
|
@@ -141,25 +141,36 @@ var createChecks = exports.createChecks = function createChecks(context) {
|
|
|
141
141
|
if (typeof moduleSource === 'string' && ['@atlaskit/icon/glyph/', '@atlaskit/icon-object/glyph/'].find(function (val) {
|
|
142
142
|
return moduleSource.startsWith(val);
|
|
143
143
|
}) && node.specifiers.length) {
|
|
144
|
-
|
|
145
|
-
|
|
144
|
+
var _iterator4 = _createForOfIteratorHelper(node.specifiers),
|
|
145
|
+
_step4;
|
|
146
|
+
try {
|
|
147
|
+
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
148
|
+
var spec = _step4.value;
|
|
149
|
+
(0, _helpers.createCantMigrateReExportError)(spec, moduleSource, spec.exported.name, errorsManual);
|
|
150
|
+
guidance[(0, _helpers.locToString)(spec)] = (0, _helpers.createGuidance)(moduleSource);
|
|
151
|
+
}
|
|
152
|
+
} catch (err) {
|
|
153
|
+
_iterator4.e(err);
|
|
154
|
+
} finally {
|
|
155
|
+
_iterator4.f();
|
|
156
|
+
}
|
|
146
157
|
}
|
|
147
158
|
} else if (node.declaration && (0, _eslintCodemodUtils.isNodeOfType)(node.declaration, 'VariableDeclaration')) {
|
|
148
159
|
// export const Icon = AddIcon;
|
|
149
|
-
var
|
|
150
|
-
|
|
160
|
+
var _iterator5 = _createForOfIteratorHelper(node.declaration.declarations),
|
|
161
|
+
_step5;
|
|
151
162
|
try {
|
|
152
|
-
for (
|
|
153
|
-
var decl =
|
|
163
|
+
for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
|
|
164
|
+
var decl = _step5.value;
|
|
154
165
|
if ((0, _eslintCodemodUtils.isNodeOfType)(decl, 'VariableDeclarator') && 'init' in decl && decl.init && (0, _eslintCodemodUtils.isNodeOfType)(decl.init, 'Identifier') && decl.init.name in legacyIconImports) {
|
|
155
166
|
(0, _helpers.createCantMigrateReExportError)(node, legacyIconImports[decl.init.name].packageName, decl.init.name, errorsManual);
|
|
156
|
-
guidance[(0, _helpers.locToString)(node)] = (0, _helpers.createGuidance)(
|
|
167
|
+
guidance[(0, _helpers.locToString)(node)] = (0, _helpers.createGuidance)(legacyIconImports[decl.init.name].packageName);
|
|
157
168
|
}
|
|
158
169
|
}
|
|
159
170
|
} catch (err) {
|
|
160
|
-
|
|
171
|
+
_iterator5.e(err);
|
|
161
172
|
} finally {
|
|
162
|
-
|
|
173
|
+
_iterator5.f();
|
|
163
174
|
}
|
|
164
175
|
} else if (!node.source && node.specifiers && node.specifiers.length > 0) {
|
|
165
176
|
/**
|
|
@@ -168,25 +179,25 @@ var createChecks = exports.createChecks = function createChecks(context) {
|
|
|
168
179
|
* const crossIcon = LegacyIcon2;
|
|
169
180
|
* export { AddIcon, CrossIcon as default }
|
|
170
181
|
*/
|
|
171
|
-
var
|
|
172
|
-
|
|
182
|
+
var _iterator6 = _createForOfIteratorHelper(node.specifiers),
|
|
183
|
+
_step6;
|
|
173
184
|
try {
|
|
174
|
-
for (
|
|
175
|
-
var
|
|
176
|
-
if (
|
|
185
|
+
for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
|
|
186
|
+
var _spec2 = _step6.value;
|
|
187
|
+
if (_spec2.local.name in legacyIconImports) {
|
|
177
188
|
//update legacy imports to be exported
|
|
178
|
-
legacyIconImports[
|
|
179
|
-
packageName: legacyIconImports[
|
|
189
|
+
legacyIconImports[_spec2.local.name] = {
|
|
190
|
+
packageName: legacyIconImports[_spec2.local.name].packageName,
|
|
180
191
|
exported: true
|
|
181
192
|
};
|
|
182
|
-
(0, _helpers.createCantMigrateReExportError)(
|
|
183
|
-
guidance[(0, _helpers.locToString)(
|
|
193
|
+
(0, _helpers.createCantMigrateReExportError)(_spec2, legacyIconImports[_spec2.local.name].packageName, _spec2.exported.name, errorsManual);
|
|
194
|
+
guidance[(0, _helpers.locToString)(_spec2)] = (0, _helpers.createGuidance)(legacyIconImports[_spec2.local.name].packageName);
|
|
184
195
|
}
|
|
185
196
|
}
|
|
186
197
|
} catch (err) {
|
|
187
|
-
|
|
198
|
+
_iterator6.e(err);
|
|
188
199
|
} finally {
|
|
189
|
-
|
|
200
|
+
_iterator6.f();
|
|
190
201
|
}
|
|
191
202
|
}
|
|
192
203
|
};
|
|
@@ -233,18 +244,17 @@ var createChecks = exports.createChecks = function createChecks(context) {
|
|
|
233
244
|
UNSAFE_propName = result.UNSAFE_propName;
|
|
234
245
|
}
|
|
235
246
|
if (newIcon && isInNewButton && isNewIconMigratable && UNSAFE_size !== 'large' && UNSAFE_size !== 'xlarge') {
|
|
236
|
-
|
|
237
|
-
(0, _helpers.
|
|
238
|
-
guidance[(0, _helpers.locToString)(node)] = (0, _helpers.createGuidance)(legacyIconImports[node.name].packageName, 'medium');
|
|
247
|
+
(0, _helpers.createAutoMigrationError)(node, legacyIconImports[node.name].packageName, node.name, errorsAuto);
|
|
248
|
+
guidance[(0, _helpers.locToString)(node)] = (0, _helpers.createGuidance)(legacyIconImports[node.name].packageName, isInNewButton, 'medium');
|
|
239
249
|
} else if ((!newIcon || !isNewIconMigratable) && !UNSAFE_size) {
|
|
240
250
|
(0, _helpers.createCantFindSuitableReplacementError)(node, legacyIconImports[node.name].packageName, node.name, errorsManual);
|
|
241
|
-
guidance[(0, _helpers.locToString)(node)] = (0, _helpers.createGuidance)(legacyIconImports[node.name].packageName);
|
|
251
|
+
guidance[(0, _helpers.locToString)(node)] = (0, _helpers.createGuidance)(legacyIconImports[node.name].packageName, isInNewButton);
|
|
242
252
|
} else if ((UNSAFE_size === 'large' || UNSAFE_size === 'xlarge') && UNSAFE_propName) {
|
|
243
253
|
(0, _helpers.createCantMigrateUnsafeProp)(node, UNSAFE_propName, UNSAFE_size, legacyIconImports[node.name].packageName, node.name, errorsManual);
|
|
244
|
-
guidance[(0, _helpers.locToString)(node)] = (0, _helpers.createGuidance)(legacyIconImports[node.name].packageName, UNSAFE_size);
|
|
254
|
+
guidance[(0, _helpers.locToString)(node)] = (0, _helpers.createGuidance)(legacyIconImports[node.name].packageName, isInNewButton, UNSAFE_size);
|
|
245
255
|
} else if (!isInNewButton) {
|
|
246
256
|
(0, _helpers.createCantMigrateFunctionUnknownError)(node, legacyIconImports[node.name].packageName, node.name, errorsManual);
|
|
247
|
-
guidance[(0, _helpers.locToString)(node)] = (0, _helpers.createGuidance)(legacyIconImports[node.name].packageName);
|
|
257
|
+
guidance[(0, _helpers.locToString)(node)] = (0, _helpers.createGuidance)(legacyIconImports[node.name].packageName, isInNewButton);
|
|
248
258
|
}
|
|
249
259
|
}
|
|
250
260
|
};
|
|
@@ -287,11 +297,11 @@ var createChecks = exports.createChecks = function createChecks(context) {
|
|
|
287
297
|
var requiredAttributesAfterSpread = new Set(['size', 'primaryColor', 'secondaryColor']);
|
|
288
298
|
var hasSpread = false;
|
|
289
299
|
var hasPrimaryColorProp = false;
|
|
290
|
-
var
|
|
291
|
-
|
|
300
|
+
var _iterator7 = _createForOfIteratorHelper(node.openingElement.attributes),
|
|
301
|
+
_step7;
|
|
292
302
|
try {
|
|
293
|
-
for (
|
|
294
|
-
var attr =
|
|
303
|
+
for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
|
|
304
|
+
var attr = _step7.value;
|
|
295
305
|
// Detect spread props
|
|
296
306
|
if ((0, _eslintCodemodUtils.isNodeOfType)(attr, 'JSXSpreadAttribute')) {
|
|
297
307
|
// In case there are more spread props
|
|
@@ -324,9 +334,9 @@ var createChecks = exports.createChecks = function createChecks(context) {
|
|
|
324
334
|
}
|
|
325
335
|
}
|
|
326
336
|
} catch (err) {
|
|
327
|
-
|
|
337
|
+
_iterator7.e(err);
|
|
328
338
|
} finally {
|
|
329
|
-
|
|
339
|
+
_iterator7.f();
|
|
330
340
|
}
|
|
331
341
|
var hasManualMigration = false;
|
|
332
342
|
if (primaryColor && !(0, _helpers.canMigrateColor)(primaryColor) || hasPrimaryColorProp && !primaryColor) {
|
|
@@ -340,7 +350,6 @@ var createChecks = exports.createChecks = function createChecks(context) {
|
|
|
340
350
|
(0, _helpers.createCantMigrateSizeUnknown)(node, errorsManual, legacyIconImports[name].packageName, name);
|
|
341
351
|
hasManualMigration = true;
|
|
342
352
|
}
|
|
343
|
-
guidance[(0, _helpers.locToString)(node)] = (0, _helpers.createGuidance)(legacyIconImports[name].packageName, size ? size : undefined);
|
|
344
353
|
// Check for unsafe size
|
|
345
354
|
if ((UNSAFE_size === 'large' || UNSAFE_size === 'xlarge') && (UNSAFE_propName === 'UNSAFE_iconAfter_size' || UNSAFE_propName === 'UNSAFE_iconBefore_size' || UNSAFE_propName === 'UNSAFE_size')) {
|
|
346
355
|
(0, _helpers.createCantMigrateUnsafeProp)(node, UNSAFE_propName, UNSAFE_size, legacyIconImports[name].packageName, name, errorsManual);
|
|
@@ -362,14 +371,14 @@ var createChecks = exports.createChecks = function createChecks(context) {
|
|
|
362
371
|
hasManualMigration = true;
|
|
363
372
|
}
|
|
364
373
|
var migrationMapObject = (0, _helpers.getMigrationMapObject)(legacyIconImports[name].packageName);
|
|
365
|
-
var iconKey = (0, _helpers.getIconKey)(legacyIconImports[name].packageName);
|
|
366
374
|
var newIcon = migrationMapObject === null || migrationMapObject === void 0 ? void 0 : migrationMapObject.newIcon;
|
|
367
375
|
var isNewIconMigratable = (0, _helpers.canAutoMigrateNewIconBasedOnSize)(migrationMapObject === null || migrationMapObject === void 0 ? void 0 : migrationMapObject.sizeGuidance[(_size = size) !== null && _size !== void 0 ? _size : 'medium']);
|
|
368
376
|
if (!hasManualMigration && newIcon && isNewIconMigratable) {
|
|
369
|
-
(0, _helpers.createAutoMigrationError)(node, legacyIconImports[name].packageName, name,
|
|
377
|
+
(0, _helpers.createAutoMigrationError)(node, legacyIconImports[name].packageName, name, errorsAuto);
|
|
370
378
|
} else if ((!newIcon || !isNewIconMigratable) && size) {
|
|
371
|
-
(0, _helpers.createCantFindSuitableReplacementError)(node, legacyIconImports[name].packageName, name, errorsManual);
|
|
379
|
+
(0, _helpers.createCantFindSuitableReplacementError)(node, legacyIconImports[name].packageName, name, errorsManual, migrationMapObject ? true : false);
|
|
372
380
|
}
|
|
381
|
+
guidance[(0, _helpers.locToString)(node)] = (0, _helpers.createGuidance)(legacyIconImports[name].packageName, insideNewButton, size && (0, _migrationMapTemp.isSize)(size) ? size : undefined);
|
|
373
382
|
}
|
|
374
383
|
};
|
|
375
384
|
|
|
@@ -379,20 +388,20 @@ var createChecks = exports.createChecks = function createChecks(context) {
|
|
|
379
388
|
*/
|
|
380
389
|
var checkCallExpression = function checkCallExpression(node) {
|
|
381
390
|
if ('arguments' in node && node.arguments.length) {
|
|
382
|
-
var
|
|
383
|
-
|
|
391
|
+
var _iterator8 = _createForOfIteratorHelper(node.arguments),
|
|
392
|
+
_step8;
|
|
384
393
|
try {
|
|
385
|
-
for (
|
|
386
|
-
var arg =
|
|
394
|
+
for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
|
|
395
|
+
var arg = _step8.value;
|
|
387
396
|
if ((0, _eslintCodemodUtils.isNodeOfType)(arg, 'Identifier') && arg.name in legacyIconImports && legacyIconImports[arg.name].packageName) {
|
|
388
397
|
(0, _helpers.createCantMigrateFunctionUnknownError)(node, legacyIconImports[arg.name].packageName, arg.name, errorsManual);
|
|
389
398
|
guidance[(0, _helpers.locToString)(node)] = (0, _helpers.createGuidance)(legacyIconImports[arg.name].packageName);
|
|
390
399
|
}
|
|
391
400
|
}
|
|
392
401
|
} catch (err) {
|
|
393
|
-
|
|
402
|
+
_iterator8.e(err);
|
|
394
403
|
} finally {
|
|
395
|
-
|
|
404
|
+
_iterator8.f();
|
|
396
405
|
}
|
|
397
406
|
}
|
|
398
407
|
};
|
|
@@ -408,36 +417,28 @@ var createChecks = exports.createChecks = function createChecks(context) {
|
|
|
408
417
|
errorList = _Object$entries$_i[1];
|
|
409
418
|
var node = 'node' in errorList.errors[0] ? errorList.errors[0].node : null;
|
|
410
419
|
if (node) {
|
|
420
|
+
var guidanceMessage = _key in guidance ? guidance[_key] : '';
|
|
411
421
|
context.report({
|
|
412
422
|
node: node,
|
|
413
423
|
messageId: 'noLegacyIconsManualMigration',
|
|
414
424
|
data: {
|
|
415
425
|
iconName: errorList.iconName,
|
|
416
426
|
importSource: errorList.importSource,
|
|
417
|
-
|
|
427
|
+
guidance: isQuietMode ? guidanceMessage : "".concat(guidanceMessage, "For more information see the below errors.\n")
|
|
418
428
|
}
|
|
419
429
|
});
|
|
420
430
|
if (!isQuietMode) {
|
|
421
|
-
var
|
|
422
|
-
|
|
431
|
+
var _iterator9 = _createForOfIteratorHelper(errorList.errors),
|
|
432
|
+
_step9;
|
|
423
433
|
try {
|
|
424
|
-
for (
|
|
425
|
-
var error =
|
|
434
|
+
for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
|
|
435
|
+
var error = _step9.value;
|
|
426
436
|
context.report(error);
|
|
427
437
|
}
|
|
428
438
|
} catch (err) {
|
|
429
|
-
|
|
439
|
+
_iterator9.e(err);
|
|
430
440
|
} finally {
|
|
431
|
-
|
|
432
|
-
}
|
|
433
|
-
if (_key in guidance) {
|
|
434
|
-
context.report({
|
|
435
|
-
node: node,
|
|
436
|
-
messageId: 'guidance',
|
|
437
|
-
data: {
|
|
438
|
-
guidance: guidance[_key]
|
|
439
|
-
}
|
|
440
|
-
});
|
|
441
|
+
_iterator9.f();
|
|
441
442
|
}
|
|
442
443
|
}
|
|
443
444
|
}
|
|
@@ -456,16 +457,11 @@ var createChecks = exports.createChecks = function createChecks(context) {
|
|
|
456
457
|
}
|
|
457
458
|
var _node = 'node' in _error ? _error.node : null;
|
|
458
459
|
if (_node) {
|
|
459
|
-
|
|
460
|
-
if (
|
|
461
|
-
|
|
462
|
-
node: _node,
|
|
463
|
-
messageId: 'guidance',
|
|
464
|
-
data: {
|
|
465
|
-
guidance: guidance[_key2]
|
|
466
|
-
}
|
|
467
|
-
});
|
|
460
|
+
var _guidanceMessage = _key2 in guidance ? guidance[_key2] : '';
|
|
461
|
+
if ('data' in _error && _error.data) {
|
|
462
|
+
_error.data.guidance = _guidanceMessage;
|
|
468
463
|
}
|
|
464
|
+
context.report(_error);
|
|
469
465
|
}
|
|
470
466
|
}
|
|
471
467
|
}
|
|
@@ -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.locToString = exports.getMigrationMapObject = exports.getLiteralStringValue = exports.
|
|
8
|
+
exports.locToString = exports.getMigrationMapObject = exports.getLiteralStringValue = exports.findUNSAFEProp = exports.createHelpers = exports.createGuidance = exports.createCantMigrateUnsafeProp = 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
11
|
var _getImportName = require("../utils/get-import-name");
|
|
@@ -30,7 +30,7 @@ var getMigrationMapObject = exports.getMigrationMapObject = function getMigratio
|
|
|
30
30
|
* @param iconPackage The name of the legacy icon package
|
|
31
31
|
* @returns The unique identifier for the icon (the part after "@atlaskit/icon/glyph")
|
|
32
32
|
*/
|
|
33
|
-
var getIconKey =
|
|
33
|
+
var getIconKey = function getIconKey(iconPackage) {
|
|
34
34
|
var key = iconPackage.replace(/^@atlaskit\/icon\/glyph\//, '');
|
|
35
35
|
return key;
|
|
36
36
|
};
|
|
@@ -45,39 +45,48 @@ var canAutoMigrateNewIconBasedOnSize = exports.canAutoMigrateNewIconBasedOnSize
|
|
|
45
45
|
/**
|
|
46
46
|
* Creates the written guidance for migrating a legacy icon to a new icon
|
|
47
47
|
*/
|
|
48
|
-
var createGuidance = exports.createGuidance = function createGuidance(iconPackage
|
|
48
|
+
var createGuidance = exports.createGuidance = function createGuidance(iconPackage) {
|
|
49
|
+
var insideNewButton = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
50
|
+
var size = arguments.length > 2 ? arguments[2] : undefined;
|
|
49
51
|
var migrationMapObject = getMigrationMapObject(iconPackage);
|
|
50
52
|
if (migrationMapObject) {
|
|
51
53
|
var newIcon = migrationMapObject.newIcon;
|
|
52
54
|
if (!newIcon) {
|
|
53
55
|
return 'No equivalent icon in new set. An option is to contribute a custom icon into icon-labs package instead.\n';
|
|
54
56
|
}
|
|
57
|
+
var buttonGuidanceStr = "Please set 'spacing' property of the new icon to 'none', to ensure appropriate spacing inside `@atlaskit/button`.\n";
|
|
58
|
+
var guidance = '';
|
|
55
59
|
if (size) {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
guidance += " Please: ".concat(_migrationMapTemp.outcomeDescriptionMap[migrationMapObject.sizeGuidance[size]], "\n");
|
|
60
|
+
if (migrationMapObject.sizeGuidance[size] && canAutoMigrateNewIconBasedOnSize(migrationMapObject.sizeGuidance[size])) {
|
|
61
|
+
guidance += "Fix: Use ".concat(newIcon.name, " from @atlaskit/").concat(newIcon.library, "/").concat(newIcon.type, "/").concat(newIcon.name, " instead.");
|
|
59
62
|
} else {
|
|
60
|
-
guidance +=
|
|
63
|
+
guidance += "No equivalent icon for this size, ".concat(size, ", in new set.");
|
|
61
64
|
}
|
|
62
|
-
|
|
65
|
+
guidance += "".concat(migrationMapObject.sizeGuidance[size] in _migrationMapTemp.outcomeDescriptionMap ? " Please: ".concat(_migrationMapTemp.outcomeDescriptionMap[migrationMapObject.sizeGuidance[size]]) : ' No migration size advice given.', "\n");
|
|
63
66
|
} else {
|
|
64
|
-
|
|
67
|
+
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");
|
|
65
68
|
for (var _i = 0, _Object$entries = Object.entries(migrationMapObject.sizeGuidance); _i < _Object$entries.length; _i++) {
|
|
66
69
|
var _Object$entries$_i = (0, _slicedToArray2.default)(_Object$entries[_i], 2),
|
|
67
70
|
_size = _Object$entries$_i[0],
|
|
68
71
|
value = _Object$entries$_i[1];
|
|
69
|
-
|
|
72
|
+
guidance += "\t- ".concat(_size, ": ");
|
|
70
73
|
if (!(value in _migrationMapTemp.outcomeDescriptionMap)) {
|
|
71
|
-
|
|
74
|
+
guidance += 'No migration advice given.\n';
|
|
72
75
|
} else {
|
|
73
|
-
|
|
76
|
+
guidance += "".concat(_migrationMapTemp.outcomeDescriptionMap[value], ".\n");
|
|
74
77
|
}
|
|
75
|
-
_guidance;
|
|
76
78
|
}
|
|
77
|
-
return _guidance;
|
|
78
79
|
}
|
|
80
|
+
if (insideNewButton) {
|
|
81
|
+
guidance += buttonGuidanceStr;
|
|
82
|
+
} else if (size && size === 'medium') {
|
|
83
|
+
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
|
+
} else if (size) {
|
|
85
|
+
guidance += "In the new icon, please use spacing='none'.\n";
|
|
86
|
+
}
|
|
87
|
+
return guidance;
|
|
79
88
|
} else {
|
|
80
|
-
return
|
|
89
|
+
return "Migration suggestions not found for \"".concat(iconPackage, "\".\n");
|
|
81
90
|
}
|
|
82
91
|
};
|
|
83
92
|
|
|
@@ -155,13 +164,14 @@ var createCantMigrateUnsafeProp = exports.createCantMigrateUnsafeProp = function
|
|
|
155
164
|
};
|
|
156
165
|
pushManualError(locToString(node), errors, myError, packageName, iconName);
|
|
157
166
|
};
|
|
158
|
-
var createCantFindSuitableReplacementError = exports.createCantFindSuitableReplacementError = function createCantFindSuitableReplacementError(node, importSource, iconName, errors) {
|
|
167
|
+
var createCantFindSuitableReplacementError = exports.createCantFindSuitableReplacementError = function createCantFindSuitableReplacementError(node, importSource, iconName, errors, sizeIssue) {
|
|
159
168
|
var myError = {
|
|
160
169
|
node: node,
|
|
161
170
|
messageId: 'cantFindSuitableReplacement',
|
|
162
171
|
data: {
|
|
163
172
|
importSource: importSource,
|
|
164
|
-
iconName: iconName
|
|
173
|
+
iconName: iconName,
|
|
174
|
+
sizeGuidance: sizeIssue ? ' at the current size' : ''
|
|
165
175
|
}
|
|
166
176
|
};
|
|
167
177
|
pushManualError(locToString(node), errors, myError, importSource, iconName);
|
|
@@ -204,18 +214,13 @@ var createCantMigrateSizeUnknown = exports.createCantMigrateSizeUnknown = functi
|
|
|
204
214
|
};
|
|
205
215
|
pushManualError(locToString(node), errors, myError, importSource, iconName);
|
|
206
216
|
};
|
|
207
|
-
var createAutoMigrationError = exports.createAutoMigrationError = function createAutoMigrationError(node, importSource, iconName,
|
|
208
|
-
var migrationKey = newIcon.name === oldIconName ? newIcon.name : "".concat(newIcon.name, "--").concat(oldIconName);
|
|
209
|
-
var newMigrationIconPackage = "@atlaskit/".concat(newIcon.library, "/").concat(newIcon.type, "/migration/").concat(migrationKey);
|
|
217
|
+
var createAutoMigrationError = exports.createAutoMigrationError = function createAutoMigrationError(node, importSource, iconName, errors) {
|
|
210
218
|
var myError = {
|
|
211
219
|
node: node,
|
|
212
220
|
messageId: 'noLegacyIconsAutoMigration',
|
|
213
221
|
data: {
|
|
214
222
|
importSource: importSource,
|
|
215
|
-
iconName: iconName
|
|
216
|
-
newIcon: newIcon.name,
|
|
217
|
-
//TODO: provide size guidance
|
|
218
|
-
newPackage: newMigrationIconPackage
|
|
223
|
+
iconName: iconName
|
|
219
224
|
}
|
|
220
225
|
};
|
|
221
226
|
errors[locToString(node)] = myError;
|
|
@@ -33,17 +33,16 @@ var rule = (0, _createRule.createLintRule)({
|
|
|
33
33
|
additionalProperties: false
|
|
34
34
|
}],
|
|
35
35
|
messages: {
|
|
36
|
-
noLegacyIconsAutoMigration: "Auto Migration:\nLegacy icon '{{iconName}}' from '{{importSource}}' detected.\nAutomatic migration is possible
|
|
37
|
-
noLegacyIconsManualMigration: "Manual Migration:\nLegacy icon '{{iconName}}' from '{{importSource}}' detected.\nAutomatic migration not possible
|
|
38
|
-
cantFindSuitableReplacement: "No suitable replacement found for '{{iconName}}' from '{{importSource}}'
|
|
36
|
+
noLegacyIconsAutoMigration: "Auto Migration:\nLegacy icon '{{iconName}}' from '{{importSource}}' detected.\nAutomatic migration is possible.\n\n{{guidance}}\nAtlassians: See https://go.atlassian.com/icon-migration-guide for details.'",
|
|
37
|
+
noLegacyIconsManualMigration: "Manual Migration:\nLegacy icon '{{iconName}}' from '{{importSource}}' detected.\nAutomatic migration not possible.\n\n{{guidance}}\nAtlassians: See https://go.atlassian.com/icon-migration-guide for details.",
|
|
38
|
+
cantFindSuitableReplacement: "No suitable replacement found for '{{iconName}}' from '{{importSource}}'{{sizeGuidance}}. Please manually migrate this icon.",
|
|
39
39
|
cantMigrateReExport: "'{{exportName}}' is a re-export of icon from '{{packageName}}' and cannot be automatically migrated. Please utilize the export from icons directly.",
|
|
40
40
|
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).",
|
|
41
41
|
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}}' ",
|
|
42
42
|
cantMigrateSizeUnknown: "This usage of Icon sets the size via a variable or function that can't be determined.",
|
|
43
43
|
cantMigrateFunctionUnknown: "'{{iconName}}' from legacy '{{importSource}}' is used in unknown function/component. Please manually migrate this icon.",
|
|
44
44
|
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.",
|
|
45
|
-
cantMigrateUnsafeProp: "Property '{{propName}}' with value of '{{value}}' is unable to be auto-migrated to the new button. Please manually migrate this icon."
|
|
46
|
-
guidance: "Guidance:\n'{{guidance}}'"
|
|
45
|
+
cantMigrateUnsafeProp: "Property '{{propName}}' with value of '{{value}}' is unable to be auto-migrated to the new button. Please manually migrate this icon."
|
|
47
46
|
}
|
|
48
47
|
},
|
|
49
48
|
create: function create(context) {
|
|
@@ -60,95 +59,23 @@ var rule = (0, _createRule.createLintRule)({
|
|
|
60
59
|
checkJSXElement = _createChecks.checkJSXElement,
|
|
61
60
|
checkCallExpression = _createChecks.checkCallExpression,
|
|
62
61
|
throwErrors = _createChecks.throwErrors;
|
|
63
|
-
return {
|
|
62
|
+
return (0, _errorBoundary.errorBoundary)({
|
|
64
63
|
// Track imports of relevant components
|
|
65
|
-
ImportDeclaration:
|
|
66
|
-
(0, _errorBoundary.errorBoundary)(function () {
|
|
67
|
-
return checkImportDeclarations(node);
|
|
68
|
-
}, {
|
|
69
|
-
config: {
|
|
70
|
-
failSilently: failSilently
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
},
|
|
64
|
+
ImportDeclaration: checkImportDeclarations,
|
|
74
65
|
// Keep track of the relevant variable declarations and renames
|
|
75
|
-
VariableDeclaration:
|
|
76
|
-
(0, _errorBoundary.errorBoundary)(function () {
|
|
77
|
-
return checkVariableDeclarations(node);
|
|
78
|
-
}, {
|
|
79
|
-
config: {
|
|
80
|
-
failSilently: failSilently
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
},
|
|
66
|
+
VariableDeclaration: checkVariableDeclarations,
|
|
84
67
|
// Case: default re-exports. Can't be auto-migrated
|
|
85
|
-
ExportDefaultDeclaration:
|
|
86
|
-
|
|
87
|
-
return checkExportDefaultDeclaration(node);
|
|
88
|
-
}, {
|
|
89
|
-
config: {
|
|
90
|
-
failSilently: failSilently
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
|
-
},
|
|
94
|
-
ExportNamedDeclaration: function ExportNamedDeclaration(node) {
|
|
95
|
-
(0, _errorBoundary.errorBoundary)(function () {
|
|
96
|
-
return checkExportNamedVariables(node);
|
|
97
|
-
}, {
|
|
98
|
-
config: {
|
|
99
|
-
failSilently: failSilently
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
},
|
|
68
|
+
ExportDefaultDeclaration: checkExportDefaultDeclaration,
|
|
69
|
+
ExportNamedDeclaration: checkExportNamedVariables,
|
|
103
70
|
// Legacy icons found in arrays/objects
|
|
104
|
-
'ObjectExpression > Property > Identifier, ArrayExpression > Identifier ':
|
|
105
|
-
(0, _errorBoundary.errorBoundary)(function () {
|
|
106
|
-
return checkArrayOrMap(node);
|
|
107
|
-
}, {
|
|
108
|
-
config: {
|
|
109
|
-
failSilently: failSilently
|
|
110
|
-
}
|
|
111
|
-
});
|
|
112
|
-
},
|
|
71
|
+
'ObjectExpression > Property > Identifier, ArrayExpression > Identifier ': checkArrayOrMap,
|
|
113
72
|
// Legacy icons passed in via props, as JSX identifier (i.e. icon={AddIcon})
|
|
114
|
-
'JSXOpeningElement > JSXAttribute > JSXExpressionContainer > Identifier':
|
|
115
|
-
|
|
116
|
-
return checkIconAsProp(node);
|
|
117
|
-
}, {
|
|
118
|
-
config: {
|
|
119
|
-
failSilently: failSilently
|
|
120
|
-
}
|
|
121
|
-
});
|
|
122
|
-
},
|
|
123
|
-
JSXElement: function JSXElement(node) {
|
|
124
|
-
(0, _errorBoundary.errorBoundary)(function () {
|
|
125
|
-
return checkJSXElement(node);
|
|
126
|
-
}, {
|
|
127
|
-
config: {
|
|
128
|
-
failSilently: failSilently
|
|
129
|
-
}
|
|
130
|
-
});
|
|
131
|
-
},
|
|
73
|
+
'JSXOpeningElement > JSXAttribute > JSXExpressionContainer > Identifier': checkIconAsProp,
|
|
74
|
+
JSXElement: checkJSXElement,
|
|
132
75
|
// Icons called as an argument of a function (i.e. icon={DefaultIcon(AddIcon)})
|
|
133
|
-
CallExpression:
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
}, {
|
|
137
|
-
config: {
|
|
138
|
-
failSilently: failSilently
|
|
139
|
-
}
|
|
140
|
-
});
|
|
141
|
-
},
|
|
142
|
-
'Program:exit': function ProgramExit() {
|
|
143
|
-
(0, _errorBoundary.errorBoundary)(function () {
|
|
144
|
-
return throwErrors();
|
|
145
|
-
}, {
|
|
146
|
-
config: {
|
|
147
|
-
failSilently: failSilently
|
|
148
|
-
}
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
|
-
};
|
|
76
|
+
CallExpression: checkCallExpression,
|
|
77
|
+
'Program:exit': throwErrors
|
|
78
|
+
}, failSilently);
|
|
152
79
|
}
|
|
153
80
|
});
|
|
154
81
|
var _default = exports.default = rule;
|
|
@@ -12,16 +12,12 @@ var create = function create(context) {
|
|
|
12
12
|
var config = (0, _config.getConfig)(context.options[0]);
|
|
13
13
|
return {
|
|
14
14
|
// const styles = css({ fontSize: '14px, ... }), styled.div({ fontSize: 14, ... })
|
|
15
|
-
ObjectExpression: function
|
|
16
|
-
return (
|
|
17
|
-
|
|
18
|
-
context: context,
|
|
19
|
-
config: config
|
|
20
|
-
});
|
|
21
|
-
}, {
|
|
15
|
+
ObjectExpression: (0, _errorBoundary.errorBoundary)(function (node) {
|
|
16
|
+
return _styleObject.StyleObject.lint(node, {
|
|
17
|
+
context: context,
|
|
22
18
|
config: config
|
|
23
19
|
});
|
|
24
|
-
}
|
|
20
|
+
}, config)
|
|
25
21
|
};
|
|
26
22
|
};
|
|
27
23
|
var rule = (0, _createRule.createLintRule)({
|