@atlaskit/eslint-plugin-design-system 4.8.1 → 4.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -0
- package/dist/cjs/rules/ensure-design-token-usage/index.js +45 -17
- package/dist/cjs/rules/utils/is-color.js +8 -11
- package/dist/cjs/rules/utils/is-node.js +22 -1
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/rules/ensure-design-token-usage/index.js +46 -18
- package/dist/es2019/rules/utils/is-color.js +7 -12
- package/dist/es2019/rules/utils/is-node.js +15 -0
- package/dist/es2019/version.json +1 -1
- package/dist/esm/rules/ensure-design-token-usage/index.js +46 -18
- package/dist/esm/rules/utils/is-color.js +8 -11
- package/dist/esm/rules/utils/is-node.js +15 -0
- package/dist/esm/version.json +1 -1
- package/dist/types/rules/utils/is-node.d.ts +2 -0
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @atlaskit/eslint-plugin-design-system
|
|
2
2
|
|
|
3
|
+
## 4.10.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [`bb808f9a186`](https://bitbucket.org/atlassian/atlassian-frontend/commits/bb808f9a186) - Add exceptions option to ensure-design-token-usage rule
|
|
8
|
+
|
|
9
|
+
## 4.9.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- [`9701bf4a8b3`](https://bitbucket.org/atlassian/atlassian-frontend/commits/9701bf4a8b3) - Fix false positives for variable names and object property keys
|
|
14
|
+
|
|
15
|
+
## 4.8.2
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- [`8d4228767b0`](https://bitbucket.org/atlassian/atlassian-frontend/commits/8d4228767b0) - Upgrade Typescript from `4.2.4` to `4.3.5`.
|
|
20
|
+
|
|
3
21
|
## 4.8.1
|
|
4
22
|
|
|
5
23
|
### Patch Changes
|
|
@@ -58,13 +58,20 @@ var rule = {
|
|
|
58
58
|
},
|
|
59
59
|
create: function create(context) {
|
|
60
60
|
var config = context.options[0] || defaultConfig;
|
|
61
|
+
|
|
62
|
+
var isException = function isException(value) {
|
|
63
|
+
var _config$exceptions$in, _config$exceptions;
|
|
64
|
+
|
|
65
|
+
return (_config$exceptions$in = (_config$exceptions = config.exceptions) === null || _config$exceptions === void 0 ? void 0 : _config$exceptions.includes(value)) !== null && _config$exceptions$in !== void 0 ? _config$exceptions$in : false;
|
|
66
|
+
};
|
|
67
|
+
|
|
61
68
|
return {
|
|
62
69
|
'TemplateLiteral > Identifier': function TemplateLiteralIdentifier(node) {
|
|
63
70
|
if (!(0, _isNode.isDecendantOfStyleBlock)(node)) {
|
|
64
71
|
return;
|
|
65
72
|
}
|
|
66
73
|
|
|
67
|
-
if (node.type === 'Identifier' && (0, _isColor.isLegacyNamedColor)(node.name)) {
|
|
74
|
+
if (node.type === 'Identifier' && (0, _isColor.isLegacyNamedColor)(node.name) && !isException(node.name)) {
|
|
68
75
|
context.report({
|
|
69
76
|
messageId: 'hardCodedColor',
|
|
70
77
|
node: node,
|
|
@@ -74,17 +81,26 @@ var rule = {
|
|
|
74
81
|
}
|
|
75
82
|
},
|
|
76
83
|
Identifier: function Identifier(node) {
|
|
77
|
-
if ((0, _isNode.isDecendantOfGlobalToken)(node) || (0, _isNode.isDecendantOfType)(node, 'ImportDeclaration')) {
|
|
84
|
+
if (isException(node.name) || (0, _isNode.isDecendantOfGlobalToken)(node) || (0, _isNode.isDecendantOfType)(node, 'ImportDeclaration') || (0, _isNode.isPropertyKey)(node) || (0, _isNode.isVariableName)(node)) {
|
|
78
85
|
return;
|
|
79
86
|
}
|
|
80
87
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
+
var isNodeLegacyColor = (0, _isColor.isLegacyColor)(node.name);
|
|
89
|
+
|
|
90
|
+
if (isNodeLegacyColor || (0, _isColor.isHardCodedColor)(node.name)) {
|
|
91
|
+
if (node.parent.type === 'MemberExpression') {
|
|
92
|
+
if (node.parent.object.type === 'Identifier') {
|
|
93
|
+
// Object members as named colors, like obj.ivory, should be valid,
|
|
94
|
+
// and hexes and color functions cannot be property names anyway.
|
|
95
|
+
if (isNodeLegacyColor) {
|
|
96
|
+
context.report({
|
|
97
|
+
messageId: 'hardCodedColor',
|
|
98
|
+
node: node,
|
|
99
|
+
suggest: getTokenSuggestion(node.parent, "".concat(node.parent.object.name, ".").concat(node.name), config)
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
88
104
|
return;
|
|
89
105
|
}
|
|
90
106
|
|
|
@@ -155,6 +171,10 @@ var rule = {
|
|
|
155
171
|
return;
|
|
156
172
|
}
|
|
157
173
|
|
|
174
|
+
if (isException(node.value)) {
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
|
|
158
178
|
if ((0, _isColor.isHardCodedColor)(node.value) || (0, _isColor.includesHardCodedColor)(node.value)) {
|
|
159
179
|
context.report({
|
|
160
180
|
messageId: 'hardCodedColor',
|
|
@@ -173,7 +193,7 @@ var rule = {
|
|
|
173
193
|
return;
|
|
174
194
|
}
|
|
175
195
|
|
|
176
|
-
if (!(0, _isColor.isLegacyNamedColor)(node.callee.name) || (0, _isNode.isDecendantOfGlobalToken)(node)) {
|
|
196
|
+
if (!(0, _isColor.isLegacyNamedColor)(node.callee.name) || (0, _isNode.isDecendantOfGlobalToken)(node) || isException(node.callee.name)) {
|
|
177
197
|
return;
|
|
178
198
|
}
|
|
179
199
|
|
|
@@ -192,13 +212,21 @@ var rule = {
|
|
|
192
212
|
return;
|
|
193
213
|
}
|
|
194
214
|
|
|
195
|
-
if (node.value.type === 'Literal'
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
}
|
|
201
|
-
|
|
215
|
+
if (node.value.type === 'Literal') {
|
|
216
|
+
var literalValue = node.value.value;
|
|
217
|
+
|
|
218
|
+
if (isException(literalValue)) {
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
if ((0, _isColor.isHardCodedColor)(literalValue) || (0, _isColor.includesHardCodedColor)(literalValue)) {
|
|
223
|
+
context.report({
|
|
224
|
+
messageId: 'hardCodedColor',
|
|
225
|
+
node: node,
|
|
226
|
+
suggest: getTokenSuggestion(node.value, literalValue, config)
|
|
227
|
+
});
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
202
230
|
}
|
|
203
231
|
}
|
|
204
232
|
};
|
|
@@ -4,29 +4,26 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.isLegacyNamedColor = exports.isLegacyColor = exports.isHardCodedColor = exports.includesHardCodedColor = void 0;
|
|
7
|
-
var namedColors = ['black', 'silver', 'gray', 'white', 'maroon', 'red', 'purple', 'fuchsia', 'green', 'lime', 'olive', 'yellow', 'navy', 'blue', 'teal', 'aqua', 'orange', 'aliceblue', 'antiquewhite', 'aquamarine', 'azure', 'beige', 'bisque', 'blanchedalmond', 'blueviolet', 'brown', 'burlywood', 'cadetblue', 'chartreuse', 'chocolate', 'coral', 'cornflowerblue', 'cornsilk', 'crimson', 'cyan', 'darkblue', 'darkcyan', 'darkgoldenrod', 'darkgray', 'darkgreen', 'darkgrey', 'darkkhaki', 'darkmagenta', 'darkolivegreen', 'darkorange', 'darkorchid', 'darkred', 'darksalmon', 'darkseagreen', 'darkslateblue', 'darkslategray', 'darkslategrey', 'darkturquoise', 'darkviolet', 'deeppink', 'deepskyblue', 'dimgray', 'dimgrey', 'dodgerblue', 'firebrick', 'floralwhite', 'forestgreen', 'gainsboro', 'ghostwhite', 'gold', 'goldenrod', 'greenyellow', 'grey', 'honeydew', 'hotpink', 'indianred', 'indigo', 'ivory', 'khaki', 'lavender', 'lavenderblush', 'lawngreen', 'lemonchiffon', 'lightblue', 'lightcoral', 'lightcyan', 'lightgoldenrodyellow', 'lightgray', 'lightgreen', 'lightgrey', 'lightpink', 'lightsalmon', 'lightseagreen', 'lightskyblue', 'lightslategray', 'lightslategrey', 'lightsteelblue', 'lightyellow', 'limegreen', 'linen', 'magenta', 'mediumaquamarine', 'mediumblue', 'mediumorchid', 'mediumpurple', 'mediumseagreen', 'mediumslateblue', 'mediumspringgreen', 'mediumturquoise', 'mediumvioletred', 'midnightblue', 'mintcream', 'mistyrose', 'moccasin', 'navajowhite', 'oldlace', 'olivedrab', 'orangered', 'orchid', 'palegoldenrod', 'palegreen', 'paleturquoise', 'palevioletred', 'papayawhip', 'peachpuff', 'peru', 'pink', 'plum', 'powderblue', 'rosybrown', 'royalblue', 'saddlebrown', 'salmon', 'sandybrown', 'seagreen', 'seashell', 'sienna', 'skyblue', 'slateblue', 'slategray', 'slategrey', 'snow', 'springgreen', 'steelblue', 'tan', 'thistle', 'tomato', 'turquoise', 'violet', 'wheat', 'whitesmoke', 'yellowgreen', 'rebeccapurple'];
|
|
8
|
-
var legacyColors = ['R50', 'R75', 'R100', 'R200', 'R300', 'R400', 'R500', 'Y50', 'Y75', 'Y100', 'Y200', 'Y300', 'Y400', 'Y500', 'G50', 'G75', 'G100', 'G200', 'G300', 'G400', 'G500', 'B50', 'B75', 'B100', 'B200', 'B300', 'B400', 'B500', 'P50', 'P75', 'P100', 'P200', 'P300', 'P400', 'P500', 'T50', 'T75', 'T100', 'T200', 'T300', 'T400', 'T500', 'N0', 'N10', 'N20', 'N30', 'N40', 'N50', 'N60', 'N70', 'N80', 'N90', 'N100', 'N200', 'N300', 'N400', 'N500', 'N600', 'N700', 'N800', 'N900', 'N10A', 'N20A', 'N30A', 'N40A', 'N50A', 'N60A', 'N70A', 'N80A', 'N90A', 'N100A', 'N200A', 'N300A', 'N400A', 'N500A', 'N600A', 'N700A', 'N800A', 'DN900', 'DN800', 'DN700', 'DN600', 'DN500', 'DN400', 'DN300', 'DN200', 'DN100', 'DN90', 'DN80', 'DN70', 'DN60', 'DN50', 'DN40', 'DN30', 'DN20', 'DN10', 'DN0', 'DN800A', 'DN700A', 'DN600A', 'DN500A', 'DN400A', 'DN300A', 'DN200A', 'DN100A', 'DN90A', 'DN80A', 'DN70A', 'DN60A', 'DN50A', 'DN40A', 'DN30A', 'DN20A', 'DN10A'
|
|
9
|
-
|
|
7
|
+
var namedColors = new Set(['black', 'silver', 'gray', 'white', 'maroon', 'red', 'purple', 'fuchsia', 'green', 'lime', 'olive', 'yellow', 'navy', 'blue', 'teal', 'aqua', 'orange', 'aliceblue', 'antiquewhite', 'aquamarine', 'azure', 'beige', 'bisque', 'blanchedalmond', 'blueviolet', 'brown', 'burlywood', 'cadetblue', 'chartreuse', 'chocolate', 'coral', 'cornflowerblue', 'cornsilk', 'crimson', 'cyan', 'darkblue', 'darkcyan', 'darkgoldenrod', 'darkgray', 'darkgreen', 'darkgrey', 'darkkhaki', 'darkmagenta', 'darkolivegreen', 'darkorange', 'darkorchid', 'darkred', 'darksalmon', 'darkseagreen', 'darkslateblue', 'darkslategray', 'darkslategrey', 'darkturquoise', 'darkviolet', 'deeppink', 'deepskyblue', 'dimgray', 'dimgrey', 'dodgerblue', 'firebrick', 'floralwhite', 'forestgreen', 'gainsboro', 'ghostwhite', 'gold', 'goldenrod', 'greenyellow', 'grey', 'honeydew', 'hotpink', 'indianred', 'indigo', 'ivory', 'khaki', 'lavender', 'lavenderblush', 'lawngreen', 'lemonchiffon', 'lightblue', 'lightcoral', 'lightcyan', 'lightgoldenrodyellow', 'lightgray', 'lightgreen', 'lightgrey', 'lightpink', 'lightsalmon', 'lightseagreen', 'lightskyblue', 'lightslategray', 'lightslategrey', 'lightsteelblue', 'lightyellow', 'limegreen', 'linen', 'magenta', 'mediumaquamarine', 'mediumblue', 'mediumorchid', 'mediumpurple', 'mediumseagreen', 'mediumslateblue', 'mediumspringgreen', 'mediumturquoise', 'mediumvioletred', 'midnightblue', 'mintcream', 'mistyrose', 'moccasin', 'navajowhite', 'oldlace', 'olivedrab', 'orangered', 'orchid', 'palegoldenrod', 'palegreen', 'paleturquoise', 'palevioletred', 'papayawhip', 'peachpuff', 'peru', 'pink', 'plum', 'powderblue', 'rosybrown', 'royalblue', 'saddlebrown', 'salmon', 'sandybrown', 'seagreen', 'seashell', 'sienna', 'skyblue', 'slateblue', 'slategray', 'slategrey', 'snow', 'springgreen', 'steelblue', 'tan', 'thistle', 'tomato', 'turquoise', 'violet', 'wheat', 'whitesmoke', 'yellowgreen', 'rebeccapurple']);
|
|
8
|
+
var legacyColors = new Set(['R50', 'R75', 'R100', 'R200', 'R300', 'R400', 'R500', 'Y50', 'Y75', 'Y100', 'Y200', 'Y300', 'Y400', 'Y500', 'G50', 'G75', 'G100', 'G200', 'G300', 'G400', 'G500', 'B50', 'B75', 'B100', 'B200', 'B300', 'B400', 'B500', 'P50', 'P75', 'P100', 'P200', 'P300', 'P400', 'P500', 'T50', 'T75', 'T100', 'T200', 'T300', 'T400', 'T500', 'N0', 'N10', 'N20', 'N30', 'N40', 'N50', 'N60', 'N70', 'N80', 'N90', 'N100', 'N200', 'N300', 'N400', 'N500', 'N600', 'N700', 'N800', 'N900', 'N10A', 'N20A', 'N30A', 'N40A', 'N50A', 'N60A', 'N70A', 'N80A', 'N90A', 'N100A', 'N200A', 'N300A', 'N400A', 'N500A', 'N600A', 'N700A', 'N800A', 'DN900', 'DN800', 'DN700', 'DN600', 'DN500', 'DN400', 'DN300', 'DN200', 'DN100', 'DN90', 'DN80', 'DN70', 'DN60', 'DN50', 'DN40', 'DN30', 'DN20', 'DN10', 'DN0', 'DN800A', 'DN700A', 'DN600A', 'DN500A', 'DN400A', 'DN300A', 'DN200A', 'DN100A', 'DN90A', 'DN80A', 'DN70A', 'DN60A', 'DN50A', 'DN40A', 'DN30A', 'DN20A', 'DN10A', // Legacy Trello colors:
|
|
9
|
+
'AtlassianBlue50', 'AtlassianBlue200', 'AtlassianBlue300', 'AtlassianBlue400', 'TrelloBlue25', 'TrelloBlue50', 'TrelloBlue100', 'TrelloBlue200', 'TrelloBlue300', 'TrelloBlue400', 'TrelloBlue500', 'TrelloBlue600', 'TrelloBlue700', 'TrelloBlue800', 'TrelloBlue900', 'Green50', 'Green100', 'Green200', 'Green300', 'Green400', 'Green500', 'Green600', 'Green700', 'Green800', 'Green900', 'Orange50', 'Orange100', 'Orange200', 'Orange300', 'Orange400', 'Orange500', 'Orange600', 'Orange700', 'Orange800', 'Orange900', 'Red50', 'Red100', 'Red200', 'Red300', 'Red400', 'Red500', 'Red600', 'Red700', 'Red800', 'Red900', 'Yellow50', 'Yellow100', 'Yellow200', 'Yellow300', 'Yellow400', 'Yellow500', 'Yellow600', 'Yellow700', 'Yellow800', 'Yellow900', 'Purple50', 'Purple100', 'Purple200', 'Purple300', 'Purple400', 'Purple500', 'Purple600', 'Purple700', 'Purple800', 'Purple900', 'VioletMbgAlert', 'Pink50', 'Pink100', 'Pink200', 'Pink300', 'Pink400', 'Pink500', 'Pink600', 'Pink700', 'Pink800', 'Pink900', 'Sky25', 'Sky50', 'Sky100', 'Sky200', 'Sky300', 'Sky400', 'Sky500', 'Sky600', 'Sky700', 'Sky800', 'Sky900', 'Lime50', 'Lime100', 'Lime200', 'Lime300', 'Lime400', 'Lime500', 'Lime600', 'Lime700', 'Lime800', 'Lime900', 'BusinessBlue50', 'BusinessBlue100', 'BusinessBlue200', 'BusinessBlue300', 'BusinessBlue400', 'BusinessBlue500', 'BusinessBlue600', 'BusinessBlue700', 'BusinessBlue800', 'BusinessBlue900', 'Opacity1', 'Opacity2', 'Opacity3', 'Opacity4', 'Opacity5', 'Opacity6', 'Opacity7', 'Opacity8', 'Opacity9', 'OpacityDark1', 'OpacityDark2', 'OpacityDark3', 'OpacityDark4', 'OpacityDark5', 'OpacityDark6', 'OpacityDark7', 'OpacityDark8', 'OpacityDark9', 'Black']);
|
|
10
|
+
var legacyColorMixins = new Set(['background', 'backgroundActive', 'backgroundHover', 'backgroundOnLayer', 'text', 'textHover', 'textActive', 'subtleText', 'placeholderText', 'heading', 'subtleHeading', 'codeBlock', 'link', 'linkHover', 'linkActive', 'linkOutline', 'primary', 'blue', 'teal', 'purple', 'red', 'yellow', 'green', 'skeleton']);
|
|
10
11
|
|
|
11
12
|
var includesWholeWord = function includesWholeWord(value, options) {
|
|
12
13
|
var values = value.replace(/[^a-zA-Z ]/g, ' ').trim().split(/(?:,|\.| )+/);
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
if (values.includes(el)) {
|
|
16
|
-
result = true;
|
|
17
|
-
}
|
|
14
|
+
return values.some(function (value) {
|
|
15
|
+
return options.has(value);
|
|
18
16
|
});
|
|
19
|
-
return result;
|
|
20
17
|
};
|
|
21
18
|
|
|
22
19
|
var isLegacyColor = function isLegacyColor(value) {
|
|
23
|
-
return legacyColors.
|
|
20
|
+
return legacyColors.has(value);
|
|
24
21
|
};
|
|
25
22
|
|
|
26
23
|
exports.isLegacyColor = isLegacyColor;
|
|
27
24
|
|
|
28
25
|
var isLegacyNamedColor = function isLegacyNamedColor(value) {
|
|
29
|
-
return legacyColorMixins.
|
|
26
|
+
return legacyColorMixins.has(value);
|
|
30
27
|
};
|
|
31
28
|
|
|
32
29
|
exports.isLegacyNamedColor = isLegacyNamedColor;
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.isStyledTemplateNode = exports.isStyledObjectNode = exports.isDecendantOfType = exports.isDecendantOfStyleJsxAttribute = exports.isDecendantOfStyleBlock = exports.isDecendantOfGlobalToken = exports.isChildOfType = void 0;
|
|
6
|
+
exports.isVariableName = exports.isStyledTemplateNode = exports.isStyledObjectNode = exports.isPropertyKey = exports.isDecendantOfType = exports.isDecendantOfStyleJsxAttribute = exports.isDecendantOfStyleBlock = exports.isDecendantOfGlobalToken = exports.isChildOfType = void 0;
|
|
7
7
|
|
|
8
8
|
var _eslintCodemodUtils = require("eslint-codemod-utils");
|
|
9
9
|
|
|
@@ -37,6 +37,27 @@ var isDecendantOfType = function isDecendantOfType(node, type) {
|
|
|
37
37
|
|
|
38
38
|
exports.isDecendantOfType = isDecendantOfType;
|
|
39
39
|
|
|
40
|
+
var isPropertyKey = function isPropertyKey(node) {
|
|
41
|
+
if ((0, _eslintCodemodUtils.isNodeOfType)(node, 'Identifier') && isDecendantOfType(node, 'Property')) {
|
|
42
|
+
var parent = node.parent;
|
|
43
|
+
return node === parent.key || parent.shorthand;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return false;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
exports.isPropertyKey = isPropertyKey;
|
|
50
|
+
|
|
51
|
+
var isVariableName = function isVariableName(node) {
|
|
52
|
+
if ((0, _eslintCodemodUtils.isNodeOfType)(node, 'Identifier') && isDecendantOfType(node, 'VariableDeclarator')) {
|
|
53
|
+
return node === node.parent.id;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return false;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
exports.isVariableName = isVariableName;
|
|
60
|
+
|
|
40
61
|
var isDecendantOfStyleJsxAttribute = function isDecendantOfStyleJsxAttribute(node) {
|
|
41
62
|
// @ts-ignore
|
|
42
63
|
if (node.type === 'JSXAttribute') {
|
package/dist/cjs/version.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { isNodeOfType } from 'eslint-codemod-utils';
|
|
2
2
|
import { includesHardCodedColor, isHardCodedColor, isLegacyColor, isLegacyNamedColor } from '../utils/is-color';
|
|
3
3
|
import { isLegacyElevation } from '../utils/is-elevation';
|
|
4
|
-
import { isChildOfType, isDecendantOfGlobalToken, isDecendantOfStyleBlock, isDecendantOfStyleJsxAttribute, isDecendantOfType } from '../utils/is-node';
|
|
4
|
+
import { isChildOfType, isDecendantOfGlobalToken, isDecendantOfStyleBlock, isDecendantOfStyleJsxAttribute, isDecendantOfType, isPropertyKey, isVariableName } from '../utils/is-node';
|
|
5
5
|
const defaultConfig = {
|
|
6
6
|
shouldEnforceFallbacks: false
|
|
7
7
|
};
|
|
@@ -49,13 +49,20 @@ token('color.background.blanket');
|
|
|
49
49
|
|
|
50
50
|
create(context) {
|
|
51
51
|
const config = context.options[0] || defaultConfig;
|
|
52
|
+
|
|
53
|
+
const isException = value => {
|
|
54
|
+
var _config$exceptions$in, _config$exceptions;
|
|
55
|
+
|
|
56
|
+
return (_config$exceptions$in = (_config$exceptions = config.exceptions) === null || _config$exceptions === void 0 ? void 0 : _config$exceptions.includes(value)) !== null && _config$exceptions$in !== void 0 ? _config$exceptions$in : false;
|
|
57
|
+
};
|
|
58
|
+
|
|
52
59
|
return {
|
|
53
60
|
'TemplateLiteral > Identifier': node => {
|
|
54
61
|
if (!isDecendantOfStyleBlock(node)) {
|
|
55
62
|
return;
|
|
56
63
|
}
|
|
57
64
|
|
|
58
|
-
if (node.type === 'Identifier' && isLegacyNamedColor(node.name)) {
|
|
65
|
+
if (node.type === 'Identifier' && isLegacyNamedColor(node.name) && !isException(node.name)) {
|
|
59
66
|
context.report({
|
|
60
67
|
messageId: 'hardCodedColor',
|
|
61
68
|
node,
|
|
@@ -66,17 +73,26 @@ token('color.background.blanket');
|
|
|
66
73
|
},
|
|
67
74
|
|
|
68
75
|
Identifier(node) {
|
|
69
|
-
if (isDecendantOfGlobalToken(node) || isDecendantOfType(node, 'ImportDeclaration')) {
|
|
76
|
+
if (isException(node.name) || isDecendantOfGlobalToken(node) || isDecendantOfType(node, 'ImportDeclaration') || isPropertyKey(node) || isVariableName(node)) {
|
|
70
77
|
return;
|
|
71
78
|
}
|
|
72
79
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
+
const isNodeLegacyColor = isLegacyColor(node.name);
|
|
81
|
+
|
|
82
|
+
if (isNodeLegacyColor || isHardCodedColor(node.name)) {
|
|
83
|
+
if (node.parent.type === 'MemberExpression') {
|
|
84
|
+
if (node.parent.object.type === 'Identifier') {
|
|
85
|
+
// Object members as named colors, like obj.ivory, should be valid,
|
|
86
|
+
// and hexes and color functions cannot be property names anyway.
|
|
87
|
+
if (isNodeLegacyColor) {
|
|
88
|
+
context.report({
|
|
89
|
+
messageId: 'hardCodedColor',
|
|
90
|
+
node,
|
|
91
|
+
suggest: getTokenSuggestion(node.parent, `${node.parent.object.name}.${node.name}`, config)
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
80
96
|
return;
|
|
81
97
|
}
|
|
82
98
|
|
|
@@ -152,6 +168,10 @@ ${' '.repeat(getNodeColumn(node) - 2)}box-shadow: \${token('${elevation.shadow}'
|
|
|
152
168
|
return;
|
|
153
169
|
}
|
|
154
170
|
|
|
171
|
+
if (isException(node.value)) {
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
|
|
155
175
|
if (isHardCodedColor(node.value) || includesHardCodedColor(node.value)) {
|
|
156
176
|
context.report({
|
|
157
177
|
messageId: 'hardCodedColor',
|
|
@@ -171,7 +191,7 @@ ${' '.repeat(getNodeColumn(node) - 2)}box-shadow: \${token('${elevation.shadow}'
|
|
|
171
191
|
return;
|
|
172
192
|
}
|
|
173
193
|
|
|
174
|
-
if (!isLegacyNamedColor(node.callee.name) || isDecendantOfGlobalToken(node)) {
|
|
194
|
+
if (!isLegacyNamedColor(node.callee.name) || isDecendantOfGlobalToken(node) || isException(node.callee.name)) {
|
|
175
195
|
return;
|
|
176
196
|
}
|
|
177
197
|
|
|
@@ -191,13 +211,21 @@ ${' '.repeat(getNodeColumn(node) - 2)}box-shadow: \${token('${elevation.shadow}'
|
|
|
191
211
|
return;
|
|
192
212
|
}
|
|
193
213
|
|
|
194
|
-
if (node.value.type === 'Literal'
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
}
|
|
200
|
-
|
|
214
|
+
if (node.value.type === 'Literal') {
|
|
215
|
+
const literalValue = node.value.value;
|
|
216
|
+
|
|
217
|
+
if (isException(literalValue)) {
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
if (isHardCodedColor(literalValue) || includesHardCodedColor(literalValue)) {
|
|
222
|
+
context.report({
|
|
223
|
+
messageId: 'hardCodedColor',
|
|
224
|
+
node,
|
|
225
|
+
suggest: getTokenSuggestion(node.value, literalValue, config)
|
|
226
|
+
});
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
201
229
|
}
|
|
202
230
|
}
|
|
203
231
|
|
|
@@ -1,20 +1,15 @@
|
|
|
1
|
-
const namedColors = ['black', 'silver', 'gray', 'white', 'maroon', 'red', 'purple', 'fuchsia', 'green', 'lime', 'olive', 'yellow', 'navy', 'blue', 'teal', 'aqua', 'orange', 'aliceblue', 'antiquewhite', 'aquamarine', 'azure', 'beige', 'bisque', 'blanchedalmond', 'blueviolet', 'brown', 'burlywood', 'cadetblue', 'chartreuse', 'chocolate', 'coral', 'cornflowerblue', 'cornsilk', 'crimson', 'cyan', 'darkblue', 'darkcyan', 'darkgoldenrod', 'darkgray', 'darkgreen', 'darkgrey', 'darkkhaki', 'darkmagenta', 'darkolivegreen', 'darkorange', 'darkorchid', 'darkred', 'darksalmon', 'darkseagreen', 'darkslateblue', 'darkslategray', 'darkslategrey', 'darkturquoise', 'darkviolet', 'deeppink', 'deepskyblue', 'dimgray', 'dimgrey', 'dodgerblue', 'firebrick', 'floralwhite', 'forestgreen', 'gainsboro', 'ghostwhite', 'gold', 'goldenrod', 'greenyellow', 'grey', 'honeydew', 'hotpink', 'indianred', 'indigo', 'ivory', 'khaki', 'lavender', 'lavenderblush', 'lawngreen', 'lemonchiffon', 'lightblue', 'lightcoral', 'lightcyan', 'lightgoldenrodyellow', 'lightgray', 'lightgreen', 'lightgrey', 'lightpink', 'lightsalmon', 'lightseagreen', 'lightskyblue', 'lightslategray', 'lightslategrey', 'lightsteelblue', 'lightyellow', 'limegreen', 'linen', 'magenta', 'mediumaquamarine', 'mediumblue', 'mediumorchid', 'mediumpurple', 'mediumseagreen', 'mediumslateblue', 'mediumspringgreen', 'mediumturquoise', 'mediumvioletred', 'midnightblue', 'mintcream', 'mistyrose', 'moccasin', 'navajowhite', 'oldlace', 'olivedrab', 'orangered', 'orchid', 'palegoldenrod', 'palegreen', 'paleturquoise', 'palevioletred', 'papayawhip', 'peachpuff', 'peru', 'pink', 'plum', 'powderblue', 'rosybrown', 'royalblue', 'saddlebrown', 'salmon', 'sandybrown', 'seagreen', 'seashell', 'sienna', 'skyblue', 'slateblue', 'slategray', 'slategrey', 'snow', 'springgreen', 'steelblue', 'tan', 'thistle', 'tomato', 'turquoise', 'violet', 'wheat', 'whitesmoke', 'yellowgreen', 'rebeccapurple'];
|
|
2
|
-
const legacyColors = ['R50', 'R75', 'R100', 'R200', 'R300', 'R400', 'R500', 'Y50', 'Y75', 'Y100', 'Y200', 'Y300', 'Y400', 'Y500', 'G50', 'G75', 'G100', 'G200', 'G300', 'G400', 'G500', 'B50', 'B75', 'B100', 'B200', 'B300', 'B400', 'B500', 'P50', 'P75', 'P100', 'P200', 'P300', 'P400', 'P500', 'T50', 'T75', 'T100', 'T200', 'T300', 'T400', 'T500', 'N0', 'N10', 'N20', 'N30', 'N40', 'N50', 'N60', 'N70', 'N80', 'N90', 'N100', 'N200', 'N300', 'N400', 'N500', 'N600', 'N700', 'N800', 'N900', 'N10A', 'N20A', 'N30A', 'N40A', 'N50A', 'N60A', 'N70A', 'N80A', 'N90A', 'N100A', 'N200A', 'N300A', 'N400A', 'N500A', 'N600A', 'N700A', 'N800A', 'DN900', 'DN800', 'DN700', 'DN600', 'DN500', 'DN400', 'DN300', 'DN200', 'DN100', 'DN90', 'DN80', 'DN70', 'DN60', 'DN50', 'DN40', 'DN30', 'DN20', 'DN10', 'DN0', 'DN800A', 'DN700A', 'DN600A', 'DN500A', 'DN400A', 'DN300A', 'DN200A', 'DN100A', 'DN90A', 'DN80A', 'DN70A', 'DN60A', 'DN50A', 'DN40A', 'DN30A', 'DN20A', 'DN10A'
|
|
3
|
-
|
|
1
|
+
const namedColors = new Set(['black', 'silver', 'gray', 'white', 'maroon', 'red', 'purple', 'fuchsia', 'green', 'lime', 'olive', 'yellow', 'navy', 'blue', 'teal', 'aqua', 'orange', 'aliceblue', 'antiquewhite', 'aquamarine', 'azure', 'beige', 'bisque', 'blanchedalmond', 'blueviolet', 'brown', 'burlywood', 'cadetblue', 'chartreuse', 'chocolate', 'coral', 'cornflowerblue', 'cornsilk', 'crimson', 'cyan', 'darkblue', 'darkcyan', 'darkgoldenrod', 'darkgray', 'darkgreen', 'darkgrey', 'darkkhaki', 'darkmagenta', 'darkolivegreen', 'darkorange', 'darkorchid', 'darkred', 'darksalmon', 'darkseagreen', 'darkslateblue', 'darkslategray', 'darkslategrey', 'darkturquoise', 'darkviolet', 'deeppink', 'deepskyblue', 'dimgray', 'dimgrey', 'dodgerblue', 'firebrick', 'floralwhite', 'forestgreen', 'gainsboro', 'ghostwhite', 'gold', 'goldenrod', 'greenyellow', 'grey', 'honeydew', 'hotpink', 'indianred', 'indigo', 'ivory', 'khaki', 'lavender', 'lavenderblush', 'lawngreen', 'lemonchiffon', 'lightblue', 'lightcoral', 'lightcyan', 'lightgoldenrodyellow', 'lightgray', 'lightgreen', 'lightgrey', 'lightpink', 'lightsalmon', 'lightseagreen', 'lightskyblue', 'lightslategray', 'lightslategrey', 'lightsteelblue', 'lightyellow', 'limegreen', 'linen', 'magenta', 'mediumaquamarine', 'mediumblue', 'mediumorchid', 'mediumpurple', 'mediumseagreen', 'mediumslateblue', 'mediumspringgreen', 'mediumturquoise', 'mediumvioletred', 'midnightblue', 'mintcream', 'mistyrose', 'moccasin', 'navajowhite', 'oldlace', 'olivedrab', 'orangered', 'orchid', 'palegoldenrod', 'palegreen', 'paleturquoise', 'palevioletred', 'papayawhip', 'peachpuff', 'peru', 'pink', 'plum', 'powderblue', 'rosybrown', 'royalblue', 'saddlebrown', 'salmon', 'sandybrown', 'seagreen', 'seashell', 'sienna', 'skyblue', 'slateblue', 'slategray', 'slategrey', 'snow', 'springgreen', 'steelblue', 'tan', 'thistle', 'tomato', 'turquoise', 'violet', 'wheat', 'whitesmoke', 'yellowgreen', 'rebeccapurple']);
|
|
2
|
+
const legacyColors = new Set(['R50', 'R75', 'R100', 'R200', 'R300', 'R400', 'R500', 'Y50', 'Y75', 'Y100', 'Y200', 'Y300', 'Y400', 'Y500', 'G50', 'G75', 'G100', 'G200', 'G300', 'G400', 'G500', 'B50', 'B75', 'B100', 'B200', 'B300', 'B400', 'B500', 'P50', 'P75', 'P100', 'P200', 'P300', 'P400', 'P500', 'T50', 'T75', 'T100', 'T200', 'T300', 'T400', 'T500', 'N0', 'N10', 'N20', 'N30', 'N40', 'N50', 'N60', 'N70', 'N80', 'N90', 'N100', 'N200', 'N300', 'N400', 'N500', 'N600', 'N700', 'N800', 'N900', 'N10A', 'N20A', 'N30A', 'N40A', 'N50A', 'N60A', 'N70A', 'N80A', 'N90A', 'N100A', 'N200A', 'N300A', 'N400A', 'N500A', 'N600A', 'N700A', 'N800A', 'DN900', 'DN800', 'DN700', 'DN600', 'DN500', 'DN400', 'DN300', 'DN200', 'DN100', 'DN90', 'DN80', 'DN70', 'DN60', 'DN50', 'DN40', 'DN30', 'DN20', 'DN10', 'DN0', 'DN800A', 'DN700A', 'DN600A', 'DN500A', 'DN400A', 'DN300A', 'DN200A', 'DN100A', 'DN90A', 'DN80A', 'DN70A', 'DN60A', 'DN50A', 'DN40A', 'DN30A', 'DN20A', 'DN10A', // Legacy Trello colors:
|
|
3
|
+
'AtlassianBlue50', 'AtlassianBlue200', 'AtlassianBlue300', 'AtlassianBlue400', 'TrelloBlue25', 'TrelloBlue50', 'TrelloBlue100', 'TrelloBlue200', 'TrelloBlue300', 'TrelloBlue400', 'TrelloBlue500', 'TrelloBlue600', 'TrelloBlue700', 'TrelloBlue800', 'TrelloBlue900', 'Green50', 'Green100', 'Green200', 'Green300', 'Green400', 'Green500', 'Green600', 'Green700', 'Green800', 'Green900', 'Orange50', 'Orange100', 'Orange200', 'Orange300', 'Orange400', 'Orange500', 'Orange600', 'Orange700', 'Orange800', 'Orange900', 'Red50', 'Red100', 'Red200', 'Red300', 'Red400', 'Red500', 'Red600', 'Red700', 'Red800', 'Red900', 'Yellow50', 'Yellow100', 'Yellow200', 'Yellow300', 'Yellow400', 'Yellow500', 'Yellow600', 'Yellow700', 'Yellow800', 'Yellow900', 'Purple50', 'Purple100', 'Purple200', 'Purple300', 'Purple400', 'Purple500', 'Purple600', 'Purple700', 'Purple800', 'Purple900', 'VioletMbgAlert', 'Pink50', 'Pink100', 'Pink200', 'Pink300', 'Pink400', 'Pink500', 'Pink600', 'Pink700', 'Pink800', 'Pink900', 'Sky25', 'Sky50', 'Sky100', 'Sky200', 'Sky300', 'Sky400', 'Sky500', 'Sky600', 'Sky700', 'Sky800', 'Sky900', 'Lime50', 'Lime100', 'Lime200', 'Lime300', 'Lime400', 'Lime500', 'Lime600', 'Lime700', 'Lime800', 'Lime900', 'BusinessBlue50', 'BusinessBlue100', 'BusinessBlue200', 'BusinessBlue300', 'BusinessBlue400', 'BusinessBlue500', 'BusinessBlue600', 'BusinessBlue700', 'BusinessBlue800', 'BusinessBlue900', 'Opacity1', 'Opacity2', 'Opacity3', 'Opacity4', 'Opacity5', 'Opacity6', 'Opacity7', 'Opacity8', 'Opacity9', 'OpacityDark1', 'OpacityDark2', 'OpacityDark3', 'OpacityDark4', 'OpacityDark5', 'OpacityDark6', 'OpacityDark7', 'OpacityDark8', 'OpacityDark9', 'Black']);
|
|
4
|
+
const legacyColorMixins = new Set(['background', 'backgroundActive', 'backgroundHover', 'backgroundOnLayer', 'text', 'textHover', 'textActive', 'subtleText', 'placeholderText', 'heading', 'subtleHeading', 'codeBlock', 'link', 'linkHover', 'linkActive', 'linkOutline', 'primary', 'blue', 'teal', 'purple', 'red', 'yellow', 'green', 'skeleton']);
|
|
4
5
|
|
|
5
6
|
const includesWholeWord = (value, options) => {
|
|
6
7
|
const values = value.replace(/[^a-zA-Z ]/g, ' ').trim().split(/(?:,|\.| )+/);
|
|
7
|
-
|
|
8
|
-
options.forEach(el => {
|
|
9
|
-
if (values.includes(el)) {
|
|
10
|
-
result = true;
|
|
11
|
-
}
|
|
12
|
-
});
|
|
13
|
-
return result;
|
|
8
|
+
return values.some(value => options.has(value));
|
|
14
9
|
};
|
|
15
10
|
|
|
16
|
-
export const isLegacyColor = value => legacyColors.
|
|
17
|
-
export const isLegacyNamedColor = value => legacyColorMixins.
|
|
11
|
+
export const isLegacyColor = value => legacyColors.has(value);
|
|
12
|
+
export const isLegacyNamedColor = value => legacyColorMixins.has(value);
|
|
18
13
|
export const includesHardCodedColor = raw => {
|
|
19
14
|
const value = raw.toLowerCase();
|
|
20
15
|
|
|
@@ -21,6 +21,21 @@ export const isDecendantOfType = (node, type, skipNode = true) => {
|
|
|
21
21
|
|
|
22
22
|
return false;
|
|
23
23
|
};
|
|
24
|
+
export const isPropertyKey = node => {
|
|
25
|
+
if (isNodeOfType(node, 'Identifier') && isDecendantOfType(node, 'Property')) {
|
|
26
|
+
const parent = node.parent;
|
|
27
|
+
return node === parent.key || parent.shorthand;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return false;
|
|
31
|
+
};
|
|
32
|
+
export const isVariableName = node => {
|
|
33
|
+
if (isNodeOfType(node, 'Identifier') && isDecendantOfType(node, 'VariableDeclarator')) {
|
|
34
|
+
return node === node.parent.id;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return false;
|
|
38
|
+
};
|
|
24
39
|
export const isDecendantOfStyleJsxAttribute = node => {
|
|
25
40
|
// @ts-ignore
|
|
26
41
|
if (node.type === 'JSXAttribute') {
|
package/dist/es2019/version.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { isNodeOfType } from 'eslint-codemod-utils';
|
|
2
2
|
import { includesHardCodedColor, isHardCodedColor, isLegacyColor, isLegacyNamedColor } from '../utils/is-color';
|
|
3
3
|
import { isLegacyElevation } from '../utils/is-elevation';
|
|
4
|
-
import { isChildOfType, isDecendantOfGlobalToken, isDecendantOfStyleBlock, isDecendantOfStyleJsxAttribute, isDecendantOfType } from '../utils/is-node';
|
|
4
|
+
import { isChildOfType, isDecendantOfGlobalToken, isDecendantOfStyleBlock, isDecendantOfStyleJsxAttribute, isDecendantOfType, isPropertyKey, isVariableName } from '../utils/is-node';
|
|
5
5
|
var defaultConfig = {
|
|
6
6
|
shouldEnforceFallbacks: false
|
|
7
7
|
};
|
|
@@ -47,13 +47,20 @@ var rule = {
|
|
|
47
47
|
},
|
|
48
48
|
create: function create(context) {
|
|
49
49
|
var config = context.options[0] || defaultConfig;
|
|
50
|
+
|
|
51
|
+
var isException = function isException(value) {
|
|
52
|
+
var _config$exceptions$in, _config$exceptions;
|
|
53
|
+
|
|
54
|
+
return (_config$exceptions$in = (_config$exceptions = config.exceptions) === null || _config$exceptions === void 0 ? void 0 : _config$exceptions.includes(value)) !== null && _config$exceptions$in !== void 0 ? _config$exceptions$in : false;
|
|
55
|
+
};
|
|
56
|
+
|
|
50
57
|
return {
|
|
51
58
|
'TemplateLiteral > Identifier': function TemplateLiteralIdentifier(node) {
|
|
52
59
|
if (!isDecendantOfStyleBlock(node)) {
|
|
53
60
|
return;
|
|
54
61
|
}
|
|
55
62
|
|
|
56
|
-
if (node.type === 'Identifier' && isLegacyNamedColor(node.name)) {
|
|
63
|
+
if (node.type === 'Identifier' && isLegacyNamedColor(node.name) && !isException(node.name)) {
|
|
57
64
|
context.report({
|
|
58
65
|
messageId: 'hardCodedColor',
|
|
59
66
|
node: node,
|
|
@@ -63,17 +70,26 @@ var rule = {
|
|
|
63
70
|
}
|
|
64
71
|
},
|
|
65
72
|
Identifier: function Identifier(node) {
|
|
66
|
-
if (isDecendantOfGlobalToken(node) || isDecendantOfType(node, 'ImportDeclaration')) {
|
|
73
|
+
if (isException(node.name) || isDecendantOfGlobalToken(node) || isDecendantOfType(node, 'ImportDeclaration') || isPropertyKey(node) || isVariableName(node)) {
|
|
67
74
|
return;
|
|
68
75
|
}
|
|
69
76
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
+
var isNodeLegacyColor = isLegacyColor(node.name);
|
|
78
|
+
|
|
79
|
+
if (isNodeLegacyColor || isHardCodedColor(node.name)) {
|
|
80
|
+
if (node.parent.type === 'MemberExpression') {
|
|
81
|
+
if (node.parent.object.type === 'Identifier') {
|
|
82
|
+
// Object members as named colors, like obj.ivory, should be valid,
|
|
83
|
+
// and hexes and color functions cannot be property names anyway.
|
|
84
|
+
if (isNodeLegacyColor) {
|
|
85
|
+
context.report({
|
|
86
|
+
messageId: 'hardCodedColor',
|
|
87
|
+
node: node,
|
|
88
|
+
suggest: getTokenSuggestion(node.parent, "".concat(node.parent.object.name, ".").concat(node.name), config)
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
77
93
|
return;
|
|
78
94
|
}
|
|
79
95
|
|
|
@@ -144,6 +160,10 @@ var rule = {
|
|
|
144
160
|
return;
|
|
145
161
|
}
|
|
146
162
|
|
|
163
|
+
if (isException(node.value)) {
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
|
|
147
167
|
if (isHardCodedColor(node.value) || includesHardCodedColor(node.value)) {
|
|
148
168
|
context.report({
|
|
149
169
|
messageId: 'hardCodedColor',
|
|
@@ -162,7 +182,7 @@ var rule = {
|
|
|
162
182
|
return;
|
|
163
183
|
}
|
|
164
184
|
|
|
165
|
-
if (!isLegacyNamedColor(node.callee.name) || isDecendantOfGlobalToken(node)) {
|
|
185
|
+
if (!isLegacyNamedColor(node.callee.name) || isDecendantOfGlobalToken(node) || isException(node.callee.name)) {
|
|
166
186
|
return;
|
|
167
187
|
}
|
|
168
188
|
|
|
@@ -181,13 +201,21 @@ var rule = {
|
|
|
181
201
|
return;
|
|
182
202
|
}
|
|
183
203
|
|
|
184
|
-
if (node.value.type === 'Literal'
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
}
|
|
190
|
-
|
|
204
|
+
if (node.value.type === 'Literal') {
|
|
205
|
+
var literalValue = node.value.value;
|
|
206
|
+
|
|
207
|
+
if (isException(literalValue)) {
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
if (isHardCodedColor(literalValue) || includesHardCodedColor(literalValue)) {
|
|
212
|
+
context.report({
|
|
213
|
+
messageId: 'hardCodedColor',
|
|
214
|
+
node: node,
|
|
215
|
+
suggest: getTokenSuggestion(node.value, literalValue, config)
|
|
216
|
+
});
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
191
219
|
}
|
|
192
220
|
}
|
|
193
221
|
};
|
|
@@ -1,23 +1,20 @@
|
|
|
1
|
-
var namedColors = ['black', 'silver', 'gray', 'white', 'maroon', 'red', 'purple', 'fuchsia', 'green', 'lime', 'olive', 'yellow', 'navy', 'blue', 'teal', 'aqua', 'orange', 'aliceblue', 'antiquewhite', 'aquamarine', 'azure', 'beige', 'bisque', 'blanchedalmond', 'blueviolet', 'brown', 'burlywood', 'cadetblue', 'chartreuse', 'chocolate', 'coral', 'cornflowerblue', 'cornsilk', 'crimson', 'cyan', 'darkblue', 'darkcyan', 'darkgoldenrod', 'darkgray', 'darkgreen', 'darkgrey', 'darkkhaki', 'darkmagenta', 'darkolivegreen', 'darkorange', 'darkorchid', 'darkred', 'darksalmon', 'darkseagreen', 'darkslateblue', 'darkslategray', 'darkslategrey', 'darkturquoise', 'darkviolet', 'deeppink', 'deepskyblue', 'dimgray', 'dimgrey', 'dodgerblue', 'firebrick', 'floralwhite', 'forestgreen', 'gainsboro', 'ghostwhite', 'gold', 'goldenrod', 'greenyellow', 'grey', 'honeydew', 'hotpink', 'indianred', 'indigo', 'ivory', 'khaki', 'lavender', 'lavenderblush', 'lawngreen', 'lemonchiffon', 'lightblue', 'lightcoral', 'lightcyan', 'lightgoldenrodyellow', 'lightgray', 'lightgreen', 'lightgrey', 'lightpink', 'lightsalmon', 'lightseagreen', 'lightskyblue', 'lightslategray', 'lightslategrey', 'lightsteelblue', 'lightyellow', 'limegreen', 'linen', 'magenta', 'mediumaquamarine', 'mediumblue', 'mediumorchid', 'mediumpurple', 'mediumseagreen', 'mediumslateblue', 'mediumspringgreen', 'mediumturquoise', 'mediumvioletred', 'midnightblue', 'mintcream', 'mistyrose', 'moccasin', 'navajowhite', 'oldlace', 'olivedrab', 'orangered', 'orchid', 'palegoldenrod', 'palegreen', 'paleturquoise', 'palevioletred', 'papayawhip', 'peachpuff', 'peru', 'pink', 'plum', 'powderblue', 'rosybrown', 'royalblue', 'saddlebrown', 'salmon', 'sandybrown', 'seagreen', 'seashell', 'sienna', 'skyblue', 'slateblue', 'slategray', 'slategrey', 'snow', 'springgreen', 'steelblue', 'tan', 'thistle', 'tomato', 'turquoise', 'violet', 'wheat', 'whitesmoke', 'yellowgreen', 'rebeccapurple'];
|
|
2
|
-
var legacyColors = ['R50', 'R75', 'R100', 'R200', 'R300', 'R400', 'R500', 'Y50', 'Y75', 'Y100', 'Y200', 'Y300', 'Y400', 'Y500', 'G50', 'G75', 'G100', 'G200', 'G300', 'G400', 'G500', 'B50', 'B75', 'B100', 'B200', 'B300', 'B400', 'B500', 'P50', 'P75', 'P100', 'P200', 'P300', 'P400', 'P500', 'T50', 'T75', 'T100', 'T200', 'T300', 'T400', 'T500', 'N0', 'N10', 'N20', 'N30', 'N40', 'N50', 'N60', 'N70', 'N80', 'N90', 'N100', 'N200', 'N300', 'N400', 'N500', 'N600', 'N700', 'N800', 'N900', 'N10A', 'N20A', 'N30A', 'N40A', 'N50A', 'N60A', 'N70A', 'N80A', 'N90A', 'N100A', 'N200A', 'N300A', 'N400A', 'N500A', 'N600A', 'N700A', 'N800A', 'DN900', 'DN800', 'DN700', 'DN600', 'DN500', 'DN400', 'DN300', 'DN200', 'DN100', 'DN90', 'DN80', 'DN70', 'DN60', 'DN50', 'DN40', 'DN30', 'DN20', 'DN10', 'DN0', 'DN800A', 'DN700A', 'DN600A', 'DN500A', 'DN400A', 'DN300A', 'DN200A', 'DN100A', 'DN90A', 'DN80A', 'DN70A', 'DN60A', 'DN50A', 'DN40A', 'DN30A', 'DN20A', 'DN10A'
|
|
3
|
-
|
|
1
|
+
var namedColors = new Set(['black', 'silver', 'gray', 'white', 'maroon', 'red', 'purple', 'fuchsia', 'green', 'lime', 'olive', 'yellow', 'navy', 'blue', 'teal', 'aqua', 'orange', 'aliceblue', 'antiquewhite', 'aquamarine', 'azure', 'beige', 'bisque', 'blanchedalmond', 'blueviolet', 'brown', 'burlywood', 'cadetblue', 'chartreuse', 'chocolate', 'coral', 'cornflowerblue', 'cornsilk', 'crimson', 'cyan', 'darkblue', 'darkcyan', 'darkgoldenrod', 'darkgray', 'darkgreen', 'darkgrey', 'darkkhaki', 'darkmagenta', 'darkolivegreen', 'darkorange', 'darkorchid', 'darkred', 'darksalmon', 'darkseagreen', 'darkslateblue', 'darkslategray', 'darkslategrey', 'darkturquoise', 'darkviolet', 'deeppink', 'deepskyblue', 'dimgray', 'dimgrey', 'dodgerblue', 'firebrick', 'floralwhite', 'forestgreen', 'gainsboro', 'ghostwhite', 'gold', 'goldenrod', 'greenyellow', 'grey', 'honeydew', 'hotpink', 'indianred', 'indigo', 'ivory', 'khaki', 'lavender', 'lavenderblush', 'lawngreen', 'lemonchiffon', 'lightblue', 'lightcoral', 'lightcyan', 'lightgoldenrodyellow', 'lightgray', 'lightgreen', 'lightgrey', 'lightpink', 'lightsalmon', 'lightseagreen', 'lightskyblue', 'lightslategray', 'lightslategrey', 'lightsteelblue', 'lightyellow', 'limegreen', 'linen', 'magenta', 'mediumaquamarine', 'mediumblue', 'mediumorchid', 'mediumpurple', 'mediumseagreen', 'mediumslateblue', 'mediumspringgreen', 'mediumturquoise', 'mediumvioletred', 'midnightblue', 'mintcream', 'mistyrose', 'moccasin', 'navajowhite', 'oldlace', 'olivedrab', 'orangered', 'orchid', 'palegoldenrod', 'palegreen', 'paleturquoise', 'palevioletred', 'papayawhip', 'peachpuff', 'peru', 'pink', 'plum', 'powderblue', 'rosybrown', 'royalblue', 'saddlebrown', 'salmon', 'sandybrown', 'seagreen', 'seashell', 'sienna', 'skyblue', 'slateblue', 'slategray', 'slategrey', 'snow', 'springgreen', 'steelblue', 'tan', 'thistle', 'tomato', 'turquoise', 'violet', 'wheat', 'whitesmoke', 'yellowgreen', 'rebeccapurple']);
|
|
2
|
+
var legacyColors = new Set(['R50', 'R75', 'R100', 'R200', 'R300', 'R400', 'R500', 'Y50', 'Y75', 'Y100', 'Y200', 'Y300', 'Y400', 'Y500', 'G50', 'G75', 'G100', 'G200', 'G300', 'G400', 'G500', 'B50', 'B75', 'B100', 'B200', 'B300', 'B400', 'B500', 'P50', 'P75', 'P100', 'P200', 'P300', 'P400', 'P500', 'T50', 'T75', 'T100', 'T200', 'T300', 'T400', 'T500', 'N0', 'N10', 'N20', 'N30', 'N40', 'N50', 'N60', 'N70', 'N80', 'N90', 'N100', 'N200', 'N300', 'N400', 'N500', 'N600', 'N700', 'N800', 'N900', 'N10A', 'N20A', 'N30A', 'N40A', 'N50A', 'N60A', 'N70A', 'N80A', 'N90A', 'N100A', 'N200A', 'N300A', 'N400A', 'N500A', 'N600A', 'N700A', 'N800A', 'DN900', 'DN800', 'DN700', 'DN600', 'DN500', 'DN400', 'DN300', 'DN200', 'DN100', 'DN90', 'DN80', 'DN70', 'DN60', 'DN50', 'DN40', 'DN30', 'DN20', 'DN10', 'DN0', 'DN800A', 'DN700A', 'DN600A', 'DN500A', 'DN400A', 'DN300A', 'DN200A', 'DN100A', 'DN90A', 'DN80A', 'DN70A', 'DN60A', 'DN50A', 'DN40A', 'DN30A', 'DN20A', 'DN10A', // Legacy Trello colors:
|
|
3
|
+
'AtlassianBlue50', 'AtlassianBlue200', 'AtlassianBlue300', 'AtlassianBlue400', 'TrelloBlue25', 'TrelloBlue50', 'TrelloBlue100', 'TrelloBlue200', 'TrelloBlue300', 'TrelloBlue400', 'TrelloBlue500', 'TrelloBlue600', 'TrelloBlue700', 'TrelloBlue800', 'TrelloBlue900', 'Green50', 'Green100', 'Green200', 'Green300', 'Green400', 'Green500', 'Green600', 'Green700', 'Green800', 'Green900', 'Orange50', 'Orange100', 'Orange200', 'Orange300', 'Orange400', 'Orange500', 'Orange600', 'Orange700', 'Orange800', 'Orange900', 'Red50', 'Red100', 'Red200', 'Red300', 'Red400', 'Red500', 'Red600', 'Red700', 'Red800', 'Red900', 'Yellow50', 'Yellow100', 'Yellow200', 'Yellow300', 'Yellow400', 'Yellow500', 'Yellow600', 'Yellow700', 'Yellow800', 'Yellow900', 'Purple50', 'Purple100', 'Purple200', 'Purple300', 'Purple400', 'Purple500', 'Purple600', 'Purple700', 'Purple800', 'Purple900', 'VioletMbgAlert', 'Pink50', 'Pink100', 'Pink200', 'Pink300', 'Pink400', 'Pink500', 'Pink600', 'Pink700', 'Pink800', 'Pink900', 'Sky25', 'Sky50', 'Sky100', 'Sky200', 'Sky300', 'Sky400', 'Sky500', 'Sky600', 'Sky700', 'Sky800', 'Sky900', 'Lime50', 'Lime100', 'Lime200', 'Lime300', 'Lime400', 'Lime500', 'Lime600', 'Lime700', 'Lime800', 'Lime900', 'BusinessBlue50', 'BusinessBlue100', 'BusinessBlue200', 'BusinessBlue300', 'BusinessBlue400', 'BusinessBlue500', 'BusinessBlue600', 'BusinessBlue700', 'BusinessBlue800', 'BusinessBlue900', 'Opacity1', 'Opacity2', 'Opacity3', 'Opacity4', 'Opacity5', 'Opacity6', 'Opacity7', 'Opacity8', 'Opacity9', 'OpacityDark1', 'OpacityDark2', 'OpacityDark3', 'OpacityDark4', 'OpacityDark5', 'OpacityDark6', 'OpacityDark7', 'OpacityDark8', 'OpacityDark9', 'Black']);
|
|
4
|
+
var legacyColorMixins = new Set(['background', 'backgroundActive', 'backgroundHover', 'backgroundOnLayer', 'text', 'textHover', 'textActive', 'subtleText', 'placeholderText', 'heading', 'subtleHeading', 'codeBlock', 'link', 'linkHover', 'linkActive', 'linkOutline', 'primary', 'blue', 'teal', 'purple', 'red', 'yellow', 'green', 'skeleton']);
|
|
4
5
|
|
|
5
6
|
var includesWholeWord = function includesWholeWord(value, options) {
|
|
6
7
|
var values = value.replace(/[^a-zA-Z ]/g, ' ').trim().split(/(?:,|\.| )+/);
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
if (values.includes(el)) {
|
|
10
|
-
result = true;
|
|
11
|
-
}
|
|
8
|
+
return values.some(function (value) {
|
|
9
|
+
return options.has(value);
|
|
12
10
|
});
|
|
13
|
-
return result;
|
|
14
11
|
};
|
|
15
12
|
|
|
16
13
|
export var isLegacyColor = function isLegacyColor(value) {
|
|
17
|
-
return legacyColors.
|
|
14
|
+
return legacyColors.has(value);
|
|
18
15
|
};
|
|
19
16
|
export var isLegacyNamedColor = function isLegacyNamedColor(value) {
|
|
20
|
-
return legacyColorMixins.
|
|
17
|
+
return legacyColorMixins.has(value);
|
|
21
18
|
};
|
|
22
19
|
export var includesHardCodedColor = function includesHardCodedColor(raw) {
|
|
23
20
|
var value = raw.toLowerCase();
|
|
@@ -23,6 +23,21 @@ export var isDecendantOfType = function isDecendantOfType(node, type) {
|
|
|
23
23
|
|
|
24
24
|
return false;
|
|
25
25
|
};
|
|
26
|
+
export var isPropertyKey = function isPropertyKey(node) {
|
|
27
|
+
if (isNodeOfType(node, 'Identifier') && isDecendantOfType(node, 'Property')) {
|
|
28
|
+
var parent = node.parent;
|
|
29
|
+
return node === parent.key || parent.shorthand;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return false;
|
|
33
|
+
};
|
|
34
|
+
export var isVariableName = function isVariableName(node) {
|
|
35
|
+
if (isNodeOfType(node, 'Identifier') && isDecendantOfType(node, 'VariableDeclarator')) {
|
|
36
|
+
return node === node.parent.id;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return false;
|
|
40
|
+
};
|
|
26
41
|
export var isDecendantOfStyleJsxAttribute = function isDecendantOfStyleJsxAttribute(node) {
|
|
27
42
|
// @ts-ignore
|
|
28
43
|
if (node.type === 'JSXAttribute') {
|
package/dist/esm/version.json
CHANGED
|
@@ -2,6 +2,8 @@ import type { Rule } from 'eslint';
|
|
|
2
2
|
import { CallExpression, Expression, TaggedTemplateExpression } from 'eslint-codemod-utils';
|
|
3
3
|
export declare const isDecendantOfGlobalToken: (node: Rule.Node) => boolean;
|
|
4
4
|
export declare const isDecendantOfType: (node: Rule.Node, type: Rule.Node['type'], skipNode?: boolean) => boolean;
|
|
5
|
+
export declare const isPropertyKey: (node: Rule.Node) => boolean;
|
|
6
|
+
export declare const isVariableName: (node: Rule.Node) => boolean;
|
|
5
7
|
export declare const isDecendantOfStyleJsxAttribute: (node: Rule.Node) => boolean;
|
|
6
8
|
export declare const isStyledTemplateNode: (node?: Expression | null | undefined) => node is TaggedTemplateExpression;
|
|
7
9
|
export declare const isStyledObjectNode: (node?: Expression | null | undefined) => node is CallExpression;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/eslint-plugin-design-system",
|
|
3
3
|
"description": "The essential plugin for use with the Atlassian Design System.",
|
|
4
|
-
"version": "4.
|
|
4
|
+
"version": "4.10.0",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -35,12 +35,12 @@
|
|
|
35
35
|
"@atlaskit/theme": "^12.0.2",
|
|
36
36
|
"@atlassian/atlassian-frontend-prettier-config-1.0.1": "npm:@atlassian/atlassian-frontend-prettier-config@1.0.1",
|
|
37
37
|
"@emotion/core": "^10.0.9",
|
|
38
|
-
"@emotion/styled": "^
|
|
38
|
+
"@emotion/styled": "^11.0.0",
|
|
39
39
|
"eslint": "^7.7.0",
|
|
40
40
|
"react": "^16.8.0",
|
|
41
41
|
"ts-node": "^10.0.0",
|
|
42
42
|
"tsconfig-paths": "^3.9.0",
|
|
43
|
-
"typescript": "4.
|
|
43
|
+
"typescript": "4.3.5"
|
|
44
44
|
},
|
|
45
45
|
"techstack": {
|
|
46
46
|
"@atlassian/frontend": {
|