@atlaskit/eslint-plugin-ui-styling-standard 0.14.1 → 0.15.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 +22 -0
- package/README.md +1 -0
- package/afm-cc/tsconfig.json +10 -3
- package/afm-jira/tsconfig.json +28 -0
- package/constellation/index/overview.mdx +29 -28
- package/constellation/no-unsafe-selectors/usage.mdx +244 -0
- package/dist/cjs/presets/all.codegen.js +2 -1
- package/dist/cjs/presets/recommended.codegen.js +2 -1
- package/dist/cjs/rules/atlaskit-theme/index.js +10 -4
- 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 +185 -0
- package/dist/cjs/rules/no-unsafe-selectors/lint-selector.js +189 -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/presets/all.codegen.js +2 -1
- package/dist/es2019/presets/recommended.codegen.js +2 -1
- package/dist/es2019/rules/atlaskit-theme/index.js +10 -4
- 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 +173 -0
- package/dist/es2019/rules/no-unsafe-selectors/lint-selector.js +152 -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/presets/all.codegen.js +2 -1
- package/dist/esm/presets/recommended.codegen.js +2 -1
- package/dist/esm/rules/atlaskit-theme/index.js +10 -4
- 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 +178 -0
- package/dist/esm/rules/no-unsafe-selectors/lint-selector.js +182 -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 +13 -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 +13 -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 +6 -5
- package/scripts/codegen.tsx +3 -4
- package/src/presets/all.codegen.tsx +2 -1
- package/src/presets/recommended.codegen.tsx +2 -1
- package/src/rules/atlaskit-theme/__tests__/test.ts +11 -0
- package/src/rules/atlaskit-theme/index.ts +10 -4
- package/src/rules/index.codegen.tsx +3 -1
- 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 +358 -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 +201 -0
- package/src/rules/no-unsafe-selectors/lint-selector.tsx +168 -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
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { tester } from '../../__tests__/utils/_tester';
|
|
2
|
+
import rule from '../index';
|
|
3
|
+
|
|
4
|
+
tester.run('no-restricted-at-rules', rule, {
|
|
5
|
+
valid: [
|
|
6
|
+
{
|
|
7
|
+
name: '@media',
|
|
8
|
+
code: `
|
|
9
|
+
import { css } from '@compiled/react';
|
|
10
|
+
|
|
11
|
+
css({
|
|
12
|
+
'@media screen and (min-width: 900px)': {}
|
|
13
|
+
});
|
|
14
|
+
`,
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
name: '@media in cssMap',
|
|
18
|
+
code: `
|
|
19
|
+
import { cssMap } from '@compiled/react';
|
|
20
|
+
|
|
21
|
+
const myMap = cssMap({
|
|
22
|
+
danger: {
|
|
23
|
+
color: 'red',
|
|
24
|
+
'@media (min-width: 500px)': {
|
|
25
|
+
fontSize: '1.5em',
|
|
26
|
+
},
|
|
27
|
+
'@media (max-width: 800px)': {
|
|
28
|
+
fontSize: '1.8em',
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
`,
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
name: 'no space after rule name',
|
|
36
|
+
code: `
|
|
37
|
+
import { css } from '@compiled/react';
|
|
38
|
+
|
|
39
|
+
css({
|
|
40
|
+
'@supports(display: flex)': {}
|
|
41
|
+
});
|
|
42
|
+
`,
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
name: '@supports',
|
|
46
|
+
code: `
|
|
47
|
+
import { css } from '@compiled/react';
|
|
48
|
+
|
|
49
|
+
css({
|
|
50
|
+
'@supports (display: flex)': {}
|
|
51
|
+
});
|
|
52
|
+
`,
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
name: '@container',
|
|
56
|
+
code: `
|
|
57
|
+
import { css } from '@compiled/react';
|
|
58
|
+
|
|
59
|
+
css({
|
|
60
|
+
'@container (width > 400px)': {}
|
|
61
|
+
});
|
|
62
|
+
`,
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
name: '@property',
|
|
66
|
+
code: `
|
|
67
|
+
import { css } from '@compiled/react';
|
|
68
|
+
|
|
69
|
+
css({
|
|
70
|
+
'@property --property-name': {
|
|
71
|
+
syntax: '"<color>"',
|
|
72
|
+
inherits: 'false',
|
|
73
|
+
initialValue: '#c0ffee',
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
`,
|
|
77
|
+
},
|
|
78
|
+
],
|
|
79
|
+
invalid: [
|
|
80
|
+
{
|
|
81
|
+
name: '@color-profile',
|
|
82
|
+
code: `
|
|
83
|
+
import { css } from '@compiled/react';
|
|
84
|
+
|
|
85
|
+
css({
|
|
86
|
+
'@color-profile --swop5c': {}
|
|
87
|
+
});
|
|
88
|
+
`,
|
|
89
|
+
errors: [
|
|
90
|
+
{
|
|
91
|
+
messageId: 'no-restricted-at-rules',
|
|
92
|
+
data: { atRule: '@color-profile' },
|
|
93
|
+
},
|
|
94
|
+
],
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
name: '@scope',
|
|
98
|
+
code: `
|
|
99
|
+
import { css } from '@compiled/react';
|
|
100
|
+
|
|
101
|
+
css({
|
|
102
|
+
'@scope (.article-body) to (figure)': {}
|
|
103
|
+
});
|
|
104
|
+
`,
|
|
105
|
+
errors: [
|
|
106
|
+
{
|
|
107
|
+
messageId: 'no-restricted-at-rules',
|
|
108
|
+
data: { atRule: '@scope' },
|
|
109
|
+
},
|
|
110
|
+
],
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
name: '@scope in cssMap',
|
|
114
|
+
code: `
|
|
115
|
+
import { cssMap } from '@compiled/react';
|
|
116
|
+
|
|
117
|
+
cssMap({
|
|
118
|
+
base: {
|
|
119
|
+
'@scope (.article-body) to (figure)': {}
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
`,
|
|
123
|
+
errors: [
|
|
124
|
+
{
|
|
125
|
+
messageId: 'no-restricted-at-rules',
|
|
126
|
+
data: { atRule: '@scope' },
|
|
127
|
+
},
|
|
128
|
+
],
|
|
129
|
+
},
|
|
130
|
+
],
|
|
131
|
+
});
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { tester } from '../../__tests__/utils/_tester';
|
|
2
|
+
import rule from '../index';
|
|
3
|
+
|
|
4
|
+
tester.run('no-restricted-pseudos', rule, {
|
|
5
|
+
valid: [
|
|
6
|
+
{
|
|
7
|
+
name: ':hover',
|
|
8
|
+
code: `
|
|
9
|
+
import { css } from '@compiled/react';
|
|
10
|
+
|
|
11
|
+
css({
|
|
12
|
+
'&:hover': {}
|
|
13
|
+
});
|
|
14
|
+
`,
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
name: ':active',
|
|
18
|
+
code: `
|
|
19
|
+
import { css } from '@compiled/react';
|
|
20
|
+
|
|
21
|
+
css({
|
|
22
|
+
'&:active': {}
|
|
23
|
+
});
|
|
24
|
+
`,
|
|
25
|
+
},
|
|
26
|
+
],
|
|
27
|
+
invalid: [
|
|
28
|
+
{
|
|
29
|
+
name: ':has()',
|
|
30
|
+
code: `
|
|
31
|
+
import { css } from '@compiled/react';
|
|
32
|
+
|
|
33
|
+
css({
|
|
34
|
+
'&:has(div)': {},
|
|
35
|
+
});
|
|
36
|
+
`,
|
|
37
|
+
errors: [
|
|
38
|
+
{
|
|
39
|
+
messageId: 'no-restricted-pseudos',
|
|
40
|
+
line: 5,
|
|
41
|
+
column: 13,
|
|
42
|
+
endColumn: 17,
|
|
43
|
+
data: { pseudo: ':has' },
|
|
44
|
+
},
|
|
45
|
+
],
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
name: ':first-child',
|
|
49
|
+
code: `
|
|
50
|
+
import { css } from '@compiled/react';
|
|
51
|
+
|
|
52
|
+
css({
|
|
53
|
+
'&:first-child': {},
|
|
54
|
+
});
|
|
55
|
+
`,
|
|
56
|
+
errors: [
|
|
57
|
+
{
|
|
58
|
+
messageId: 'no-restricted-pseudos',
|
|
59
|
+
line: 5,
|
|
60
|
+
column: 13,
|
|
61
|
+
endColumn: 25,
|
|
62
|
+
data: {
|
|
63
|
+
pseudo: ':first-child',
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
],
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
name: ':first-of-type',
|
|
70
|
+
code: `
|
|
71
|
+
import { css } from '@compiled/react';
|
|
72
|
+
|
|
73
|
+
css({
|
|
74
|
+
'&:first-of-type': {},
|
|
75
|
+
});
|
|
76
|
+
`,
|
|
77
|
+
errors: [
|
|
78
|
+
{
|
|
79
|
+
messageId: 'no-restricted-pseudos',
|
|
80
|
+
line: 5,
|
|
81
|
+
column: 13,
|
|
82
|
+
endColumn: 27,
|
|
83
|
+
data: {
|
|
84
|
+
pseudo: ':first-of-type',
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
],
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
name: ':nth-child(2)',
|
|
91
|
+
code: `
|
|
92
|
+
import { css } from '@compiled/react';
|
|
93
|
+
|
|
94
|
+
css({
|
|
95
|
+
'&:nth-child(2)': {},
|
|
96
|
+
});
|
|
97
|
+
`,
|
|
98
|
+
errors: [
|
|
99
|
+
{
|
|
100
|
+
messageId: 'no-restricted-pseudos',
|
|
101
|
+
line: 5,
|
|
102
|
+
column: 13,
|
|
103
|
+
endColumn: 23,
|
|
104
|
+
data: {
|
|
105
|
+
pseudo: ':nth-child',
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
],
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
name: 'compound selector with child selectors',
|
|
112
|
+
code: `
|
|
113
|
+
import { css } from '@compiled/react';
|
|
114
|
+
|
|
115
|
+
css({
|
|
116
|
+
'&:hover:first-child:active': {},
|
|
117
|
+
});
|
|
118
|
+
`,
|
|
119
|
+
errors: [
|
|
120
|
+
{
|
|
121
|
+
messageId: 'no-restricted-pseudos',
|
|
122
|
+
line: 5,
|
|
123
|
+
column: 19,
|
|
124
|
+
endColumn: 31,
|
|
125
|
+
data: {
|
|
126
|
+
pseudo: ':first-child',
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
],
|
|
130
|
+
},
|
|
131
|
+
],
|
|
132
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { tester } from '../../__tests__/utils/_tester';
|
|
2
|
+
import rule from '../index';
|
|
3
|
+
|
|
4
|
+
tester.run('no-selectors-object', rule, {
|
|
5
|
+
valid: [],
|
|
6
|
+
invalid: [
|
|
7
|
+
{
|
|
8
|
+
name: 'selectors object is provided',
|
|
9
|
+
code: `
|
|
10
|
+
import { cssMap } from '@compiled/react';
|
|
11
|
+
|
|
12
|
+
cssMap({
|
|
13
|
+
variant: {
|
|
14
|
+
selectors: {}
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
`,
|
|
18
|
+
errors: [
|
|
19
|
+
{
|
|
20
|
+
messageId: 'no-selectors-object',
|
|
21
|
+
},
|
|
22
|
+
],
|
|
23
|
+
},
|
|
24
|
+
],
|
|
25
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { tester } from '../../__tests__/utils/_tester';
|
|
2
|
+
import rule from '../index';
|
|
3
|
+
|
|
4
|
+
tester.run('no-unparsable-selectors', rule, {
|
|
5
|
+
valid: [],
|
|
6
|
+
invalid: [
|
|
7
|
+
{
|
|
8
|
+
name: 'unparsable selectors',
|
|
9
|
+
code: `
|
|
10
|
+
import { css } from '@emotion/react';
|
|
11
|
+
|
|
12
|
+
css({
|
|
13
|
+
'[&]': {},
|
|
14
|
+
':name:': {},
|
|
15
|
+
});
|
|
16
|
+
`,
|
|
17
|
+
errors: [
|
|
18
|
+
{
|
|
19
|
+
messageId: 'no-unparsable-selectors',
|
|
20
|
+
data: { selectorText: '[&]' },
|
|
21
|
+
line: 5,
|
|
22
|
+
column: 11,
|
|
23
|
+
endColumn: 16,
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
messageId: 'no-unparsable-selectors',
|
|
27
|
+
data: { selectorText: ':name:' },
|
|
28
|
+
line: 6,
|
|
29
|
+
column: 11,
|
|
30
|
+
endColumn: 19,
|
|
31
|
+
},
|
|
32
|
+
],
|
|
33
|
+
},
|
|
34
|
+
],
|
|
35
|
+
});
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
import outdent from 'outdent';
|
|
2
|
+
import { tester } from '../../__tests__/utils/_tester';
|
|
3
|
+
import rule from '../index';
|
|
4
|
+
|
|
5
|
+
tester.run('no-unsafe-selectors', rule, {
|
|
6
|
+
valid: [
|
|
7
|
+
{
|
|
8
|
+
name: 'css API valid usage',
|
|
9
|
+
code: `
|
|
10
|
+
import { css } from '@compiled/react';
|
|
11
|
+
|
|
12
|
+
css({
|
|
13
|
+
'&:hover': {},
|
|
14
|
+
'&:focus, &:active': {},
|
|
15
|
+
});
|
|
16
|
+
`,
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
name: 'styled API valid usage',
|
|
20
|
+
code: `
|
|
21
|
+
import { styled } from '@compiled/react';
|
|
22
|
+
|
|
23
|
+
styled.div({
|
|
24
|
+
'&:hover': {},
|
|
25
|
+
'&:focus, &:active': {},
|
|
26
|
+
});
|
|
27
|
+
`,
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
name: 'keyframes API valid usage',
|
|
31
|
+
code: `
|
|
32
|
+
import { keyframes } from '@compiled/react';
|
|
33
|
+
|
|
34
|
+
keyframes({
|
|
35
|
+
'0%': {
|
|
36
|
+
'&:hover': {},
|
|
37
|
+
'&:focus, &:active': {},
|
|
38
|
+
},
|
|
39
|
+
'100%': {
|
|
40
|
+
'&:hover': {},
|
|
41
|
+
'&:focus, &:active': {},
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
`,
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
name: 'xcss API valid usage',
|
|
48
|
+
code: `
|
|
49
|
+
import { xcss } from '@atlaskit/primitives';
|
|
50
|
+
|
|
51
|
+
xcss({
|
|
52
|
+
'&:hover': {},
|
|
53
|
+
});
|
|
54
|
+
`,
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
name: 'cssMap API valid usage',
|
|
58
|
+
code: `
|
|
59
|
+
import { cssMap } from '@atlaskit/primitives';
|
|
60
|
+
|
|
61
|
+
cssMap({
|
|
62
|
+
':name:': {
|
|
63
|
+
'&:hover': {},
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
`,
|
|
67
|
+
},
|
|
68
|
+
],
|
|
69
|
+
invalid: [
|
|
70
|
+
{
|
|
71
|
+
name: 'css API invalid usage',
|
|
72
|
+
code: outdent`
|
|
73
|
+
import { css } from '@compiled/react';
|
|
74
|
+
|
|
75
|
+
css({
|
|
76
|
+
':hover': {},
|
|
77
|
+
'&:after': {},
|
|
78
|
+
});
|
|
79
|
+
`,
|
|
80
|
+
output: outdent`
|
|
81
|
+
import { css } from '@compiled/react';
|
|
82
|
+
|
|
83
|
+
css({
|
|
84
|
+
'&:hover': {},
|
|
85
|
+
'&::after': {},
|
|
86
|
+
});
|
|
87
|
+
`,
|
|
88
|
+
errors: [
|
|
89
|
+
{
|
|
90
|
+
messageId: 'no-ambiguous-pseudos',
|
|
91
|
+
line: 4,
|
|
92
|
+
column: 4,
|
|
93
|
+
endColumn: 10,
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
messageId: 'no-legacy-pseudo-element-syntax',
|
|
97
|
+
line: 5,
|
|
98
|
+
column: 5,
|
|
99
|
+
endColumn: 11,
|
|
100
|
+
},
|
|
101
|
+
],
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
name: 'styled API invalid usage',
|
|
105
|
+
code: `
|
|
106
|
+
import { styled } from '@compiled/react';
|
|
107
|
+
|
|
108
|
+
styled.div({
|
|
109
|
+
'@keyframes fadeIn': {},
|
|
110
|
+
'@media screen and (width < 900px)': {},
|
|
111
|
+
'@supports (display: flex)': {},
|
|
112
|
+
'@scope (article) to (figure)': {},
|
|
113
|
+
});
|
|
114
|
+
`,
|
|
115
|
+
errors: [
|
|
116
|
+
{
|
|
117
|
+
messageId: 'no-keyframes-at-rules',
|
|
118
|
+
line: 5,
|
|
119
|
+
column: 11,
|
|
120
|
+
endColumn: 30,
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
messageId: 'no-restricted-at-rules',
|
|
124
|
+
line: 8,
|
|
125
|
+
column: 11,
|
|
126
|
+
endColumn: 41,
|
|
127
|
+
},
|
|
128
|
+
],
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
name: 'keyframes API invalid usage',
|
|
132
|
+
code: outdent`
|
|
133
|
+
import { keyframes } from '@emotion/react';
|
|
134
|
+
|
|
135
|
+
keyframes({
|
|
136
|
+
'0%': {
|
|
137
|
+
':hover': {},
|
|
138
|
+
},
|
|
139
|
+
'100%': {
|
|
140
|
+
'&:abcd': {}
|
|
141
|
+
},
|
|
142
|
+
':hover': {}, // Not valid but shouldn't be picked up by this rule
|
|
143
|
+
});
|
|
144
|
+
`,
|
|
145
|
+
output: outdent`
|
|
146
|
+
import { keyframes } from '@emotion/react';
|
|
147
|
+
|
|
148
|
+
keyframes({
|
|
149
|
+
'0%': {
|
|
150
|
+
'&:hover': {},
|
|
151
|
+
},
|
|
152
|
+
'100%': {
|
|
153
|
+
'&:abcd': {}
|
|
154
|
+
},
|
|
155
|
+
':hover': {}, // Not valid but shouldn't be picked up by this rule
|
|
156
|
+
});
|
|
157
|
+
`,
|
|
158
|
+
errors: [
|
|
159
|
+
{
|
|
160
|
+
messageId: 'no-ambiguous-pseudos',
|
|
161
|
+
line: 5,
|
|
162
|
+
column: 6,
|
|
163
|
+
endColumn: 12,
|
|
164
|
+
},
|
|
165
|
+
{
|
|
166
|
+
messageId: 'no-restricted-pseudos',
|
|
167
|
+
line: 8,
|
|
168
|
+
column: 7,
|
|
169
|
+
endColumn: 12,
|
|
170
|
+
},
|
|
171
|
+
],
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
name: 'xcss API invalid usage',
|
|
175
|
+
code: `
|
|
176
|
+
import { xcss } from '@atlaskit/primitives';
|
|
177
|
+
|
|
178
|
+
xcss({
|
|
179
|
+
'&&&&&&': {},
|
|
180
|
+
});
|
|
181
|
+
`,
|
|
182
|
+
errors: [
|
|
183
|
+
{
|
|
184
|
+
messageId: 'no-increased-specificity',
|
|
185
|
+
line: 5,
|
|
186
|
+
column: 12,
|
|
187
|
+
endColumn: 18,
|
|
188
|
+
},
|
|
189
|
+
],
|
|
190
|
+
},
|
|
191
|
+
{
|
|
192
|
+
name: 'cssMap API invalid usage',
|
|
193
|
+
code: outdent`
|
|
194
|
+
import { cssMap } from '@atlaskit/primitives';
|
|
195
|
+
|
|
196
|
+
cssMap({
|
|
197
|
+
':name:': {
|
|
198
|
+
':hover': {},
|
|
199
|
+
},
|
|
200
|
+
':hover': {},
|
|
201
|
+
'[&]': {
|
|
202
|
+
'&:first-child': {}
|
|
203
|
+
},
|
|
204
|
+
});
|
|
205
|
+
`,
|
|
206
|
+
output: outdent`
|
|
207
|
+
import { cssMap } from '@atlaskit/primitives';
|
|
208
|
+
|
|
209
|
+
cssMap({
|
|
210
|
+
':name:': {
|
|
211
|
+
'&:hover': {},
|
|
212
|
+
},
|
|
213
|
+
':hover': {},
|
|
214
|
+
'[&]': {
|
|
215
|
+
'&:first-child': {}
|
|
216
|
+
},
|
|
217
|
+
});
|
|
218
|
+
`,
|
|
219
|
+
errors: [
|
|
220
|
+
{
|
|
221
|
+
messageId: 'no-ambiguous-pseudos',
|
|
222
|
+
line: 5,
|
|
223
|
+
column: 6,
|
|
224
|
+
endColumn: 12,
|
|
225
|
+
},
|
|
226
|
+
{
|
|
227
|
+
messageId: 'no-restricted-pseudos',
|
|
228
|
+
data: {
|
|
229
|
+
pseudo: ':first-child',
|
|
230
|
+
},
|
|
231
|
+
line: 9,
|
|
232
|
+
column: 7,
|
|
233
|
+
endColumn: 19,
|
|
234
|
+
},
|
|
235
|
+
],
|
|
236
|
+
},
|
|
237
|
+
],
|
|
238
|
+
});
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import type { CSSPseudos } from '@compiled/react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Validation approach from
|
|
5
|
+
* https://stackoverflow.com/a/71236280
|
|
6
|
+
*/
|
|
7
|
+
type Validate<T extends true> = T;
|
|
8
|
+
type HasAllUnique<Tuple, Union, Seen = never> = Tuple extends readonly [
|
|
9
|
+
infer Head,
|
|
10
|
+
...infer Tail,
|
|
11
|
+
]
|
|
12
|
+
? Head extends Seen
|
|
13
|
+
? {
|
|
14
|
+
ERROR: ['The following key appears more than once in the tuple:', Head];
|
|
15
|
+
}
|
|
16
|
+
: HasAllUnique<Tail, Exclude<Union, Head>, Head | Seen>
|
|
17
|
+
: [Union] extends [never]
|
|
18
|
+
? true
|
|
19
|
+
: { ERROR: ['Some keys are missing from the tuple:', Union] };
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Exporting this so it isn't considered unused.
|
|
23
|
+
*/
|
|
24
|
+
export type _ = Validate<HasAllUnique<typeof cssPseudos, CSSPseudos>>;
|
|
25
|
+
|
|
26
|
+
const cssPseudos = [
|
|
27
|
+
'&:active',
|
|
28
|
+
'&:autofill',
|
|
29
|
+
'&:blank',
|
|
30
|
+
'&:checked',
|
|
31
|
+
'&:default',
|
|
32
|
+
'&:defined',
|
|
33
|
+
'&:disabled',
|
|
34
|
+
'&:empty',
|
|
35
|
+
'&:enabled',
|
|
36
|
+
'&:first',
|
|
37
|
+
'&:focus',
|
|
38
|
+
'&:focus-visible',
|
|
39
|
+
'&:focus-within',
|
|
40
|
+
'&:fullscreen',
|
|
41
|
+
'&:hover',
|
|
42
|
+
'&:in-range',
|
|
43
|
+
'&:indeterminate',
|
|
44
|
+
'&:invalid',
|
|
45
|
+
'&:left',
|
|
46
|
+
'&:link',
|
|
47
|
+
'&:local-link',
|
|
48
|
+
'&:optional',
|
|
49
|
+
'&:out-of-range',
|
|
50
|
+
'&:paused',
|
|
51
|
+
'&:picture-in-picture',
|
|
52
|
+
'&:placeholder-shown',
|
|
53
|
+
'&:playing',
|
|
54
|
+
'&:read-only',
|
|
55
|
+
'&:read-write',
|
|
56
|
+
'&:required',
|
|
57
|
+
'&:right',
|
|
58
|
+
'&:target',
|
|
59
|
+
'&:user-invalid',
|
|
60
|
+
'&:user-valid',
|
|
61
|
+
'&:valid',
|
|
62
|
+
'&:visited',
|
|
63
|
+
'&::after',
|
|
64
|
+
'&::backdrop',
|
|
65
|
+
'&::before',
|
|
66
|
+
'&::cue',
|
|
67
|
+
'&::cue-region',
|
|
68
|
+
'&::first-letter',
|
|
69
|
+
'&::first-line',
|
|
70
|
+
'&::grammar-error',
|
|
71
|
+
'&::marker',
|
|
72
|
+
'&::placeholder',
|
|
73
|
+
'&::selection',
|
|
74
|
+
'&::spelling-error',
|
|
75
|
+
'&::target-text',
|
|
76
|
+
'&::view-transition',
|
|
77
|
+
] as const;
|
|
78
|
+
|
|
79
|
+
export const allowedPseudos = new Set(
|
|
80
|
+
/**
|
|
81
|
+
* The `&` is included above for type checking reasons,
|
|
82
|
+
* but we don't actually want it when consuming the values.
|
|
83
|
+
*/
|
|
84
|
+
cssPseudos.map((pseudo) => pseudo.slice(1)),
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
export const legacyPseudoElements = new Set([
|
|
88
|
+
':after',
|
|
89
|
+
':before',
|
|
90
|
+
':first-letter',
|
|
91
|
+
':first-line',
|
|
92
|
+
]);
|
|
93
|
+
|
|
94
|
+
export const ignoredAtRules = new Set([
|
|
95
|
+
'@container', // ignored because it's covered by `no-container-queries`
|
|
96
|
+
'@media', // ignored because it's covered by `no-nested-styles`
|
|
97
|
+
'@supports',
|
|
98
|
+
'@property',
|
|
99
|
+
]);
|