@atlaskit/eslint-plugin-design-system 8.4.2 → 8.4.4
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 +13 -0
- package/dist/cjs/rules/ensure-design-token-usage/index.js +19 -18
- package/dist/cjs/rules/ensure-design-token-usage/spacing.js +21 -21
- package/dist/cjs/rules/ensure-design-token-usage/{spacing-utils.js → utils.js} +1 -1
- package/dist/cjs/rules/ensure-design-token-usage-preview/index.js +2 -2
- package/dist/cjs/rules/prefer-primitives/index.js +2 -2
- package/dist/cjs/rules/use-primitives/utils.js +4 -5
- package/dist/cjs/rules/utils/is-color.js +7 -2
- package/dist/es2019/rules/ensure-design-token-usage/index.js +4 -3
- package/dist/es2019/rules/ensure-design-token-usage/spacing.js +1 -1
- package/dist/es2019/rules/ensure-design-token-usage/{spacing-utils.js → utils.js} +2 -2
- package/dist/es2019/rules/prefer-primitives/index.js +2 -2
- package/dist/es2019/rules/use-primitives/utils.js +2 -3
- package/dist/es2019/rules/utils/is-color.js +3 -1
- package/dist/esm/rules/ensure-design-token-usage/index.js +4 -3
- package/dist/esm/rules/ensure-design-token-usage/spacing.js +3 -3
- package/dist/esm/rules/ensure-design-token-usage/{spacing-utils.js → utils.js} +2 -2
- package/dist/esm/rules/ensure-design-token-usage-preview/index.js +2 -2
- package/dist/esm/rules/prefer-primitives/index.js +2 -2
- package/dist/esm/rules/use-primitives/utils.js +4 -5
- package/dist/esm/rules/utils/is-color.js +4 -0
- package/dist/types/rules/use-primitives/utils.d.ts +1 -1
- package/dist/types/rules/utils/is-color.d.ts +1 -0
- package/dist/types-ts4.5/rules/use-primitives/utils.d.ts +1 -1
- package/dist/types-ts4.5/rules/utils/is-color.d.ts +1 -0
- package/package.json +1 -1
- /package/dist/types/rules/ensure-design-token-usage/{spacing-utils.d.ts → utils.d.ts} +0 -0
- /package/dist/types-ts4.5/rules/ensure-design-token-usage/{spacing-utils.d.ts → utils.d.ts} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @atlaskit/eslint-plugin-design-system
|
|
2
2
|
|
|
3
|
+
## 8.4.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`f7a807adba2`](https://bitbucket.org/atlassian/atlassian-frontend/commits/f7a807adba2) - Update the `ensure-design-token-usage` rule to disallow setting the 'current surface' CSS variable (--ds-elevation-surface-current) to a hardcoded color.
|
|
8
|
+
- Updated dependencies
|
|
9
|
+
|
|
10
|
+
## 8.4.3
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- [`96e35ec4b9d`](https://bitbucket.org/atlassian/atlassian-frontend/commits/96e35ec4b9d) - Tweak `use-primitives` and `prefer-primitives` logic to stop false positives for component names that contain HTML element names.
|
|
15
|
+
|
|
3
16
|
## 8.4.2
|
|
4
17
|
|
|
5
18
|
### Patch Changes
|
|
@@ -13,7 +13,7 @@ var _isNode = require("../utils/is-node");
|
|
|
13
13
|
var _color = require("./color");
|
|
14
14
|
var _ruleMeta = _interopRequireDefault(require("./rule-meta"));
|
|
15
15
|
var _spacing = require("./spacing");
|
|
16
|
-
var
|
|
16
|
+
var _utils = require("./utils");
|
|
17
17
|
var defaultConfig = {
|
|
18
18
|
domains: ['color', 'spacing'],
|
|
19
19
|
applyImport: true,
|
|
@@ -69,12 +69,13 @@ var createWithConfig = function createWithConfig(initialConfig) {
|
|
|
69
69
|
if ((0, _eslintCodemodUtils.isNodeOfType)(node.value, 'ObjectExpression')) {
|
|
70
70
|
return node.value.properties.forEach(findObjectStyles);
|
|
71
71
|
}
|
|
72
|
-
if (!(0, _eslintCodemodUtils.isNodeOfType)(node.key, 'Identifier')) {
|
|
72
|
+
if (!(0, _eslintCodemodUtils.isNodeOfType)(node.key, 'Identifier') && !(0, _eslintCodemodUtils.isNodeOfType)(node.key, 'Literal')) {
|
|
73
73
|
return;
|
|
74
74
|
}
|
|
75
|
+
var propertyName = (0, _eslintCodemodUtils.isNodeOfType)(node.key, 'Identifier') ? node.key.name : String(node.key.value);
|
|
75
76
|
|
|
76
77
|
// Returns which domains to lint against based on rule's config and current property
|
|
77
|
-
var domains = (0,
|
|
78
|
+
var domains = (0, _utils.getDomainsForProperty)(propertyName, config.domains);
|
|
78
79
|
if (domains.length === 0 || (0, _isNode.isDecendantOfGlobalToken)(node.value)) {
|
|
79
80
|
return;
|
|
80
81
|
}
|
|
@@ -88,7 +89,7 @@ var createWithConfig = function createWithConfig(initialConfig) {
|
|
|
88
89
|
/**
|
|
89
90
|
* We do this in case the fontSize for a style object is declared alongside the `em` or `lineHeight` declaration
|
|
90
91
|
*/
|
|
91
|
-
var fontSize = (0,
|
|
92
|
+
var fontSize = (0, _utils.getFontSizeFromNode)(parentNode, context);
|
|
92
93
|
return (0, _spacing.lintObjectForSpacing)(node, context, config, fontSize, tokenNode);
|
|
93
94
|
}
|
|
94
95
|
}
|
|
@@ -102,12 +103,12 @@ var createWithConfig = function createWithConfig(initialConfig) {
|
|
|
102
103
|
if (!(0, _eslintCodemodUtils.isNodeOfType)(node, 'TaggedTemplateExpression')) {
|
|
103
104
|
return;
|
|
104
105
|
}
|
|
105
|
-
var processedCssLines = (0,
|
|
106
|
+
var processedCssLines = (0, _utils.processCssNode)(node, context);
|
|
106
107
|
if (!processedCssLines) {
|
|
107
108
|
// if we can't get a processed css we bail
|
|
108
109
|
return;
|
|
109
110
|
}
|
|
110
|
-
var globalFontSize = (0,
|
|
111
|
+
var globalFontSize = (0, _utils.getFontSizeValueInScope)(processedCssLines);
|
|
111
112
|
var textForSource = context.getSourceCode().getText(node.quasi);
|
|
112
113
|
var allReplacedValues = [];
|
|
113
114
|
var completeSource = processedCssLines.reduce(function (currentSource, _ref) {
|
|
@@ -122,16 +123,16 @@ var createWithConfig = function createWithConfig(initialConfig) {
|
|
|
122
123
|
_originalCssLine$spli2 = (0, _slicedToArray2.default)(_originalCssLine$spli, 2),
|
|
123
124
|
_ = _originalCssLine$spli2[0],
|
|
124
125
|
originalCssValues = _originalCssLine$spli2[1];
|
|
125
|
-
var propertyName = (0,
|
|
126
|
+
var propertyName = (0, _utils.convertHyphenatedNameToCamelCase)(originalProperty);
|
|
126
127
|
var isFontFamily = /fontFamily/.test(propertyName);
|
|
127
128
|
var replacedValuesPerProperty = [originalProperty];
|
|
128
|
-
var domains = (0,
|
|
129
|
+
var domains = (0, _utils.getDomainsForProperty)(propertyName, config.domains);
|
|
129
130
|
if (domains.length === 0 || !resolvedCssValues) {
|
|
130
131
|
// in both of these cases no changes should be made to the current property
|
|
131
132
|
return currentSource;
|
|
132
133
|
}
|
|
133
134
|
if (domains.includes('color')) {
|
|
134
|
-
if ((0,
|
|
135
|
+
if ((0, _utils.includesTokenString)(resolvedCssValues.trim())) {
|
|
135
136
|
return currentSource;
|
|
136
137
|
}
|
|
137
138
|
if ((0, _isColor.includesHardCodedColor)(resolvedCssValues)) {
|
|
@@ -143,16 +144,16 @@ var createWithConfig = function createWithConfig(initialConfig) {
|
|
|
143
144
|
}
|
|
144
145
|
}
|
|
145
146
|
if (domains.includes('spacing') || domains.includes('typography') || domains.includes('shape')) {
|
|
146
|
-
if (!(0,
|
|
147
|
+
if (!(0, _utils.isValidSpacingValue)(resolvedCssValues, globalFontSize)) {
|
|
147
148
|
// no changes should be made to the current property
|
|
148
149
|
return currentSource;
|
|
149
150
|
}
|
|
150
151
|
|
|
151
152
|
// gets the values from the associated property, numeric values or NaN
|
|
152
|
-
var processedNumericValues = (0,
|
|
153
|
-
var processedValues = (0,
|
|
153
|
+
var processedNumericValues = (0, _utils.getValueFromShorthand)(resolvedCssValues);
|
|
154
|
+
var processedValues = (0, _utils.splitShorthandValues)(resolvedCssValues);
|
|
154
155
|
// only splits shorthand values but it does not transform NaNs so tokens are preserved
|
|
155
|
-
var originalValues = (0,
|
|
156
|
+
var originalValues = (0, _utils.splitShorthandValues)(originalCssValues);
|
|
156
157
|
|
|
157
158
|
// reconstructing the string
|
|
158
159
|
// should replace what it can and preserve the raw value for everything else
|
|
@@ -162,7 +163,7 @@ var createWithConfig = function createWithConfig(initialConfig) {
|
|
|
162
163
|
.map(function (value, index) {
|
|
163
164
|
return [
|
|
164
165
|
// if emToPX conversion fails we'll default to original value
|
|
165
|
-
(0,
|
|
166
|
+
(0, _utils.emToPixels)(value, globalFontSize) || value, processedValues[index], originalValues[index]];
|
|
166
167
|
}).map(function (_ref3) {
|
|
167
168
|
var _ref4 = (0, _slicedToArray2.default)(_ref3, 3),
|
|
168
169
|
numericOrNanValue = _ref4[0],
|
|
@@ -171,13 +172,13 @@ var createWithConfig = function createWithConfig(initialConfig) {
|
|
|
171
172
|
if (!originalValue) {
|
|
172
173
|
return originalValue;
|
|
173
174
|
}
|
|
174
|
-
if ((0,
|
|
175
|
+
if ((0, _utils.isTokenValueString)(originalValue)) {
|
|
175
176
|
// if the value is already valid, nothing to report or replace
|
|
176
177
|
return originalValue;
|
|
177
178
|
}
|
|
178
179
|
|
|
179
180
|
// do not replace 0 or auto with tokens
|
|
180
|
-
if ((0,
|
|
181
|
+
if ((0, _utils.isZero)(pxValue) || (0, _utils.isAuto)(pxValue)) {
|
|
181
182
|
return originalValue;
|
|
182
183
|
}
|
|
183
184
|
if (isNaN(numericOrNanValue) && !isFontFamily) {
|
|
@@ -195,7 +196,7 @@ var createWithConfig = function createWithConfig(initialConfig) {
|
|
|
195
196
|
});
|
|
196
197
|
|
|
197
198
|
// from here on we know value is numeric or a font family, so it might or might not have a token equivalent
|
|
198
|
-
var replacementNode = (0,
|
|
199
|
+
var replacementNode = (0, _utils.getTokenReplacement)(propertyName, numericOrNanValue);
|
|
199
200
|
if (!replacementNode) {
|
|
200
201
|
return originalValue;
|
|
201
202
|
}
|
|
@@ -225,7 +226,7 @@ var createWithConfig = function createWithConfig(initialConfig) {
|
|
|
225
226
|
node: node,
|
|
226
227
|
messageId: 'autofixesPossible',
|
|
227
228
|
fix: function fix(fixer) {
|
|
228
|
-
return (!tokenNode && config.applyImport ? [(0,
|
|
229
|
+
return (!tokenNode && config.applyImport ? [(0, _utils.insertTokensImport)(fixer)] : []).concat([fixer.replaceText(node.quasi, completeSource)]);
|
|
229
230
|
}
|
|
230
231
|
});
|
|
231
232
|
}
|
|
@@ -8,11 +8,11 @@ exports.lintObjectForSpacing = void 0;
|
|
|
8
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
9
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
10
10
|
var _eslintCodemodUtils = require("eslint-codemod-utils");
|
|
11
|
-
var
|
|
12
|
-
function ownKeys(
|
|
13
|
-
function _objectSpread(
|
|
11
|
+
var _utils = require("./utils");
|
|
12
|
+
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; }
|
|
13
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
14
14
|
var lintObjectForSpacing = function lintObjectForSpacing(node, context, ruleConfig, fontSize, tokenNode) {
|
|
15
|
-
if ((0, _eslintCodemodUtils.isNodeOfType)(node.value, 'Literal') && !(0,
|
|
15
|
+
if ((0, _eslintCodemodUtils.isNodeOfType)(node.value, 'Literal') && !(0, _utils.isValidSpacingValue)(node.value.value, fontSize)) {
|
|
16
16
|
context.report({
|
|
17
17
|
node: node,
|
|
18
18
|
messageId: 'noRawSpacingValues',
|
|
@@ -24,12 +24,12 @@ var lintObjectForSpacing = function lintObjectForSpacing(node, context, ruleConf
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
// Don't report on CSS calc function
|
|
27
|
-
if ((0, _eslintCodemodUtils.isNodeOfType)(node.value, 'Literal') && (0,
|
|
27
|
+
if ((0, _eslintCodemodUtils.isNodeOfType)(node.value, 'Literal') && (0, _utils.isCalc)(node.value.value)) {
|
|
28
28
|
return;
|
|
29
29
|
}
|
|
30
30
|
var propertyName = node.key.name;
|
|
31
31
|
var isFontFamily = /fontFamily/.test(propertyName);
|
|
32
|
-
var value = (0,
|
|
32
|
+
var value = (0, _utils.getValue)(node.value, context);
|
|
33
33
|
|
|
34
34
|
// Value is a token string (e.g. set via a variable)
|
|
35
35
|
if (typeof value === 'string' && /\${token\(.*\)}/.test(value)) {
|
|
@@ -37,7 +37,7 @@ var lintObjectForSpacing = function lintObjectForSpacing(node, context, ruleConf
|
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
// value is either NaN or it can't be resolved (e.g. em, 100% etc...)
|
|
40
|
-
if (!(value && (0,
|
|
40
|
+
if (!(value && (0, _utils.isValidSpacingValue)(value, fontSize))) {
|
|
41
41
|
return context.report({
|
|
42
42
|
node: node,
|
|
43
43
|
messageId: 'noRawSpacingValues',
|
|
@@ -57,10 +57,10 @@ var lintObjectForSpacing = function lintObjectForSpacing(node, context, ruleConf
|
|
|
57
57
|
_value = _valuesForProperty[0];
|
|
58
58
|
|
|
59
59
|
// Do not report or suggest a token to replace 0 or auto
|
|
60
|
-
if ((0,
|
|
60
|
+
if ((0, _utils.isZero)(_value) || (0, _utils.isAuto)(_value)) {
|
|
61
61
|
return;
|
|
62
62
|
}
|
|
63
|
-
var pixelValue = isFontFamily ? _value : (0,
|
|
63
|
+
var pixelValue = isFontFamily ? _value : (0, _utils.emToPixels)(_value, fontSize);
|
|
64
64
|
return context.report({
|
|
65
65
|
node: node,
|
|
66
66
|
messageId: 'noRawSpacingValues',
|
|
@@ -68,11 +68,11 @@ var lintObjectForSpacing = function lintObjectForSpacing(node, context, ruleConf
|
|
|
68
68
|
payload: "".concat(propertyName, ":").concat(pixelValue)
|
|
69
69
|
},
|
|
70
70
|
fix: function fix(fixer) {
|
|
71
|
-
var replacementNode = (0,
|
|
71
|
+
var replacementNode = (0, _utils.getTokenReplacement)(propertyName, pixelValue);
|
|
72
72
|
if (!replacementNode) {
|
|
73
73
|
return null;
|
|
74
74
|
}
|
|
75
|
-
return (!tokenNode && ruleConfig.applyImport ? [(0,
|
|
75
|
+
return (!tokenNode && ruleConfig.applyImport ? [(0, _utils.insertTokensImport)(fixer)] : []).concat([fixer.replaceText(node, (0, _eslintCodemodUtils.property)(_objectSpread(_objectSpread({}, node), {}, {
|
|
76
76
|
value: replacementNode
|
|
77
77
|
})).toString())]);
|
|
78
78
|
}
|
|
@@ -87,10 +87,10 @@ var lintObjectForSpacing = function lintObjectForSpacing(node, context, ruleConf
|
|
|
87
87
|
* { padding: '8px 0px' }
|
|
88
88
|
*/
|
|
89
89
|
valuesForProperty.forEach(function (val) {
|
|
90
|
-
var pixelValue = (0,
|
|
90
|
+
var pixelValue = (0, _utils.emToPixels)(val, fontSize);
|
|
91
91
|
|
|
92
92
|
// Do not report or suggest a token to replace 0 or auto
|
|
93
|
-
if ((0,
|
|
93
|
+
if ((0, _utils.isZero)(val) || (0, _utils.isAuto)(val)) {
|
|
94
94
|
return;
|
|
95
95
|
}
|
|
96
96
|
context.report({
|
|
@@ -101,13 +101,13 @@ var lintObjectForSpacing = function lintObjectForSpacing(node, context, ruleConf
|
|
|
101
101
|
},
|
|
102
102
|
fix: function fix(fixer) {
|
|
103
103
|
var allResolvableValues = valuesForProperty.every(function (value) {
|
|
104
|
-
return !Number.isNaN((0,
|
|
104
|
+
return !Number.isNaN((0, _utils.emToPixels)(value, fontSize));
|
|
105
105
|
});
|
|
106
106
|
if (!allResolvableValues) {
|
|
107
107
|
return null;
|
|
108
108
|
}
|
|
109
109
|
var valuesWithTokenReplacement = valuesForProperty.filter(function (value) {
|
|
110
|
-
return (0,
|
|
110
|
+
return (0, _utils.findTokenNameByPropertyValue)(propertyName, value);
|
|
111
111
|
}).filter(function (value) {
|
|
112
112
|
return value !== 0;
|
|
113
113
|
});
|
|
@@ -116,7 +116,7 @@ var lintObjectForSpacing = function lintObjectForSpacing(node, context, ruleConf
|
|
|
116
116
|
// if none of the values have token replacement we bail
|
|
117
117
|
return null;
|
|
118
118
|
}
|
|
119
|
-
var originalCssString = (0,
|
|
119
|
+
var originalCssString = (0, _utils.getRawExpression)(node.value, context);
|
|
120
120
|
if (!originalCssString) {
|
|
121
121
|
return null;
|
|
122
122
|
}
|
|
@@ -126,20 +126,20 @@ var lintObjectForSpacing = function lintObjectForSpacing(node, context, ruleConf
|
|
|
126
126
|
* we'll need to remove all quote chars since `getRawExpression` will return those as part of the string
|
|
127
127
|
* given they're part of the substring of the current node
|
|
128
128
|
*/
|
|
129
|
-
var originalValues = (0,
|
|
129
|
+
var originalValues = (0, _utils.splitShorthandValues)(originalCssString.replace(/`|'|"/g, ''));
|
|
130
130
|
if (originalValues.length !== valuesForProperty.length) {
|
|
131
131
|
// we bail just in case original values don't correspond to the replaced values
|
|
132
132
|
return null;
|
|
133
133
|
}
|
|
134
|
-
return (!tokenNode && ruleConfig.applyImport ? [(0,
|
|
135
|
-
if ((0,
|
|
134
|
+
return (!tokenNode && ruleConfig.applyImport ? [(0, _utils.insertTokensImport)(fixer)] : []).concat([fixer.replaceText(node.value, "`".concat(valuesForProperty.map(function (value, index) {
|
|
135
|
+
if ((0, _utils.isZero)(value)) {
|
|
136
136
|
return originalValues[index];
|
|
137
137
|
}
|
|
138
|
-
var pixelValue = (0,
|
|
138
|
+
var pixelValue = (0, _utils.emToPixels)(value, fontSize);
|
|
139
139
|
var pixelValueString = "".concat(pixelValue, "px");
|
|
140
140
|
// if there is a token we take it, otherwise we go with the original value
|
|
141
141
|
|
|
142
|
-
return (0,
|
|
142
|
+
return (0, _utils.findTokenNameByPropertyValue)(propertyName, value) ? "${".concat((0, _utils.getTokenNodeForValue)(propertyName, pixelValueString), "}") : originalValues[index];
|
|
143
143
|
}).join(' '), "`"))]);
|
|
144
144
|
}
|
|
145
145
|
});
|
|
@@ -351,7 +351,7 @@ var findParentNodeForLine = function findParentNodeForLine(node) {
|
|
|
351
351
|
exports.findParentNodeForLine = findParentNodeForLine;
|
|
352
352
|
function getDomainsForProperty(propertyName, targetOptions) {
|
|
353
353
|
var domains = [];
|
|
354
|
-
if ((0, _isColor.isColorCssPropertyName)(propertyName) && targetOptions.includes('color')) {
|
|
354
|
+
if (((0, _isColor.isColorCssPropertyName)(propertyName) || (0, _isColor.isCurrentSurfaceCustomPropertyName)(propertyName)) && targetOptions.includes('color')) {
|
|
355
355
|
domains.push('color');
|
|
356
356
|
}
|
|
357
357
|
if (isSpacingProperty(propertyName) && targetOptions.includes('spacing')) {
|
|
@@ -9,8 +9,8 @@ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/de
|
|
|
9
9
|
var _ensureDesignTokenUsage = require("../ensure-design-token-usage");
|
|
10
10
|
var _ruleMeta = _interopRequireDefault(require("../ensure-design-token-usage/rule-meta"));
|
|
11
11
|
var _createRule = require("../utils/create-rule");
|
|
12
|
-
function ownKeys(
|
|
13
|
-
function _objectSpread(
|
|
12
|
+
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; }
|
|
13
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
14
14
|
var defaultConfig = {
|
|
15
15
|
domains: ['spacing'],
|
|
16
16
|
applyImport: true,
|
|
@@ -53,7 +53,7 @@ var rule = (0, _createRule.createLintRule)({
|
|
|
53
53
|
|
|
54
54
|
// styled.div``
|
|
55
55
|
if ((0, _eslintCodemodUtils.isNodeOfType)(node.property, 'Identifier')) {
|
|
56
|
-
if (_utils.validPrimitiveElements.
|
|
56
|
+
if (_utils.validPrimitiveElements.has(node.property.name)) {
|
|
57
57
|
var styledIdentifier = node.object.name;
|
|
58
58
|
var elementName = node.property.name;
|
|
59
59
|
|
|
@@ -80,7 +80,7 @@ var rule = (0, _createRule.createLintRule)({
|
|
|
80
80
|
if ((0, _eslintCodemodUtils.isNodeOfType)(node.arguments[0], 'Literal')) {
|
|
81
81
|
var argValue = node.arguments[0].raw;
|
|
82
82
|
if (typeof argValue === 'string') {
|
|
83
|
-
var suggest = _utils.validPrimitiveElements.
|
|
83
|
+
var suggest = _utils.validPrimitiveElements.has(argValue.replaceAll("'", '') // argValue will have '' around the element name, strip it out for this test
|
|
84
84
|
);
|
|
85
85
|
|
|
86
86
|
if (suggest) {
|
|
@@ -7,8 +7,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
exports.validPrimitiveElements = exports.shouldSuggestText = exports.shouldSuggestStack = exports.shouldSuggestInline = exports.shouldSuggestBox = exports.primitiveFixer = exports.isWhiteSpace = exports.isValidPrimitiveElement = exports.getChildrenByType = void 0;
|
|
8
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
9
|
var _eslintCodemodUtils = require("eslint-codemod-utils");
|
|
10
|
-
function ownKeys(
|
|
11
|
-
function _objectSpread(
|
|
10
|
+
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; }
|
|
11
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
12
12
|
var shouldSuggestBox = function shouldSuggestBox(node
|
|
13
13
|
// scope: Scope.Scope,
|
|
14
14
|
) {
|
|
@@ -322,11 +322,10 @@ var getCSSPropStyleObject = function getCSSPropStyleObject(node, context) {
|
|
|
322
322
|
}
|
|
323
323
|
return styleObj;
|
|
324
324
|
};
|
|
325
|
-
var validPrimitiveElements =
|
|
325
|
+
var validPrimitiveElements = new Set(['div', 'span', 'article', 'aside', 'dialog', 'footer', 'header', 'li', 'main', 'nav', 'ol', 'section', 'ul']);
|
|
326
326
|
exports.validPrimitiveElements = validPrimitiveElements;
|
|
327
327
|
var isValidPrimitiveElement = function isValidPrimitiveElement(node) {
|
|
328
|
-
|
|
329
|
-
return validPrimitiveElements.test(node.openingElement.name.name);
|
|
328
|
+
return validPrimitiveElements.has(node.openingElement.name.name.toLowerCase());
|
|
330
329
|
};
|
|
331
330
|
exports.isValidPrimitiveElement = isValidPrimitiveElement;
|
|
332
331
|
var hasInlineCompatibleStyles = function hasInlineCompatibleStyles(cssStyleObject) {
|
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.isLegacyNamedColor = exports.isLegacyColor = exports.isHardCodedColor = exports.isColorCssPropertyName = exports.includesHardCodedColor = void 0;
|
|
6
|
+
exports.isLegacyNamedColor = exports.isLegacyColor = exports.isHardCodedColor = exports.isCurrentSurfaceCustomPropertyName = exports.isColorCssPropertyName = exports.includesHardCodedColor = void 0;
|
|
7
|
+
var _tokens = require("@atlaskit/tokens");
|
|
7
8
|
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
9
|
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',
|
|
9
10
|
// Legacy Trello colors:
|
|
@@ -58,4 +59,8 @@ var kebabize = function kebabize(str) {
|
|
|
58
59
|
var isColorCssPropertyName = function isColorCssPropertyName(value) {
|
|
59
60
|
return validColorPropertyNames.has(kebabize(value));
|
|
60
61
|
};
|
|
61
|
-
exports.isColorCssPropertyName = isColorCssPropertyName;
|
|
62
|
+
exports.isColorCssPropertyName = isColorCssPropertyName;
|
|
63
|
+
var isCurrentSurfaceCustomPropertyName = function isCurrentSurfaceCustomPropertyName(value) {
|
|
64
|
+
return value === 'CURRENT_SURFACE_CSS_VAR' || value === _tokens.CURRENT_SURFACE_CSS_VAR;
|
|
65
|
+
};
|
|
66
|
+
exports.isCurrentSurfaceCustomPropertyName = isCurrentSurfaceCustomPropertyName;
|
|
@@ -5,7 +5,7 @@ import { isDecendantOfGlobalToken, isDecendantOfStyleBlock, isDecendantOfType }
|
|
|
5
5
|
import { lintJSXIdentifierForColor, lintJSXLiteralForColor, lintJSXMemberForColor, lintObjectForColor, lintTemplateIdentifierForColor } from './color';
|
|
6
6
|
import ruleMeta from './rule-meta';
|
|
7
7
|
import { lintObjectForSpacing } from './spacing';
|
|
8
|
-
import { convertHyphenatedNameToCamelCase, emToPixels, getDomainsForProperty, getFontSizeFromNode, getFontSizeValueInScope, getTokenReplacement, getValueFromShorthand, includesTokenString, insertTokensImport, isAuto, isTokenValueString, isValidSpacingValue, isZero, processCssNode, splitShorthandValues } from './
|
|
8
|
+
import { convertHyphenatedNameToCamelCase, emToPixels, getDomainsForProperty, getFontSizeFromNode, getFontSizeValueInScope, getTokenReplacement, getValueFromShorthand, includesTokenString, insertTokensImport, isAuto, isTokenValueString, isValidSpacingValue, isZero, processCssNode, splitShorthandValues } from './utils';
|
|
9
9
|
const defaultConfig = {
|
|
10
10
|
domains: ['color', 'spacing'],
|
|
11
11
|
applyImport: true,
|
|
@@ -52,12 +52,13 @@ const createWithConfig = initialConfig => context => {
|
|
|
52
52
|
if (isNodeOfType(node.value, 'ObjectExpression')) {
|
|
53
53
|
return node.value.properties.forEach(findObjectStyles);
|
|
54
54
|
}
|
|
55
|
-
if (!isNodeOfType(node.key, 'Identifier')) {
|
|
55
|
+
if (!isNodeOfType(node.key, 'Identifier') && !isNodeOfType(node.key, 'Literal')) {
|
|
56
56
|
return;
|
|
57
57
|
}
|
|
58
|
+
const propertyName = isNodeOfType(node.key, 'Identifier') ? node.key.name : String(node.key.value);
|
|
58
59
|
|
|
59
60
|
// Returns which domains to lint against based on rule's config and current property
|
|
60
|
-
const domains = getDomainsForProperty(
|
|
61
|
+
const domains = getDomainsForProperty(propertyName, config.domains);
|
|
61
62
|
if (domains.length === 0 || isDecendantOfGlobalToken(node.value)) {
|
|
62
63
|
return;
|
|
63
64
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isNodeOfType, property } from 'eslint-codemod-utils';
|
|
2
|
-
import { emToPixels, findTokenNameByPropertyValue, getRawExpression, getTokenNodeForValue, getTokenReplacement, getValue, insertTokensImport, isAuto, isCalc, isValidSpacingValue, isZero, splitShorthandValues } from './
|
|
2
|
+
import { emToPixels, findTokenNameByPropertyValue, getRawExpression, getTokenNodeForValue, getTokenReplacement, getValue, insertTokensImport, isAuto, isCalc, isValidSpacingValue, isZero, splitShorthandValues } from './utils';
|
|
3
3
|
export const lintObjectForSpacing = (node, context, ruleConfig, fontSize, tokenNode) => {
|
|
4
4
|
if (isNodeOfType(node.value, 'Literal') && !isValidSpacingValue(node.value.value, fontSize)) {
|
|
5
5
|
context.report({
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { callExpression, identifier, insertAtStartOfFile, insertImportDeclaration, isNodeOfType, literal } from 'eslint-codemod-utils';
|
|
2
2
|
import { spacing as spacingScale } from '@atlaskit/tokens/tokens-raw';
|
|
3
3
|
import { findIdentifierInParentScope } from '../utils/find-in-parent';
|
|
4
|
-
import { isColorCssPropertyName } from '../utils/is-color';
|
|
4
|
+
import { isColorCssPropertyName, isCurrentSurfaceCustomPropertyName } from '../utils/is-color';
|
|
5
5
|
import { borderWidthValueToToken, isBorderRadius, isBorderSizeProperty, isShapeProperty, radiusValueToToken } from './shape';
|
|
6
6
|
import { isCodeFontFamily, isFontFamily, isFontSize, isFontSizeSmall, isTypographyProperty, typographyValueToToken } from './typography';
|
|
7
7
|
const properties = ['padding', 'paddingBlock', 'paddingInline', 'paddingLeft', 'paddingTop', 'paddingRight', 'paddingBottom', 'paddingInline', 'paddingInlineStart', 'paddingInlineEnd', 'paddingBlock', 'paddingBlockStart', 'paddingBlockEnd', 'marginLeft', 'marginTop', 'marginRight', 'marginBottom', 'marginInline', 'marginInlineStart', 'marginInlineEnd', 'marginBlock', 'marginBlockStart', 'marginBlockEnd', 'margin', 'gap', 'rowGap', 'gridRowGap', 'columnGap', 'gridColumnGap', 'top', 'left', 'right', 'bottom', 'inlineStart', 'inlineEnd', 'blockStart', 'blockEnd', 'outline-offset'];
|
|
@@ -303,7 +303,7 @@ export const findParentNodeForLine = node => {
|
|
|
303
303
|
*/
|
|
304
304
|
export function getDomainsForProperty(propertyName, targetOptions) {
|
|
305
305
|
const domains = [];
|
|
306
|
-
if (isColorCssPropertyName(propertyName) && targetOptions.includes('color')) {
|
|
306
|
+
if ((isColorCssPropertyName(propertyName) || isCurrentSurfaceCustomPropertyName(propertyName)) && targetOptions.includes('color')) {
|
|
307
307
|
domains.push('color');
|
|
308
308
|
}
|
|
309
309
|
if (isSpacingProperty(propertyName) && targetOptions.includes('spacing')) {
|
|
@@ -48,7 +48,7 @@ const rule = createLintRule({
|
|
|
48
48
|
|
|
49
49
|
// styled.div``
|
|
50
50
|
if (isNodeOfType(node.property, 'Identifier')) {
|
|
51
|
-
if (validPrimitiveElements.
|
|
51
|
+
if (validPrimitiveElements.has(node.property.name)) {
|
|
52
52
|
const styledIdentifier = node.object.name;
|
|
53
53
|
const elementName = node.property.name;
|
|
54
54
|
|
|
@@ -75,7 +75,7 @@ const rule = createLintRule({
|
|
|
75
75
|
if (isNodeOfType(node.arguments[0], 'Literal')) {
|
|
76
76
|
const argValue = node.arguments[0].raw;
|
|
77
77
|
if (typeof argValue === 'string') {
|
|
78
|
-
const suggest = validPrimitiveElements.
|
|
78
|
+
const suggest = validPrimitiveElements.has(argValue.replaceAll(`'`, '') // argValue will have '' around the element name, strip it out for this test
|
|
79
79
|
);
|
|
80
80
|
|
|
81
81
|
if (suggest) {
|
|
@@ -303,10 +303,9 @@ const getCSSPropStyleObject = (node, context) => {
|
|
|
303
303
|
}
|
|
304
304
|
return styleObj;
|
|
305
305
|
};
|
|
306
|
-
export const validPrimitiveElements =
|
|
306
|
+
export const validPrimitiveElements = new Set(['div', 'span', 'article', 'aside', 'dialog', 'footer', 'header', 'li', 'main', 'nav', 'ol', 'section', 'ul']);
|
|
307
307
|
export const isValidPrimitiveElement = node => {
|
|
308
|
-
|
|
309
|
-
return validPrimitiveElements.test(node.openingElement.name.name);
|
|
308
|
+
return validPrimitiveElements.has(node.openingElement.name.name.toLowerCase());
|
|
310
309
|
};
|
|
311
310
|
const hasInlineCompatibleStyles = cssStyleObject => {
|
|
312
311
|
if (!['flex', 'inline-flex'].includes(cssStyleObject['display'])) {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { CURRENT_SURFACE_CSS_VAR } from '@atlaskit/tokens';
|
|
1
2
|
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
3
|
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',
|
|
3
4
|
// Legacy Trello colors:
|
|
@@ -35,4 +36,5 @@ export const isHardCodedColor = value => {
|
|
|
35
36
|
};
|
|
36
37
|
const validColorPropertyNames = new Set(['color', 'background', 'background-color', 'border', 'border-left', 'border-right', 'border-top', 'border-bottom', 'border-color', 'border-left-color', 'border-right-color', 'border-top-color', 'border-bottom-color', 'outline', 'outline-color', 'box-shadow']);
|
|
37
38
|
const kebabize = str => str.replace(/[A-Z]+(?![a-z])|[A-Z]/g, ($, ofs) => (ofs ? '-' : '') + $.toLowerCase());
|
|
38
|
-
export const isColorCssPropertyName = value => validColorPropertyNames.has(kebabize(value));
|
|
39
|
+
export const isColorCssPropertyName = value => validColorPropertyNames.has(kebabize(value));
|
|
40
|
+
export const isCurrentSurfaceCustomPropertyName = value => value === 'CURRENT_SURFACE_CSS_VAR' || value === CURRENT_SURFACE_CSS_VAR;
|
|
@@ -6,7 +6,7 @@ import { isDecendantOfGlobalToken, isDecendantOfStyleBlock, isDecendantOfType }
|
|
|
6
6
|
import { lintJSXIdentifierForColor, lintJSXLiteralForColor, lintJSXMemberForColor, lintObjectForColor, lintTemplateIdentifierForColor } from './color';
|
|
7
7
|
import ruleMeta from './rule-meta';
|
|
8
8
|
import { lintObjectForSpacing } from './spacing';
|
|
9
|
-
import { convertHyphenatedNameToCamelCase, emToPixels, getDomainsForProperty, getFontSizeFromNode, getFontSizeValueInScope, getTokenReplacement, getValueFromShorthand, includesTokenString, insertTokensImport, isAuto, isTokenValueString, isValidSpacingValue, isZero, processCssNode, splitShorthandValues } from './
|
|
9
|
+
import { convertHyphenatedNameToCamelCase, emToPixels, getDomainsForProperty, getFontSizeFromNode, getFontSizeValueInScope, getTokenReplacement, getValueFromShorthand, includesTokenString, insertTokensImport, isAuto, isTokenValueString, isValidSpacingValue, isZero, processCssNode, splitShorthandValues } from './utils';
|
|
10
10
|
var defaultConfig = {
|
|
11
11
|
domains: ['color', 'spacing'],
|
|
12
12
|
applyImport: true,
|
|
@@ -62,12 +62,13 @@ var createWithConfig = function createWithConfig(initialConfig) {
|
|
|
62
62
|
if (isNodeOfType(node.value, 'ObjectExpression')) {
|
|
63
63
|
return node.value.properties.forEach(findObjectStyles);
|
|
64
64
|
}
|
|
65
|
-
if (!isNodeOfType(node.key, 'Identifier')) {
|
|
65
|
+
if (!isNodeOfType(node.key, 'Identifier') && !isNodeOfType(node.key, 'Literal')) {
|
|
66
66
|
return;
|
|
67
67
|
}
|
|
68
|
+
var propertyName = isNodeOfType(node.key, 'Identifier') ? node.key.name : String(node.key.value);
|
|
68
69
|
|
|
69
70
|
// Returns which domains to lint against based on rule's config and current property
|
|
70
|
-
var domains = getDomainsForProperty(
|
|
71
|
+
var domains = getDomainsForProperty(propertyName, config.domains);
|
|
71
72
|
if (domains.length === 0 || isDecendantOfGlobalToken(node.value)) {
|
|
72
73
|
return;
|
|
73
74
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
2
|
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
3
|
-
function ownKeys(
|
|
4
|
-
function _objectSpread(
|
|
3
|
+
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; }
|
|
4
|
+
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; }
|
|
5
5
|
import { isNodeOfType, property } from 'eslint-codemod-utils';
|
|
6
|
-
import { emToPixels, findTokenNameByPropertyValue, getRawExpression, getTokenNodeForValue, getTokenReplacement, getValue, insertTokensImport, isAuto, isCalc, isValidSpacingValue, isZero, splitShorthandValues } from './
|
|
6
|
+
import { emToPixels, findTokenNameByPropertyValue, getRawExpression, getTokenNodeForValue, getTokenReplacement, getValue, insertTokensImport, isAuto, isCalc, isValidSpacingValue, isZero, splitShorthandValues } from './utils';
|
|
7
7
|
export var lintObjectForSpacing = function lintObjectForSpacing(node, context, ruleConfig, fontSize, tokenNode) {
|
|
8
8
|
if (isNodeOfType(node.value, 'Literal') && !isValidSpacingValue(node.value.value, fontSize)) {
|
|
9
9
|
context.report({
|
|
@@ -2,7 +2,7 @@ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
|
2
2
|
import { callExpression, identifier, insertAtStartOfFile, insertImportDeclaration, isNodeOfType, literal } from 'eslint-codemod-utils';
|
|
3
3
|
import { spacing as spacingScale } from '@atlaskit/tokens/tokens-raw';
|
|
4
4
|
import { findIdentifierInParentScope } from '../utils/find-in-parent';
|
|
5
|
-
import { isColorCssPropertyName } from '../utils/is-color';
|
|
5
|
+
import { isColorCssPropertyName, isCurrentSurfaceCustomPropertyName } from '../utils/is-color';
|
|
6
6
|
import { borderWidthValueToToken, isBorderRadius, isBorderSizeProperty, isShapeProperty, radiusValueToToken } from './shape';
|
|
7
7
|
import { isCodeFontFamily, isFontFamily, isFontSize, isFontSizeSmall, isTypographyProperty, typographyValueToToken } from './typography';
|
|
8
8
|
var properties = ['padding', 'paddingBlock', 'paddingInline', 'paddingLeft', 'paddingTop', 'paddingRight', 'paddingBottom', 'paddingInline', 'paddingInlineStart', 'paddingInlineEnd', 'paddingBlock', 'paddingBlockStart', 'paddingBlockEnd', 'marginLeft', 'marginTop', 'marginRight', 'marginBottom', 'marginInline', 'marginInlineStart', 'marginInlineEnd', 'marginBlock', 'marginBlockStart', 'marginBlockEnd', 'margin', 'gap', 'rowGap', 'gridRowGap', 'columnGap', 'gridColumnGap', 'top', 'left', 'right', 'bottom', 'inlineStart', 'inlineEnd', 'blockStart', 'blockEnd', 'outline-offset'];
|
|
@@ -312,7 +312,7 @@ export var findParentNodeForLine = function findParentNodeForLine(node) {
|
|
|
312
312
|
*/
|
|
313
313
|
export function getDomainsForProperty(propertyName, targetOptions) {
|
|
314
314
|
var domains = [];
|
|
315
|
-
if (isColorCssPropertyName(propertyName) && targetOptions.includes('color')) {
|
|
315
|
+
if ((isColorCssPropertyName(propertyName) || isCurrentSurfaceCustomPropertyName(propertyName)) && targetOptions.includes('color')) {
|
|
316
316
|
domains.push('color');
|
|
317
317
|
}
|
|
318
318
|
if (isSpacingProperty(propertyName) && targetOptions.includes('spacing')) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
-
function ownKeys(
|
|
3
|
-
function _objectSpread(
|
|
2
|
+
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; }
|
|
3
|
+
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; }
|
|
4
4
|
import { createWithConfig } from '../ensure-design-token-usage';
|
|
5
5
|
import ruleMeta from '../ensure-design-token-usage/rule-meta';
|
|
6
6
|
import { createLintRule } from '../utils/create-rule';
|
|
@@ -47,7 +47,7 @@ var rule = createLintRule({
|
|
|
47
47
|
|
|
48
48
|
// styled.div``
|
|
49
49
|
if (isNodeOfType(node.property, 'Identifier')) {
|
|
50
|
-
if (validPrimitiveElements.
|
|
50
|
+
if (validPrimitiveElements.has(node.property.name)) {
|
|
51
51
|
var styledIdentifier = node.object.name;
|
|
52
52
|
var elementName = node.property.name;
|
|
53
53
|
|
|
@@ -74,7 +74,7 @@ var rule = createLintRule({
|
|
|
74
74
|
if (isNodeOfType(node.arguments[0], 'Literal')) {
|
|
75
75
|
var argValue = node.arguments[0].raw;
|
|
76
76
|
if (typeof argValue === 'string') {
|
|
77
|
-
var suggest = validPrimitiveElements.
|
|
77
|
+
var suggest = validPrimitiveElements.has(argValue.replaceAll("'", '') // argValue will have '' around the element name, strip it out for this test
|
|
78
78
|
);
|
|
79
79
|
|
|
80
80
|
if (suggest) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
-
function ownKeys(
|
|
3
|
-
function _objectSpread(
|
|
2
|
+
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; }
|
|
3
|
+
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; }
|
|
4
4
|
import { getIdentifierInParentScope, hasImportDeclaration, insertImportDeclaration, insertImportSpecifier, isNodeOfType, jsxAttribute, jsxIdentifier, jsxOpeningElement, literal } from 'eslint-codemod-utils';
|
|
5
5
|
export var shouldSuggestBox = function shouldSuggestBox(node
|
|
6
6
|
// scope: Scope.Scope,
|
|
@@ -309,10 +309,9 @@ var getCSSPropStyleObject = function getCSSPropStyleObject(node, context) {
|
|
|
309
309
|
}
|
|
310
310
|
return styleObj;
|
|
311
311
|
};
|
|
312
|
-
export var validPrimitiveElements =
|
|
312
|
+
export var validPrimitiveElements = new Set(['div', 'span', 'article', 'aside', 'dialog', 'footer', 'header', 'li', 'main', 'nav', 'ol', 'section', 'ul']);
|
|
313
313
|
export var isValidPrimitiveElement = function isValidPrimitiveElement(node) {
|
|
314
|
-
|
|
315
|
-
return validPrimitiveElements.test(node.openingElement.name.name);
|
|
314
|
+
return validPrimitiveElements.has(node.openingElement.name.name.toLowerCase());
|
|
316
315
|
};
|
|
317
316
|
var hasInlineCompatibleStyles = function hasInlineCompatibleStyles(cssStyleObject) {
|
|
318
317
|
if (!['flex', 'inline-flex'].includes(cssStyleObject['display'])) {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { CURRENT_SURFACE_CSS_VAR } from '@atlaskit/tokens';
|
|
1
2
|
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
3
|
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',
|
|
3
4
|
// Legacy Trello colors:
|
|
@@ -47,4 +48,7 @@ var kebabize = function kebabize(str) {
|
|
|
47
48
|
};
|
|
48
49
|
export var isColorCssPropertyName = function isColorCssPropertyName(value) {
|
|
49
50
|
return validColorPropertyNames.has(kebabize(value));
|
|
51
|
+
};
|
|
52
|
+
export var isCurrentSurfaceCustomPropertyName = function isCurrentSurfaceCustomPropertyName(value) {
|
|
53
|
+
return value === 'CURRENT_SURFACE_CSS_VAR' || value === CURRENT_SURFACE_CSS_VAR;
|
|
50
54
|
};
|
|
@@ -8,6 +8,6 @@ export declare const primitiveFixer: (node: EslintNode, nodeName: string, contex
|
|
|
8
8
|
export declare const isWhiteSpace: (value: string) => boolean;
|
|
9
9
|
type JSXChild = 'JSXElement' | 'JSXExpressionContainer' | 'JSXFragment' | 'JSXText' | 'JSXSpreadChild'[];
|
|
10
10
|
export declare const getChildrenByType: (node: JSXElement, types: JSXChild[]) => (JSXElement | JSXExpressionContainer | import("estree-jsx").JSXFragment | JSXText | import("estree-jsx").JSXSpreadChild)[];
|
|
11
|
-
export declare const validPrimitiveElements:
|
|
11
|
+
export declare const validPrimitiveElements: Set<string>;
|
|
12
12
|
export declare const isValidPrimitiveElement: (node: JSXElement) => boolean;
|
|
13
13
|
export {};
|
|
@@ -3,3 +3,4 @@ export declare const isLegacyNamedColor: (value: string) => boolean;
|
|
|
3
3
|
export declare const includesHardCodedColor: (raw: string) => boolean;
|
|
4
4
|
export declare const isHardCodedColor: (value: string) => boolean;
|
|
5
5
|
export declare const isColorCssPropertyName: (value: string) => boolean;
|
|
6
|
+
export declare const isCurrentSurfaceCustomPropertyName: (value: string) => boolean;
|
|
@@ -8,6 +8,6 @@ export declare const primitiveFixer: (node: EslintNode, nodeName: string, contex
|
|
|
8
8
|
export declare const isWhiteSpace: (value: string) => boolean;
|
|
9
9
|
type JSXChild = 'JSXElement' | 'JSXExpressionContainer' | 'JSXFragment' | 'JSXText' | 'JSXSpreadChild'[];
|
|
10
10
|
export declare const getChildrenByType: (node: JSXElement, types: JSXChild[]) => (JSXElement | JSXExpressionContainer | import("estree-jsx").JSXFragment | JSXText | import("estree-jsx").JSXSpreadChild)[];
|
|
11
|
-
export declare const validPrimitiveElements:
|
|
11
|
+
export declare const validPrimitiveElements: Set<string>;
|
|
12
12
|
export declare const isValidPrimitiveElement: (node: JSXElement) => boolean;
|
|
13
13
|
export {};
|
|
@@ -3,3 +3,4 @@ export declare const isLegacyNamedColor: (value: string) => boolean;
|
|
|
3
3
|
export declare const includesHardCodedColor: (raw: string) => boolean;
|
|
4
4
|
export declare const isHardCodedColor: (value: string) => boolean;
|
|
5
5
|
export declare const isColorCssPropertyName: (value: string) => boolean;
|
|
6
|
+
export declare const isCurrentSurfaceCustomPropertyName: (value: string) => boolean;
|
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": "8.4.
|
|
4
|
+
"version": "8.4.4",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"registry": "https://registry.npmjs.org/"
|
|
File without changes
|
|
File without changes
|