@atlaskit/eslint-plugin-design-system 8.19.2 → 8.20.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 +10 -0
- package/constellation/index/usage.mdx +1 -1
- package/dist/cjs/rules/consistent-css-prop-usage/index.js +13 -4
- package/dist/cjs/rules/use-primitives/utils/convert-ast-object-expression-to-js-object.js +24 -32
- package/dist/cjs/rules/use-primitives/utils/is-valid-css-properties-to-transform.js +7 -3
- package/dist/es2019/rules/consistent-css-prop-usage/index.js +12 -4
- package/dist/es2019/rules/use-primitives/utils/convert-ast-object-expression-to-js-object.js +23 -32
- package/dist/es2019/rules/use-primitives/utils/is-valid-css-properties-to-transform.js +6 -3
- package/dist/esm/rules/consistent-css-prop-usage/index.js +13 -4
- package/dist/esm/rules/use-primitives/utils/convert-ast-object-expression-to-js-object.js +23 -32
- package/dist/esm/rules/use-primitives/utils/is-valid-css-properties-to-transform.js +7 -3
- package/dist/types/rules/use-primitives/utils/convert-ast-object-expression-to-js-object.d.ts +6 -2
- package/dist/types-ts4.5/rules/use-primitives/utils/convert-ast-object-expression-to-js-object.d.ts +6 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# @atlaskit/eslint-plugin-design-system
|
|
2
2
|
|
|
3
|
+
## 8.20.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#66409](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/66409) [`f6c48f4a67c1`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/f6c48f4a67c1) - Implemented functionality for the consistent-css-prop-usage rule to account for cssMap usages
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- [#66604](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/66604) [`3205b1daf57f`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/3205b1daf57f) - Refactor internal logic of `use-primitives` to better handle cases it will not suggest transformations for, based on the value of CSS properties.
|
|
12
|
+
|
|
3
13
|
## 8.19.2
|
|
4
14
|
|
|
5
15
|
### Patch Changes
|
|
@@ -142,7 +142,7 @@ This rule comes with options to support different repository configurations.
|
|
|
142
142
|
|
|
143
143
|
#### cssFunctions
|
|
144
144
|
|
|
145
|
-
An array of function names the linting rule should target. Defaults to `['css', 'xcss']`.
|
|
145
|
+
An array of function names the linting rule should target. Defaults to `['css', 'xcss']`. Functionality of cssMap will be linted regardless of the configuration of `cssFunctions` as it can be used with either attribute.
|
|
146
146
|
|
|
147
147
|
#### stylesPlacement
|
|
148
148
|
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.default = void 0;
|
|
8
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
9
10
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
10
11
|
var _eslintCodemodUtils = require("eslint-codemod-utils");
|
|
11
12
|
var _assign = _interopRequireDefault(require("lodash/assign"));
|
|
@@ -25,9 +26,9 @@ function findSpreadProperties(node) {
|
|
|
25
26
|
});
|
|
26
27
|
}
|
|
27
28
|
function analyzeIdentifier(context, sourceIdentifier, configuration) {
|
|
28
|
-
var _getIdentifierInParen;
|
|
29
|
+
var _getIdentifierInParen, _getIdentifierInParen2;
|
|
29
30
|
var scope = context.getScope();
|
|
30
|
-
var _ref = (
|
|
31
|
+
var _ref = (_getIdentifierInParen = (_getIdentifierInParen2 = (0, _eslintCodemodUtils.getIdentifierInParentScope)(scope, sourceIdentifier.name)) === null || _getIdentifierInParen2 === void 0 ? void 0 : _getIdentifierInParen2.identifiers) !== null && _getIdentifierInParen !== void 0 ? _getIdentifierInParen : [],
|
|
31
32
|
_ref2 = (0, _slicedToArray2.default)(_ref, 1),
|
|
32
33
|
identifier = _ref2[0];
|
|
33
34
|
if (!identifier || !identifier.parent) {
|
|
@@ -50,7 +51,7 @@ function analyzeIdentifier(context, sourceIdentifier, configuration) {
|
|
|
50
51
|
});
|
|
51
52
|
return;
|
|
52
53
|
}
|
|
53
|
-
if (identifier.parent && identifier.parent.init && !isCssCallExpression(identifier.parent.init, configuration.cssFunctions)) {
|
|
54
|
+
if (identifier.parent && identifier.parent.init && !isCssCallExpression(identifier.parent.init, [].concat((0, _toConsumableArray2.default)(configuration.cssFunctions), ['cssMap']))) {
|
|
54
55
|
// When variable value is not of type css({})
|
|
55
56
|
context.report({
|
|
56
57
|
node: identifier,
|
|
@@ -69,6 +70,13 @@ function analyzeIdentifier(context, sourceIdentifier, configuration) {
|
|
|
69
70
|
});
|
|
70
71
|
}
|
|
71
72
|
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Handle different cases based on what's been passed in the css-related JSXAttribute
|
|
76
|
+
* @param context the context of the node
|
|
77
|
+
* @param expression the expression of the JSXAttribute value
|
|
78
|
+
* @param configuration what css-related functions to account for (eg. css, xcss, cssMap), and whether to detect bottom vs top expressions
|
|
79
|
+
*/
|
|
72
80
|
var traverseExpressionWithConfig = function traverseExpressionWithConfig(context, expression, configuration) {
|
|
73
81
|
function traverseExpression(expression) {
|
|
74
82
|
switch (expression.type) {
|
|
@@ -140,7 +148,8 @@ var rule = (0, _createRule.createLintRule)({
|
|
|
140
148
|
create: function create(context) {
|
|
141
149
|
var _ref3;
|
|
142
150
|
var mergedConfig = (0, _assign.default)({}, defaultConfig, context.options[0]);
|
|
143
|
-
var
|
|
151
|
+
var callSelectorFunctions = [].concat((0, _toConsumableArray2.default)(mergedConfig.cssFunctions), ['cssMap']);
|
|
152
|
+
var callSelector = callSelectorFunctions.map(function (fn) {
|
|
144
153
|
return "CallExpression[callee.name=".concat(fn, "]");
|
|
145
154
|
}).join(',');
|
|
146
155
|
return _ref3 = {}, (0, _defineProperty2.default)(_ref3, callSelector, function (node) {
|
|
@@ -3,34 +3,24 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.convertASTObjectExpressionToJSObject = void 0;
|
|
6
|
+
exports.convertASTObjectExpressionToJSObject = exports.SPREAD_SYNTAX = void 0;
|
|
7
7
|
var _eslintCodemodUtils = require("eslint-codemod-utils");
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
var SPREAD_SYNTAX = exports.SPREAD_SYNTAX = Symbol('SPREAD_SYNTAX');
|
|
10
9
|
/**
|
|
11
10
|
* Note: Not recursive. Only handles top level key/value pairs
|
|
12
11
|
*/
|
|
13
12
|
var convertASTObjectExpressionToJSObject = exports.convertASTObjectExpressionToJSObject = function convertASTObjectExpressionToJSObject(styles) {
|
|
14
|
-
var styleObj = {
|
|
13
|
+
var styleObj = {
|
|
14
|
+
unsupported: []
|
|
15
|
+
};
|
|
15
16
|
|
|
16
|
-
// if we see any spread props we
|
|
17
|
+
// if we see any spread props we indicate that as unsupported
|
|
17
18
|
if (!styles.properties.every(function (prop) {
|
|
18
19
|
return (0, _eslintCodemodUtils.isNodeOfType)(prop, 'Property');
|
|
19
20
|
})) {
|
|
20
|
-
|
|
21
|
+
styleObj.unsupported.push(SPREAD_SYNTAX);
|
|
21
22
|
}
|
|
22
|
-
|
|
23
|
-
// TODO: https://product-fabric.atlassian.net/browse/DSP-16055
|
|
24
|
-
// We need to harden this logic asap.
|
|
25
|
-
// It currently generates a false positive for:
|
|
26
|
-
// styled.div({
|
|
27
|
-
// marginTop: "0px",
|
|
28
|
-
// marginBottom: blah(...),
|
|
29
|
-
// })
|
|
30
|
-
// as the value for `marginBottom` is not a string nor a `token` call, it is just skipped
|
|
31
|
-
// from the resulting map and this is inaccurate.
|
|
32
23
|
styles.properties.forEach(function (prop) {
|
|
33
|
-
// cases we want to skip (see note above)
|
|
34
24
|
if (!(0, _eslintCodemodUtils.isNodeOfType)(prop, 'Property')) {
|
|
35
25
|
return;
|
|
36
26
|
}
|
|
@@ -41,28 +31,30 @@ var convertASTObjectExpressionToJSObject = exports.convertASTObjectExpressionToJ
|
|
|
41
31
|
// a literal string value, the base case
|
|
42
32
|
if ((0, _eslintCodemodUtils.isNodeOfType)(prop.value, 'Literal') && typeof prop.value.value === 'string') {
|
|
43
33
|
styleObj[prop.key.name] = prop.value.value;
|
|
34
|
+
return;
|
|
44
35
|
}
|
|
45
36
|
|
|
46
37
|
// try to handle a direct call to `token`
|
|
47
38
|
if ((0, _eslintCodemodUtils.isNodeOfType)(prop.value, 'CallExpression')) {
|
|
48
|
-
var _callExpression$argum;
|
|
49
39
|
var callExpression = prop.value;
|
|
50
|
-
//
|
|
51
|
-
if (
|
|
52
|
-
|
|
40
|
+
// strictly handle calls to `token`
|
|
41
|
+
if ((0, _eslintCodemodUtils.isNodeOfType)(callExpression.callee, 'Identifier') && callExpression.callee.name === 'token') {
|
|
42
|
+
// only two valid cases are supported
|
|
43
|
+
// one argument => token('space.100')
|
|
44
|
+
// two arguments => token('space.100', '8px')
|
|
45
|
+
if ((callExpression.arguments.length === 1 || callExpression.arguments.length === 2) && (0, _eslintCodemodUtils.isNodeOfType)(callExpression.arguments[0], 'Literal') && (typeof callExpression.arguments[1] === 'undefined' || (0, _eslintCodemodUtils.isNodeOfType)(callExpression.arguments[1], 'Literal'))) {
|
|
46
|
+
var _callExpression$argum;
|
|
47
|
+
styleObj[prop.key.name] = {
|
|
48
|
+
tokenName: String(callExpression.arguments[0].value),
|
|
49
|
+
fallbackValue: (_callExpression$argum = callExpression.arguments[1]) !== null && _callExpression$argum !== void 0 && _callExpression$argum.value ? String(callExpression.arguments[1].value) : undefined
|
|
50
|
+
};
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
53
|
}
|
|
54
|
-
|
|
55
|
-
// only two valid cases are supported
|
|
56
|
-
// one argument => token('space.100')
|
|
57
|
-
// two arguments => token('space.100', '8px')
|
|
58
|
-
if (callExpression.arguments.length !== 1 && callExpression.arguments.length !== 2 || !(0, _eslintCodemodUtils.isNodeOfType)(callExpression.arguments[0], 'Literal') || callExpression.arguments[1] && !(0, _eslintCodemodUtils.isNodeOfType)(callExpression.arguments[1], 'Literal')) {
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
styleObj[prop.key.name] = {
|
|
62
|
-
tokenName: String(callExpression.arguments[0].value),
|
|
63
|
-
fallbackValue: (_callExpression$argum = callExpression.arguments[1]) !== null && _callExpression$argum !== void 0 && _callExpression$argum.value ? String(callExpression.arguments[1].value) : undefined
|
|
64
|
-
};
|
|
65
54
|
}
|
|
55
|
+
|
|
56
|
+
// if we get here we have an unsupported value
|
|
57
|
+
styleObj.unsupported.push(prop.key.name);
|
|
66
58
|
});
|
|
67
59
|
return styleObj;
|
|
68
60
|
};
|
|
@@ -6,18 +6,22 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.isValidCssPropertiesToTransform = void 0;
|
|
8
8
|
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
9
|
+
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
9
10
|
var _eslintCodemodUtils = require("eslint-codemod-utils");
|
|
10
11
|
var _cssToXcss = require("../transformers/css-to-xcss");
|
|
11
12
|
var _convertAstObjectExpressionToJsObject = require("./convert-ast-object-expression-to-js-object");
|
|
13
|
+
var _excluded = ["unsupported"];
|
|
12
14
|
var isValidCssPropertiesToTransform = exports.isValidCssPropertiesToTransform = function isValidCssPropertiesToTransform(node, config) {
|
|
13
15
|
var cssObjectExpression = node.arguments[0];
|
|
14
16
|
// Bail on empty object calls
|
|
15
17
|
if (!cssObjectExpression || !(0, _eslintCodemodUtils.isNodeOfType)(cssObjectExpression, 'ObjectExpression')) {
|
|
16
18
|
return false;
|
|
17
19
|
}
|
|
18
|
-
var
|
|
19
|
-
|
|
20
|
-
|
|
20
|
+
var _convertASTObjectExpr = (0, _convertAstObjectExpressionToJsObject.convertASTObjectExpressionToJSObject)(cssObjectExpression),
|
|
21
|
+
unsupported = _convertASTObjectExpr.unsupported,
|
|
22
|
+
cssObject = (0, _objectWithoutProperties2.default)(_convertASTObjectExpr, _excluded);
|
|
23
|
+
// Bail if there are any unsupported styles
|
|
24
|
+
if (unsupported.length > 0 || Object.keys(cssObject).length !== 1) {
|
|
21
25
|
return false;
|
|
22
26
|
}
|
|
23
27
|
// Short-circuit when token calls are found but pattern is not enabled in config
|
|
@@ -14,9 +14,9 @@ function findSpreadProperties(node) {
|
|
|
14
14
|
property.type === 'ExperimentalSpreadProperty');
|
|
15
15
|
}
|
|
16
16
|
function analyzeIdentifier(context, sourceIdentifier, configuration) {
|
|
17
|
-
var _getIdentifierInParen;
|
|
17
|
+
var _getIdentifierInParen, _getIdentifierInParen2;
|
|
18
18
|
const scope = context.getScope();
|
|
19
|
-
const [identifier] = (
|
|
19
|
+
const [identifier] = (_getIdentifierInParen = (_getIdentifierInParen2 = getIdentifierInParentScope(scope, sourceIdentifier.name)) === null || _getIdentifierInParen2 === void 0 ? void 0 : _getIdentifierInParen2.identifiers) !== null && _getIdentifierInParen !== void 0 ? _getIdentifierInParen : [];
|
|
20
20
|
if (!identifier || !identifier.parent) {
|
|
21
21
|
// Identifier isn't in the module, skip!
|
|
22
22
|
return;
|
|
@@ -37,7 +37,7 @@ function analyzeIdentifier(context, sourceIdentifier, configuration) {
|
|
|
37
37
|
});
|
|
38
38
|
return;
|
|
39
39
|
}
|
|
40
|
-
if (identifier.parent && identifier.parent.init && !isCssCallExpression(identifier.parent.init, configuration.cssFunctions)) {
|
|
40
|
+
if (identifier.parent && identifier.parent.init && !isCssCallExpression(identifier.parent.init, [...configuration.cssFunctions, 'cssMap'])) {
|
|
41
41
|
// When variable value is not of type css({})
|
|
42
42
|
context.report({
|
|
43
43
|
node: identifier,
|
|
@@ -56,6 +56,13 @@ function analyzeIdentifier(context, sourceIdentifier, configuration) {
|
|
|
56
56
|
});
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Handle different cases based on what's been passed in the css-related JSXAttribute
|
|
62
|
+
* @param context the context of the node
|
|
63
|
+
* @param expression the expression of the JSXAttribute value
|
|
64
|
+
* @param configuration what css-related functions to account for (eg. css, xcss, cssMap), and whether to detect bottom vs top expressions
|
|
65
|
+
*/
|
|
59
66
|
const traverseExpressionWithConfig = (context, expression, configuration) => {
|
|
60
67
|
function traverseExpression(expression) {
|
|
61
68
|
switch (expression.type) {
|
|
@@ -124,7 +131,8 @@ const rule = createLintRule({
|
|
|
124
131
|
},
|
|
125
132
|
create(context) {
|
|
126
133
|
const mergedConfig = assign({}, defaultConfig, context.options[0]);
|
|
127
|
-
const
|
|
134
|
+
const callSelectorFunctions = [...mergedConfig.cssFunctions, 'cssMap'];
|
|
135
|
+
const callSelector = callSelectorFunctions.map(fn => `CallExpression[callee.name=${fn}]`).join(',');
|
|
128
136
|
return {
|
|
129
137
|
[callSelector]: node => {
|
|
130
138
|
if (node.parent.type !== 'VariableDeclarator') {
|
package/dist/es2019/rules/use-primitives/utils/convert-ast-object-expression-to-js-object.js
CHANGED
|
@@ -1,29 +1,18 @@
|
|
|
1
1
|
import { isNodeOfType } from 'eslint-codemod-utils';
|
|
2
|
-
|
|
3
|
-
// FIXME: This is only loosely typed
|
|
4
|
-
|
|
2
|
+
export const SPREAD_SYNTAX = Symbol('SPREAD_SYNTAX');
|
|
5
3
|
/**
|
|
6
4
|
* Note: Not recursive. Only handles top level key/value pairs
|
|
7
5
|
*/
|
|
8
6
|
export const convertASTObjectExpressionToJSObject = styles => {
|
|
9
|
-
const styleObj = {
|
|
7
|
+
const styleObj = {
|
|
8
|
+
unsupported: []
|
|
9
|
+
};
|
|
10
10
|
|
|
11
|
-
// if we see any spread props we
|
|
11
|
+
// if we see any spread props we indicate that as unsupported
|
|
12
12
|
if (!styles.properties.every(prop => isNodeOfType(prop, 'Property'))) {
|
|
13
|
-
|
|
13
|
+
styleObj.unsupported.push(SPREAD_SYNTAX);
|
|
14
14
|
}
|
|
15
|
-
|
|
16
|
-
// TODO: https://product-fabric.atlassian.net/browse/DSP-16055
|
|
17
|
-
// We need to harden this logic asap.
|
|
18
|
-
// It currently generates a false positive for:
|
|
19
|
-
// styled.div({
|
|
20
|
-
// marginTop: "0px",
|
|
21
|
-
// marginBottom: blah(...),
|
|
22
|
-
// })
|
|
23
|
-
// as the value for `marginBottom` is not a string nor a `token` call, it is just skipped
|
|
24
|
-
// from the resulting map and this is inaccurate.
|
|
25
15
|
styles.properties.forEach(prop => {
|
|
26
|
-
// cases we want to skip (see note above)
|
|
27
16
|
if (!isNodeOfType(prop, 'Property')) {
|
|
28
17
|
return;
|
|
29
18
|
}
|
|
@@ -34,28 +23,30 @@ export const convertASTObjectExpressionToJSObject = styles => {
|
|
|
34
23
|
// a literal string value, the base case
|
|
35
24
|
if (isNodeOfType(prop.value, 'Literal') && typeof prop.value.value === 'string') {
|
|
36
25
|
styleObj[prop.key.name] = prop.value.value;
|
|
26
|
+
return;
|
|
37
27
|
}
|
|
38
28
|
|
|
39
29
|
// try to handle a direct call to `token`
|
|
40
30
|
if (isNodeOfType(prop.value, 'CallExpression')) {
|
|
41
|
-
var _callExpression$argum;
|
|
42
31
|
const callExpression = prop.value;
|
|
43
|
-
//
|
|
44
|
-
if (
|
|
45
|
-
|
|
32
|
+
// strictly handle calls to `token`
|
|
33
|
+
if (isNodeOfType(callExpression.callee, 'Identifier') && callExpression.callee.name === 'token') {
|
|
34
|
+
// only two valid cases are supported
|
|
35
|
+
// one argument => token('space.100')
|
|
36
|
+
// two arguments => token('space.100', '8px')
|
|
37
|
+
if ((callExpression.arguments.length === 1 || callExpression.arguments.length === 2) && isNodeOfType(callExpression.arguments[0], 'Literal') && (typeof callExpression.arguments[1] === 'undefined' || isNodeOfType(callExpression.arguments[1], 'Literal'))) {
|
|
38
|
+
var _callExpression$argum;
|
|
39
|
+
styleObj[prop.key.name] = {
|
|
40
|
+
tokenName: String(callExpression.arguments[0].value),
|
|
41
|
+
fallbackValue: (_callExpression$argum = callExpression.arguments[1]) !== null && _callExpression$argum !== void 0 && _callExpression$argum.value ? String(callExpression.arguments[1].value) : undefined
|
|
42
|
+
};
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
46
45
|
}
|
|
47
|
-
|
|
48
|
-
// only two valid cases are supported
|
|
49
|
-
// one argument => token('space.100')
|
|
50
|
-
// two arguments => token('space.100', '8px')
|
|
51
|
-
if (callExpression.arguments.length !== 1 && callExpression.arguments.length !== 2 || !isNodeOfType(callExpression.arguments[0], 'Literal') || callExpression.arguments[1] && !isNodeOfType(callExpression.arguments[1], 'Literal')) {
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
styleObj[prop.key.name] = {
|
|
55
|
-
tokenName: String(callExpression.arguments[0].value),
|
|
56
|
-
fallbackValue: (_callExpression$argum = callExpression.arguments[1]) !== null && _callExpression$argum !== void 0 && _callExpression$argum.value ? String(callExpression.arguments[1].value) : undefined
|
|
57
|
-
};
|
|
58
46
|
}
|
|
47
|
+
|
|
48
|
+
// if we get here we have an unsupported value
|
|
49
|
+
styleObj.unsupported.push(prop.key.name);
|
|
59
50
|
});
|
|
60
51
|
return styleObj;
|
|
61
52
|
};
|
|
@@ -7,9 +7,12 @@ export const isValidCssPropertiesToTransform = (node, config) => {
|
|
|
7
7
|
if (!cssObjectExpression || !isNodeOfType(cssObjectExpression, 'ObjectExpression')) {
|
|
8
8
|
return false;
|
|
9
9
|
}
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
const {
|
|
11
|
+
unsupported,
|
|
12
|
+
...cssObject
|
|
13
|
+
} = convertASTObjectExpressionToJSObject(cssObjectExpression);
|
|
14
|
+
// Bail if there are any unsupported styles
|
|
15
|
+
if (unsupported.length > 0 || Object.keys(cssObject).length !== 1) {
|
|
13
16
|
return false;
|
|
14
17
|
}
|
|
15
18
|
// Short-circuit when token calls are found but pattern is not enabled in config
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
+
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
2
3
|
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
3
4
|
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
4
5
|
|
|
@@ -18,9 +19,9 @@ function findSpreadProperties(node) {
|
|
|
18
19
|
});
|
|
19
20
|
}
|
|
20
21
|
function analyzeIdentifier(context, sourceIdentifier, configuration) {
|
|
21
|
-
var _getIdentifierInParen;
|
|
22
|
+
var _getIdentifierInParen, _getIdentifierInParen2;
|
|
22
23
|
var scope = context.getScope();
|
|
23
|
-
var _ref = (
|
|
24
|
+
var _ref = (_getIdentifierInParen = (_getIdentifierInParen2 = getIdentifierInParentScope(scope, sourceIdentifier.name)) === null || _getIdentifierInParen2 === void 0 ? void 0 : _getIdentifierInParen2.identifiers) !== null && _getIdentifierInParen !== void 0 ? _getIdentifierInParen : [],
|
|
24
25
|
_ref2 = _slicedToArray(_ref, 1),
|
|
25
26
|
identifier = _ref2[0];
|
|
26
27
|
if (!identifier || !identifier.parent) {
|
|
@@ -43,7 +44,7 @@ function analyzeIdentifier(context, sourceIdentifier, configuration) {
|
|
|
43
44
|
});
|
|
44
45
|
return;
|
|
45
46
|
}
|
|
46
|
-
if (identifier.parent && identifier.parent.init && !isCssCallExpression(identifier.parent.init, configuration.cssFunctions)) {
|
|
47
|
+
if (identifier.parent && identifier.parent.init && !isCssCallExpression(identifier.parent.init, [].concat(_toConsumableArray(configuration.cssFunctions), ['cssMap']))) {
|
|
47
48
|
// When variable value is not of type css({})
|
|
48
49
|
context.report({
|
|
49
50
|
node: identifier,
|
|
@@ -62,6 +63,13 @@ function analyzeIdentifier(context, sourceIdentifier, configuration) {
|
|
|
62
63
|
});
|
|
63
64
|
}
|
|
64
65
|
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Handle different cases based on what's been passed in the css-related JSXAttribute
|
|
69
|
+
* @param context the context of the node
|
|
70
|
+
* @param expression the expression of the JSXAttribute value
|
|
71
|
+
* @param configuration what css-related functions to account for (eg. css, xcss, cssMap), and whether to detect bottom vs top expressions
|
|
72
|
+
*/
|
|
65
73
|
var traverseExpressionWithConfig = function traverseExpressionWithConfig(context, expression, configuration) {
|
|
66
74
|
function traverseExpression(expression) {
|
|
67
75
|
switch (expression.type) {
|
|
@@ -133,7 +141,8 @@ var rule = createLintRule({
|
|
|
133
141
|
create: function create(context) {
|
|
134
142
|
var _ref3;
|
|
135
143
|
var mergedConfig = assign({}, defaultConfig, context.options[0]);
|
|
136
|
-
var
|
|
144
|
+
var callSelectorFunctions = [].concat(_toConsumableArray(mergedConfig.cssFunctions), ['cssMap']);
|
|
145
|
+
var callSelector = callSelectorFunctions.map(function (fn) {
|
|
137
146
|
return "CallExpression[callee.name=".concat(fn, "]");
|
|
138
147
|
}).join(',');
|
|
139
148
|
return _ref3 = {}, _defineProperty(_ref3, callSelector, function (node) {
|
|
@@ -1,31 +1,20 @@
|
|
|
1
1
|
import { isNodeOfType } from 'eslint-codemod-utils';
|
|
2
|
-
|
|
3
|
-
// FIXME: This is only loosely typed
|
|
4
|
-
|
|
2
|
+
export var SPREAD_SYNTAX = Symbol('SPREAD_SYNTAX');
|
|
5
3
|
/**
|
|
6
4
|
* Note: Not recursive. Only handles top level key/value pairs
|
|
7
5
|
*/
|
|
8
6
|
export var convertASTObjectExpressionToJSObject = function convertASTObjectExpressionToJSObject(styles) {
|
|
9
|
-
var styleObj = {
|
|
7
|
+
var styleObj = {
|
|
8
|
+
unsupported: []
|
|
9
|
+
};
|
|
10
10
|
|
|
11
|
-
// if we see any spread props we
|
|
11
|
+
// if we see any spread props we indicate that as unsupported
|
|
12
12
|
if (!styles.properties.every(function (prop) {
|
|
13
13
|
return isNodeOfType(prop, 'Property');
|
|
14
14
|
})) {
|
|
15
|
-
|
|
15
|
+
styleObj.unsupported.push(SPREAD_SYNTAX);
|
|
16
16
|
}
|
|
17
|
-
|
|
18
|
-
// TODO: https://product-fabric.atlassian.net/browse/DSP-16055
|
|
19
|
-
// We need to harden this logic asap.
|
|
20
|
-
// It currently generates a false positive for:
|
|
21
|
-
// styled.div({
|
|
22
|
-
// marginTop: "0px",
|
|
23
|
-
// marginBottom: blah(...),
|
|
24
|
-
// })
|
|
25
|
-
// as the value for `marginBottom` is not a string nor a `token` call, it is just skipped
|
|
26
|
-
// from the resulting map and this is inaccurate.
|
|
27
17
|
styles.properties.forEach(function (prop) {
|
|
28
|
-
// cases we want to skip (see note above)
|
|
29
18
|
if (!isNodeOfType(prop, 'Property')) {
|
|
30
19
|
return;
|
|
31
20
|
}
|
|
@@ -36,28 +25,30 @@ export var convertASTObjectExpressionToJSObject = function convertASTObjectExpre
|
|
|
36
25
|
// a literal string value, the base case
|
|
37
26
|
if (isNodeOfType(prop.value, 'Literal') && typeof prop.value.value === 'string') {
|
|
38
27
|
styleObj[prop.key.name] = prop.value.value;
|
|
28
|
+
return;
|
|
39
29
|
}
|
|
40
30
|
|
|
41
31
|
// try to handle a direct call to `token`
|
|
42
32
|
if (isNodeOfType(prop.value, 'CallExpression')) {
|
|
43
|
-
var _callExpression$argum;
|
|
44
33
|
var callExpression = prop.value;
|
|
45
|
-
//
|
|
46
|
-
if (
|
|
47
|
-
|
|
34
|
+
// strictly handle calls to `token`
|
|
35
|
+
if (isNodeOfType(callExpression.callee, 'Identifier') && callExpression.callee.name === 'token') {
|
|
36
|
+
// only two valid cases are supported
|
|
37
|
+
// one argument => token('space.100')
|
|
38
|
+
// two arguments => token('space.100', '8px')
|
|
39
|
+
if ((callExpression.arguments.length === 1 || callExpression.arguments.length === 2) && isNodeOfType(callExpression.arguments[0], 'Literal') && (typeof callExpression.arguments[1] === 'undefined' || isNodeOfType(callExpression.arguments[1], 'Literal'))) {
|
|
40
|
+
var _callExpression$argum;
|
|
41
|
+
styleObj[prop.key.name] = {
|
|
42
|
+
tokenName: String(callExpression.arguments[0].value),
|
|
43
|
+
fallbackValue: (_callExpression$argum = callExpression.arguments[1]) !== null && _callExpression$argum !== void 0 && _callExpression$argum.value ? String(callExpression.arguments[1].value) : undefined
|
|
44
|
+
};
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
48
47
|
}
|
|
49
|
-
|
|
50
|
-
// only two valid cases are supported
|
|
51
|
-
// one argument => token('space.100')
|
|
52
|
-
// two arguments => token('space.100', '8px')
|
|
53
|
-
if (callExpression.arguments.length !== 1 && callExpression.arguments.length !== 2 || !isNodeOfType(callExpression.arguments[0], 'Literal') || callExpression.arguments[1] && !isNodeOfType(callExpression.arguments[1], 'Literal')) {
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
styleObj[prop.key.name] = {
|
|
57
|
-
tokenName: String(callExpression.arguments[0].value),
|
|
58
|
-
fallbackValue: (_callExpression$argum = callExpression.arguments[1]) !== null && _callExpression$argum !== void 0 && _callExpression$argum.value ? String(callExpression.arguments[1].value) : undefined
|
|
59
|
-
};
|
|
60
48
|
}
|
|
49
|
+
|
|
50
|
+
// if we get here we have an unsupported value
|
|
51
|
+
styleObj.unsupported.push(prop.key.name);
|
|
61
52
|
});
|
|
62
53
|
return styleObj;
|
|
63
54
|
};
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import _typeof from "@babel/runtime/helpers/typeof";
|
|
2
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
3
|
+
var _excluded = ["unsupported"];
|
|
2
4
|
import { isNodeOfType } from 'eslint-codemod-utils';
|
|
3
5
|
import { supportedStylesMap } from '../transformers/css-to-xcss';
|
|
4
6
|
import { convertASTObjectExpressionToJSObject } from './convert-ast-object-expression-to-js-object';
|
|
@@ -8,9 +10,11 @@ export var isValidCssPropertiesToTransform = function isValidCssPropertiesToTran
|
|
|
8
10
|
if (!cssObjectExpression || !isNodeOfType(cssObjectExpression, 'ObjectExpression')) {
|
|
9
11
|
return false;
|
|
10
12
|
}
|
|
11
|
-
var
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
var _convertASTObjectExpr = convertASTObjectExpressionToJSObject(cssObjectExpression),
|
|
14
|
+
unsupported = _convertASTObjectExpr.unsupported,
|
|
15
|
+
cssObject = _objectWithoutProperties(_convertASTObjectExpr, _excluded);
|
|
16
|
+
// Bail if there are any unsupported styles
|
|
17
|
+
if (unsupported.length > 0 || Object.keys(cssObject).length !== 1) {
|
|
14
18
|
return false;
|
|
15
19
|
}
|
|
16
20
|
// Short-circuit when token calls are found but pattern is not enabled in config
|
package/dist/types/rules/use-primitives/utils/convert-ast-object-expression-to-js-object.d.ts
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
|
+
import type { CSSProperties } from 'react';
|
|
1
2
|
import type { Rule } from 'eslint';
|
|
2
3
|
import { ObjectExpression } from 'eslint-codemod-utils';
|
|
4
|
+
export declare const SPREAD_SYNTAX: unique symbol;
|
|
3
5
|
type Token = {
|
|
4
6
|
tokenName: string;
|
|
5
7
|
fallbackValue: string | undefined;
|
|
6
8
|
};
|
|
7
9
|
export type CSSPropStyleObject = {
|
|
8
|
-
[key
|
|
10
|
+
[key in keyof CSSProperties]: string | number | Token;
|
|
11
|
+
} & {
|
|
12
|
+
unsupported: (keyof CSSProperties | typeof SPREAD_SYNTAX)[];
|
|
9
13
|
};
|
|
10
14
|
/**
|
|
11
15
|
* Note: Not recursive. Only handles top level key/value pairs
|
|
12
16
|
*/
|
|
13
|
-
export declare const convertASTObjectExpressionToJSObject: (styles: ObjectExpression & Partial<Rule.NodeParentExtension>) => CSSPropStyleObject
|
|
17
|
+
export declare const convertASTObjectExpressionToJSObject: (styles: ObjectExpression & Partial<Rule.NodeParentExtension>) => CSSPropStyleObject;
|
|
14
18
|
export {};
|
package/dist/types-ts4.5/rules/use-primitives/utils/convert-ast-object-expression-to-js-object.d.ts
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
|
+
import type { CSSProperties } from 'react';
|
|
1
2
|
import type { Rule } from 'eslint';
|
|
2
3
|
import { ObjectExpression } from 'eslint-codemod-utils';
|
|
4
|
+
export declare const SPREAD_SYNTAX: unique symbol;
|
|
3
5
|
type Token = {
|
|
4
6
|
tokenName: string;
|
|
5
7
|
fallbackValue: string | undefined;
|
|
6
8
|
};
|
|
7
9
|
export type CSSPropStyleObject = {
|
|
8
|
-
[key
|
|
10
|
+
[key in keyof CSSProperties]: string | number | Token;
|
|
11
|
+
} & {
|
|
12
|
+
unsupported: (keyof CSSProperties | typeof SPREAD_SYNTAX)[];
|
|
9
13
|
};
|
|
10
14
|
/**
|
|
11
15
|
* Note: Not recursive. Only handles top level key/value pairs
|
|
12
16
|
*/
|
|
13
|
-
export declare const convertASTObjectExpressionToJSObject: (styles: ObjectExpression & Partial<Rule.NodeParentExtension>) => CSSPropStyleObject
|
|
17
|
+
export declare const convertASTObjectExpressionToJSObject: (styles: ObjectExpression & Partial<Rule.NodeParentExtension>) => CSSPropStyleObject;
|
|
14
18
|
export {};
|
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.20.0",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"registry": "https://registry.npmjs.org/"
|