@atlaskit/eslint-plugin-design-system 10.16.0 → 10.17.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 -1
- package/dist/cjs/rules/no-legacy-icons/checks.js +272 -84
- package/dist/cjs/rules/no-legacy-icons/helpers.js +214 -14
- package/dist/cjs/rules/no-legacy-icons/index.js +4 -0
- package/dist/cjs/rules/no-legacy-icons/upcoming-icons.js +1 -1
- package/dist/es2019/rules/no-legacy-icons/checks.js +190 -24
- package/dist/es2019/rules/no-legacy-icons/helpers.js +220 -6
- package/dist/es2019/rules/no-legacy-icons/index.js +4 -0
- package/dist/es2019/rules/no-legacy-icons/upcoming-icons.js +1 -1
- package/dist/esm/rules/no-legacy-icons/checks.js +273 -85
- package/dist/esm/rules/no-legacy-icons/helpers.js +214 -14
- package/dist/esm/rules/no-legacy-icons/index.js +4 -0
- package/dist/esm/rules/no-legacy-icons/upcoming-icons.js +1 -1
- package/dist/types/rules/no-legacy-icons/helpers.d.ts +88 -3
- package/dist/types-ts4.5/rules/no-legacy-icons/helpers.d.ts +88 -3
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# @atlaskit/eslint-plugin-design-system
|
|
2
2
|
|
|
3
|
+
## 10.17.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#133643](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/133643)
|
|
8
|
+
[`1ab5ca9bddc97`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/1ab5ca9bddc97) -
|
|
9
|
+
Updated the list of upcoming icons after a new set of icons were added
|
|
10
|
+
- Updated dependencies
|
|
11
|
+
|
|
12
|
+
## 10.17.0
|
|
13
|
+
|
|
14
|
+
### Minor Changes
|
|
15
|
+
|
|
16
|
+
- [#131211](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/131211)
|
|
17
|
+
[`9877a261592a7`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/9877a261592a7) -
|
|
18
|
+
Added an autofixer for `no-legacy-icons` eslint rule which migrates icons in the "Auto Migration"
|
|
19
|
+
category to new icons. Use `shouldUseMigrationPath` option to control the import path of the new
|
|
20
|
+
icon.
|
|
21
|
+
|
|
3
22
|
## 10.16.0
|
|
4
23
|
|
|
5
24
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -68,7 +68,7 @@ module.exports = {
|
|
|
68
68
|
| <a href="./src/rules/no-html-button/README.md">no-html-button</a> | Discourage direct usage of HTML button elements in favor of Atlassian Design System button components. | Yes | | |
|
|
69
69
|
| <a href="./src/rules/no-invalid-css-map/README.md">no-invalid-css-map</a> | Checks the validity of a CSS map created through cssMap. This is intended to be used alongside TypeScript's type-checking. | Yes | | |
|
|
70
70
|
| <a href="./src/rules/no-keyframes-tagged-template-expression/README.md">no-keyframes-tagged-template-expression</a> | Disallows any `keyframe` tagged template expressions that originate from Emotion, Styled Components or Compiled | | Yes | |
|
|
71
|
-
| <a href="./src/rules/no-legacy-icons/README.md">no-legacy-icons</a> | Enforces no legacy icons are used. | |
|
|
71
|
+
| <a href="./src/rules/no-legacy-icons/README.md">no-legacy-icons</a> | Enforces no legacy icons are used. | | Yes | |
|
|
72
72
|
| <a href="./src/rules/no-margin/README.md">no-margin</a> | Disallow using the margin CSS property. | | | |
|
|
73
73
|
| <a href="./src/rules/no-nested-styles/README.md">no-nested-styles</a> | Disallows use of nested styles in `css` functions. | Yes | | |
|
|
74
74
|
| <a href="./src/rules/no-physical-properties/README.md">no-physical-properties</a> | Disallow physical properties and values in `css` function calls. | | Yes | |
|
|
@@ -5,9 +5,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports.createChecks = void 0;
|
|
8
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
9
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
8
10
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
9
11
|
var _eslintCodemodUtils = require("eslint-codemod-utils");
|
|
10
12
|
var _helpers = require("./helpers");
|
|
13
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
14
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
11
15
|
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; } } }; }
|
|
12
16
|
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); }
|
|
13
17
|
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; }
|
|
@@ -17,15 +21,19 @@ var createChecks = exports.createChecks = function createChecks(context) {
|
|
|
17
21
|
getPrimaryColor = _createHelpers.getPrimaryColor,
|
|
18
22
|
getConfigFlag = _createHelpers.getConfigFlag;
|
|
19
23
|
var legacyIconImports = {};
|
|
24
|
+
var migrationIconImports = {};
|
|
20
25
|
var newButtonImports = new Set();
|
|
26
|
+
var legacyButtonImports = new Set();
|
|
21
27
|
var errorsManual = {};
|
|
22
28
|
var errorsAuto = {};
|
|
23
29
|
var guidance = {};
|
|
30
|
+
var autoIconJSXElementOccurrenceCount = 0;
|
|
24
31
|
|
|
25
32
|
// Extract parameters
|
|
26
33
|
var shouldErrorForManualMigration = getConfigFlag('shouldErrorForManualMigration', true);
|
|
27
34
|
var shouldErrorForAutoMigration = getConfigFlag('shouldErrorForAutoMigration', true);
|
|
28
35
|
var isQuietMode = getConfigFlag('quiet', false);
|
|
36
|
+
var shouldUseMigrationPath = getConfigFlag('shouldUseMigrationPath', true);
|
|
29
37
|
|
|
30
38
|
// Sorted list of ranges
|
|
31
39
|
var errorRanges = [];
|
|
@@ -49,7 +57,8 @@ var createChecks = exports.createChecks = function createChecks(context) {
|
|
|
49
57
|
if (spec.local.name) {
|
|
50
58
|
legacyIconImports[spec.local.name] = {
|
|
51
59
|
packageName: moduleSource,
|
|
52
|
-
exported: false
|
|
60
|
+
exported: false,
|
|
61
|
+
importNode: node
|
|
53
62
|
};
|
|
54
63
|
}
|
|
55
64
|
}
|
|
@@ -60,6 +69,19 @@ var createChecks = exports.createChecks = function createChecks(context) {
|
|
|
60
69
|
}
|
|
61
70
|
}
|
|
62
71
|
|
|
72
|
+
// Find the imports for icons that import from migration path
|
|
73
|
+
if (moduleSource && typeof moduleSource === 'string' && (moduleSource.startsWith('@atlaskit/icon/core/migration/') || moduleSource.startsWith('@atlaskit/icon/utility/migration/')) && node.specifiers.length) {
|
|
74
|
+
node.specifiers.forEach(function (spec) {
|
|
75
|
+
if (spec.local.name) {
|
|
76
|
+
migrationIconImports[spec.local.name] = {
|
|
77
|
+
packageName: moduleSource,
|
|
78
|
+
exported: false,
|
|
79
|
+
importNode: node
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
63
85
|
// Find the imports for new button and IconButton
|
|
64
86
|
if (typeof moduleSource === 'string' && moduleSource.startsWith('@atlaskit/button/new') && node.specifiers.length) {
|
|
65
87
|
var _iterator2 = _createForOfIteratorHelper(node.specifiers),
|
|
@@ -79,6 +101,24 @@ var createChecks = exports.createChecks = function createChecks(context) {
|
|
|
79
101
|
_iterator2.f();
|
|
80
102
|
}
|
|
81
103
|
}
|
|
104
|
+
|
|
105
|
+
// Find the imports for legacy default button
|
|
106
|
+
if (typeof moduleSource === 'string' && (moduleSource === '@atlaskit/button' || moduleSource === '@atlaskit/button/standard-button' || moduleSource === '@atlaskit/button/loading-button' || moduleSource === '@atlaskit/button/custom-theme-button') && node.specifiers.length) {
|
|
107
|
+
var _iterator3 = _createForOfIteratorHelper(node.specifiers),
|
|
108
|
+
_step3;
|
|
109
|
+
try {
|
|
110
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
111
|
+
var _spec2 = _step3.value;
|
|
112
|
+
if (_spec2.type === 'ImportDefaultSpecifier') {
|
|
113
|
+
legacyButtonImports.add(_spec2.local.name);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
} catch (err) {
|
|
117
|
+
_iterator3.e(err);
|
|
118
|
+
} finally {
|
|
119
|
+
_iterator3.f();
|
|
120
|
+
}
|
|
121
|
+
}
|
|
82
122
|
};
|
|
83
123
|
|
|
84
124
|
/**
|
|
@@ -88,11 +128,11 @@ var createChecks = exports.createChecks = function createChecks(context) {
|
|
|
88
128
|
var checkVariableDeclarations = function checkVariableDeclarations(node) {
|
|
89
129
|
if ((0, _eslintCodemodUtils.isNodeOfType)(node, 'VariableDeclaration')) {
|
|
90
130
|
var isExported = node.parent && (0, _eslintCodemodUtils.isNodeOfType)(node.parent, 'ExportNamedDeclaration');
|
|
91
|
-
var
|
|
92
|
-
|
|
131
|
+
var _iterator4 = _createForOfIteratorHelper(node.declarations),
|
|
132
|
+
_step4;
|
|
93
133
|
try {
|
|
94
|
-
for (
|
|
95
|
-
var decl =
|
|
134
|
+
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
135
|
+
var decl = _step4.value;
|
|
96
136
|
if ((0, _eslintCodemodUtils.isNodeOfType)(decl, 'VariableDeclarator') && Object.keys(decl).includes('init') && Object.keys(decl).includes('id') && decl.init && decl.id && 'name' in decl.id && decl.id.name && (0, _eslintCodemodUtils.isNodeOfType)(decl.init, 'Identifier')) {
|
|
97
137
|
if (Object.keys(legacyIconImports).includes(decl.init.name)) {
|
|
98
138
|
legacyIconImports[decl.id.name] = {
|
|
@@ -105,9 +145,9 @@ var createChecks = exports.createChecks = function createChecks(context) {
|
|
|
105
145
|
}
|
|
106
146
|
}
|
|
107
147
|
} catch (err) {
|
|
108
|
-
|
|
148
|
+
_iterator4.e(err);
|
|
109
149
|
} finally {
|
|
110
|
-
|
|
150
|
+
_iterator4.f();
|
|
111
151
|
}
|
|
112
152
|
}
|
|
113
153
|
};
|
|
@@ -130,7 +170,10 @@ var createChecks = exports.createChecks = function createChecks(context) {
|
|
|
130
170
|
}
|
|
131
171
|
(0, _helpers.createCantMigrateReExportError)(node, packageName, exportName, errorsManual);
|
|
132
172
|
(0, _helpers.addToListOfRanges)(node, errorRanges);
|
|
133
|
-
guidance[(0, _helpers.locToString)(node)] = (0, _helpers.createGuidance)(
|
|
173
|
+
guidance[(0, _helpers.locToString)(node)] = (0, _helpers.createGuidance)({
|
|
174
|
+
iconPackage: packageName,
|
|
175
|
+
shouldUseMigrationPath: shouldUseMigrationPath
|
|
176
|
+
});
|
|
134
177
|
};
|
|
135
178
|
|
|
136
179
|
/**
|
|
@@ -144,38 +187,44 @@ var createChecks = exports.createChecks = function createChecks(context) {
|
|
|
144
187
|
if (typeof moduleSource === 'string' && ['@atlaskit/icon/glyph/', '@atlaskit/icon-object/glyph/'].find(function (val) {
|
|
145
188
|
return moduleSource.startsWith(val);
|
|
146
189
|
}) && node.specifiers.length) {
|
|
147
|
-
var
|
|
148
|
-
|
|
190
|
+
var _iterator5 = _createForOfIteratorHelper(node.specifiers),
|
|
191
|
+
_step5;
|
|
149
192
|
try {
|
|
150
|
-
for (
|
|
151
|
-
var spec =
|
|
193
|
+
for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
|
|
194
|
+
var spec = _step5.value;
|
|
152
195
|
(0, _helpers.createCantMigrateReExportError)(spec, moduleSource, spec.exported.name, errorsManual);
|
|
153
196
|
(0, _helpers.addToListOfRanges)(spec, errorRanges);
|
|
154
|
-
guidance[(0, _helpers.locToString)(spec)] = (0, _helpers.createGuidance)(
|
|
197
|
+
guidance[(0, _helpers.locToString)(spec)] = (0, _helpers.createGuidance)({
|
|
198
|
+
iconPackage: moduleSource,
|
|
199
|
+
shouldUseMigrationPath: shouldUseMigrationPath
|
|
200
|
+
});
|
|
155
201
|
}
|
|
156
202
|
} catch (err) {
|
|
157
|
-
|
|
203
|
+
_iterator5.e(err);
|
|
158
204
|
} finally {
|
|
159
|
-
|
|
205
|
+
_iterator5.f();
|
|
160
206
|
}
|
|
161
207
|
}
|
|
162
208
|
} else if (node.declaration && (0, _eslintCodemodUtils.isNodeOfType)(node.declaration, 'VariableDeclaration')) {
|
|
163
209
|
// export const Icon = AddIcon;
|
|
164
|
-
var
|
|
165
|
-
|
|
210
|
+
var _iterator6 = _createForOfIteratorHelper(node.declaration.declarations),
|
|
211
|
+
_step6;
|
|
166
212
|
try {
|
|
167
|
-
for (
|
|
168
|
-
var decl =
|
|
213
|
+
for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
|
|
214
|
+
var decl = _step6.value;
|
|
169
215
|
if ((0, _eslintCodemodUtils.isNodeOfType)(decl, 'VariableDeclarator') && Object.keys(decl).includes('init') && decl.init && (0, _eslintCodemodUtils.isNodeOfType)(decl.init, 'Identifier') && Object.keys(legacyIconImports).includes(decl.init.name)) {
|
|
170
216
|
(0, _helpers.createCantMigrateReExportError)(node, legacyIconImports[decl.init.name].packageName, decl.init.name, errorsManual);
|
|
171
217
|
(0, _helpers.addToListOfRanges)(node, errorRanges);
|
|
172
|
-
guidance[(0, _helpers.locToString)(node)] = (0, _helpers.createGuidance)(
|
|
218
|
+
guidance[(0, _helpers.locToString)(node)] = (0, _helpers.createGuidance)({
|
|
219
|
+
iconPackage: legacyIconImports[decl.init.name].packageName,
|
|
220
|
+
shouldUseMigrationPath: shouldUseMigrationPath
|
|
221
|
+
});
|
|
173
222
|
}
|
|
174
223
|
}
|
|
175
224
|
} catch (err) {
|
|
176
|
-
|
|
225
|
+
_iterator6.e(err);
|
|
177
226
|
} finally {
|
|
178
|
-
|
|
227
|
+
_iterator6.f();
|
|
179
228
|
}
|
|
180
229
|
} else if (!node.source && node.specifiers && node.specifiers.length > 0) {
|
|
181
230
|
/**
|
|
@@ -184,26 +233,29 @@ var createChecks = exports.createChecks = function createChecks(context) {
|
|
|
184
233
|
* const crossIcon = LegacyIcon2;
|
|
185
234
|
* export { AddIcon, CrossIcon as default }
|
|
186
235
|
*/
|
|
187
|
-
var
|
|
188
|
-
|
|
236
|
+
var _iterator7 = _createForOfIteratorHelper(node.specifiers),
|
|
237
|
+
_step7;
|
|
189
238
|
try {
|
|
190
|
-
for (
|
|
191
|
-
var
|
|
192
|
-
if (Object.keys(legacyIconImports).includes(
|
|
239
|
+
for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
|
|
240
|
+
var _spec3 = _step7.value;
|
|
241
|
+
if (Object.keys(legacyIconImports).includes(_spec3.local.name)) {
|
|
193
242
|
//update legacy imports to be exported
|
|
194
|
-
legacyIconImports[
|
|
195
|
-
packageName: legacyIconImports[
|
|
243
|
+
legacyIconImports[_spec3.local.name] = {
|
|
244
|
+
packageName: legacyIconImports[_spec3.local.name].packageName,
|
|
196
245
|
exported: true
|
|
197
246
|
};
|
|
198
|
-
(0, _helpers.createCantMigrateReExportError)(
|
|
199
|
-
(0, _helpers.addToListOfRanges)(
|
|
200
|
-
guidance[(0, _helpers.locToString)(
|
|
247
|
+
(0, _helpers.createCantMigrateReExportError)(_spec3, legacyIconImports[_spec3.local.name].packageName, _spec3.exported.name, errorsManual);
|
|
248
|
+
(0, _helpers.addToListOfRanges)(_spec3, errorRanges);
|
|
249
|
+
guidance[(0, _helpers.locToString)(_spec3)] = (0, _helpers.createGuidance)({
|
|
250
|
+
iconPackage: legacyIconImports[_spec3.local.name].packageName,
|
|
251
|
+
shouldUseMigrationPath: shouldUseMigrationPath
|
|
252
|
+
});
|
|
201
253
|
}
|
|
202
254
|
}
|
|
203
255
|
} catch (err) {
|
|
204
|
-
|
|
256
|
+
_iterator7.e(err);
|
|
205
257
|
} finally {
|
|
206
|
-
|
|
258
|
+
_iterator7.f();
|
|
207
259
|
}
|
|
208
260
|
}
|
|
209
261
|
};
|
|
@@ -219,7 +271,10 @@ var createChecks = exports.createChecks = function createChecks(context) {
|
|
|
219
271
|
if (node.name && Object.keys(legacyIconImports).includes(node.name) && legacyIconImports[node.name].packageName) {
|
|
220
272
|
(0, _helpers.createCantMigrateIdentifierMapOrArrayError)(node, legacyIconImports[node.name].packageName, node.name, errorsManual);
|
|
221
273
|
(0, _helpers.addToListOfRanges)(node, errorRanges);
|
|
222
|
-
guidance[(0, _helpers.locToString)(node)] = (0, _helpers.createGuidance)(
|
|
274
|
+
guidance[(0, _helpers.locToString)(node)] = (0, _helpers.createGuidance)({
|
|
275
|
+
iconPackage: legacyIconImports[node.name].packageName,
|
|
276
|
+
shouldUseMigrationPath: shouldUseMigrationPath
|
|
277
|
+
});
|
|
223
278
|
}
|
|
224
279
|
};
|
|
225
280
|
|
|
@@ -245,29 +300,59 @@ var createChecks = exports.createChecks = function createChecks(context) {
|
|
|
245
300
|
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);
|
|
246
301
|
var isInNewButton = (0, _eslintCodemodUtils.isNodeOfType)(node.parent.parent.parent.name, 'JSXIdentifier') && newButtonImports.has(node.parent.parent.parent.name.name);
|
|
247
302
|
if (newIcon && isInNewButton && isNewIconMigratable || upcomingIcon && isInNewButton && isNewIconMigratable) {
|
|
248
|
-
(0, _helpers.createAutoMigrationError)(
|
|
303
|
+
(0, _helpers.createAutoMigrationError)({
|
|
304
|
+
node: node,
|
|
305
|
+
importSource: legacyIconImports[node.name].packageName,
|
|
306
|
+
iconName: node.name,
|
|
307
|
+
errors: errorsAuto
|
|
308
|
+
});
|
|
249
309
|
(0, _helpers.addToListOfRanges)(node, errorRanges);
|
|
250
|
-
guidance[(0, _helpers.locToString)(node)] = (0, _helpers.createGuidance)(
|
|
310
|
+
guidance[(0, _helpers.locToString)(node)] = (0, _helpers.createGuidance)({
|
|
311
|
+
iconPackage: legacyIconImports[node.name].packageName,
|
|
312
|
+
insideNewButton: true,
|
|
313
|
+
size: 'medium',
|
|
314
|
+
shouldUseMigrationPath: shouldUseMigrationPath
|
|
315
|
+
});
|
|
251
316
|
} else if (!newIcon && !upcomingIcon || !isNewIconMigratable) {
|
|
252
317
|
(0, _helpers.createCantFindSuitableReplacementError)(node, legacyIconImports[node.name].packageName, node.name, errorsManual);
|
|
253
318
|
(0, _helpers.addToListOfRanges)(node, errorRanges);
|
|
254
|
-
guidance[(0, _helpers.locToString)(node)] = (0, _helpers.createGuidance)(
|
|
319
|
+
guidance[(0, _helpers.locToString)(node)] = (0, _helpers.createGuidance)({
|
|
320
|
+
iconPackage: legacyIconImports[node.name].packageName,
|
|
321
|
+
insideNewButton: isInNewButton,
|
|
322
|
+
shouldUseMigrationPath: shouldUseMigrationPath
|
|
323
|
+
});
|
|
255
324
|
} else if (!isInNewButton) {
|
|
256
325
|
(0, _helpers.createCantMigrateFunctionUnknownError)(node, legacyIconImports[node.name].packageName, node.name, errorsManual);
|
|
257
326
|
(0, _helpers.addToListOfRanges)(node, errorRanges);
|
|
258
|
-
guidance[(0, _helpers.locToString)(node)] = (0, _helpers.createGuidance)(
|
|
327
|
+
guidance[(0, _helpers.locToString)(node)] = (0, _helpers.createGuidance)({
|
|
328
|
+
iconPackage: legacyIconImports[node.name].packageName,
|
|
329
|
+
insideNewButton: false,
|
|
330
|
+
shouldUseMigrationPath: shouldUseMigrationPath
|
|
331
|
+
});
|
|
259
332
|
}
|
|
260
333
|
}
|
|
261
334
|
};
|
|
262
335
|
var checkIconReference = function checkIconReference(node) {
|
|
263
|
-
//check the reference to see if it's a legacy icon, if not exit early
|
|
264
|
-
if (!Object.keys(legacyIconImports).includes(node.name)) {
|
|
265
|
-
return;
|
|
266
|
-
}
|
|
267
336
|
//if this is an import statement then exit early
|
|
268
337
|
if (node.parent && ((0, _eslintCodemodUtils.isNodeOfType)(node.parent, 'ImportSpecifier') || (0, _eslintCodemodUtils.isNodeOfType)(node.parent, 'ImportDefaultSpecifier'))) {
|
|
269
338
|
return;
|
|
270
339
|
}
|
|
340
|
+
|
|
341
|
+
// Flag icons imported from migration path
|
|
342
|
+
if (!shouldUseMigrationPath && Object.keys(migrationIconImports).includes(node.name)) {
|
|
343
|
+
(0, _helpers.createAutoMigrationError)({
|
|
344
|
+
node: node,
|
|
345
|
+
importSource: migrationIconImports[node.name].packageName,
|
|
346
|
+
iconName: node.name,
|
|
347
|
+
errors: errorsAuto
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
//check the reference to see if it's a legacy icon, if not exit early
|
|
352
|
+
if (!Object.keys(legacyIconImports).includes(node.name)) {
|
|
353
|
+
return;
|
|
354
|
+
}
|
|
355
|
+
|
|
271
356
|
//if in Fallback prop, do not error
|
|
272
357
|
if (node.parent && node.parent.parent && (0, _eslintCodemodUtils.isNodeOfType)(node.parent.parent, 'JSXAttribute') && (0, _eslintCodemodUtils.isNodeOfType)(node.parent.parent.name, 'JSXIdentifier') && node.parent.parent.name.name === 'LEGACY_fallbackIcon') {
|
|
273
358
|
return;
|
|
@@ -291,15 +376,38 @@ var createChecks = exports.createChecks = function createChecks(context) {
|
|
|
291
376
|
return;
|
|
292
377
|
}
|
|
293
378
|
var name = node.openingElement.name.name;
|
|
379
|
+
|
|
380
|
+
// Flag icons imported from migration path
|
|
381
|
+
if (!shouldUseMigrationPath && Object.keys(migrationIconImports).includes(name)) {
|
|
382
|
+
var _sizeProp$value;
|
|
383
|
+
var sizeProp = node.openingElement.attributes.find(function (attribute) {
|
|
384
|
+
return attribute.type === 'JSXAttribute' && (attribute.name.name === 'size' || attribute.name.name === 'LEGACY_size');
|
|
385
|
+
});
|
|
386
|
+
var insideNewButton = (0, _helpers.isInsideNewButton)(node, newButtonImports);
|
|
387
|
+
// Add spacious spacing if:
|
|
388
|
+
// 1. size is medium, or not set (default is medium)
|
|
389
|
+
// 2. not inside a new or legacy button
|
|
390
|
+
var shouldAddSpaciousSpacing = (sizeProp && sizeProp.type === 'JSXAttribute' && ((_sizeProp$value = sizeProp.value) === null || _sizeProp$value === void 0 ? void 0 : _sizeProp$value.type) === 'Literal' && sizeProp.value.value === 'medium' || !sizeProp) && !(0, _helpers.isInsideNewButton)(node, newButtonImports) && !(0, _helpers.isInsideLegacyButton)(node, legacyButtonImports);
|
|
391
|
+
(0, _helpers.createAutoMigrationError)({
|
|
392
|
+
node: node,
|
|
393
|
+
importSource: migrationIconImports[name].packageName,
|
|
394
|
+
iconName: name,
|
|
395
|
+
errors: errorsAuto,
|
|
396
|
+
shouldAddSpaciousSpacing: shouldAddSpaciousSpacing,
|
|
397
|
+
insideNewButton: insideNewButton
|
|
398
|
+
});
|
|
399
|
+
}
|
|
400
|
+
|
|
294
401
|
// Legacy icons rendered as JSX elements
|
|
295
402
|
if (Object.keys(legacyIconImports).includes(name)) {
|
|
296
|
-
var
|
|
403
|
+
var _size, _size2, _sizeProp$value2;
|
|
297
404
|
// Determine if inside a new button - if so:
|
|
298
405
|
// - Assume spread props are safe - still error if props explicitly set to unmigratable values
|
|
299
|
-
var
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
406
|
+
var _insideNewButton = (0, _helpers.isInsideNewButton)(node, newButtonImports);
|
|
407
|
+
|
|
408
|
+
// Determine if inside a legacy default button - if so:
|
|
409
|
+
// the auto fixer will add spacing prop to the medium size icon
|
|
410
|
+
var insideLegacyButton = (0, _helpers.isInsideLegacyButton)(node, legacyButtonImports);
|
|
303
411
|
|
|
304
412
|
// Find size prop on node
|
|
305
413
|
var size = 'medium';
|
|
@@ -308,11 +416,11 @@ var createChecks = exports.createChecks = function createChecks(context) {
|
|
|
308
416
|
var requiredAttributesAfterSpread = new Set(['size', 'primaryColor', 'secondaryColor']);
|
|
309
417
|
var hasSpread = false;
|
|
310
418
|
var hasPrimaryColorProp = false;
|
|
311
|
-
var
|
|
312
|
-
|
|
419
|
+
var _iterator8 = _createForOfIteratorHelper(node.openingElement.attributes),
|
|
420
|
+
_step8;
|
|
313
421
|
try {
|
|
314
|
-
for (
|
|
315
|
-
var attr =
|
|
422
|
+
for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
|
|
423
|
+
var attr = _step8.value;
|
|
316
424
|
// Detect spread props
|
|
317
425
|
if ((0, _eslintCodemodUtils.isNodeOfType)(attr, 'JSXSpreadAttribute')) {
|
|
318
426
|
// In case there are more spread props
|
|
@@ -345,9 +453,9 @@ var createChecks = exports.createChecks = function createChecks(context) {
|
|
|
345
453
|
}
|
|
346
454
|
}
|
|
347
455
|
} catch (err) {
|
|
348
|
-
|
|
456
|
+
_iterator8.e(err);
|
|
349
457
|
} finally {
|
|
350
|
-
|
|
458
|
+
_iterator8.f();
|
|
351
459
|
}
|
|
352
460
|
var hasManualMigration = false;
|
|
353
461
|
if (primaryColor && !(0, _helpers.canMigrateColor)(primaryColor) || hasPrimaryColorProp && !primaryColor) {
|
|
@@ -364,7 +472,7 @@ var createChecks = exports.createChecks = function createChecks(context) {
|
|
|
364
472
|
// Do a set comparison - is requiredAttributesAfterSpread a subset of afterSpreadSet?
|
|
365
473
|
if (hasSpread === true && !Array.from(requiredAttributesAfterSpread).every(function (val) {
|
|
366
474
|
return afterSpreadSet.has(val);
|
|
367
|
-
}) && !
|
|
475
|
+
}) && !_insideNewButton) {
|
|
368
476
|
var missingProps = Array.from(requiredAttributesAfterSpread).filter(function (val) {
|
|
369
477
|
return !afterSpreadSet.has(val);
|
|
370
478
|
});
|
|
@@ -380,13 +488,34 @@ var createChecks = exports.createChecks = function createChecks(context) {
|
|
|
380
488
|
var upcomingIcon = (0, _helpers.getUpcomingIcons)(legacyIconImports[name].packageName);
|
|
381
489
|
var newIcon = migrationMapObject === null || migrationMapObject === void 0 ? void 0 : migrationMapObject.newIcon;
|
|
382
490
|
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']);
|
|
491
|
+
|
|
492
|
+
// Add spacious spacing if:
|
|
493
|
+
// 1. size is medium, or not set (default is medium)
|
|
494
|
+
// 2. not inside a new or legacy button
|
|
495
|
+
var _sizeProp = node.openingElement.attributes.find(function (attribute) {
|
|
496
|
+
return attribute.type === 'JSXAttribute' && (attribute.name.name === 'size' || attribute.name.name === 'LEGACY_size');
|
|
497
|
+
});
|
|
498
|
+
var _shouldAddSpaciousSpacing = (_sizeProp && _sizeProp.type === 'JSXAttribute' && ((_sizeProp$value2 = _sizeProp.value) === null || _sizeProp$value2 === void 0 ? void 0 : _sizeProp$value2.type) === 'Literal' && _sizeProp.value.value === 'medium' || !_sizeProp) && !_insideNewButton && !insideLegacyButton;
|
|
383
499
|
if (!hasManualMigration && (newIcon || upcomingIcon) && isNewIconMigratable) {
|
|
384
|
-
|
|
500
|
+
autoIconJSXElementOccurrenceCount++;
|
|
501
|
+
(0, _helpers.createAutoMigrationError)({
|
|
502
|
+
node: node,
|
|
503
|
+
importSource: legacyIconImports[name].packageName,
|
|
504
|
+
iconName: name,
|
|
505
|
+
errors: errorsAuto,
|
|
506
|
+
shouldAddSpaciousSpacing: _shouldAddSpaciousSpacing,
|
|
507
|
+
insideNewButton: _insideNewButton
|
|
508
|
+
});
|
|
385
509
|
} else if ((!newIcon && !upcomingIcon || !isNewIconMigratable) && size) {
|
|
386
510
|
(0, _helpers.createCantFindSuitableReplacementError)(node, legacyIconImports[name].packageName, name, errorsManual, upcomingIcon ? true : migrationMapObject ? true : false);
|
|
387
511
|
}
|
|
388
512
|
(0, _helpers.addToListOfRanges)(node, errorRanges);
|
|
389
|
-
guidance[(0, _helpers.locToString)(node)] = (0, _helpers.createGuidance)(
|
|
513
|
+
guidance[(0, _helpers.locToString)(node)] = (0, _helpers.createGuidance)({
|
|
514
|
+
iconPackage: legacyIconImports[name].packageName,
|
|
515
|
+
insideNewButton: _insideNewButton,
|
|
516
|
+
size: size && (0, _helpers.isSize)(size) ? size : undefined,
|
|
517
|
+
shouldUseMigrationPath: shouldUseMigrationPath
|
|
518
|
+
});
|
|
390
519
|
}
|
|
391
520
|
};
|
|
392
521
|
|
|
@@ -396,21 +525,24 @@ var createChecks = exports.createChecks = function createChecks(context) {
|
|
|
396
525
|
*/
|
|
397
526
|
var checkCallExpression = function checkCallExpression(node) {
|
|
398
527
|
if (Object.keys(node).includes('arguments') && node.arguments.length) {
|
|
399
|
-
var
|
|
400
|
-
|
|
528
|
+
var _iterator9 = _createForOfIteratorHelper(node.arguments),
|
|
529
|
+
_step9;
|
|
401
530
|
try {
|
|
402
|
-
for (
|
|
403
|
-
var arg =
|
|
531
|
+
for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
|
|
532
|
+
var arg = _step9.value;
|
|
404
533
|
if ((0, _eslintCodemodUtils.isNodeOfType)(arg, 'Identifier') && Object.keys(legacyIconImports).includes(arg.name) && legacyIconImports[arg.name].packageName) {
|
|
405
534
|
(0, _helpers.createCantMigrateFunctionUnknownError)(node, legacyIconImports[arg.name].packageName, arg.name, errorsManual);
|
|
406
535
|
(0, _helpers.addToListOfRanges)(node, errorRanges);
|
|
407
|
-
guidance[(0, _helpers.locToString)(node)] = (0, _helpers.createGuidance)(
|
|
536
|
+
guidance[(0, _helpers.locToString)(node)] = (0, _helpers.createGuidance)({
|
|
537
|
+
iconPackage: legacyIconImports[arg.name].packageName,
|
|
538
|
+
shouldUseMigrationPath: shouldUseMigrationPath
|
|
539
|
+
});
|
|
408
540
|
}
|
|
409
541
|
}
|
|
410
542
|
} catch (err) {
|
|
411
|
-
|
|
543
|
+
_iterator9.e(err);
|
|
412
544
|
} finally {
|
|
413
|
-
|
|
545
|
+
_iterator9.f();
|
|
414
546
|
}
|
|
415
547
|
}
|
|
416
548
|
};
|
|
@@ -445,19 +577,19 @@ var createChecks = exports.createChecks = function createChecks(context) {
|
|
|
445
577
|
}
|
|
446
578
|
});
|
|
447
579
|
if (!isQuietMode) {
|
|
448
|
-
var
|
|
449
|
-
|
|
580
|
+
var _iterator10 = _createForOfIteratorHelper(errorList.errors),
|
|
581
|
+
_step10;
|
|
450
582
|
try {
|
|
451
|
-
for (
|
|
452
|
-
var error =
|
|
583
|
+
for (_iterator10.s(); !(_step10 = _iterator10.n()).done;) {
|
|
584
|
+
var error = _step10.value;
|
|
453
585
|
if ('messageId' in error && (error.messageId !== 'cantMigrateIdentifier' || error.messageId === 'cantMigrateIdentifier' && !isInRange)) {
|
|
454
586
|
context.report(error);
|
|
455
587
|
}
|
|
456
588
|
}
|
|
457
589
|
} catch (err) {
|
|
458
|
-
|
|
590
|
+
_iterator10.e(err);
|
|
459
591
|
} finally {
|
|
460
|
-
|
|
592
|
+
_iterator10.f();
|
|
461
593
|
}
|
|
462
594
|
}
|
|
463
595
|
}
|
|
@@ -465,28 +597,84 @@ var createChecks = exports.createChecks = function createChecks(context) {
|
|
|
465
597
|
}
|
|
466
598
|
}
|
|
467
599
|
if (shouldErrorForAutoMigration) {
|
|
468
|
-
|
|
600
|
+
var _loop = function _loop() {
|
|
469
601
|
var _Object$entries2$_i = (0, _slicedToArray2.default)(_Object$entries2[_i2], 2),
|
|
470
|
-
|
|
471
|
-
|
|
602
|
+
key = _Object$entries2$_i[0],
|
|
603
|
+
error = _Object$entries2$_i[1];
|
|
472
604
|
// If there's a manual error that exists for this same component,
|
|
473
605
|
// don't throw the auto error
|
|
474
|
-
if (Object.keys(errorsManual).includes(
|
|
475
|
-
var _cantMigrateIdentifierError = errorsManual[
|
|
606
|
+
if (Object.keys(errorsManual).includes(key)) {
|
|
607
|
+
var _cantMigrateIdentifierError = errorsManual[key].errors.find(function (x) {
|
|
476
608
|
return 'messageId' in x && x.messageId === 'cantMigrateIdentifier';
|
|
477
609
|
});
|
|
478
|
-
if (!_cantMigrateIdentifierError || _cantMigrateIdentifierError && errorsManual[
|
|
479
|
-
delete errorsAuto[
|
|
480
|
-
continue
|
|
610
|
+
if (!_cantMigrateIdentifierError || _cantMigrateIdentifierError && errorsManual[key].errors.length > 1) {
|
|
611
|
+
delete errorsAuto[key];
|
|
612
|
+
return 1; // continue
|
|
481
613
|
}
|
|
482
614
|
}
|
|
483
|
-
var
|
|
484
|
-
if (
|
|
485
|
-
var _guidanceMessage = Object.keys(guidance).includes(
|
|
486
|
-
if (Object.keys(
|
|
487
|
-
|
|
615
|
+
var node = 'node' in error ? error.node : null;
|
|
616
|
+
if (node) {
|
|
617
|
+
var _guidanceMessage = Object.keys(guidance).includes(key) ? guidance[key] : '';
|
|
618
|
+
if (Object.keys(error).includes('data') && error.data) {
|
|
619
|
+
error.data.guidance = _guidanceMessage;
|
|
488
620
|
}
|
|
489
|
-
context.report(
|
|
621
|
+
context.report(_objectSpread(_objectSpread({}, error), {}, {
|
|
622
|
+
fix: function fix(fixer) {
|
|
623
|
+
var _legacyIconImports$er, _migrationIconImports;
|
|
624
|
+
// don't migration if the new icon is not available
|
|
625
|
+
if (!error.data || shouldUseMigrationPath && !(0, _helpers.checkIfNewIconExist)(error)) {
|
|
626
|
+
return [];
|
|
627
|
+
}
|
|
628
|
+
var fixArguments = {
|
|
629
|
+
metadata: error.data,
|
|
630
|
+
legacyImportNode: (_legacyIconImports$er = legacyIconImports[error.data.iconName]) === null || _legacyIconImports$er === void 0 ? void 0 : _legacyIconImports$er.importNode,
|
|
631
|
+
migrationImportNode: (_migrationIconImports = migrationIconImports[error.data.iconName]) === null || _migrationIconImports === void 0 ? void 0 : _migrationIconImports.importNode,
|
|
632
|
+
shouldUseMigrationPath: shouldUseMigrationPath
|
|
633
|
+
};
|
|
634
|
+
var propsFixes = (0, _helpers.createPropFixes)(_objectSpread(_objectSpread({}, fixArguments), {}, {
|
|
635
|
+
node: node,
|
|
636
|
+
fixer: fixer
|
|
637
|
+
}));
|
|
638
|
+
var importFixes = [];
|
|
639
|
+
// Otherwise if there are multiple occurrences of the icon, import path will be handled after the prop fix
|
|
640
|
+
if (autoIconJSXElementOccurrenceCount <= 1) {
|
|
641
|
+
importFixes = (0, _helpers.createImportFix)(_objectSpread(_objectSpread({}, fixArguments), {}, {
|
|
642
|
+
fixer: fixer
|
|
643
|
+
}));
|
|
644
|
+
}
|
|
645
|
+
return [].concat((0, _toConsumableArray2.default)(propsFixes), (0, _toConsumableArray2.default)(importFixes));
|
|
646
|
+
}
|
|
647
|
+
}));
|
|
648
|
+
}
|
|
649
|
+
};
|
|
650
|
+
for (var _i2 = 0, _Object$entries2 = Object.entries(errorsAuto); _i2 < _Object$entries2.length; _i2++) {
|
|
651
|
+
if (_loop()) continue;
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
// Update import path at the end if there are multiple occurrences of the icon
|
|
655
|
+
if (autoIconJSXElementOccurrenceCount > 1) {
|
|
656
|
+
var _loop2 = function _loop2() {
|
|
657
|
+
var _Object$entries3$_i = (0, _slicedToArray2.default)(_Object$entries3[_i3], 2),
|
|
658
|
+
_ = _Object$entries3$_i[0],
|
|
659
|
+
error = _Object$entries3$_i[1];
|
|
660
|
+
context.report(_objectSpread(_objectSpread({}, error), {}, {
|
|
661
|
+
fix: function fix(fixer) {
|
|
662
|
+
var _legacyIconImports$er2, _migrationIconImports2;
|
|
663
|
+
if (!error.data || shouldUseMigrationPath && !(0, _helpers.checkIfNewIconExist)(error)) {
|
|
664
|
+
return [];
|
|
665
|
+
}
|
|
666
|
+
return (0, _helpers.createImportFix)({
|
|
667
|
+
metadata: error.data,
|
|
668
|
+
fixer: fixer,
|
|
669
|
+
legacyImportNode: (_legacyIconImports$er2 = legacyIconImports[error.data.iconName]) === null || _legacyIconImports$er2 === void 0 ? void 0 : _legacyIconImports$er2.importNode,
|
|
670
|
+
migrationImportNode: (_migrationIconImports2 = migrationIconImports[error.data.iconName]) === null || _migrationIconImports2 === void 0 ? void 0 : _migrationIconImports2.importNode,
|
|
671
|
+
shouldUseMigrationPath: shouldUseMigrationPath
|
|
672
|
+
});
|
|
673
|
+
}
|
|
674
|
+
}));
|
|
675
|
+
};
|
|
676
|
+
for (var _i3 = 0, _Object$entries3 = Object.entries(errorsAuto); _i3 < _Object$entries3.length; _i3++) {
|
|
677
|
+
_loop2();
|
|
490
678
|
}
|
|
491
679
|
}
|
|
492
680
|
}
|