@atlaskit/eslint-plugin-design-system 8.36.3 → 8.37.1
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 +12 -0
- package/dist/cjs/ast-nodes/object-entry.js +13 -0
- package/dist/cjs/rules/ensure-design-token-usage/types.js +1 -5
- package/dist/cjs/rules/use-primitives/transformers/compiled-styled/index.js +2 -1
- package/dist/cjs/rules/use-primitives/transformers/emotion-css/index.js +3 -3
- package/dist/cjs/rules/use-primitives/utils/validate-styles.js +113 -0
- package/dist/cjs/rules/utils/create-no-tagged-template-expression-rule/types.js +1 -5
- package/dist/es2019/ast-nodes/object-entry.js +13 -0
- package/dist/es2019/rules/ensure-design-token-usage/types.js +0 -1
- package/dist/es2019/rules/use-primitives/transformers/compiled-styled/index.js +2 -1
- package/dist/es2019/rules/use-primitives/transformers/emotion-css/index.js +3 -3
- package/dist/es2019/rules/use-primitives/utils/validate-styles.js +106 -0
- package/dist/es2019/rules/utils/create-no-tagged-template-expression-rule/types.js +0 -1
- package/dist/esm/ast-nodes/object-entry.js +13 -0
- package/dist/esm/rules/ensure-design-token-usage/types.js +0 -1
- package/dist/esm/rules/use-primitives/transformers/compiled-styled/index.js +2 -1
- package/dist/esm/rules/use-primitives/transformers/emotion-css/index.js +3 -3
- package/dist/esm/rules/use-primitives/utils/validate-styles.js +104 -0
- package/dist/esm/rules/utils/create-no-tagged-template-expression-rule/types.js +0 -1
- package/dist/types/ast-nodes/object-entry.d.ts +2 -1
- package/dist/types/rules/use-primitives/config/index.d.ts +1 -1
- package/dist/types/rules/use-primitives/utils/validate-styles.d.ts +3 -0
- package/dist/types-ts4.5/ast-nodes/object-entry.d.ts +2 -1
- package/dist/types-ts4.5/rules/use-primitives/config/index.d.ts +1 -1
- package/dist/types-ts4.5/rules/use-primitives/utils/validate-styles.d.ts +3 -0
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @atlaskit/eslint-plugin-design-system
|
|
2
2
|
|
|
3
|
+
## 8.37.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#81307](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/81307) [`6420f933c8ae`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/6420f933c8ae) - Fix issue where `use-primitives` was incorrectly transforming styles with string properties.
|
|
8
|
+
|
|
9
|
+
## 8.37.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- [#81166](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/81166) [`a249a1bd29a6`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/a249a1bd29a6) - Upgrade ESLint to version 8
|
|
14
|
+
|
|
3
15
|
## 8.36.3
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.ObjectEntry = void 0;
|
|
7
|
+
var _eslintCodemodUtils = require("eslint-codemod-utils");
|
|
7
8
|
var ObjectEntry = exports.ObjectEntry = {
|
|
8
9
|
deleteEntry: function deleteEntry(node, context, fixer) {
|
|
9
10
|
var _lastToken;
|
|
@@ -23,5 +24,17 @@ var ObjectEntry = exports.ObjectEntry = {
|
|
|
23
24
|
lastToken = sourceCode.getTokenBefore(lastToken);
|
|
24
25
|
}
|
|
25
26
|
return fixer.removeRange([prevToken.range[1], lastToken.range[1]]);
|
|
27
|
+
},
|
|
28
|
+
getPropertyName: function getPropertyName(node) {
|
|
29
|
+
// SpreadElements don't really have a property name
|
|
30
|
+
if (!(0, _eslintCodemodUtils.isNodeOfType)(node, 'Property')) {
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
if ((0, _eslintCodemodUtils.isNodeOfType)(node.key, 'Literal')) {
|
|
34
|
+
return node.key.raw;
|
|
35
|
+
}
|
|
36
|
+
if ((0, _eslintCodemodUtils.isNodeOfType)(node.key, 'Identifier')) {
|
|
37
|
+
return node.key.name;
|
|
38
|
+
}
|
|
26
39
|
}
|
|
27
40
|
};
|
|
@@ -10,6 +10,7 @@ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers
|
|
|
10
10
|
var _eslintCodemodUtils = require("eslint-codemod-utils");
|
|
11
11
|
var ast = _interopRequireWildcard(require("../../../../ast-nodes"));
|
|
12
12
|
var _utils = require("../../utils");
|
|
13
|
+
var _validateStyles = require("../../utils/validate-styles");
|
|
13
14
|
var _convertJsxCallSite = require("./convert-jsx-call-site");
|
|
14
15
|
var _convertStyledComponentCallToJsx = require("./convert-styled-component-call-to-jsx");
|
|
15
16
|
var _findValidJsxUsageToTransform = require("./find-valid-jsx-usage-to-transform");
|
|
@@ -60,7 +61,7 @@ var CompiledStyled = exports.CompiledStyled = {
|
|
|
60
61
|
};
|
|
61
62
|
}
|
|
62
63
|
var styledComponentVariableRef = (0, _findValidStyledComponentCall.findValidStyledComponentCall)(node);
|
|
63
|
-
if (!styledComponentVariableRef || !(0, _eslintCodemodUtils.isNodeOfType)(styledComponentVariableRef.id, 'Identifier') || !(0, _utils.isValidCssPropertiesToTransform)(node, config)) {
|
|
64
|
+
if (!styledComponentVariableRef || !(0, _eslintCodemodUtils.isNodeOfType)(styledComponentVariableRef.id, 'Identifier') || !(config.patterns.includes('string-style-property-fix') ? (0, _validateStyles.validateStyles)(node, config) : (0, _utils.isValidCssPropertiesToTransform)(node, config))) {
|
|
64
65
|
return {
|
|
65
66
|
success: false
|
|
66
67
|
};
|
|
@@ -10,6 +10,7 @@ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers
|
|
|
10
10
|
var _eslintCodemodUtils = require("eslint-codemod-utils");
|
|
11
11
|
var ast = _interopRequireWildcard(require("../../../../ast-nodes"));
|
|
12
12
|
var _utils = require("../../utils");
|
|
13
|
+
var _validateStyles = require("../../utils/validate-styles");
|
|
13
14
|
var _cssToXcss = require("../css-to-xcss");
|
|
14
15
|
var supported = _interopRequireWildcard(require("./supported"));
|
|
15
16
|
var _upsertImportDeclaration = require("./upsert-import-declaration");
|
|
@@ -44,7 +45,6 @@ var EmotionCSS = exports.EmotionCSS = {
|
|
|
44
45
|
});
|
|
45
46
|
},
|
|
46
47
|
_check: function _check(node, _ref2) {
|
|
47
|
-
var _cssVariableValue$nod, _cssVariableValue$nod2;
|
|
48
48
|
var context = _ref2.context,
|
|
49
49
|
config = _ref2.config;
|
|
50
50
|
if (!config.patterns.includes('compiled-css-function')) {
|
|
@@ -91,10 +91,10 @@ var EmotionCSS = exports.EmotionCSS = {
|
|
|
91
91
|
var cssVariableDefinition = (0, _eslintCodemodUtils.getIdentifierInParentScope)(context.getScope(), cssAttrValue.value);
|
|
92
92
|
var cssVariableValue = (0, _utils.getVariableDefinitionValue)(cssVariableDefinition);
|
|
93
93
|
// Check if `cssVariableValue` is a function called `css()`
|
|
94
|
-
if (ast.FunctionCall.getName(cssVariableValue === null || cssVariableValue === void 0
|
|
94
|
+
if (ast.FunctionCall.getName(cssVariableValue === null || cssVariableValue === void 0 ? void 0 : cssVariableValue.node.init) !== 'css') {
|
|
95
95
|
return false;
|
|
96
96
|
}
|
|
97
|
-
if (!(0,
|
|
97
|
+
if (!(config.patterns.includes('string-style-property-fix') ? (0, _validateStyles.validateStyles)(cssVariableValue === null || cssVariableValue === void 0 ? void 0 : cssVariableValue.node.init, config) : (0, _utils.isValidCssPropertiesToTransform)(cssVariableValue === null || cssVariableValue === void 0 ? void 0 : cssVariableValue.node.init, config))) {
|
|
98
98
|
return false;
|
|
99
99
|
}
|
|
100
100
|
var importDeclaration = ast.Root.findImportsByModule(context.getSourceCode().ast.body, '@atlaskit/primitives');
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.validateStyles = void 0;
|
|
8
|
+
var _eslintCodemodUtils = require("eslint-codemod-utils");
|
|
9
|
+
var ast = _interopRequireWildcard(require("../../../ast-nodes"));
|
|
10
|
+
var _transformers = require("../transformers");
|
|
11
|
+
var _cssToXcss = require("../transformers/css-to-xcss");
|
|
12
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
13
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
14
|
+
var validateStyles = exports.validateStyles = function validateStyles(node, config) {
|
|
15
|
+
if (!node) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
var cssObjectExpression = node.arguments[0];
|
|
19
|
+
// Bail on empty object calls
|
|
20
|
+
if (!(0, _eslintCodemodUtils.isNodeOfType)(cssObjectExpression, 'ObjectExpression')) {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
if (!ast.Object.isFlat(cssObjectExpression)) {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
var entries = ast.Object.getEntries(cssObjectExpression);
|
|
27
|
+
if (entries.length === 0) {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
if (!config.patterns.includes('multiple-properties') && entries.length > 1) {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
return entries.every(function (entry) {
|
|
34
|
+
// Bail on SpreadElements
|
|
35
|
+
if (!(0, _eslintCodemodUtils.isNodeOfType)(entry, 'Property')) {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
var key = entry.key,
|
|
39
|
+
value = entry.value;
|
|
40
|
+
|
|
41
|
+
// Bail if the property is not something we understand, e.g. `{ [SOME_CONSTANT]: '8px' }`
|
|
42
|
+
if (!(0, _eslintCodemodUtils.isNodeOfType)(key, 'Identifier')) {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
var property = ast.ObjectEntry.getPropertyName(entry);
|
|
46
|
+
if (!property) {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Currently, we handle values like `'8px'` (a 'Literal') or `token('space.100')` (a 'CallExpression')
|
|
51
|
+
if ((0, _eslintCodemodUtils.isNodeOfType)(value, 'Literal')) {
|
|
52
|
+
if (!value.value) {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
var valueString = value.value.toString();
|
|
56
|
+
if (!_transformers.supportedStylesMap[property] || !_transformers.supportedStylesMap[property][valueString]) {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
} else if ((0, _eslintCodemodUtils.isNodeOfType)(value, 'CallExpression')) {
|
|
60
|
+
// If it's a function call, then make sure it's the `token` function (and we have `css-property-with-tokens` enabled)
|
|
61
|
+
|
|
62
|
+
// Short-circuit when token calls are found but pattern is not enabled in config
|
|
63
|
+
if (isTokenCall(value) && !config.patterns.includes('css-property-with-tokens')) {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Bail if it's a function, but that function call is not `tokens('<token>')`
|
|
68
|
+
if (!isTokenCall(value)) {
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
} else {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Bail if dimension property is found but pattern is not enabled in config
|
|
76
|
+
// Note: We don't need to exhaustively re-check the key/value pair here. That's already been done above.
|
|
77
|
+
// This is just to check wether 'dimension-properties' pattern is enabled and can be removed when the pattern is completely rolled out
|
|
78
|
+
var isDimensionProperty = !!_cssToXcss.supportedDimensionAttributesMap[property];
|
|
79
|
+
if (isDimensionProperty && !config.patterns.includes('dimension-properties')) {
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
return true;
|
|
83
|
+
});
|
|
84
|
+
};
|
|
85
|
+
var isTokenCall = function isTokenCall(node) {
|
|
86
|
+
// Is it a function call?
|
|
87
|
+
if (!(0, _eslintCodemodUtils.isNodeOfType)(node, 'CallExpression')) {
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// Is the function called 'token'?
|
|
92
|
+
if (ast.FunctionCall.getName(node) !== 'token') {
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
var token = ast.FunctionCall.getArgumentAtPos(node, 0);
|
|
96
|
+
var fallback = ast.FunctionCall.getArgumentAtPos(node, 1);
|
|
97
|
+
if (!token || token.type !== 'Literal') {
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// Is the token one that we understand
|
|
102
|
+
if (!Object.values(_transformers.spaceTokenMap).includes(token.value)) {
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// Not all `token()` calls have a fall back. This is fine, but if there is a fallback, make sure it's the same as the fallback xcss will use
|
|
107
|
+
if (fallback && fallback.type === 'Literal') {
|
|
108
|
+
if (_transformers.spaceTokenMap[fallback.value] !== token.value) {
|
|
109
|
+
return false;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return true;
|
|
113
|
+
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isNodeOfType } from 'eslint-codemod-utils';
|
|
1
2
|
const ObjectEntry = {
|
|
2
3
|
deleteEntry(node, context, fixer) {
|
|
3
4
|
var _lastToken;
|
|
@@ -17,6 +18,18 @@ const ObjectEntry = {
|
|
|
17
18
|
lastToken = sourceCode.getTokenBefore(lastToken);
|
|
18
19
|
}
|
|
19
20
|
return fixer.removeRange([prevToken.range[1], lastToken.range[1]]);
|
|
21
|
+
},
|
|
22
|
+
getPropertyName(node) {
|
|
23
|
+
// SpreadElements don't really have a property name
|
|
24
|
+
if (!isNodeOfType(node, 'Property')) {
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
if (isNodeOfType(node.key, 'Literal')) {
|
|
28
|
+
return node.key.raw;
|
|
29
|
+
}
|
|
30
|
+
if (isNodeOfType(node.key, 'Identifier')) {
|
|
31
|
+
return node.key.name;
|
|
32
|
+
}
|
|
20
33
|
}
|
|
21
34
|
};
|
|
22
35
|
export { ObjectEntry };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import { isNodeOfType } from 'eslint-codemod-utils';
|
|
4
4
|
import * as ast from '../../../../ast-nodes';
|
|
5
5
|
import { isValidCssPropertiesToTransform } from '../../utils';
|
|
6
|
+
import { validateStyles } from '../../utils/validate-styles';
|
|
6
7
|
import { convertJsxCallSite } from './convert-jsx-call-site';
|
|
7
8
|
import { convertStyledComponentToXcss } from './convert-styled-component-call-to-jsx';
|
|
8
9
|
import { findValidJsxUsageToTransform } from './find-valid-jsx-usage-to-transform';
|
|
@@ -52,7 +53,7 @@ export const CompiledStyled = {
|
|
|
52
53
|
};
|
|
53
54
|
}
|
|
54
55
|
const styledComponentVariableRef = findValidStyledComponentCall(node);
|
|
55
|
-
if (!styledComponentVariableRef || !isNodeOfType(styledComponentVariableRef.id, 'Identifier') || !isValidCssPropertiesToTransform(node, config)) {
|
|
56
|
+
if (!styledComponentVariableRef || !isNodeOfType(styledComponentVariableRef.id, 'Identifier') || !(config.patterns.includes('string-style-property-fix') ? validateStyles(node, config) : isValidCssPropertiesToTransform(node, config))) {
|
|
56
57
|
return {
|
|
57
58
|
success: false
|
|
58
59
|
};
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import { getIdentifierInParentScope, isNodeOfType } from 'eslint-codemod-utils';
|
|
4
4
|
import * as ast from '../../../../ast-nodes';
|
|
5
5
|
import { getVariableDefinitionValue, getVariableUsagesCount, isValidCssPropertiesToTransform } from '../../utils';
|
|
6
|
+
import { validateStyles } from '../../utils/validate-styles';
|
|
6
7
|
import { cssToXcssTransformer } from '../css-to-xcss';
|
|
7
8
|
import * as supported from './supported';
|
|
8
9
|
import { upsertImportDeclaration } from './upsert-import-declaration';
|
|
@@ -37,7 +38,6 @@ export const EmotionCSS = {
|
|
|
37
38
|
context,
|
|
38
39
|
config
|
|
39
40
|
}) {
|
|
40
|
-
var _cssVariableValue$nod, _cssVariableValue$nod2;
|
|
41
41
|
if (!config.patterns.includes('compiled-css-function')) {
|
|
42
42
|
return false;
|
|
43
43
|
}
|
|
@@ -82,10 +82,10 @@ export const EmotionCSS = {
|
|
|
82
82
|
const cssVariableDefinition = getIdentifierInParentScope(context.getScope(), cssAttrValue.value);
|
|
83
83
|
const cssVariableValue = getVariableDefinitionValue(cssVariableDefinition);
|
|
84
84
|
// Check if `cssVariableValue` is a function called `css()`
|
|
85
|
-
if (ast.FunctionCall.getName(cssVariableValue === null || cssVariableValue === void 0 ? void 0 :
|
|
85
|
+
if (ast.FunctionCall.getName(cssVariableValue === null || cssVariableValue === void 0 ? void 0 : cssVariableValue.node.init) !== 'css') {
|
|
86
86
|
return false;
|
|
87
87
|
}
|
|
88
|
-
if (!
|
|
88
|
+
if (!(config.patterns.includes('string-style-property-fix') ? validateStyles(cssVariableValue === null || cssVariableValue === void 0 ? void 0 : cssVariableValue.node.init, config) : isValidCssPropertiesToTransform(cssVariableValue === null || cssVariableValue === void 0 ? void 0 : cssVariableValue.node.init, config))) {
|
|
89
89
|
return false;
|
|
90
90
|
}
|
|
91
91
|
const importDeclaration = ast.Root.findImportsByModule(context.getSourceCode().ast.body, '@atlaskit/primitives');
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { isNodeOfType } from 'eslint-codemod-utils';
|
|
2
|
+
import * as ast from '../../../ast-nodes';
|
|
3
|
+
import { spaceTokenMap, supportedStylesMap } from '../transformers';
|
|
4
|
+
import { supportedDimensionAttributesMap } from '../transformers/css-to-xcss';
|
|
5
|
+
export const validateStyles = (node, config) => {
|
|
6
|
+
if (!node) {
|
|
7
|
+
return false;
|
|
8
|
+
}
|
|
9
|
+
const cssObjectExpression = node.arguments[0];
|
|
10
|
+
// Bail on empty object calls
|
|
11
|
+
if (!isNodeOfType(cssObjectExpression, 'ObjectExpression')) {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
if (!ast.Object.isFlat(cssObjectExpression)) {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
const entries = ast.Object.getEntries(cssObjectExpression);
|
|
18
|
+
if (entries.length === 0) {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
if (!config.patterns.includes('multiple-properties') && entries.length > 1) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
return entries.every(entry => {
|
|
25
|
+
// Bail on SpreadElements
|
|
26
|
+
if (!isNodeOfType(entry, 'Property')) {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
const {
|
|
30
|
+
key,
|
|
31
|
+
value
|
|
32
|
+
} = entry;
|
|
33
|
+
|
|
34
|
+
// Bail if the property is not something we understand, e.g. `{ [SOME_CONSTANT]: '8px' }`
|
|
35
|
+
if (!isNodeOfType(key, 'Identifier')) {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
const property = ast.ObjectEntry.getPropertyName(entry);
|
|
39
|
+
if (!property) {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Currently, we handle values like `'8px'` (a 'Literal') or `token('space.100')` (a 'CallExpression')
|
|
44
|
+
if (isNodeOfType(value, 'Literal')) {
|
|
45
|
+
if (!value.value) {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
const valueString = value.value.toString();
|
|
49
|
+
if (!supportedStylesMap[property] || !supportedStylesMap[property][valueString]) {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
} else if (isNodeOfType(value, 'CallExpression')) {
|
|
53
|
+
// If it's a function call, then make sure it's the `token` function (and we have `css-property-with-tokens` enabled)
|
|
54
|
+
|
|
55
|
+
// Short-circuit when token calls are found but pattern is not enabled in config
|
|
56
|
+
if (isTokenCall(value) && !config.patterns.includes('css-property-with-tokens')) {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Bail if it's a function, but that function call is not `tokens('<token>')`
|
|
61
|
+
if (!isTokenCall(value)) {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
} else {
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Bail if dimension property is found but pattern is not enabled in config
|
|
69
|
+
// Note: We don't need to exhaustively re-check the key/value pair here. That's already been done above.
|
|
70
|
+
// This is just to check wether 'dimension-properties' pattern is enabled and can be removed when the pattern is completely rolled out
|
|
71
|
+
const isDimensionProperty = !!supportedDimensionAttributesMap[property];
|
|
72
|
+
if (isDimensionProperty && !config.patterns.includes('dimension-properties')) {
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
return true;
|
|
76
|
+
});
|
|
77
|
+
};
|
|
78
|
+
const isTokenCall = node => {
|
|
79
|
+
// Is it a function call?
|
|
80
|
+
if (!isNodeOfType(node, 'CallExpression')) {
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Is the function called 'token'?
|
|
85
|
+
if (ast.FunctionCall.getName(node) !== 'token') {
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
const token = ast.FunctionCall.getArgumentAtPos(node, 0);
|
|
89
|
+
const fallback = ast.FunctionCall.getArgumentAtPos(node, 1);
|
|
90
|
+
if (!token || token.type !== 'Literal') {
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Is the token one that we understand
|
|
95
|
+
if (!Object.values(spaceTokenMap).includes(token.value)) {
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// Not all `token()` calls have a fall back. This is fine, but if there is a fallback, make sure it's the same as the fallback xcss will use
|
|
100
|
+
if (fallback && fallback.type === 'Literal') {
|
|
101
|
+
if (spaceTokenMap[fallback.value] !== token.value) {
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return true;
|
|
106
|
+
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isNodeOfType } from 'eslint-codemod-utils';
|
|
1
2
|
var ObjectEntry = {
|
|
2
3
|
deleteEntry: function deleteEntry(node, context, fixer) {
|
|
3
4
|
var _lastToken;
|
|
@@ -17,6 +18,18 @@ var ObjectEntry = {
|
|
|
17
18
|
lastToken = sourceCode.getTokenBefore(lastToken);
|
|
18
19
|
}
|
|
19
20
|
return fixer.removeRange([prevToken.range[1], lastToken.range[1]]);
|
|
21
|
+
},
|
|
22
|
+
getPropertyName: function getPropertyName(node) {
|
|
23
|
+
// SpreadElements don't really have a property name
|
|
24
|
+
if (!isNodeOfType(node, 'Property')) {
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
if (isNodeOfType(node.key, 'Literal')) {
|
|
28
|
+
return node.key.raw;
|
|
29
|
+
}
|
|
30
|
+
if (isNodeOfType(node.key, 'Identifier')) {
|
|
31
|
+
return node.key.name;
|
|
32
|
+
}
|
|
20
33
|
}
|
|
21
34
|
};
|
|
22
35
|
export { ObjectEntry };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -4,6 +4,7 @@ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
|
4
4
|
import { isNodeOfType } from 'eslint-codemod-utils';
|
|
5
5
|
import * as ast from '../../../../ast-nodes';
|
|
6
6
|
import { isValidCssPropertiesToTransform } from '../../utils';
|
|
7
|
+
import { validateStyles } from '../../utils/validate-styles';
|
|
7
8
|
import { convertJsxCallSite } from './convert-jsx-call-site';
|
|
8
9
|
import { convertStyledComponentToXcss } from './convert-styled-component-call-to-jsx';
|
|
9
10
|
import { findValidJsxUsageToTransform } from './find-valid-jsx-usage-to-transform';
|
|
@@ -50,7 +51,7 @@ export var CompiledStyled = {
|
|
|
50
51
|
};
|
|
51
52
|
}
|
|
52
53
|
var styledComponentVariableRef = findValidStyledComponentCall(node);
|
|
53
|
-
if (!styledComponentVariableRef || !isNodeOfType(styledComponentVariableRef.id, 'Identifier') || !isValidCssPropertiesToTransform(node, config)) {
|
|
54
|
+
if (!styledComponentVariableRef || !isNodeOfType(styledComponentVariableRef.id, 'Identifier') || !(config.patterns.includes('string-style-property-fix') ? validateStyles(node, config) : isValidCssPropertiesToTransform(node, config))) {
|
|
54
55
|
return {
|
|
55
56
|
success: false
|
|
56
57
|
};
|
|
@@ -4,6 +4,7 @@ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
|
4
4
|
import { getIdentifierInParentScope, isNodeOfType } from 'eslint-codemod-utils';
|
|
5
5
|
import * as ast from '../../../../ast-nodes';
|
|
6
6
|
import { getVariableDefinitionValue, getVariableUsagesCount, isValidCssPropertiesToTransform } from '../../utils';
|
|
7
|
+
import { validateStyles } from '../../utils/validate-styles';
|
|
7
8
|
import { cssToXcssTransformer } from '../css-to-xcss';
|
|
8
9
|
import * as supported from './supported';
|
|
9
10
|
import { upsertImportDeclaration } from './upsert-import-declaration';
|
|
@@ -34,7 +35,6 @@ export var EmotionCSS = {
|
|
|
34
35
|
});
|
|
35
36
|
},
|
|
36
37
|
_check: function _check(node, _ref2) {
|
|
37
|
-
var _cssVariableValue$nod, _cssVariableValue$nod2;
|
|
38
38
|
var context = _ref2.context,
|
|
39
39
|
config = _ref2.config;
|
|
40
40
|
if (!config.patterns.includes('compiled-css-function')) {
|
|
@@ -81,10 +81,10 @@ export var EmotionCSS = {
|
|
|
81
81
|
var cssVariableDefinition = getIdentifierInParentScope(context.getScope(), cssAttrValue.value);
|
|
82
82
|
var cssVariableValue = getVariableDefinitionValue(cssVariableDefinition);
|
|
83
83
|
// Check if `cssVariableValue` is a function called `css()`
|
|
84
|
-
if (ast.FunctionCall.getName(cssVariableValue === null || cssVariableValue === void 0
|
|
84
|
+
if (ast.FunctionCall.getName(cssVariableValue === null || cssVariableValue === void 0 ? void 0 : cssVariableValue.node.init) !== 'css') {
|
|
85
85
|
return false;
|
|
86
86
|
}
|
|
87
|
-
if (!
|
|
87
|
+
if (!(config.patterns.includes('string-style-property-fix') ? validateStyles(cssVariableValue === null || cssVariableValue === void 0 ? void 0 : cssVariableValue.node.init, config) : isValidCssPropertiesToTransform(cssVariableValue === null || cssVariableValue === void 0 ? void 0 : cssVariableValue.node.init, config))) {
|
|
88
88
|
return false;
|
|
89
89
|
}
|
|
90
90
|
var importDeclaration = ast.Root.findImportsByModule(context.getSourceCode().ast.body, '@atlaskit/primitives');
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { isNodeOfType } from 'eslint-codemod-utils';
|
|
2
|
+
import * as ast from '../../../ast-nodes';
|
|
3
|
+
import { spaceTokenMap, supportedStylesMap } from '../transformers';
|
|
4
|
+
import { supportedDimensionAttributesMap } from '../transformers/css-to-xcss';
|
|
5
|
+
export var validateStyles = function validateStyles(node, config) {
|
|
6
|
+
if (!node) {
|
|
7
|
+
return false;
|
|
8
|
+
}
|
|
9
|
+
var cssObjectExpression = node.arguments[0];
|
|
10
|
+
// Bail on empty object calls
|
|
11
|
+
if (!isNodeOfType(cssObjectExpression, 'ObjectExpression')) {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
if (!ast.Object.isFlat(cssObjectExpression)) {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
var entries = ast.Object.getEntries(cssObjectExpression);
|
|
18
|
+
if (entries.length === 0) {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
if (!config.patterns.includes('multiple-properties') && entries.length > 1) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
return entries.every(function (entry) {
|
|
25
|
+
// Bail on SpreadElements
|
|
26
|
+
if (!isNodeOfType(entry, 'Property')) {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
var key = entry.key,
|
|
30
|
+
value = entry.value;
|
|
31
|
+
|
|
32
|
+
// Bail if the property is not something we understand, e.g. `{ [SOME_CONSTANT]: '8px' }`
|
|
33
|
+
if (!isNodeOfType(key, 'Identifier')) {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
var property = ast.ObjectEntry.getPropertyName(entry);
|
|
37
|
+
if (!property) {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Currently, we handle values like `'8px'` (a 'Literal') or `token('space.100')` (a 'CallExpression')
|
|
42
|
+
if (isNodeOfType(value, 'Literal')) {
|
|
43
|
+
if (!value.value) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
var valueString = value.value.toString();
|
|
47
|
+
if (!supportedStylesMap[property] || !supportedStylesMap[property][valueString]) {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
} else if (isNodeOfType(value, 'CallExpression')) {
|
|
51
|
+
// If it's a function call, then make sure it's the `token` function (and we have `css-property-with-tokens` enabled)
|
|
52
|
+
|
|
53
|
+
// Short-circuit when token calls are found but pattern is not enabled in config
|
|
54
|
+
if (isTokenCall(value) && !config.patterns.includes('css-property-with-tokens')) {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Bail if it's a function, but that function call is not `tokens('<token>')`
|
|
59
|
+
if (!isTokenCall(value)) {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
} else {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Bail if dimension property is found but pattern is not enabled in config
|
|
67
|
+
// Note: We don't need to exhaustively re-check the key/value pair here. That's already been done above.
|
|
68
|
+
// This is just to check wether 'dimension-properties' pattern is enabled and can be removed when the pattern is completely rolled out
|
|
69
|
+
var isDimensionProperty = !!supportedDimensionAttributesMap[property];
|
|
70
|
+
if (isDimensionProperty && !config.patterns.includes('dimension-properties')) {
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
return true;
|
|
74
|
+
});
|
|
75
|
+
};
|
|
76
|
+
var isTokenCall = function isTokenCall(node) {
|
|
77
|
+
// Is it a function call?
|
|
78
|
+
if (!isNodeOfType(node, 'CallExpression')) {
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// Is the function called 'token'?
|
|
83
|
+
if (ast.FunctionCall.getName(node) !== 'token') {
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
var token = ast.FunctionCall.getArgumentAtPos(node, 0);
|
|
87
|
+
var fallback = ast.FunctionCall.getArgumentAtPos(node, 1);
|
|
88
|
+
if (!token || token.type !== 'Literal') {
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Is the token one that we understand
|
|
93
|
+
if (!Object.values(spaceTokenMap).includes(token.value)) {
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// Not all `token()` calls have a fall back. This is fine, but if there is a fallback, make sure it's the same as the fallback xcss will use
|
|
98
|
+
if (fallback && fallback.type === 'Literal') {
|
|
99
|
+
if (spaceTokenMap[fallback.value] !== token.value) {
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return true;
|
|
104
|
+
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Rule } from 'eslint';
|
|
2
|
-
import
|
|
2
|
+
import { Property, SpreadElement } from 'eslint-codemod-utils';
|
|
3
3
|
declare const ObjectEntry: {
|
|
4
4
|
deleteEntry(node: Property | SpreadElement, context: Rule.RuleContext, fixer: Rule.RuleFixer): Rule.Fix;
|
|
5
|
+
getPropertyName(node: Property | SpreadElement): string | undefined;
|
|
5
6
|
};
|
|
6
7
|
export { ObjectEntry };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
type Pattern = 'compiled-css-function' | 'compiled-styled-object' | 'css-template-literal' | 'css-property-with-tokens' | 'css-property-multiple-values' | 'multiple-properties' | 'dimension-properties' | 'jsx-order-fix';
|
|
1
|
+
type Pattern = 'compiled-css-function' | 'compiled-styled-object' | 'css-template-literal' | 'css-property-with-tokens' | 'css-property-multiple-values' | 'multiple-properties' | 'dimension-properties' | 'jsx-order-fix' | 'string-style-property-fix';
|
|
2
2
|
export interface RuleConfig {
|
|
3
3
|
patterns: Pattern[];
|
|
4
4
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Rule } from 'eslint';
|
|
2
|
-
import
|
|
2
|
+
import { Property, SpreadElement } from 'eslint-codemod-utils';
|
|
3
3
|
declare const ObjectEntry: {
|
|
4
4
|
deleteEntry(node: Property | SpreadElement, context: Rule.RuleContext, fixer: Rule.RuleFixer): Rule.Fix;
|
|
5
|
+
getPropertyName(node: Property | SpreadElement): string | undefined;
|
|
5
6
|
};
|
|
6
7
|
export { ObjectEntry };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
type Pattern = 'compiled-css-function' | 'compiled-styled-object' | 'css-template-literal' | 'css-property-with-tokens' | 'css-property-multiple-values' | 'multiple-properties' | 'dimension-properties' | 'jsx-order-fix';
|
|
1
|
+
type Pattern = 'compiled-css-function' | 'compiled-styled-object' | 'css-template-literal' | 'css-property-with-tokens' | 'css-property-multiple-values' | 'multiple-properties' | 'dimension-properties' | 'jsx-order-fix' | 'string-style-property-fix';
|
|
2
2
|
export interface RuleConfig {
|
|
3
3
|
patterns: Pattern[];
|
|
4
4
|
}
|
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.37.1",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -50,12 +50,12 @@
|
|
|
50
50
|
"@atlaskit/theme": "^12.6.0",
|
|
51
51
|
"@atlassian/atlassian-frontend-prettier-config-1.0.1": "npm:@atlassian/atlassian-frontend-prettier-config@1.0.1",
|
|
52
52
|
"@atlassian/codegen": "*",
|
|
53
|
-
"@atlassian/eslint-utils": "^0.
|
|
53
|
+
"@atlassian/eslint-utils": "^0.4.0",
|
|
54
54
|
"@emotion/react": "^11.7.1",
|
|
55
55
|
"@emotion/styled": "^11.0.0",
|
|
56
56
|
"@types/eslint": "^8.4.5",
|
|
57
57
|
"@types/estraverse": "^5.1.7",
|
|
58
|
-
"eslint": "^
|
|
58
|
+
"eslint": "^8.49.0",
|
|
59
59
|
"jscodeshift": "^0.13.0",
|
|
60
60
|
"outdent": "^0.5.0",
|
|
61
61
|
"prettier": "^2.8.0",
|