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