@atlaskit/eslint-plugin-ui-styling-standard 0.16.2 → 0.16.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 +16 -0
- package/constellation/atlaskit-theme/usage.mdx +74 -55
- package/constellation/convert-props-syntax/usage.mdx +29 -24
- package/constellation/enforce-style-prop/usage.mdx +32 -26
- package/constellation/local-cx-xcss/usage.mdx +27 -15
- package/constellation/no-array-arguments/usage.mdx +12 -9
- package/constellation/no-classname-prop/usage.mdx +13 -5
- package/constellation/no-container-queries/usage.mdx +65 -16
- package/constellation/no-dynamic-styles/usage.mdx +16 -11
- package/constellation/no-exported-styles/usage.mdx +25 -30
- package/constellation/no-global-styles/usage.mdx +4 -3
- package/constellation/no-important-styles/usage.mdx +5 -3
- package/constellation/no-imported-style-values/usage.mdx +30 -27
- package/constellation/no-nested-selectors/usage.mdx +51 -18
- package/constellation/no-styled/usage.mdx +17 -14
- package/constellation/no-unsafe-selectors/usage.mdx +184 -58
- package/constellation/no-unsafe-values/usage.mdx +150 -48
- package/constellation/use-compiled/usage.mdx +8 -8
- package/dist/cjs/rules/no-array-arguments/index.js +3 -3
- package/dist/cjs/rules/no-dynamic-styles/index.js +2 -2
- package/dist/cjs/rules/no-imported-style-values/index.js +2 -2
- package/dist/cjs/rules/no-unsafe-values/index.js +2 -2
- package/dist/es2019/rules/no-array-arguments/index.js +2 -2
- package/dist/es2019/rules/no-dynamic-styles/index.js +1 -1
- package/dist/es2019/rules/no-imported-style-values/index.js +1 -1
- package/dist/es2019/rules/no-unsafe-values/index.js +1 -1
- package/dist/esm/rules/no-array-arguments/index.js +3 -3
- package/dist/esm/rules/no-dynamic-styles/index.js +2 -2
- package/dist/esm/rules/no-imported-style-values/index.js +2 -2
- package/dist/esm/rules/no-unsafe-values/index.js +2 -2
- package/package.json +8 -3
- package/src/rules/atlaskit-theme/README.md +74 -55
- package/src/rules/convert-props-syntax/README.md +29 -24
- package/src/rules/enforce-style-prop/README.md +32 -26
- package/src/rules/local-cx-xcss/README.md +27 -15
- package/src/rules/no-array-arguments/README.md +12 -9
- package/src/rules/no-array-arguments/index.tsx +2 -2
- package/src/rules/no-classname-prop/README.md +13 -5
- package/src/rules/no-container-queries/README.md +65 -16
- package/src/rules/no-dynamic-styles/README.md +16 -11
- package/src/rules/no-dynamic-styles/index.tsx +1 -1
- package/src/rules/no-exported-styles/README.md +25 -30
- package/src/rules/no-global-styles/README.md +4 -3
- package/src/rules/no-important-styles/README.md +5 -3
- package/src/rules/no-imported-style-values/README.md +30 -27
- package/src/rules/no-imported-style-values/index.tsx +1 -1
- package/src/rules/no-nested-selectors/README.md +51 -18
- package/src/rules/no-styled/README.md +17 -14
- package/src/rules/no-unsafe-selectors/README.md +184 -58
- package/src/rules/no-unsafe-values/README.md +150 -48
- package/src/rules/no-unsafe-values/index.tsx +1 -1
- package/src/rules/use-compiled/README.md +8 -8
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
# use-compiled
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Blocks CSS-in-JS libraries other than `@compiled/react`, including Emotion and styled-components.
|
|
4
4
|
|
|
5
5
|
**WARNING** It may be unsafe to mix usages of `@compiled/react` with other CSS-in-JS libraries on
|
|
6
6
|
the same component. When converting to `@compiled/react` verify ALL changes. For this reason, the
|
|
7
|
-
|
|
7
|
+
autofixer has been disabled by default, but it may be useful to enable to empower a migration.
|
|
8
8
|
|
|
9
9
|
## Examples
|
|
10
10
|
|
|
11
11
|
### Incorrect
|
|
12
12
|
|
|
13
|
-
```
|
|
13
|
+
```tsx
|
|
14
14
|
/** @jsx jsx */
|
|
15
15
|
import { css } from '@emotion/core';
|
|
16
16
|
import { jsx } from '@emotion/react';
|
|
17
17
|
import styled from '@emotion/styled';
|
|
18
18
|
```
|
|
19
19
|
|
|
20
|
-
```
|
|
20
|
+
```tsx
|
|
21
21
|
import styled, { css } from 'styled-components';
|
|
22
22
|
```
|
|
23
23
|
|
|
@@ -26,7 +26,7 @@ import styled, { css } from 'styled-components';
|
|
|
26
26
|
We expect usage of `xcss` with `@atlaskit/primitives` when working with Primitives, and `css` with
|
|
27
27
|
`@compiled/react` when working with custom or native code.
|
|
28
28
|
|
|
29
|
-
```
|
|
29
|
+
```tsx
|
|
30
30
|
/** @jsx jsx */
|
|
31
31
|
import { jsx, css, styled } from '@compiled/react';
|
|
32
32
|
|
|
@@ -34,7 +34,7 @@ const styles = css({ color: 'var(--ds-color-text)' });
|
|
|
34
34
|
export default () => <div css={styles}>…</div>;
|
|
35
35
|
```
|
|
36
36
|
|
|
37
|
-
```
|
|
37
|
+
```tsx
|
|
38
38
|
import { xcss, Box } from '@atlaskit/primitives';
|
|
39
39
|
|
|
40
40
|
const styles = xcss({ color: 'color.text' });
|
|
@@ -45,10 +45,10 @@ export default () => <Box xcss={styles}>…</Box>;
|
|
|
45
45
|
|
|
46
46
|
### `canAutoFix: boolean`
|
|
47
47
|
|
|
48
|
-
Determines whether or not the
|
|
48
|
+
Determines whether or not the autofixer is enabled.
|
|
49
49
|
|
|
50
50
|
Defaults to `false` due to safety concerns when mixing Compiled and other CSS-in-JS libraries on the
|
|
51
51
|
same component.
|
|
52
52
|
|
|
53
|
-
Even when enabled, the
|
|
53
|
+
Even when enabled, the autofixer will only convert usages that are deemed safe. Currently this is
|
|
54
54
|
limited to purely static styles where all keys and values are simple literals.
|
|
@@ -40,8 +40,8 @@ var rule = exports.rule = (0, _createRule.createLintRule)({
|
|
|
40
40
|
var importSources = (0, _isSupportedImport.getImportSources)(context);
|
|
41
41
|
return {
|
|
42
42
|
CallExpression: function CallExpression(node) {
|
|
43
|
-
var _context$
|
|
44
|
-
references = _context$
|
|
43
|
+
var _context$getScope = context.getScope(),
|
|
44
|
+
references = _context$getScope.references;
|
|
45
45
|
if (!(0, _isSupportedImport.hasStyleObjectArguments)(node.callee, references, importSources)) {
|
|
46
46
|
return;
|
|
47
47
|
}
|
|
@@ -70,7 +70,7 @@ var rule = exports.rule = (0, _createRule.createLintRule)({
|
|
|
70
70
|
var items = argument.elements.filter(function (value) {
|
|
71
71
|
return value !== null;
|
|
72
72
|
}).map(function (element) {
|
|
73
|
-
return context.
|
|
73
|
+
return context.getSourceCode().getText(element);
|
|
74
74
|
});
|
|
75
75
|
return fixer.replaceText(argument, items.join(', '));
|
|
76
76
|
}
|
|
@@ -41,8 +41,8 @@ var rule = exports.rule = (0, _createRule.createLintRule)({
|
|
|
41
41
|
var importSources = (0, _isSupportedImport.getImportSources)(context);
|
|
42
42
|
return {
|
|
43
43
|
CallExpression: function CallExpression(node) {
|
|
44
|
-
var _context$
|
|
45
|
-
references = _context$
|
|
44
|
+
var _context$getScope = context.getScope(),
|
|
45
|
+
references = _context$getScope.references;
|
|
46
46
|
if (!(0, _isSupportedImport.hasStyleObjectArguments)(node.callee, references, importSources)) {
|
|
47
47
|
return;
|
|
48
48
|
}
|
|
@@ -120,8 +120,8 @@ var rule = exports.rule = (0, _createRule.createLintRule)({
|
|
|
120
120
|
return {
|
|
121
121
|
// Checking css/cssMap/keyframes/styled/xcss calls
|
|
122
122
|
CallExpression: function CallExpression(node) {
|
|
123
|
-
var _context$
|
|
124
|
-
references = _context$
|
|
123
|
+
var _context$getScope = context.getScope(),
|
|
124
|
+
references = _context$getScope.references;
|
|
125
125
|
if (!(0, _isSupportedImport.hasStyleObjectArguments)(node.callee, references, importSources)) {
|
|
126
126
|
return;
|
|
127
127
|
}
|
|
@@ -65,8 +65,8 @@ var rule = exports.rule = (0, _createRule.createLintRule)({
|
|
|
65
65
|
var importSources = (0, _isSupportedImport.getImportSources)(context);
|
|
66
66
|
return {
|
|
67
67
|
CallExpression: function CallExpression(node) {
|
|
68
|
-
var _context$
|
|
69
|
-
references = _context$
|
|
68
|
+
var _context$getScope = context.getScope(),
|
|
69
|
+
references = _context$getScope.references;
|
|
70
70
|
if (!(0, _isSupportedImport.isCss)(node.callee, references, importSources) && !(0, _isSupportedImport.isStyled)(node.callee, references, importSources) && !(0, _isSupportedImport.isKeyframes)(node.callee, references, importSources) && !(0, _isSupportedImport.isCssMap)(node.callee, references, importSources) && !(0, _isSupportedImport.isXcss)(node.callee, references, importSources)) {
|
|
71
71
|
return;
|
|
72
72
|
}
|
|
@@ -33,7 +33,7 @@ export const rule = createLintRule({
|
|
|
33
33
|
CallExpression(node) {
|
|
34
34
|
const {
|
|
35
35
|
references
|
|
36
|
-
} = context.
|
|
36
|
+
} = context.getScope();
|
|
37
37
|
if (!hasStyleObjectArguments(node.callee, references, importSources)) {
|
|
38
38
|
return;
|
|
39
39
|
}
|
|
@@ -55,7 +55,7 @@ export const rule = createLintRule({
|
|
|
55
55
|
*/
|
|
56
56
|
return null;
|
|
57
57
|
}
|
|
58
|
-
const items = argument.elements.filter(value => value !== null).map(element => context.
|
|
58
|
+
const items = argument.elements.filter(value => value !== null).map(element => context.getSourceCode().getText(element));
|
|
59
59
|
return fixer.replaceText(argument, items.join(', '));
|
|
60
60
|
}
|
|
61
61
|
});
|
|
@@ -101,7 +101,7 @@ export const rule = createLintRule({
|
|
|
101
101
|
CallExpression(node) {
|
|
102
102
|
const {
|
|
103
103
|
references
|
|
104
|
-
} = context.
|
|
104
|
+
} = context.getScope();
|
|
105
105
|
if (!hasStyleObjectArguments(node.callee, references, importSources)) {
|
|
106
106
|
return;
|
|
107
107
|
}
|
|
@@ -61,7 +61,7 @@ export const rule = createLintRule({
|
|
|
61
61
|
CallExpression(node) {
|
|
62
62
|
const {
|
|
63
63
|
references
|
|
64
|
-
} = context.
|
|
64
|
+
} = context.getScope();
|
|
65
65
|
if (!isCss(node.callee, references, importSources) && !isStyled(node.callee, references, importSources) && !isKeyframes(node.callee, references, importSources) && !isCssMap(node.callee, references, importSources) && !isXcss(node.callee, references, importSources)) {
|
|
66
66
|
return;
|
|
67
67
|
}
|
|
@@ -34,8 +34,8 @@ export var rule = createLintRule({
|
|
|
34
34
|
var importSources = getImportSources(context);
|
|
35
35
|
return {
|
|
36
36
|
CallExpression: function CallExpression(node) {
|
|
37
|
-
var _context$
|
|
38
|
-
references = _context$
|
|
37
|
+
var _context$getScope = context.getScope(),
|
|
38
|
+
references = _context$getScope.references;
|
|
39
39
|
if (!hasStyleObjectArguments(node.callee, references, importSources)) {
|
|
40
40
|
return;
|
|
41
41
|
}
|
|
@@ -64,7 +64,7 @@ export var rule = createLintRule({
|
|
|
64
64
|
var items = argument.elements.filter(function (value) {
|
|
65
65
|
return value !== null;
|
|
66
66
|
}).map(function (element) {
|
|
67
|
-
return context.
|
|
67
|
+
return context.getSourceCode().getText(element);
|
|
68
68
|
});
|
|
69
69
|
return fixer.replaceText(argument, items.join(', '));
|
|
70
70
|
}
|
|
@@ -34,8 +34,8 @@ export var rule = createLintRule({
|
|
|
34
34
|
var importSources = getImportSources(context);
|
|
35
35
|
return {
|
|
36
36
|
CallExpression: function CallExpression(node) {
|
|
37
|
-
var _context$
|
|
38
|
-
references = _context$
|
|
37
|
+
var _context$getScope = context.getScope(),
|
|
38
|
+
references = _context$getScope.references;
|
|
39
39
|
if (!hasStyleObjectArguments(node.callee, references, importSources)) {
|
|
40
40
|
return;
|
|
41
41
|
}
|
|
@@ -113,8 +113,8 @@ export var rule = createLintRule({
|
|
|
113
113
|
return {
|
|
114
114
|
// Checking css/cssMap/keyframes/styled/xcss calls
|
|
115
115
|
CallExpression: function CallExpression(node) {
|
|
116
|
-
var _context$
|
|
117
|
-
references = _context$
|
|
116
|
+
var _context$getScope = context.getScope(),
|
|
117
|
+
references = _context$getScope.references;
|
|
118
118
|
if (!hasStyleObjectArguments(node.callee, references, importSources)) {
|
|
119
119
|
return;
|
|
120
120
|
}
|
|
@@ -59,8 +59,8 @@ export var rule = createLintRule({
|
|
|
59
59
|
var importSources = getImportSources(context);
|
|
60
60
|
return {
|
|
61
61
|
CallExpression: function CallExpression(node) {
|
|
62
|
-
var _context$
|
|
63
|
-
references = _context$
|
|
62
|
+
var _context$getScope = context.getScope(),
|
|
63
|
+
references = _context$getScope.references;
|
|
64
64
|
if (!isCss(node.callee, references, importSources) && !isStyled(node.callee, references, importSources) && !isKeyframes(node.callee, references, importSources) && !isCssMap(node.callee, references, importSources) && !isXcss(node.callee, references, importSources)) {
|
|
65
65
|
return;
|
|
66
66
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/eslint-plugin-ui-styling-standard",
|
|
3
|
-
"version": "0.16.
|
|
3
|
+
"version": "0.16.4",
|
|
4
4
|
"author": "Atlassian Pty Ltd",
|
|
5
5
|
"description": "The eslint plugin to enforce and educate on Atlassian's UI Styling Standard",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -12,7 +12,9 @@
|
|
|
12
12
|
"name": "UI Styling Standard",
|
|
13
13
|
"category": "Tooling"
|
|
14
14
|
},
|
|
15
|
-
"productPushConsumption": [
|
|
15
|
+
"productPushConsumption": [
|
|
16
|
+
"jira"
|
|
17
|
+
]
|
|
16
18
|
},
|
|
17
19
|
"publishConfig": {
|
|
18
20
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -25,7 +27,10 @@
|
|
|
25
27
|
"types": "dist/types/index.d.ts",
|
|
26
28
|
"typesVersions": {
|
|
27
29
|
">=4.5 <4.9": {
|
|
28
|
-
"*": [
|
|
30
|
+
"*": [
|
|
31
|
+
"dist/types-ts4.5/*",
|
|
32
|
+
"dist/types-ts4.5/index.d.ts"
|
|
33
|
+
]
|
|
29
34
|
}
|
|
30
35
|
},
|
|
31
36
|
"sideEffects": false,
|
|
@@ -1,111 +1,130 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
Blocks legacy `@atlaskit/theme` mixins that `@compiled/react` cannot compile. This includes the
|
|
2
|
+
`typography`, `elevation` and `skeletonShimmer` mixins.
|
|
3
3
|
|
|
4
4
|
## Examples
|
|
5
5
|
|
|
6
6
|
### Typography
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
Don't use `typography` mixins.
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
Use [typography tokens](https://atlassian.design/foundations/typography-beta/applying-typography) or
|
|
11
|
+
the [Heading](https://atlassian.design/components/heading) and
|
|
12
|
+
[Text](https://atlassian.design/components/primitives/text) components.
|
|
11
13
|
|
|
12
|
-
|
|
13
|
-
import { styled } from '@compiled/react';
|
|
14
|
-
import { typography } from '@atlaskit/theme';
|
|
15
|
-
|
|
16
|
-
export const HeadingComponent = styled.h2`
|
|
17
|
-
${typography.h200()};
|
|
18
|
-
`;
|
|
19
|
-
```
|
|
14
|
+
#### Incorrect
|
|
20
15
|
|
|
21
16
|
```tsx
|
|
22
|
-
import {
|
|
17
|
+
import { css } from '@compiled/react';
|
|
23
18
|
import { typography } from '@atlaskit/theme';
|
|
24
19
|
|
|
25
|
-
|
|
20
|
+
const titleStyles = css(typography.h700());
|
|
26
21
|
```
|
|
27
22
|
|
|
28
|
-
|
|
23
|
+
#### Correct
|
|
29
24
|
|
|
30
25
|
```tsx
|
|
31
|
-
import {
|
|
26
|
+
import { css } from '@compiled/react';
|
|
27
|
+
import { token } from '@atlaskit/tokens';
|
|
32
28
|
|
|
33
|
-
const
|
|
34
|
-
|
|
29
|
+
const titleStyles = css({
|
|
30
|
+
font: token('font.heading.large'),
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
const paragraphStyles = css({
|
|
34
|
+
font: token('font.body.large'),
|
|
35
35
|
});
|
|
36
36
|
```
|
|
37
37
|
|
|
38
38
|
```tsx
|
|
39
|
+
import { css } from '@compiled/react';
|
|
39
40
|
import Heading from '@atlaskit/heading';
|
|
41
|
+
import { Stack, Text } from '@atlaskit/primitives';
|
|
40
42
|
import { token } from '@atlaskit/tokens';
|
|
41
|
-
import { styled } from '@compiled/react';
|
|
42
43
|
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
<Heading level="h200" as="h3">
|
|
49
|
-
<TitleComponent {...props} />
|
|
50
|
-
</Heading>
|
|
44
|
+
const Component = () => (
|
|
45
|
+
<Stack>
|
|
46
|
+
<Heading size="large">Title</Heading>
|
|
47
|
+
<Text size="large">Lorem ipsum</Text>
|
|
48
|
+
</Stack>
|
|
51
49
|
);
|
|
52
50
|
```
|
|
53
51
|
|
|
54
52
|
### Elevation
|
|
55
53
|
|
|
56
|
-
|
|
54
|
+
Don't use `elevation` mixins.
|
|
55
|
+
|
|
56
|
+
Use [elevation tokens](https://atlassian.design/foundations/elevation) instead.
|
|
57
57
|
|
|
58
|
-
|
|
58
|
+
#### Incorrect
|
|
59
59
|
|
|
60
60
|
```tsx
|
|
61
|
-
import {
|
|
61
|
+
import { css } from '@compiled/react';
|
|
62
62
|
import { elevation } from '@atlaskit/theme';
|
|
63
63
|
|
|
64
|
-
|
|
65
|
-
${elevation.e100()};
|
|
66
|
-
`;
|
|
64
|
+
const cardStyles = css(elevation.e100());
|
|
67
65
|
```
|
|
68
66
|
|
|
69
|
-
|
|
67
|
+
#### Correct
|
|
70
68
|
|
|
71
69
|
```tsx
|
|
72
70
|
import { styled } from '@compiled/react';
|
|
73
71
|
import { token } from '@atlaskit/tokens';
|
|
74
72
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
'0 1px 1px rgba(9,30,66,0.25),0 0 1px 1px rgba(9,30,66,0.13)',
|
|
79
|
-
),
|
|
73
|
+
const cardStyles = css({
|
|
74
|
+
backgroundColor: token('elevation.surface.raised'),
|
|
75
|
+
boxShadow: token('elevation.shadow.raised'),
|
|
80
76
|
});
|
|
81
77
|
```
|
|
82
78
|
|
|
83
79
|
### Skeleton Shimmer
|
|
84
80
|
|
|
85
|
-
|
|
86
|
-
[link](https://staging.atlassian.design/components/skeleton/examples)).
|
|
81
|
+
Don't use the `skeletonShimmer` mixin.
|
|
87
82
|
|
|
88
|
-
|
|
83
|
+
Preview our [Skeleton](https://staging.atlassian.design/components/skeleton/examples) component
|
|
84
|
+
(internal Atlassians only).
|
|
89
85
|
|
|
90
|
-
|
|
86
|
+
Otherwise:
|
|
87
|
+
|
|
88
|
+
- Use the `color.skeleton` and `color.skeleton.subtle` tokens to make your own component.
|
|
89
|
+
- Use `@atlassian/jira-skeletons` when working on Jira (internal Atlassians only).
|
|
90
|
+
|
|
91
|
+
#### Incorrect
|
|
91
92
|
|
|
92
93
|
```tsx
|
|
93
|
-
import {
|
|
94
|
+
import { css } from '@compiled/react';
|
|
94
95
|
import { skeletonShimmer } from '@atlaskit/theme/constants';
|
|
95
96
|
|
|
96
|
-
|
|
97
|
-
${skeletonShimmer};
|
|
98
|
-
`;
|
|
97
|
+
const skeletonStyles = css(skeletonShimmer());
|
|
99
98
|
```
|
|
100
99
|
|
|
101
|
-
|
|
100
|
+
#### Correct
|
|
101
|
+
|
|
102
|
+
```tsx
|
|
103
|
+
import Skeleton from '@atlaskit/skeleton';
|
|
104
|
+
|
|
105
|
+
<Skeleton width="200px" height="16px" isShimmering />;
|
|
106
|
+
```
|
|
102
107
|
|
|
103
108
|
```tsx
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
109
|
+
import { css, keyframes } from '@compiled/react';
|
|
110
|
+
|
|
111
|
+
const shimmer = keyframes({
|
|
112
|
+
from: { backgroundColor: token('color.skeleton') },
|
|
113
|
+
to: { backgroundColor: token('color.skeleton.subtle') },
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
const skeletonStyles = css({
|
|
117
|
+
backgroundColor: token('color.skeleton'),
|
|
118
|
+
animationName: shimmer,
|
|
119
|
+
animationDuration: '1.5s',
|
|
120
|
+
animationIterationCount: 'infinite',
|
|
121
|
+
animationTimingFunction: 'linear',
|
|
122
|
+
animationDirection: 'alternate',
|
|
123
|
+
});
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
```tsx
|
|
127
|
+
import { ListSkeleton } from '@atlassian/jira-skeletons';
|
|
128
|
+
|
|
129
|
+
<ListSkeleton numOfRows={3} />;
|
|
111
130
|
```
|
|
@@ -1,11 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
`no-styled-tagged-template-expression`, as output from the latter may use props syntax that results
|
|
4
|
-
in a type error.
|
|
1
|
+
Blocks dynamic styling syntax that is unsupported by `styled-components@<4` and `@emotion/styled`,
|
|
2
|
+
and provides an autofix for converting to a supported syntax.
|
|
5
3
|
|
|
6
|
-
|
|
4
|
+
Use this rule alongside `no-styled-tagged-template-expression`, which can output the unsupported
|
|
5
|
+
dynamic styling syntax.
|
|
7
6
|
|
|
8
|
-
|
|
7
|
+
This rule applies only to `styled` usages from `styled-components` and `@emotion/styled`.
|
|
8
|
+
|
|
9
|
+
## Autofix
|
|
10
|
+
|
|
11
|
+
The autofix will find style object values that are arrow functions,
|
|
12
|
+
|
|
13
|
+
```tsx
|
|
9
14
|
styled.div({
|
|
10
15
|
color: ({ myColor }) => myColor,
|
|
11
16
|
backgroundColor: (props) => props.someColor,
|
|
@@ -15,7 +20,7 @@ styled.div({
|
|
|
15
20
|
However, refactoring the arrow function so that it is the argument to `styled.div` will fix the
|
|
16
21
|
issue:
|
|
17
22
|
|
|
18
|
-
```
|
|
23
|
+
```tsx
|
|
19
24
|
styled.div((props) => ({
|
|
20
25
|
color: props.myColor,
|
|
21
26
|
backgroundColor: props.someColor,
|
|
@@ -38,47 +43,47 @@ manually fix the output, or migrate the code to `@compiled/react`.
|
|
|
38
43
|
Type annotations in the arrow function are not supported; you will need to remediate the lint error
|
|
39
44
|
manually. For example:
|
|
40
45
|
|
|
41
|
-
```
|
|
46
|
+
```tsx
|
|
42
47
|
type Props = {
|
|
43
|
-
|
|
44
|
-
|
|
48
|
+
myColor: string;
|
|
49
|
+
someColor: string;
|
|
45
50
|
};
|
|
46
51
|
|
|
47
52
|
styled.div({
|
|
48
|
-
|
|
49
|
-
|
|
53
|
+
color: ({ myColor }: Props) => myColor,
|
|
54
|
+
backgroundColor: (props: Props) => props.someColor,
|
|
50
55
|
});
|
|
51
56
|
```
|
|
52
57
|
|
|
53
|
-
|
|
58
|
+
could be refactored as
|
|
54
59
|
|
|
55
|
-
```
|
|
60
|
+
```tsx
|
|
56
61
|
type Props = {
|
|
57
|
-
|
|
58
|
-
|
|
62
|
+
myColor: string;
|
|
63
|
+
someColor: string;
|
|
59
64
|
};
|
|
60
65
|
|
|
61
66
|
styled.div((props: Props) => ({
|
|
62
|
-
|
|
63
|
-
|
|
67
|
+
color: props.myColor,
|
|
68
|
+
backgroundColor: props.someColor,
|
|
64
69
|
}));
|
|
65
70
|
```
|
|
66
71
|
|
|
67
|
-
### Special syntax in
|
|
72
|
+
### Special syntax in function parameters
|
|
68
73
|
|
|
69
74
|
Rest elements, default values, and so on in the parameter of an arrow function will need to be
|
|
70
75
|
remediated manually. For example:
|
|
71
76
|
|
|
72
|
-
```
|
|
77
|
+
```tsx
|
|
73
78
|
styled.div({
|
|
74
79
|
color: ({ myColor = '#fff' }) => myColor,
|
|
75
80
|
backgroundColor: ({ myColor = '#aaa' }) => myColor,
|
|
76
81
|
});
|
|
77
82
|
```
|
|
78
83
|
|
|
79
|
-
could
|
|
84
|
+
could be refactored as
|
|
80
85
|
|
|
81
|
-
```
|
|
86
|
+
```tsx
|
|
82
87
|
styled.div((props) => ({
|
|
83
88
|
color: myColor ?? '#fff',
|
|
84
89
|
backgroundColor: myColor ?? '#aaa',
|
|
@@ -89,7 +94,7 @@ styled.div((props) => ({
|
|
|
89
94
|
|
|
90
95
|
### Incorrect
|
|
91
96
|
|
|
92
|
-
```
|
|
97
|
+
```tsx
|
|
93
98
|
import styled from 'styled-components';
|
|
94
99
|
|
|
95
100
|
styled.div({
|
|
@@ -104,7 +109,7 @@ styled.div({
|
|
|
104
109
|
|
|
105
110
|
### Correct
|
|
106
111
|
|
|
107
|
-
```
|
|
112
|
+
```tsx
|
|
108
113
|
import styled from '@emotion/styled';
|
|
109
114
|
|
|
110
115
|
styled.div((props) => ({
|
|
@@ -1,39 +1,45 @@
|
|
|
1
|
-
|
|
1
|
+
Blocks providing static values through the `style` prop, which should only be used to provide
|
|
2
|
+
dynamic values (values unknown at build time).
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
time, e.g. `<div style={{ width: props.width }}>`. No statics values such as numbers, strings or any
|
|
5
|
-
other statically analysable values should be passed to the `style` attribute. Instead, static CSS
|
|
6
|
-
values should be passed into the `css` prop in JSX components.
|
|
4
|
+
Use the `css` prop for providing static values instead.
|
|
7
5
|
|
|
8
6
|
## Examples
|
|
9
7
|
|
|
10
8
|
### Incorrect
|
|
11
9
|
|
|
12
10
|
```tsx
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
11
|
+
import { token } from '@atlaskit/tokens';
|
|
12
|
+
|
|
13
|
+
const Component = () => (
|
|
14
|
+
<div
|
|
15
|
+
style={{
|
|
16
|
+
margin: 0,
|
|
17
|
+
color: token('color.text.danger'),
|
|
18
|
+
}}
|
|
19
|
+
/>
|
|
20
|
+
);
|
|
23
21
|
```
|
|
24
22
|
|
|
25
23
|
### Correct
|
|
26
24
|
|
|
25
|
+
Although `token` is a function call, it is statically resolvable by Compiled and should not be used
|
|
26
|
+
in the `style` prop.
|
|
27
|
+
|
|
27
28
|
```tsx
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
29
|
+
import { css } from '@compiled/react';
|
|
30
|
+
import { token } from '@atlaskit/tokens';
|
|
31
|
+
|
|
32
|
+
type Props = { width: string };
|
|
33
|
+
|
|
34
|
+
const baseStyles = css({ margin: 0, color: token('color.text.danger') });
|
|
35
|
+
|
|
36
|
+
const Component = ({ width }: Props) => (
|
|
37
|
+
<div
|
|
38
|
+
css={baseStyles}
|
|
39
|
+
style={{
|
|
40
|
+
width: props.width,
|
|
41
|
+
'--my-nested-width': props.width,
|
|
42
|
+
}}
|
|
43
|
+
/>
|
|
44
|
+
);
|
|
39
45
|
```
|