@atlaskit/eslint-plugin-design-system 8.7.1 → 8.8.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 +6 -0
- package/dist/cjs/rules/ensure-design-token-usage/index.js +24 -2
- package/dist/cjs/rules/ensure-design-token-usage/rule-meta.js +1 -0
- package/dist/cjs/rules/ensure-design-token-usage/spacing.js +19 -4
- package/dist/cjs/rules/ensure-design-token-usage/utils.js +9 -4
- package/dist/es2019/rules/ensure-design-token-usage/index.js +25 -3
- package/dist/es2019/rules/ensure-design-token-usage/rule-meta.js +1 -0
- package/dist/es2019/rules/ensure-design-token-usage/spacing.js +19 -4
- package/dist/es2019/rules/ensure-design-token-usage/utils.js +7 -3
- package/dist/esm/rules/ensure-design-token-usage/index.js +25 -3
- package/dist/esm/rules/ensure-design-token-usage/rule-meta.js +1 -0
- package/dist/esm/rules/ensure-design-token-usage/spacing.js +19 -4
- package/dist/esm/rules/ensure-design-token-usage/utils.js +7 -3
- package/dist/types/rules/ensure-design-token-usage/utils.d.ts +15 -0
- package/dist/types-ts4.5/rules/ensure-design-token-usage/utils.d.ts +15 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @atlaskit/eslint-plugin-design-system
|
|
2
2
|
|
|
3
|
+
## 8.8.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [`6c149f3e71d`](https://bitbucket.org/atlassian/atlassian-frontend/commits/6c149f3e71d) - The `ensure-design-token-usage` rules now report on use of the CSS `calc` function when used with padding, margin, and gap properties.
|
|
8
|
+
|
|
3
9
|
## 8.7.1
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
|
@@ -79,8 +79,20 @@ var createWithConfig = function createWithConfig(initialConfig) {
|
|
|
79
79
|
if (domains.length === 0 || (0, _isNode.isDecendantOfGlobalToken)(node.value)) {
|
|
80
80
|
return;
|
|
81
81
|
}
|
|
82
|
-
if ((0, _eslintCodemodUtils.isNodeOfType)(node.value, 'TemplateLiteral')
|
|
83
|
-
|
|
82
|
+
if ((0, _eslintCodemodUtils.isNodeOfType)(node.value, 'TemplateLiteral')) {
|
|
83
|
+
var value = (0, _utils.getValueFromTemplateLiteralRaw)(node.value, context);
|
|
84
|
+
if (Array.isArray(value) && value.some(_utils.isCalc)) {
|
|
85
|
+
return context.report({
|
|
86
|
+
node: node,
|
|
87
|
+
messageId: 'noCalcUsage',
|
|
88
|
+
data: {
|
|
89
|
+
payload: "".concat(propertyName)
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
if (node.value.expressions.some(_isNode.isDecendantOfGlobalToken)) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
84
96
|
}
|
|
85
97
|
if (domains.includes('color')) {
|
|
86
98
|
return (0, _color.lintObjectForColor)(node, context, config);
|
|
@@ -172,6 +184,16 @@ var createWithConfig = function createWithConfig(initialConfig) {
|
|
|
172
184
|
if (!originalValue) {
|
|
173
185
|
return originalValue;
|
|
174
186
|
}
|
|
187
|
+
if ((0, _utils.isCalc)(originalValue)) {
|
|
188
|
+
context.report({
|
|
189
|
+
node: node,
|
|
190
|
+
messageId: 'noCalcUsage',
|
|
191
|
+
data: {
|
|
192
|
+
payload: "".concat(propertyName)
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
return originalValue;
|
|
196
|
+
}
|
|
175
197
|
if ((0, _utils.isTokenValueString)(originalValue)) {
|
|
176
198
|
// if the value is already valid, nothing to report or replace
|
|
177
199
|
return originalValue;
|
|
@@ -42,6 +42,7 @@ var ruleMeta = {
|
|
|
42
42
|
noRawRadiusValues: 'The use of shape tokens is preferred over the direct application of border properties.\n\n@meta <<{{payload}}>>',
|
|
43
43
|
noRawSpacingValues: 'The use of spacing primitives or tokens is preferred over the direct application of spacing properties.\n\n@meta <<{{payload}}>>',
|
|
44
44
|
autofixesPossible: 'Automated corrections available for spacing values. Apply autofix to replace values with appropriate tokens',
|
|
45
|
+
noCalcUsage: 'The use of space tokens is preferred over using the CSS calc function. If using a value that is not aligned to the spacing scale, consider aligning to the scale and using tokens instead.',
|
|
45
46
|
hardCodedColor: "Colors can be sourced from the global theme using the token function.",
|
|
46
47
|
legacyElevation: "Elevations can be sourced from the global theme using the token function made of both a background and shadow. Use \"card\" for card elevations, and \"overlay\" for anything else that should appear elevated."
|
|
47
48
|
}
|
|
@@ -22,13 +22,19 @@ var lintObjectForSpacing = function lintObjectForSpacing(node, context, ruleConf
|
|
|
22
22
|
});
|
|
23
23
|
return;
|
|
24
24
|
}
|
|
25
|
+
var propertyName = node.key.name;
|
|
26
|
+
var isFontFamily = /fontFamily/.test(propertyName);
|
|
25
27
|
|
|
26
|
-
//
|
|
28
|
+
// Report on CSS calc function for strings
|
|
27
29
|
if ((0, _eslintCodemodUtils.isNodeOfType)(node.value, 'Literal') && (0, _utils.isCalc)(node.value.value)) {
|
|
28
|
-
return
|
|
30
|
+
return context.report({
|
|
31
|
+
node: node,
|
|
32
|
+
messageId: 'noCalcUsage',
|
|
33
|
+
data: {
|
|
34
|
+
payload: "".concat(propertyName)
|
|
35
|
+
}
|
|
36
|
+
});
|
|
29
37
|
}
|
|
30
|
-
var propertyName = node.key.name;
|
|
31
|
-
var isFontFamily = /fontFamily/.test(propertyName);
|
|
32
38
|
var value = (0, _utils.getValue)(node.value, context);
|
|
33
39
|
|
|
34
40
|
// Value is a token string (e.g. set via a variable)
|
|
@@ -87,6 +93,15 @@ var lintObjectForSpacing = function lintObjectForSpacing(node, context, ruleConf
|
|
|
87
93
|
* { padding: '8px 0px' }
|
|
88
94
|
*/
|
|
89
95
|
valuesForProperty.forEach(function (val) {
|
|
96
|
+
if ((0, _utils.isCalc)(val)) {
|
|
97
|
+
return context.report({
|
|
98
|
+
node: node,
|
|
99
|
+
messageId: 'noCalcUsage',
|
|
100
|
+
data: {
|
|
101
|
+
payload: "".concat(propertyName, ":").concat(val)
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
}
|
|
90
105
|
var pixelValue = (0, _utils.emToPixels)(val, fontSize);
|
|
91
106
|
|
|
92
107
|
// Do not report or suggest a token to replace 0 or auto
|
|
@@ -13,7 +13,7 @@ exports.getFontSizeValueInScope = getFontSizeValueInScope;
|
|
|
13
13
|
exports.getRawExpression = void 0;
|
|
14
14
|
exports.getTokenNodeForValue = getTokenNodeForValue;
|
|
15
15
|
exports.getTokenReplacement = getTokenReplacement;
|
|
16
|
-
exports.getValueFromShorthand = exports.getValue = void 0;
|
|
16
|
+
exports.getValueFromTemplateLiteralRaw = exports.getValueFromShorthand = exports.getValue = void 0;
|
|
17
17
|
exports.includesTokenString = includesTokenString;
|
|
18
18
|
exports.insertTokensImport = insertTokensImport;
|
|
19
19
|
exports.isSpacingProperty = exports.isCalc = exports.isAuto = void 0;
|
|
@@ -207,7 +207,7 @@ var getValueFromUnaryExpression = function getValueFromUnaryExpression(node, con
|
|
|
207
207
|
* // results in [2, 4, 0]
|
|
208
208
|
* ```
|
|
209
209
|
*/
|
|
210
|
-
var
|
|
210
|
+
var getValueFromTemplateLiteralRaw = function getValueFromTemplateLiteralRaw(node, context) {
|
|
211
211
|
if (!(0, _eslintCodemodUtils.isNodeOfType)(node, "TemplateLiteral")) {
|
|
212
212
|
return null;
|
|
213
213
|
}
|
|
@@ -218,7 +218,12 @@ var getValueFromTemplateLiteral = function getValueFromTemplateLiteral(node, con
|
|
|
218
218
|
if (fontFamily.test(combinedString)) {
|
|
219
219
|
return combinedString;
|
|
220
220
|
}
|
|
221
|
-
return combinedString.split(' ')
|
|
221
|
+
return combinedString.split(' ');
|
|
222
|
+
};
|
|
223
|
+
exports.getValueFromTemplateLiteralRaw = getValueFromTemplateLiteralRaw;
|
|
224
|
+
var getValueFromTemplateLiteral = function getValueFromTemplateLiteral(node, context) {
|
|
225
|
+
var value = getValueFromTemplateLiteralRaw(node, context);
|
|
226
|
+
return Array.isArray(value) ? value.map(removePixelSuffix) : value;
|
|
222
227
|
};
|
|
223
228
|
var getValueFromBinaryExpression = function getValueFromBinaryExpression(node, context) {
|
|
224
229
|
if (!(0, _eslintCodemodUtils.isNodeOfType)(node, 'BinaryExpression')) {
|
|
@@ -252,7 +257,7 @@ var emToPixels = function emToPixels(value, fontSize) {
|
|
|
252
257
|
exports.emToPixels = emToPixels;
|
|
253
258
|
var percentageOrEmOrAuto = /(%$)|(\d+em$)|(auto$)/;
|
|
254
259
|
var removePixelSuffix = function removePixelSuffix(value) {
|
|
255
|
-
if (typeof value === 'string' && percentageOrEmOrAuto.test(value)) {
|
|
260
|
+
if (typeof value === 'string' && (percentageOrEmOrAuto.test(value) || isCalc(value))) {
|
|
256
261
|
return value;
|
|
257
262
|
}
|
|
258
263
|
return Number(typeof value === 'string' ? value.replace('px', '') : value);
|
|
@@ -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 './utils';
|
|
8
|
+
import { convertHyphenatedNameToCamelCase, emToPixels, getDomainsForProperty, getFontSizeFromNode, getFontSizeValueInScope, getTokenReplacement, getValueFromShorthand, getValueFromTemplateLiteralRaw, includesTokenString, insertTokensImport, isAuto, isCalc, isTokenValueString, isValidSpacingValue, isZero, processCssNode, splitShorthandValues } from './utils';
|
|
9
9
|
const defaultConfig = {
|
|
10
10
|
domains: ['color', 'spacing'],
|
|
11
11
|
applyImport: true,
|
|
@@ -62,8 +62,20 @@ const createWithConfig = initialConfig => context => {
|
|
|
62
62
|
if (domains.length === 0 || isDecendantOfGlobalToken(node.value)) {
|
|
63
63
|
return;
|
|
64
64
|
}
|
|
65
|
-
if (isNodeOfType(node.value, 'TemplateLiteral')
|
|
66
|
-
|
|
65
|
+
if (isNodeOfType(node.value, 'TemplateLiteral')) {
|
|
66
|
+
const value = getValueFromTemplateLiteralRaw(node.value, context);
|
|
67
|
+
if (Array.isArray(value) && value.some(isCalc)) {
|
|
68
|
+
return context.report({
|
|
69
|
+
node,
|
|
70
|
+
messageId: 'noCalcUsage',
|
|
71
|
+
data: {
|
|
72
|
+
payload: `${propertyName}`
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
if (node.value.expressions.some(isDecendantOfGlobalToken)) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
67
79
|
}
|
|
68
80
|
if (domains.includes('color')) {
|
|
69
81
|
return lintObjectForColor(node, context, config);
|
|
@@ -140,6 +152,16 @@ const createWithConfig = initialConfig => context => {
|
|
|
140
152
|
if (!originalValue) {
|
|
141
153
|
return originalValue;
|
|
142
154
|
}
|
|
155
|
+
if (isCalc(originalValue)) {
|
|
156
|
+
context.report({
|
|
157
|
+
node,
|
|
158
|
+
messageId: 'noCalcUsage',
|
|
159
|
+
data: {
|
|
160
|
+
payload: `${propertyName}`
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
return originalValue;
|
|
164
|
+
}
|
|
143
165
|
if (isTokenValueString(originalValue)) {
|
|
144
166
|
// if the value is already valid, nothing to report or replace
|
|
145
167
|
return originalValue;
|
|
@@ -36,6 +36,7 @@ const ruleMeta = {
|
|
|
36
36
|
noRawRadiusValues: 'The use of shape tokens is preferred over the direct application of border properties.\n\n@meta <<{{payload}}>>',
|
|
37
37
|
noRawSpacingValues: 'The use of spacing primitives or tokens is preferred over the direct application of spacing properties.\n\n@meta <<{{payload}}>>',
|
|
38
38
|
autofixesPossible: 'Automated corrections available for spacing values. Apply autofix to replace values with appropriate tokens',
|
|
39
|
+
noCalcUsage: 'The use of space tokens is preferred over using the CSS calc function. If using a value that is not aligned to the spacing scale, consider aligning to the scale and using tokens instead.',
|
|
39
40
|
hardCodedColor: `Colors can be sourced from the global theme using the token function.`,
|
|
40
41
|
legacyElevation: `Elevations can be sourced from the global theme using the token function made of both a background and shadow. Use "card" for card elevations, and "overlay" for anything else that should appear elevated.`
|
|
41
42
|
}
|
|
@@ -11,13 +11,19 @@ export const lintObjectForSpacing = (node, context, ruleConfig, fontSize, tokenN
|
|
|
11
11
|
});
|
|
12
12
|
return;
|
|
13
13
|
}
|
|
14
|
+
const propertyName = node.key.name;
|
|
15
|
+
const isFontFamily = /fontFamily/.test(propertyName);
|
|
14
16
|
|
|
15
|
-
//
|
|
17
|
+
// Report on CSS calc function for strings
|
|
16
18
|
if (isNodeOfType(node.value, 'Literal') && isCalc(node.value.value)) {
|
|
17
|
-
return
|
|
19
|
+
return context.report({
|
|
20
|
+
node,
|
|
21
|
+
messageId: 'noCalcUsage',
|
|
22
|
+
data: {
|
|
23
|
+
payload: `${propertyName}`
|
|
24
|
+
}
|
|
25
|
+
});
|
|
18
26
|
}
|
|
19
|
-
const propertyName = node.key.name;
|
|
20
|
-
const isFontFamily = /fontFamily/.test(propertyName);
|
|
21
27
|
const value = getValue(node.value, context);
|
|
22
28
|
|
|
23
29
|
// Value is a token string (e.g. set via a variable)
|
|
@@ -76,6 +82,15 @@ export const lintObjectForSpacing = (node, context, ruleConfig, fontSize, tokenN
|
|
|
76
82
|
* { padding: '8px 0px' }
|
|
77
83
|
*/
|
|
78
84
|
valuesForProperty.forEach(val => {
|
|
85
|
+
if (isCalc(val)) {
|
|
86
|
+
return context.report({
|
|
87
|
+
node,
|
|
88
|
+
messageId: 'noCalcUsage',
|
|
89
|
+
data: {
|
|
90
|
+
payload: `${propertyName}:${val}`
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
}
|
|
79
94
|
const pixelValue = emToPixels(val, fontSize);
|
|
80
95
|
|
|
81
96
|
// Do not report or suggest a token to replace 0 or auto
|
|
@@ -167,7 +167,7 @@ const getValueFromUnaryExpression = (node, context) => {
|
|
|
167
167
|
* // results in [2, 4, 0]
|
|
168
168
|
* ```
|
|
169
169
|
*/
|
|
170
|
-
const
|
|
170
|
+
export const getValueFromTemplateLiteralRaw = (node, context) => {
|
|
171
171
|
if (!isNodeOfType(node, `TemplateLiteral`)) {
|
|
172
172
|
return null;
|
|
173
173
|
}
|
|
@@ -178,7 +178,11 @@ const getValueFromTemplateLiteral = (node, context) => {
|
|
|
178
178
|
if (fontFamily.test(combinedString)) {
|
|
179
179
|
return combinedString;
|
|
180
180
|
}
|
|
181
|
-
return combinedString.split(' ')
|
|
181
|
+
return combinedString.split(' ');
|
|
182
|
+
};
|
|
183
|
+
const getValueFromTemplateLiteral = (node, context) => {
|
|
184
|
+
const value = getValueFromTemplateLiteralRaw(node, context);
|
|
185
|
+
return Array.isArray(value) ? value.map(removePixelSuffix) : value;
|
|
182
186
|
};
|
|
183
187
|
const getValueFromBinaryExpression = (node, context) => {
|
|
184
188
|
if (!isNodeOfType(node, 'BinaryExpression')) {
|
|
@@ -213,7 +217,7 @@ export const emToPixels = (value, fontSize) => {
|
|
|
213
217
|
};
|
|
214
218
|
const percentageOrEmOrAuto = /(%$)|(\d+em$)|(auto$)/;
|
|
215
219
|
export const removePixelSuffix = value => {
|
|
216
|
-
if (typeof value === 'string' && percentageOrEmOrAuto.test(value)) {
|
|
220
|
+
if (typeof value === 'string' && (percentageOrEmOrAuto.test(value) || isCalc(value))) {
|
|
217
221
|
return value;
|
|
218
222
|
}
|
|
219
223
|
return Number(typeof value === 'string' ? value.replace('px', '') : value);
|
|
@@ -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 './utils';
|
|
9
|
+
import { convertHyphenatedNameToCamelCase, emToPixels, getDomainsForProperty, getFontSizeFromNode, getFontSizeValueInScope, getTokenReplacement, getValueFromShorthand, getValueFromTemplateLiteralRaw, includesTokenString, insertTokensImport, isAuto, isCalc, isTokenValueString, isValidSpacingValue, isZero, processCssNode, splitShorthandValues } from './utils';
|
|
10
10
|
var defaultConfig = {
|
|
11
11
|
domains: ['color', 'spacing'],
|
|
12
12
|
applyImport: true,
|
|
@@ -72,8 +72,20 @@ var createWithConfig = function createWithConfig(initialConfig) {
|
|
|
72
72
|
if (domains.length === 0 || isDecendantOfGlobalToken(node.value)) {
|
|
73
73
|
return;
|
|
74
74
|
}
|
|
75
|
-
if (isNodeOfType(node.value, 'TemplateLiteral')
|
|
76
|
-
|
|
75
|
+
if (isNodeOfType(node.value, 'TemplateLiteral')) {
|
|
76
|
+
var value = getValueFromTemplateLiteralRaw(node.value, context);
|
|
77
|
+
if (Array.isArray(value) && value.some(isCalc)) {
|
|
78
|
+
return context.report({
|
|
79
|
+
node: node,
|
|
80
|
+
messageId: 'noCalcUsage',
|
|
81
|
+
data: {
|
|
82
|
+
payload: "".concat(propertyName)
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
if (node.value.expressions.some(isDecendantOfGlobalToken)) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
77
89
|
}
|
|
78
90
|
if (domains.includes('color')) {
|
|
79
91
|
return lintObjectForColor(node, context, config);
|
|
@@ -165,6 +177,16 @@ var createWithConfig = function createWithConfig(initialConfig) {
|
|
|
165
177
|
if (!originalValue) {
|
|
166
178
|
return originalValue;
|
|
167
179
|
}
|
|
180
|
+
if (isCalc(originalValue)) {
|
|
181
|
+
context.report({
|
|
182
|
+
node: node,
|
|
183
|
+
messageId: 'noCalcUsage',
|
|
184
|
+
data: {
|
|
185
|
+
payload: "".concat(propertyName)
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
return originalValue;
|
|
189
|
+
}
|
|
168
190
|
if (isTokenValueString(originalValue)) {
|
|
169
191
|
// if the value is already valid, nothing to report or replace
|
|
170
192
|
return originalValue;
|
|
@@ -36,6 +36,7 @@ var ruleMeta = {
|
|
|
36
36
|
noRawRadiusValues: 'The use of shape tokens is preferred over the direct application of border properties.\n\n@meta <<{{payload}}>>',
|
|
37
37
|
noRawSpacingValues: 'The use of spacing primitives or tokens is preferred over the direct application of spacing properties.\n\n@meta <<{{payload}}>>',
|
|
38
38
|
autofixesPossible: 'Automated corrections available for spacing values. Apply autofix to replace values with appropriate tokens',
|
|
39
|
+
noCalcUsage: 'The use of space tokens is preferred over using the CSS calc function. If using a value that is not aligned to the spacing scale, consider aligning to the scale and using tokens instead.',
|
|
39
40
|
hardCodedColor: "Colors can be sourced from the global theme using the token function.",
|
|
40
41
|
legacyElevation: "Elevations can be sourced from the global theme using the token function made of both a background and shadow. Use \"card\" for card elevations, and \"overlay\" for anything else that should appear elevated."
|
|
41
42
|
}
|
|
@@ -15,13 +15,19 @@ export var lintObjectForSpacing = function lintObjectForSpacing(node, context, r
|
|
|
15
15
|
});
|
|
16
16
|
return;
|
|
17
17
|
}
|
|
18
|
+
var propertyName = node.key.name;
|
|
19
|
+
var isFontFamily = /fontFamily/.test(propertyName);
|
|
18
20
|
|
|
19
|
-
//
|
|
21
|
+
// Report on CSS calc function for strings
|
|
20
22
|
if (isNodeOfType(node.value, 'Literal') && isCalc(node.value.value)) {
|
|
21
|
-
return
|
|
23
|
+
return context.report({
|
|
24
|
+
node: node,
|
|
25
|
+
messageId: 'noCalcUsage',
|
|
26
|
+
data: {
|
|
27
|
+
payload: "".concat(propertyName)
|
|
28
|
+
}
|
|
29
|
+
});
|
|
22
30
|
}
|
|
23
|
-
var propertyName = node.key.name;
|
|
24
|
-
var isFontFamily = /fontFamily/.test(propertyName);
|
|
25
31
|
var value = getValue(node.value, context);
|
|
26
32
|
|
|
27
33
|
// Value is a token string (e.g. set via a variable)
|
|
@@ -80,6 +86,15 @@ export var lintObjectForSpacing = function lintObjectForSpacing(node, context, r
|
|
|
80
86
|
* { padding: '8px 0px' }
|
|
81
87
|
*/
|
|
82
88
|
valuesForProperty.forEach(function (val) {
|
|
89
|
+
if (isCalc(val)) {
|
|
90
|
+
return context.report({
|
|
91
|
+
node: node,
|
|
92
|
+
messageId: 'noCalcUsage',
|
|
93
|
+
data: {
|
|
94
|
+
payload: "".concat(propertyName, ":").concat(val)
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
}
|
|
83
98
|
var pixelValue = emToPixels(val, fontSize);
|
|
84
99
|
|
|
85
100
|
// Do not report or suggest a token to replace 0 or auto
|
|
@@ -176,7 +176,7 @@ var getValueFromUnaryExpression = function getValueFromUnaryExpression(node, con
|
|
|
176
176
|
* // results in [2, 4, 0]
|
|
177
177
|
* ```
|
|
178
178
|
*/
|
|
179
|
-
var
|
|
179
|
+
export var getValueFromTemplateLiteralRaw = function getValueFromTemplateLiteralRaw(node, context) {
|
|
180
180
|
if (!isNodeOfType(node, "TemplateLiteral")) {
|
|
181
181
|
return null;
|
|
182
182
|
}
|
|
@@ -187,7 +187,11 @@ var getValueFromTemplateLiteral = function getValueFromTemplateLiteral(node, con
|
|
|
187
187
|
if (fontFamily.test(combinedString)) {
|
|
188
188
|
return combinedString;
|
|
189
189
|
}
|
|
190
|
-
return combinedString.split(' ')
|
|
190
|
+
return combinedString.split(' ');
|
|
191
|
+
};
|
|
192
|
+
var getValueFromTemplateLiteral = function getValueFromTemplateLiteral(node, context) {
|
|
193
|
+
var value = getValueFromTemplateLiteralRaw(node, context);
|
|
194
|
+
return Array.isArray(value) ? value.map(removePixelSuffix) : value;
|
|
191
195
|
};
|
|
192
196
|
var getValueFromBinaryExpression = function getValueFromBinaryExpression(node, context) {
|
|
193
197
|
if (!isNodeOfType(node, 'BinaryExpression')) {
|
|
@@ -220,7 +224,7 @@ export var emToPixels = function emToPixels(value, fontSize) {
|
|
|
220
224
|
};
|
|
221
225
|
var percentageOrEmOrAuto = /(%$)|(\d+em$)|(auto$)/;
|
|
222
226
|
export var removePixelSuffix = function removePixelSuffix(value) {
|
|
223
|
-
if (typeof value === 'string' && percentageOrEmOrAuto.test(value)) {
|
|
227
|
+
if (typeof value === 'string' && (percentageOrEmOrAuto.test(value) || isCalc(value))) {
|
|
224
228
|
return value;
|
|
225
229
|
}
|
|
226
230
|
return Number(typeof value === 'string' ? value.replace('px', '') : value);
|
|
@@ -19,6 +19,21 @@ export declare const splitShorthandValues: (str: string) => string[];
|
|
|
19
19
|
export declare const getValueFromShorthand: (str: unknown) => any[];
|
|
20
20
|
export declare const getValue: (node: EslintNode, context: Rule.RuleContext) => string | number | any[] | null | undefined;
|
|
21
21
|
export declare const getRawExpression: (node: EslintNode, context: Rule.RuleContext) => string | null;
|
|
22
|
+
/**
|
|
23
|
+
* @example
|
|
24
|
+
* ```js
|
|
25
|
+
* `2 ${variable} 0`
|
|
26
|
+
*
|
|
27
|
+
* // results in [2, NaN, 0]
|
|
28
|
+
* ```
|
|
29
|
+
* ```js
|
|
30
|
+
* const variable = 4;
|
|
31
|
+
* `2 ${variable} 0`
|
|
32
|
+
*
|
|
33
|
+
* // results in [2, 4, 0]
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export declare const getValueFromTemplateLiteralRaw: (node: EslintNode, context: Rule.RuleContext) => string[] | string | null;
|
|
22
37
|
export declare const emToPixels: <T extends unknown>(value: T, fontSize: number | null | undefined) => number | T | null;
|
|
23
38
|
export declare const removePixelSuffix: (value: string | number) => string | number;
|
|
24
39
|
export declare const isValidSpacingValue: (value: string | number | boolean | RegExp | null | undefined | any[] | bigint, fontSize?: number | null | undefined) => boolean;
|
|
@@ -22,6 +22,21 @@ export declare const splitShorthandValues: (str: string) => string[];
|
|
|
22
22
|
export declare const getValueFromShorthand: (str: unknown) => any[];
|
|
23
23
|
export declare const getValue: (node: EslintNode, context: Rule.RuleContext) => string | number | any[] | null | undefined;
|
|
24
24
|
export declare const getRawExpression: (node: EslintNode, context: Rule.RuleContext) => string | null;
|
|
25
|
+
/**
|
|
26
|
+
* @example
|
|
27
|
+
* ```js
|
|
28
|
+
* `2 ${variable} 0`
|
|
29
|
+
*
|
|
30
|
+
* // results in [2, NaN, 0]
|
|
31
|
+
* ```
|
|
32
|
+
* ```js
|
|
33
|
+
* const variable = 4;
|
|
34
|
+
* `2 ${variable} 0`
|
|
35
|
+
*
|
|
36
|
+
* // results in [2, 4, 0]
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export declare const getValueFromTemplateLiteralRaw: (node: EslintNode, context: Rule.RuleContext) => string[] | string | null;
|
|
25
40
|
export declare const emToPixels: <T extends unknown>(value: T, fontSize: number | null | undefined) => number | T | null;
|
|
26
41
|
export declare const removePixelSuffix: (value: string | number) => string | number;
|
|
27
42
|
export declare const isValidSpacingValue: (value: string | number | boolean | RegExp | null | undefined | any[] | bigint, fontSize?: number | null | undefined) => 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
|
+
"version": "8.8.0",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"registry": "https://registry.npmjs.org/"
|