@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
|
@@ -5,81 +5,78 @@ import { createLintRule } from '../utils/create-rule';
|
|
|
5
5
|
const restrictedFileTypes = ['.css', '.less', '.sass', '.scss'];
|
|
6
6
|
|
|
7
7
|
const restrictedImports = {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
'@emotion/core': ['Global'],
|
|
9
|
+
'@emotion/react': ['Global'],
|
|
10
|
+
'styled-components': ['createGlobalStyle', 'injectGlobal'],
|
|
11
11
|
};
|
|
12
12
|
|
|
13
13
|
type RestrictedImportSource = keyof typeof restrictedImports;
|
|
14
|
-
function isRestrictedImportSource(
|
|
15
|
-
|
|
16
|
-
): importSource is RestrictedImportSource {
|
|
17
|
-
return importSource in restrictedImports;
|
|
14
|
+
function isRestrictedImportSource(importSource: string): importSource is RestrictedImportSource {
|
|
15
|
+
return importSource in restrictedImports;
|
|
18
16
|
}
|
|
19
17
|
|
|
20
18
|
export const rule = createLintRule({
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
19
|
+
meta: {
|
|
20
|
+
name: 'no-global-styles',
|
|
21
|
+
docs: {
|
|
22
|
+
description: 'Prevents global styles through CSS-in-JS or CSS module imports',
|
|
23
|
+
recommended: true,
|
|
24
|
+
severity: 'warn',
|
|
25
|
+
},
|
|
26
|
+
messages: {
|
|
27
|
+
'no-global-styles': 'Global styles are not allowed.',
|
|
28
|
+
'no-css-modules': 'Importing CSS files is not allowed.',
|
|
29
|
+
},
|
|
30
|
+
type: 'problem',
|
|
31
|
+
},
|
|
32
|
+
create(context) {
|
|
33
|
+
function checkFileType(node: ESTree.ImportDeclaration) {
|
|
34
|
+
const importSource = node.source.value as string;
|
|
35
|
+
if (restrictedFileTypes.some((suffix) => importSource.endsWith(suffix))) {
|
|
36
|
+
context.report({
|
|
37
|
+
node: node.source,
|
|
38
|
+
messageId: 'no-css-modules',
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
45
42
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
43
|
+
function checkImports(node: ESTree.ImportDeclaration) {
|
|
44
|
+
const importSource = node.source.value as string;
|
|
45
|
+
if (!isRestrictedImportSource(importSource)) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
51
48
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
49
|
+
for (const importName of restrictedImports[importSource]) {
|
|
50
|
+
const specifier = node.specifiers
|
|
51
|
+
.filter(isImportSpecifier)
|
|
52
|
+
.find((specifier) => specifier.imported.name === importName);
|
|
56
53
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
54
|
+
if (specifier) {
|
|
55
|
+
context.report({
|
|
56
|
+
node: specifier,
|
|
57
|
+
messageId: 'no-global-styles',
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
65
62
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
63
|
+
return {
|
|
64
|
+
ImportDeclaration(node: ESTree.ImportDeclaration) {
|
|
65
|
+
checkFileType(node);
|
|
66
|
+
checkImports(node);
|
|
67
|
+
},
|
|
68
|
+
'JSXOpeningElement[name.name="style"]'(node: ESTree.Node) {
|
|
69
|
+
context.report({
|
|
70
|
+
node,
|
|
71
|
+
messageId: 'no-global-styles',
|
|
72
|
+
});
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
},
|
|
79
76
|
});
|
|
80
77
|
|
|
81
78
|
export default rule;
|
|
82
79
|
|
|
83
80
|
function isImportSpecifier(node: ESTree.Node): node is ESTree.ImportSpecifier {
|
|
84
|
-
|
|
81
|
+
return node.type === 'ImportSpecifier';
|
|
85
82
|
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
This rule prevents the usage of the `!important` flag in style declarations.
|
|
2
2
|
|
|
3
|
-
Properly composed styles will never need an `!important` flag. It is used to override specificity
|
|
3
|
+
Properly composed styles will never need an `!important` flag. It is used to override specificity
|
|
4
|
+
when working across different scopes, and the UI Styling Standard enforces styles with minimal
|
|
5
|
+
scope.
|
|
4
6
|
|
|
5
7
|
The use of `!important` is a code smell and greatly impacts readability and determinism.
|
|
6
8
|
|
|
@@ -12,7 +14,7 @@ The use of `!important` is a code smell and greatly impacts readability and dete
|
|
|
12
14
|
import { css } from '@compiled/react';
|
|
13
15
|
|
|
14
16
|
const styles = css({
|
|
15
|
-
|
|
17
|
+
color: 'red!important',
|
|
16
18
|
});
|
|
17
19
|
```
|
|
18
20
|
|
|
@@ -22,6 +24,6 @@ const styles = css({
|
|
|
22
24
|
import { css } from '@compiled/react';
|
|
23
25
|
|
|
24
26
|
const styles = css({
|
|
25
|
-
|
|
27
|
+
color: 'red',
|
|
26
28
|
});
|
|
27
29
|
```
|
|
@@ -2,56 +2,56 @@ import { tester } from '../../__tests__/utils/_tester';
|
|
|
2
2
|
import rule from '../index';
|
|
3
3
|
|
|
4
4
|
tester.run('no-important-styles', rule, {
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
valid: [
|
|
6
|
+
`
|
|
7
7
|
import { css } from '@compiled/react';
|
|
8
8
|
|
|
9
9
|
const styles = css({
|
|
10
10
|
color: 'red'
|
|
11
11
|
});
|
|
12
12
|
`,
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
{
|
|
14
|
+
name: 'custom import sources (subtractive)',
|
|
15
|
+
code: `
|
|
16
16
|
import { css } from '@compiled/react';
|
|
17
17
|
|
|
18
18
|
const styles = css({
|
|
19
19
|
color: 'red !important'
|
|
20
20
|
});
|
|
21
21
|
`,
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
22
|
+
options: [
|
|
23
|
+
{
|
|
24
|
+
importSources: [],
|
|
25
|
+
},
|
|
26
|
+
],
|
|
27
|
+
},
|
|
28
|
+
],
|
|
29
|
+
invalid: [
|
|
30
|
+
{
|
|
31
|
+
name: 'basic test case',
|
|
32
|
+
code: `
|
|
33
33
|
import { css } from '@compiled/react';
|
|
34
34
|
|
|
35
35
|
const styles = css({
|
|
36
36
|
color: 'red !important'
|
|
37
37
|
});
|
|
38
38
|
`,
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
39
|
+
errors: [{ messageId: 'no-important-styles' }],
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
name: 'whitespace handling',
|
|
43
|
+
code: `
|
|
44
44
|
import { css } from '@compiled/react';
|
|
45
45
|
|
|
46
46
|
const styles = css({
|
|
47
47
|
color: 'red !important '
|
|
48
48
|
});
|
|
49
49
|
`,
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
50
|
+
errors: [{ messageId: 'no-important-styles' }],
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
name: 'nesting',
|
|
54
|
+
code: `
|
|
55
55
|
import { css } from '@compiled/react';
|
|
56
56
|
|
|
57
57
|
const styles = css({
|
|
@@ -65,11 +65,11 @@ tester.run('no-important-styles', rule, {
|
|
|
65
65
|
}
|
|
66
66
|
});
|
|
67
67
|
`,
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
68
|
+
errors: [{ messageId: 'no-important-styles' }],
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
name: 'styled API',
|
|
72
|
+
code: `
|
|
73
73
|
import { styled } from '@compiled/react';
|
|
74
74
|
|
|
75
75
|
const Component = styled.div({
|
|
@@ -83,11 +83,11 @@ tester.run('no-important-styles', rule, {
|
|
|
83
83
|
}
|
|
84
84
|
});
|
|
85
85
|
`,
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
86
|
+
errors: [{ messageId: 'no-important-styles' }],
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
name: 'keyframes API',
|
|
90
|
+
code: `
|
|
91
91
|
import { keyframes } from '@compiled/react';
|
|
92
92
|
|
|
93
93
|
const fadeOut = keyframes({
|
|
@@ -99,11 +99,11 @@ tester.run('no-important-styles', rule, {
|
|
|
99
99
|
},
|
|
100
100
|
});
|
|
101
101
|
`,
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
102
|
+
errors: [{ messageId: 'no-important-styles' }],
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
name: 'cssMap API',
|
|
106
|
+
code: `
|
|
107
107
|
import { cssMap } from '@compiled/react';
|
|
108
108
|
|
|
109
109
|
const borderStyleMap = cssMap({
|
|
@@ -111,34 +111,34 @@ tester.run('no-important-styles', rule, {
|
|
|
111
111
|
solid: { borderStyle: 'solid' },
|
|
112
112
|
});
|
|
113
113
|
`,
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
114
|
+
errors: [{ messageId: 'no-important-styles' }],
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
name: 'xcss API',
|
|
118
|
+
code: `
|
|
119
119
|
import { xcss } from '@atlaskit/primitives';
|
|
120
120
|
|
|
121
121
|
const styles = xcss({
|
|
122
122
|
display: 'block !important'
|
|
123
123
|
});
|
|
124
124
|
`,
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
125
|
+
errors: [{ messageId: 'no-important-styles' }],
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
name: 'custom import sources (additive)',
|
|
129
|
+
code: `
|
|
130
130
|
import { css } from 'custom-library';
|
|
131
131
|
|
|
132
132
|
const styles = css({
|
|
133
133
|
color: 'red !important'
|
|
134
134
|
});
|
|
135
135
|
`,
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
136
|
+
errors: [{ messageId: 'no-important-styles' }],
|
|
137
|
+
options: [{ importSources: ['custom-library'] }],
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
name: 'template string',
|
|
141
|
+
code: `
|
|
142
142
|
import { css } from '@compiled/react';
|
|
143
143
|
|
|
144
144
|
const color = 'red';
|
|
@@ -147,19 +147,19 @@ tester.run('no-important-styles', rule, {
|
|
|
147
147
|
color: \`\${color}!important\`
|
|
148
148
|
});
|
|
149
149
|
`,
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
150
|
+
errors: [{ messageId: 'no-important-styles' }],
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
name: 'uses default when options object is provided without importSources',
|
|
154
|
+
code: `
|
|
155
155
|
import { css } from '@compiled/react';
|
|
156
156
|
|
|
157
157
|
const styles = css({
|
|
158
158
|
color: 'red !important'
|
|
159
159
|
});
|
|
160
160
|
`,
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
161
|
+
errors: [{ messageId: 'no-important-styles' }],
|
|
162
|
+
options: [{}],
|
|
163
|
+
},
|
|
164
|
+
],
|
|
165
165
|
});
|
|
@@ -7,64 +7,64 @@ import { importSources } from '@atlaskit/eslint-utils/schema';
|
|
|
7
7
|
import { createLintRuleWithTypedConfig } from '../utils/create-rule-with-typed-config';
|
|
8
8
|
|
|
9
9
|
export const rule = createLintRuleWithTypedConfig({
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
10
|
+
meta: {
|
|
11
|
+
name: 'no-important-styles',
|
|
12
|
+
docs: {
|
|
13
|
+
description: 'Disallows important style declarations',
|
|
14
|
+
recommended: true,
|
|
15
|
+
severity: 'warn',
|
|
16
|
+
},
|
|
17
|
+
messages: {
|
|
18
|
+
'no-important-styles':
|
|
19
|
+
'Important style declarations are disallowed. Refactor so the `!important` flag is not needed.',
|
|
20
|
+
},
|
|
21
|
+
type: 'problem',
|
|
22
|
+
schema: {
|
|
23
|
+
type: 'object',
|
|
24
|
+
properties: {
|
|
25
|
+
importSources,
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
create(context, { importSources }) {
|
|
30
|
+
return {
|
|
31
|
+
CallExpression(node) {
|
|
32
|
+
const { references } = context.getScope();
|
|
33
33
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
if (!hasStyleObjectArguments(node.callee, references, importSources)) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
37
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
38
|
+
const matches = esquery(node, 'Property');
|
|
39
|
+
for (const match of matches) {
|
|
40
|
+
if (match.type !== 'Property') {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
43
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
44
|
+
if (isImportant(match.value)) {
|
|
45
|
+
context.report({
|
|
46
|
+
node: match.value,
|
|
47
|
+
messageId: 'no-important-styles',
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
},
|
|
54
54
|
});
|
|
55
55
|
|
|
56
56
|
export default rule;
|
|
57
57
|
|
|
58
58
|
const importantRegex = /!\s*important\s*$/;
|
|
59
59
|
function isImportant(node: Property['value']): boolean {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
60
|
+
if (node.type === 'Literal') {
|
|
61
|
+
return typeof node.value === 'string' && importantRegex.test(node.value);
|
|
62
|
+
}
|
|
63
63
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
64
|
+
if (node.type === 'TemplateLiteral') {
|
|
65
|
+
const joinedRaw = node.quasis.map((element) => element.value.raw).join('');
|
|
66
|
+
return importantRegex.test(joinedRaw);
|
|
67
|
+
}
|
|
68
68
|
|
|
69
|
-
|
|
69
|
+
return false;
|
|
70
70
|
}
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
This rule disallows using imported style values in `css`, `cssMap`, `styled`, `keyframes` and `xcss`
|
|
1
|
+
This rule disallows using imported style values in `css`, `cssMap`, `styled`, `keyframes` and `xcss`
|
|
2
|
+
calls.
|
|
2
3
|
|
|
3
|
-
Importing style values may result in unexpected errors when used in these APIs, because its value
|
|
4
|
+
Importing style values may result in unexpected errors when used in these APIs, because its value
|
|
5
|
+
will be null at runtime when using `@compiled/react`. Additionally, co-locating style definitions
|
|
6
|
+
with their usage is considered best practice in order to improve code readability and build
|
|
7
|
+
performance.
|
|
4
8
|
|
|
5
9
|
## Examples
|
|
6
10
|
|
|
@@ -11,8 +15,8 @@ import { css } from '@compiled/react';
|
|
|
11
15
|
import { colors, getColor } from '@mui/theme';
|
|
12
16
|
|
|
13
17
|
const styles = css({
|
|
14
|
-
|
|
15
|
-
|
|
18
|
+
[colorKey]: getColor('red'),
|
|
19
|
+
background: colors['red'],
|
|
16
20
|
});
|
|
17
21
|
```
|
|
18
22
|
|
|
@@ -24,10 +28,10 @@ import { ff } from '@atlaskit/ff';
|
|
|
24
28
|
const sharedObject = { padding: 0 };
|
|
25
29
|
|
|
26
30
|
const styles = css({
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
+
...cssShared,
|
|
32
|
+
...sharedObject,
|
|
33
|
+
height: `${HEIGHT}px`,
|
|
34
|
+
width: ff('…') ? `${HEIGHT}px` : undefined,
|
|
31
35
|
});
|
|
32
36
|
```
|
|
33
37
|
|
|
@@ -38,7 +42,7 @@ import { css } from '@compiled/react';
|
|
|
38
42
|
import { buttonStyles } from '../shared';
|
|
39
43
|
|
|
40
44
|
const styles = css({
|
|
41
|
-
|
|
45
|
+
color: 'red',
|
|
42
46
|
});
|
|
43
47
|
|
|
44
48
|
export default () => <div css={[styles, buttonStyles]} />;
|
|
@@ -54,15 +58,16 @@ export default () => <div style={{ width: importedWidth }} />;
|
|
|
54
58
|
|
|
55
59
|
### Correct
|
|
56
60
|
|
|
57
|
-
Co-locate your styles next to your components to improve code readability, linting, and build
|
|
61
|
+
Co-locate your styles next to your components to improve code readability, linting, and build
|
|
62
|
+
performance.
|
|
58
63
|
|
|
59
64
|
```js
|
|
60
65
|
import { css } from '@compiled/react';
|
|
61
66
|
import { token } from '@atlaskit/tokens';
|
|
62
67
|
|
|
63
68
|
const styles = css({
|
|
64
|
-
|
|
65
|
-
|
|
69
|
+
color: 'red',
|
|
70
|
+
padding: token('space.150'),
|
|
66
71
|
});
|
|
67
72
|
export const Component = ({ children }) => <div css={styles}>{children}></div>;
|
|
68
73
|
```
|
|
@@ -81,7 +86,8 @@ export const Component = ({ children }) => <div css={styles}>{children}></div>;
|
|
|
81
86
|
|
|
82
87
|
Use this to allow specified imports as dynamic keys, in addition to the built-in allow-list.
|
|
83
88
|
|
|
84
|
-
Each value should be a two-element array. The first item is the entrypoint, and the second item is a
|
|
89
|
+
Each value should be a two-element array. The first item is the entrypoint, and the second item is a
|
|
90
|
+
named export.
|
|
85
91
|
|
|
86
92
|
Default imports are not supported.
|
|
87
93
|
|
|
@@ -107,7 +113,8 @@ Default imports are not supported.
|
|
|
107
113
|
|
|
108
114
|
Use this to allow specific functions to be called, in addition to the built-in allow-list.
|
|
109
115
|
|
|
110
|
-
Each value should be a two-element array. The first item is the entrypoint, and the second item is a
|
|
116
|
+
Each value should be a two-element array. The first item is the entrypoint, and the second item is a
|
|
117
|
+
named export.
|
|
111
118
|
|
|
112
119
|
Default imports are not currently supported.
|
|
113
120
|
|
|
@@ -141,4 +148,5 @@ By default, this rule will check `css` usages from:
|
|
|
141
148
|
- `@emotion/styled`
|
|
142
149
|
- `styled-components`
|
|
143
150
|
|
|
144
|
-
To change this list of libraries, you can define a custom set of `importSources`, which accepts an
|
|
151
|
+
To change this list of libraries, you can define a custom set of `importSources`, which accepts an
|
|
152
|
+
array of package names (strings).
|