@atlaskit/eslint-plugin-design-system 8.23.4 → 8.25.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 +12 -0
- package/dist/cjs/ast-nodes/object.js +23 -5
- package/dist/cjs/rules/ensure-design-token-usage/color.js +3 -0
- package/dist/cjs/rules/use-primitives/utils/is-valid-css-properties-to-transform.js +12 -1
- package/dist/cjs/rules/utils/is-node.js +13 -1
- package/dist/es2019/ast-nodes/object.js +23 -5
- package/dist/es2019/rules/ensure-design-token-usage/color.js +4 -1
- package/dist/es2019/rules/use-primitives/utils/is-valid-css-properties-to-transform.js +9 -1
- package/dist/es2019/rules/utils/is-node.js +12 -0
- package/dist/esm/ast-nodes/object.js +23 -5
- package/dist/esm/rules/ensure-design-token-usage/color.js +4 -1
- package/dist/esm/rules/use-primitives/utils/is-valid-css-properties-to-transform.js +9 -1
- package/dist/esm/rules/utils/is-node.js +12 -0
- package/dist/types/ast-nodes/object.d.ts +13 -5
- package/dist/types/rules/use-primitives/config/index.d.ts +1 -1
- package/dist/types/rules/utils/is-node.d.ts +1 -0
- package/dist/types-ts4.5/ast-nodes/object.d.ts +13 -5
- package/dist/types-ts4.5/rules/use-primitives/config/index.d.ts +1 -1
- package/dist/types-ts4.5/rules/utils/is-node.d.ts +1 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @atlaskit/eslint-plugin-design-system
|
|
2
2
|
|
|
3
|
+
## 8.25.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#70369](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/70369) [`611434ce1fe5`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/611434ce1fe5) - ensure-design-token-usage no longer errors on color properties defined in SVG JSX elements.
|
|
8
|
+
|
|
9
|
+
## 8.24.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- [#70036](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/70036) [`667c0a990b15`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/667c0a990b15) - Allow linting of multiple property style objects in use-primitives rule.
|
|
14
|
+
|
|
3
15
|
## 8.23.4
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
|
@@ -15,7 +15,25 @@ var ASTObjectExpression = exports.Object = {
|
|
|
15
15
|
return !!ASTObjectExpression.getProperty(node, name);
|
|
16
16
|
},
|
|
17
17
|
/**
|
|
18
|
-
* Returns
|
|
18
|
+
* Returns true if an object contains no nested values, false otherwise.
|
|
19
|
+
*
|
|
20
|
+
* Note:
|
|
21
|
+
* - Returns false if object contains spread elements.
|
|
22
|
+
* - Returns true if object is empty.
|
|
23
|
+
*/
|
|
24
|
+
isFlat: function isFlat(node) {
|
|
25
|
+
return node.properties.every(function (entry) {
|
|
26
|
+
if (!(0, _eslintCodemodUtils.isNodeOfType)(entry, 'Property')) {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
if ((0, _eslintCodemodUtils.isNodeOfType)(entry.value, 'ObjectExpression')) {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
return true;
|
|
33
|
+
});
|
|
34
|
+
},
|
|
35
|
+
/**
|
|
36
|
+
* Returns a key-value pair like: `padding: '8px'` from: `{ padding: '8px' }`.
|
|
19
37
|
*/
|
|
20
38
|
getEntryByPropertyName: function getEntryByPropertyName(node, name) {
|
|
21
39
|
return node.properties.find(function (property) {
|
|
@@ -36,16 +54,16 @@ var ASTObjectExpression = exports.Object = {
|
|
|
36
54
|
return [fixer.remove(entry)];
|
|
37
55
|
},
|
|
38
56
|
/**
|
|
39
|
-
* Returns a only the property @type {Property['key']} like: `padding` from: `{ padding: '8px' }
|
|
57
|
+
* Returns a only the property @type {Property['key']} like: `padding` from: `{ padding: '8px' }`.
|
|
40
58
|
*/
|
|
41
59
|
getProperty: function getProperty(node, name) {
|
|
42
60
|
var _ASTObjectExpression$;
|
|
43
61
|
return (_ASTObjectExpression$ = ASTObjectExpression.getEntryByPropertyName(node, name)) === null || _ASTObjectExpression$ === void 0 ? void 0 : _ASTObjectExpression$.key;
|
|
44
62
|
},
|
|
45
63
|
/**
|
|
46
|
-
* Returns a only the property @type {Property['value']} like: `'8px` from: `{ padding: '8px' }
|
|
64
|
+
* Returns a only the property @type {Property['value']} like: `'8px` from: `{ padding: '8px' }`.
|
|
47
65
|
*
|
|
48
|
-
* Values can be basically anything, so be careful with this
|
|
66
|
+
* Values can be basically anything, so be careful with this.
|
|
49
67
|
*/
|
|
50
68
|
getValueByPropertyName: function getValueByPropertyName(node, name) {
|
|
51
69
|
var _ASTObjectExpression$2;
|
|
@@ -73,7 +91,7 @@ var ASTObjectExpression = exports.Object = {
|
|
|
73
91
|
* fixer,
|
|
74
92
|
* )
|
|
75
93
|
* ```
|
|
76
|
-
* Will result in `{ padding: 'space.100', margin: 'space.200'}
|
|
94
|
+
* Will result in `{ padding: 'space.100', margin: 'space.200'}`.
|
|
77
95
|
*/
|
|
78
96
|
appendEntry: function appendEntry(node, key, value, fixer) {
|
|
79
97
|
return fixer.insertTextAfter(node.properties[node.properties.length - 1], "".concat((0, _eslintCodemodUtils.property)({
|
|
@@ -140,6 +140,9 @@ var lintJSXLiteralForColor = exports.lintJSXLiteralForColor = function lintJSXLi
|
|
|
140
140
|
if (!(0, _eslintCodemodUtils.isNodeOfType)(node.parent.name, 'JSXIdentifier')) {
|
|
141
141
|
return;
|
|
142
142
|
}
|
|
143
|
+
if ((0, _isNode.isDecendantOfSvgElement)(node.parent)) {
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
143
146
|
if (['alt', 'src', 'label', 'key'].includes(node.parent.name.name)) {
|
|
144
147
|
return;
|
|
145
148
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
var _typeof3 = require("@babel/runtime/helpers/typeof");
|
|
4
5
|
Object.defineProperty(exports, "__esModule", {
|
|
5
6
|
value: true
|
|
6
7
|
});
|
|
@@ -8,9 +9,12 @@ exports.isValidCssPropertiesToTransform = void 0;
|
|
|
8
9
|
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
9
10
|
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
10
11
|
var _eslintCodemodUtils = require("eslint-codemod-utils");
|
|
12
|
+
var ast = _interopRequireWildcard(require("../../../ast-nodes"));
|
|
11
13
|
var _cssToXcss = require("../transformers/css-to-xcss");
|
|
12
14
|
var _convertAstObjectExpressionToJsObject = require("./convert-ast-object-expression-to-js-object");
|
|
13
15
|
var _excluded = ["unsupported"];
|
|
16
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
17
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof3(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
14
18
|
var isValidCssPropertiesToTransform = exports.isValidCssPropertiesToTransform = function isValidCssPropertiesToTransform(node, config) {
|
|
15
19
|
if (!node) {
|
|
16
20
|
return false;
|
|
@@ -20,13 +24,20 @@ var isValidCssPropertiesToTransform = exports.isValidCssPropertiesToTransform =
|
|
|
20
24
|
if (!cssObjectExpression || !(0, _eslintCodemodUtils.isNodeOfType)(cssObjectExpression, 'ObjectExpression')) {
|
|
21
25
|
return false;
|
|
22
26
|
}
|
|
27
|
+
if (!ast.Object.isFlat(cssObjectExpression)) {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
23
30
|
var _convertASTObjectExpr = (0, _convertAstObjectExpressionToJsObject.convertASTObjectExpressionToJSObject)(cssObjectExpression),
|
|
24
31
|
unsupported = _convertASTObjectExpr.unsupported,
|
|
25
32
|
cssObject = (0, _objectWithoutProperties2.default)(_convertASTObjectExpr, _excluded);
|
|
26
33
|
// Bail if there are any unsupported styles
|
|
27
|
-
if (unsupported.length > 0
|
|
34
|
+
if (unsupported.length > 0) {
|
|
28
35
|
return false;
|
|
29
36
|
}
|
|
37
|
+
if (!config.patterns.includes('multiple-properties') && Object.keys(cssObject).length > 1) {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
|
|
30
41
|
// Short-circuit when token calls are found but pattern is not enabled in config
|
|
31
42
|
if (!config.patterns.includes('css-property-with-tokens') && Object.values(cssObject).some(function (value) {
|
|
32
43
|
return (0, _typeof2.default)(value) === 'object' && value.tokenName;
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.isPropertyKey = exports.isDecendantOfType = exports.isDecendantOfStyleJsxAttribute = exports.isDecendantOfStyleBlock = exports.isDecendantOfGlobalToken = exports.isCssInJsTemplateNode = exports.isCssInJsObjectNode = exports.isCssInJsCallNode = exports.isChildOfType = void 0;
|
|
6
|
+
exports.isPropertyKey = exports.isDecendantOfType = exports.isDecendantOfSvgElement = exports.isDecendantOfStyleJsxAttribute = exports.isDecendantOfStyleBlock = exports.isDecendantOfGlobalToken = exports.isCssInJsTemplateNode = exports.isCssInJsObjectNode = exports.isCssInJsCallNode = exports.isChildOfType = void 0;
|
|
7
7
|
var _eslintCodemodUtils = require("eslint-codemod-utils");
|
|
8
8
|
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
9
9
|
|
|
@@ -42,6 +42,18 @@ var isDecendantOfStyleJsxAttribute = exports.isDecendantOfStyleJsxAttribute = fu
|
|
|
42
42
|
}
|
|
43
43
|
return false;
|
|
44
44
|
};
|
|
45
|
+
var isDecendantOfSvgElement = exports.isDecendantOfSvgElement = function isDecendantOfSvgElement(node) {
|
|
46
|
+
if ((0, _eslintCodemodUtils.isNodeOfType)(node, 'JSXElement')) {
|
|
47
|
+
// @ts-ignore
|
|
48
|
+
if (node.openingElement.name.name === 'svg') {
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
if (node.parent) {
|
|
53
|
+
return isDecendantOfSvgElement(node.parent);
|
|
54
|
+
}
|
|
55
|
+
return false;
|
|
56
|
+
};
|
|
45
57
|
var cssInJsCallees = ['css', 'styled', 'styled2'];
|
|
46
58
|
var isCssInJsTemplateNode = exports.isCssInJsTemplateNode = function isCssInJsTemplateNode(node) {
|
|
47
59
|
return (node === null || node === void 0 ? void 0 : node.type) === 'TaggedTemplateExpression' && node.tag.type === 'MemberExpression' && node.tag.object.type === 'Identifier' && node.tag.object.name === 'styled';
|
|
@@ -9,7 +9,25 @@ const ASTObjectExpression = {
|
|
|
9
9
|
return !!ASTObjectExpression.getProperty(node, name);
|
|
10
10
|
},
|
|
11
11
|
/**
|
|
12
|
-
* Returns
|
|
12
|
+
* Returns true if an object contains no nested values, false otherwise.
|
|
13
|
+
*
|
|
14
|
+
* Note:
|
|
15
|
+
* - Returns false if object contains spread elements.
|
|
16
|
+
* - Returns true if object is empty.
|
|
17
|
+
*/
|
|
18
|
+
isFlat(node) {
|
|
19
|
+
return node.properties.every(entry => {
|
|
20
|
+
if (!isNodeOfType(entry, 'Property')) {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
if (isNodeOfType(entry.value, 'ObjectExpression')) {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
return true;
|
|
27
|
+
});
|
|
28
|
+
},
|
|
29
|
+
/**
|
|
30
|
+
* Returns a key-value pair like: `padding: '8px'` from: `{ padding: '8px' }`.
|
|
13
31
|
*/
|
|
14
32
|
getEntryByPropertyName(node, name) {
|
|
15
33
|
return node.properties.find(property => {
|
|
@@ -30,16 +48,16 @@ const ASTObjectExpression = {
|
|
|
30
48
|
return [fixer.remove(entry)];
|
|
31
49
|
},
|
|
32
50
|
/**
|
|
33
|
-
* Returns a only the property @type {Property['key']} like: `padding` from: `{ padding: '8px' }
|
|
51
|
+
* Returns a only the property @type {Property['key']} like: `padding` from: `{ padding: '8px' }`.
|
|
34
52
|
*/
|
|
35
53
|
getProperty(node, name) {
|
|
36
54
|
var _ASTObjectExpression$;
|
|
37
55
|
return (_ASTObjectExpression$ = ASTObjectExpression.getEntryByPropertyName(node, name)) === null || _ASTObjectExpression$ === void 0 ? void 0 : _ASTObjectExpression$.key;
|
|
38
56
|
},
|
|
39
57
|
/**
|
|
40
|
-
* Returns a only the property @type {Property['value']} like: `'8px` from: `{ padding: '8px' }
|
|
58
|
+
* Returns a only the property @type {Property['value']} like: `'8px` from: `{ padding: '8px' }`.
|
|
41
59
|
*
|
|
42
|
-
* Values can be basically anything, so be careful with this
|
|
60
|
+
* Values can be basically anything, so be careful with this.
|
|
43
61
|
*/
|
|
44
62
|
getValueByPropertyName(node, name) {
|
|
45
63
|
var _ASTObjectExpression$2;
|
|
@@ -67,7 +85,7 @@ const ASTObjectExpression = {
|
|
|
67
85
|
* fixer,
|
|
68
86
|
* )
|
|
69
87
|
* ```
|
|
70
|
-
* Will result in `{ padding: 'space.100', margin: 'space.200'}
|
|
88
|
+
* Will result in `{ padding: 'space.100', margin: 'space.200'}`.
|
|
71
89
|
*/
|
|
72
90
|
appendEntry(node, key, value, fixer) {
|
|
73
91
|
return fixer.insertTextAfter(node.properties[node.properties.length - 1], `${property({
|
|
@@ -4,7 +4,7 @@ import { node as generate, isNodeOfType } from 'eslint-codemod-utils';
|
|
|
4
4
|
import { getIsException } from '../utils/get-is-exception';
|
|
5
5
|
import { includesHardCodedColor, isHardCodedColor, isLegacyColor, isLegacyNamedColor } from '../utils/is-color';
|
|
6
6
|
import { isLegacyElevation } from '../utils/is-elevation';
|
|
7
|
-
import { isChildOfType, isDecendantOfGlobalToken, isDecendantOfStyleBlock } from '../utils/is-node';
|
|
7
|
+
import { isChildOfType, isDecendantOfGlobalToken, isDecendantOfStyleBlock, isDecendantOfSvgElement } from '../utils/is-node';
|
|
8
8
|
// TemplateLiteral > Identifier
|
|
9
9
|
export const lintTemplateIdentifierForColor = (node, context, config) => {
|
|
10
10
|
if (node.type !== 'Identifier') {
|
|
@@ -135,6 +135,9 @@ export const lintJSXLiteralForColor = (node, context, config) => {
|
|
|
135
135
|
if (!isNodeOfType(node.parent.name, 'JSXIdentifier')) {
|
|
136
136
|
return;
|
|
137
137
|
}
|
|
138
|
+
if (isDecendantOfSvgElement(node.parent)) {
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
138
141
|
if (['alt', 'src', 'label', 'key'].includes(node.parent.name.name)) {
|
|
139
142
|
return;
|
|
140
143
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { isNodeOfType } from 'eslint-codemod-utils';
|
|
2
|
+
import * as ast from '../../../ast-nodes';
|
|
2
3
|
import { supportedStylesMap } from '../transformers/css-to-xcss';
|
|
3
4
|
import { convertASTObjectExpressionToJSObject } from './convert-ast-object-expression-to-js-object';
|
|
4
5
|
export const isValidCssPropertiesToTransform = (node, config) => {
|
|
@@ -10,14 +11,21 @@ export const isValidCssPropertiesToTransform = (node, config) => {
|
|
|
10
11
|
if (!cssObjectExpression || !isNodeOfType(cssObjectExpression, 'ObjectExpression')) {
|
|
11
12
|
return false;
|
|
12
13
|
}
|
|
14
|
+
if (!ast.Object.isFlat(cssObjectExpression)) {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
13
17
|
const {
|
|
14
18
|
unsupported,
|
|
15
19
|
...cssObject
|
|
16
20
|
} = convertASTObjectExpressionToJSObject(cssObjectExpression);
|
|
17
21
|
// Bail if there are any unsupported styles
|
|
18
|
-
if (unsupported.length > 0
|
|
22
|
+
if (unsupported.length > 0) {
|
|
19
23
|
return false;
|
|
20
24
|
}
|
|
25
|
+
if (!config.patterns.includes('multiple-properties') && Object.keys(cssObject).length > 1) {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
|
|
21
29
|
// Short-circuit when token calls are found but pattern is not enabled in config
|
|
22
30
|
if (!config.patterns.includes('css-property-with-tokens') && Object.values(cssObject).some(value => typeof value === 'object' && value.tokenName)) {
|
|
23
31
|
return false;
|
|
@@ -35,6 +35,18 @@ export const isDecendantOfStyleJsxAttribute = node => {
|
|
|
35
35
|
}
|
|
36
36
|
return false;
|
|
37
37
|
};
|
|
38
|
+
export const isDecendantOfSvgElement = node => {
|
|
39
|
+
if (isNodeOfType(node, 'JSXElement')) {
|
|
40
|
+
// @ts-ignore
|
|
41
|
+
if (node.openingElement.name.name === 'svg') {
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
if (node.parent) {
|
|
46
|
+
return isDecendantOfSvgElement(node.parent);
|
|
47
|
+
}
|
|
48
|
+
return false;
|
|
49
|
+
};
|
|
38
50
|
const cssInJsCallees = ['css', 'styled', 'styled2'];
|
|
39
51
|
export const isCssInJsTemplateNode = node => (node === null || node === void 0 ? void 0 : node.type) === 'TaggedTemplateExpression' && node.tag.type === 'MemberExpression' && node.tag.object.type === 'Identifier' && node.tag.object.name === 'styled';
|
|
40
52
|
export const isCssInJsCallNode = node => (node === null || node === void 0 ? void 0 : node.type) === 'CallExpression' && node.callee.type === 'Identifier' && cssInJsCallees.includes(node.callee.name);
|
|
@@ -9,7 +9,25 @@ var ASTObjectExpression = {
|
|
|
9
9
|
return !!ASTObjectExpression.getProperty(node, name);
|
|
10
10
|
},
|
|
11
11
|
/**
|
|
12
|
-
* Returns
|
|
12
|
+
* Returns true if an object contains no nested values, false otherwise.
|
|
13
|
+
*
|
|
14
|
+
* Note:
|
|
15
|
+
* - Returns false if object contains spread elements.
|
|
16
|
+
* - Returns true if object is empty.
|
|
17
|
+
*/
|
|
18
|
+
isFlat: function isFlat(node) {
|
|
19
|
+
return node.properties.every(function (entry) {
|
|
20
|
+
if (!isNodeOfType(entry, 'Property')) {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
if (isNodeOfType(entry.value, 'ObjectExpression')) {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
return true;
|
|
27
|
+
});
|
|
28
|
+
},
|
|
29
|
+
/**
|
|
30
|
+
* Returns a key-value pair like: `padding: '8px'` from: `{ padding: '8px' }`.
|
|
13
31
|
*/
|
|
14
32
|
getEntryByPropertyName: function getEntryByPropertyName(node, name) {
|
|
15
33
|
return node.properties.find(function (property) {
|
|
@@ -30,16 +48,16 @@ var ASTObjectExpression = {
|
|
|
30
48
|
return [fixer.remove(entry)];
|
|
31
49
|
},
|
|
32
50
|
/**
|
|
33
|
-
* Returns a only the property @type {Property['key']} like: `padding` from: `{ padding: '8px' }
|
|
51
|
+
* Returns a only the property @type {Property['key']} like: `padding` from: `{ padding: '8px' }`.
|
|
34
52
|
*/
|
|
35
53
|
getProperty: function getProperty(node, name) {
|
|
36
54
|
var _ASTObjectExpression$;
|
|
37
55
|
return (_ASTObjectExpression$ = ASTObjectExpression.getEntryByPropertyName(node, name)) === null || _ASTObjectExpression$ === void 0 ? void 0 : _ASTObjectExpression$.key;
|
|
38
56
|
},
|
|
39
57
|
/**
|
|
40
|
-
* Returns a only the property @type {Property['value']} like: `'8px` from: `{ padding: '8px' }
|
|
58
|
+
* Returns a only the property @type {Property['value']} like: `'8px` from: `{ padding: '8px' }`.
|
|
41
59
|
*
|
|
42
|
-
* Values can be basically anything, so be careful with this
|
|
60
|
+
* Values can be basically anything, so be careful with this.
|
|
43
61
|
*/
|
|
44
62
|
getValueByPropertyName: function getValueByPropertyName(node, name) {
|
|
45
63
|
var _ASTObjectExpression$2;
|
|
@@ -67,7 +85,7 @@ var ASTObjectExpression = {
|
|
|
67
85
|
* fixer,
|
|
68
86
|
* )
|
|
69
87
|
* ```
|
|
70
|
-
* Will result in `{ padding: 'space.100', margin: 'space.200'}
|
|
88
|
+
* Will result in `{ padding: 'space.100', margin: 'space.200'}`.
|
|
71
89
|
*/
|
|
72
90
|
appendEntry: function appendEntry(node, key, value, fixer) {
|
|
73
91
|
return fixer.insertTextAfter(node.properties[node.properties.length - 1], "".concat(property({
|
|
@@ -4,7 +4,7 @@ import { node as generate, isNodeOfType } from 'eslint-codemod-utils';
|
|
|
4
4
|
import { getIsException } from '../utils/get-is-exception';
|
|
5
5
|
import { includesHardCodedColor, isHardCodedColor, isLegacyColor, isLegacyNamedColor } from '../utils/is-color';
|
|
6
6
|
import { isLegacyElevation } from '../utils/is-elevation';
|
|
7
|
-
import { isChildOfType, isDecendantOfGlobalToken, isDecendantOfStyleBlock } from '../utils/is-node';
|
|
7
|
+
import { isChildOfType, isDecendantOfGlobalToken, isDecendantOfStyleBlock, isDecendantOfSvgElement } from '../utils/is-node';
|
|
8
8
|
// TemplateLiteral > Identifier
|
|
9
9
|
export var lintTemplateIdentifierForColor = function lintTemplateIdentifierForColor(node, context, config) {
|
|
10
10
|
if (node.type !== 'Identifier') {
|
|
@@ -134,6 +134,9 @@ export var lintJSXLiteralForColor = function lintJSXLiteralForColor(node, contex
|
|
|
134
134
|
if (!isNodeOfType(node.parent.name, 'JSXIdentifier')) {
|
|
135
135
|
return;
|
|
136
136
|
}
|
|
137
|
+
if (isDecendantOfSvgElement(node.parent)) {
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
137
140
|
if (['alt', 'src', 'label', 'key'].includes(node.parent.name.name)) {
|
|
138
141
|
return;
|
|
139
142
|
}
|
|
@@ -2,6 +2,7 @@ import _typeof from "@babel/runtime/helpers/typeof";
|
|
|
2
2
|
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
3
3
|
var _excluded = ["unsupported"];
|
|
4
4
|
import { isNodeOfType } from 'eslint-codemod-utils';
|
|
5
|
+
import * as ast from '../../../ast-nodes';
|
|
5
6
|
import { supportedStylesMap } from '../transformers/css-to-xcss';
|
|
6
7
|
import { convertASTObjectExpressionToJSObject } from './convert-ast-object-expression-to-js-object';
|
|
7
8
|
export var isValidCssPropertiesToTransform = function isValidCssPropertiesToTransform(node, config) {
|
|
@@ -13,13 +14,20 @@ export var isValidCssPropertiesToTransform = function isValidCssPropertiesToTran
|
|
|
13
14
|
if (!cssObjectExpression || !isNodeOfType(cssObjectExpression, 'ObjectExpression')) {
|
|
14
15
|
return false;
|
|
15
16
|
}
|
|
17
|
+
if (!ast.Object.isFlat(cssObjectExpression)) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
16
20
|
var _convertASTObjectExpr = convertASTObjectExpressionToJSObject(cssObjectExpression),
|
|
17
21
|
unsupported = _convertASTObjectExpr.unsupported,
|
|
18
22
|
cssObject = _objectWithoutProperties(_convertASTObjectExpr, _excluded);
|
|
19
23
|
// Bail if there are any unsupported styles
|
|
20
|
-
if (unsupported.length > 0
|
|
24
|
+
if (unsupported.length > 0) {
|
|
21
25
|
return false;
|
|
22
26
|
}
|
|
27
|
+
if (!config.patterns.includes('multiple-properties') && Object.keys(cssObject).length > 1) {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
|
|
23
31
|
// Short-circuit when token calls are found but pattern is not enabled in config
|
|
24
32
|
if (!config.patterns.includes('css-property-with-tokens') && Object.values(cssObject).some(function (value) {
|
|
25
33
|
return _typeof(value) === 'object' && value.tokenName;
|
|
@@ -36,6 +36,18 @@ export var isDecendantOfStyleJsxAttribute = function isDecendantOfStyleJsxAttrib
|
|
|
36
36
|
}
|
|
37
37
|
return false;
|
|
38
38
|
};
|
|
39
|
+
export var isDecendantOfSvgElement = function isDecendantOfSvgElement(node) {
|
|
40
|
+
if (isNodeOfType(node, 'JSXElement')) {
|
|
41
|
+
// @ts-ignore
|
|
42
|
+
if (node.openingElement.name.name === 'svg') {
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
if (node.parent) {
|
|
47
|
+
return isDecendantOfSvgElement(node.parent);
|
|
48
|
+
}
|
|
49
|
+
return false;
|
|
50
|
+
};
|
|
39
51
|
var cssInJsCallees = ['css', 'styled', 'styled2'];
|
|
40
52
|
export var isCssInJsTemplateNode = function isCssInJsTemplateNode(node) {
|
|
41
53
|
return (node === null || node === void 0 ? void 0 : node.type) === 'TaggedTemplateExpression' && node.tag.type === 'MemberExpression' && node.tag.object.type === 'Identifier' && node.tag.object.name === 'styled';
|
|
@@ -6,18 +6,26 @@ declare const ASTObjectExpression: {
|
|
|
6
6
|
*/
|
|
7
7
|
hasProperty(node: ObjectExpression, name: string): boolean;
|
|
8
8
|
/**
|
|
9
|
-
* Returns
|
|
9
|
+
* Returns true if an object contains no nested values, false otherwise.
|
|
10
|
+
*
|
|
11
|
+
* Note:
|
|
12
|
+
* - Returns false if object contains spread elements.
|
|
13
|
+
* - Returns true if object is empty.
|
|
14
|
+
*/
|
|
15
|
+
isFlat(node: ObjectExpression): boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Returns a key-value pair like: `padding: '8px'` from: `{ padding: '8px' }`.
|
|
10
18
|
*/
|
|
11
19
|
getEntryByPropertyName(node: ObjectExpression, name: string): Property | undefined;
|
|
12
20
|
deleteEntry(node: ObjectExpression, name: string, fixer: Rule.RuleFixer): Rule.Fix[];
|
|
13
21
|
/**
|
|
14
|
-
* Returns a only the property @type {Property['key']} like: `padding` from: `{ padding: '8px' }
|
|
22
|
+
* Returns a only the property @type {Property['key']} like: `padding` from: `{ padding: '8px' }`.
|
|
15
23
|
*/
|
|
16
24
|
getProperty(node: ObjectExpression, name: string): Property['key'] | undefined;
|
|
17
25
|
/**
|
|
18
|
-
* Returns a only the property @type {Property['value']} like: `'8px` from: `{ padding: '8px' }
|
|
26
|
+
* Returns a only the property @type {Property['value']} like: `'8px` from: `{ padding: '8px' }`.
|
|
19
27
|
*
|
|
20
|
-
* Values can be basically anything, so be careful with this
|
|
28
|
+
* Values can be basically anything, so be careful with this.
|
|
21
29
|
*/
|
|
22
30
|
getValueByPropertyName(node: ObjectExpression, name: string): Property['value'] | undefined;
|
|
23
31
|
containsSpreadProps(node: ObjectExpression): boolean;
|
|
@@ -32,7 +40,7 @@ declare const ASTObjectExpression: {
|
|
|
32
40
|
* fixer,
|
|
33
41
|
* )
|
|
34
42
|
* ```
|
|
35
|
-
* Will result in `{ padding: 'space.100', margin: 'space.200'}
|
|
43
|
+
* Will result in `{ padding: 'space.100', margin: 'space.200'}`.
|
|
36
44
|
*/
|
|
37
45
|
appendEntry(node: ObjectExpression, key: string, value: string, fixer: Rule.RuleFixer): Rule.Fix;
|
|
38
46
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
type Pattern = 'compiled-css-function' | 'compiled-styled-object' | 'css-template-literal' | 'css-property-with-tokens' | 'css-property-multiple-values';
|
|
1
|
+
type Pattern = 'compiled-css-function' | 'compiled-styled-object' | 'css-template-literal' | 'css-property-with-tokens' | 'css-property-multiple-values' | 'multiple-properties';
|
|
2
2
|
export interface RuleConfig {
|
|
3
3
|
patterns: Pattern[];
|
|
4
4
|
}
|
|
@@ -4,6 +4,7 @@ export declare const isDecendantOfGlobalToken: (node: EslintNode) => boolean;
|
|
|
4
4
|
export declare const isDecendantOfType: (node: Rule.Node, type: Rule.Node['type'], skipNode?: boolean) => boolean;
|
|
5
5
|
export declare const isPropertyKey: (node: Rule.Node) => boolean;
|
|
6
6
|
export declare const isDecendantOfStyleJsxAttribute: (node: Rule.Node) => boolean;
|
|
7
|
+
export declare const isDecendantOfSvgElement: (node: Rule.Node) => boolean;
|
|
7
8
|
export declare const isCssInJsTemplateNode: (node?: Expression | null) => node is TaggedTemplateExpression;
|
|
8
9
|
export declare const isCssInJsCallNode: (node?: Expression | null) => node is CallExpression;
|
|
9
10
|
export declare const isCssInJsObjectNode: (node?: Expression | null) => node is CallExpression;
|
|
@@ -6,18 +6,26 @@ declare const ASTObjectExpression: {
|
|
|
6
6
|
*/
|
|
7
7
|
hasProperty(node: ObjectExpression, name: string): boolean;
|
|
8
8
|
/**
|
|
9
|
-
* Returns
|
|
9
|
+
* Returns true if an object contains no nested values, false otherwise.
|
|
10
|
+
*
|
|
11
|
+
* Note:
|
|
12
|
+
* - Returns false if object contains spread elements.
|
|
13
|
+
* - Returns true if object is empty.
|
|
14
|
+
*/
|
|
15
|
+
isFlat(node: ObjectExpression): boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Returns a key-value pair like: `padding: '8px'` from: `{ padding: '8px' }`.
|
|
10
18
|
*/
|
|
11
19
|
getEntryByPropertyName(node: ObjectExpression, name: string): Property | undefined;
|
|
12
20
|
deleteEntry(node: ObjectExpression, name: string, fixer: Rule.RuleFixer): Rule.Fix[];
|
|
13
21
|
/**
|
|
14
|
-
* Returns a only the property @type {Property['key']} like: `padding` from: `{ padding: '8px' }
|
|
22
|
+
* Returns a only the property @type {Property['key']} like: `padding` from: `{ padding: '8px' }`.
|
|
15
23
|
*/
|
|
16
24
|
getProperty(node: ObjectExpression, name: string): Property['key'] | undefined;
|
|
17
25
|
/**
|
|
18
|
-
* Returns a only the property @type {Property['value']} like: `'8px` from: `{ padding: '8px' }
|
|
26
|
+
* Returns a only the property @type {Property['value']} like: `'8px` from: `{ padding: '8px' }`.
|
|
19
27
|
*
|
|
20
|
-
* Values can be basically anything, so be careful with this
|
|
28
|
+
* Values can be basically anything, so be careful with this.
|
|
21
29
|
*/
|
|
22
30
|
getValueByPropertyName(node: ObjectExpression, name: string): Property['value'] | undefined;
|
|
23
31
|
containsSpreadProps(node: ObjectExpression): boolean;
|
|
@@ -32,7 +40,7 @@ declare const ASTObjectExpression: {
|
|
|
32
40
|
* fixer,
|
|
33
41
|
* )
|
|
34
42
|
* ```
|
|
35
|
-
* Will result in `{ padding: 'space.100', margin: 'space.200'}
|
|
43
|
+
* Will result in `{ padding: 'space.100', margin: 'space.200'}`.
|
|
36
44
|
*/
|
|
37
45
|
appendEntry(node: ObjectExpression, key: string, value: string, fixer: Rule.RuleFixer): Rule.Fix;
|
|
38
46
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
type Pattern = 'compiled-css-function' | 'compiled-styled-object' | 'css-template-literal' | 'css-property-with-tokens' | 'css-property-multiple-values';
|
|
1
|
+
type Pattern = 'compiled-css-function' | 'compiled-styled-object' | 'css-template-literal' | 'css-property-with-tokens' | 'css-property-multiple-values' | 'multiple-properties';
|
|
2
2
|
export interface RuleConfig {
|
|
3
3
|
patterns: Pattern[];
|
|
4
4
|
}
|
|
@@ -4,6 +4,7 @@ export declare const isDecendantOfGlobalToken: (node: EslintNode) => boolean;
|
|
|
4
4
|
export declare const isDecendantOfType: (node: Rule.Node, type: Rule.Node['type'], skipNode?: boolean) => boolean;
|
|
5
5
|
export declare const isPropertyKey: (node: Rule.Node) => boolean;
|
|
6
6
|
export declare const isDecendantOfStyleJsxAttribute: (node: Rule.Node) => boolean;
|
|
7
|
+
export declare const isDecendantOfSvgElement: (node: Rule.Node) => boolean;
|
|
7
8
|
export declare const isCssInJsTemplateNode: (node?: Expression | null) => node is TaggedTemplateExpression;
|
|
8
9
|
export declare const isCssInJsCallNode: (node?: Expression | null) => node is CallExpression;
|
|
9
10
|
export declare const isCssInJsObjectNode: (node?: Expression | null) => node is CallExpression;
|
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.25.0",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"registry": "https://registry.npmjs.org/"
|