@atlaskit/eslint-plugin-design-system 13.41.3 → 13.42.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 +16 -0
- package/README.md +0 -1
- package/dist/cjs/presets/all-flat.codegen.js +1 -2
- package/dist/cjs/presets/all.codegen.js +1 -2
- package/dist/cjs/rules/index.codegen.js +1 -3
- package/dist/cjs/rules/use-primitives/utils/is-valid-css-properties-to-transform.js +5 -4
- package/dist/es2019/presets/all-flat.codegen.js +1 -2
- package/dist/es2019/presets/all.codegen.js +1 -2
- package/dist/es2019/rules/index.codegen.js +1 -3
- package/dist/es2019/rules/use-primitives/utils/is-valid-css-properties-to-transform.js +5 -4
- package/dist/esm/presets/all-flat.codegen.js +1 -2
- package/dist/esm/presets/all.codegen.js +1 -2
- package/dist/esm/rules/index.codegen.js +1 -3
- package/dist/esm/rules/use-primitives/utils/is-valid-css-properties-to-transform.js +5 -4
- package/dist/types/presets/all-flat.codegen.d.ts +1 -1
- package/dist/types/presets/all.codegen.d.ts +1 -1
- package/dist/types/rules/ensure-design-token-usage/index.d.ts +1 -1
- package/dist/types/rules/ensure-design-token-usage/rule-meta.d.ts +1 -1
- package/dist/types/rules/ensure-design-token-usage/utils.d.ts +1 -1
- package/dist/types/rules/index.codegen.d.ts +1 -1
- package/dist/types/rules/no-deprecated-imports/handlers/icon.d.ts +1 -1
- package/dist/types/rules/use-heading/transformers/common.d.ts +2 -2
- package/dist/types/rules/use-latest-xcss-syntax-typography/linters/common.d.ts +1 -1
- package/dist/types/rules/use-latest-xcss-syntax-typography/linters/wrapped-token-value.d.ts +1 -1
- package/dist/types/rules/use-primitives/transformers/compiled-styled/index.d.ts +1 -1
- package/dist/types/rules/use-primitives/transformers/emotion-css/index.d.ts +1 -1
- package/dist/types/rules/use-primitives/utils/is-valid-css-properties-to-transform.d.ts +1 -1
- package/dist/types/rules/use-primitives/utils/validate-styles.d.ts +1 -1
- package/dist/types/rules/use-primitives-text/transformers/common.d.ts +1 -1
- package/dist/types/rules/use-primitives-text/transformers/unsafe-small-text.d.ts +1 -1
- package/dist/types/rules/use-tokens-typography/config/index.d.ts +1 -1
- package/dist/types/rules/use-tokens-typography/transformers/banned-properties.d.ts +1 -1
- package/dist/types/rules/use-tokens-typography/transformers/font-family.d.ts +1 -1
- package/dist/types/rules/use-tokens-typography/transformers/font-weight.d.ts +1 -1
- package/dist/types/rules/use-tokens-typography/transformers/restricted-capitalisation.d.ts +1 -1
- package/dist/types/rules/use-tokens-typography/transformers/style-object.d.ts +1 -1
- package/dist/types/rules/use-tokens-typography/transformers/untokenized-properties.d.ts +1 -1
- package/dist/types/rules/utils/create-no-exported-rule/check-if-supported-export.d.ts +1 -1
- package/dist/types/rules/utils/get-first-supported-import.d.ts +1 -1
- package/dist/types-ts4.5/presets/all-flat.codegen.d.ts +1 -1
- package/dist/types-ts4.5/presets/all.codegen.d.ts +1 -1
- package/dist/types-ts4.5/rules/ensure-design-token-usage/index.d.ts +1 -1
- package/dist/types-ts4.5/rules/ensure-design-token-usage/rule-meta.d.ts +1 -1
- package/dist/types-ts4.5/rules/ensure-design-token-usage/utils.d.ts +1 -1
- package/dist/types-ts4.5/rules/index.codegen.d.ts +1 -1
- package/dist/types-ts4.5/rules/no-deprecated-imports/handlers/icon.d.ts +1 -1
- package/dist/types-ts4.5/rules/use-heading/transformers/common.d.ts +2 -2
- package/dist/types-ts4.5/rules/use-latest-xcss-syntax-typography/linters/common.d.ts +1 -1
- package/dist/types-ts4.5/rules/use-latest-xcss-syntax-typography/linters/wrapped-token-value.d.ts +1 -1
- package/dist/types-ts4.5/rules/use-primitives/transformers/compiled-styled/index.d.ts +1 -1
- package/dist/types-ts4.5/rules/use-primitives/transformers/emotion-css/index.d.ts +1 -1
- package/dist/types-ts4.5/rules/use-primitives/utils/is-valid-css-properties-to-transform.d.ts +1 -1
- package/dist/types-ts4.5/rules/use-primitives/utils/validate-styles.d.ts +1 -1
- package/dist/types-ts4.5/rules/use-primitives-text/transformers/common.d.ts +1 -1
- package/dist/types-ts4.5/rules/use-primitives-text/transformers/unsafe-small-text.d.ts +1 -1
- package/dist/types-ts4.5/rules/use-tokens-typography/config/index.d.ts +1 -1
- package/dist/types-ts4.5/rules/use-tokens-typography/transformers/banned-properties.d.ts +1 -1
- package/dist/types-ts4.5/rules/use-tokens-typography/transformers/font-family.d.ts +1 -1
- package/dist/types-ts4.5/rules/use-tokens-typography/transformers/font-weight.d.ts +1 -1
- package/dist/types-ts4.5/rules/use-tokens-typography/transformers/restricted-capitalisation.d.ts +1 -1
- package/dist/types-ts4.5/rules/use-tokens-typography/transformers/style-object.d.ts +1 -1
- package/dist/types-ts4.5/rules/use-tokens-typography/transformers/untokenized-properties.d.ts +1 -1
- package/dist/types-ts4.5/rules/utils/create-no-exported-rule/check-if-supported-export.d.ts +1 -1
- package/dist/types-ts4.5/rules/utils/get-first-supported-import.d.ts +1 -1
- package/package.json +4 -4
- package/dist/cjs/rules/no-legacy-icons/checks.js +0 -619
- package/dist/cjs/rules/no-legacy-icons/helpers.js +0 -900
- package/dist/cjs/rules/no-legacy-icons/index.js +0 -91
- package/dist/cjs/rules/no-legacy-icons/upcoming-icons.js +0 -7
- package/dist/es2019/rules/no-legacy-icons/checks.js +0 -520
- package/dist/es2019/rules/no-legacy-icons/helpers.js +0 -853
- package/dist/es2019/rules/no-legacy-icons/index.js +0 -87
- package/dist/es2019/rules/no-legacy-icons/upcoming-icons.js +0 -1
- package/dist/esm/rules/no-legacy-icons/checks.js +0 -613
- package/dist/esm/rules/no-legacy-icons/helpers.js +0 -891
- package/dist/esm/rules/no-legacy-icons/index.js +0 -85
- package/dist/esm/rules/no-legacy-icons/upcoming-icons.js +0 -1
- package/dist/types/rules/no-legacy-icons/checks.d.ts +0 -16
- package/dist/types/rules/no-legacy-icons/helpers.d.ts +0 -151
- package/dist/types/rules/no-legacy-icons/index.d.ts +0 -2
- package/dist/types/rules/no-legacy-icons/upcoming-icons.d.ts +0 -1
- package/dist/types-ts4.5/rules/no-legacy-icons/checks.d.ts +0 -16
- package/dist/types-ts4.5/rules/no-legacy-icons/helpers.d.ts +0 -156
- package/dist/types-ts4.5/rules/no-legacy-icons/index.d.ts +0 -2
- package/dist/types-ts4.5/rules/no-legacy-icons/upcoming-icons.d.ts +0 -1
|
@@ -1,891 +0,0 @@
|
|
|
1
|
-
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
2
|
-
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
3
|
-
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
4
|
-
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; }
|
|
5
|
-
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) { _defineProperty(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; }
|
|
6
|
-
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, 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 o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
|
|
7
|
-
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
8
|
-
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
9
|
-
import { isNodeOfType, literal } from 'eslint-codemod-utils';
|
|
10
|
-
import baseMigrationMap, { migrationOutcomeDescriptionMap } from '@atlaskit/icon/migration-map';
|
|
11
|
-
import { upcomingIcons } from './upcoming-icons';
|
|
12
|
-
var sizes = ['small', 'medium', 'large', 'xlarge'];
|
|
13
|
-
export var isSize = function isSize(size) {
|
|
14
|
-
return sizes.includes(size);
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Returns the migration map object for a legacy icon or null if not found
|
|
19
|
-
* @param iconPackage The name of the legacy icon package
|
|
20
|
-
* @returns The migration map object for the legacy icon or null if not found
|
|
21
|
-
*/
|
|
22
|
-
export var getMigrationMapObject = function getMigrationMapObject(iconPackage) {
|
|
23
|
-
var key = getIconKey(iconPackage);
|
|
24
|
-
if (Object.keys(baseMigrationMap).includes(key)) {
|
|
25
|
-
return baseMigrationMap[key];
|
|
26
|
-
}
|
|
27
|
-
return null;
|
|
28
|
-
};
|
|
29
|
-
export var getUpcomingIcons = function getUpcomingIcons(iconPackage) {
|
|
30
|
-
var key = getIconKey(iconPackage);
|
|
31
|
-
if (upcomingIcons.includes(key)) {
|
|
32
|
-
var retval = {
|
|
33
|
-
sizeGuidance: {
|
|
34
|
-
small: 'swap',
|
|
35
|
-
medium: 'swap',
|
|
36
|
-
large: 'icon-tile',
|
|
37
|
-
xlarge: 'icon-tile'
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
return retval;
|
|
41
|
-
}
|
|
42
|
-
return null;
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Returns the key of a legacy icon
|
|
47
|
-
* @param iconPackage The name of the legacy icon package
|
|
48
|
-
* @returns The unique identifier for the icon (the part after "@atlaskit/icon/glyph")
|
|
49
|
-
*/
|
|
50
|
-
var getIconKey = function getIconKey(iconPackage) {
|
|
51
|
-
var key = iconPackage.replace(/^@atlaskit\/icon\/glyph\//, '');
|
|
52
|
-
return key;
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Checks if a new icon can be auto-migrated based on guidance from the migration map
|
|
57
|
-
*/
|
|
58
|
-
export var canAutoMigrateNewIconBasedOnSize = function canAutoMigrateNewIconBasedOnSize(guidance) {
|
|
59
|
-
return guidance ? ['swap', 'swap-slight-visual-change', 'swap-visual-change'].includes(guidance) : false;
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
*
|
|
64
|
-
* @param iconPackage string
|
|
65
|
-
* @returns object of new icon name and import path
|
|
66
|
-
*/
|
|
67
|
-
var getNewIconNameAndImportPath = function getNewIconNameAndImportPath(iconPackage, shouldUseMigrationPath) {
|
|
68
|
-
var legacyIconName = getIconKey(iconPackage);
|
|
69
|
-
var migrationMapObject = getMigrationMapObject(iconPackage);
|
|
70
|
-
if (!migrationMapObject || !migrationMapObject.newIcon) {
|
|
71
|
-
return {};
|
|
72
|
-
}
|
|
73
|
-
var newIcon = migrationMapObject.newIcon;
|
|
74
|
-
var migrationPath = newIcon.name === legacyIconName ? "".concat(newIcon.package, "/core/migration/").concat(newIcon.name) : "".concat(newIcon.package, "/core/migration/").concat(newIcon.name, "--").concat(legacyIconName.replaceAll('/', '-'));
|
|
75
|
-
return {
|
|
76
|
-
iconName: newIcon.name,
|
|
77
|
-
importPath: shouldUseMigrationPath ? migrationPath : "".concat(newIcon.package, "/core/").concat(newIcon.name)
|
|
78
|
-
};
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Creates the written guidance for migrating a legacy icon to a new icon
|
|
83
|
-
*/
|
|
84
|
-
export var createGuidance = function createGuidance(_ref) {
|
|
85
|
-
var iconPackage = _ref.iconPackage,
|
|
86
|
-
insideNewButton = _ref.insideNewButton,
|
|
87
|
-
initialSize = _ref.size,
|
|
88
|
-
shouldUseMigrationPath = _ref.shouldUseMigrationPath,
|
|
89
|
-
shouldForceSmallIcon = _ref.shouldForceSmallIcon;
|
|
90
|
-
var size = shouldForceSmallIcon ? 'small' : initialSize;
|
|
91
|
-
var migrationMapObject = getMigrationMapObject(iconPackage);
|
|
92
|
-
var upcomingIcon = getUpcomingIcons(iconPackage);
|
|
93
|
-
if (upcomingIcon) {
|
|
94
|
-
var guidance = '';
|
|
95
|
-
if (size) {
|
|
96
|
-
if (upcomingIcon.sizeGuidance[size] && canAutoMigrateNewIconBasedOnSize(upcomingIcon.sizeGuidance[size])) {
|
|
97
|
-
guidance += "Fix: An upcoming icon release is planned to migrate this legacy icon.";
|
|
98
|
-
} else {
|
|
99
|
-
guidance += "No equivalent icon for this size, ".concat(size, ", in the current or upcoming set of icons.");
|
|
100
|
-
}
|
|
101
|
-
guidance += "".concat(Object.keys(migrationOutcomeDescriptionMap).includes(upcomingIcon.sizeGuidance[size]) ? " Once the upcoming icons are released, please: ".concat(migrationOutcomeDescriptionMap[upcomingIcon.sizeGuidance[size]]) : ' No migration size advice given.', "\n");
|
|
102
|
-
} else {
|
|
103
|
-
guidance = "Please wait for the upcoming icons released, as it will contain an alternative for this legacy icon.\nMigration suggestions, depending on the legacy icon size:\n";
|
|
104
|
-
for (var _i = 0, _Object$entries = Object.entries(upcomingIcon.sizeGuidance); _i < _Object$entries.length; _i++) {
|
|
105
|
-
var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
|
|
106
|
-
_size = _Object$entries$_i[0],
|
|
107
|
-
value = _Object$entries$_i[1];
|
|
108
|
-
guidance += "\t- ".concat(_size, ": ");
|
|
109
|
-
if (!Object.keys(migrationOutcomeDescriptionMap).includes(value)) {
|
|
110
|
-
guidance += 'No migration advice given.\n';
|
|
111
|
-
} else {
|
|
112
|
-
guidance += "".concat(migrationOutcomeDescriptionMap[value], ".\n");
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
return guidance;
|
|
117
|
-
} else if (migrationMapObject) {
|
|
118
|
-
var newIcon = migrationMapObject.newIcon;
|
|
119
|
-
if (!newIcon) {
|
|
120
|
-
return 'No equivalent icon in new set. An option is to contribute a custom icon into icon-labs package instead.\n';
|
|
121
|
-
}
|
|
122
|
-
var _getNewIconNameAndImp = getNewIconNameAndImportPath(iconPackage, shouldUseMigrationPath),
|
|
123
|
-
iconName = _getNewIconNameAndImp.iconName,
|
|
124
|
-
importPath = _getNewIconNameAndImp.importPath;
|
|
125
|
-
var buttonGuidanceStr = "Please set 'spacing' property of the new icon to 'none', to ensure appropriate spacing inside `@atlaskit/button`.\n";
|
|
126
|
-
var _guidance = '';
|
|
127
|
-
if (size) {
|
|
128
|
-
if (migrationMapObject.sizeGuidance[size] && canAutoMigrateNewIconBasedOnSize(migrationMapObject.sizeGuidance[size])) {
|
|
129
|
-
_guidance += "Fix: Use ".concat(iconName, " from ").concat(importPath, " instead.");
|
|
130
|
-
} else {
|
|
131
|
-
_guidance += "No equivalent icon for this size, ".concat(size, ", in new set.");
|
|
132
|
-
}
|
|
133
|
-
_guidance += "".concat(Object.keys(migrationOutcomeDescriptionMap).includes(migrationMapObject.sizeGuidance[size]) ? " Please: ".concat(migrationOutcomeDescriptionMap[migrationMapObject.sizeGuidance[size]]) : ' No migration size advice given.', "\n");
|
|
134
|
-
} else {
|
|
135
|
-
_guidance = "Use ".concat(iconName, " from ").concat(importPath, " instead.\nMigration suggestions, depending on the legacy icon size:\n");
|
|
136
|
-
Object.entries(migrationMapObject.sizeGuidance).forEach(function (_ref2) {
|
|
137
|
-
var _ref3 = _slicedToArray(_ref2, 2),
|
|
138
|
-
size = _ref3[0],
|
|
139
|
-
value = _ref3[1];
|
|
140
|
-
_guidance += "\t- ".concat(size, ": ");
|
|
141
|
-
if (!Object.keys(migrationOutcomeDescriptionMap).includes(value)) {
|
|
142
|
-
_guidance += 'No migration advice given.\n';
|
|
143
|
-
} else {
|
|
144
|
-
_guidance += "".concat(migrationOutcomeDescriptionMap[value], ".\n");
|
|
145
|
-
}
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
if (insideNewButton) {
|
|
149
|
-
_guidance += buttonGuidanceStr;
|
|
150
|
-
} else if (size === 'medium') {
|
|
151
|
-
_guidance += "Setting the spacing='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";
|
|
152
|
-
} else if (size === 'small') {
|
|
153
|
-
if (initialSize !== 'small' && shouldForceSmallIcon) {
|
|
154
|
-
_guidance += "For this icon, it's recommended to use a smaller size using size='small'. Alternatively, for special cases where a larger version is needed size='medium' can be used, but it is generally discouraged for this icon.\n";
|
|
155
|
-
} else if (initialSize === 'small') {
|
|
156
|
-
if (shouldForceSmallIcon) {
|
|
157
|
-
_guidance += "Setting spacing='compact' will maintain the icon's box dimensions - but consider setting spacing='none' as it allows for easier control of spacing by parent elements.\n";
|
|
158
|
-
} else {
|
|
159
|
-
_guidance += "It's recommended to upscale to a medium icon with no spacing. Alternatively for special cases where smaller icons are required, the original icon size and dimensions can be maintained by using size='small' and spacing='compact'.\n";
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
} else if (size) {
|
|
163
|
-
_guidance += "In the new icon, please use spacing='none'.\n";
|
|
164
|
-
}
|
|
165
|
-
return _guidance;
|
|
166
|
-
} else {
|
|
167
|
-
return "Migration suggestions not found for \"".concat(iconPackage, "\".\n");
|
|
168
|
-
}
|
|
169
|
-
};
|
|
170
|
-
|
|
171
|
-
/**
|
|
172
|
-
* Checks if the color can be migrated
|
|
173
|
-
* @param color String representing the color to check
|
|
174
|
-
* @returns True if the color can be migrated, false otherwise
|
|
175
|
-
*/
|
|
176
|
-
export var canMigrateColor = function canMigrateColor(color) {
|
|
177
|
-
if (color.match(/^color\.icon/)) {
|
|
178
|
-
return true;
|
|
179
|
-
} else if (color.match(/^color\.link/)) {
|
|
180
|
-
return true;
|
|
181
|
-
} else if (color.match(/^color\.text/)) {
|
|
182
|
-
return true;
|
|
183
|
-
} else if (color === 'currentColor') {
|
|
184
|
-
return true;
|
|
185
|
-
} else {
|
|
186
|
-
return false;
|
|
187
|
-
}
|
|
188
|
-
};
|
|
189
|
-
export var locToString = function locToString(node) {
|
|
190
|
-
if (node.range && node.range.length >= 2) {
|
|
191
|
-
return "".concat(node.range[0], ":").concat(node.range[1]);
|
|
192
|
-
} else {
|
|
193
|
-
return '';
|
|
194
|
-
}
|
|
195
|
-
};
|
|
196
|
-
export var createCantMigrateReExportError = function createCantMigrateReExportError(node, packageName, exportName, errors) {
|
|
197
|
-
var myError = {
|
|
198
|
-
node: node,
|
|
199
|
-
messageId: 'cantMigrateReExport',
|
|
200
|
-
data: {
|
|
201
|
-
packageName: packageName,
|
|
202
|
-
exportName: exportName
|
|
203
|
-
}
|
|
204
|
-
};
|
|
205
|
-
pushManualError(locToString(node), errors, myError, packageName, exportName);
|
|
206
|
-
};
|
|
207
|
-
export var createCantMigrateIdentifierMapOrArrayError = function createCantMigrateIdentifierMapOrArrayError(node, packageName, exportName, errors) {
|
|
208
|
-
var myError = {
|
|
209
|
-
node: node,
|
|
210
|
-
messageId: 'cantMigrateIdentifierMapOrArray',
|
|
211
|
-
data: {
|
|
212
|
-
packageName: packageName,
|
|
213
|
-
exportName: exportName
|
|
214
|
-
}
|
|
215
|
-
};
|
|
216
|
-
pushManualError(locToString(node), errors, myError, packageName, exportName);
|
|
217
|
-
};
|
|
218
|
-
export var createCantMigrateIdentifierError = function createCantMigrateIdentifierError(node, packageName, exportName, errors) {
|
|
219
|
-
var myError = {
|
|
220
|
-
node: node,
|
|
221
|
-
messageId: 'cantMigrateIdentifier',
|
|
222
|
-
data: {
|
|
223
|
-
iconSource: packageName,
|
|
224
|
-
iconName: exportName
|
|
225
|
-
}
|
|
226
|
-
};
|
|
227
|
-
pushManualError(locToString(node), errors, myError, packageName, exportName);
|
|
228
|
-
};
|
|
229
|
-
export var createCantFindSuitableReplacementError = function createCantFindSuitableReplacementError(node, importSource, iconName, errors, sizeIssue) {
|
|
230
|
-
var myError = {
|
|
231
|
-
node: node,
|
|
232
|
-
messageId: 'cantFindSuitableReplacement',
|
|
233
|
-
data: {
|
|
234
|
-
importSource: importSource,
|
|
235
|
-
iconName: iconName,
|
|
236
|
-
sizeGuidance: sizeIssue ? ' at the current size' : ''
|
|
237
|
-
}
|
|
238
|
-
};
|
|
239
|
-
pushManualError(locToString(node), errors, myError, importSource, iconName);
|
|
240
|
-
};
|
|
241
|
-
export var createCantMigrateFunctionUnknownError = function createCantMigrateFunctionUnknownError(node, importSource, iconName, errors) {
|
|
242
|
-
var myError = {
|
|
243
|
-
node: node,
|
|
244
|
-
messageId: 'cantMigrateFunctionUnknown',
|
|
245
|
-
data: {
|
|
246
|
-
importSource: importSource,
|
|
247
|
-
iconName: iconName
|
|
248
|
-
}
|
|
249
|
-
};
|
|
250
|
-
pushManualError(locToString(node), errors, myError, importSource, iconName);
|
|
251
|
-
};
|
|
252
|
-
export var createCantMigrateColorError = function createCantMigrateColorError(node, colorValue, errors, importSource, iconName) {
|
|
253
|
-
var myError = {
|
|
254
|
-
node: node,
|
|
255
|
-
messageId: 'cantMigrateColor',
|
|
256
|
-
data: {
|
|
257
|
-
colorValue: colorValue
|
|
258
|
-
}
|
|
259
|
-
};
|
|
260
|
-
pushManualError(locToString(node), errors, myError, importSource, iconName);
|
|
261
|
-
};
|
|
262
|
-
export var createCantMigrateSpreadPropsError = function createCantMigrateSpreadPropsError(node, missingProps, errors, importSource, iconName) {
|
|
263
|
-
var myError = {
|
|
264
|
-
node: node,
|
|
265
|
-
messageId: 'cantMigrateSpreadProps',
|
|
266
|
-
data: {
|
|
267
|
-
missingProps: missingProps.join(', ')
|
|
268
|
-
}
|
|
269
|
-
};
|
|
270
|
-
pushManualError(locToString(node), errors, myError, importSource, iconName);
|
|
271
|
-
};
|
|
272
|
-
export var createCantMigrateSizeUnknown = function createCantMigrateSizeUnknown(node, errors, importSource, iconName) {
|
|
273
|
-
var myError = {
|
|
274
|
-
node: node,
|
|
275
|
-
messageId: 'cantMigrateSizeUnknown'
|
|
276
|
-
};
|
|
277
|
-
pushManualError(locToString(node), errors, myError, importSource, iconName);
|
|
278
|
-
};
|
|
279
|
-
export var createAutoMigrationError = function createAutoMigrationError(_ref4) {
|
|
280
|
-
var node = _ref4.node,
|
|
281
|
-
importSource = _ref4.importSource,
|
|
282
|
-
iconName = _ref4.iconName,
|
|
283
|
-
errors = _ref4.errors,
|
|
284
|
-
spacing = _ref4.spacing,
|
|
285
|
-
insideNewButton = _ref4.insideNewButton,
|
|
286
|
-
shouldForceSmallIcon = _ref4.shouldForceSmallIcon;
|
|
287
|
-
var myError = {
|
|
288
|
-
node: node,
|
|
289
|
-
messageId: 'noLegacyIconsAutoMigration',
|
|
290
|
-
data: {
|
|
291
|
-
importSource: importSource,
|
|
292
|
-
iconName: iconName,
|
|
293
|
-
spacing: spacing !== null && spacing !== void 0 ? spacing : '',
|
|
294
|
-
// value type need to be a string in Rule.ReportDescriptor
|
|
295
|
-
insideNewButton: String(insideNewButton),
|
|
296
|
-
shouldForceSmallIcon: String(shouldForceSmallIcon)
|
|
297
|
-
}
|
|
298
|
-
};
|
|
299
|
-
errors[locToString(node)] = myError;
|
|
300
|
-
};
|
|
301
|
-
var pushManualError = function pushManualError(key, errors, myError, importSource, iconName) {
|
|
302
|
-
if (Object.keys(errors).includes(key)) {
|
|
303
|
-
errors[key].errors.push(myError);
|
|
304
|
-
} else {
|
|
305
|
-
errors[key] = {
|
|
306
|
-
errors: [myError],
|
|
307
|
-
importSource: importSource,
|
|
308
|
-
iconName: iconName
|
|
309
|
-
};
|
|
310
|
-
}
|
|
311
|
-
};
|
|
312
|
-
var getLiteralStringValue = function getLiteralStringValue(value) {
|
|
313
|
-
if (!value) {
|
|
314
|
-
return;
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
// propName="value"
|
|
318
|
-
if (isNodeOfType(value, 'Literal') && typeof value.value === 'string') {
|
|
319
|
-
return value.value;
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
// propName={"value"}
|
|
323
|
-
if (isNodeOfType(value, 'JSXExpressionContainer') && isNodeOfType(value.expression, 'Literal') && typeof value.expression.value === 'string') {
|
|
324
|
-
return value.expression.value;
|
|
325
|
-
}
|
|
326
|
-
return;
|
|
327
|
-
};
|
|
328
|
-
export var createHelpers = function createHelpers(ctx) {
|
|
329
|
-
// TODO: JFP-2823 - this type cast was added due to Jira's ESLint v9 migration
|
|
330
|
-
var context = ctx;
|
|
331
|
-
/**
|
|
332
|
-
* Extracts the token name of a token() call from a JSXExpressionContainer
|
|
333
|
-
* @param value The JSXExpressionContainer to extract the token call from
|
|
334
|
-
* @returns The value of the token call, or null if it could not be extracted
|
|
335
|
-
*/
|
|
336
|
-
var getTokenCallValue = function getTokenCallValue(value) {
|
|
337
|
-
/**
|
|
338
|
-
* Previously, we used getImportName() to extract the token name from a token() call.
|
|
339
|
-
* However, this was failing in the Issue Automat so we are now using a simpler approach.
|
|
340
|
-
*/
|
|
341
|
-
|
|
342
|
-
if (isNodeOfType(value, 'JSXExpressionContainer') && isNodeOfType(value.expression, 'CallExpression') && 'name' in value.expression.callee && value.expression.callee.name === 'token') {
|
|
343
|
-
// propName={token("color...."}
|
|
344
|
-
return getLiteralStringValue(value.expression.arguments[0]);
|
|
345
|
-
}
|
|
346
|
-
return;
|
|
347
|
-
};
|
|
348
|
-
|
|
349
|
-
/**
|
|
350
|
-
* Gets the value of a boolean configuration flag
|
|
351
|
-
* @param key the key of the configuration flag
|
|
352
|
-
* @param defaultValue The default value of the configuration flag
|
|
353
|
-
* @returns defaultValue if the configuration flag is not set, the defaultValue of the configuration flag otherwise
|
|
354
|
-
*/
|
|
355
|
-
var getConfigFlag = function getConfigFlag(key, defaultValue) {
|
|
356
|
-
if (context.options.length > 0 && context.options[0] && Object.keys(context.options[0]).includes(key)) {
|
|
357
|
-
return context.options[0][key] === !defaultValue ? !defaultValue : defaultValue;
|
|
358
|
-
}
|
|
359
|
-
return defaultValue;
|
|
360
|
-
};
|
|
361
|
-
return {
|
|
362
|
-
/**
|
|
363
|
-
* Extracts the primaryColor value from a JSXAttribute
|
|
364
|
-
*/
|
|
365
|
-
getPrimaryColor: function getPrimaryColor(attr) {
|
|
366
|
-
var _ref5, _getLiteralStringValu;
|
|
367
|
-
var value = attr.value;
|
|
368
|
-
return (_ref5 = (_getLiteralStringValu = getLiteralStringValue(value)) !== null && _getLiteralStringValu !== void 0 ? _getLiteralStringValu : getTokenCallValue(value)) !== null && _ref5 !== void 0 ? _ref5 : null;
|
|
369
|
-
},
|
|
370
|
-
getTokenCallValue: getTokenCallValue,
|
|
371
|
-
getConfigFlag: getConfigFlag
|
|
372
|
-
};
|
|
373
|
-
};
|
|
374
|
-
export var addToListOfRanges = function addToListOfRanges(node, sortedListOfRangesForErrors) {
|
|
375
|
-
if (node.range && node.range.length >= 2) {
|
|
376
|
-
sortedListOfRangesForErrors.push({
|
|
377
|
-
start: node.range[0],
|
|
378
|
-
end: node.range[1]
|
|
379
|
-
});
|
|
380
|
-
}
|
|
381
|
-
};
|
|
382
|
-
var isInRangeList = function isInRangeList(node, sortedListOfRangesForErrors) {
|
|
383
|
-
var range = node.range;
|
|
384
|
-
if (!range || range.length < 2) {
|
|
385
|
-
return false;
|
|
386
|
-
}
|
|
387
|
-
var found = sortedListOfRangesForErrors.find(function (currRange) {
|
|
388
|
-
return range[0] >= currRange.start && range[1] <= currRange.end;
|
|
389
|
-
});
|
|
390
|
-
return !!found;
|
|
391
|
-
};
|
|
392
|
-
|
|
393
|
-
/**
|
|
394
|
-
*
|
|
395
|
-
* @param node Icon JSXelement
|
|
396
|
-
* @param newButtonImports list of new button import specifiers
|
|
397
|
-
* @returns if Icon is inside a new button
|
|
398
|
-
*/
|
|
399
|
-
export var isInsideNewButton = function isInsideNewButton(node, newButtonImports) {
|
|
400
|
-
var _node$parent, _node$parent2;
|
|
401
|
-
var insideNewButton = false;
|
|
402
|
-
if (node.parent && isNodeOfType(node.parent, 'ArrowFunctionExpression') && (_node$parent = node.parent) !== null && _node$parent !== void 0 && (_node$parent = _node$parent.parent) !== null && _node$parent !== void 0 && _node$parent.parent && isNodeOfType(node.parent.parent.parent, 'JSXAttribute') && isNodeOfType(node.parent.parent.parent.name, 'JSXIdentifier') && (_node$parent2 = node.parent) !== null && _node$parent2 !== void 0 && (_node$parent2 = _node$parent2.parent) !== null && _node$parent2 !== void 0 && (_node$parent2 = _node$parent2.parent) !== null && _node$parent2 !== void 0 && _node$parent2.parent && isNodeOfType(node.parent.parent.parent.parent, 'JSXOpeningElement') && isNodeOfType(node.parent.parent.parent.parent.name, 'JSXIdentifier') && newButtonImports.has(node.parent.parent.parent.parent.name.name)) {
|
|
403
|
-
insideNewButton = true;
|
|
404
|
-
}
|
|
405
|
-
return insideNewButton;
|
|
406
|
-
};
|
|
407
|
-
|
|
408
|
-
/**
|
|
409
|
-
*
|
|
410
|
-
* @param node Icon JSXelement
|
|
411
|
-
* @param newButtonImports list of legacy button import specifiers
|
|
412
|
-
* @returns if Icon is inside a legacy button
|
|
413
|
-
*/
|
|
414
|
-
export var isInsideLegacyButton = function isInsideLegacyButton(node, legacyButtonImports) {
|
|
415
|
-
var _node$parent3, _node$parent4, _node$parent5, _node$parent6;
|
|
416
|
-
return node.parent && isNodeOfType(node.parent, 'JSXExpressionContainer') && ((_node$parent3 = node.parent) === null || _node$parent3 === void 0 ? void 0 : _node$parent3.parent) && isNodeOfType(node.parent.parent, 'JSXAttribute') && (node.parent.parent.name.name === 'iconBefore' || node.parent.parent.name.name === 'iconAfter') && isNodeOfType((_node$parent4 = node.parent) === null || _node$parent4 === void 0 || (_node$parent4 = _node$parent4.parent) === null || _node$parent4 === void 0 ? void 0 : _node$parent4.parent, 'JSXOpeningElement') && isNodeOfType((_node$parent5 = node.parent) === null || _node$parent5 === void 0 || (_node$parent5 = _node$parent5.parent) === null || _node$parent5 === void 0 ? void 0 : _node$parent5.parent.name, 'JSXIdentifier') && legacyButtonImports.has((_node$parent6 = node.parent) === null || _node$parent6 === void 0 || (_node$parent6 = _node$parent6.parent) === null || _node$parent6 === void 0 ? void 0 : _node$parent6.parent.name.name);
|
|
417
|
-
};
|
|
418
|
-
|
|
419
|
-
/**
|
|
420
|
-
*
|
|
421
|
-
* @param node Icon JSXelement
|
|
422
|
-
* @param newButtonImports list of legacy button import specifiers
|
|
423
|
-
* @returns if Icon is inside a legacy button
|
|
424
|
-
*/
|
|
425
|
-
export var isInsideIconOnlyLegacyButton = function isInsideIconOnlyLegacyButton(node, legacyButtonImports) {
|
|
426
|
-
var insideIconOnlyLegacyButton = false;
|
|
427
|
-
if (isInsideLegacyButton(node, legacyButtonImports)) {
|
|
428
|
-
var _node$parent7, _node$parent8, _node$parent9, _node$parent0, _node$parent1, _node$parent10;
|
|
429
|
-
var legacyButtonAttributes = node.parent && isNodeOfType(node.parent, 'JSXExpressionContainer') && (_node$parent7 = node.parent) !== null && _node$parent7 !== void 0 && _node$parent7.parent && isNodeOfType(node.parent.parent, 'JSXAttribute') && node.parent.parent.parent && isNodeOfType((_node$parent8 = node.parent) === null || _node$parent8 === void 0 || (_node$parent8 = _node$parent8.parent) === null || _node$parent8 === void 0 ? void 0 : _node$parent8.parent, 'JSXOpeningElement') ? (_node$parent9 = node.parent) === null || _node$parent9 === void 0 || (_node$parent9 = _node$parent9.parent) === null || _node$parent9 === void 0 ? void 0 : _node$parent9.parent.attributes.map(function (attribute) {
|
|
430
|
-
var _attribute$name;
|
|
431
|
-
return isNodeOfType(attribute, 'JSXAttribute') && isNodeOfType(attribute.name, 'JSXIdentifier') && (attribute === null || attribute === void 0 || (_attribute$name = attribute.name) === null || _attribute$name === void 0 ? void 0 : _attribute$name.name);
|
|
432
|
-
}).filter(Boolean) : [];
|
|
433
|
-
var hasIconBefore = legacyButtonAttributes.includes('iconBefore');
|
|
434
|
-
var hasIconAfter = legacyButtonAttributes.includes('iconAfter');
|
|
435
|
-
var hasChildren = ((_node$parent0 = node.parent) === null || _node$parent0 === void 0 || (_node$parent0 = _node$parent0.parent) === null || _node$parent0 === void 0 || (_node$parent0 = _node$parent0.parent) === null || _node$parent0 === void 0 ? void 0 : _node$parent0.parent) && isNodeOfType((_node$parent1 = node.parent) === null || _node$parent1 === void 0 || (_node$parent1 = _node$parent1.parent) === null || _node$parent1 === void 0 || (_node$parent1 = _node$parent1.parent) === null || _node$parent1 === void 0 ? void 0 : _node$parent1.parent, 'JSXElement') && ((_node$parent10 = node.parent) === null || _node$parent10 === void 0 || (_node$parent10 = _node$parent10.parent) === null || _node$parent10 === void 0 || (_node$parent10 = _node$parent10.parent) === null || _node$parent10 === void 0 ? void 0 : _node$parent10.parent.children.length) > 0;
|
|
436
|
-
if (hasIconBefore && !hasIconAfter && !hasChildren || !hasIconBefore && hasIconAfter && !hasChildren || !hasIconBefore && !hasIconAfter && hasChildren) {
|
|
437
|
-
insideIconOnlyLegacyButton = true;
|
|
438
|
-
}
|
|
439
|
-
}
|
|
440
|
-
return insideIconOnlyLegacyButton;
|
|
441
|
-
};
|
|
442
|
-
var findProp = function findProp(attributes, propName) {
|
|
443
|
-
return attributes.find(function (attr) {
|
|
444
|
-
return attr.type === 'JSXAttribute' && attr.name.name === propName;
|
|
445
|
-
});
|
|
446
|
-
};
|
|
447
|
-
var getNewIconNameForRenaming = function getNewIconNameForRenaming(isInManualArray, importSource, importSpecifier) {
|
|
448
|
-
var newIconName;
|
|
449
|
-
if (isInManualArray) {
|
|
450
|
-
newIconName = getNewIconNameAndImportPath(importSource).iconName;
|
|
451
|
-
var keyToName = newIconName ? getComponentName(newIconName) : undefined;
|
|
452
|
-
newIconName = keyToName;
|
|
453
|
-
if (newIconName === undefined || importSpecifier === keyToName) {
|
|
454
|
-
newIconName = "".concat(keyToName, "New");
|
|
455
|
-
}
|
|
456
|
-
}
|
|
457
|
-
return newIconName;
|
|
458
|
-
};
|
|
459
|
-
export var getComponentName = function getComponentName(name) {
|
|
460
|
-
return name.split(/\W/).map(function (part) {
|
|
461
|
-
return "".concat(part[0].toUpperCase()).concat(part.slice(1));
|
|
462
|
-
}).join('').concat('Icon');
|
|
463
|
-
};
|
|
464
|
-
|
|
465
|
-
/**
|
|
466
|
-
*
|
|
467
|
-
* Creates a list of fixers to update the icon import path
|
|
468
|
-
* @param metadata Metadata including the import source and spacing
|
|
469
|
-
* @param fixer The original fix function
|
|
470
|
-
* @param legacyImportNode The import declaration node to replace
|
|
471
|
-
* @param shouldUseMigrationPath The eslint rule config, whether to use migration entrypoint or not
|
|
472
|
-
* @param migrationImportNode The migration import declaration node to replace, only present if shouldUseMigrationPath is false
|
|
473
|
-
* @returns A list of fixers to migrate the icon
|
|
474
|
-
*/
|
|
475
|
-
var createImportFix = function createImportFix(_ref6) {
|
|
476
|
-
var fixer = _ref6.fixer,
|
|
477
|
-
legacyImportNode = _ref6.legacyImportNode,
|
|
478
|
-
metadata = _ref6.metadata,
|
|
479
|
-
shouldUseMigrationPath = _ref6.shouldUseMigrationPath,
|
|
480
|
-
migrationImportNode = _ref6.migrationImportNode,
|
|
481
|
-
newIconName = _ref6.newIconName;
|
|
482
|
-
var fixes = [];
|
|
483
|
-
var importSource = metadata.importSource;
|
|
484
|
-
var importPath = migrationImportNode ? importSource.replace('/migration', '').split('--')[0] : getNewIconNameAndImportPath(importSource, shouldUseMigrationPath).importPath;
|
|
485
|
-
var useMigrationPath = legacyImportNode && importPath;
|
|
486
|
-
var useFinalPath = migrationImportNode && !shouldUseMigrationPath && importPath;
|
|
487
|
-
var programNode = legacyImportNode && findProgramNode(legacyImportNode);
|
|
488
|
-
if (useMigrationPath) {
|
|
489
|
-
if (newIconName) {
|
|
490
|
-
var isExisting = programNode ? alreadyHasImportedLocalName(programNode, newIconName, importPath) : false;
|
|
491
|
-
if (!isExisting) {
|
|
492
|
-
fixes.push(fixer.insertTextBefore(legacyImportNode, "import ".concat(newIconName, " from '").concat(importPath, "';\n")));
|
|
493
|
-
}
|
|
494
|
-
} else {
|
|
495
|
-
fixes.push(fixer.replaceText(legacyImportNode.source, "'".concat(literal(importPath), "'")));
|
|
496
|
-
}
|
|
497
|
-
} else if (useFinalPath) {
|
|
498
|
-
if (newIconName) {
|
|
499
|
-
var _isExisting = programNode ? alreadyHasImportedLocalName(programNode, newIconName, importPath) : false;
|
|
500
|
-
if (!_isExisting) {
|
|
501
|
-
fixes.push(fixer.insertTextBefore(migrationImportNode, "import ".concat(newIconName, " from '").concat(importPath, "';\n")));
|
|
502
|
-
}
|
|
503
|
-
} else {
|
|
504
|
-
fixes.push(fixer.replaceText(migrationImportNode.source, "'".concat(literal(importPath), "'")));
|
|
505
|
-
}
|
|
506
|
-
}
|
|
507
|
-
return fixes;
|
|
508
|
-
};
|
|
509
|
-
|
|
510
|
-
/**
|
|
511
|
-
* Creates a list of fixers to update the icon props
|
|
512
|
-
* @param node The Icon element to migrate
|
|
513
|
-
* @param metadata Metadata including the import source and spacing
|
|
514
|
-
* @param fixer The original fix function
|
|
515
|
-
* @param legacyImportNode The import declaration node to replace
|
|
516
|
-
* @param shouldUseMigrationPath The eslint rule config, whether to use migration entrypoint or not
|
|
517
|
-
* @param migrationImportNode The migration import declaration node to replace, only present if shouldUseMigrationPath is false
|
|
518
|
-
* @returns A list of fixers to migrate the icon
|
|
519
|
-
*/
|
|
520
|
-
var createPropFixes = function createPropFixes(_ref7) {
|
|
521
|
-
var node = _ref7.node,
|
|
522
|
-
fixer = _ref7.fixer,
|
|
523
|
-
legacyImportNode = _ref7.legacyImportNode,
|
|
524
|
-
metadata = _ref7.metadata,
|
|
525
|
-
shouldUseMigrationPath = _ref7.shouldUseMigrationPath,
|
|
526
|
-
migrationImportNode = _ref7.migrationImportNode,
|
|
527
|
-
newIconName = _ref7.newIconName;
|
|
528
|
-
var fixes = [];
|
|
529
|
-
var spacing = metadata.spacing,
|
|
530
|
-
size = metadata.size,
|
|
531
|
-
importSource = metadata.importSource;
|
|
532
|
-
if (shouldUseMigrationPath && !legacyImportNode) {
|
|
533
|
-
return fixes;
|
|
534
|
-
}
|
|
535
|
-
if (node.type === 'JSXElement') {
|
|
536
|
-
var openingElement = node.openingElement;
|
|
537
|
-
if (newIconName) {
|
|
538
|
-
fixes.push(fixer.replaceText(openingElement.name, newIconName));
|
|
539
|
-
}
|
|
540
|
-
var attributes = openingElement.attributes;
|
|
541
|
-
|
|
542
|
-
// replace primaryColor prop with color
|
|
543
|
-
var primaryColor = findProp(attributes, 'primaryColor');
|
|
544
|
-
if (primaryColor && primaryColor.type === 'JSXAttribute') {
|
|
545
|
-
fixes.push(fixer.replaceText(primaryColor.name, 'color'));
|
|
546
|
-
}
|
|
547
|
-
var sizeProp = findProp(attributes, 'size');
|
|
548
|
-
var spacingProp = findProp(attributes, 'spacing');
|
|
549
|
-
if (sizeProp && sizeProp.type === 'JSXAttribute') {
|
|
550
|
-
if (shouldUseMigrationPath) {
|
|
551
|
-
// Rename existing size prop to LEGACY_size and add new size prop if applicable
|
|
552
|
-
fixes.push(fixer.replaceText(sizeProp.name, 'LEGACY_size'));
|
|
553
|
-
if (size) {
|
|
554
|
-
fixes.push(fixer.insertTextAfter(sizeProp, " size=\"".concat(size, "\"")));
|
|
555
|
-
}
|
|
556
|
-
} else {
|
|
557
|
-
if (size && sizeProp.value) {
|
|
558
|
-
// update size prop with new replacement size
|
|
559
|
-
fixes.push(fixer.replaceText(sizeProp.value, "\"".concat(size, "\"")));
|
|
560
|
-
} else if (importSource.startsWith('@atlaskit/icon/glyph/')) {
|
|
561
|
-
// only remove size prop for glyph entry points if no new replacement size is specified
|
|
562
|
-
fixes.push(fixer.remove(sizeProp));
|
|
563
|
-
} else if (sizeProp.value && sizeProp.value.type === 'Literal' && typeof sizeProp.value.value === 'string' && sizeProp.value.value === 'medium') {
|
|
564
|
-
// if size is medium, we can remove it as it is the default size
|
|
565
|
-
fixes.push(fixer.remove(sizeProp));
|
|
566
|
-
}
|
|
567
|
-
}
|
|
568
|
-
} else if (size) {
|
|
569
|
-
fixes.push(fixer.insertTextAfter(openingElement.name, " size=\"".concat(size, "\"")));
|
|
570
|
-
}
|
|
571
|
-
|
|
572
|
-
// Add spacing prop if no existing spacing prop and icon is not imported from migration entrypoint
|
|
573
|
-
if (spacing && spacing !== 'none' && !spacingProp && !migrationImportNode) {
|
|
574
|
-
fixes.push(fixer.insertTextAfter(sizeProp || openingElement.name, " spacing=\"".concat(spacing, "\"")));
|
|
575
|
-
}
|
|
576
|
-
|
|
577
|
-
// rename or remove secondaryColor prop based on shouldUseMigrationPath
|
|
578
|
-
var secondaryColorProp = findProp(attributes, 'secondaryColor');
|
|
579
|
-
if (secondaryColorProp && secondaryColorProp.type === 'JSXAttribute') {
|
|
580
|
-
fixes.push(shouldUseMigrationPath ?
|
|
581
|
-
// replace secondaryColor prop with LEGACY_secondaryColor
|
|
582
|
-
fixer.replaceText(secondaryColorProp.name, 'LEGACY_secondaryColor') :
|
|
583
|
-
// remove secondaryColor prop if shouldUseMigrationPath is false
|
|
584
|
-
fixer.remove(secondaryColorProp));
|
|
585
|
-
}
|
|
586
|
-
|
|
587
|
-
// remove LEGACY props
|
|
588
|
-
if (!shouldUseMigrationPath) {
|
|
589
|
-
['LEGACY_size', 'LEGACY_margin', 'LEGACY_fallbackIcon', 'LEGACY_secondaryColor'].forEach(function (propName) {
|
|
590
|
-
var legacyProp = findProp(attributes, propName);
|
|
591
|
-
if (legacyProp && legacyProp.type === 'JSXAttribute') {
|
|
592
|
-
fixes.push(fixer.remove(legacyProp));
|
|
593
|
-
}
|
|
594
|
-
});
|
|
595
|
-
}
|
|
596
|
-
} else if (node.type === 'Identifier' && newIconName) {
|
|
597
|
-
fixes.push(fixer.replaceText(node, newIconName));
|
|
598
|
-
}
|
|
599
|
-
return fixes;
|
|
600
|
-
};
|
|
601
|
-
|
|
602
|
-
/**
|
|
603
|
-
* Check if the new icon exists in the migration map
|
|
604
|
-
*/
|
|
605
|
-
var checkIfNewIconExist = function checkIfNewIconExist(error) {
|
|
606
|
-
var _error$data;
|
|
607
|
-
if (!((_error$data = error.data) !== null && _error$data !== void 0 && _error$data.importSource)) {
|
|
608
|
-
return false;
|
|
609
|
-
}
|
|
610
|
-
var iconKey = getIconKey(error.data.importSource);
|
|
611
|
-
var _ref8 = baseMigrationMap[iconKey] || {},
|
|
612
|
-
newIcon = _ref8.newIcon;
|
|
613
|
-
return Boolean(newIcon);
|
|
614
|
-
};
|
|
615
|
-
export var throwManualErrors = function throwManualErrors(_ref9) {
|
|
616
|
-
var errorsManual = _ref9.errorsManual,
|
|
617
|
-
errorRanges = _ref9.errorRanges,
|
|
618
|
-
guidance = _ref9.guidance,
|
|
619
|
-
context = _ref9.context,
|
|
620
|
-
isQuietMode = _ref9.isQuietMode;
|
|
621
|
-
for (var _i2 = 0, _Object$entries2 = Object.entries(errorsManual); _i2 < _Object$entries2.length; _i2++) {
|
|
622
|
-
var _Object$entries2$_i = _slicedToArray(_Object$entries2[_i2], 2),
|
|
623
|
-
_key = _Object$entries2$_i[0],
|
|
624
|
-
errorList = _Object$entries2$_i[1];
|
|
625
|
-
var node = 'node' in errorList.errors[0] ? errorList.errors[0].node : null;
|
|
626
|
-
if (!node) {
|
|
627
|
-
return;
|
|
628
|
-
}
|
|
629
|
-
var cantMigrateIdentifierError = errorList.errors.find(function (x) {
|
|
630
|
-
return 'messageId' in x && x.messageId === 'cantMigrateIdentifier';
|
|
631
|
-
});
|
|
632
|
-
var isInRange = false;
|
|
633
|
-
if (cantMigrateIdentifierError && isInRangeList(node, errorRanges)) {
|
|
634
|
-
isInRange = true;
|
|
635
|
-
}
|
|
636
|
-
if (isInRange && errorList.errors.length - 1 > 0 || !isInRange && errorList.errors.length > 0) {
|
|
637
|
-
var guidanceMessage = Object.keys(guidance).includes(_key) ? guidance[_key] : '';
|
|
638
|
-
context.report({
|
|
639
|
-
node: node,
|
|
640
|
-
messageId: 'noLegacyIconsManualMigration',
|
|
641
|
-
data: {
|
|
642
|
-
iconName: errorList.iconName,
|
|
643
|
-
importSource: errorList.importSource,
|
|
644
|
-
guidance: isQuietMode ? guidanceMessage : "".concat(guidanceMessage, "For more information see the below errors.\n")
|
|
645
|
-
}
|
|
646
|
-
});
|
|
647
|
-
if (!isQuietMode) {
|
|
648
|
-
var _iterator = _createForOfIteratorHelper(errorList.errors),
|
|
649
|
-
_step;
|
|
650
|
-
try {
|
|
651
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
652
|
-
var error = _step.value;
|
|
653
|
-
if ('messageId' in error && (error.messageId !== 'cantMigrateIdentifier' || error.messageId === 'cantMigrateIdentifier' && !isInRange)) {
|
|
654
|
-
context.report(error);
|
|
655
|
-
}
|
|
656
|
-
}
|
|
657
|
-
} catch (err) {
|
|
658
|
-
_iterator.e(err);
|
|
659
|
-
} finally {
|
|
660
|
-
_iterator.f();
|
|
661
|
-
}
|
|
662
|
-
}
|
|
663
|
-
}
|
|
664
|
-
}
|
|
665
|
-
};
|
|
666
|
-
|
|
667
|
-
// Loops through automatic errors and them after adding the required suggestion/fix
|
|
668
|
-
export var throwAutoErrors = function throwAutoErrors(_ref0) {
|
|
669
|
-
var errorsManual = _ref0.errorsManual,
|
|
670
|
-
errorsAuto = _ref0.errorsAuto,
|
|
671
|
-
iconSizesInfo = _ref0.iconSizesInfo,
|
|
672
|
-
legacyIconImports = _ref0.legacyIconImports,
|
|
673
|
-
guidance = _ref0.guidance,
|
|
674
|
-
migrationIconImports = _ref0.migrationIconImports,
|
|
675
|
-
shouldUseMigrationPath = _ref0.shouldUseMigrationPath,
|
|
676
|
-
context = _ref0.context;
|
|
677
|
-
// Set of all the import sources that have manual errors (required later to check if a source has both manual and auto
|
|
678
|
-
// errors in one file making it impossible to just remove the legacy import)
|
|
679
|
-
var allManualErrorSources = Object.entries(errorsManual).reduce(function (result, option) {
|
|
680
|
-
var _option = _slicedToArray(option, 2),
|
|
681
|
-
key = _option[0],
|
|
682
|
-
errorInfo = _option[1];
|
|
683
|
-
if (!errorsAuto.hasOwnProperty(key)) {
|
|
684
|
-
result.add(errorInfo.importSource);
|
|
685
|
-
}
|
|
686
|
-
return result;
|
|
687
|
-
}, new Set());
|
|
688
|
-
// Group errors by import source and remove any unwanted errors
|
|
689
|
-
var groupedErrorList = Object.entries(errorsAuto).reduce(function (result, option) {
|
|
690
|
-
var _option2 = _slicedToArray(option, 2),
|
|
691
|
-
key = _option2[0],
|
|
692
|
-
error = _option2[1];
|
|
693
|
-
// Return early if no data
|
|
694
|
-
if (!error.data) {
|
|
695
|
-
return result;
|
|
696
|
-
}
|
|
697
|
-
if (Object.keys(errorsManual).includes(key)) {
|
|
698
|
-
var cantMigrateIdentifierError = errorsManual[key].errors.find(function (x) {
|
|
699
|
-
return 'messageId' in x && x.messageId === 'cantMigrateIdentifier';
|
|
700
|
-
});
|
|
701
|
-
// If cantMigrateIdentifier is the only manual error found we still want to throw the auto error
|
|
702
|
-
if (!(cantMigrateIdentifierError && errorsManual[key].errors.length === 1)) {
|
|
703
|
-
return result;
|
|
704
|
-
}
|
|
705
|
-
}
|
|
706
|
-
var importSource = error.data.importSource;
|
|
707
|
-
if (!result.hasOwnProperty(importSource)) {
|
|
708
|
-
result[importSource] = [];
|
|
709
|
-
}
|
|
710
|
-
result[importSource].push(_objectSpread({
|
|
711
|
-
key: key
|
|
712
|
-
}, error));
|
|
713
|
-
return result;
|
|
714
|
-
}, {});
|
|
715
|
-
var _loop = function _loop() {
|
|
716
|
-
var _Object$entries3$_i = _slicedToArray(_Object$entries3[_i3], 2),
|
|
717
|
-
importSource = _Object$entries3$_i[0],
|
|
718
|
-
errorList = _Object$entries3$_i[1];
|
|
719
|
-
var autoFixers = [];
|
|
720
|
-
// appliedErrorsForImport will contain all the errors FOR A SINGLE IMPORT and will be merged into errorListForReport
|
|
721
|
-
var appliedErrorsForImport = [];
|
|
722
|
-
// Loop over auto errors for a single import source
|
|
723
|
-
var _iterator2 = _createForOfIteratorHelper(errorList.entries()),
|
|
724
|
-
_step2;
|
|
725
|
-
try {
|
|
726
|
-
var _loop2 = function _loop2() {
|
|
727
|
-
var _iconSizesInfo$import, _iconSizesInfo$import2, _iconSizesInfo$import3, _legacyIconImports$er, _error$data2, _legacyIconImports$er2, _migrationIconImports;
|
|
728
|
-
var _step2$value = _slicedToArray(_step2.value, 2),
|
|
729
|
-
_ = _step2$value[0],
|
|
730
|
-
error = _step2$value[1];
|
|
731
|
-
var key = error.key;
|
|
732
|
-
var node = 'node' in error ? error.node : null;
|
|
733
|
-
// Check if there is a manual error for the same import source somewhere else in the same file
|
|
734
|
-
// If that is the case we'll need to provide a suggestion instead of auto-fixing as the suggestion will
|
|
735
|
-
// add another import without removing the old import and this needs to be validated
|
|
736
|
-
var isInManualArray = allManualErrorSources.has(importSource);
|
|
737
|
-
|
|
738
|
-
// Check if the icon has size of small, if so it cannot be automatically migrated. Two suggestions will be provided
|
|
739
|
-
// 1. Use core icon with no spacing
|
|
740
|
-
// 2. Use utility icon with compact spacing
|
|
741
|
-
var isSizeSmall = (_iconSizesInfo$import = iconSizesInfo[importSource]) === null || _iconSizesInfo$import === void 0 ? void 0 : _iconSizesInfo$import.small.includes(key);
|
|
742
|
-
var isMixedSizeUsage = ((_iconSizesInfo$import2 = iconSizesInfo[importSource]) === null || _iconSizesInfo$import2 === void 0 ? void 0 : _iconSizesInfo$import2.small.length) > 0 && ((_iconSizesInfo$import3 = iconSizesInfo[importSource]) === null || _iconSizesInfo$import3 === void 0 ? void 0 : _iconSizesInfo$import3.small.length) < iconSizesInfo[importSource].usageCount;
|
|
743
|
-
|
|
744
|
-
// Icon should be renamed
|
|
745
|
-
// 1. If the icon is in the manual array OR
|
|
746
|
-
// 2. If there is mixed size usages of this icon with size small
|
|
747
|
-
var shouldRenameIcon = isInManualArray || isMixedSizeUsage;
|
|
748
|
-
|
|
749
|
-
// New icon name for renaming if the icon is in the manual array
|
|
750
|
-
var newIconName = getNewIconNameForRenaming(shouldRenameIcon, importSource, errorList[0].data ? (_legacyIconImports$er = legacyIconImports[errorList[0].data.iconName]) === null || _legacyIconImports$er === void 0 ? void 0 : _legacyIconImports$er.importSpecifier : undefined);
|
|
751
|
-
if (!node) {
|
|
752
|
-
return 0; // continue
|
|
753
|
-
}
|
|
754
|
-
var guidanceMessage = guidance.hasOwnProperty(key) ? guidance[key] : '';
|
|
755
|
-
if (Object.keys(error).includes('data') && error.data) {
|
|
756
|
-
error.data.guidance = guidanceMessage;
|
|
757
|
-
}
|
|
758
|
-
var shouldForceSmallIcon = ((_error$data2 = error.data) === null || _error$data2 === void 0 ? void 0 : _error$data2.shouldForceSmallIcon) === 'true';
|
|
759
|
-
var fixArguments = error.data ? {
|
|
760
|
-
metadata: _objectSpread(_objectSpread({}, error.data), {}, {
|
|
761
|
-
spacing: error.data.isInNewButton ? 'none' : error.data.spacing,
|
|
762
|
-
size: shouldForceSmallIcon ? 'small' : error.data.size
|
|
763
|
-
}),
|
|
764
|
-
legacyImportNode: (_legacyIconImports$er2 = legacyIconImports[error.data.iconName]) === null || _legacyIconImports$er2 === void 0 ? void 0 : _legacyIconImports$er2.importNode,
|
|
765
|
-
migrationImportNode: (_migrationIconImports = migrationIconImports[error.data.iconName]) === null || _migrationIconImports === void 0 ? void 0 : _migrationIconImports.importNode,
|
|
766
|
-
shouldUseMigrationPath: shouldUseMigrationPath,
|
|
767
|
-
newIconName: shouldRenameIcon ? newIconName : undefined
|
|
768
|
-
} : null;
|
|
769
|
-
if (!error.data || shouldUseMigrationPath && !checkIfNewIconExist(error) || !fixArguments) {
|
|
770
|
-
return 0; // continue
|
|
771
|
-
}
|
|
772
|
-
var isInNewButton = fixArguments.metadata.insideNewButton === 'true';
|
|
773
|
-
if (isSizeSmall && !shouldForceSmallIcon) {
|
|
774
|
-
error.suggest = [{
|
|
775
|
-
desc: isInNewButton ? 'Replace with medium core icon (Recommended)' : 'Replace with medium core icon and no spacing (Recommended)',
|
|
776
|
-
fix: function fix(fixer) {
|
|
777
|
-
return [].concat(_toConsumableArray(createPropFixes(_objectSpread(_objectSpread({}, fixArguments), {}, {
|
|
778
|
-
metadata: _objectSpread(_objectSpread({}, fixArguments.metadata), {}, {
|
|
779
|
-
spacing: 'none'
|
|
780
|
-
}),
|
|
781
|
-
node: node,
|
|
782
|
-
fixer: fixer
|
|
783
|
-
}))), _toConsumableArray(createImportFix(_objectSpread(_objectSpread({}, fixArguments), {}, {
|
|
784
|
-
fixer: fixer
|
|
785
|
-
}))));
|
|
786
|
-
}
|
|
787
|
-
}, {
|
|
788
|
-
desc: isInNewButton ? 'Replace with small core icon' : 'Replace with small core icon and compact spacing',
|
|
789
|
-
fix: function fix(fixer) {
|
|
790
|
-
return [].concat(_toConsumableArray(createPropFixes(_objectSpread(_objectSpread({}, fixArguments), {}, {
|
|
791
|
-
metadata: _objectSpread(_objectSpread({}, fixArguments.metadata), {}, {
|
|
792
|
-
spacing: 'compact',
|
|
793
|
-
size: 'small'
|
|
794
|
-
}),
|
|
795
|
-
node: node,
|
|
796
|
-
fixer: fixer
|
|
797
|
-
}))), _toConsumableArray(createImportFix(_objectSpread(_objectSpread({}, fixArguments), {}, {
|
|
798
|
-
fixer: fixer
|
|
799
|
-
}))));
|
|
800
|
-
}
|
|
801
|
-
}];
|
|
802
|
-
} else {
|
|
803
|
-
if (isInManualArray) {
|
|
804
|
-
// provide suggestion if there is a manual error for the same import source and thus the legacy import can't be removed
|
|
805
|
-
error.suggest = [{
|
|
806
|
-
desc: 'Rename icon import, import from the new package, and update props.',
|
|
807
|
-
fix: function fix(fixer) {
|
|
808
|
-
return [].concat(_toConsumableArray(createPropFixes(_objectSpread(_objectSpread({}, fixArguments), {}, {
|
|
809
|
-
node: node,
|
|
810
|
-
fixer: fixer
|
|
811
|
-
}))), _toConsumableArray(createImportFix(_objectSpread(_objectSpread({}, fixArguments), {}, {
|
|
812
|
-
fixer: fixer
|
|
813
|
-
}))));
|
|
814
|
-
}
|
|
815
|
-
}];
|
|
816
|
-
} else {
|
|
817
|
-
// Update Guidance message for auto-fixing
|
|
818
|
-
if (error.data) {
|
|
819
|
-
error.data.guidance = error.data.guidance + "\nTo automatically fix this icon, run the auto-fixer attached to the first use of ".concat(importSource, " in this file - either manually, or by saving this file.");
|
|
820
|
-
}
|
|
821
|
-
// There should only be 1 import fix for each import source and thus only add this at the start of the list
|
|
822
|
-
if (autoFixers.length === 0) {
|
|
823
|
-
autoFixers.push(function (fixer) {
|
|
824
|
-
return createImportFix(_objectSpread(_objectSpread({}, fixArguments), {}, {
|
|
825
|
-
fixer: fixer
|
|
826
|
-
}));
|
|
827
|
-
});
|
|
828
|
-
}
|
|
829
|
-
// Push the prop fix regardless
|
|
830
|
-
autoFixers.push(function (fixer) {
|
|
831
|
-
return createPropFixes(_objectSpread(_objectSpread({}, fixArguments), {}, {
|
|
832
|
-
node: node,
|
|
833
|
-
fixer: fixer
|
|
834
|
-
}));
|
|
835
|
-
});
|
|
836
|
-
}
|
|
837
|
-
}
|
|
838
|
-
// Add the error to the appliedErrorsForImport, ready to be thrown later
|
|
839
|
-
appliedErrorsForImport.push(error);
|
|
840
|
-
},
|
|
841
|
-
_ret;
|
|
842
|
-
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
843
|
-
_ret = _loop2();
|
|
844
|
-
if (_ret === 0) continue;
|
|
845
|
-
}
|
|
846
|
-
// We want to have only 1 fix for each import source that is not in the manual array
|
|
847
|
-
// NOTE: If in the manual array, suggestions have been applied above and autoFixers.length will be 0 which will mean no fix is added
|
|
848
|
-
} catch (err) {
|
|
849
|
-
_iterator2.e(err);
|
|
850
|
-
} finally {
|
|
851
|
-
_iterator2.f();
|
|
852
|
-
}
|
|
853
|
-
if (autoFixers.length > 0) {
|
|
854
|
-
// Add the fix to only one of the errors in the list of errors from the current import source
|
|
855
|
-
appliedErrorsForImport[0].fix = function (fixer) {
|
|
856
|
-
return autoFixers.flatMap(function (autoFixer) {
|
|
857
|
-
return autoFixer(fixer);
|
|
858
|
-
});
|
|
859
|
-
};
|
|
860
|
-
}
|
|
861
|
-
// throw errors
|
|
862
|
-
appliedErrorsForImport.forEach(function (error) {
|
|
863
|
-
context.report(error);
|
|
864
|
-
});
|
|
865
|
-
};
|
|
866
|
-
for (var _i3 = 0, _Object$entries3 = Object.entries(groupedErrorList); _i3 < _Object$entries3.length; _i3++) {
|
|
867
|
-
_loop();
|
|
868
|
-
}
|
|
869
|
-
};
|
|
870
|
-
function findProgramNode(node) {
|
|
871
|
-
while (node && node.parent) {
|
|
872
|
-
if (node.parent.type === 'Program') {
|
|
873
|
-
return node.parent;
|
|
874
|
-
}
|
|
875
|
-
node = node.parent;
|
|
876
|
-
}
|
|
877
|
-
return null;
|
|
878
|
-
}
|
|
879
|
-
function alreadyHasImportedLocalName(programNode, localName, importPath) {
|
|
880
|
-
if (!(programNode !== null && programNode !== void 0 && programNode.body)) {
|
|
881
|
-
return false;
|
|
882
|
-
}
|
|
883
|
-
return programNode.body.some(function (stmt) {
|
|
884
|
-
if (stmt.type === 'ImportDeclaration' && stmt.source.value === importPath) {
|
|
885
|
-
return stmt.specifiers.some(function (s) {
|
|
886
|
-
return s.local.name === localName;
|
|
887
|
-
});
|
|
888
|
-
}
|
|
889
|
-
return false;
|
|
890
|
-
});
|
|
891
|
-
}
|