@atlaskit/eslint-plugin-design-system 4.15.1 → 4.15.3
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-spacing/index.js +22 -15
- package/dist/cjs/rules/ensure-design-token-usage-spacing/utils.js +32 -14
- package/dist/cjs/rules/utils/is-elevation.js +10 -10
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/rules/ensure-design-token-usage-spacing/index.js +19 -12
- package/dist/es2019/rules/ensure-design-token-usage-spacing/utils.js +26 -13
- package/dist/es2019/rules/utils/is-elevation.js +10 -10
- package/dist/es2019/version.json +1 -1
- package/dist/esm/rules/ensure-design-token-usage-spacing/index.js +23 -16
- package/dist/esm/rules/ensure-design-token-usage-spacing/utils.js +29 -13
- package/dist/esm/rules/utils/is-elevation.js +10 -10
- package/dist/esm/version.json +1 -1
- package/dist/types/rules/ensure-design-token-usage-spacing/utils.d.ts +1 -0
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @atlaskit/eslint-plugin-design-system
|
|
2
2
|
|
|
3
|
+
## 4.15.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`965e9c7f5d7`](https://bitbucket.org/atlassian/atlassian-frontend/commits/965e9c7f5d7) - Fix spacing token autofix in tagged template literal styles, enabling replacement of expression to equivalent spacing tokens
|
|
8
|
+
|
|
9
|
+
## 4.15.2
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [`cf16d8f8bcc`](https://bitbucket.org/atlassian/atlassian-frontend/commits/cf16d8f8bcc) - Removes usage of tokens which have been removed from the codebase
|
|
14
|
+
- Updated dependencies
|
|
15
|
+
|
|
3
16
|
## 4.15.1
|
|
4
17
|
|
|
5
18
|
### Patch Changes
|
|
@@ -79,6 +79,20 @@ function shouldAnalyzeProperty(propertyName, targetOptions) {
|
|
|
79
79
|
}
|
|
80
80
|
return false;
|
|
81
81
|
}
|
|
82
|
+
/**
|
|
83
|
+
* Attempts to remove all non-essential words & characters from a style block.
|
|
84
|
+
* Including selectors and queries
|
|
85
|
+
* Adapted from ensure-design-token-usage
|
|
86
|
+
* @param styleString string of css properties
|
|
87
|
+
*/
|
|
88
|
+
function splitCssProperties(styleString) {
|
|
89
|
+
return styleString.split('\n').filter(function (line) {
|
|
90
|
+
return !line.trim().startsWith('@');
|
|
91
|
+
}).join('\n').replace(/\n/g, '').split(/;|(?<!\$){|(?<!\${.+?)}/) // don't split on template literal expressions i.e. `${...}`
|
|
92
|
+
.map(function (el) {
|
|
93
|
+
return el.trim() || '';
|
|
94
|
+
}).filter(Boolean);
|
|
95
|
+
}
|
|
82
96
|
var rule = {
|
|
83
97
|
meta: {
|
|
84
98
|
type: 'problem',
|
|
@@ -243,18 +257,11 @@ var rule = {
|
|
|
243
257
|
var combinedString = node.quasi.quasis.map(function (q, i) {
|
|
244
258
|
return "".concat(q.value.raw).concat(node.quasi.expressions[i] ? (0, _utils.getValue)(node.quasi.expressions[i], context) : '');
|
|
245
259
|
}).join('');
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
*/
|
|
252
|
-
var cssProperties = combinedString.split('\n').filter(function (line) {
|
|
253
|
-
return !line.trim().startsWith('@');
|
|
254
|
-
}).join('\n').replace(/\n/g, '').split(/;|(?<!\$){|(?<!\${.+?)}/) // don't split on template literal expressions i.e. `${...}`
|
|
255
|
-
.map(function (el) {
|
|
256
|
-
return el.trim() || '';
|
|
257
|
-
}).filter(Boolean);
|
|
260
|
+
var rawString = node.quasi.quasis.map(function (q, i) {
|
|
261
|
+
return "".concat(q.value.raw).concat(node.quasi.expressions[i] ? "${".concat((0, _utils.getRawExpression)(node.quasi.expressions[i], context), "}") : '');
|
|
262
|
+
}).join('');
|
|
263
|
+
var cssProperties = splitCssProperties(combinedString);
|
|
264
|
+
var unalteredCssProperties = splitCssProperties(rawString);
|
|
258
265
|
|
|
259
266
|
// Get font size
|
|
260
267
|
var fontSizeNode = cssProperties.find(function (style) {
|
|
@@ -265,7 +272,7 @@ var rule = {
|
|
|
265
272
|
return /font-size/.test(rawProperty) ? value : null;
|
|
266
273
|
});
|
|
267
274
|
var fontSize = (0, _utils.getValueFromShorthand)(fontSizeNode)[0];
|
|
268
|
-
cssProperties.forEach(function (style) {
|
|
275
|
+
cssProperties.forEach(function (style, currentPropIndex) {
|
|
269
276
|
var _style$split3 = style.split(':'),
|
|
270
277
|
_style$split4 = (0, _slicedToArray2.default)(_style$split3, 2),
|
|
271
278
|
rawProperty = _style$split4[0],
|
|
@@ -325,9 +332,9 @@ var rule = {
|
|
|
325
332
|
var textForSource = context.getSourceCode().getText(node.quasi);
|
|
326
333
|
|
|
327
334
|
// find `<property>: ...;` in original
|
|
328
|
-
var
|
|
335
|
+
var styleString = unalteredCssProperties[currentPropIndex];
|
|
329
336
|
// replace property:val with new property:val
|
|
330
|
-
var replacement = textForSource.replace(
|
|
337
|
+
var replacement = textForSource.replace(styleString, // padding: ${gridSize()}px;
|
|
331
338
|
"".concat(rawProperty, ": ").concat(replacementValue));
|
|
332
339
|
if (!replacement) {
|
|
333
340
|
return [];
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
3
4
|
Object.defineProperty(exports, "__esModule", {
|
|
4
5
|
value: true
|
|
5
6
|
});
|
|
6
7
|
exports.emToPixels = exports.convertHyphenatedNameToCamelCase = void 0;
|
|
7
8
|
exports.findIdentifierInParentScope = findIdentifierInParentScope;
|
|
8
|
-
exports.removePixelSuffix = exports.isValidSpacingValue = exports.isTypographyProperty = exports.isSpacingProperty = exports.getValueFromShorthand = exports.getValue = exports.findParentNodeForLine = void 0;
|
|
9
|
+
exports.removePixelSuffix = exports.isValidSpacingValue = exports.isTypographyProperty = exports.isSpacingProperty = exports.getValueFromShorthand = exports.getValue = exports.getRawExpression = exports.findParentNodeForLine = void 0;
|
|
10
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
9
11
|
var _eslintCodemodUtils = require("eslint-codemod-utils");
|
|
10
12
|
var typographyProperties = ['fontSize', 'fontWeight', 'fontFamily', 'lineHeight'];
|
|
11
13
|
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'];
|
|
@@ -62,6 +64,21 @@ var isCodeFontFamily = function isCodeFontFamily(node) {
|
|
|
62
64
|
var isToken = function isToken(node) {
|
|
63
65
|
return (0, _eslintCodemodUtils.isNodeOfType)(node, 'CallExpression') && (0, _eslintCodemodUtils.isNodeOfType)(node.callee, 'Identifier') && node.callee.name === 'token';
|
|
64
66
|
};
|
|
67
|
+
var getRawExpressionForToken = function getRawExpressionForToken(node, context) {
|
|
68
|
+
var args = node.arguments;
|
|
69
|
+
var call = "${token(".concat(args.map(function (argNode) {
|
|
70
|
+
if ((0, _eslintCodemodUtils.isNodeOfType)(argNode, 'Literal')) {
|
|
71
|
+
return argNode.raw;
|
|
72
|
+
}
|
|
73
|
+
if ((0, _eslintCodemodUtils.isNodeOfType)(argNode, 'Identifier')) {
|
|
74
|
+
return argNode.name;
|
|
75
|
+
}
|
|
76
|
+
if ((0, _eslintCodemodUtils.isNodeOfType)(argNode, 'MemberExpression')) {
|
|
77
|
+
return getValue(argNode, context);
|
|
78
|
+
}
|
|
79
|
+
}).join(', '), ")}");
|
|
80
|
+
return call;
|
|
81
|
+
};
|
|
65
82
|
var getValueFromCallExpression = function getValueFromCallExpression(node, context) {
|
|
66
83
|
if (!(0, _eslintCodemodUtils.isNodeOfType)(node, 'CallExpression')) {
|
|
67
84
|
return null;
|
|
@@ -82,19 +99,7 @@ var getValueFromCallExpression = function getValueFromCallExpression(node, conte
|
|
|
82
99
|
return "'SFMono-Medium', 'SF Mono', 'Segoe UI Mono', 'Roboto Mono', 'Ubuntu Mono', Menlo, Consolas, Courier, monospace";
|
|
83
100
|
}
|
|
84
101
|
if (isToken(node)) {
|
|
85
|
-
|
|
86
|
-
var call = "${token(".concat(args.map(function (argNode) {
|
|
87
|
-
if ((0, _eslintCodemodUtils.isNodeOfType)(argNode, 'Literal')) {
|
|
88
|
-
return argNode.raw;
|
|
89
|
-
}
|
|
90
|
-
if ((0, _eslintCodemodUtils.isNodeOfType)(argNode, 'Identifier')) {
|
|
91
|
-
return argNode.name;
|
|
92
|
-
}
|
|
93
|
-
if ((0, _eslintCodemodUtils.isNodeOfType)(argNode, 'MemberExpression')) {
|
|
94
|
-
return getValue(argNode, context);
|
|
95
|
-
}
|
|
96
|
-
}).join(', '), ")}");
|
|
97
|
-
return call;
|
|
102
|
+
return getRawExpressionForToken(node, context);
|
|
98
103
|
}
|
|
99
104
|
return null;
|
|
100
105
|
};
|
|
@@ -120,6 +125,19 @@ var getValue = function getValue(node, context) {
|
|
|
120
125
|
return null;
|
|
121
126
|
};
|
|
122
127
|
exports.getValue = getValue;
|
|
128
|
+
var getRawExpression = function getRawExpression(node, context) {
|
|
129
|
+
if (!(
|
|
130
|
+
// if not one of our recognized types or doesn't have a range prop, early return
|
|
131
|
+
|
|
132
|
+
(0, _eslintCodemodUtils.isNodeOfType)(node, 'Literal') || (0, _eslintCodemodUtils.isNodeOfType)(node, 'Identifier') || (0, _eslintCodemodUtils.isNodeOfType)(node, 'BinaryExpression') || (0, _eslintCodemodUtils.isNodeOfType)(node, 'UnaryExpression') || (0, _eslintCodemodUtils.isNodeOfType)(node, 'TemplateLiteral') || (0, _eslintCodemodUtils.isNodeOfType)(node, 'CallExpression')) || !Array.isArray(node.range)) {
|
|
133
|
+
return null;
|
|
134
|
+
}
|
|
135
|
+
var _node$range = (0, _slicedToArray2.default)(node.range, 2),
|
|
136
|
+
start = _node$range[0],
|
|
137
|
+
end = _node$range[1];
|
|
138
|
+
return context.getSourceCode().getText().substring(start, end);
|
|
139
|
+
};
|
|
140
|
+
exports.getRawExpression = getRawExpression;
|
|
123
141
|
var getValueFromIdentifier = function getValueFromIdentifier(node, context) {
|
|
124
142
|
if (!(0, _eslintCodemodUtils.isNodeOfType)(node, 'Identifier')) {
|
|
125
143
|
return null;
|
|
@@ -6,24 +6,24 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.isLegacyElevation = void 0;
|
|
7
7
|
var legacyElevation = {
|
|
8
8
|
e100: {
|
|
9
|
-
background: '
|
|
10
|
-
shadow: 'shadow.
|
|
9
|
+
background: 'elevation.surface.raised',
|
|
10
|
+
shadow: 'elevation.shadow.raised'
|
|
11
11
|
},
|
|
12
12
|
e200: {
|
|
13
|
-
background: '
|
|
14
|
-
shadow: 'shadow.overlay'
|
|
13
|
+
background: 'elevation.surface.overlay',
|
|
14
|
+
shadow: 'elevation.shadow.overlay'
|
|
15
15
|
},
|
|
16
16
|
e300: {
|
|
17
|
-
background: '
|
|
18
|
-
shadow: 'shadow.overlay'
|
|
17
|
+
background: 'elevation.surface.overlay',
|
|
18
|
+
shadow: 'elevation.shadow.overlay'
|
|
19
19
|
},
|
|
20
20
|
e400: {
|
|
21
|
-
background: '
|
|
22
|
-
shadow: 'shadow.overlay'
|
|
21
|
+
background: 'elevation.surface.overlay',
|
|
22
|
+
shadow: 'elevation.shadow.overlay'
|
|
23
23
|
},
|
|
24
24
|
e500: {
|
|
25
|
-
background: '
|
|
26
|
-
shadow: 'shadow.overlay'
|
|
25
|
+
background: 'elevation.surface.overlay',
|
|
26
|
+
shadow: 'elevation.shadow.overlay'
|
|
27
27
|
}
|
|
28
28
|
};
|
|
29
29
|
var isLegacyElevation = function isLegacyElevation(name) {
|
package/dist/cjs/version.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import { callExpression, identifier, isNodeOfType, literal, node as nodeFn, property } from 'eslint-codemod-utils';
|
|
4
4
|
import { spacing as spacingScale, typography as typographyTokens } from '@atlaskit/tokens/tokens-raw';
|
|
5
5
|
import { isDecendantOfGlobalToken } from '../utils/is-node';
|
|
6
|
-
import { convertHyphenatedNameToCamelCase, emToPixels, findParentNodeForLine, getValue, getValueFromShorthand, isSpacingProperty, isTypographyProperty, isValidSpacingValue } from './utils';
|
|
6
|
+
import { convertHyphenatedNameToCamelCase, emToPixels, findParentNodeForLine, getRawExpression, getValue, getValueFromShorthand, isSpacingProperty, isTypographyProperty, isValidSpacingValue } from './utils';
|
|
7
7
|
/**
|
|
8
8
|
* Currently we have a wide range of experimental spacing tokens that we are testing.
|
|
9
9
|
* We only want transforms to apply to the stable scale values, not the rest.
|
|
@@ -62,6 +62,16 @@ function shouldAnalyzeProperty(propertyName, targetOptions) {
|
|
|
62
62
|
}
|
|
63
63
|
return false;
|
|
64
64
|
}
|
|
65
|
+
/**
|
|
66
|
+
* Attempts to remove all non-essential words & characters from a style block.
|
|
67
|
+
* Including selectors and queries
|
|
68
|
+
* Adapted from ensure-design-token-usage
|
|
69
|
+
* @param styleString string of css properties
|
|
70
|
+
*/
|
|
71
|
+
function splitCssProperties(styleString) {
|
|
72
|
+
return styleString.split('\n').filter(line => !line.trim().startsWith('@')).join('\n').replace(/\n/g, '').split(/;|(?<!\$){|(?<!\${.+?)}/) // don't split on template literal expressions i.e. `${...}`
|
|
73
|
+
.map(el => el.trim() || '').filter(Boolean);
|
|
74
|
+
}
|
|
65
75
|
const rule = {
|
|
66
76
|
meta: {
|
|
67
77
|
type: 'problem',
|
|
@@ -224,14 +234,11 @@ const rule = {
|
|
|
224
234
|
const combinedString = node.quasi.quasis.map((q, i) => {
|
|
225
235
|
return `${q.value.raw}${node.quasi.expressions[i] ? getValue(node.quasi.expressions[i], context) : ''}`;
|
|
226
236
|
}).join('');
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
*/
|
|
233
|
-
const cssProperties = combinedString.split('\n').filter(line => !line.trim().startsWith('@')).join('\n').replace(/\n/g, '').split(/;|(?<!\$){|(?<!\${.+?)}/) // don't split on template literal expressions i.e. `${...}`
|
|
234
|
-
.map(el => el.trim() || '').filter(Boolean);
|
|
237
|
+
const rawString = node.quasi.quasis.map((q, i) => {
|
|
238
|
+
return `${q.value.raw}${node.quasi.expressions[i] ? `\${${getRawExpression(node.quasi.expressions[i], context)}}` : ''}`;
|
|
239
|
+
}).join('');
|
|
240
|
+
const cssProperties = splitCssProperties(combinedString);
|
|
241
|
+
const unalteredCssProperties = splitCssProperties(rawString);
|
|
235
242
|
|
|
236
243
|
// Get font size
|
|
237
244
|
const fontSizeNode = cssProperties.find(style => {
|
|
@@ -239,7 +246,7 @@ const rule = {
|
|
|
239
246
|
return /font-size/.test(rawProperty) ? value : null;
|
|
240
247
|
});
|
|
241
248
|
const fontSize = getValueFromShorthand(fontSizeNode)[0];
|
|
242
|
-
cssProperties.forEach(style => {
|
|
249
|
+
cssProperties.forEach((style, currentPropIndex) => {
|
|
243
250
|
const [rawProperty, value] = style.split(':');
|
|
244
251
|
const propertyName = convertHyphenatedNameToCamelCase(rawProperty);
|
|
245
252
|
if (!shouldAnalyzeProperty(propertyName, targetCategories)) {
|
|
@@ -294,9 +301,9 @@ const rule = {
|
|
|
294
301
|
const textForSource = context.getSourceCode().getText(node.quasi);
|
|
295
302
|
|
|
296
303
|
// find `<property>: ...;` in original
|
|
297
|
-
const
|
|
304
|
+
const styleString = unalteredCssProperties[currentPropIndex];
|
|
298
305
|
// replace property:val with new property:val
|
|
299
|
-
const replacement = textForSource.replace(
|
|
306
|
+
const replacement = textForSource.replace(styleString,
|
|
300
307
|
// padding: ${gridSize()}px;
|
|
301
308
|
`${rawProperty}: ${replacementValue}`);
|
|
302
309
|
if (!replacement) {
|
|
@@ -36,6 +36,21 @@ const isFontSizeSmall = node => isNodeOfType(node, 'CallExpression') && isNodeOf
|
|
|
36
36
|
const isFontFamily = node => isNodeOfType(node, 'CallExpression') && isNodeOfType(node.callee, 'Identifier') && (node.callee.name === 'fontFamily' || node.callee.name === 'getFontFamily');
|
|
37
37
|
const isCodeFontFamily = node => isNodeOfType(node, 'CallExpression') && isNodeOfType(node.callee, 'Identifier') && (node.callee.name === 'codeFontFamily' || node.callee.name === 'getCodeFontFamily');
|
|
38
38
|
const isToken = node => isNodeOfType(node, 'CallExpression') && isNodeOfType(node.callee, 'Identifier') && node.callee.name === 'token';
|
|
39
|
+
const getRawExpressionForToken = (node, context) => {
|
|
40
|
+
const args = node.arguments;
|
|
41
|
+
const call = `\${token(${args.map(argNode => {
|
|
42
|
+
if (isNodeOfType(argNode, 'Literal')) {
|
|
43
|
+
return argNode.raw;
|
|
44
|
+
}
|
|
45
|
+
if (isNodeOfType(argNode, 'Identifier')) {
|
|
46
|
+
return argNode.name;
|
|
47
|
+
}
|
|
48
|
+
if (isNodeOfType(argNode, 'MemberExpression')) {
|
|
49
|
+
return getValue(argNode, context);
|
|
50
|
+
}
|
|
51
|
+
}).join(', ')})}`;
|
|
52
|
+
return call;
|
|
53
|
+
};
|
|
39
54
|
const getValueFromCallExpression = (node, context) => {
|
|
40
55
|
if (!isNodeOfType(node, 'CallExpression')) {
|
|
41
56
|
return null;
|
|
@@ -56,19 +71,7 @@ const getValueFromCallExpression = (node, context) => {
|
|
|
56
71
|
return `'SFMono-Medium', 'SF Mono', 'Segoe UI Mono', 'Roboto Mono', 'Ubuntu Mono', Menlo, Consolas, Courier, monospace`;
|
|
57
72
|
}
|
|
58
73
|
if (isToken(node)) {
|
|
59
|
-
|
|
60
|
-
const call = `\${token(${args.map(argNode => {
|
|
61
|
-
if (isNodeOfType(argNode, 'Literal')) {
|
|
62
|
-
return argNode.raw;
|
|
63
|
-
}
|
|
64
|
-
if (isNodeOfType(argNode, 'Identifier')) {
|
|
65
|
-
return argNode.name;
|
|
66
|
-
}
|
|
67
|
-
if (isNodeOfType(argNode, 'MemberExpression')) {
|
|
68
|
-
return getValue(argNode, context);
|
|
69
|
-
}
|
|
70
|
-
}).join(', ')})}`;
|
|
71
|
-
return call;
|
|
74
|
+
return getRawExpressionForToken(node, context);
|
|
72
75
|
}
|
|
73
76
|
return null;
|
|
74
77
|
};
|
|
@@ -93,6 +96,16 @@ export const getValue = (node, context) => {
|
|
|
93
96
|
}
|
|
94
97
|
return null;
|
|
95
98
|
};
|
|
99
|
+
export const getRawExpression = (node, context) => {
|
|
100
|
+
if (!(
|
|
101
|
+
// if not one of our recognized types or doesn't have a range prop, early return
|
|
102
|
+
|
|
103
|
+
isNodeOfType(node, 'Literal') || isNodeOfType(node, 'Identifier') || isNodeOfType(node, 'BinaryExpression') || isNodeOfType(node, 'UnaryExpression') || isNodeOfType(node, 'TemplateLiteral') || isNodeOfType(node, 'CallExpression')) || !Array.isArray(node.range)) {
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
const [start, end] = node.range;
|
|
107
|
+
return context.getSourceCode().getText().substring(start, end);
|
|
108
|
+
};
|
|
96
109
|
const getValueFromIdentifier = (node, context) => {
|
|
97
110
|
if (!isNodeOfType(node, 'Identifier')) {
|
|
98
111
|
return null;
|
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
const legacyElevation = {
|
|
2
2
|
e100: {
|
|
3
|
-
background: '
|
|
4
|
-
shadow: 'shadow.
|
|
3
|
+
background: 'elevation.surface.raised',
|
|
4
|
+
shadow: 'elevation.shadow.raised'
|
|
5
5
|
},
|
|
6
6
|
e200: {
|
|
7
|
-
background: '
|
|
8
|
-
shadow: 'shadow.overlay'
|
|
7
|
+
background: 'elevation.surface.overlay',
|
|
8
|
+
shadow: 'elevation.shadow.overlay'
|
|
9
9
|
},
|
|
10
10
|
e300: {
|
|
11
|
-
background: '
|
|
12
|
-
shadow: 'shadow.overlay'
|
|
11
|
+
background: 'elevation.surface.overlay',
|
|
12
|
+
shadow: 'elevation.shadow.overlay'
|
|
13
13
|
},
|
|
14
14
|
e400: {
|
|
15
|
-
background: '
|
|
16
|
-
shadow: 'shadow.overlay'
|
|
15
|
+
background: 'elevation.surface.overlay',
|
|
16
|
+
shadow: 'elevation.shadow.overlay'
|
|
17
17
|
},
|
|
18
18
|
e500: {
|
|
19
|
-
background: '
|
|
20
|
-
shadow: 'shadow.overlay'
|
|
19
|
+
background: 'elevation.surface.overlay',
|
|
20
|
+
shadow: 'elevation.shadow.overlay'
|
|
21
21
|
}
|
|
22
22
|
};
|
|
23
23
|
export const isLegacyElevation = name => {
|
package/dist/es2019/version.json
CHANGED
|
@@ -7,7 +7,7 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
7
7
|
import { callExpression, identifier, isNodeOfType, literal, node as nodeFn, property } from 'eslint-codemod-utils';
|
|
8
8
|
import { spacing as spacingScale, typography as typographyTokens } from '@atlaskit/tokens/tokens-raw';
|
|
9
9
|
import { isDecendantOfGlobalToken } from '../utils/is-node';
|
|
10
|
-
import { convertHyphenatedNameToCamelCase, emToPixels, findParentNodeForLine, getValue, getValueFromShorthand, isSpacingProperty, isTypographyProperty, isValidSpacingValue } from './utils';
|
|
10
|
+
import { convertHyphenatedNameToCamelCase, emToPixels, findParentNodeForLine, getRawExpression, getValue, getValueFromShorthand, isSpacingProperty, isTypographyProperty, isValidSpacingValue } from './utils';
|
|
11
11
|
/**
|
|
12
12
|
* Currently we have a wide range of experimental spacing tokens that we are testing.
|
|
13
13
|
* We only want transforms to apply to the stable scale values, not the rest.
|
|
@@ -74,6 +74,20 @@ function shouldAnalyzeProperty(propertyName, targetOptions) {
|
|
|
74
74
|
}
|
|
75
75
|
return false;
|
|
76
76
|
}
|
|
77
|
+
/**
|
|
78
|
+
* Attempts to remove all non-essential words & characters from a style block.
|
|
79
|
+
* Including selectors and queries
|
|
80
|
+
* Adapted from ensure-design-token-usage
|
|
81
|
+
* @param styleString string of css properties
|
|
82
|
+
*/
|
|
83
|
+
function splitCssProperties(styleString) {
|
|
84
|
+
return styleString.split('\n').filter(function (line) {
|
|
85
|
+
return !line.trim().startsWith('@');
|
|
86
|
+
}).join('\n').replace(/\n/g, '').split(/;|(?<!\$){|(?<!\${.+?)}/) // don't split on template literal expressions i.e. `${...}`
|
|
87
|
+
.map(function (el) {
|
|
88
|
+
return el.trim() || '';
|
|
89
|
+
}).filter(Boolean);
|
|
90
|
+
}
|
|
77
91
|
var rule = {
|
|
78
92
|
meta: {
|
|
79
93
|
type: 'problem',
|
|
@@ -238,18 +252,11 @@ var rule = {
|
|
|
238
252
|
var combinedString = node.quasi.quasis.map(function (q, i) {
|
|
239
253
|
return "".concat(q.value.raw).concat(node.quasi.expressions[i] ? getValue(node.quasi.expressions[i], context) : '');
|
|
240
254
|
}).join('');
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
*/
|
|
247
|
-
var cssProperties = combinedString.split('\n').filter(function (line) {
|
|
248
|
-
return !line.trim().startsWith('@');
|
|
249
|
-
}).join('\n').replace(/\n/g, '').split(/;|(?<!\$){|(?<!\${.+?)}/) // don't split on template literal expressions i.e. `${...}`
|
|
250
|
-
.map(function (el) {
|
|
251
|
-
return el.trim() || '';
|
|
252
|
-
}).filter(Boolean);
|
|
255
|
+
var rawString = node.quasi.quasis.map(function (q, i) {
|
|
256
|
+
return "".concat(q.value.raw).concat(node.quasi.expressions[i] ? "${".concat(getRawExpression(node.quasi.expressions[i], context), "}") : '');
|
|
257
|
+
}).join('');
|
|
258
|
+
var cssProperties = splitCssProperties(combinedString);
|
|
259
|
+
var unalteredCssProperties = splitCssProperties(rawString);
|
|
253
260
|
|
|
254
261
|
// Get font size
|
|
255
262
|
var fontSizeNode = cssProperties.find(function (style) {
|
|
@@ -260,7 +267,7 @@ var rule = {
|
|
|
260
267
|
return /font-size/.test(rawProperty) ? value : null;
|
|
261
268
|
});
|
|
262
269
|
var fontSize = getValueFromShorthand(fontSizeNode)[0];
|
|
263
|
-
cssProperties.forEach(function (style) {
|
|
270
|
+
cssProperties.forEach(function (style, currentPropIndex) {
|
|
264
271
|
var _style$split3 = style.split(':'),
|
|
265
272
|
_style$split4 = _slicedToArray(_style$split3, 2),
|
|
266
273
|
rawProperty = _style$split4[0],
|
|
@@ -320,9 +327,9 @@ var rule = {
|
|
|
320
327
|
var textForSource = context.getSourceCode().getText(node.quasi);
|
|
321
328
|
|
|
322
329
|
// find `<property>: ...;` in original
|
|
323
|
-
var
|
|
330
|
+
var styleString = unalteredCssProperties[currentPropIndex];
|
|
324
331
|
// replace property:val with new property:val
|
|
325
|
-
var replacement = textForSource.replace(
|
|
332
|
+
var replacement = textForSource.replace(styleString, // padding: ${gridSize()}px;
|
|
326
333
|
"".concat(rawProperty, ": ").concat(replacementValue));
|
|
327
334
|
if (!replacement) {
|
|
328
335
|
return [];
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
1
2
|
import { isNodeOfType } from 'eslint-codemod-utils';
|
|
2
3
|
var typographyProperties = ['fontSize', 'fontWeight', 'fontFamily', 'lineHeight'];
|
|
3
4
|
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'];
|
|
@@ -51,6 +52,21 @@ var isCodeFontFamily = function isCodeFontFamily(node) {
|
|
|
51
52
|
var isToken = function isToken(node) {
|
|
52
53
|
return isNodeOfType(node, 'CallExpression') && isNodeOfType(node.callee, 'Identifier') && node.callee.name === 'token';
|
|
53
54
|
};
|
|
55
|
+
var getRawExpressionForToken = function getRawExpressionForToken(node, context) {
|
|
56
|
+
var args = node.arguments;
|
|
57
|
+
var call = "${token(".concat(args.map(function (argNode) {
|
|
58
|
+
if (isNodeOfType(argNode, 'Literal')) {
|
|
59
|
+
return argNode.raw;
|
|
60
|
+
}
|
|
61
|
+
if (isNodeOfType(argNode, 'Identifier')) {
|
|
62
|
+
return argNode.name;
|
|
63
|
+
}
|
|
64
|
+
if (isNodeOfType(argNode, 'MemberExpression')) {
|
|
65
|
+
return getValue(argNode, context);
|
|
66
|
+
}
|
|
67
|
+
}).join(', '), ")}");
|
|
68
|
+
return call;
|
|
69
|
+
};
|
|
54
70
|
var getValueFromCallExpression = function getValueFromCallExpression(node, context) {
|
|
55
71
|
if (!isNodeOfType(node, 'CallExpression')) {
|
|
56
72
|
return null;
|
|
@@ -71,19 +87,7 @@ var getValueFromCallExpression = function getValueFromCallExpression(node, conte
|
|
|
71
87
|
return "'SFMono-Medium', 'SF Mono', 'Segoe UI Mono', 'Roboto Mono', 'Ubuntu Mono', Menlo, Consolas, Courier, monospace";
|
|
72
88
|
}
|
|
73
89
|
if (isToken(node)) {
|
|
74
|
-
|
|
75
|
-
var call = "${token(".concat(args.map(function (argNode) {
|
|
76
|
-
if (isNodeOfType(argNode, 'Literal')) {
|
|
77
|
-
return argNode.raw;
|
|
78
|
-
}
|
|
79
|
-
if (isNodeOfType(argNode, 'Identifier')) {
|
|
80
|
-
return argNode.name;
|
|
81
|
-
}
|
|
82
|
-
if (isNodeOfType(argNode, 'MemberExpression')) {
|
|
83
|
-
return getValue(argNode, context);
|
|
84
|
-
}
|
|
85
|
-
}).join(', '), ")}");
|
|
86
|
-
return call;
|
|
90
|
+
return getRawExpressionForToken(node, context);
|
|
87
91
|
}
|
|
88
92
|
return null;
|
|
89
93
|
};
|
|
@@ -108,6 +112,18 @@ export var getValue = function getValue(node, context) {
|
|
|
108
112
|
}
|
|
109
113
|
return null;
|
|
110
114
|
};
|
|
115
|
+
export var getRawExpression = function getRawExpression(node, context) {
|
|
116
|
+
if (!(
|
|
117
|
+
// if not one of our recognized types or doesn't have a range prop, early return
|
|
118
|
+
|
|
119
|
+
isNodeOfType(node, 'Literal') || isNodeOfType(node, 'Identifier') || isNodeOfType(node, 'BinaryExpression') || isNodeOfType(node, 'UnaryExpression') || isNodeOfType(node, 'TemplateLiteral') || isNodeOfType(node, 'CallExpression')) || !Array.isArray(node.range)) {
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
122
|
+
var _node$range = _slicedToArray(node.range, 2),
|
|
123
|
+
start = _node$range[0],
|
|
124
|
+
end = _node$range[1];
|
|
125
|
+
return context.getSourceCode().getText().substring(start, end);
|
|
126
|
+
};
|
|
111
127
|
var getValueFromIdentifier = function getValueFromIdentifier(node, context) {
|
|
112
128
|
if (!isNodeOfType(node, 'Identifier')) {
|
|
113
129
|
return null;
|
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
var legacyElevation = {
|
|
2
2
|
e100: {
|
|
3
|
-
background: '
|
|
4
|
-
shadow: 'shadow.
|
|
3
|
+
background: 'elevation.surface.raised',
|
|
4
|
+
shadow: 'elevation.shadow.raised'
|
|
5
5
|
},
|
|
6
6
|
e200: {
|
|
7
|
-
background: '
|
|
8
|
-
shadow: 'shadow.overlay'
|
|
7
|
+
background: 'elevation.surface.overlay',
|
|
8
|
+
shadow: 'elevation.shadow.overlay'
|
|
9
9
|
},
|
|
10
10
|
e300: {
|
|
11
|
-
background: '
|
|
12
|
-
shadow: 'shadow.overlay'
|
|
11
|
+
background: 'elevation.surface.overlay',
|
|
12
|
+
shadow: 'elevation.shadow.overlay'
|
|
13
13
|
},
|
|
14
14
|
e400: {
|
|
15
|
-
background: '
|
|
16
|
-
shadow: 'shadow.overlay'
|
|
15
|
+
background: 'elevation.surface.overlay',
|
|
16
|
+
shadow: 'elevation.shadow.overlay'
|
|
17
17
|
},
|
|
18
18
|
e500: {
|
|
19
|
-
background: '
|
|
20
|
-
shadow: 'shadow.overlay'
|
|
19
|
+
background: 'elevation.surface.overlay',
|
|
20
|
+
shadow: 'elevation.shadow.overlay'
|
|
21
21
|
}
|
|
22
22
|
};
|
|
23
23
|
export var isLegacyElevation = function isLegacyElevation(name) {
|
package/dist/esm/version.json
CHANGED
|
@@ -8,6 +8,7 @@ export declare const isSpacingProperty: (propertyName: string) => boolean;
|
|
|
8
8
|
export declare const isTypographyProperty: (propertyName: string) => boolean;
|
|
9
9
|
export declare const getValueFromShorthand: (str: unknown) => any[];
|
|
10
10
|
export declare const getValue: (node: EslintNode, context: Rule.RuleContext) => string | number | any[] | null | undefined;
|
|
11
|
+
export declare const getRawExpression: (node: EslintNode, context: Rule.RuleContext) => string | null;
|
|
11
12
|
export declare const emToPixels: <T extends unknown>(value: T, fontSize: number | null | undefined) => number | T | null;
|
|
12
13
|
export declare const removePixelSuffix: (value: string | number) => string | number;
|
|
13
14
|
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": "4.15.
|
|
4
|
+
"version": "4.15.3",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
".": "./src/index.tsx"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@atlaskit/tokens": "^
|
|
36
|
+
"@atlaskit/tokens": "^1.1.0",
|
|
37
37
|
"@babel/runtime": "^7.0.0",
|
|
38
38
|
"eslint-codemod-utils": "^1.5.0"
|
|
39
39
|
},
|