@atlaskit/eslint-plugin-ui-styling-standard 0.15.2 → 0.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/constellation/index/migration-guide.mdx +309 -0
- package/constellation/index/overview.mdx +4 -0
- package/constellation/index/props.mdx +9 -5
- package/dist/types/rules/no-unsafe-selectors/constants.d.ts +1 -4
- package/index.js +9 -9
- package/package.json +3 -3
- package/scripts/codegen.tsx +223 -284
- package/src/rules/__tests__/utils/_tester.tsx +24 -24
- package/src/rules/atlaskit-theme/README.md +21 -19
- package/src/rules/atlaskit-theme/__tests__/test.ts +53 -53
- package/src/rules/atlaskit-theme/index.ts +107 -115
- package/src/rules/convert-props-syntax/README.md +32 -22
- package/src/rules/convert-props-syntax/__tests__/invalid.test.tsx +46 -46
- package/src/rules/convert-props-syntax/__tests__/rule.test.tsx +175 -175
- package/src/rules/convert-props-syntax/__tests__/type-annotations.test.tsx +52 -52
- package/src/rules/convert-props-syntax/__tests__/unusual-properties.test.tsx +33 -33
- package/src/rules/convert-props-syntax/index.tsx +356 -386
- package/src/rules/enforce-style-prop/README.md +21 -18
- package/src/rules/enforce-style-prop/__tests__/rule.test.tsx +90 -96
- package/src/rules/enforce-style-prop/index.tsx +144 -160
- package/src/rules/external-rules.tsx +163 -164
- package/src/rules/local-cx-xcss/README.md +10 -6
- package/src/rules/local-cx-xcss/__tests__/rule.test.tsx +26 -26
- package/src/rules/local-cx-xcss/index.tsx +46 -56
- package/src/rules/no-array-arguments/README.md +2 -1
- package/src/rules/no-array-arguments/__tests__/rule.test.tsx +37 -46
- package/src/rules/no-array-arguments/index.tsx +68 -69
- package/src/rules/no-classname-prop/README.md +7 -4
- package/src/rules/no-classname-prop/__tests__/rule.test.tsx +22 -22
- package/src/rules/no-classname-prop/index.tsx +25 -25
- package/src/rules/no-container-queries/README.md +11 -9
- package/src/rules/no-container-queries/__tests__/rule.test.tsx +47 -50
- package/src/rules/no-container-queries/index.tsx +75 -81
- package/src/rules/no-dynamic-styles/README.md +16 -19
- package/src/rules/no-dynamic-styles/__tests__/rule.test.tsx +58 -67
- package/src/rules/no-dynamic-styles/index.tsx +45 -48
- package/src/rules/no-exported-styles/README.md +17 -12
- package/src/rules/no-exported-styles/__tests__/rule.test.tsx +102 -111
- package/src/rules/no-exported-styles/index.tsx +36 -36
- package/src/rules/no-global-styles/README.md +15 -14
- package/src/rules/no-global-styles/__tests__/no-css-modules.test.tsx +28 -28
- package/src/rules/no-global-styles/__tests__/no-global-styles.test.tsx +37 -37
- package/src/rules/no-global-styles/index.tsx +59 -62
- package/src/rules/no-important-styles/README.md +5 -3
- package/src/rules/no-important-styles/__tests__/rule.test.tsx +66 -66
- package/src/rules/no-important-styles/index.tsx +49 -49
- package/src/rules/no-imported-style-values/README.md +23 -15
- package/src/rules/no-imported-style-values/__tests__/rule.test.tsx +123 -123
- package/src/rules/no-imported-style-values/index.tsx +116 -120
- package/src/rules/no-nested-selectors/README.md +15 -13
- package/src/rules/no-nested-selectors/__tests__/rule.test.tsx +128 -128
- package/src/rules/no-styled/README.md +14 -9
- package/src/rules/no-styled/__tests__/rule.test.tsx +31 -31
- package/src/rules/no-styled/index.tsx +34 -41
- package/src/rules/no-unsafe-selectors/README.md +103 -93
- package/src/rules/no-unsafe-selectors/__tests__/no-grouped-at-rules.test.tsx +21 -24
- package/src/rules/no-unsafe-selectors/__tests__/no-increased-specificity.test.tsx +44 -44
- package/src/rules/no-unsafe-selectors/__tests__/no-keyframes-at-rules.test.tsx +21 -21
- package/src/rules/no-unsafe-selectors/__tests__/no-legacy-pseudo-element-syntax.test.tsx +57 -57
- package/src/rules/no-unsafe-selectors/__tests__/no-restricted-at-rules.test.tsx +58 -58
- package/src/rules/no-unsafe-selectors/__tests__/no-restricted-pseudos.test.tsx +85 -85
- package/src/rules/no-unsafe-selectors/__tests__/no-selectors-object.test.tsx +12 -12
- package/src/rules/no-unsafe-selectors/__tests__/no-unparsable-selectors.test.tsx +23 -23
- package/src/rules/no-unsafe-selectors/__tests__/rule.test.tsx +114 -114
- package/src/rules/no-unsafe-selectors/constants.tsx +69 -77
- package/src/rules/no-unsafe-selectors/source-position-utils.tsx +38 -38
- package/src/rules/no-unsafe-selectors/walk-css-map.tsx +178 -184
- package/src/rules/no-unsafe-values/README.md +34 -40
- package/src/rules/no-unsafe-values/__tests__/no-array-values.test.tsx +13 -13
- package/src/rules/no-unsafe-values/__tests__/no-conditional-values.test.tsx +18 -18
- package/src/rules/no-unsafe-values/__tests__/no-dynamic-keys.test.tsx +104 -104
- package/src/rules/no-unsafe-values/__tests__/no-function-calls.test.tsx +128 -128
- package/src/rules/no-unsafe-values/__tests__/no-identifier-arguments.test.tsx +23 -23
- package/src/rules/no-unsafe-values/__tests__/no-object-access.test.tsx +38 -38
- package/src/rules/no-unsafe-values/__tests__/no-object-references.test.tsx +18 -18
- package/src/rules/no-unsafe-values/__tests__/no-spread-elements.test.tsx +18 -18
- package/src/rules/no-unsafe-values/__tests__/no-unsafe-values.test.tsx +28 -28
- package/src/rules/no-unsafe-values/__tests__/no-variables.test.tsx +47 -47
- package/src/rules/no-unsafe-values/index.tsx +76 -78
- package/src/rules/no-unsafe-values/messages.tsx +12 -12
- package/src/rules/no-unsafe-values/utils.tsx +370 -382
- package/src/rules/use-compiled/README.md +11 -8
- package/src/rules/use-compiled/__tests__/can-auto-fix.test.tsx +32 -32
- package/src/rules/use-compiled/__tests__/css.test.tsx +53 -53
- package/src/rules/use-compiled/__tests__/imports.test.tsx +90 -95
- package/src/rules/use-compiled/__tests__/keyframes.test.tsx +47 -47
- package/src/rules/use-compiled/__tests__/pragma.test.tsx +64 -64
- package/src/rules/use-compiled/__tests__/styled.test.tsx +53 -53
- package/src/rules/use-compiled/__tests__/use-compiled.test.tsx +10 -10
- package/src/rules/use-compiled/index.tsx +203 -226
- package/src/rules/use-compiled/is-safe.tsx +113 -117
- package/src/rules/use-compiled/utils.tsx +14 -18
- package/src/rules/utils/create-rule-with-typed-config.tsx +62 -63
- package/src/rules/utils/create-rule.tsx +3 -6
|
@@ -2,30 +2,30 @@ import { typescriptEslintTester } from '../../__tests__/utils/_tester';
|
|
|
2
2
|
import rule from '../index';
|
|
3
3
|
|
|
4
4
|
typescriptEslintTester.run(
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
5
|
+
'no-nested-selectors',
|
|
6
|
+
// @ts-expect-error
|
|
7
|
+
rule,
|
|
8
|
+
{
|
|
9
|
+
valid: [],
|
|
10
|
+
invalid: [
|
|
11
|
+
{
|
|
12
|
+
name: 'single array argument',
|
|
13
|
+
code: `
|
|
14
14
|
import { css } from '@compiled/react';
|
|
15
15
|
const styles = css([
|
|
16
16
|
{ width: 100 },
|
|
17
17
|
{ height: 100 }
|
|
18
18
|
]);
|
|
19
19
|
`,
|
|
20
|
-
|
|
20
|
+
output: `
|
|
21
21
|
import { css } from '@compiled/react';
|
|
22
22
|
const styles = css({ width: 100 }, { height: 100 });
|
|
23
23
|
`,
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
24
|
+
errors: [{ messageId: 'no-array-arguments' }],
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
name: 'multiple array arguments',
|
|
28
|
+
code: `
|
|
29
29
|
import { css } from '@compiled/react';
|
|
30
30
|
const styles = css(
|
|
31
31
|
[
|
|
@@ -37,21 +37,18 @@ typescriptEslintTester.run(
|
|
|
37
37
|
]
|
|
38
38
|
);
|
|
39
39
|
`,
|
|
40
|
-
|
|
40
|
+
output: `
|
|
41
41
|
import { css } from '@compiled/react';
|
|
42
42
|
const styles = css(
|
|
43
43
|
{ width: 100 }, { height: 100 },
|
|
44
44
|
{ color: 'red' }
|
|
45
45
|
);
|
|
46
46
|
`,
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
{
|
|
53
|
-
name: 'interspersed array arguments',
|
|
54
|
-
code: `
|
|
47
|
+
errors: [{ messageId: 'no-array-arguments' }, { messageId: 'no-array-arguments' }],
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
name: 'interspersed array arguments',
|
|
51
|
+
code: `
|
|
55
52
|
import { css } from '@compiled/react';
|
|
56
53
|
const styles = css(
|
|
57
54
|
{ a: 1 },
|
|
@@ -67,7 +64,7 @@ typescriptEslintTester.run(
|
|
|
67
64
|
{ c: 3 }
|
|
68
65
|
);
|
|
69
66
|
`,
|
|
70
|
-
|
|
67
|
+
output: `
|
|
71
68
|
import { css } from '@compiled/react';
|
|
72
69
|
const styles = css(
|
|
73
70
|
{ a: 1 },
|
|
@@ -77,14 +74,11 @@ typescriptEslintTester.run(
|
|
|
77
74
|
{ c: 3 }
|
|
78
75
|
);
|
|
79
76
|
`,
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
{
|
|
86
|
-
name: 'empty array argument',
|
|
87
|
-
code: `
|
|
77
|
+
errors: [{ messageId: 'no-array-arguments' }, { messageId: 'no-array-arguments' }],
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
name: 'empty array argument',
|
|
81
|
+
code: `
|
|
88
82
|
import { css } from '@compiled/react';
|
|
89
83
|
const styles = css(
|
|
90
84
|
[],
|
|
@@ -92,25 +86,22 @@ typescriptEslintTester.run(
|
|
|
92
86
|
[]
|
|
93
87
|
);
|
|
94
88
|
`,
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
{
|
|
101
|
-
name: 'spread in array',
|
|
102
|
-
code: `
|
|
89
|
+
errors: [{ messageId: 'no-array-arguments' }, { messageId: 'no-array-arguments' }],
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
name: 'spread in array',
|
|
93
|
+
code: `
|
|
103
94
|
import { css } from '@compiled/react';
|
|
104
95
|
const styles = css([
|
|
105
96
|
...items
|
|
106
97
|
]);
|
|
107
98
|
`,
|
|
108
|
-
|
|
99
|
+
output: `
|
|
109
100
|
import { css } from '@compiled/react';
|
|
110
101
|
const styles = css(...items);
|
|
111
102
|
`,
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
103
|
+
errors: [{ messageId: 'no-array-arguments' }],
|
|
104
|
+
},
|
|
105
|
+
],
|
|
106
|
+
},
|
|
116
107
|
);
|
|
@@ -1,87 +1,86 @@
|
|
|
1
1
|
import type { Expression, SpreadElement } from 'estree';
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
getImportSources,
|
|
5
|
+
hasStyleObjectArguments,
|
|
6
6
|
} from '@atlaskit/eslint-utils/is-supported-import';
|
|
7
7
|
import { createLintRule } from '../utils/create-rule';
|
|
8
8
|
import type { JSONSchema4 } from '@typescript-eslint/utils/dist/json-schema';
|
|
9
9
|
|
|
10
10
|
const schema: JSONSchema4 = [
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
11
|
+
{
|
|
12
|
+
type: 'object',
|
|
13
|
+
properties: {
|
|
14
|
+
importSources: {
|
|
15
|
+
type: 'array',
|
|
16
|
+
items: { type: 'string' },
|
|
17
|
+
uniqueItems: true,
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
21
|
];
|
|
22
22
|
|
|
23
23
|
export const rule = createLintRule({
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
const { references } = context.sourceCode.getScope(node);
|
|
24
|
+
meta: {
|
|
25
|
+
name: 'no-array-arguments',
|
|
26
|
+
docs: {
|
|
27
|
+
description: 'Prevents usage of array arguments to style declaration functions',
|
|
28
|
+
recommended: true,
|
|
29
|
+
severity: 'warn',
|
|
30
|
+
},
|
|
31
|
+
messages: {
|
|
32
|
+
'no-array-arguments':
|
|
33
|
+
"Don't pass multiple value in an array. Pass them as multiple arguments instead.",
|
|
34
|
+
},
|
|
35
|
+
type: 'problem',
|
|
36
|
+
fixable: 'code',
|
|
37
|
+
schema,
|
|
38
|
+
},
|
|
39
|
+
create(context) {
|
|
40
|
+
const importSources = getImportSources(context);
|
|
41
|
+
return {
|
|
42
|
+
CallExpression(node) {
|
|
43
|
+
const { references } = context.sourceCode.getScope(node);
|
|
45
44
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
45
|
+
if (!hasStyleObjectArguments(node.callee, references, importSources)) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
49
48
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
49
|
+
for (const argument of node.arguments) {
|
|
50
|
+
if (argument.type === 'ArrayExpression') {
|
|
51
|
+
context.report({
|
|
52
|
+
node: argument,
|
|
53
|
+
messageId: 'no-array-arguments',
|
|
54
|
+
fix(fixer) {
|
|
55
|
+
if (argument.elements.length === 0) {
|
|
56
|
+
/**
|
|
57
|
+
* Don't autofix if it's an empty array.
|
|
58
|
+
*
|
|
59
|
+
* I couldn't figure out how to get rid of the comma afterwards,
|
|
60
|
+
* so the autofix was producing syntax problems.
|
|
61
|
+
*
|
|
62
|
+
* This is an edge case that shouldn't actually be happening,
|
|
63
|
+
* but if it does it's not hard to just delete the empty array...
|
|
64
|
+
*/
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
68
67
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
68
|
+
const items = argument.elements
|
|
69
|
+
.filter(
|
|
70
|
+
(
|
|
71
|
+
value: SpreadElement | Expression | null,
|
|
72
|
+
): value is SpreadElement | Expression => value !== null,
|
|
73
|
+
)
|
|
74
|
+
.map((element) => context.sourceCode.getText(element));
|
|
76
75
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
76
|
+
return fixer.replaceText(argument, items.join(', '));
|
|
77
|
+
},
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
},
|
|
85
84
|
});
|
|
86
85
|
|
|
87
86
|
export default rule;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
This rule prevents usage of the `className` prop in JSX.
|
|
2
2
|
|
|
3
|
-
Avoid `className` because it invites the use of unsafe global styles and is impossible to determine
|
|
3
|
+
Avoid `className` because it invites the use of unsafe global styles and is impossible to determine
|
|
4
|
+
via local tooling. Use props for configuration and typical CSS-in-JS for styling or `xcss` for
|
|
5
|
+
bounded overrides.
|
|
4
6
|
|
|
5
7
|
## Examples
|
|
6
8
|
|
|
@@ -30,7 +32,8 @@ import { css } from '@compiled/react';
|
|
|
30
32
|
|
|
31
33
|
### What if I'm using `className` to target elements with JavaScript?
|
|
32
34
|
|
|
33
|
-
There are some cases where a selector is required to integrate with a 3rd party library,
|
|
34
|
-
|
|
35
|
+
There are some cases where a selector is required to integrate with a 3rd party library, such as
|
|
36
|
+
legacy code using jQuery.
|
|
35
37
|
|
|
36
|
-
Use a `ref` if possible. Otherwise, if you _must_ have a selector, use a `data-*` attribute that
|
|
38
|
+
Use a `ref` if possible. Otherwise, if you _must_ have a selector, use a `data-*` attribute that
|
|
39
|
+
gives enough context and is unique enough, for example `data-editor-table-target="true"`.
|
|
@@ -2,38 +2,38 @@ import { tester } from '../../__tests__/utils/_tester';
|
|
|
2
2
|
import rule from '../index';
|
|
3
3
|
|
|
4
4
|
tester.run('no-classname-prop', rule, {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
valid: [
|
|
6
|
+
{
|
|
7
|
+
code: `
|
|
8
8
|
<div />
|
|
9
9
|
`,
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
10
|
+
},
|
|
11
|
+
],
|
|
12
|
+
invalid: [
|
|
13
|
+
{
|
|
14
|
+
// Basic test case
|
|
15
|
+
code: `
|
|
16
16
|
<div className={myStyles} />
|
|
17
17
|
`,
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
18
|
+
errors: [{ messageId: 'no-classname-prop' }],
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
// String
|
|
22
|
+
code: `
|
|
23
23
|
<div className="my-class" />
|
|
24
24
|
`,
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
25
|
+
errors: [{ messageId: 'no-classname-prop' }],
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
// With non-primitive elements
|
|
29
|
+
code: `
|
|
30
30
|
import { styled } from '@compiled/react';
|
|
31
31
|
|
|
32
32
|
const Component = styled.div({});
|
|
33
33
|
|
|
34
34
|
<Component className="my-class" />
|
|
35
35
|
`,
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
errors: [{ messageId: 'no-classname-prop' }],
|
|
37
|
+
},
|
|
38
|
+
],
|
|
39
39
|
});
|
|
@@ -3,32 +3,32 @@ import { isNodeOfType, type Node } from 'eslint-codemod-utils';
|
|
|
3
3
|
import { createLintRule } from '../utils/create-rule';
|
|
4
4
|
|
|
5
5
|
export const rule = createLintRule({
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
6
|
+
meta: {
|
|
7
|
+
name: 'no-classname-prop',
|
|
8
|
+
docs: {
|
|
9
|
+
description: 'Disallows usage of the `className` prop in JSX',
|
|
10
|
+
recommended: true,
|
|
11
|
+
severity: 'warn',
|
|
12
|
+
},
|
|
13
|
+
messages: {
|
|
14
|
+
'no-classname-prop':
|
|
15
|
+
'Avoid `className` because it invites the use of unsafe global styles and is impossible to determine via local tooling.',
|
|
16
|
+
},
|
|
17
|
+
type: 'problem',
|
|
18
|
+
},
|
|
19
|
+
create(context) {
|
|
20
|
+
return {
|
|
21
|
+
JSXAttribute(node: Node) {
|
|
22
|
+
if (!isNodeOfType(node, 'JSXAttribute')) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
26
|
+
if (node.name.name === 'className') {
|
|
27
|
+
context.report({ node, messageId: 'no-classname-prop' });
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
},
|
|
32
32
|
});
|
|
33
33
|
|
|
34
34
|
export default rule;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
This rule prevents the usage of the `@container` query in style declarations.
|
|
2
2
|
|
|
3
|
-
Container queries break the rules of scope and aren’t guaranteed to be deterministic or type safe
|
|
3
|
+
Container queries break the rules of scope and aren’t guaranteed to be deterministic or type safe
|
|
4
|
+
and isn’t fully supported across our frontend tech stacks.
|
|
4
5
|
|
|
5
6
|
We suggest you explore the use alternatives such as client JavaScript-based APIs or media queries.
|
|
6
7
|
|
|
@@ -12,11 +13,11 @@ We suggest you explore the use alternatives such as client JavaScript-based APIs
|
|
|
12
13
|
import { css } from '@compiled/react';
|
|
13
14
|
|
|
14
15
|
const styles = css({
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
'@container (width > 400px)': {
|
|
17
|
+
h2: {
|
|
18
|
+
fontSize: '1.5rem',
|
|
19
|
+
},
|
|
20
|
+
},
|
|
20
21
|
});
|
|
21
22
|
```
|
|
22
23
|
|
|
@@ -26,8 +27,8 @@ const styles = css({
|
|
|
26
27
|
import { css } from '@compiled/react';
|
|
27
28
|
|
|
28
29
|
const containerStyles = css({
|
|
29
|
-
|
|
30
|
-
|
|
30
|
+
display: 'flex',
|
|
31
|
+
flexDirection: 'column',
|
|
31
32
|
});
|
|
32
33
|
```
|
|
33
34
|
|
|
@@ -45,4 +46,5 @@ By default, this rule will check `css` usages from:
|
|
|
45
46
|
- `@emotion/styled`
|
|
46
47
|
- `styled-components`
|
|
47
48
|
|
|
48
|
-
To change this list of libraries, you can define a custom set of `importSources`, which accepts an
|
|
49
|
+
To change this list of libraries, you can define a custom set of `importSources`, which accepts an
|
|
50
|
+
array of package names (strings).
|
|
@@ -2,24 +2,24 @@ import { typescriptEslintTester } from '../../__tests__/utils/_tester';
|
|
|
2
2
|
import rule from '../index';
|
|
3
3
|
|
|
4
4
|
typescriptEslintTester.run(
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
5
|
+
'no-container-queries',
|
|
6
|
+
// @ts-expect-error
|
|
7
|
+
rule,
|
|
8
|
+
{
|
|
9
|
+
valid: [
|
|
10
|
+
{
|
|
11
|
+
name: 'Basic valid test',
|
|
12
|
+
code: `
|
|
13
13
|
import { css } from '@compiled/react';
|
|
14
14
|
const containerStyles = css({
|
|
15
15
|
display: 'flex',
|
|
16
16
|
flexDirection: 'column',
|
|
17
17
|
});
|
|
18
18
|
`,
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
name: 'Custom import sources (subtractive)',
|
|
22
|
+
code: `
|
|
23
23
|
import { css } from '@compiled/react';
|
|
24
24
|
const styles = css({
|
|
25
25
|
'@container (width > 400px)': {
|
|
@@ -29,17 +29,17 @@ typescriptEslintTester.run(
|
|
|
29
29
|
}
|
|
30
30
|
});
|
|
31
31
|
`,
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
32
|
+
options: [
|
|
33
|
+
{
|
|
34
|
+
importSources: [],
|
|
35
|
+
},
|
|
36
|
+
],
|
|
37
|
+
},
|
|
38
|
+
],
|
|
39
|
+
invalid: [
|
|
40
|
+
{
|
|
41
|
+
name: 'Basic test for @container',
|
|
42
|
+
code: `
|
|
43
43
|
import { css } from '@compiled/react';
|
|
44
44
|
|
|
45
45
|
const styles = css({
|
|
@@ -50,11 +50,11 @@ typescriptEslintTester.run(
|
|
|
50
50
|
}
|
|
51
51
|
});
|
|
52
52
|
`,
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
53
|
+
errors: [{ messageId: 'no-container-queries' }],
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
name: '@container template literal in styled div',
|
|
57
|
+
code: `
|
|
58
58
|
import { styled } from '@compiled/react';
|
|
59
59
|
|
|
60
60
|
const Component = styled.div({
|
|
@@ -70,14 +70,11 @@ typescriptEslintTester.run(
|
|
|
70
70
|
},
|
|
71
71
|
});
|
|
72
72
|
`,
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
{
|
|
79
|
-
name: '@container in styled div under feature flag',
|
|
80
|
-
code: `
|
|
73
|
+
errors: [{ messageId: 'no-container-queries' }, { messageId: 'no-container-queries' }],
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
name: '@container in styled div under feature flag',
|
|
77
|
+
code: `
|
|
81
78
|
import { styled } from "@compiled/react";
|
|
82
79
|
const Container = styled.div(
|
|
83
80
|
{
|
|
@@ -99,11 +96,11 @@ typescriptEslintTester.run(
|
|
|
99
96
|
},
|
|
100
97
|
);
|
|
101
98
|
`,
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
99
|
+
errors: [{ messageId: 'no-container-queries' }],
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
name: '@container in a styled div with TS type parameter',
|
|
103
|
+
code: `
|
|
107
104
|
import { styled } from "@compiled/react";
|
|
108
105
|
|
|
109
106
|
const Component = styled.div<{
|
|
@@ -116,11 +113,11 @@ typescriptEslintTester.run(
|
|
|
116
113
|
},
|
|
117
114
|
});
|
|
118
115
|
`,
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
116
|
+
errors: [{ messageId: 'no-container-queries' }],
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
name: '@container in template literal within styled div with TS type parameter',
|
|
120
|
+
code: `
|
|
124
121
|
import { styled } from "@compiled/react";
|
|
125
122
|
const Container = styled.div<{
|
|
126
123
|
paddingBottom: number;
|
|
@@ -135,8 +132,8 @@ typescriptEslintTester.run(
|
|
|
135
132
|
},
|
|
136
133
|
});
|
|
137
134
|
`,
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
135
|
+
errors: [{ messageId: 'no-container-queries' }],
|
|
136
|
+
},
|
|
137
|
+
],
|
|
138
|
+
},
|
|
142
139
|
);
|