@atlaskit/eslint-plugin-design-system 8.23.0 → 8.23.2
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/function-call.js +48 -0
- package/dist/cjs/ast-nodes/import.js +49 -0
- package/dist/cjs/ast-nodes/index.js +40 -0
- package/dist/cjs/ast-nodes/jsx-attribute.js +64 -0
- package/dist/cjs/ast-nodes/jsx-element.js +55 -0
- package/dist/cjs/ast-nodes/root.js +34 -0
- package/dist/cjs/rules/ensure-design-token-usage/error-boundary.js +24 -0
- package/dist/cjs/rules/ensure-design-token-usage/index.js +208 -177
- package/dist/cjs/rules/use-primitives/index.js +6 -76
- package/dist/cjs/rules/use-primitives/transformers/emotion-css/index.js +168 -0
- package/dist/cjs/rules/use-primitives/transformers/emotion-css/supported.js +52 -0
- package/dist/cjs/rules/use-primitives/utils/is-valid-css-properties-to-transform.js +3 -0
- package/dist/es2019/ast-nodes/function-call.js +42 -0
- package/dist/es2019/ast-nodes/import.js +42 -0
- package/dist/es2019/ast-nodes/index.js +5 -0
- package/dist/es2019/ast-nodes/jsx-attribute.js +59 -0
- package/dist/es2019/ast-nodes/jsx-element.js +50 -0
- package/dist/es2019/ast-nodes/root.js +28 -0
- package/dist/es2019/rules/ensure-design-token-usage/error-boundary.js +19 -0
- package/dist/es2019/rules/ensure-design-token-usage/index.js +33 -16
- package/dist/es2019/rules/use-primitives/index.js +9 -79
- package/dist/es2019/rules/use-primitives/transformers/emotion-css/index.js +159 -0
- package/dist/es2019/rules/use-primitives/transformers/emotion-css/supported.js +46 -0
- package/dist/es2019/rules/use-primitives/utils/is-valid-css-properties-to-transform.js +3 -0
- package/dist/esm/ast-nodes/function-call.js +42 -0
- package/dist/esm/ast-nodes/import.js +43 -0
- package/dist/esm/ast-nodes/index.js +5 -0
- package/dist/esm/ast-nodes/jsx-attribute.js +59 -0
- package/dist/esm/ast-nodes/jsx-element.js +50 -0
- package/dist/esm/ast-nodes/root.js +28 -0
- package/dist/esm/rules/ensure-design-token-usage/error-boundary.js +18 -0
- package/dist/esm/rules/ensure-design-token-usage/index.js +208 -177
- package/dist/esm/rules/use-primitives/index.js +9 -79
- package/dist/esm/rules/use-primitives/transformers/emotion-css/index.js +158 -0
- package/dist/esm/rules/use-primitives/transformers/emotion-css/supported.js +46 -0
- package/dist/esm/rules/use-primitives/utils/is-valid-css-properties-to-transform.js +3 -0
- package/dist/types/ast-nodes/function-call.d.ts +21 -0
- package/dist/types/ast-nodes/import.d.ts +16 -0
- package/dist/types/ast-nodes/index.d.ts +5 -0
- package/dist/types/ast-nodes/jsx-attribute.d.ts +26 -0
- package/dist/types/ast-nodes/jsx-element.d.ts +21 -0
- package/dist/types/ast-nodes/root.d.ts +19 -0
- package/dist/types/rules/ensure-design-token-usage/error-boundary.d.ts +11 -0
- package/dist/types/rules/ensure-design-token-usage/types.d.ts +1 -0
- package/dist/types/rules/use-primitives/transformers/emotion-css/index.d.ts +35 -0
- package/dist/types/rules/use-primitives/transformers/emotion-css/supported.d.ts +9 -0
- package/dist/types-ts4.5/ast-nodes/function-call.d.ts +21 -0
- package/dist/types-ts4.5/ast-nodes/import.d.ts +16 -0
- package/dist/types-ts4.5/ast-nodes/index.d.ts +5 -0
- package/dist/types-ts4.5/ast-nodes/jsx-attribute.d.ts +26 -0
- package/dist/types-ts4.5/ast-nodes/jsx-element.d.ts +21 -0
- package/dist/types-ts4.5/ast-nodes/root.d.ts +19 -0
- package/dist/types-ts4.5/rules/ensure-design-token-usage/error-boundary.d.ts +11 -0
- package/dist/types-ts4.5/rules/ensure-design-token-usage/types.d.ts +1 -0
- package/dist/types-ts4.5/rules/use-primitives/transformers/emotion-css/index.d.ts +35 -0
- package/dist/types-ts4.5/rules/use-primitives/transformers/emotion-css/supported.d.ts +9 -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.23.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#65758](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/65758) [`16e6a0fbe125`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/16e6a0fbe125) - Internal refactor of `use-primitves` rule. There should be no change to consumers of the rule.
|
|
8
|
+
|
|
9
|
+
## 8.23.1
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [#68093](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/68093) [`4c5371a76547`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/4c5371a76547) - Wrap ensure-design-token-usage with an error boudary to stop it breaking issue-automat CI.
|
|
14
|
+
|
|
3
15
|
## 8.23.0
|
|
4
16
|
|
|
5
17
|
### Minor Changes
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.FunctionCall = void 0;
|
|
7
|
+
var _eslintCodemodUtils = require("eslint-codemod-utils");
|
|
8
|
+
/* eslint-disable @repo/internal/react/require-jsdoc */
|
|
9
|
+
|
|
10
|
+
var FunctionCall = exports.FunctionCall = {
|
|
11
|
+
getName: function getName(node) {
|
|
12
|
+
if (!(0, _eslintCodemodUtils.isNodeOfType)(node, 'CallExpression')) {
|
|
13
|
+
return undefined;
|
|
14
|
+
}
|
|
15
|
+
if (!(0, _eslintCodemodUtils.isNodeOfType)(node.callee, 'Identifier')) {
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
18
|
+
return node.callee.name;
|
|
19
|
+
},
|
|
20
|
+
updateName: function updateName(node, newName, fixer) {
|
|
21
|
+
return fixer.replaceText(node.callee, newName);
|
|
22
|
+
},
|
|
23
|
+
/**
|
|
24
|
+
* Function arguments can be many things:
|
|
25
|
+
* `css(myStyles, () => {}, undefined, 'literal', ...rest) // etc`
|
|
26
|
+
* They all need slightly different treatment.
|
|
27
|
+
*
|
|
28
|
+
* Currently 'getArgumentAtPos' only implements strategies for Literals and ObjectExpressions.
|
|
29
|
+
* If you need to support another type of arg, add it, and update the type.
|
|
30
|
+
*/
|
|
31
|
+
getArgumentAtPos: function getArgumentAtPos(node, pos) {
|
|
32
|
+
var argument = node.arguments[pos];
|
|
33
|
+
if ((0, _eslintCodemodUtils.isNodeOfType)(argument, 'Literal') && argument.value) {
|
|
34
|
+
var _argument$value;
|
|
35
|
+
return {
|
|
36
|
+
type: 'Literal',
|
|
37
|
+
value: (_argument$value = argument.value) === null || _argument$value === void 0 ? void 0 : _argument$value.toString()
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
if ((0, _eslintCodemodUtils.isNodeOfType)(argument, 'ObjectExpression')) {
|
|
41
|
+
argument;
|
|
42
|
+
return {
|
|
43
|
+
type: 'ObjectExpression',
|
|
44
|
+
value: argument
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.Import = void 0;
|
|
7
|
+
var _eslintCodemodUtils = require("eslint-codemod-utils");
|
|
8
|
+
/* eslint-disable @repo/internal/react/require-jsdoc */
|
|
9
|
+
|
|
10
|
+
var Import = exports.Import = {
|
|
11
|
+
/**
|
|
12
|
+
* Note: fixes can't overlap, which means this will fail:
|
|
13
|
+
* ```
|
|
14
|
+
* const importNode = Root.findImportByModule('@atlaskit/primitives')
|
|
15
|
+
* Import.insertNamedSpecifier(importNode, 'Box')
|
|
16
|
+
* Import.insertNamedSpecifier(importNode, 'xcss')
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* For this reason `insertNamedSpecifiers` accepts a `specifiers` array, so you can group all inserts together.
|
|
20
|
+
*/
|
|
21
|
+
insertNamedSpecifiers: function insertNamedSpecifiers(node, specifiers, fixer) {
|
|
22
|
+
var _this = this;
|
|
23
|
+
/**
|
|
24
|
+
* `insertImportSpecifier()` has the unfortunate implementation detail of naively adding duplicate specifiers.
|
|
25
|
+
* e.g. calling
|
|
26
|
+
* `insertImportSpecifier(importDecl, 'xcss')`
|
|
27
|
+
* on
|
|
28
|
+
* `import { Inline, xcss } from '@atlaskit/primitives'`
|
|
29
|
+
* will result in:
|
|
30
|
+
* `import { Inline, xcss, xcss } from '@atlaskit/primitives'`.
|
|
31
|
+
* So, we need to filter out specifiers that are already imported.
|
|
32
|
+
*/
|
|
33
|
+
var uniqueSpecifiers = specifiers.filter(function (specifier) {
|
|
34
|
+
return !_this.containsNamedSpecifier(node, specifier);
|
|
35
|
+
});
|
|
36
|
+
if (uniqueSpecifiers.length === 0) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
return fixer.replaceText(node, "".concat((0, _eslintCodemodUtils.insertImportSpecifier)(node, uniqueSpecifiers.join(', ')), ";\n"));
|
|
40
|
+
},
|
|
41
|
+
containsNamedSpecifier: function containsNamedSpecifier(node, name) {
|
|
42
|
+
return node.specifiers.some(function (specifier) {
|
|
43
|
+
if (!(0, _eslintCodemodUtils.isNodeOfType)(specifier, 'ImportSpecifier')) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
return specifier.imported.name === name;
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "FunctionCall", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function get() {
|
|
9
|
+
return _functionCall.FunctionCall;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "Import", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function get() {
|
|
15
|
+
return _import.Import;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(exports, "JSXAttribute", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function get() {
|
|
21
|
+
return _jsxAttribute.JSXAttribute;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
Object.defineProperty(exports, "JSXElement", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function get() {
|
|
27
|
+
return _jsxElement.JSXElement;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
Object.defineProperty(exports, "Root", {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
get: function get() {
|
|
33
|
+
return _root.Root;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
var _functionCall = require("./function-call");
|
|
37
|
+
var _import = require("./import");
|
|
38
|
+
var _jsxAttribute = require("./jsx-attribute");
|
|
39
|
+
var _jsxElement = require("./jsx-element");
|
|
40
|
+
var _root = require("./root");
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.JSXAttribute = void 0;
|
|
7
|
+
var _eslintCodemodUtils = require("eslint-codemod-utils");
|
|
8
|
+
var HelperJSXAttribute = exports.JSXAttribute = {
|
|
9
|
+
getName: function getName(node) {
|
|
10
|
+
if (!(0, _eslintCodemodUtils.isNodeOfType)(node, 'JSXAttribute')) {
|
|
11
|
+
throw new Error('Not a JSXAttribute');
|
|
12
|
+
}
|
|
13
|
+
if (!(0, _eslintCodemodUtils.isNodeOfType)(node.name, 'JSXIdentifier')) {
|
|
14
|
+
throw new Error('name is not a JSXIdentifier');
|
|
15
|
+
}
|
|
16
|
+
return node.name.name;
|
|
17
|
+
},
|
|
18
|
+
updateName: function updateName(node, name, fixer) {
|
|
19
|
+
if (!(0, _eslintCodemodUtils.isNodeOfType)(node, 'JSXAttribute')) {
|
|
20
|
+
throw new Error('Not a JSXAttribute');
|
|
21
|
+
}
|
|
22
|
+
if (!(0, _eslintCodemodUtils.isNodeOfType)(node.name, 'JSXIdentifier')) {
|
|
23
|
+
throw new Error('name is not a JSXIdentifier');
|
|
24
|
+
}
|
|
25
|
+
return fixer.replaceText(node.name, (0, _eslintCodemodUtils.literal)(name).toString());
|
|
26
|
+
},
|
|
27
|
+
/**
|
|
28
|
+
* A JSXAttribute value can be many things:
|
|
29
|
+
* - css='myStyles'
|
|
30
|
+
* - css={myStyles}
|
|
31
|
+
* - css={[styles1, styles2]}
|
|
32
|
+
* - header={<></>}
|
|
33
|
+
* - css={styleMap.header}
|
|
34
|
+
* - css={...styles}
|
|
35
|
+
*
|
|
36
|
+
* Currently, `getValue` has only implemented strategies for when the value is a string, or an ExpressionStatement
|
|
37
|
+
* If you need additional functionality add it, and set the correct `type` on the returned object
|
|
38
|
+
*/
|
|
39
|
+
getValue: function getValue(node) {
|
|
40
|
+
if (!(0, _eslintCodemodUtils.isNodeOfType)(node, 'JSXAttribute')) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
if (!node.value) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// handle `css={myStyles}`
|
|
48
|
+
if ((0, _eslintCodemodUtils.isNodeOfType)(node.value, 'JSXExpressionContainer') && (0, _eslintCodemodUtils.isNodeOfType)(node.value.expression, 'Identifier')) {
|
|
49
|
+
return {
|
|
50
|
+
type: 'ExpressionStatement',
|
|
51
|
+
value: node.value.expression.name
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// handle `css='myStyles'`
|
|
56
|
+
if ((0, _eslintCodemodUtils.isNodeOfType)(node.value, 'Literal') && node.value.value) {
|
|
57
|
+
var _node$value$value;
|
|
58
|
+
return {
|
|
59
|
+
type: 'Literal',
|
|
60
|
+
value: (_node$value$value = node.value.value) === null || _node$value$value === void 0 ? void 0 : _node$value$value.toString()
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.JSXElementHelper = exports.JSXElement = void 0;
|
|
7
|
+
var _eslintCodemodUtils = require("eslint-codemod-utils");
|
|
8
|
+
var JSXElementHelper = exports.JSXElement = exports.JSXElementHelper = {
|
|
9
|
+
/**
|
|
10
|
+
* Names of JSXElements can be any of:
|
|
11
|
+
* `<Component></Component>` - (JSXIdentifier)
|
|
12
|
+
* `<MyComponents.Component></MyComponents.Component>` - `MyComponents` is a namespace (JSXNamespacedName)
|
|
13
|
+
* `<MyComponents.Component></MyComponents.Component>` - `MyComponents` is an object (JSXMemberExpression)
|
|
14
|
+
*
|
|
15
|
+
* Getting the name of a JSXMemberExpression is difficult, because object can contain objects, which is recursively defined in the AST.
|
|
16
|
+
* e.g. getting the name of `<MyComponents.PresentationLayer.LeftSideBar.Header />` would require `getName` to recursively resolve all parts of the name.
|
|
17
|
+
* `getName` does not currently have this functionality. Add it if you need it.
|
|
18
|
+
*/
|
|
19
|
+
getName: function getName(node) {
|
|
20
|
+
if (!(0, _eslintCodemodUtils.isNodeOfType)(node.openingElement.name, 'JSXIdentifier')) {
|
|
21
|
+
// TODO: We may want to log this
|
|
22
|
+
return '';
|
|
23
|
+
}
|
|
24
|
+
return node.openingElement.name.name;
|
|
25
|
+
},
|
|
26
|
+
updateName: function updateName(node, newName, fixer) {
|
|
27
|
+
var isSelfClosing = JSXElementHelper.isSelfClosing(node);
|
|
28
|
+
var openingElementFix = fixer.replaceText(node.openingElement.name, (0, _eslintCodemodUtils.jsxIdentifier)(newName).toString());
|
|
29
|
+
if (isSelfClosing || !node.closingElement) {
|
|
30
|
+
return [openingElementFix];
|
|
31
|
+
}
|
|
32
|
+
var closingElementFix = fixer.replaceText(node.closingElement.name, (0, _eslintCodemodUtils.jsxIdentifier)(newName).toString());
|
|
33
|
+
return [openingElementFix, closingElementFix];
|
|
34
|
+
},
|
|
35
|
+
isSelfClosing: function isSelfClosing(node) {
|
|
36
|
+
return node.openingElement.selfClosing;
|
|
37
|
+
},
|
|
38
|
+
getAttributes: function getAttributes(node) {
|
|
39
|
+
return node.openingElement.attributes;
|
|
40
|
+
},
|
|
41
|
+
getAttributeByName: function getAttributeByName(node, name) {
|
|
42
|
+
return node.openingElement.attributes.find(function (attr) {
|
|
43
|
+
// Ignore anything other than JSXAttribute
|
|
44
|
+
if (!(0, _eslintCodemodUtils.isNodeOfType)(attr, 'JSXAttribute')) {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
return attr.name.name === name;
|
|
48
|
+
});
|
|
49
|
+
},
|
|
50
|
+
containsSpreadAttributes: function containsSpreadAttributes(node) {
|
|
51
|
+
return node.openingElement.attributes.some(function (attr) {
|
|
52
|
+
return (0, _eslintCodemodUtils.isNodeOfType)(attr, 'JSXSpreadAttribute');
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.Root = void 0;
|
|
7
|
+
var _eslintCodemodUtils = require("eslint-codemod-utils");
|
|
8
|
+
/* eslint-disable @repo/internal/react/require-jsdoc */
|
|
9
|
+
|
|
10
|
+
// Little bit unreadable, but better than duplicating the type
|
|
11
|
+
|
|
12
|
+
var Root = exports.Root = {
|
|
13
|
+
/**
|
|
14
|
+
* Note: This can return multiple ImportDeclarations for cases like:
|
|
15
|
+
* ```
|
|
16
|
+
* import { Stack } from '@atlaskit/primitives'
|
|
17
|
+
* import type { StackProps } from '@atlaskit/primitives'
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
findImportsByModule: function findImportsByModule(root, name) {
|
|
21
|
+
return root.filter(function (node) {
|
|
22
|
+
if (!(0, _eslintCodemodUtils.isNodeOfType)(node, 'ImportDeclaration')) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
if (!(0, _eslintCodemodUtils.hasImportDeclaration)(node, name)) {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
return true;
|
|
29
|
+
});
|
|
30
|
+
},
|
|
31
|
+
insertImport: function insertImport(root, data, fixer) {
|
|
32
|
+
return fixer.insertTextBefore(root[0], "".concat((0, _eslintCodemodUtils.insertImportDeclaration)(data.module, data.specifiers), ";\n"));
|
|
33
|
+
}
|
|
34
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.errorBoundary = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* ESLint rules should NEVER throw exceptions, because that breaks the VSCode ESLint server
|
|
9
|
+
* (and probably the IntelliJ one too), which causes linting to fail in a file.
|
|
10
|
+
*
|
|
11
|
+
* It also breaks CI, which was the reason this error boundary was added. It's a final
|
|
12
|
+
* catch all.
|
|
13
|
+
*/
|
|
14
|
+
var errorBoundary = exports.errorBoundary = function errorBoundary(func, _ref) {
|
|
15
|
+
var config = _ref.config;
|
|
16
|
+
try {
|
|
17
|
+
func();
|
|
18
|
+
} catch (err) {
|
|
19
|
+
if (!config.failSilently) {
|
|
20
|
+
// eslint-disable-next-line no-console
|
|
21
|
+
console.warn(err);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
};
|