@atlaskit/eslint-plugin-ui-styling-standard 0.15.1 → 0.16.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 +17 -0
- package/constellation/index/migration-guide.mdx +309 -0
- package/constellation/index/overview.mdx +4 -0
- package/constellation/index/props.mdx +9 -5
- package/dist/cjs/rules/no-nested-selectors/index.js +68 -49
- package/dist/es2019/rules/no-nested-selectors/index.js +63 -45
- package/dist/esm/rules/no-nested-selectors/index.js +64 -49
- package/dist/types/rules/no-unsafe-selectors/constants.d.ts +1 -4
- package/index.js +9 -9
- package/package.json +3 -3
- package/scripts/codegen.tsx +223 -284
- package/src/rules/__tests__/utils/_tester.tsx +24 -24
- package/src/rules/atlaskit-theme/README.md +21 -19
- package/src/rules/atlaskit-theme/__tests__/test.ts +53 -53
- package/src/rules/atlaskit-theme/index.ts +107 -115
- package/src/rules/convert-props-syntax/README.md +32 -22
- package/src/rules/convert-props-syntax/__tests__/invalid.test.tsx +46 -46
- package/src/rules/convert-props-syntax/__tests__/rule.test.tsx +175 -175
- package/src/rules/convert-props-syntax/__tests__/type-annotations.test.tsx +52 -52
- package/src/rules/convert-props-syntax/__tests__/unusual-properties.test.tsx +33 -33
- package/src/rules/convert-props-syntax/index.tsx +356 -386
- package/src/rules/enforce-style-prop/README.md +21 -18
- package/src/rules/enforce-style-prop/__tests__/rule.test.tsx +90 -96
- package/src/rules/enforce-style-prop/index.tsx +144 -160
- package/src/rules/external-rules.tsx +163 -164
- package/src/rules/local-cx-xcss/README.md +10 -6
- package/src/rules/local-cx-xcss/__tests__/rule.test.tsx +26 -26
- package/src/rules/local-cx-xcss/index.tsx +46 -56
- package/src/rules/no-array-arguments/README.md +2 -1
- package/src/rules/no-array-arguments/__tests__/rule.test.tsx +37 -46
- package/src/rules/no-array-arguments/index.tsx +68 -69
- package/src/rules/no-classname-prop/README.md +7 -4
- package/src/rules/no-classname-prop/__tests__/rule.test.tsx +22 -22
- package/src/rules/no-classname-prop/index.tsx +25 -25
- package/src/rules/no-container-queries/README.md +11 -9
- package/src/rules/no-container-queries/__tests__/rule.test.tsx +47 -50
- package/src/rules/no-container-queries/index.tsx +75 -81
- package/src/rules/no-dynamic-styles/README.md +16 -19
- package/src/rules/no-dynamic-styles/__tests__/rule.test.tsx +58 -67
- package/src/rules/no-dynamic-styles/index.tsx +45 -48
- package/src/rules/no-exported-styles/README.md +17 -12
- package/src/rules/no-exported-styles/__tests__/rule.test.tsx +102 -111
- package/src/rules/no-exported-styles/index.tsx +36 -36
- package/src/rules/no-global-styles/README.md +15 -14
- package/src/rules/no-global-styles/__tests__/no-css-modules.test.tsx +28 -28
- package/src/rules/no-global-styles/__tests__/no-global-styles.test.tsx +37 -37
- package/src/rules/no-global-styles/index.tsx +59 -62
- package/src/rules/no-important-styles/README.md +5 -3
- package/src/rules/no-important-styles/__tests__/rule.test.tsx +66 -66
- package/src/rules/no-important-styles/index.tsx +49 -49
- package/src/rules/no-imported-style-values/README.md +23 -15
- package/src/rules/no-imported-style-values/__tests__/rule.test.tsx +123 -123
- package/src/rules/no-imported-style-values/index.tsx +116 -120
- package/src/rules/no-nested-selectors/README.md +15 -13
- package/src/rules/no-nested-selectors/__tests__/rule.test.tsx +186 -149
- package/src/rules/no-nested-selectors/index.tsx +92 -105
- package/src/rules/no-styled/README.md +14 -9
- package/src/rules/no-styled/__tests__/rule.test.tsx +31 -31
- package/src/rules/no-styled/index.tsx +34 -41
- package/src/rules/no-unsafe-selectors/README.md +103 -93
- package/src/rules/no-unsafe-selectors/__tests__/no-grouped-at-rules.test.tsx +21 -24
- package/src/rules/no-unsafe-selectors/__tests__/no-increased-specificity.test.tsx +44 -44
- package/src/rules/no-unsafe-selectors/__tests__/no-keyframes-at-rules.test.tsx +21 -21
- package/src/rules/no-unsafe-selectors/__tests__/no-legacy-pseudo-element-syntax.test.tsx +57 -57
- package/src/rules/no-unsafe-selectors/__tests__/no-restricted-at-rules.test.tsx +58 -58
- package/src/rules/no-unsafe-selectors/__tests__/no-restricted-pseudos.test.tsx +85 -85
- package/src/rules/no-unsafe-selectors/__tests__/no-selectors-object.test.tsx +12 -12
- package/src/rules/no-unsafe-selectors/__tests__/no-unparsable-selectors.test.tsx +23 -23
- package/src/rules/no-unsafe-selectors/__tests__/rule.test.tsx +114 -114
- package/src/rules/no-unsafe-selectors/constants.tsx +69 -77
- package/src/rules/no-unsafe-selectors/source-position-utils.tsx +38 -38
- package/src/rules/no-unsafe-selectors/walk-css-map.tsx +178 -184
- package/src/rules/no-unsafe-values/README.md +34 -40
- package/src/rules/no-unsafe-values/__tests__/no-array-values.test.tsx +13 -13
- package/src/rules/no-unsafe-values/__tests__/no-conditional-values.test.tsx +18 -18
- package/src/rules/no-unsafe-values/__tests__/no-dynamic-keys.test.tsx +104 -104
- package/src/rules/no-unsafe-values/__tests__/no-function-calls.test.tsx +128 -128
- package/src/rules/no-unsafe-values/__tests__/no-identifier-arguments.test.tsx +23 -23
- package/src/rules/no-unsafe-values/__tests__/no-object-access.test.tsx +38 -38
- package/src/rules/no-unsafe-values/__tests__/no-object-references.test.tsx +18 -18
- package/src/rules/no-unsafe-values/__tests__/no-spread-elements.test.tsx +18 -18
- package/src/rules/no-unsafe-values/__tests__/no-unsafe-values.test.tsx +28 -28
- package/src/rules/no-unsafe-values/__tests__/no-variables.test.tsx +47 -47
- package/src/rules/no-unsafe-values/index.tsx +76 -78
- package/src/rules/no-unsafe-values/messages.tsx +12 -12
- package/src/rules/no-unsafe-values/utils.tsx +370 -382
- package/src/rules/use-compiled/README.md +11 -8
- package/src/rules/use-compiled/__tests__/can-auto-fix.test.tsx +32 -32
- package/src/rules/use-compiled/__tests__/css.test.tsx +53 -53
- package/src/rules/use-compiled/__tests__/imports.test.tsx +90 -95
- package/src/rules/use-compiled/__tests__/keyframes.test.tsx +47 -47
- package/src/rules/use-compiled/__tests__/pragma.test.tsx +64 -64
- package/src/rules/use-compiled/__tests__/styled.test.tsx +53 -53
- package/src/rules/use-compiled/__tests__/use-compiled.test.tsx +10 -10
- package/src/rules/use-compiled/index.tsx +203 -226
- package/src/rules/use-compiled/is-safe.tsx +113 -117
- package/src/rules/use-compiled/utils.tsx +14 -18
- package/src/rules/utils/create-rule-with-typed-config.tsx +62 -63
- package/src/rules/utils/create-rule.tsx +3 -6
|
@@ -1,34 +1,42 @@
|
|
|
1
|
-
Convert props syntax that are unsupported by `styled-components@<4` and `@emotion/styled` to a props
|
|
1
|
+
Convert props syntax that are unsupported by `styled-components@<4` and `@emotion/styled` to a props
|
|
2
|
+
syntax that is supported. This is useful when used in conjunction with
|
|
3
|
+
`no-styled-tagged-template-expression`, as output from the latter may use props syntax that results
|
|
4
|
+
in a type error.
|
|
2
5
|
|
|
3
6
|
These libraries do not support having an arrow function inside a CSS value:
|
|
4
7
|
|
|
5
8
|
```js
|
|
6
9
|
styled.div({
|
|
7
|
-
|
|
8
|
-
|
|
10
|
+
color: ({ myColor }) => myColor,
|
|
11
|
+
backgroundColor: (props) => props.someColor,
|
|
9
12
|
});
|
|
10
13
|
```
|
|
11
14
|
|
|
12
|
-
However, refactoring the arrow function so that it is the argument to `styled.div` will fix the
|
|
15
|
+
However, refactoring the arrow function so that it is the argument to `styled.div` will fix the
|
|
16
|
+
issue:
|
|
13
17
|
|
|
14
18
|
```js
|
|
15
19
|
styled.div((props) => ({
|
|
16
|
-
|
|
17
|
-
|
|
20
|
+
color: props.myColor,
|
|
21
|
+
backgroundColor: props.someColor,
|
|
18
22
|
}));
|
|
19
23
|
```
|
|
20
24
|
|
|
21
|
-
This ESLint rule will only run on usages of the `styled` API when imported from libraries that are
|
|
25
|
+
This ESLint rule will only run on usages of the `styled` API when imported from libraries that are
|
|
26
|
+
known to have this problem.
|
|
22
27
|
|
|
23
28
|
## About the autofixer
|
|
24
29
|
|
|
25
|
-
This rule has an autofixer that will automatically perform the above arrow function refactoring for
|
|
30
|
+
This rule has an autofixer that will automatically perform the above arrow function refactoring for
|
|
31
|
+
the majority of cases, including for nested selectors and any props used in template literal values.
|
|
26
32
|
|
|
27
|
-
However, there are a few situations where the autofixer will not be run. For these, you will need to
|
|
33
|
+
However, there are a few situations where the autofixer will not be run. For these, you will need to
|
|
34
|
+
manually fix the output, or migrate the code to `@compiled/react`.
|
|
28
35
|
|
|
29
36
|
### Type annotations
|
|
30
37
|
|
|
31
|
-
Type annotations in the arrow function are not supported; you will need to remediate the lint error
|
|
38
|
+
Type annotations in the arrow function are not supported; you will need to remediate the lint error
|
|
39
|
+
manually. For example:
|
|
32
40
|
|
|
33
41
|
```js
|
|
34
42
|
type Props = {
|
|
@@ -58,12 +66,13 @@ styled.div((props: Props) => ({
|
|
|
58
66
|
|
|
59
67
|
### Special syntax in the arrow function parameter(s)
|
|
60
68
|
|
|
61
|
-
Rest elements, default values, and so on in the parameter of an arrow function will need to be
|
|
69
|
+
Rest elements, default values, and so on in the parameter of an arrow function will need to be
|
|
70
|
+
remediated manually. For example:
|
|
62
71
|
|
|
63
72
|
```js
|
|
64
73
|
styled.div({
|
|
65
|
-
|
|
66
|
-
|
|
74
|
+
color: ({ myColor = '#fff' }) => myColor,
|
|
75
|
+
backgroundColor: ({ myColor = '#aaa' }) => myColor,
|
|
67
76
|
});
|
|
68
77
|
```
|
|
69
78
|
|
|
@@ -71,8 +80,8 @@ could potentially be remediated with
|
|
|
71
80
|
|
|
72
81
|
```js
|
|
73
82
|
styled.div((props) => ({
|
|
74
|
-
|
|
75
|
-
|
|
83
|
+
color: myColor ?? '#fff',
|
|
84
|
+
backgroundColor: myColor ?? '#aaa',
|
|
76
85
|
}));
|
|
77
86
|
```
|
|
78
87
|
|
|
@@ -84,12 +93,12 @@ styled.div((props) => ({
|
|
|
84
93
|
import styled from 'styled-components';
|
|
85
94
|
|
|
86
95
|
styled.div({
|
|
87
|
-
|
|
88
|
-
|
|
96
|
+
color: ({ myColor }) => myColor,
|
|
97
|
+
backgroundColor: (props) => props.someColor,
|
|
89
98
|
});
|
|
90
99
|
|
|
91
100
|
styled.div({
|
|
92
|
-
|
|
101
|
+
color: `url(/tmp/${({ coolProp }) => coolProp}.png)`,
|
|
93
102
|
});
|
|
94
103
|
```
|
|
95
104
|
|
|
@@ -99,15 +108,16 @@ styled.div({
|
|
|
99
108
|
import styled from '@emotion/styled';
|
|
100
109
|
|
|
101
110
|
styled.div((props) => ({
|
|
102
|
-
|
|
103
|
-
|
|
111
|
+
color: props.myColor,
|
|
112
|
+
backgroundColor: props.someColor,
|
|
104
113
|
}));
|
|
105
114
|
|
|
106
115
|
styled.div((props) => ({
|
|
107
|
-
|
|
116
|
+
color: url(`/tmp/${coolProp}.png`),
|
|
108
117
|
}));
|
|
109
118
|
```
|
|
110
119
|
|
|
111
120
|
## When not to use it
|
|
112
121
|
|
|
113
|
-
You do not need this rule if you are not using a codebase that has a violating library as it will
|
|
122
|
+
You do not need this rule if you are not using a codebase that has a violating library as it will
|
|
123
|
+
never do anything.
|
|
@@ -2,75 +2,75 @@ import { typescriptEslintTester } from '../../__tests__/utils/_tester';
|
|
|
2
2
|
import rule from '../index';
|
|
3
3
|
|
|
4
4
|
typescriptEslintTester.run(
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
5
|
+
'convert-props-syntax',
|
|
6
|
+
// @ts-expect-error
|
|
7
|
+
rule,
|
|
8
|
+
{
|
|
9
|
+
valid: [],
|
|
10
|
+
invalid: [
|
|
11
|
+
// ESLint rule shouldn't try to fix all of the test cases below, which are
|
|
12
|
+
// erroneous and invalid. But we should still report an error nonetheless.
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
{
|
|
15
|
+
name: 'disables autofixer when two arguments in arrow function (with destructured props)',
|
|
16
|
+
code: `
|
|
17
17
|
import styled from 'styled-components';
|
|
18
18
|
|
|
19
19
|
styled.div({
|
|
20
20
|
color: ({ customColor }, anotherVariable) => customColor,
|
|
21
21
|
});
|
|
22
22
|
`,
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
23
|
+
errors: [
|
|
24
|
+
{
|
|
25
|
+
messageId: 'unsupported-prop-syntax-no-autofixer',
|
|
26
|
+
},
|
|
27
|
+
],
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
name: 'disables autofixer when two arguments in arrow function (with props argument)',
|
|
31
|
+
code: `
|
|
32
32
|
import styled from 'styled-components';
|
|
33
33
|
|
|
34
34
|
styled.div({
|
|
35
35
|
color: (oneVariable, anotherVariable) => oneVariable.color,
|
|
36
36
|
});
|
|
37
37
|
`,
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
38
|
+
errors: [
|
|
39
|
+
{
|
|
40
|
+
messageId: 'unsupported-prop-syntax-no-autofixer',
|
|
41
|
+
},
|
|
42
|
+
],
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
name: "disables autofixer when props argument doesn't match",
|
|
46
|
+
code: `
|
|
47
47
|
import styled from 'styled-components';
|
|
48
48
|
|
|
49
49
|
styled.div({
|
|
50
50
|
backgroundColor: (props) => myProps.customColor,
|
|
51
51
|
});
|
|
52
52
|
`,
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
53
|
+
errors: [
|
|
54
|
+
{
|
|
55
|
+
messageId: 'unsupported-prop-syntax-no-autofixer',
|
|
56
|
+
},
|
|
57
|
+
],
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
name: "disables autofixer when destructured props don't match",
|
|
61
|
+
code: `
|
|
62
62
|
import styled from 'styled-components';
|
|
63
63
|
|
|
64
64
|
styled.div({
|
|
65
65
|
backgroundColor: ({ customColor }) => otherColor,
|
|
66
66
|
});
|
|
67
67
|
`,
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
68
|
+
errors: [
|
|
69
|
+
{
|
|
70
|
+
messageId: 'unsupported-prop-syntax-no-autofixer',
|
|
71
|
+
},
|
|
72
|
+
],
|
|
73
|
+
},
|
|
74
|
+
],
|
|
75
|
+
},
|
|
76
76
|
);
|