@atlaskit/eslint-plugin-design-system 8.23.2 → 8.23.4
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 +15 -0
- package/README.md +1 -0
- package/constellation/index/usage.mdx +39 -0
- package/dist/cjs/ast-nodes/index.js +7 -0
- package/dist/cjs/ast-nodes/object.js +84 -0
- package/dist/cjs/presets/all.codegen.js +2 -1
- package/dist/cjs/presets/recommended.codegen.js +2 -1
- package/dist/cjs/rules/consistent-css-prop-usage/index.js +25 -5
- package/dist/cjs/rules/index.codegen.js +3 -1
- package/dist/cjs/rules/local-cx-xcss/index.js +51 -0
- package/dist/cjs/rules/no-css-tagged-template-expression/create-no-tagged-template-expression-rule/index.js +3 -1
- package/dist/cjs/rules/no-css-tagged-template-expression/index.js +2 -2
- package/dist/cjs/rules/use-primitives/index.js +4 -30
- package/dist/cjs/rules/use-primitives/transformers/compiled-styled/convert-jsx-call-site.js +39 -0
- package/dist/cjs/rules/use-primitives/transformers/compiled-styled/convert-styled-component-call-to-jsx.js +44 -0
- package/dist/cjs/rules/use-primitives/{utils → transformers/compiled-styled}/find-valid-styled-component-call.js +5 -2
- package/dist/cjs/rules/use-primitives/transformers/compiled-styled/index.js +117 -0
- package/dist/cjs/rules/use-primitives/transformers/compiled-styled/supported.js +10 -0
- package/dist/cjs/rules/use-primitives/transformers/compiled-styled/upsert-import-declaration.js +37 -0
- package/dist/cjs/rules/use-primitives/transformers/emotion-css/contains-only-supported-attrs.js +27 -0
- package/dist/cjs/rules/use-primitives/transformers/emotion-css/index.js +4 -47
- package/dist/cjs/rules/use-primitives/transformers/emotion-css/supported.js +2 -44
- package/dist/cjs/rules/use-primitives/transformers/emotion-css/upsert-import-declaration.js +37 -0
- package/dist/cjs/rules/use-primitives/transformers/index.js +10 -10
- package/dist/cjs/rules/use-primitives/utils/index.js +1 -43
- package/dist/cjs/rules/utils/is-supported-import.js +61 -0
- package/dist/es2019/ast-nodes/index.js +1 -0
- package/dist/es2019/ast-nodes/object.js +79 -0
- package/dist/es2019/presets/all.codegen.js +2 -1
- package/dist/es2019/presets/recommended.codegen.js +2 -1
- package/dist/es2019/rules/consistent-css-prop-usage/index.js +23 -5
- package/dist/es2019/rules/index.codegen.js +3 -1
- package/dist/es2019/rules/local-cx-xcss/index.js +45 -0
- package/dist/es2019/rules/no-css-tagged-template-expression/create-no-tagged-template-expression-rule/index.js +3 -1
- package/dist/es2019/rules/no-css-tagged-template-expression/index.js +2 -2
- package/dist/es2019/rules/use-primitives/index.js +4 -30
- package/dist/es2019/rules/use-primitives/transformers/compiled-styled/convert-jsx-call-site.js +29 -0
- package/dist/es2019/rules/use-primitives/transformers/compiled-styled/convert-styled-component-call-to-jsx.js +37 -0
- package/dist/es2019/rules/use-primitives/{utils → transformers/compiled-styled}/find-valid-styled-component-call.js +2 -2
- package/dist/es2019/rules/use-primitives/transformers/compiled-styled/index.js +107 -0
- package/dist/es2019/rules/use-primitives/transformers/compiled-styled/supported.js +4 -0
- package/dist/es2019/rules/use-primitives/transformers/compiled-styled/upsert-import-declaration.js +30 -0
- package/dist/es2019/rules/use-primitives/transformers/emotion-css/contains-only-supported-attrs.js +19 -0
- package/dist/es2019/rules/use-primitives/transformers/emotion-css/index.js +4 -48
- package/dist/es2019/rules/use-primitives/transformers/emotion-css/supported.js +1 -43
- package/dist/es2019/rules/use-primitives/transformers/emotion-css/upsert-import-declaration.js +30 -0
- package/dist/es2019/rules/use-primitives/transformers/index.js +2 -2
- package/dist/es2019/rules/use-primitives/utils/index.js +1 -7
- package/dist/es2019/rules/utils/is-supported-import.js +52 -0
- package/dist/esm/ast-nodes/index.js +1 -0
- package/dist/esm/ast-nodes/object.js +79 -0
- package/dist/esm/presets/all.codegen.js +2 -1
- package/dist/esm/presets/recommended.codegen.js +2 -1
- package/dist/esm/rules/consistent-css-prop-usage/index.js +25 -5
- package/dist/esm/rules/index.codegen.js +3 -1
- package/dist/esm/rules/local-cx-xcss/index.js +45 -0
- package/dist/esm/rules/no-css-tagged-template-expression/create-no-tagged-template-expression-rule/index.js +3 -1
- package/dist/esm/rules/no-css-tagged-template-expression/index.js +2 -2
- package/dist/esm/rules/use-primitives/index.js +4 -30
- package/dist/esm/rules/use-primitives/transformers/compiled-styled/convert-jsx-call-site.js +30 -0
- package/dist/esm/rules/use-primitives/transformers/compiled-styled/convert-styled-component-call-to-jsx.js +38 -0
- package/dist/esm/rules/use-primitives/{utils → transformers/compiled-styled}/find-valid-styled-component-call.js +2 -2
- package/dist/esm/rules/use-primitives/transformers/compiled-styled/index.js +107 -0
- package/dist/esm/rules/use-primitives/transformers/compiled-styled/supported.js +4 -0
- package/dist/esm/rules/use-primitives/transformers/compiled-styled/upsert-import-declaration.js +29 -0
- package/dist/esm/rules/use-primitives/transformers/emotion-css/contains-only-supported-attrs.js +19 -0
- package/dist/esm/rules/use-primitives/transformers/emotion-css/index.js +4 -47
- package/dist/esm/rules/use-primitives/transformers/emotion-css/supported.js +1 -43
- package/dist/esm/rules/use-primitives/transformers/emotion-css/upsert-import-declaration.js +29 -0
- package/dist/esm/rules/use-primitives/transformers/index.js +2 -2
- package/dist/esm/rules/use-primitives/utils/index.js +1 -7
- package/dist/esm/rules/utils/is-supported-import.js +54 -0
- package/dist/types/ast-nodes/index.d.ts +1 -0
- package/dist/types/ast-nodes/object.d.ts +39 -0
- package/dist/types/index.codegen.d.ts +2 -0
- package/dist/types/presets/all.codegen.d.ts +2 -1
- package/dist/types/presets/recommended.codegen.d.ts +2 -1
- package/dist/types/rules/index.codegen.d.ts +1 -0
- package/dist/types/rules/local-cx-xcss/index.d.ts +3 -0
- package/dist/types/rules/no-css-tagged-template-expression/create-no-tagged-template-expression-rule/index.d.ts +3 -4
- package/dist/types/rules/use-primitives/transformers/compiled-styled/convert-jsx-call-site.d.ts +17 -0
- package/dist/types/rules/use-primitives/transformers/compiled-styled/convert-styled-component-call-to-jsx.d.ts +17 -0
- package/dist/types/rules/use-primitives/transformers/compiled-styled/index.d.ts +25 -0
- package/dist/types/rules/use-primitives/transformers/compiled-styled/supported.d.ts +2 -0
- package/dist/types/rules/use-primitives/transformers/compiled-styled/upsert-import-declaration.d.ts +14 -0
- package/dist/types/rules/use-primitives/transformers/emotion-css/contains-only-supported-attrs.d.ts +7 -0
- package/dist/types/rules/use-primitives/transformers/emotion-css/index.d.ts +0 -19
- package/dist/types/rules/use-primitives/transformers/emotion-css/supported.d.ts +0 -7
- package/dist/types/rules/use-primitives/transformers/emotion-css/upsert-import-declaration.d.ts +14 -0
- package/dist/types/rules/use-primitives/transformers/index.d.ts +2 -2
- package/dist/types/rules/use-primitives/utils/index.d.ts +0 -6
- package/dist/types/rules/utils/is-supported-import.d.ts +16 -0
- package/dist/types-ts4.5/ast-nodes/index.d.ts +1 -0
- package/dist/types-ts4.5/ast-nodes/object.d.ts +39 -0
- package/dist/types-ts4.5/index.codegen.d.ts +2 -0
- package/dist/types-ts4.5/presets/all.codegen.d.ts +2 -1
- package/dist/types-ts4.5/presets/recommended.codegen.d.ts +2 -1
- package/dist/types-ts4.5/rules/index.codegen.d.ts +1 -0
- package/dist/types-ts4.5/rules/local-cx-xcss/index.d.ts +3 -0
- package/dist/types-ts4.5/rules/no-css-tagged-template-expression/create-no-tagged-template-expression-rule/index.d.ts +3 -4
- package/dist/types-ts4.5/rules/use-primitives/transformers/compiled-styled/convert-jsx-call-site.d.ts +17 -0
- package/dist/types-ts4.5/rules/use-primitives/transformers/compiled-styled/convert-styled-component-call-to-jsx.d.ts +17 -0
- package/dist/types-ts4.5/rules/use-primitives/transformers/compiled-styled/index.d.ts +25 -0
- package/dist/types-ts4.5/rules/use-primitives/transformers/compiled-styled/supported.d.ts +2 -0
- package/dist/types-ts4.5/rules/use-primitives/transformers/compiled-styled/upsert-import-declaration.d.ts +14 -0
- package/dist/types-ts4.5/rules/use-primitives/transformers/emotion-css/contains-only-supported-attrs.d.ts +7 -0
- package/dist/types-ts4.5/rules/use-primitives/transformers/emotion-css/index.d.ts +0 -19
- package/dist/types-ts4.5/rules/use-primitives/transformers/emotion-css/supported.d.ts +0 -7
- package/dist/types-ts4.5/rules/use-primitives/transformers/emotion-css/upsert-import-declaration.d.ts +14 -0
- package/dist/types-ts4.5/rules/use-primitives/transformers/index.d.ts +2 -2
- package/dist/types-ts4.5/rules/use-primitives/utils/index.d.ts +0 -6
- package/dist/types-ts4.5/rules/utils/is-supported-import.d.ts +16 -0
- package/package.json +1 -1
- package/dist/cjs/rules/no-css-tagged-template-expression/is-supported-import.js +0 -29
- package/dist/cjs/rules/use-primitives/transformers/jsx-element-to-box.js +0 -26
- package/dist/cjs/rules/use-primitives/transformers/styled-component-to-primitive.js +0 -68
- package/dist/cjs/rules/use-primitives/utils/contains-only-supported-attrs.js +0 -19
- package/dist/cjs/rules/use-primitives/utils/is-valid-tag-name.js +0 -13
- package/dist/cjs/rules/use-primitives/utils/update-jsx-element-name.js +0 -16
- package/dist/cjs/rules/use-primitives/utils/upsert-import-declaration.js +0 -80
- package/dist/es2019/rules/no-css-tagged-template-expression/is-supported-import.js +0 -21
- package/dist/es2019/rules/use-primitives/transformers/jsx-element-to-box.js +0 -16
- package/dist/es2019/rules/use-primitives/transformers/styled-component-to-primitive.js +0 -59
- package/dist/es2019/rules/use-primitives/utils/contains-only-supported-attrs.js +0 -13
- package/dist/es2019/rules/use-primitives/utils/is-valid-tag-name.js +0 -7
- package/dist/es2019/rules/use-primitives/utils/update-jsx-element-name.js +0 -12
- package/dist/es2019/rules/use-primitives/utils/upsert-import-declaration.js +0 -76
- package/dist/esm/rules/no-css-tagged-template-expression/is-supported-import.js +0 -23
- package/dist/esm/rules/use-primitives/transformers/jsx-element-to-box.js +0 -19
- package/dist/esm/rules/use-primitives/transformers/styled-component-to-primitive.js +0 -61
- package/dist/esm/rules/use-primitives/utils/contains-only-supported-attrs.js +0 -13
- package/dist/esm/rules/use-primitives/utils/is-valid-tag-name.js +0 -7
- package/dist/esm/rules/use-primitives/utils/update-jsx-element-name.js +0 -10
- package/dist/esm/rules/use-primitives/utils/upsert-import-declaration.js +0 -75
- package/dist/types/rules/no-css-tagged-template-expression/is-supported-import.d.ts +0 -12
- package/dist/types/rules/use-primitives/transformers/jsx-element-to-box.d.ts +0 -3
- package/dist/types/rules/use-primitives/transformers/styled-component-to-primitive.d.ts +0 -13
- package/dist/types/rules/use-primitives/utils/contains-only-supported-attrs.d.ts +0 -2
- package/dist/types/rules/use-primitives/utils/is-valid-tag-name.d.ts +0 -3
- package/dist/types/rules/use-primitives/utils/update-jsx-element-name.d.ts +0 -3
- package/dist/types/rules/use-primitives/utils/upsert-import-declaration.d.ts +0 -11
- package/dist/types-ts4.5/rules/no-css-tagged-template-expression/is-supported-import.d.ts +0 -12
- package/dist/types-ts4.5/rules/use-primitives/transformers/jsx-element-to-box.d.ts +0 -3
- package/dist/types-ts4.5/rules/use-primitives/transformers/styled-component-to-primitive.d.ts +0 -13
- package/dist/types-ts4.5/rules/use-primitives/utils/contains-only-supported-attrs.d.ts +0 -2
- package/dist/types-ts4.5/rules/use-primitives/utils/is-valid-tag-name.d.ts +0 -3
- package/dist/types-ts4.5/rules/use-primitives/utils/update-jsx-element-name.d.ts +0 -3
- package/dist/types-ts4.5/rules/use-primitives/utils/upsert-import-declaration.d.ts +0 -11
- /package/dist/cjs/rules/use-primitives/{utils → transformers/compiled-styled}/find-valid-jsx-usage-to-transform.js +0 -0
- /package/dist/es2019/rules/use-primitives/{utils → transformers/compiled-styled}/find-valid-jsx-usage-to-transform.js +0 -0
- /package/dist/esm/rules/use-primitives/{utils → transformers/compiled-styled}/find-valid-jsx-usage-to-transform.js +0 -0
- /package/dist/types/rules/use-primitives/{utils → transformers/compiled-styled}/find-valid-jsx-usage-to-transform.d.ts +0 -0
- /package/dist/types/rules/use-primitives/{utils → transformers/compiled-styled}/find-valid-styled-component-call.d.ts +0 -0
- /package/dist/types-ts4.5/rules/use-primitives/{utils → transformers/compiled-styled}/find-valid-jsx-usage-to-transform.d.ts +0 -0
- /package/dist/types-ts4.5/rules/use-primitives/{utils → transformers/compiled-styled}/find-valid-styled-component-call.d.ts +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @atlaskit/eslint-plugin-design-system
|
|
2
2
|
|
|
3
|
+
## 8.23.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#69370](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/69370) [`e14e79732cd4`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/e14e79732cd4) - Add local-cx-xcss rule, which ensures that the `cx()` function (if imported from `@compiled/react` or `@atlaskit/css`) is only used within the `xcss` prop.
|
|
8
|
+
|
|
9
|
+
Internal changes: Also refactored the utility functions used by `no-css-tagged-template-expression`.
|
|
10
|
+
|
|
11
|
+
## 8.23.3
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- [#69222](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/69222) [`a1c52086fdb9`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/a1c52086fdb9) - Address issues in consistent-css-prop-usage hoisting and naming fixers
|
|
16
|
+
- Updated dependencies
|
|
17
|
+
|
|
3
18
|
## 8.23.2
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -53,6 +53,7 @@ module.exports = {
|
|
|
53
53
|
| <a href="./src/rules/ensure-design-token-usage/README.md">ensure-design-token-usage</a> | Enforces usage of design tokens rather than hard-coded values. | Yes | Yes | Yes |
|
|
54
54
|
| <a href="./src/rules/ensure-design-token-usage-preview/README.md">ensure-design-token-usage/preview</a> | Enforces usage of pre-release design tokens rather than hard-coded values. | | Yes | Yes |
|
|
55
55
|
| <a href="./src/rules/icon-label/README.md">icon-label</a> | Enforces accessible usage of icon labels when composed with Atlassian Design System components. | Yes | Yes | |
|
|
56
|
+
| <a href="./src/rules/local-cx-xcss/README.md">local-cx-xcss</a> | Ensures the cx() function, which is part of the XCSS API, is only used within the xcss prop. This aids tracking what styles are applied to a jsx element. | Yes | | |
|
|
56
57
|
| <a href="./src/rules/no-banned-imports/README.md">no-banned-imports</a> | Disallow importing banned modules. | Yes | | |
|
|
57
58
|
| <a href="./src/rules/no-css-tagged-template-expression/README.md">no-css-tagged-template-expression</a> | Disallows any `css` tagged template expressions that originate from Emotion, Styled Components or Compiled | | Yes | |
|
|
58
59
|
| <a href="./src/rules/no-deprecated-apis/README.md">no-deprecated-apis</a> | Disallow using deprecated APIs. | Yes | | |
|
|
@@ -17,6 +17,7 @@ This plugin contains rules that should be used when working with the [Atlassian
|
|
|
17
17
|
| <a href="#ensure-design-token-usage">ensure-design-token-usage</a> | Enforces usage of design tokens rather than hard-coded values. | Yes | Yes | Yes |
|
|
18
18
|
| <a href="#ensure-design-token-usage-preview">ensure-design-token-usage/preview</a> | Enforces usage of pre-release design tokens rather than hard-coded values. | | Yes | Yes |
|
|
19
19
|
| <a href="#icon-label">icon-label</a> | Enforces accessible usage of icon labels when composed with Atlassian Design System components. | Yes | Yes | |
|
|
20
|
+
| <a href="#local-cx-xcss">local-cx-xcss</a> | Ensures the cx() function, which is part of the XCSS API, is only used within the xcss prop. This aids tracking what styles are applied to a jsx element. | Yes | | |
|
|
20
21
|
| <a href="#no-banned-imports">no-banned-imports</a> | Disallow importing banned modules. | Yes | | |
|
|
21
22
|
| <a href="#no-css-tagged-template-expression">no-css-tagged-template-expression</a> | Disallows any `css` tagged template expressions that originate from Emotion, Styled Components or Compiled | | Yes | |
|
|
22
23
|
| <a href="#no-deprecated-apis">no-deprecated-apis</a> | Disallow using deprecated APIs. | Yes | | |
|
|
@@ -318,6 +319,44 @@ import ActivityIcon from '@atlaskit/icon/glyph/activity'
|
|
|
318
319
|
</ButtonItem>
|
|
319
320
|
```
|
|
320
321
|
|
|
322
|
+
## local-cx-xcss
|
|
323
|
+
|
|
324
|
+
This rule ensures the `cx()` function is only used within the `xcss` prop. This aids tracking what styles are applied to a jsx element.
|
|
325
|
+
|
|
326
|
+
The `cx` function is checked only if it is imported from `@compiled/react` or `@atlaskit/css`.
|
|
327
|
+
|
|
328
|
+
Passing arguments to the `cx()` function is how you compose styles (combine more than one set of styles together) with XCSS. This is a workaround for the more conventional array syntax (e.g. [in Emotion](https://emotion.sh/docs/composition)) `<div xcss={[style1, style2]} />` not giving robust enough type checking.
|
|
329
|
+
|
|
330
|
+
<h3>Examples</h3>
|
|
331
|
+
|
|
332
|
+
#### Incorrect
|
|
333
|
+
|
|
334
|
+
```js
|
|
335
|
+
import { cx, cssMap } from '@compiled/react';
|
|
336
|
+
|
|
337
|
+
const styles = cssMap({
|
|
338
|
+
text: { color: 'red' },
|
|
339
|
+
bg: { background: 'blue' },
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
const joinedStyles = cx(styles.text, styles.bg);
|
|
343
|
+
|
|
344
|
+
<Button xcss={joinedStyles} />;
|
|
345
|
+
```
|
|
346
|
+
|
|
347
|
+
#### Correct
|
|
348
|
+
|
|
349
|
+
```js
|
|
350
|
+
import { cx, cssMap } from '@compiled/react';
|
|
351
|
+
|
|
352
|
+
const styles = cssMap({
|
|
353
|
+
text: { color: 'red' },
|
|
354
|
+
bg: { background: 'blue' },
|
|
355
|
+
});
|
|
356
|
+
|
|
357
|
+
<Button xcss={cx(styles.text, styles.bg)} />;
|
|
358
|
+
```
|
|
359
|
+
|
|
321
360
|
## no-banned-imports
|
|
322
361
|
|
|
323
362
|
Using private or experimental packages is dangerous as they are not supported across major versions meaning you will not be able to migrate easily causing friction for yourself and the Atlassian Design System team.
|
|
@@ -27,6 +27,12 @@ Object.defineProperty(exports, "JSXElement", {
|
|
|
27
27
|
return _jsxElement.JSXElement;
|
|
28
28
|
}
|
|
29
29
|
});
|
|
30
|
+
Object.defineProperty(exports, "Object", {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
get: function get() {
|
|
33
|
+
return _object.Object;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
30
36
|
Object.defineProperty(exports, "Root", {
|
|
31
37
|
enumerable: true,
|
|
32
38
|
get: function get() {
|
|
@@ -37,4 +43,5 @@ var _functionCall = require("./function-call");
|
|
|
37
43
|
var _import = require("./import");
|
|
38
44
|
var _jsxAttribute = require("./jsx-attribute");
|
|
39
45
|
var _jsxElement = require("./jsx-element");
|
|
46
|
+
var _object = require("./object");
|
|
40
47
|
var _root = require("./root");
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.Object = void 0;
|
|
7
|
+
var _eslintCodemodUtils = require("eslint-codemod-utils");
|
|
8
|
+
/* eslint-disable @repo/internal/react/require-jsdoc */
|
|
9
|
+
|
|
10
|
+
var ASTObjectExpression = exports.Object = {
|
|
11
|
+
/**
|
|
12
|
+
* Returns `true` if an object contains a property with the specified name, `false` otherwise.
|
|
13
|
+
*/
|
|
14
|
+
hasProperty: function hasProperty(node, name) {
|
|
15
|
+
return !!ASTObjectExpression.getProperty(node, name);
|
|
16
|
+
},
|
|
17
|
+
/**
|
|
18
|
+
* Returns a key-value pair like: `padding: '8px'` from: `{ padding: '8px' }`
|
|
19
|
+
*/
|
|
20
|
+
getEntryByPropertyName: function getEntryByPropertyName(node, name) {
|
|
21
|
+
return node.properties.find(function (property) {
|
|
22
|
+
if (!(0, _eslintCodemodUtils.isNodeOfType)(property, 'Property')) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
if (!(0, _eslintCodemodUtils.isNodeOfType)(property.key, 'Identifier')) {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
return property.key.name === name;
|
|
29
|
+
});
|
|
30
|
+
},
|
|
31
|
+
deleteEntry: function deleteEntry(node, name, fixer) {
|
|
32
|
+
var entry = ASTObjectExpression.getEntryByPropertyName(node, name);
|
|
33
|
+
if (!entry) {
|
|
34
|
+
return [];
|
|
35
|
+
}
|
|
36
|
+
return [fixer.remove(entry)];
|
|
37
|
+
},
|
|
38
|
+
/**
|
|
39
|
+
* Returns a only the property @type {Property['key']} like: `padding` from: `{ padding: '8px' }`
|
|
40
|
+
*/
|
|
41
|
+
getProperty: function getProperty(node, name) {
|
|
42
|
+
var _ASTObjectExpression$;
|
|
43
|
+
return (_ASTObjectExpression$ = ASTObjectExpression.getEntryByPropertyName(node, name)) === null || _ASTObjectExpression$ === void 0 ? void 0 : _ASTObjectExpression$.key;
|
|
44
|
+
},
|
|
45
|
+
/**
|
|
46
|
+
* Returns a only the property @type {Property['value']} like: `'8px` from: `{ padding: '8px' }`
|
|
47
|
+
*
|
|
48
|
+
* Values can be basically anything, so be careful with this
|
|
49
|
+
*/
|
|
50
|
+
getValueByPropertyName: function getValueByPropertyName(node, name) {
|
|
51
|
+
var _ASTObjectExpression$2;
|
|
52
|
+
return (_ASTObjectExpression$2 = ASTObjectExpression.getEntryByPropertyName(node, name)) === null || _ASTObjectExpression$2 === void 0 ? void 0 : _ASTObjectExpression$2.value;
|
|
53
|
+
},
|
|
54
|
+
containsSpreadProps: function containsSpreadProps(node) {
|
|
55
|
+
return node.properties.some(function (property) {
|
|
56
|
+
return (0, _eslintCodemodUtils.isNodeOfType)(property, 'SpreadElement');
|
|
57
|
+
});
|
|
58
|
+
},
|
|
59
|
+
updateValue: function updateValue(node, propertyName, newValue, fixer) {
|
|
60
|
+
var value = ASTObjectExpression.getValueByPropertyName(node, propertyName);
|
|
61
|
+
if (value === undefined) {
|
|
62
|
+
throw new Error("Object.updateValue: Could not get value of property ".concat(propertyName));
|
|
63
|
+
}
|
|
64
|
+
return fixer.replaceText(value, newValue);
|
|
65
|
+
},
|
|
66
|
+
/**
|
|
67
|
+
* Appends a key-value pair to the end of an object. For example:
|
|
68
|
+
* ```
|
|
69
|
+
* ast.Object.appendEntry(
|
|
70
|
+
* node, // { padding: 'space.100' }
|
|
71
|
+
* key, // 'margin',
|
|
72
|
+
* value, // 'space.200'
|
|
73
|
+
* fixer,
|
|
74
|
+
* )
|
|
75
|
+
* ```
|
|
76
|
+
* Will result in `{ padding: 'space.100', margin: 'space.200'}`
|
|
77
|
+
*/
|
|
78
|
+
appendEntry: function appendEntry(node, key, value, fixer) {
|
|
79
|
+
return fixer.insertTextAfter(node.properties[node.properties.length - 1], "".concat((0, _eslintCodemodUtils.property)({
|
|
80
|
+
key: (0, _eslintCodemodUtils.identifier)(key),
|
|
81
|
+
value: (0, _eslintCodemodUtils.literal)(value)
|
|
82
|
+
}).toString(), ", "));
|
|
83
|
+
}
|
|
84
|
+
};
|
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
/**
|
|
8
8
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
9
|
-
* @codegen <<SignedSource::
|
|
9
|
+
* @codegen <<SignedSource::5026ba2cb55b3c1bcacbfe7fb7728a6c>>
|
|
10
10
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
|
|
11
11
|
*/
|
|
12
12
|
var _default = exports.default = {
|
|
@@ -16,6 +16,7 @@ var _default = exports.default = {
|
|
|
16
16
|
'@atlaskit/design-system/ensure-design-token-usage': 'error',
|
|
17
17
|
'@atlaskit/design-system/ensure-design-token-usage/preview': 'warn',
|
|
18
18
|
'@atlaskit/design-system/icon-label': 'warn',
|
|
19
|
+
'@atlaskit/design-system/local-cx-xcss': 'error',
|
|
19
20
|
'@atlaskit/design-system/no-banned-imports': 'error',
|
|
20
21
|
'@atlaskit/design-system/no-css-tagged-template-expression': 'error',
|
|
21
22
|
'@atlaskit/design-system/no-deprecated-apis': 'error',
|
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
/**
|
|
8
8
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
9
|
-
* @codegen <<SignedSource::
|
|
9
|
+
* @codegen <<SignedSource::839224bfab98c1ddf6018dec5320968e>>
|
|
10
10
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
|
|
11
11
|
*/
|
|
12
12
|
var _default = exports.default = {
|
|
@@ -15,6 +15,7 @@ var _default = exports.default = {
|
|
|
15
15
|
'@atlaskit/design-system/consistent-css-prop-usage': 'error',
|
|
16
16
|
'@atlaskit/design-system/ensure-design-token-usage': 'error',
|
|
17
17
|
'@atlaskit/design-system/icon-label': 'warn',
|
|
18
|
+
'@atlaskit/design-system/local-cx-xcss': 'error',
|
|
18
19
|
'@atlaskit/design-system/no-banned-imports': 'error',
|
|
19
20
|
'@atlaskit/design-system/no-deprecated-apis': 'error',
|
|
20
21
|
'@atlaskit/design-system/no-deprecated-design-token-usage': 'warn',
|
|
@@ -13,6 +13,8 @@ var _assign = _interopRequireDefault(require("lodash/assign"));
|
|
|
13
13
|
var _createRule = require("../utils/create-rule");
|
|
14
14
|
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
15
15
|
|
|
16
|
+
// File-level tracking of styles hoisted from the cssOnTopOfModule/cssAtBottomOfModule fixers
|
|
17
|
+
var hoistedCss = [];
|
|
16
18
|
function isCssCallExpression(node, cssFunctions) {
|
|
17
19
|
cssFunctions = [].concat((0, _toConsumableArray2.default)(cssFunctions), ['cssMap']);
|
|
18
20
|
return !!((0, _eslintCodemodUtils.isNodeOfType)(node, 'CallExpression') && node.callee && node.callee.type === 'Identifier' && cssFunctions.includes(node.callee.name) && node.arguments.length && node.arguments[0].type === 'ObjectExpression');
|
|
@@ -25,11 +27,11 @@ function findSpreadProperties(node) {
|
|
|
25
27
|
property.type === 'ExperimentalSpreadProperty';
|
|
26
28
|
});
|
|
27
29
|
}
|
|
28
|
-
var
|
|
30
|
+
var getProgramNode = function getProgramNode(expression) {
|
|
29
31
|
while (expression.parent.type !== 'Program') {
|
|
30
32
|
expression = expression.parent;
|
|
31
33
|
}
|
|
32
|
-
return expression;
|
|
34
|
+
return expression.parent;
|
|
33
35
|
};
|
|
34
36
|
|
|
35
37
|
// TODO: This can be optimised by implementing a fixer at the very end (Program:exit) and handling all validations at once
|
|
@@ -48,7 +50,7 @@ var getDeclaratorString = function getDeclaratorString(context) {
|
|
|
48
50
|
}
|
|
49
51
|
var variables = scope.variables.map(function (variable) {
|
|
50
52
|
return variable.name;
|
|
51
|
-
});
|
|
53
|
+
}).concat(hoistedCss);
|
|
52
54
|
var count = 2;
|
|
53
55
|
var declaratorName = 'styles';
|
|
54
56
|
|
|
@@ -61,6 +63,9 @@ var getDeclaratorString = function getDeclaratorString(context) {
|
|
|
61
63
|
count++;
|
|
62
64
|
}
|
|
63
65
|
}
|
|
66
|
+
|
|
67
|
+
// Keep track of it by adding it to the hoistedCss global array
|
|
68
|
+
hoistedCss = [].concat((0, _toConsumableArray2.default)(hoistedCss), ["".concat(declaratorName).concat(count)]);
|
|
64
69
|
return "".concat(declaratorName).concat(count);
|
|
65
70
|
};
|
|
66
71
|
function analyzeIdentifier(context, sourceIdentifier, configuration) {
|
|
@@ -123,7 +128,19 @@ function analyzeIdentifier(context, sourceIdentifier, configuration) {
|
|
|
123
128
|
*/
|
|
124
129
|
var fixCssNotInModuleScope = function fixCssNotInModuleScope(fixer, context, configuration, node, cssAttributeName) {
|
|
125
130
|
var sourceCode = context.getSourceCode();
|
|
126
|
-
|
|
131
|
+
|
|
132
|
+
// Get the program node in order to properly position the hoisted styles
|
|
133
|
+
var programNode = getProgramNode(node);
|
|
134
|
+
var fixerNodePlacement = programNode;
|
|
135
|
+
if (configuration.stylesPlacement === 'bottom') {
|
|
136
|
+
// The last value is the bottom of the file
|
|
137
|
+
fixerNodePlacement = programNode.body[programNode.body.length - 1];
|
|
138
|
+
} else {
|
|
139
|
+
// Place after the last ImportDeclaration
|
|
140
|
+
fixerNodePlacement = programNode.body.length === 1 ? programNode.body[0] : programNode.body.find(function (node) {
|
|
141
|
+
return node.type !== 'ImportDeclaration';
|
|
142
|
+
});
|
|
143
|
+
}
|
|
127
144
|
var moduleString;
|
|
128
145
|
var implementFixer = [];
|
|
129
146
|
if (node.type === 'Identifier') {
|
|
@@ -145,7 +162,7 @@ var fixCssNotInModuleScope = function fixCssNotInModuleScope(fixer, context, con
|
|
|
145
162
|
}
|
|
146
163
|
return [].concat(implementFixer, [
|
|
147
164
|
// Insert the node either before or after
|
|
148
|
-
configuration.stylesPlacement === 'bottom' ? fixer.insertTextAfter(
|
|
165
|
+
configuration.stylesPlacement === 'bottom' ? fixer.insertTextAfter(fixerNodePlacement, '\n' + moduleString) : fixer.insertTextBefore(fixerNodePlacement, moduleString + '\n')]);
|
|
149
166
|
};
|
|
150
167
|
|
|
151
168
|
/**
|
|
@@ -276,6 +293,9 @@ var rule = (0, _createRule.createLintRule)({
|
|
|
276
293
|
}), (0, _defineProperty2.default)(_ref3, "JSXAttribute", function JSXAttribute(node) {
|
|
277
294
|
var name = node.name,
|
|
278
295
|
value = node.value;
|
|
296
|
+
|
|
297
|
+
// Always reset to empty array
|
|
298
|
+
hoistedCss = [];
|
|
279
299
|
if (name.type === 'JSXIdentifier' && mergedConfig.cssFunctions.includes(name.name)) {
|
|
280
300
|
// When not a jsx expression. For eg. css=""
|
|
281
301
|
if ((value === null || value === void 0 ? void 0 : value.type) !== 'JSXExpressionContainer') {
|
|
@@ -9,6 +9,7 @@ var _consistentCssPropUsage = _interopRequireDefault(require("./consistent-css-p
|
|
|
9
9
|
var _ensureDesignTokenUsage = _interopRequireDefault(require("./ensure-design-token-usage"));
|
|
10
10
|
var _ensureDesignTokenUsagePreview = _interopRequireDefault(require("./ensure-design-token-usage-preview"));
|
|
11
11
|
var _iconLabel = _interopRequireDefault(require("./icon-label"));
|
|
12
|
+
var _localCxXcss = _interopRequireDefault(require("./local-cx-xcss"));
|
|
12
13
|
var _noBannedImports = _interopRequireDefault(require("./no-banned-imports"));
|
|
13
14
|
var _noCssTaggedTemplateExpression = _interopRequireDefault(require("./no-css-tagged-template-expression"));
|
|
14
15
|
var _noDeprecatedApis = _interopRequireDefault(require("./no-deprecated-apis"));
|
|
@@ -29,7 +30,7 @@ var _usePrimitives = _interopRequireDefault(require("./use-primitives"));
|
|
|
29
30
|
var _useVisuallyHidden = _interopRequireDefault(require("./use-visually-hidden"));
|
|
30
31
|
/**
|
|
31
32
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
32
|
-
* @codegen <<SignedSource::
|
|
33
|
+
* @codegen <<SignedSource::a67afc33adf50db651edb1cf12e16ef3>>
|
|
33
34
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
|
|
34
35
|
*/
|
|
35
36
|
var _default = exports.default = {
|
|
@@ -37,6 +38,7 @@ var _default = exports.default = {
|
|
|
37
38
|
'ensure-design-token-usage': _ensureDesignTokenUsage.default,
|
|
38
39
|
'ensure-design-token-usage/preview': _ensureDesignTokenUsagePreview.default,
|
|
39
40
|
'icon-label': _iconLabel.default,
|
|
41
|
+
'local-cx-xcss': _localCxXcss.default,
|
|
40
42
|
'no-banned-imports': _noBannedImports.default,
|
|
41
43
|
'no-css-tagged-template-expression': _noCssTaggedTemplateExpression.default,
|
|
42
44
|
'no-deprecated-apis': _noDeprecatedApis.default,
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.rule = exports.default = void 0;
|
|
7
|
+
var _createRule = require("../utils/create-rule");
|
|
8
|
+
var _isSupportedImport = require("../utils/is-supported-import");
|
|
9
|
+
var IMPORT_SOURCES = [_isSupportedImport.CSS_IN_JS_IMPORTS.compiled, _isSupportedImport.CSS_IN_JS_IMPORTS.atlaskitCss];
|
|
10
|
+
function getParentJSXAttribute(node) {
|
|
11
|
+
var parent = node.parent;
|
|
12
|
+
while (parent && parent.type !== 'JSXAttribute') {
|
|
13
|
+
parent = parent.parent;
|
|
14
|
+
}
|
|
15
|
+
if (parent && parent.type === 'JSXAttribute') {
|
|
16
|
+
return parent;
|
|
17
|
+
}
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
var rule = exports.rule = (0, _createRule.createLintRule)({
|
|
21
|
+
meta: {
|
|
22
|
+
name: 'local-cx-xcss',
|
|
23
|
+
docs: {
|
|
24
|
+
description: 'Ensures the cx() function, which is part of the XCSS API, is only used within the xcss prop. This aids tracking what styles are applied to a jsx element.',
|
|
25
|
+
recommended: true,
|
|
26
|
+
severity: 'error'
|
|
27
|
+
},
|
|
28
|
+
messages: {
|
|
29
|
+
'local-cx-xcss': 'The cx function should only be declared inside the xcss prop to simplify tracking styles that are applied to a jsx element.'
|
|
30
|
+
},
|
|
31
|
+
type: 'problem'
|
|
32
|
+
},
|
|
33
|
+
create: function create(context) {
|
|
34
|
+
return {
|
|
35
|
+
'CallExpression[callee.name="cx"]': function CallExpressionCalleeNameCx(node) {
|
|
36
|
+
if (node.type === 'CallExpression' && (0, _isSupportedImport.isCxFunction)(node.callee, context.getScope().references, IMPORT_SOURCES)) {
|
|
37
|
+
var parentJSXAttribute = getParentJSXAttribute(node);
|
|
38
|
+
var propName = parentJSXAttribute === null || parentJSXAttribute === void 0 ? void 0 : parentJSXAttribute.name.name.toString();
|
|
39
|
+
if (propName && /[xX]css$/.test(propName)) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
context.report({
|
|
43
|
+
node: node,
|
|
44
|
+
messageId: 'local-cx-xcss'
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
var _default = exports.default = rule;
|
|
@@ -6,19 +6,21 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.createNoTaggedTemplateExpressionRule = void 0;
|
|
8
8
|
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
9
|
+
var _isSupportedImport = require("../../utils/is-supported-import");
|
|
9
10
|
var _generate = require("./generate");
|
|
10
11
|
var _getTaggedTemplateExpressionOffset = require("./get-tagged-template-expression-offset");
|
|
11
12
|
var _toArguments = require("./to-arguments");
|
|
12
13
|
// Original source from Compiled https://github.com/atlassian-labs/compiled/blob/master/packages/eslint-plugin/src/utils/create-no-tagged-template-expression-rule/index.ts
|
|
13
14
|
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
14
15
|
|
|
16
|
+
var IMPORT_SOURCES = [_isSupportedImport.CSS_IN_JS_IMPORTS.compiled, _isSupportedImport.CSS_IN_JS_IMPORTS.emotionReact, _isSupportedImport.CSS_IN_JS_IMPORTS.emotionCore, _isSupportedImport.CSS_IN_JS_IMPORTS.styledComponents];
|
|
15
17
|
var createNoTaggedTemplateExpressionRule = exports.createNoTaggedTemplateExpressionRule = function createNoTaggedTemplateExpressionRule(isUsage, messageId) {
|
|
16
18
|
return function (context) {
|
|
17
19
|
return {
|
|
18
20
|
TaggedTemplateExpression: function TaggedTemplateExpression(node) {
|
|
19
21
|
var _context$getScope = context.getScope(),
|
|
20
22
|
references = _context$getScope.references;
|
|
21
|
-
if (!isUsage(node.tag, references)) {
|
|
23
|
+
if (!isUsage(node.tag, references, IMPORT_SOURCES)) {
|
|
22
24
|
return;
|
|
23
25
|
}
|
|
24
26
|
context.report({
|
|
@@ -5,8 +5,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _createRule = require("../utils/create-rule");
|
|
8
|
+
var _isSupportedImport = require("../utils/is-supported-import");
|
|
8
9
|
var _createNoTaggedTemplateExpressionRule = require("./create-no-tagged-template-expression-rule");
|
|
9
|
-
var _isSupportedImport = require("./is-supported-import");
|
|
10
10
|
var rule = (0, _createRule.createLintRule)({
|
|
11
11
|
meta: {
|
|
12
12
|
name: 'no-css-tagged-template-expression',
|
|
@@ -21,6 +21,6 @@ var rule = (0, _createRule.createLintRule)({
|
|
|
21
21
|
unexpectedTaggedTemplate: 'Unexpected `css` tagged template expression'
|
|
22
22
|
}
|
|
23
23
|
},
|
|
24
|
-
create: (0, _createNoTaggedTemplateExpressionRule.createNoTaggedTemplateExpressionRule)(
|
|
24
|
+
create: (0, _createNoTaggedTemplateExpressionRule.createNoTaggedTemplateExpressionRule)(_isSupportedImport.isCss, 'unexpectedTaggedTemplate')
|
|
25
25
|
});
|
|
26
26
|
var _default = exports.default = rule;
|
|
@@ -4,12 +4,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
var _eslintCodemodUtils = require("eslint-codemod-utils");
|
|
8
7
|
var _createRule = require("../utils/create-rule");
|
|
9
8
|
var _config = require("./config");
|
|
10
9
|
var _transformers = require("./transformers");
|
|
11
|
-
var _emotionCss = require("./transformers/emotion-css");
|
|
12
|
-
var _utils = require("./utils");
|
|
13
10
|
var boxDocsUrl = 'https://atlassian.design/components/primitives/box';
|
|
14
11
|
var rule = (0, _createRule.createLintRule)({
|
|
15
12
|
meta: {
|
|
@@ -31,37 +28,14 @@ var rule = (0, _createRule.createLintRule)({
|
|
|
31
28
|
return {
|
|
32
29
|
// transforms styled.<html>(...) usages
|
|
33
30
|
CallExpression: function CallExpression(node) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
if (!(0, _eslintCodemodUtils.isNodeOfType)(node, 'CallExpression')) {
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
var styledComponentVariableRef = (0, _utils.findValidStyledComponentCall)(node);
|
|
41
|
-
if (!styledComponentVariableRef || !(0, _eslintCodemodUtils.isNodeOfType)(styledComponentVariableRef.id, 'Identifier') || !(0, _utils.isValidCssPropertiesToTransform)(node, config)) {
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
var styledComponentJsxRef = (0, _utils.findValidJsxUsageToTransform)(styledComponentVariableRef.id.name, context.getScope());
|
|
45
|
-
if (!styledComponentJsxRef) {
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// if we have both references at this point then we can offer a fix \o/
|
|
50
|
-
context.report({
|
|
51
|
-
node: styledComponentVariableRef,
|
|
52
|
-
messageId: 'preferPrimitivesBox',
|
|
53
|
-
suggest: [{
|
|
54
|
-
desc: "Convert ".concat(styledComponentVariableRef.id.name, " to Box"),
|
|
55
|
-
fix: (0, _transformers.styledComponentToPrimitive)({
|
|
56
|
-
stylesRef: styledComponentVariableRef,
|
|
57
|
-
jsxRef: styledComponentJsxRef
|
|
58
|
-
}, context)
|
|
59
|
-
}]
|
|
31
|
+
_transformers.CompiledStyled.lint(node, {
|
|
32
|
+
context: context,
|
|
33
|
+
config: config
|
|
60
34
|
});
|
|
61
35
|
},
|
|
62
36
|
// transforms <div css={...}> usages
|
|
63
37
|
JSXElement: function JSXElement(node) {
|
|
64
|
-
|
|
38
|
+
_transformers.EmotionCSS.lint(node, {
|
|
65
39
|
context: context,
|
|
66
40
|
config: config
|
|
67
41
|
});
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.convertJsxCallSite = void 0;
|
|
9
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
10
|
+
var _eslintCodemodUtils = require("eslint-codemod-utils");
|
|
11
|
+
var ast = _interopRequireWildcard(require("../../../../ast-nodes"));
|
|
12
|
+
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); }
|
|
13
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(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
|
+
/**
|
|
15
|
+
* Transforms a JSXElement from:
|
|
16
|
+
* ```
|
|
17
|
+
* <div>
|
|
18
|
+
* // ...
|
|
19
|
+
* </div>
|
|
20
|
+
* ```
|
|
21
|
+
* to
|
|
22
|
+
* ```
|
|
23
|
+
* <Box xcss={myStyles}>
|
|
24
|
+
* // ...
|
|
25
|
+
* </Box>
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
var convertJsxCallSite = exports.convertJsxCallSite = function convertJsxCallSite(jsxElement, newStylesVariableName, fixer) {
|
|
29
|
+
var fixes = [];
|
|
30
|
+
|
|
31
|
+
// renames the JSX call site
|
|
32
|
+
if ((0, _eslintCodemodUtils.isNodeOfType)(jsxElement, 'JSXElement')) {
|
|
33
|
+
fixes.push.apply(fixes, (0, _toConsumableArray2.default)(ast.JSXElement.updateName(jsxElement, 'Box', fixer)));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// adds xcss prop
|
|
37
|
+
fixes.push(fixer.insertTextAfter(jsxElement.openingElement.name, " xcss={".concat(newStylesVariableName, "}")));
|
|
38
|
+
return fixes;
|
|
39
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.convertStyledComponentToXcss = void 0;
|
|
8
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
9
|
+
var _eslintCodemodUtils = require("eslint-codemod-utils");
|
|
10
|
+
var _cssToXcss = require("../css-to-xcss");
|
|
11
|
+
/**
|
|
12
|
+
* Transforms a variable like:
|
|
13
|
+
* ```
|
|
14
|
+
* const MyComponent = styled.div({
|
|
15
|
+
* padding: '8px',
|
|
16
|
+
* })
|
|
17
|
+
* ```
|
|
18
|
+
* to
|
|
19
|
+
* ```
|
|
20
|
+
* const myComponentStyles = xcss({
|
|
21
|
+
* padding: 'space.100',
|
|
22
|
+
* })
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
var convertStyledComponentToXcss = exports.convertStyledComponentToXcss = function convertStyledComponentToXcss(styles, newStylesVariableName, fixer) {
|
|
26
|
+
var fixes = [];
|
|
27
|
+
|
|
28
|
+
// renames the variable from MyComponent to myComponentStyles
|
|
29
|
+
fixes.push(fixer.replaceText(styles.id, newStylesVariableName));
|
|
30
|
+
|
|
31
|
+
// renames the function call from styled.<tag> to xcss
|
|
32
|
+
if (styles.init && (0, _eslintCodemodUtils.isNodeOfType)(styles.init, 'CallExpression')) {
|
|
33
|
+
fixes.push(fixer.replaceText(styles.init.callee, 'xcss'));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// converts CSS values to XCSS-compatible tokens
|
|
37
|
+
if (styles.init && (0, _eslintCodemodUtils.isNodeOfType)(styles.init, 'CallExpression')) {
|
|
38
|
+
var objectExpression = styles.init.arguments[0];
|
|
39
|
+
if ((0, _eslintCodemodUtils.isNodeOfType)(objectExpression, 'ObjectExpression')) {
|
|
40
|
+
fixes.push.apply(fixes, (0, _toConsumableArray2.default)((0, _cssToXcss.styledObjectToXcssTokens)(objectExpression, fixer)));
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return fixes;
|
|
44
|
+
};
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
3
4
|
Object.defineProperty(exports, "__esModule", {
|
|
4
5
|
value: true
|
|
5
6
|
});
|
|
6
7
|
exports.findValidStyledComponentCall = void 0;
|
|
7
8
|
var _eslintCodemodUtils = require("eslint-codemod-utils");
|
|
8
|
-
var
|
|
9
|
+
var supported = _interopRequireWildcard(require("./supported"));
|
|
10
|
+
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); }
|
|
11
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(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; }
|
|
9
12
|
/**
|
|
10
13
|
* returns a variable reference if preconditions are favourable for
|
|
11
14
|
* the transformation to proceed, undefined otherwise.
|
|
@@ -46,7 +49,7 @@ var isStyledCallExpression = function isStyledCallExpression(call) {
|
|
|
46
49
|
if (!(0, _eslintCodemodUtils.isNodeOfType)(call.callee.object, 'Identifier') || !(0, _eslintCodemodUtils.isNodeOfType)(call.callee.property, 'Identifier')) {
|
|
47
50
|
return false;
|
|
48
51
|
}
|
|
49
|
-
if (/^styled2?$/.test(call.callee.object.name) &&
|
|
52
|
+
if (/^styled2?$/.test(call.callee.object.name) && supported.elements.includes(call.callee.property.name)) {
|
|
50
53
|
return true;
|
|
51
54
|
}
|
|
52
55
|
return false;
|