@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,35 @@
|
|
|
1
|
-
|
|
2
|
-
styles are applied
|
|
1
|
+
Blocks the `cx()` function from being used outside of the `xcss` prop. This aids tracking which
|
|
2
|
+
styles are applied.
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
Use the `cx()` function when passing multiple styles to the `xcss` prop. This provides more robust
|
|
5
|
+
type checking than the conventional array syntax:
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
```tsx
|
|
8
|
+
import { cssMap, cx } from '@compiled/react';
|
|
9
|
+
import { token } from '@atlaskit/tokens';
|
|
10
|
+
import { Component } from 'some-package';
|
|
11
|
+
|
|
12
|
+
const styles = cssMap({
|
|
13
|
+
text: { color: token('color.text') },
|
|
14
|
+
primary: { color: token('color.text.brand') },
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
<Component xcss={cx(isPrimary && styles.text, !isPrimary && styles.primary)} />;
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
The `cx()` function is only checked when imported from `@compiled/react` or `@atlaskit/css`.
|
|
10
21
|
|
|
11
22
|
## Examples
|
|
12
23
|
|
|
13
24
|
### Incorrect
|
|
14
25
|
|
|
15
|
-
```
|
|
16
|
-
import {
|
|
26
|
+
```tsx
|
|
27
|
+
import { cssMap, cx } from '@compiled/react';
|
|
28
|
+
import { token } from '@atlaskit/tokens';
|
|
17
29
|
|
|
18
30
|
const styles = cssMap({
|
|
19
|
-
text: { color: '
|
|
20
|
-
bg: { background: '
|
|
31
|
+
text: { color: token('color.text') },
|
|
32
|
+
bg: { background: token('color.background.neutral') },
|
|
21
33
|
});
|
|
22
34
|
|
|
23
35
|
const joinedStyles = cx(styles.text, styles.bg);
|
|
@@ -27,12 +39,12 @@ const joinedStyles = cx(styles.text, styles.bg);
|
|
|
27
39
|
|
|
28
40
|
### Correct
|
|
29
41
|
|
|
30
|
-
```
|
|
31
|
-
import {
|
|
42
|
+
```tsx
|
|
43
|
+
import { cssMap, cx } from '@compiled/react';
|
|
32
44
|
|
|
33
45
|
const styles = cssMap({
|
|
34
|
-
text: { color: '
|
|
35
|
-
bg: { background: '
|
|
46
|
+
text: { color: token('color.text') },
|
|
47
|
+
bg: { background: token('color.background.neutral') },
|
|
36
48
|
});
|
|
37
49
|
|
|
38
50
|
<Button xcss={cx(styles.text, styles.bg)} />;
|
|
@@ -1,36 +1,40 @@
|
|
|
1
|
-
|
|
1
|
+
Blocks passing array arguments to style declaration functions.
|
|
2
2
|
|
|
3
3
|
## Examples
|
|
4
4
|
|
|
5
5
|
### Incorrect
|
|
6
6
|
|
|
7
|
-
```
|
|
7
|
+
```tsx
|
|
8
8
|
import { css } from '@compiled/react';
|
|
9
|
+
|
|
9
10
|
const styles = css([{ width: 100 }, { height: 100 }]);
|
|
10
11
|
```
|
|
11
12
|
|
|
12
|
-
```
|
|
13
|
+
```tsx
|
|
13
14
|
import { styled } from '@compiled/react';
|
|
15
|
+
|
|
14
16
|
const styles = css([{ width: 100 }, ...items]);
|
|
15
17
|
```
|
|
16
18
|
|
|
17
19
|
### Correct
|
|
18
20
|
|
|
19
|
-
```
|
|
21
|
+
```tsx
|
|
20
22
|
import { css } from '@compiled/react';
|
|
23
|
+
|
|
21
24
|
const styles = css({ width: 100 }, { height: 100 });
|
|
22
25
|
```
|
|
23
26
|
|
|
24
|
-
```
|
|
27
|
+
```tsx
|
|
25
28
|
import { css } from '@compiled/react';
|
|
29
|
+
|
|
26
30
|
const styles = css({ width: 100 }, ...items);
|
|
27
31
|
```
|
|
28
32
|
|
|
29
33
|
## Options
|
|
30
34
|
|
|
31
|
-
### importSources
|
|
35
|
+
### `importSources: string[]`
|
|
32
36
|
|
|
33
|
-
By default, this rule will check
|
|
37
|
+
By default, this rule will check styles using:
|
|
34
38
|
|
|
35
39
|
- `@atlaskit/css`
|
|
36
40
|
- `@atlaskit/primitives`
|
|
@@ -40,5 +44,4 @@ By default, this rule will check `css` usages from:
|
|
|
40
44
|
- `@emotion/styled`
|
|
41
45
|
- `styled-components`
|
|
42
46
|
|
|
43
|
-
|
|
44
|
-
array of package names (strings).
|
|
47
|
+
Override this list with the `importSources` option, which accepts an array of package names.
|
|
@@ -40,7 +40,7 @@ export const rule = createLintRule({
|
|
|
40
40
|
const importSources = getImportSources(context);
|
|
41
41
|
return {
|
|
42
42
|
CallExpression(node) {
|
|
43
|
-
const { references } = context.
|
|
43
|
+
const { references } = context.getScope();
|
|
44
44
|
|
|
45
45
|
if (!hasStyleObjectArguments(node.callee, references, importSources)) {
|
|
46
46
|
return;
|
|
@@ -71,7 +71,7 @@ export const rule = createLintRule({
|
|
|
71
71
|
value: SpreadElement | Expression | null,
|
|
72
72
|
): value is SpreadElement | Expression => value !== null,
|
|
73
73
|
)
|
|
74
|
-
.map((element) => context.
|
|
74
|
+
.map((element) => context.getSourceCode().getText(element));
|
|
75
75
|
|
|
76
76
|
return fixer.replaceText(argument, items.join(', '));
|
|
77
77
|
},
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
Blocks the `className` prop, which encourages unsafe global styles and cannot be statically
|
|
2
|
+
resolved.
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
via local tooling. Use props for configuration and typical CSS-in-JS for styling or `xcss` for
|
|
5
|
-
bounded overrides.
|
|
4
|
+
Use the `css` prop for styling, with props for configuration and `xcss` for bounded overrides.
|
|
6
5
|
|
|
7
6
|
## Examples
|
|
8
7
|
|
|
@@ -20,14 +19,23 @@ bounded overrides.
|
|
|
20
19
|
|
|
21
20
|
```tsx
|
|
22
21
|
import { css } from '@compiled/react';
|
|
22
|
+
import { token } from '@atlaskit/tokens';
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
const myStyles = css({ padding: token('space.100') });
|
|
25
|
+
|
|
26
|
+
<div css={myStyles} />;
|
|
25
27
|
```
|
|
26
28
|
|
|
27
29
|
```tsx
|
|
28
30
|
<MyComponent isDisabled={isDisabled} />
|
|
29
31
|
```
|
|
30
32
|
|
|
33
|
+
```tsx
|
|
34
|
+
import { Checkbox } from '@atlaskit/checkbox';
|
|
35
|
+
|
|
36
|
+
<Checkbox xcss={{ alignItems: 'center' }} />;
|
|
37
|
+
```
|
|
38
|
+
|
|
31
39
|
## FAQ
|
|
32
40
|
|
|
33
41
|
### What if I'm using `className` to target elements with JavaScript?
|
|
@@ -1,42 +1,92 @@
|
|
|
1
|
-
|
|
1
|
+
Blocks `@container` at-rules
|
|
2
|
+
([container queries](https://developer.mozilla.org/en-US/docs/Web/CSS/@container)), which are
|
|
3
|
+
unsafe.
|
|
2
4
|
|
|
3
|
-
Container queries
|
|
4
|
-
and isn’t fully supported across our frontend tech stacks.
|
|
5
|
+
Container queries are unsafe because they:
|
|
5
6
|
|
|
6
|
-
|
|
7
|
+
- break the rules of scope
|
|
8
|
+
- aren't deterministic
|
|
9
|
+
- aren't type-safe
|
|
10
|
+
- aren't fully supported across our frontend tech stacks
|
|
11
|
+
|
|
12
|
+
Use [media queries](https://atlassian.design/components/primitives/responsive/breakpoints/examples),
|
|
13
|
+
a
|
|
14
|
+
[WidthObserver](https://atlaskit.atlassian.com/packages/design-system/width-detector/docs/migration-guide),
|
|
15
|
+
or a custom [ResizeObserver](https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver)
|
|
16
|
+
instead.
|
|
7
17
|
|
|
8
18
|
## Examples
|
|
9
19
|
|
|
10
20
|
### Incorrect
|
|
11
21
|
|
|
12
|
-
```
|
|
22
|
+
```tsx
|
|
13
23
|
import { css } from '@compiled/react';
|
|
24
|
+
import { token } from '@atlaskit/tokens';
|
|
14
25
|
|
|
15
|
-
const
|
|
26
|
+
const headingStyles = css({
|
|
16
27
|
'@container (width > 400px)': {
|
|
17
|
-
|
|
18
|
-
fontSize: '1.5rem',
|
|
19
|
-
},
|
|
28
|
+
font: token('font.heading.large'),
|
|
20
29
|
},
|
|
21
30
|
});
|
|
22
31
|
```
|
|
23
32
|
|
|
24
33
|
### Correct
|
|
25
34
|
|
|
26
|
-
|
|
35
|
+
#### Media queries
|
|
36
|
+
|
|
37
|
+
```tsx
|
|
27
38
|
import { css } from '@compiled/react';
|
|
39
|
+
import { media } from '@atlaskit/primitives/responsive';
|
|
40
|
+
import { token } from '@atlaskit/tokens';
|
|
41
|
+
|
|
42
|
+
const headingStyles = css({
|
|
43
|
+
[media.above.sm]: {
|
|
44
|
+
font: token('font.heading.large'),
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
#### WidthObserver
|
|
50
|
+
|
|
51
|
+
```tsx
|
|
52
|
+
import { useState } from 'react';
|
|
53
|
+
import { css, cssMap } from '@compiled/react';
|
|
54
|
+
import throttle from 'lodash/throttle';
|
|
55
|
+
import { WidthObserver } from '@atlaskit/width-detector';
|
|
56
|
+
import { token } from '@atlaskit/tokens';
|
|
28
57
|
|
|
29
58
|
const containerStyles = css({
|
|
30
|
-
|
|
31
|
-
|
|
59
|
+
// Required for the `WidthObserver`, which is absolutely positioned
|
|
60
|
+
position: 'relative',
|
|
32
61
|
});
|
|
62
|
+
|
|
63
|
+
const headingStyles = cssMap({
|
|
64
|
+
small: {
|
|
65
|
+
font: token('font.heading.small'),
|
|
66
|
+
},
|
|
67
|
+
large: {
|
|
68
|
+
font: token('font.heading.large'),
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
const ResponsiveH2 = () => {
|
|
73
|
+
const [width = 0, setWidth] = useState<number | undefined>(undefined);
|
|
74
|
+
const throttledSetWidth = throttle(setWidth, 50);
|
|
75
|
+
|
|
76
|
+
return (
|
|
77
|
+
<div css={containerStyles}>
|
|
78
|
+
<WidthObserver setWidth={throttledSetWidth} />
|
|
79
|
+
<h2 css={width < 400 ? headingStyles.small : headingStyles.large}>Title</h2>
|
|
80
|
+
</div>
|
|
81
|
+
);
|
|
82
|
+
};
|
|
33
83
|
```
|
|
34
84
|
|
|
35
85
|
## Options
|
|
36
86
|
|
|
37
|
-
### importSources
|
|
87
|
+
### `importSources: string[]`
|
|
38
88
|
|
|
39
|
-
By default, this rule will check
|
|
89
|
+
By default, this rule will check styles using:
|
|
40
90
|
|
|
41
91
|
- `@atlaskit/css`
|
|
42
92
|
- `@atlaskit/primitives`
|
|
@@ -46,5 +96,4 @@ By default, this rule will check `css` usages from:
|
|
|
46
96
|
- `@emotion/styled`
|
|
47
97
|
- `styled-components`
|
|
48
98
|
|
|
49
|
-
|
|
50
|
-
array of package names (strings).
|
|
99
|
+
Override this list with the `importSources` option, which accepts an array of package names.
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
Blocks dynamic styles (function expressions) in style declarations.
|
|
2
2
|
|
|
3
3
|
This ensures that style declarations:
|
|
4
4
|
|
|
5
5
|
- are statically analyzable
|
|
6
6
|
- can be efficiently extracted into atomic CSS
|
|
7
|
-
- are more readable
|
|
7
|
+
- are more readable and deterministic, thus easier to maintain
|
|
8
8
|
|
|
9
9
|
## Examples
|
|
10
10
|
|
|
@@ -29,14 +29,20 @@ const Component = styled.div<{ width: number }>({
|
|
|
29
29
|
```tsx
|
|
30
30
|
import styled from 'styled-components';
|
|
31
31
|
|
|
32
|
-
const Container = styled.div<hasPadding>({
|
|
32
|
+
const Container = styled.div<{ hasPadding: boolean }>({
|
|
33
33
|
padding: ({ hasPadding }) => (hasPadding ? token('space.100', '8px') : token('space.0', '0px')),
|
|
34
34
|
});
|
|
35
35
|
```
|
|
36
36
|
|
|
37
37
|
### Correct
|
|
38
38
|
|
|
39
|
-
|
|
39
|
+
Define all styles statically, and dynamically apply them using the `css` prop. Use the `style` prop
|
|
40
|
+
for values that are only known at runtime.
|
|
41
|
+
|
|
42
|
+
For further guidance, consult our
|
|
43
|
+
[migration guide](https://atlassian.design/components/eslint-plugin-ui-styling-standard/migration-guide).
|
|
44
|
+
|
|
45
|
+
#### Flags
|
|
40
46
|
|
|
41
47
|
If you have a style that is on/off depending on a prop, use the `css` prop to conditionally apply
|
|
42
48
|
it.
|
|
@@ -52,7 +58,7 @@ const Container = ({ hasPadding = false }: { hasPadding?: boolean }) => {
|
|
|
52
58
|
};
|
|
53
59
|
```
|
|
54
60
|
|
|
55
|
-
|
|
61
|
+
#### Variants
|
|
56
62
|
|
|
57
63
|
If you have variants which are known ahead of time, use `cssMap` to define them and the `css` prop
|
|
58
64
|
to conditionally apply it.
|
|
@@ -77,7 +83,7 @@ const Wrapper = ({ appearance = 'primary' }: { appearance?: 'primary' | 'error'
|
|
|
77
83
|
);
|
|
78
84
|
```
|
|
79
85
|
|
|
80
|
-
|
|
86
|
+
#### Dynamic values
|
|
81
87
|
|
|
82
88
|
If you have styles which are truly dynamic, use the `style` prop.
|
|
83
89
|
|
|
@@ -95,7 +101,7 @@ const Component = ({ width }: { width: number }) => {
|
|
|
95
101
|
import { css } from '@compiled/react';
|
|
96
102
|
|
|
97
103
|
const containerStyles = css({
|
|
98
|
-
'
|
|
104
|
+
'&::before': {
|
|
99
105
|
width: 'var(--ak-example-width)',
|
|
100
106
|
},
|
|
101
107
|
});
|
|
@@ -107,9 +113,9 @@ function Example({ width }: { width: number }) {
|
|
|
107
113
|
|
|
108
114
|
## Options
|
|
109
115
|
|
|
110
|
-
### importSources
|
|
116
|
+
### `importSources: string[]`
|
|
111
117
|
|
|
112
|
-
By default, this rule will check
|
|
118
|
+
By default, this rule will check styles using:
|
|
113
119
|
|
|
114
120
|
- `@atlaskit/css`
|
|
115
121
|
- `@atlaskit/primitives`
|
|
@@ -119,5 +125,4 @@ By default, this rule will check usages from:
|
|
|
119
125
|
- `@emotion/styled`
|
|
120
126
|
- `styled-components`
|
|
121
127
|
|
|
122
|
-
|
|
123
|
-
array of package names (strings).
|
|
128
|
+
Override this list with the `importSources` option, which accepts an array of package names.
|
|
@@ -41,7 +41,7 @@ export const rule = createLintRule({
|
|
|
41
41
|
|
|
42
42
|
return {
|
|
43
43
|
CallExpression(node) {
|
|
44
|
-
const { references } = context.
|
|
44
|
+
const { references } = context.getScope();
|
|
45
45
|
|
|
46
46
|
if (!hasStyleObjectArguments(node.callee, references, importSources)) {
|
|
47
47
|
return;
|
|
@@ -1,14 +1,18 @@
|
|
|
1
|
-
|
|
1
|
+
Blocks exports of `css`, `cssMap`, `keyframes`, `styled`, `xcss` styles, which are unsafe.
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
Use alongside `no-imported-style-values` which blocks consumption of imported styles.
|
|
4
|
+
|
|
5
|
+
Compiled style declarations are null at runtime, so using imported styles will cause unexpected
|
|
6
|
+
errors.
|
|
7
|
+
|
|
8
|
+
Co-locate style definitions with their usage instead. This will also improve code readability,
|
|
9
|
+
maintainability and build performance.
|
|
6
10
|
|
|
7
11
|
## Examples
|
|
8
12
|
|
|
9
13
|
### Incorrect
|
|
10
14
|
|
|
11
|
-
```
|
|
15
|
+
```tsx
|
|
12
16
|
import { css } from '@compiled/react';
|
|
13
17
|
|
|
14
18
|
export const styles = css({});
|
|
@@ -16,7 +20,7 @@ export const styles = css({});
|
|
|
16
20
|
export default css({});
|
|
17
21
|
```
|
|
18
22
|
|
|
19
|
-
```
|
|
23
|
+
```tsx
|
|
20
24
|
import { keyframes } from '@compiled/react';
|
|
21
25
|
|
|
22
26
|
export const animation = keyframes({});
|
|
@@ -24,21 +28,12 @@ export const animation = keyframes({});
|
|
|
24
28
|
export default keyframes({});
|
|
25
29
|
```
|
|
26
30
|
|
|
27
|
-
|
|
28
|
-
`no-imported-style-values` rule which blocks consumption of imported styles.
|
|
29
|
-
|
|
30
|
-
```js
|
|
31
|
-
export default {
|
|
32
|
-
color: 'red',
|
|
33
|
-
margin: '0px',
|
|
34
|
-
};
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
```js
|
|
31
|
+
```tsx
|
|
38
32
|
import { css } from '@compiled/react';
|
|
33
|
+
import { token } from '@atlaskit/tokens';
|
|
39
34
|
|
|
40
|
-
const
|
|
41
|
-
|
|
35
|
+
const colorStyles = css({
|
|
36
|
+
color: token('color.text'),
|
|
42
37
|
});
|
|
43
38
|
|
|
44
39
|
const styles = {
|
|
@@ -54,29 +49,30 @@ export default styles.primary.text.color;
|
|
|
54
49
|
|
|
55
50
|
### Correct
|
|
56
51
|
|
|
57
|
-
Co-locate
|
|
58
|
-
performance.
|
|
52
|
+
Co-locate styles with components to improve code readability, linting, and build performance.
|
|
59
53
|
|
|
60
|
-
```
|
|
54
|
+
```tsx
|
|
61
55
|
import { css } from '@compiled/react';
|
|
62
56
|
|
|
63
57
|
const styles = css({});
|
|
64
|
-
|
|
58
|
+
|
|
59
|
+
export const Component = () => <div css={styles} />;
|
|
65
60
|
```
|
|
66
61
|
|
|
67
|
-
```
|
|
68
|
-
import { keyframes } from '@compiled/react';
|
|
62
|
+
```tsx
|
|
63
|
+
import { css, keyframes } from '@compiled/react';
|
|
69
64
|
|
|
70
65
|
const animation = keyframes({});
|
|
71
66
|
const styles = css({ animate: `${animation} 1s ease-in` });
|
|
72
|
-
|
|
67
|
+
|
|
68
|
+
export const Component = () => <div css={styles} />;
|
|
73
69
|
```
|
|
74
70
|
|
|
75
71
|
## Options
|
|
76
72
|
|
|
77
|
-
### importSources
|
|
73
|
+
### `importSources: string[]`
|
|
78
74
|
|
|
79
|
-
By default, this rule will check
|
|
75
|
+
By default, this rule will check styles using:
|
|
80
76
|
|
|
81
77
|
- `@atlaskit/css`
|
|
82
78
|
- `@atlaskit/primitives`
|
|
@@ -86,5 +82,4 @@ By default, this rule will check `css` usages from:
|
|
|
86
82
|
- `@emotion/styled`
|
|
87
83
|
- `styled-components`
|
|
88
84
|
|
|
89
|
-
|
|
90
|
-
array of package names (strings).
|
|
85
|
+
Override this list with the `importSources` option, which accepts an array of package names.
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
Blocks global styles through CSS-in-JS and CSS module imports.
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
Use local styles so that style dependencies are statically resolvable.
|
|
4
|
+
|
|
5
|
+
The only global styling that should be used is `@atlaskit/css-reset`.
|
|
5
6
|
|
|
6
7
|
## Examples
|
|
7
8
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
Blocks the `!important` flag in style declarations.
|
|
2
2
|
|
|
3
3
|
Properly composed styles will never need an `!important` flag. It is used to override specificity
|
|
4
4
|
when working across different scopes, and the UI Styling Standard enforces styles with minimal
|
|
@@ -12,9 +12,10 @@ The use of `!important` is a code smell and greatly impacts readability and dete
|
|
|
12
12
|
|
|
13
13
|
```js
|
|
14
14
|
import { css } from '@compiled/react';
|
|
15
|
+
import { token } from '@atlaskit/tokens';
|
|
15
16
|
|
|
16
17
|
const styles = css({
|
|
17
|
-
color: '
|
|
18
|
+
color: `${token('color.text.danger')}!important`,
|
|
18
19
|
});
|
|
19
20
|
```
|
|
20
21
|
|
|
@@ -22,8 +23,9 @@ const styles = css({
|
|
|
22
23
|
|
|
23
24
|
```js
|
|
24
25
|
import { css } from '@compiled/react';
|
|
26
|
+
import { token } from '@atlaskit/tokens';
|
|
25
27
|
|
|
26
28
|
const styles = css({
|
|
27
|
-
color: '
|
|
29
|
+
color: token('color.text.danger'),
|
|
28
30
|
});
|
|
29
31
|
```
|
|
@@ -1,29 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
calls.
|
|
1
|
+
Blocks imported style values in `css`, `cssMap`, `styled`, `keyframes` and `xcss` calls.
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
Use alongside `no-exported-styles` which blocks exporting styles.
|
|
4
|
+
|
|
5
|
+
Compiled style declarations are null at runtime, so using imported styles will cause unexpected
|
|
6
|
+
errors.
|
|
7
|
+
|
|
8
|
+
Co-locate style definitions with their usage instead. This will also improve code readability and
|
|
9
|
+
build performance.
|
|
8
10
|
|
|
9
11
|
## Examples
|
|
10
12
|
|
|
11
13
|
### Incorrect
|
|
12
14
|
|
|
13
|
-
```
|
|
15
|
+
```tsx
|
|
14
16
|
import { css } from '@compiled/react';
|
|
15
|
-
import { colors, getColor } from '
|
|
17
|
+
import { colors, getColor } from '../shared';
|
|
16
18
|
|
|
17
19
|
const styles = css({
|
|
18
|
-
|
|
19
|
-
|
|
20
|
+
color: getColor('red'),
|
|
21
|
+
backgroundColor: colors['red'],
|
|
20
22
|
});
|
|
21
23
|
```
|
|
22
24
|
|
|
23
|
-
```
|
|
25
|
+
```tsx
|
|
24
26
|
import { css } from '@compiled/react';
|
|
25
|
-
import { buttonStyles, cssShared, HEIGHT, colorKey } from '../shared';
|
|
26
27
|
import { ff } from '@atlaskit/ff';
|
|
28
|
+
import { buttonStyles, cssShared, HEIGHT, colorKey } from '../shared';
|
|
27
29
|
|
|
28
30
|
const sharedObject = { padding: 0 };
|
|
29
31
|
|
|
@@ -37,47 +39,49 @@ const styles = css({
|
|
|
37
39
|
|
|
38
40
|
Importing styles to use in style composition is not allowed.
|
|
39
41
|
|
|
40
|
-
```
|
|
42
|
+
```tsx
|
|
41
43
|
import { css } from '@compiled/react';
|
|
44
|
+
import { token } from '@atlaskit/tokens';
|
|
42
45
|
import { buttonStyles } from '../shared';
|
|
43
46
|
|
|
44
47
|
const styles = css({
|
|
45
|
-
color: '
|
|
48
|
+
color: token('color.text'),
|
|
46
49
|
});
|
|
47
50
|
|
|
48
|
-
|
|
51
|
+
const Component = () => <div css={[styles, buttonStyles]} />;
|
|
49
52
|
```
|
|
50
53
|
|
|
51
54
|
Importing styles to pass to the style prop is also not allowed.
|
|
52
55
|
|
|
53
|
-
```
|
|
56
|
+
```tsx
|
|
54
57
|
import { importedWidth } from '../shared';
|
|
55
58
|
|
|
56
|
-
|
|
59
|
+
const Component = () => <div style={{ width: importedWidth }} />;
|
|
57
60
|
```
|
|
58
61
|
|
|
59
62
|
### Correct
|
|
60
63
|
|
|
61
|
-
Co-locate
|
|
62
|
-
performance.
|
|
64
|
+
Co-locate styles with components to improve code readability, linting, and build performance.
|
|
63
65
|
|
|
64
|
-
```
|
|
66
|
+
```tsx
|
|
65
67
|
import { css } from '@compiled/react';
|
|
66
68
|
import { token } from '@atlaskit/tokens';
|
|
67
69
|
|
|
68
70
|
const styles = css({
|
|
69
|
-
color: '
|
|
71
|
+
color: token('color.text'),
|
|
70
72
|
padding: token('space.150'),
|
|
71
73
|
});
|
|
72
|
-
|
|
74
|
+
|
|
75
|
+
const Component = () => <div css={styles} />;
|
|
73
76
|
```
|
|
74
77
|
|
|
75
|
-
```
|
|
78
|
+
```tsx
|
|
76
79
|
import { keyframes } from '@compiled/react';
|
|
77
80
|
|
|
78
81
|
const animation = keyframes({});
|
|
79
82
|
const styles = css({ animate: `${animation} 1s ease-in` });
|
|
80
|
-
|
|
83
|
+
|
|
84
|
+
const Component = () => <div css={styles} />;
|
|
81
85
|
```
|
|
82
86
|
|
|
83
87
|
## Options
|
|
@@ -138,7 +142,7 @@ Default imports are not currently supported.
|
|
|
138
142
|
|
|
139
143
|
### `importSources: string[]`
|
|
140
144
|
|
|
141
|
-
By default, this rule will check
|
|
145
|
+
By default, this rule will check styles using:
|
|
142
146
|
|
|
143
147
|
- `@atlaskit/css`
|
|
144
148
|
- `@atlaskit/primitives`
|
|
@@ -148,5 +152,4 @@ By default, this rule will check `css` usages from:
|
|
|
148
152
|
- `@emotion/styled`
|
|
149
153
|
- `styled-components`
|
|
150
154
|
|
|
151
|
-
|
|
152
|
-
array of package names (strings).
|
|
155
|
+
Override this list with the `importSources` option, which accepts an array of package names.
|
|
@@ -122,7 +122,7 @@ export const rule = createLintRule({
|
|
|
122
122
|
return {
|
|
123
123
|
// Checking css/cssMap/keyframes/styled/xcss calls
|
|
124
124
|
CallExpression(node) {
|
|
125
|
-
const { references } = context.
|
|
125
|
+
const { references } = context.getScope();
|
|
126
126
|
|
|
127
127
|
if (!hasStyleObjectArguments(node.callee, references, importSources)) {
|
|
128
128
|
return;
|