@atlaskit/eslint-plugin-ui-styling-standard 0.14.2 → 0.15.1
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 +188 -167
- package/README.md +1 -0
- package/afm-cc/tsconfig.json +10 -3
- package/afm-jira/tsconfig.json +28 -0
- package/constellation/atlaskit-theme/usage.mdx +17 -17
- package/constellation/convert-props-syntax/usage.mdx +14 -14
- package/constellation/enforce-style-prop/usage.mdx +17 -17
- package/constellation/index/overview.mdx +99 -98
- package/constellation/local-cx-xcss/usage.mdx +4 -4
- package/constellation/no-array-arguments/usage.mdx +7 -7
- package/constellation/no-container-queries/usage.mdx +14 -14
- package/constellation/no-dynamic-styles/usage.mdx +19 -19
- package/constellation/no-exported-styles/usage.mdx +15 -15
- package/constellation/no-global-styles/usage.mdx +13 -13
- package/constellation/no-important-styles/usage.mdx +2 -2
- package/constellation/no-imported-style-values/usage.mdx +16 -16
- package/constellation/no-nested-selectors/usage.mdx +18 -18
- package/constellation/no-styled/usage.mdx +6 -6
- package/constellation/no-unsafe-selectors/usage.mdx +244 -0
- package/constellation/no-unsafe-values/usage.mdx +33 -33
- package/dist/cjs/index.codegen.js +1 -1
- package/dist/cjs/presets/all.codegen.js +2 -1
- package/dist/cjs/presets/recommended.codegen.js +2 -1
- package/dist/cjs/rules/index.codegen.js +3 -1
- package/dist/cjs/rules/no-unsafe-selectors/constants.js +30 -0
- package/dist/cjs/rules/no-unsafe-selectors/index.js +188 -0
- package/dist/cjs/rules/no-unsafe-selectors/lint-selector.js +198 -0
- package/dist/cjs/rules/no-unsafe-selectors/source-position-utils.js +42 -0
- package/dist/cjs/rules/no-unsafe-selectors/walk-css-map.js +186 -0
- package/dist/es2019/index.codegen.js +1 -1
- package/dist/es2019/presets/all.codegen.js +2 -1
- package/dist/es2019/presets/recommended.codegen.js +2 -1
- package/dist/es2019/rules/index.codegen.js +3 -1
- package/dist/es2019/rules/no-unsafe-selectors/constants.js +22 -0
- package/dist/es2019/rules/no-unsafe-selectors/index.js +176 -0
- package/dist/es2019/rules/no-unsafe-selectors/lint-selector.js +161 -0
- package/dist/es2019/rules/no-unsafe-selectors/source-position-utils.js +31 -0
- package/dist/es2019/rules/no-unsafe-selectors/walk-css-map.js +180 -0
- package/dist/esm/index.codegen.js +1 -1
- package/dist/esm/presets/all.codegen.js +2 -1
- package/dist/esm/presets/recommended.codegen.js +2 -1
- package/dist/esm/rules/index.codegen.js +3 -1
- package/dist/esm/rules/no-unsafe-selectors/constants.js +24 -0
- package/dist/esm/rules/no-unsafe-selectors/index.js +181 -0
- package/dist/esm/rules/no-unsafe-selectors/lint-selector.js +191 -0
- package/dist/esm/rules/no-unsafe-selectors/source-position-utils.js +34 -0
- package/dist/esm/rules/no-unsafe-selectors/walk-css-map.js +179 -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/no-unsafe-selectors/constants.d.ts +23 -0
- package/dist/types/rules/no-unsafe-selectors/index.d.ts +3 -0
- package/dist/types/rules/no-unsafe-selectors/lint-selector.d.ts +14 -0
- package/dist/types/rules/no-unsafe-selectors/source-position-utils.d.ts +20 -0
- package/dist/types/rules/no-unsafe-selectors/walk-css-map.d.ts +23 -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/no-unsafe-selectors/constants.d.ts +84 -0
- package/dist/types-ts4.5/rules/no-unsafe-selectors/index.d.ts +3 -0
- package/dist/types-ts4.5/rules/no-unsafe-selectors/lint-selector.d.ts +14 -0
- package/dist/types-ts4.5/rules/no-unsafe-selectors/source-position-utils.d.ts +23 -0
- package/dist/types-ts4.5/rules/no-unsafe-selectors/walk-css-map.d.ts +23 -0
- package/package.json +7 -8
- package/scripts/codegen.tsx +3 -4
- package/src/index.codegen.tsx +3 -3
- package/src/presets/all.codegen.tsx +70 -72
- package/src/presets/recommended.codegen.tsx +70 -72
- package/src/rules/index.codegen.tsx +19 -17
- package/src/rules/no-classname-prop/index.tsx +1 -1
- package/src/rules/no-nested-selectors/index.tsx +1 -1
- package/src/rules/no-unsafe-selectors/README.md +232 -0
- package/src/rules/no-unsafe-selectors/__tests__/no-ambiguous-pseudos.test.tsx +368 -0
- package/src/rules/no-unsafe-selectors/__tests__/no-grouped-at-rules.test.tsx +60 -0
- package/src/rules/no-unsafe-selectors/__tests__/no-increased-specificity.test.tsx +73 -0
- package/src/rules/no-unsafe-selectors/__tests__/no-keyframes-at-rules.test.tsx +40 -0
- package/src/rules/no-unsafe-selectors/__tests__/no-legacy-pseudo-element-syntax.test.tsx +101 -0
- package/src/rules/no-unsafe-selectors/__tests__/no-restricted-at-rules.test.tsx +131 -0
- package/src/rules/no-unsafe-selectors/__tests__/no-restricted-pseudos.test.tsx +132 -0
- package/src/rules/no-unsafe-selectors/__tests__/no-selectors-object.test.tsx +25 -0
- package/src/rules/no-unsafe-selectors/__tests__/no-unparsable-selectors.test.tsx +35 -0
- package/src/rules/no-unsafe-selectors/__tests__/rule.test.tsx +238 -0
- package/src/rules/no-unsafe-selectors/constants.tsx +99 -0
- package/src/rules/no-unsafe-selectors/index.tsx +198 -0
- package/src/rules/no-unsafe-selectors/lint-selector.tsx +155 -0
- package/src/rules/no-unsafe-selectors/source-position-utils.tsx +55 -0
- package/src/rules/no-unsafe-selectors/walk-css-map.tsx +232 -0
- package/tsconfig.app.json +45 -45
- package/tsconfig.dev.json +43 -43
|
@@ -4,9 +4,9 @@ This rule prevents the use of dynamic styles (function expressions) in style dec
|
|
|
4
4
|
|
|
5
5
|
This ensures that style declarations:
|
|
6
6
|
|
|
7
|
-
-
|
|
8
|
-
-
|
|
9
|
-
-
|
|
7
|
+
- are statically analyzable
|
|
8
|
+
- can be efficiently extracted into atomic CSS
|
|
9
|
+
- are more readable, deterministic, and thus easier to maintain
|
|
10
10
|
|
|
11
11
|
## Examples
|
|
12
12
|
|
|
@@ -16,7 +16,7 @@ This ensures that style declarations:
|
|
|
16
16
|
import { styled } from '@compiled/react';
|
|
17
17
|
|
|
18
18
|
const Component = styled.div<{ width: number }>((props) => ({
|
|
19
|
-
|
|
19
|
+
width: props.width,
|
|
20
20
|
}));
|
|
21
21
|
```
|
|
22
22
|
|
|
@@ -24,7 +24,7 @@ const Component = styled.div<{ width: number }>((props) => ({
|
|
|
24
24
|
import styled from 'styled-components';
|
|
25
25
|
|
|
26
26
|
const Component = styled.div<{ width: number }>({
|
|
27
|
-
|
|
27
|
+
width: (props) => props.width,
|
|
28
28
|
});
|
|
29
29
|
```
|
|
30
30
|
|
|
@@ -32,7 +32,7 @@ const Component = styled.div<{ width: number }>({
|
|
|
32
32
|
import styled from 'styled-components';
|
|
33
33
|
|
|
34
34
|
const Container = styled.div<hasPadding>({
|
|
35
|
-
|
|
35
|
+
padding: ({ hasPadding }) => (hasPadding ? token('space.100', '8px') : token('space.0', '0px')),
|
|
36
36
|
});
|
|
37
37
|
```
|
|
38
38
|
|
|
@@ -50,7 +50,7 @@ const baseStyles = css({ padding: token('space.0') });
|
|
|
50
50
|
const hasPaddingStyles = css({ padding: token('space.100') });
|
|
51
51
|
|
|
52
52
|
const Container = ({ hasPadding = false }: { hasPadding?: boolean }) => {
|
|
53
|
-
|
|
53
|
+
return <div css={[baseStyles, hasPadding && hasPaddingStyles]} />;
|
|
54
54
|
};
|
|
55
55
|
```
|
|
56
56
|
|
|
@@ -89,7 +89,7 @@ This approach should be used as a last resort.
|
|
|
89
89
|
import { css } from '@compiled/react';
|
|
90
90
|
|
|
91
91
|
const Component = ({ width }: { width: number }) => {
|
|
92
|
-
|
|
92
|
+
return <div style={{ width }} />;
|
|
93
93
|
};
|
|
94
94
|
```
|
|
95
95
|
|
|
@@ -97,13 +97,13 @@ const Component = ({ width }: { width: number }) => {
|
|
|
97
97
|
import { css } from '@compiled/react';
|
|
98
98
|
|
|
99
99
|
const containerStyles = css({
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
100
|
+
'::before': {
|
|
101
|
+
width: 'var(--ak-example-width)',
|
|
102
|
+
},
|
|
103
103
|
});
|
|
104
104
|
|
|
105
105
|
function Example({ width }: { width: number }) {
|
|
106
|
-
|
|
106
|
+
return <div css={containerStyles} style={{ '--ak-example-width': `${width}px` }} />;
|
|
107
107
|
}
|
|
108
108
|
```
|
|
109
109
|
|
|
@@ -113,13 +113,13 @@ function Example({ width }: { width: number }) {
|
|
|
113
113
|
|
|
114
114
|
By default, this rule will check usages from:
|
|
115
115
|
|
|
116
|
-
-
|
|
117
|
-
-
|
|
118
|
-
-
|
|
119
|
-
-
|
|
120
|
-
-
|
|
121
|
-
-
|
|
122
|
-
-
|
|
116
|
+
- `@atlaskit/css`
|
|
117
|
+
- `@atlaskit/primitives`
|
|
118
|
+
- `@compiled/react`
|
|
119
|
+
- `@emotion/react`
|
|
120
|
+
- `@emotion/core`
|
|
121
|
+
- `@emotion/styled`
|
|
122
|
+
- `styled-components`
|
|
123
123
|
|
|
124
124
|
To change this list of libraries, you can define a custom set of `importSources`, which accepts an
|
|
125
125
|
array of package names (strings).
|
|
@@ -31,8 +31,8 @@ Avoid exporting any style-like objects or values for consumption as well as thes
|
|
|
31
31
|
|
|
32
32
|
```js
|
|
33
33
|
export default {
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
color: 'red',
|
|
35
|
+
margin: '0px',
|
|
36
36
|
};
|
|
37
37
|
```
|
|
38
38
|
|
|
@@ -40,15 +40,15 @@ export default {
|
|
|
40
40
|
import { css } from '@compiled/react';
|
|
41
41
|
|
|
42
42
|
const color = css({
|
|
43
|
-
|
|
43
|
+
/* */
|
|
44
44
|
});
|
|
45
45
|
|
|
46
46
|
const styles = {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
47
|
+
primary: {
|
|
48
|
+
text: {
|
|
49
|
+
color,
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
52
|
};
|
|
53
53
|
|
|
54
54
|
export default styles.primary.text.color;
|
|
@@ -80,13 +80,13 @@ export const Component = ({ children }) => <div css={styles}>{children}></div>;
|
|
|
80
80
|
|
|
81
81
|
By default, this rule will check `css` usages from:
|
|
82
82
|
|
|
83
|
-
-
|
|
84
|
-
-
|
|
85
|
-
-
|
|
86
|
-
-
|
|
87
|
-
-
|
|
88
|
-
-
|
|
89
|
-
-
|
|
83
|
+
- `@atlaskit/css`
|
|
84
|
+
- `@atlaskit/primitives`
|
|
85
|
+
- `@compiled/react`
|
|
86
|
+
- `@emotion/react`
|
|
87
|
+
- `@emotion/core`
|
|
88
|
+
- `@emotion/styled`
|
|
89
|
+
- `styled-components`
|
|
90
90
|
|
|
91
91
|
To change this list of libraries, you can define a custom set of `importSources`, which accepts an
|
|
92
92
|
array of package names (strings).
|
|
@@ -13,12 +13,12 @@ resolvable.
|
|
|
13
13
|
import { Global } from '@emotion/react';
|
|
14
14
|
|
|
15
15
|
<Global
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
16
|
+
styles={{
|
|
17
|
+
'.some-class': {
|
|
18
|
+
fontSize: 50,
|
|
19
|
+
textAlign: 'center',
|
|
20
|
+
},
|
|
21
|
+
}}
|
|
22
22
|
/>;
|
|
23
23
|
```
|
|
24
24
|
|
|
@@ -26,9 +26,9 @@ import { Global } from '@emotion/react';
|
|
|
26
26
|
import { createGlobalStyle } from 'styled-components';
|
|
27
27
|
|
|
28
28
|
const GlobalStyle = createGlobalStyle({
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
body: {
|
|
30
|
+
margin: 0,
|
|
31
|
+
},
|
|
32
32
|
});
|
|
33
33
|
```
|
|
34
34
|
|
|
@@ -36,15 +36,15 @@ const GlobalStyle = createGlobalStyle({
|
|
|
36
36
|
import { injectGlobal } from 'styled-components';
|
|
37
37
|
|
|
38
38
|
injectGlobal({
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
39
|
+
body: {
|
|
40
|
+
margin: 0,
|
|
41
|
+
},
|
|
42
42
|
});
|
|
43
43
|
```
|
|
44
44
|
|
|
45
45
|
```tsx
|
|
46
46
|
<style>
|
|
47
|
-
|
|
47
|
+
{`
|
|
48
48
|
.some-class {
|
|
49
49
|
color: red;
|
|
50
50
|
}
|
|
@@ -16,7 +16,7 @@ The use of `!important` is a code smell and greatly impacts readability and dete
|
|
|
16
16
|
import { css } from '@compiled/react';
|
|
17
17
|
|
|
18
18
|
const styles = css({
|
|
19
|
-
|
|
19
|
+
color: 'red!important',
|
|
20
20
|
});
|
|
21
21
|
```
|
|
22
22
|
|
|
@@ -26,6 +26,6 @@ const styles = css({
|
|
|
26
26
|
import { css } from '@compiled/react';
|
|
27
27
|
|
|
28
28
|
const styles = css({
|
|
29
|
-
|
|
29
|
+
color: 'red',
|
|
30
30
|
});
|
|
31
31
|
```
|
|
@@ -17,8 +17,8 @@ import { css } from '@compiled/react';
|
|
|
17
17
|
import { colors, getColor } from '@mui/theme';
|
|
18
18
|
|
|
19
19
|
const styles = css({
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
[colorKey]: getColor('red'),
|
|
21
|
+
background: colors['red'],
|
|
22
22
|
});
|
|
23
23
|
```
|
|
24
24
|
|
|
@@ -30,10 +30,10 @@ import { ff } from '@atlaskit/ff';
|
|
|
30
30
|
const sharedObject = { padding: 0 };
|
|
31
31
|
|
|
32
32
|
const styles = css({
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
...cssShared,
|
|
34
|
+
...sharedObject,
|
|
35
|
+
height: `${HEIGHT}px`,
|
|
36
|
+
width: ff('…') ? `${HEIGHT}px` : undefined,
|
|
37
37
|
});
|
|
38
38
|
```
|
|
39
39
|
|
|
@@ -44,7 +44,7 @@ import { css } from '@compiled/react';
|
|
|
44
44
|
import { buttonStyles } from '../shared';
|
|
45
45
|
|
|
46
46
|
const styles = css({
|
|
47
|
-
|
|
47
|
+
color: 'red',
|
|
48
48
|
});
|
|
49
49
|
|
|
50
50
|
export default () => <div css={[styles, buttonStyles]} />;
|
|
@@ -68,8 +68,8 @@ import { css } from '@compiled/react';
|
|
|
68
68
|
import { token } from '@atlaskit/tokens';
|
|
69
69
|
|
|
70
70
|
const styles = css({
|
|
71
|
-
|
|
72
|
-
|
|
71
|
+
color: 'red',
|
|
72
|
+
padding: token('space.150'),
|
|
73
73
|
});
|
|
74
74
|
export const Component = ({ children }) => <div css={styles}>{children}></div>;
|
|
75
75
|
```
|
|
@@ -142,13 +142,13 @@ Default imports are not currently supported.
|
|
|
142
142
|
|
|
143
143
|
By default, this rule will check `css` usages from:
|
|
144
144
|
|
|
145
|
-
-
|
|
146
|
-
-
|
|
147
|
-
-
|
|
148
|
-
-
|
|
149
|
-
-
|
|
150
|
-
-
|
|
151
|
-
-
|
|
145
|
+
- `@atlaskit/css`
|
|
146
|
+
- `@atlaskit/primitives`
|
|
147
|
+
- `@compiled/react`
|
|
148
|
+
- `@emotion/react`
|
|
149
|
+
- `@emotion/core`
|
|
150
|
+
- `@emotion/styled`
|
|
151
|
+
- `styled-components`
|
|
152
152
|
|
|
153
153
|
To change this list of libraries, you can define a custom set of `importSources`, which accepts an
|
|
154
154
|
array of package names (strings).
|
|
@@ -10,27 +10,27 @@ any child elements or elements that require context from other elements.
|
|
|
10
10
|
```js
|
|
11
11
|
import { css } from '@compiled/react';
|
|
12
12
|
const styles = css({
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
h2: {
|
|
14
|
+
fontSize: '1.5rem',
|
|
15
|
+
},
|
|
16
16
|
});
|
|
17
17
|
```
|
|
18
18
|
|
|
19
19
|
```js
|
|
20
20
|
import { styled } from '@compiled/react';
|
|
21
21
|
const Component = styled.div({
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
'*': {
|
|
23
|
+
padding: 0,
|
|
24
|
+
},
|
|
25
25
|
});
|
|
26
26
|
```
|
|
27
27
|
|
|
28
28
|
```js
|
|
29
29
|
import { styled } from '@compiled/react';
|
|
30
30
|
const Component = styled.div({
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
'.myclass': {
|
|
32
|
+
padding: 0,
|
|
33
|
+
},
|
|
34
34
|
});
|
|
35
35
|
```
|
|
36
36
|
|
|
@@ -39,8 +39,8 @@ const Component = styled.div({
|
|
|
39
39
|
```js
|
|
40
40
|
import { css } from '@compiled/react';
|
|
41
41
|
const styles = css({
|
|
42
|
-
|
|
43
|
-
|
|
42
|
+
display: 'flex',
|
|
43
|
+
flexDirection: 'column',
|
|
44
44
|
});
|
|
45
45
|
```
|
|
46
46
|
|
|
@@ -50,13 +50,13 @@ const styles = css({
|
|
|
50
50
|
|
|
51
51
|
By default, this rule will check `css` usages from:
|
|
52
52
|
|
|
53
|
-
-
|
|
54
|
-
-
|
|
55
|
-
-
|
|
56
|
-
-
|
|
57
|
-
-
|
|
58
|
-
-
|
|
59
|
-
-
|
|
53
|
+
- `@atlaskit/css`
|
|
54
|
+
- `@atlaskit/primitives`
|
|
55
|
+
- `@compiled/react`
|
|
56
|
+
- `@emotion/react`
|
|
57
|
+
- `@emotion/core`
|
|
58
|
+
- `@emotion/styled`
|
|
59
|
+
- `styled-components`
|
|
60
60
|
|
|
61
61
|
To change this list of libraries, you can define a custom set of `importSources`, which accepts an
|
|
62
62
|
array of package names (strings).
|
|
@@ -12,7 +12,7 @@ Avoid usages of styled, eg. `styled.div`, `styled('div')`, `styled(Component)`,
|
|
|
12
12
|
import styled from 'styled-components';
|
|
13
13
|
|
|
14
14
|
const Component = styled.div`
|
|
15
|
-
|
|
15
|
+
color: red;
|
|
16
16
|
`;
|
|
17
17
|
export default styled.div({ color: 'red' });
|
|
18
18
|
```
|
|
@@ -35,7 +35,7 @@ export const ComponentTwo = styled3(Component)({ … });
|
|
|
35
35
|
import styled from 'styled-components';
|
|
36
36
|
|
|
37
37
|
export default styled.div.attrs((props) => ({ 'data-testid': props.testId }))({
|
|
38
|
-
|
|
38
|
+
color: 'red',
|
|
39
39
|
});
|
|
40
40
|
```
|
|
41
41
|
|
|
@@ -43,7 +43,7 @@ export default styled.div.attrs((props) => ({ 'data-testid': props.testId }))({
|
|
|
43
43
|
import styled from 'styled-components';
|
|
44
44
|
|
|
45
45
|
export default styled.div.attrs((props) => ({ 'data-testid': props.testId }))`
|
|
46
|
-
|
|
46
|
+
color: red;
|
|
47
47
|
`;
|
|
48
48
|
```
|
|
49
49
|
|
|
@@ -55,7 +55,7 @@ import { css, jsx } from '@emotion/react';
|
|
|
55
55
|
const styles = css({ color: 'red' });
|
|
56
56
|
|
|
57
57
|
const Component = ({ children }) => {
|
|
58
|
-
|
|
58
|
+
return <div css={styles}>{children}</div>;
|
|
59
59
|
};
|
|
60
60
|
```
|
|
61
61
|
|
|
@@ -64,11 +64,11 @@ const Component = ({ children }) => {
|
|
|
64
64
|
import { Box, xcss } from '@atlaskit/primitives';
|
|
65
65
|
|
|
66
66
|
const styles = xcss({
|
|
67
|
-
|
|
67
|
+
color: 'color.text.subtlest',
|
|
68
68
|
});
|
|
69
69
|
|
|
70
70
|
const Component = ({ children }) => {
|
|
71
|
-
|
|
71
|
+
return <Box xcss={styles}>{children}</Box>;
|
|
72
72
|
};
|
|
73
73
|
```
|
|
74
74
|
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
# no-unsafe-selectors
|
|
2
|
+
|
|
3
|
+
Disallows unsafe selectors in CSS-in-JS style objects.
|
|
4
|
+
|
|
5
|
+
This enables static analysis and prevents regressions and incidents when migrating between styling
|
|
6
|
+
APIs.
|
|
7
|
+
|
|
8
|
+
Use this rule alongside
|
|
9
|
+
[no-nested-selectors](https://atlassian.design/components/eslint-plugin-ui-styling-standard/no-nested-selectors/usage)
|
|
10
|
+
as the rules are complementary.
|
|
11
|
+
|
|
12
|
+
## Examples
|
|
13
|
+
|
|
14
|
+
### Incorrect
|
|
15
|
+
|
|
16
|
+
**No @keyframes at-rules**
|
|
17
|
+
|
|
18
|
+
Use the `keyframes` CSS-in-JS API instead.
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
css({
|
|
22
|
+
'@keyframes fadeIn': {
|
|
23
|
+
from: {
|
|
24
|
+
opacity: 0,
|
|
25
|
+
},
|
|
26
|
+
to: {
|
|
27
|
+
opacity: 1,
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
**No legacy pseudo-element syntax**
|
|
34
|
+
|
|
35
|
+
Use the `::` double colon syntax for pseudo-elements.
|
|
36
|
+
|
|
37
|
+
_Auto-fixer is available for this violation._
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
css({
|
|
41
|
+
':after': {
|
|
42
|
+
content: '""',
|
|
43
|
+
width: 100,
|
|
44
|
+
height: 100,
|
|
45
|
+
backgroundColor: 'red',
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
**No increased specificity selectors**
|
|
51
|
+
|
|
52
|
+
Use styles that do not require increased specificity.
|
|
53
|
+
|
|
54
|
+
```ts
|
|
55
|
+
css({
|
|
56
|
+
'&&': {
|
|
57
|
+
color: 'red',
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
**No restricted at-rules**
|
|
63
|
+
|
|
64
|
+
```ts
|
|
65
|
+
css({
|
|
66
|
+
'@scope (.article-body) to (figure)': {
|
|
67
|
+
img: {
|
|
68
|
+
display: 'block',
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
**No restricted pseudos**
|
|
75
|
+
|
|
76
|
+
```ts
|
|
77
|
+
css({
|
|
78
|
+
'&:first-child': {
|
|
79
|
+
width: 100,
|
|
80
|
+
},
|
|
81
|
+
});
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
**No ambiguous pseudos**
|
|
85
|
+
|
|
86
|
+
A pseudo-selector without a leading selector is ambiguous and is interpreted differently between
|
|
87
|
+
contexts.
|
|
88
|
+
|
|
89
|
+
Most CSS-in-JS libraries will implicitly add the nesting selector `&` before ambiguous
|
|
90
|
+
pseudo-selectors. This is often the desired behavior.
|
|
91
|
+
|
|
92
|
+
The CSS nesting specification, CSS pre-processors, newer versions of `styled-components` (version
|
|
93
|
+
6+) and potentially future versions of `@emotion/*` will treat ambiguous pseudo-selectors as
|
|
94
|
+
descendant selectors.
|
|
95
|
+
|
|
96
|
+
Use explicit selectors. Do not rely on implicit behavior for pseudo-selectors.
|
|
97
|
+
|
|
98
|
+
_Auto-fixer is available for this violation. By default a nesting selector `&` is added unless the
|
|
99
|
+
`shouldAlwaysInsertNestingSelectorForAmbiguousPseudos` option is disabled._
|
|
100
|
+
|
|
101
|
+
```ts
|
|
102
|
+
css({
|
|
103
|
+
/**
|
|
104
|
+
* This pseudo-class has no leading selector and is ambiguous.
|
|
105
|
+
*/
|
|
106
|
+
':hover': {},
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* In some contexts the above is treated as implicitly containing a nesting selector.
|
|
110
|
+
*/
|
|
111
|
+
'&:hover': {},
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* In other contexts it is treated as a descendant selector.
|
|
115
|
+
*
|
|
116
|
+
* (The selectors below are equivalent.)
|
|
117
|
+
*/
|
|
118
|
+
'*:hover': {},
|
|
119
|
+
'& :hover': {},
|
|
120
|
+
'& *:hover': {},
|
|
121
|
+
});
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
**No grouped at-rules**
|
|
125
|
+
|
|
126
|
+
Do not group at-rules with the `cssMap` API.
|
|
127
|
+
|
|
128
|
+
Write flattened at-rules instead.
|
|
129
|
+
|
|
130
|
+
```ts
|
|
131
|
+
cssMap({
|
|
132
|
+
success: {
|
|
133
|
+
'@media': {
|
|
134
|
+
'(min-width: 900px)': {},
|
|
135
|
+
'(min-width: 1200px)': {},
|
|
136
|
+
},
|
|
137
|
+
},
|
|
138
|
+
});
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
**No selectors object**
|
|
142
|
+
|
|
143
|
+
Do not use a selectors object with the `cssMap` API.
|
|
144
|
+
|
|
145
|
+
Refactor your styles so it is not required.
|
|
146
|
+
|
|
147
|
+
```ts
|
|
148
|
+
cssMap({
|
|
149
|
+
success: {
|
|
150
|
+
selectors: {
|
|
151
|
+
'&:not(:active)': {
|
|
152
|
+
backgroundColor: 'white',
|
|
153
|
+
},
|
|
154
|
+
},
|
|
155
|
+
},
|
|
156
|
+
});
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
### Correct
|
|
160
|
+
|
|
161
|
+
```ts
|
|
162
|
+
const fadeIn = keyframes({
|
|
163
|
+
from: {
|
|
164
|
+
opacity: 0,
|
|
165
|
+
},
|
|
166
|
+
to: {
|
|
167
|
+
opacity: 1,
|
|
168
|
+
},
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
css({
|
|
172
|
+
animationName: fadeIn,
|
|
173
|
+
});
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
```ts
|
|
177
|
+
css({
|
|
178
|
+
'::after': {
|
|
179
|
+
content: '""',
|
|
180
|
+
width: 100,
|
|
181
|
+
height: 100,
|
|
182
|
+
backgroundColor: 'red',
|
|
183
|
+
},
|
|
184
|
+
});
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
```ts
|
|
188
|
+
css({
|
|
189
|
+
'&:first-of-type': {
|
|
190
|
+
width: 100,
|
|
191
|
+
},
|
|
192
|
+
});
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
```ts
|
|
196
|
+
css({
|
|
197
|
+
'&:hover': {},
|
|
198
|
+
});
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
```ts
|
|
202
|
+
cssMap({
|
|
203
|
+
success: {
|
|
204
|
+
'@media (min-width: 900px)': {},
|
|
205
|
+
'@media (min-width: 1200px)': {},
|
|
206
|
+
},
|
|
207
|
+
});
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
```ts
|
|
211
|
+
cssMap({
|
|
212
|
+
success: {
|
|
213
|
+
backgroundColor: 'white',
|
|
214
|
+
'&:active': {
|
|
215
|
+
backgroundColor: 'green',
|
|
216
|
+
},
|
|
217
|
+
},
|
|
218
|
+
});
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
## Options
|
|
222
|
+
|
|
223
|
+
### `importSources: string[]`
|
|
224
|
+
|
|
225
|
+
By default, this rule will check `css` usages from:
|
|
226
|
+
|
|
227
|
+
- `@atlaskit/css`
|
|
228
|
+
- `@atlaskit/primitives`
|
|
229
|
+
- `@compiled/react`
|
|
230
|
+
- `@emotion/react`
|
|
231
|
+
- `@emotion/core`
|
|
232
|
+
- `@emotion/styled`
|
|
233
|
+
- `styled-components`
|
|
234
|
+
|
|
235
|
+
To change this list of libraries, you can define a custom set of `importSources`, which accepts an
|
|
236
|
+
array of package names (strings). This will override the built-in allow-list.
|
|
237
|
+
|
|
238
|
+
### `shouldAlwaysInsertNestingSelectorForAmbiguousPseudos: boolean`
|
|
239
|
+
|
|
240
|
+
By default this rule will always fix ambiguous pseudo-selectors by inserting a leading `&` (nesting
|
|
241
|
+
selector).
|
|
242
|
+
|
|
243
|
+
Set `shouldAlwaysInsertNestingSelectorForAmbiguousPseudos` to `false` to disable this auto-fix. When
|
|
244
|
+
disabled, a suggestion will be provided instead of an auto-fix.
|