@atlaskit/eslint-plugin-ui-styling-standard 0.17.0 → 0.18.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 +16 -0
- package/dist/cjs/presets/all.codegen.js +3 -2
- package/dist/cjs/presets/recommended.codegen.js +3 -2
- package/dist/cjs/rules/external-rules.js +3 -1
- package/dist/es2019/presets/all.codegen.js +3 -2
- package/dist/es2019/presets/recommended.codegen.js +3 -2
- package/dist/es2019/rules/external-rules.js +3 -1
- package/dist/esm/presets/all.codegen.js +3 -2
- package/dist/esm/presets/recommended.codegen.js +3 -2
- package/dist/esm/rules/external-rules.js +3 -1
- 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-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/package.json +2 -2
- package/afm-cc/tsconfig.json +0 -28
- package/afm-jira/tsconfig.json +0 -28
- package/build/tsconfig.json +0 -18
- package/constellation/atlaskit-theme/usage.mdx +0 -132
- package/constellation/consistent-css-prop-usage/usage.mdx +0 -7
- package/constellation/convert-props-syntax/usage.mdx +0 -130
- package/constellation/enforce-style-prop/usage.mdx +0 -47
- package/constellation/index/migration-guide.mdx +0 -309
- package/constellation/index/overview.mdx +0 -250
- package/constellation/index/props.mdx +0 -30
- package/constellation/local-cx-xcss/usage.mdx +0 -53
- package/constellation/no-array-arguments/usage.mdx +0 -49
- package/constellation/no-classname-prop/usage.mdx +0 -49
- package/constellation/no-container-queries/usage.mdx +0 -101
- package/constellation/no-css-tagged-template-expression/usage.mdx +0 -8
- package/constellation/no-dynamic-styles/usage.mdx +0 -130
- package/constellation/no-empty-styled-expression/usage.mdx +0 -8
- package/constellation/no-exported-css/usage.mdx +0 -8
- package/constellation/no-exported-keyframes/usage.mdx +0 -8
- package/constellation/no-exported-styles/usage.mdx +0 -87
- package/constellation/no-global-styles/usage.mdx +0 -60
- package/constellation/no-important-styles/usage.mdx +0 -33
- package/constellation/no-imported-style-values/usage.mdx +0 -157
- package/constellation/no-invalid-css-map/usage.mdx +0 -8
- package/constellation/no-js-xcss/usage.mdx +0 -7
- package/constellation/no-keyframes-tagged-template-expression/usage.mdx +0 -8
- package/constellation/no-nested-selectors/usage.mdx +0 -95
- package/constellation/no-styled/usage.mdx +0 -92
- package/constellation/no-styled-tagged-template-expression/usage.mdx +0 -8
- package/constellation/no-suppress-xcss/usage.mdx +0 -28
- package/constellation/no-unsafe-selectors/usage.mdx +0 -370
- package/constellation/no-unsafe-values/usage.mdx +0 -318
- package/constellation/use-compiled/usage.mdx +0 -54
- package/index.js +0 -24
- package/scripts/codegen.tsx +0 -373
- package/src/index.codegen.tsx +0 -14
- package/src/index.tsx +0 -1
- package/src/presets/all.codegen.tsx +0 -79
- package/src/presets/recommended.codegen.tsx +0 -79
- package/src/rules/TEMPLATE.md +0 -29
- package/src/rules/__tests__/utils/_tester.tsx +0 -40
- package/src/rules/atlaskit-theme/README.md +0 -130
- package/src/rules/atlaskit-theme/__tests__/test.ts +0 -133
- package/src/rules/atlaskit-theme/index.ts +0 -134
- package/src/rules/convert-props-syntax/README.md +0 -128
- package/src/rules/convert-props-syntax/__tests__/invalid.test.tsx +0 -76
- package/src/rules/convert-props-syntax/__tests__/rule.test.tsx +0 -584
- package/src/rules/convert-props-syntax/__tests__/type-annotations.test.tsx +0 -140
- package/src/rules/convert-props-syntax/__tests__/unusual-properties.test.tsx +0 -69
- package/src/rules/convert-props-syntax/index.tsx +0 -414
- package/src/rules/enforce-style-prop/README.md +0 -45
- package/src/rules/enforce-style-prop/__tests__/rule.test.tsx +0 -243
- package/src/rules/enforce-style-prop/index.tsx +0 -172
- package/src/rules/external-rules.tsx +0 -175
- package/src/rules/index.codegen.tsx +0 -42
- package/src/rules/local-cx-xcss/README.md +0 -51
- package/src/rules/local-cx-xcss/__tests__/rule.test.tsx +0 -102
- package/src/rules/local-cx-xcss/index.tsx +0 -62
- package/src/rules/no-array-arguments/README.md +0 -47
- package/src/rules/no-array-arguments/__tests__/rule.test.tsx +0 -107
- package/src/rules/no-array-arguments/index.tsx +0 -86
- package/src/rules/no-classname-prop/README.md +0 -47
- package/src/rules/no-classname-prop/__tests__/rule.test.tsx +0 -39
- package/src/rules/no-classname-prop/index.tsx +0 -34
- package/src/rules/no-container-queries/README.md +0 -99
- package/src/rules/no-container-queries/__tests__/rule.test.tsx +0 -139
- package/src/rules/no-container-queries/index.tsx +0 -94
- package/src/rules/no-dynamic-styles/README.md +0 -128
- package/src/rules/no-dynamic-styles/__tests__/rule.test.tsx +0 -135
- package/src/rules/no-dynamic-styles/index.tsx +0 -60
- package/src/rules/no-exported-styles/README.md +0 -85
- package/src/rules/no-exported-styles/__tests__/rule.test.tsx +0 -216
- package/src/rules/no-exported-styles/index.tsx +0 -52
- package/src/rules/no-global-styles/README.md +0 -58
- package/src/rules/no-global-styles/__tests__/no-css-modules.test.tsx +0 -33
- package/src/rules/no-global-styles/__tests__/no-global-styles.test.tsx +0 -46
- package/src/rules/no-global-styles/index.tsx +0 -82
- package/src/rules/no-important-styles/README.md +0 -31
- package/src/rules/no-important-styles/__tests__/rule.test.tsx +0 -165
- package/src/rules/no-important-styles/index.tsx +0 -70
- package/src/rules/no-imported-style-values/README.md +0 -155
- package/src/rules/no-imported-style-values/__tests__/rule.test.tsx +0 -491
- package/src/rules/no-imported-style-values/index.tsx +0 -188
- package/src/rules/no-nested-selectors/README.md +0 -93
- package/src/rules/no-nested-selectors/__tests__/rule.test.tsx +0 -335
- package/src/rules/no-nested-selectors/index.tsx +0 -99
- package/src/rules/no-styled/README.md +0 -90
- package/src/rules/no-styled/__tests__/rule.test.tsx +0 -73
- package/src/rules/no-styled/index.tsx +0 -45
- package/src/rules/no-unsafe-selectors/README.md +0 -368
- package/src/rules/no-unsafe-selectors/__tests__/no-ambiguous-pseudos.test.tsx +0 -368
- package/src/rules/no-unsafe-selectors/__tests__/no-grouped-at-rules.test.tsx +0 -57
- package/src/rules/no-unsafe-selectors/__tests__/no-increased-specificity.test.tsx +0 -73
- package/src/rules/no-unsafe-selectors/__tests__/no-keyframes-at-rules.test.tsx +0 -40
- package/src/rules/no-unsafe-selectors/__tests__/no-legacy-pseudo-element-syntax.test.tsx +0 -101
- package/src/rules/no-unsafe-selectors/__tests__/no-restricted-at-rules.test.tsx +0 -131
- package/src/rules/no-unsafe-selectors/__tests__/no-restricted-pseudos.test.tsx +0 -132
- package/src/rules/no-unsafe-selectors/__tests__/no-selectors-object.test.tsx +0 -25
- package/src/rules/no-unsafe-selectors/__tests__/no-unparsable-selectors.test.tsx +0 -35
- package/src/rules/no-unsafe-selectors/__tests__/rule.test.tsx +0 -257
- package/src/rules/no-unsafe-selectors/constants.tsx +0 -91
- package/src/rules/no-unsafe-selectors/index.tsx +0 -198
- package/src/rules/no-unsafe-selectors/lint-selector.tsx +0 -155
- package/src/rules/no-unsafe-selectors/source-position-utils.tsx +0 -55
- package/src/rules/no-unsafe-selectors/walk-css-map.tsx +0 -226
- package/src/rules/no-unsafe-values/README.md +0 -316
- package/src/rules/no-unsafe-values/__tests__/no-array-values.test.tsx +0 -27
- package/src/rules/no-unsafe-values/__tests__/no-conditional-values.test.tsx +0 -37
- package/src/rules/no-unsafe-values/__tests__/no-dynamic-keys.test.tsx +0 -229
- package/src/rules/no-unsafe-values/__tests__/no-function-calls.test.tsx +0 -267
- package/src/rules/no-unsafe-values/__tests__/no-identifier-arguments.test.tsx +0 -52
- package/src/rules/no-unsafe-values/__tests__/no-object-access.test.tsx +0 -106
- package/src/rules/no-unsafe-values/__tests__/no-object-references.test.tsx +0 -44
- package/src/rules/no-unsafe-values/__tests__/no-spread-elements.test.tsx +0 -48
- package/src/rules/no-unsafe-values/__tests__/no-unsafe-values.test.tsx +0 -75
- package/src/rules/no-unsafe-values/__tests__/no-variables.test.tsx +0 -121
- package/src/rules/no-unsafe-values/index.tsx +0 -94
- package/src/rules/no-unsafe-values/messages.tsx +0 -86
- package/src/rules/no-unsafe-values/utils.tsx +0 -387
- package/src/rules/use-compiled/README.md +0 -52
- package/src/rules/use-compiled/__tests__/can-auto-fix.test.tsx +0 -73
- package/src/rules/use-compiled/__tests__/css.test.tsx +0 -126
- package/src/rules/use-compiled/__tests__/imports.test.tsx +0 -158
- package/src/rules/use-compiled/__tests__/keyframes.test.tsx +0 -140
- package/src/rules/use-compiled/__tests__/pragma.test.tsx +0 -108
- package/src/rules/use-compiled/__tests__/styled.test.tsx +0 -114
- package/src/rules/use-compiled/__tests__/use-compiled.test.tsx +0 -15
- package/src/rules/use-compiled/index.tsx +0 -252
- package/src/rules/use-compiled/is-safe.tsx +0 -159
- package/src/rules/use-compiled/utils.tsx +0 -33
- package/src/rules/utils/create-rule-with-typed-config.tsx +0 -86
- package/src/rules/utils/create-rule.tsx +0 -13
- package/tsconfig.app.json +0 -47
- package/tsconfig.dev.json +0 -45
- package/tsconfig.json +0 -25
|
@@ -1,216 +0,0 @@
|
|
|
1
|
-
import { typescriptEslintTester } from '../../__tests__/utils/_tester';
|
|
2
|
-
import rule from '../index';
|
|
3
|
-
|
|
4
|
-
typescriptEslintTester.run(
|
|
5
|
-
'no-exported-styles',
|
|
6
|
-
// @ts-expect-error
|
|
7
|
-
rule,
|
|
8
|
-
{
|
|
9
|
-
valid: [
|
|
10
|
-
{
|
|
11
|
-
name: 'Basic valid test for css',
|
|
12
|
-
code: `
|
|
13
|
-
import { css } from '@compiled/react';
|
|
14
|
-
const styles = css({});
|
|
15
|
-
`,
|
|
16
|
-
},
|
|
17
|
-
{
|
|
18
|
-
name: 'Basic valid test for cssMap',
|
|
19
|
-
code: `
|
|
20
|
-
import { cssMap } from '@compiled/react';
|
|
21
|
-
const styles = xcss({});
|
|
22
|
-
`,
|
|
23
|
-
},
|
|
24
|
-
{
|
|
25
|
-
name: 'Basic valid test for keyframes',
|
|
26
|
-
code: `
|
|
27
|
-
import { css } from '@compiled/react';
|
|
28
|
-
const styles = css({});
|
|
29
|
-
`,
|
|
30
|
-
},
|
|
31
|
-
{
|
|
32
|
-
name: 'Basic valid test for styled',
|
|
33
|
-
code: `
|
|
34
|
-
import { styled } from '@compiled/react';
|
|
35
|
-
const Component = styled.div({});
|
|
36
|
-
`,
|
|
37
|
-
},
|
|
38
|
-
{
|
|
39
|
-
name: 'Basic valid test for xcss',
|
|
40
|
-
code: `
|
|
41
|
-
import { css } from '@compiled/react';
|
|
42
|
-
const styles = css({});
|
|
43
|
-
`,
|
|
44
|
-
},
|
|
45
|
-
{
|
|
46
|
-
name: 'Custom import sources (subtractive)',
|
|
47
|
-
code: `
|
|
48
|
-
import { css } from '@compiled/react';
|
|
49
|
-
export const styles = css({});
|
|
50
|
-
`,
|
|
51
|
-
options: [
|
|
52
|
-
{
|
|
53
|
-
importSources: [],
|
|
54
|
-
},
|
|
55
|
-
],
|
|
56
|
-
},
|
|
57
|
-
{
|
|
58
|
-
name: 'Exporting a div with css styles is ok',
|
|
59
|
-
code: `
|
|
60
|
-
import { css } from '@compiled/react';
|
|
61
|
-
const styles = css({});
|
|
62
|
-
export default () => (
|
|
63
|
-
<div css={styles} />
|
|
64
|
-
);
|
|
65
|
-
`,
|
|
66
|
-
},
|
|
67
|
-
],
|
|
68
|
-
invalid: [
|
|
69
|
-
{
|
|
70
|
-
name: 'Export of css',
|
|
71
|
-
code: `
|
|
72
|
-
import { css } from '@compiled/react';
|
|
73
|
-
|
|
74
|
-
export const styles = css({});
|
|
75
|
-
|
|
76
|
-
export default css({});
|
|
77
|
-
`,
|
|
78
|
-
errors: [{ messageId: 'no-exported-styles' }, { messageId: 'no-exported-styles' }],
|
|
79
|
-
},
|
|
80
|
-
{
|
|
81
|
-
name: 'Export of css from emotion',
|
|
82
|
-
code: `
|
|
83
|
-
import { css } from '@emotion/react';
|
|
84
|
-
|
|
85
|
-
export const styles = css(
|
|
86
|
-
{
|
|
87
|
-
display: 'flex',
|
|
88
|
-
position: 'relative',
|
|
89
|
-
},
|
|
90
|
-
borderRadius,
|
|
91
|
-
);
|
|
92
|
-
`,
|
|
93
|
-
errors: [{ messageId: 'no-exported-styles' }],
|
|
94
|
-
},
|
|
95
|
-
{
|
|
96
|
-
name: 'Export of cssMap',
|
|
97
|
-
code: `
|
|
98
|
-
import { cssMap } from '@compiled/react';
|
|
99
|
-
|
|
100
|
-
export const borderStyleMap = cssMap({
|
|
101
|
-
none: { borderStyle: 'none' },
|
|
102
|
-
solid: { borderStyle: 'solid' },
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
export default cssMap({});
|
|
106
|
-
`,
|
|
107
|
-
errors: [{ messageId: 'no-exported-styles' }, { messageId: 'no-exported-styles' }],
|
|
108
|
-
},
|
|
109
|
-
{
|
|
110
|
-
name: 'Export of keyframes',
|
|
111
|
-
code: `
|
|
112
|
-
import { keyframes } from '@compiled/react';
|
|
113
|
-
|
|
114
|
-
export const animation = keyframes({});
|
|
115
|
-
|
|
116
|
-
export default keyframes({});
|
|
117
|
-
`,
|
|
118
|
-
errors: [{ messageId: 'no-exported-styles' }, { messageId: 'no-exported-styles' }],
|
|
119
|
-
},
|
|
120
|
-
{
|
|
121
|
-
name: 'Exporting styled component',
|
|
122
|
-
code: `
|
|
123
|
-
import { styled } from '@compiled/react';
|
|
124
|
-
|
|
125
|
-
export const Component = styled.div({});
|
|
126
|
-
`,
|
|
127
|
-
errors: [{ messageId: 'no-exported-styles' }],
|
|
128
|
-
},
|
|
129
|
-
{
|
|
130
|
-
name: 'Exporting css styles',
|
|
131
|
-
code: `
|
|
132
|
-
import { css } from '@compiled/react';
|
|
133
|
-
import { colors, getColor } from '@mui/theme';
|
|
134
|
-
import { ff } from '@atlaskit/ff';
|
|
135
|
-
|
|
136
|
-
import { buttonStyles, cssShared, colorKey } from '../shared';
|
|
137
|
-
|
|
138
|
-
const sharedObject = { padding: 0 };
|
|
139
|
-
|
|
140
|
-
export const styles = css({
|
|
141
|
-
...cssShared,
|
|
142
|
-
...sharedObject,
|
|
143
|
-
[colorKey]: getColor('red'),
|
|
144
|
-
background: colors['red'],
|
|
145
|
-
});
|
|
146
|
-
`,
|
|
147
|
-
errors: [{ messageId: 'no-exported-styles' }],
|
|
148
|
-
},
|
|
149
|
-
{
|
|
150
|
-
name: 'Export let css',
|
|
151
|
-
code: `
|
|
152
|
-
import { css } from '@compiled/react';
|
|
153
|
-
|
|
154
|
-
export let styles = css({});
|
|
155
|
-
`,
|
|
156
|
-
errors: [{ messageId: 'no-exported-styles' }],
|
|
157
|
-
},
|
|
158
|
-
{
|
|
159
|
-
name: 'Export style in object',
|
|
160
|
-
code: `
|
|
161
|
-
import { css } from '@compiled/react';
|
|
162
|
-
|
|
163
|
-
const styles = css({});
|
|
164
|
-
|
|
165
|
-
export { styles };
|
|
166
|
-
`,
|
|
167
|
-
errors: [{ messageId: 'no-exported-styles' }],
|
|
168
|
-
},
|
|
169
|
-
{
|
|
170
|
-
name: 'Exporting nested style',
|
|
171
|
-
code: `
|
|
172
|
-
import { css } from '@compiled/react';
|
|
173
|
-
|
|
174
|
-
const styles = {
|
|
175
|
-
primary: css({}),
|
|
176
|
-
};
|
|
177
|
-
|
|
178
|
-
export { styles };
|
|
179
|
-
`,
|
|
180
|
-
errors: [{ messageId: 'no-exported-styles' }],
|
|
181
|
-
},
|
|
182
|
-
{
|
|
183
|
-
name: 'Exporting styled components',
|
|
184
|
-
code: `
|
|
185
|
-
import styled from 'styled-components'
|
|
186
|
-
|
|
187
|
-
export const PasswordInput = styled.input.attrs(props => ({
|
|
188
|
-
type: "password"
|
|
189
|
-
}))
|
|
190
|
-
`,
|
|
191
|
-
errors: [{ messageId: 'no-exported-styles' }],
|
|
192
|
-
},
|
|
193
|
-
{
|
|
194
|
-
name: 'Exporting styled component with base component',
|
|
195
|
-
code: `
|
|
196
|
-
import styled from 'styled-components'
|
|
197
|
-
|
|
198
|
-
const BaseComponent = styled.div({});
|
|
199
|
-
export const Component = styled(BaseComponent)({});
|
|
200
|
-
`,
|
|
201
|
-
errors: [{ messageId: 'no-exported-styles' }],
|
|
202
|
-
},
|
|
203
|
-
{
|
|
204
|
-
name: 'Exporting styled component from compiled',
|
|
205
|
-
code: `
|
|
206
|
-
import { styled as styled2 } from '@compiled/react'
|
|
207
|
-
|
|
208
|
-
export const Component = styled2.div({
|
|
209
|
-
margin: \`\${token('space.200', '16px')} 0\`,
|
|
210
|
-
})
|
|
211
|
-
`,
|
|
212
|
-
errors: [{ messageId: 'no-exported-styles' }],
|
|
213
|
-
},
|
|
214
|
-
],
|
|
215
|
-
},
|
|
216
|
-
);
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { createLintRule } from '../utils/create-rule';
|
|
2
|
-
import {
|
|
3
|
-
isCss,
|
|
4
|
-
isStyled,
|
|
5
|
-
isKeyframes,
|
|
6
|
-
isCssMap,
|
|
7
|
-
isXcss,
|
|
8
|
-
type SupportedNameChecker,
|
|
9
|
-
} from '@atlaskit/eslint-utils/is-supported-import';
|
|
10
|
-
import type { JSONSchema4 } from '@typescript-eslint/utils/dist/json-schema';
|
|
11
|
-
import { createNoExportedRule } from '@atlaskit/eslint-utils/create-no-exported-rule';
|
|
12
|
-
|
|
13
|
-
const schema: JSONSchema4 = [
|
|
14
|
-
{
|
|
15
|
-
type: 'object',
|
|
16
|
-
properties: {
|
|
17
|
-
importSources: {
|
|
18
|
-
type: 'array',
|
|
19
|
-
items: { type: 'string' },
|
|
20
|
-
uniqueItems: true,
|
|
21
|
-
},
|
|
22
|
-
},
|
|
23
|
-
},
|
|
24
|
-
];
|
|
25
|
-
|
|
26
|
-
const supportedImports: readonly SupportedNameChecker[] = [
|
|
27
|
-
isCss,
|
|
28
|
-
isCssMap,
|
|
29
|
-
isKeyframes,
|
|
30
|
-
isXcss,
|
|
31
|
-
isStyled,
|
|
32
|
-
];
|
|
33
|
-
|
|
34
|
-
export const rule = createLintRule({
|
|
35
|
-
meta: {
|
|
36
|
-
name: 'no-exported-styles',
|
|
37
|
-
docs: {
|
|
38
|
-
description: 'Disallows exports of css, keyframes, styled and xcss',
|
|
39
|
-
recommended: true,
|
|
40
|
-
severity: 'error',
|
|
41
|
-
},
|
|
42
|
-
messages: {
|
|
43
|
-
'no-exported-styles':
|
|
44
|
-
'Styles from css, cssMap, keyframes, styled and xcss should not be exported. All styles should be defined and used in the same file instead.',
|
|
45
|
-
},
|
|
46
|
-
type: 'problem',
|
|
47
|
-
schema,
|
|
48
|
-
},
|
|
49
|
-
create: createNoExportedRule(supportedImports, 'no-exported-styles'),
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
export default rule;
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
Blocks global styles through CSS-in-JS and CSS module imports.
|
|
2
|
-
|
|
3
|
-
Use local styles so that style dependencies are statically resolvable.
|
|
4
|
-
|
|
5
|
-
The only global styling that should be used is `@atlaskit/css-reset`.
|
|
6
|
-
|
|
7
|
-
## Examples
|
|
8
|
-
|
|
9
|
-
### Incorrect
|
|
10
|
-
|
|
11
|
-
```tsx
|
|
12
|
-
import { Global } from '@emotion/react';
|
|
13
|
-
|
|
14
|
-
<Global
|
|
15
|
-
styles={{
|
|
16
|
-
'.some-class': {
|
|
17
|
-
fontSize: 50,
|
|
18
|
-
textAlign: 'center',
|
|
19
|
-
},
|
|
20
|
-
}}
|
|
21
|
-
/>;
|
|
22
|
-
```
|
|
23
|
-
|
|
24
|
-
```tsx
|
|
25
|
-
import { createGlobalStyle } from 'styled-components';
|
|
26
|
-
|
|
27
|
-
const GlobalStyle = createGlobalStyle({
|
|
28
|
-
body: {
|
|
29
|
-
margin: 0,
|
|
30
|
-
},
|
|
31
|
-
});
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
```tsx
|
|
35
|
-
import { injectGlobal } from 'styled-components';
|
|
36
|
-
|
|
37
|
-
injectGlobal({
|
|
38
|
-
body: {
|
|
39
|
-
margin: 0,
|
|
40
|
-
},
|
|
41
|
-
});
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
```tsx
|
|
45
|
-
<style>
|
|
46
|
-
{`
|
|
47
|
-
.some-class {
|
|
48
|
-
color: red;
|
|
49
|
-
}
|
|
50
|
-
`}
|
|
51
|
-
</style>
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
### Correct
|
|
55
|
-
|
|
56
|
-
```tsx
|
|
57
|
-
import '@atlaskit/css-reset';
|
|
58
|
-
```
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { tester } from '../../__tests__/utils/_tester';
|
|
2
|
-
import rule from '../index';
|
|
3
|
-
|
|
4
|
-
tester.run('no-css-modules', rule, {
|
|
5
|
-
valid: [
|
|
6
|
-
"import 'styles-css';",
|
|
7
|
-
"import 'less';",
|
|
8
|
-
"import 'sass-module';",
|
|
9
|
-
"import 'something-scss-something';",
|
|
10
|
-
],
|
|
11
|
-
invalid: [
|
|
12
|
-
{
|
|
13
|
-
name: '.css import',
|
|
14
|
-
code: "import 'styles.css';",
|
|
15
|
-
errors: [{ messageId: 'no-css-modules' }],
|
|
16
|
-
},
|
|
17
|
-
{
|
|
18
|
-
name: '.less import',
|
|
19
|
-
code: "import 'styles.less';",
|
|
20
|
-
errors: [{ messageId: 'no-css-modules' }],
|
|
21
|
-
},
|
|
22
|
-
{
|
|
23
|
-
name: '.sass import',
|
|
24
|
-
code: "import 'styles.sass';",
|
|
25
|
-
errors: [{ messageId: 'no-css-modules' }],
|
|
26
|
-
},
|
|
27
|
-
{
|
|
28
|
-
name: '.scss import',
|
|
29
|
-
code: "import 'styles.scss';",
|
|
30
|
-
errors: [{ messageId: 'no-css-modules' }],
|
|
31
|
-
},
|
|
32
|
-
],
|
|
33
|
-
});
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { tester } from '../../__tests__/utils/_tester';
|
|
2
|
-
import rule from '../index';
|
|
3
|
-
|
|
4
|
-
tester.run('no-global-styles', rule, {
|
|
5
|
-
valid: [
|
|
6
|
-
"import { css } from '@emotion/react';",
|
|
7
|
-
"import { keyframes } from '@emotion/core';",
|
|
8
|
-
"import styled from 'styled-components';",
|
|
9
|
-
],
|
|
10
|
-
invalid: [
|
|
11
|
-
{
|
|
12
|
-
name: '[@emotion/react] Global',
|
|
13
|
-
code: "import { Global } from '@emotion/react';",
|
|
14
|
-
errors: [{ messageId: 'no-global-styles' }],
|
|
15
|
-
},
|
|
16
|
-
{
|
|
17
|
-
name: '[@emotion/core] Global',
|
|
18
|
-
code: "import { Global } from '@emotion/core';",
|
|
19
|
-
errors: [{ messageId: 'no-global-styles' }],
|
|
20
|
-
},
|
|
21
|
-
{
|
|
22
|
-
name: '[styled-components] injectGlobal',
|
|
23
|
-
code: "import { injectGlobal } from 'styled-components';",
|
|
24
|
-
errors: [{ messageId: 'no-global-styles' }],
|
|
25
|
-
},
|
|
26
|
-
{
|
|
27
|
-
name: '[styled-components] createGlobalStyle',
|
|
28
|
-
code: "import { createGlobalStyle } from 'styled-components';",
|
|
29
|
-
errors: [{ messageId: 'no-global-styles' }],
|
|
30
|
-
},
|
|
31
|
-
{
|
|
32
|
-
name: 'aliasing',
|
|
33
|
-
code: "import { Global as EmotionGlobal } from '@emotion/react';",
|
|
34
|
-
errors: [{ messageId: 'no-global-styles' }],
|
|
35
|
-
},
|
|
36
|
-
{
|
|
37
|
-
name: 'style tag',
|
|
38
|
-
code: `
|
|
39
|
-
<style>
|
|
40
|
-
{'.my-class { color: red; }'}
|
|
41
|
-
</style>
|
|
42
|
-
`,
|
|
43
|
-
errors: [{ messageId: 'no-global-styles' }],
|
|
44
|
-
},
|
|
45
|
-
],
|
|
46
|
-
});
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import type * as ESTree from 'eslint-codemod-utils';
|
|
2
|
-
|
|
3
|
-
import { createLintRule } from '../utils/create-rule';
|
|
4
|
-
|
|
5
|
-
const restrictedFileTypes = ['.css', '.less', '.sass', '.scss'];
|
|
6
|
-
|
|
7
|
-
const restrictedImports = {
|
|
8
|
-
'@emotion/core': ['Global'],
|
|
9
|
-
'@emotion/react': ['Global'],
|
|
10
|
-
'styled-components': ['createGlobalStyle', 'injectGlobal'],
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
type RestrictedImportSource = keyof typeof restrictedImports;
|
|
14
|
-
function isRestrictedImportSource(importSource: string): importSource is RestrictedImportSource {
|
|
15
|
-
return importSource in restrictedImports;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export const rule = createLintRule({
|
|
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: 'error',
|
|
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
|
-
}
|
|
42
|
-
|
|
43
|
-
function checkImports(node: ESTree.ImportDeclaration) {
|
|
44
|
-
const importSource = node.source.value as string;
|
|
45
|
-
if (!isRestrictedImportSource(importSource)) {
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
for (const importName of restrictedImports[importSource]) {
|
|
50
|
-
const specifier = node.specifiers
|
|
51
|
-
.filter(isImportSpecifier)
|
|
52
|
-
.find((specifier) => specifier.imported.name === importName);
|
|
53
|
-
|
|
54
|
-
if (specifier) {
|
|
55
|
-
context.report({
|
|
56
|
-
node: specifier,
|
|
57
|
-
messageId: 'no-global-styles',
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
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
|
-
},
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
export default rule;
|
|
79
|
-
|
|
80
|
-
function isImportSpecifier(node: ESTree.Node): node is ESTree.ImportSpecifier {
|
|
81
|
-
return node.type === 'ImportSpecifier';
|
|
82
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
Blocks the `!important` flag in style declarations.
|
|
2
|
-
|
|
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.
|
|
6
|
-
|
|
7
|
-
The use of `!important` is a code smell and greatly impacts readability and determinism.
|
|
8
|
-
|
|
9
|
-
## Examples
|
|
10
|
-
|
|
11
|
-
### Incorrect
|
|
12
|
-
|
|
13
|
-
```js
|
|
14
|
-
import { css } from '@compiled/react';
|
|
15
|
-
import { token } from '@atlaskit/tokens';
|
|
16
|
-
|
|
17
|
-
const styles = css({
|
|
18
|
-
color: `${token('color.text.danger')}!important`,
|
|
19
|
-
});
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
### Correct
|
|
23
|
-
|
|
24
|
-
```js
|
|
25
|
-
import { css } from '@compiled/react';
|
|
26
|
-
import { token } from '@atlaskit/tokens';
|
|
27
|
-
|
|
28
|
-
const styles = css({
|
|
29
|
-
color: token('color.text.danger'),
|
|
30
|
-
});
|
|
31
|
-
```
|
|
@@ -1,165 +0,0 @@
|
|
|
1
|
-
import { tester } from '../../__tests__/utils/_tester';
|
|
2
|
-
import rule from '../index';
|
|
3
|
-
|
|
4
|
-
tester.run('no-important-styles', rule, {
|
|
5
|
-
valid: [
|
|
6
|
-
`
|
|
7
|
-
import { css } from '@compiled/react';
|
|
8
|
-
|
|
9
|
-
const styles = css({
|
|
10
|
-
color: 'red'
|
|
11
|
-
});
|
|
12
|
-
`,
|
|
13
|
-
{
|
|
14
|
-
name: 'custom import sources (subtractive)',
|
|
15
|
-
code: `
|
|
16
|
-
import { css } from '@compiled/react';
|
|
17
|
-
|
|
18
|
-
const styles = css({
|
|
19
|
-
color: 'red !important'
|
|
20
|
-
});
|
|
21
|
-
`,
|
|
22
|
-
options: [
|
|
23
|
-
{
|
|
24
|
-
importSources: [],
|
|
25
|
-
},
|
|
26
|
-
],
|
|
27
|
-
},
|
|
28
|
-
],
|
|
29
|
-
invalid: [
|
|
30
|
-
{
|
|
31
|
-
name: 'basic test case',
|
|
32
|
-
code: `
|
|
33
|
-
import { css } from '@compiled/react';
|
|
34
|
-
|
|
35
|
-
const styles = css({
|
|
36
|
-
color: 'red !important'
|
|
37
|
-
});
|
|
38
|
-
`,
|
|
39
|
-
errors: [{ messageId: 'no-important-styles' }],
|
|
40
|
-
},
|
|
41
|
-
{
|
|
42
|
-
name: 'whitespace handling',
|
|
43
|
-
code: `
|
|
44
|
-
import { css } from '@compiled/react';
|
|
45
|
-
|
|
46
|
-
const styles = css({
|
|
47
|
-
color: 'red !important '
|
|
48
|
-
});
|
|
49
|
-
`,
|
|
50
|
-
errors: [{ messageId: 'no-important-styles' }],
|
|
51
|
-
},
|
|
52
|
-
{
|
|
53
|
-
name: 'nesting',
|
|
54
|
-
code: `
|
|
55
|
-
import { css } from '@compiled/react';
|
|
56
|
-
|
|
57
|
-
const styles = css({
|
|
58
|
-
div: {
|
|
59
|
-
padding: '8px',
|
|
60
|
-
span: {
|
|
61
|
-
padding: '8px',
|
|
62
|
-
color: 'blue!important',
|
|
63
|
-
margin: '8px'
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
`,
|
|
68
|
-
errors: [{ messageId: 'no-important-styles' }],
|
|
69
|
-
},
|
|
70
|
-
{
|
|
71
|
-
name: 'styled API',
|
|
72
|
-
code: `
|
|
73
|
-
import { styled } from '@compiled/react';
|
|
74
|
-
|
|
75
|
-
const Component = styled.div({
|
|
76
|
-
div: {
|
|
77
|
-
padding: '8px',
|
|
78
|
-
span: {
|
|
79
|
-
padding: '8px',
|
|
80
|
-
color: 'blue!important',
|
|
81
|
-
margin: '8px'
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
`,
|
|
86
|
-
errors: [{ messageId: 'no-important-styles' }],
|
|
87
|
-
},
|
|
88
|
-
{
|
|
89
|
-
name: 'keyframes API',
|
|
90
|
-
code: `
|
|
91
|
-
import { keyframes } from '@compiled/react';
|
|
92
|
-
|
|
93
|
-
const fadeOut = keyframes({
|
|
94
|
-
from: {
|
|
95
|
-
opacity: '1 !important',
|
|
96
|
-
},
|
|
97
|
-
to: {
|
|
98
|
-
opacity: 0,
|
|
99
|
-
},
|
|
100
|
-
});
|
|
101
|
-
`,
|
|
102
|
-
errors: [{ messageId: 'no-important-styles' }],
|
|
103
|
-
},
|
|
104
|
-
{
|
|
105
|
-
name: 'cssMap API',
|
|
106
|
-
code: `
|
|
107
|
-
import { cssMap } from '@compiled/react';
|
|
108
|
-
|
|
109
|
-
const borderStyleMap = cssMap({
|
|
110
|
-
none: { borderStyle: 'none !important' },
|
|
111
|
-
solid: { borderStyle: 'solid' },
|
|
112
|
-
});
|
|
113
|
-
`,
|
|
114
|
-
errors: [{ messageId: 'no-important-styles' }],
|
|
115
|
-
},
|
|
116
|
-
{
|
|
117
|
-
name: 'xcss API',
|
|
118
|
-
code: `
|
|
119
|
-
import { xcss } from '@atlaskit/primitives';
|
|
120
|
-
|
|
121
|
-
const styles = xcss({
|
|
122
|
-
display: 'block !important'
|
|
123
|
-
});
|
|
124
|
-
`,
|
|
125
|
-
errors: [{ messageId: 'no-important-styles' }],
|
|
126
|
-
},
|
|
127
|
-
{
|
|
128
|
-
name: 'custom import sources (additive)',
|
|
129
|
-
code: `
|
|
130
|
-
import { css } from 'custom-library';
|
|
131
|
-
|
|
132
|
-
const styles = css({
|
|
133
|
-
color: 'red !important'
|
|
134
|
-
});
|
|
135
|
-
`,
|
|
136
|
-
errors: [{ messageId: 'no-important-styles' }],
|
|
137
|
-
options: [{ importSources: ['custom-library'] }],
|
|
138
|
-
},
|
|
139
|
-
{
|
|
140
|
-
name: 'template string',
|
|
141
|
-
code: `
|
|
142
|
-
import { css } from '@compiled/react';
|
|
143
|
-
|
|
144
|
-
const color = 'red';
|
|
145
|
-
|
|
146
|
-
const styles = css({
|
|
147
|
-
color: \`\${color}!important\`
|
|
148
|
-
});
|
|
149
|
-
`,
|
|
150
|
-
errors: [{ messageId: 'no-important-styles' }],
|
|
151
|
-
},
|
|
152
|
-
{
|
|
153
|
-
name: 'uses default when options object is provided without importSources',
|
|
154
|
-
code: `
|
|
155
|
-
import { css } from '@compiled/react';
|
|
156
|
-
|
|
157
|
-
const styles = css({
|
|
158
|
-
color: 'red !important'
|
|
159
|
-
});
|
|
160
|
-
`,
|
|
161
|
-
errors: [{ messageId: 'no-important-styles' }],
|
|
162
|
-
options: [{}],
|
|
163
|
-
},
|
|
164
|
-
],
|
|
165
|
-
});
|