@atlaskit/eslint-plugin-ui-styling-standard 0.18.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 +8 -0
- package/package.json +1 -1
- package/afm-cc/tsconfig.json +0 -28
- package/afm-jira/tsconfig.json +0 -27
- 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 -177
- 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,102 +0,0 @@
|
|
|
1
|
-
import { tester } from '../../__tests__/utils/_tester';
|
|
2
|
-
import rule from '../index';
|
|
3
|
-
|
|
4
|
-
tester.run('local-cx-xcss', rule, {
|
|
5
|
-
valid: [
|
|
6
|
-
`
|
|
7
|
-
import { cx } from '@compiled/react';
|
|
8
|
-
|
|
9
|
-
<Component xcss={cx({})} />
|
|
10
|
-
`,
|
|
11
|
-
`
|
|
12
|
-
import { cx } from '@compiled/react';
|
|
13
|
-
|
|
14
|
-
<Component innerXcss={cx({})} />
|
|
15
|
-
`,
|
|
16
|
-
`
|
|
17
|
-
import { cx, cssMap } from '@compiled/react';
|
|
18
|
-
|
|
19
|
-
const styles = cssMap({
|
|
20
|
-
text: { color: 'red' },
|
|
21
|
-
bg: { background: 'blue' },
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
<Button innerXcss={cx(styles.text, styles.bg)} />;
|
|
25
|
-
`,
|
|
26
|
-
`
|
|
27
|
-
// Ignore cx usage not from compiled
|
|
28
|
-
const styles = cssMap({
|
|
29
|
-
text: { color: 'red' },
|
|
30
|
-
bg: { background: 'blue' },
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
const joinedStyles = cx(styles.text, styles.bg);
|
|
34
|
-
|
|
35
|
-
<Button xcss={joinedStyles} />;
|
|
36
|
-
`,
|
|
37
|
-
`
|
|
38
|
-
// Ignore cx usage not from compiled
|
|
39
|
-
const styles = cx({});
|
|
40
|
-
|
|
41
|
-
<Component xcss={styles} />
|
|
42
|
-
`,
|
|
43
|
-
`
|
|
44
|
-
// Ignore cx usage where
|
|
45
|
-
// the library is not specified in additionalCompiledLibraries
|
|
46
|
-
import { cx } from 'custom-package';
|
|
47
|
-
const styles = cx({});
|
|
48
|
-
|
|
49
|
-
<Component xcss={styles} />
|
|
50
|
-
`,
|
|
51
|
-
],
|
|
52
|
-
invalid: [
|
|
53
|
-
{
|
|
54
|
-
code: `
|
|
55
|
-
import { cx } from '@compiled/react';
|
|
56
|
-
const styles = cx({});
|
|
57
|
-
|
|
58
|
-
<Component xcss={styles} />
|
|
59
|
-
`,
|
|
60
|
-
errors: [{ messageId: 'local-cx-xcss' }],
|
|
61
|
-
},
|
|
62
|
-
{
|
|
63
|
-
code: `
|
|
64
|
-
import { cx, cssMap } from '@compiled/react';
|
|
65
|
-
|
|
66
|
-
const styles = cssMap({
|
|
67
|
-
text: { color: 'red' },
|
|
68
|
-
bg: { background: 'blue' },
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
const joinedStyles = cx(styles.text, styles.bg);
|
|
72
|
-
|
|
73
|
-
<Button xcss={joinedStyles} />;
|
|
74
|
-
`,
|
|
75
|
-
errors: [{ messageId: 'local-cx-xcss' }],
|
|
76
|
-
},
|
|
77
|
-
{
|
|
78
|
-
code: `
|
|
79
|
-
import { cx } from '@compiled/react';
|
|
80
|
-
const styles = cx({});
|
|
81
|
-
|
|
82
|
-
<Component innerXcss={styles} />
|
|
83
|
-
`,
|
|
84
|
-
errors: [{ messageId: 'local-cx-xcss' }],
|
|
85
|
-
},
|
|
86
|
-
{
|
|
87
|
-
code: `
|
|
88
|
-
import { cx, cssMap } from '@compiled/react';
|
|
89
|
-
|
|
90
|
-
const styles = cssMap({
|
|
91
|
-
text: { color: 'red' },
|
|
92
|
-
bg: { background: 'blue' },
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
const joinedStyles = cx(styles.text, styles.bg);
|
|
96
|
-
|
|
97
|
-
<Button innerXcss={joinedStyles} />;
|
|
98
|
-
`,
|
|
99
|
-
errors: [{ messageId: 'local-cx-xcss' }],
|
|
100
|
-
},
|
|
101
|
-
],
|
|
102
|
-
});
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import type { Rule } from 'eslint';
|
|
2
|
-
import type { JSXAttribute } from 'estree-jsx';
|
|
3
|
-
|
|
4
|
-
import { createLintRule } from '../utils/create-rule';
|
|
5
|
-
import { CSS_IN_JS_IMPORTS, isCxFunction } from '@atlaskit/eslint-utils/is-supported-import';
|
|
6
|
-
|
|
7
|
-
const IMPORT_SOURCES = [CSS_IN_JS_IMPORTS.compiled, CSS_IN_JS_IMPORTS.atlaskitCss];
|
|
8
|
-
|
|
9
|
-
function getParentJSXAttribute(node: Rule.Node): JSXAttribute | null {
|
|
10
|
-
let parent: Rule.Node | null = node.parent;
|
|
11
|
-
|
|
12
|
-
while (parent && parent.type !== 'JSXAttribute') {
|
|
13
|
-
parent = parent.parent;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
if (parent && parent.type === 'JSXAttribute') {
|
|
17
|
-
return parent;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
return null;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export const rule = createLintRule({
|
|
24
|
-
meta: {
|
|
25
|
-
name: 'local-cx-xcss',
|
|
26
|
-
docs: {
|
|
27
|
-
description:
|
|
28
|
-
'Ensures the cx() function, which is part of the XCSS API, is only used within the xcss prop. This aids tracking what styles are applied to a jsx element.',
|
|
29
|
-
recommended: true,
|
|
30
|
-
severity: 'error',
|
|
31
|
-
},
|
|
32
|
-
messages: {
|
|
33
|
-
'local-cx-xcss':
|
|
34
|
-
'The cx function should only be declared inside the xcss prop to simplify tracking styles that are applied to a jsx element.',
|
|
35
|
-
},
|
|
36
|
-
type: 'problem',
|
|
37
|
-
},
|
|
38
|
-
create(context) {
|
|
39
|
-
return {
|
|
40
|
-
'CallExpression[callee.name="cx"]': (node: Rule.Node) => {
|
|
41
|
-
if (
|
|
42
|
-
node.type === 'CallExpression' &&
|
|
43
|
-
isCxFunction(node.callee, context.getScope().references, IMPORT_SOURCES)
|
|
44
|
-
) {
|
|
45
|
-
const parentJSXAttribute = getParentJSXAttribute(node);
|
|
46
|
-
const propName = parentJSXAttribute?.name.name.toString();
|
|
47
|
-
|
|
48
|
-
if (propName && /[xX]css$/.test(propName)) {
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
context.report({
|
|
53
|
-
node,
|
|
54
|
-
messageId: 'local-cx-xcss',
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
},
|
|
58
|
-
};
|
|
59
|
-
},
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
export default rule;
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
Blocks passing array arguments to style declaration functions.
|
|
2
|
-
|
|
3
|
-
## Examples
|
|
4
|
-
|
|
5
|
-
### Incorrect
|
|
6
|
-
|
|
7
|
-
```tsx
|
|
8
|
-
import { css } from '@compiled/react';
|
|
9
|
-
|
|
10
|
-
const styles = css([{ width: 100 }, { height: 100 }]);
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
```tsx
|
|
14
|
-
import { styled } from '@compiled/react';
|
|
15
|
-
|
|
16
|
-
const styles = css([{ width: 100 }, ...items]);
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
### Correct
|
|
20
|
-
|
|
21
|
-
```tsx
|
|
22
|
-
import { css } from '@compiled/react';
|
|
23
|
-
|
|
24
|
-
const styles = css({ width: 100 }, { height: 100 });
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
```tsx
|
|
28
|
-
import { css } from '@compiled/react';
|
|
29
|
-
|
|
30
|
-
const styles = css({ width: 100 }, ...items);
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
## Options
|
|
34
|
-
|
|
35
|
-
### `importSources: string[]`
|
|
36
|
-
|
|
37
|
-
By default, this rule will check styles using:
|
|
38
|
-
|
|
39
|
-
- `@atlaskit/css`
|
|
40
|
-
- `@atlaskit/primitives`
|
|
41
|
-
- `@compiled/react`
|
|
42
|
-
- `@emotion/react`
|
|
43
|
-
- `@emotion/core`
|
|
44
|
-
- `@emotion/styled`
|
|
45
|
-
- `styled-components`
|
|
46
|
-
|
|
47
|
-
Override this list with the `importSources` option, which accepts an array of package names.
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import { typescriptEslintTester } from '../../__tests__/utils/_tester';
|
|
2
|
-
import rule from '../index';
|
|
3
|
-
|
|
4
|
-
typescriptEslintTester.run(
|
|
5
|
-
'no-nested-selectors',
|
|
6
|
-
// @ts-expect-error
|
|
7
|
-
rule,
|
|
8
|
-
{
|
|
9
|
-
valid: [],
|
|
10
|
-
invalid: [
|
|
11
|
-
{
|
|
12
|
-
name: 'single array argument',
|
|
13
|
-
code: `
|
|
14
|
-
import { css } from '@compiled/react';
|
|
15
|
-
const styles = css([
|
|
16
|
-
{ width: 100 },
|
|
17
|
-
{ height: 100 }
|
|
18
|
-
]);
|
|
19
|
-
`,
|
|
20
|
-
output: `
|
|
21
|
-
import { css } from '@compiled/react';
|
|
22
|
-
const styles = css({ width: 100 }, { height: 100 });
|
|
23
|
-
`,
|
|
24
|
-
errors: [{ messageId: 'no-array-arguments' }],
|
|
25
|
-
},
|
|
26
|
-
{
|
|
27
|
-
name: 'multiple array arguments',
|
|
28
|
-
code: `
|
|
29
|
-
import { css } from '@compiled/react';
|
|
30
|
-
const styles = css(
|
|
31
|
-
[
|
|
32
|
-
{ width: 100 },
|
|
33
|
-
{ height: 100 }
|
|
34
|
-
],
|
|
35
|
-
[
|
|
36
|
-
{ color: 'red' }
|
|
37
|
-
]
|
|
38
|
-
);
|
|
39
|
-
`,
|
|
40
|
-
output: `
|
|
41
|
-
import { css } from '@compiled/react';
|
|
42
|
-
const styles = css(
|
|
43
|
-
{ width: 100 }, { height: 100 },
|
|
44
|
-
{ color: 'red' }
|
|
45
|
-
);
|
|
46
|
-
`,
|
|
47
|
-
errors: [{ messageId: 'no-array-arguments' }, { messageId: 'no-array-arguments' }],
|
|
48
|
-
},
|
|
49
|
-
{
|
|
50
|
-
name: 'interspersed array arguments',
|
|
51
|
-
code: `
|
|
52
|
-
import { css } from '@compiled/react';
|
|
53
|
-
const styles = css(
|
|
54
|
-
{ a: 1 },
|
|
55
|
-
[
|
|
56
|
-
{ width: 100 },
|
|
57
|
-
{ height: 100 }
|
|
58
|
-
],
|
|
59
|
-
{ b: 2 },
|
|
60
|
-
[
|
|
61
|
-
{ color: 'red' },
|
|
62
|
-
{ opacity: 0.5 },
|
|
63
|
-
],
|
|
64
|
-
{ c: 3 }
|
|
65
|
-
);
|
|
66
|
-
`,
|
|
67
|
-
output: `
|
|
68
|
-
import { css } from '@compiled/react';
|
|
69
|
-
const styles = css(
|
|
70
|
-
{ a: 1 },
|
|
71
|
-
{ width: 100 }, { height: 100 },
|
|
72
|
-
{ b: 2 },
|
|
73
|
-
{ color: 'red' }, { opacity: 0.5 },
|
|
74
|
-
{ c: 3 }
|
|
75
|
-
);
|
|
76
|
-
`,
|
|
77
|
-
errors: [{ messageId: 'no-array-arguments' }, { messageId: 'no-array-arguments' }],
|
|
78
|
-
},
|
|
79
|
-
{
|
|
80
|
-
name: 'empty array argument',
|
|
81
|
-
code: `
|
|
82
|
-
import { css } from '@compiled/react';
|
|
83
|
-
const styles = css(
|
|
84
|
-
[],
|
|
85
|
-
{ color: 'red' },
|
|
86
|
-
[]
|
|
87
|
-
);
|
|
88
|
-
`,
|
|
89
|
-
errors: [{ messageId: 'no-array-arguments' }, { messageId: 'no-array-arguments' }],
|
|
90
|
-
},
|
|
91
|
-
{
|
|
92
|
-
name: 'spread in array',
|
|
93
|
-
code: `
|
|
94
|
-
import { css } from '@compiled/react';
|
|
95
|
-
const styles = css([
|
|
96
|
-
...items
|
|
97
|
-
]);
|
|
98
|
-
`,
|
|
99
|
-
output: `
|
|
100
|
-
import { css } from '@compiled/react';
|
|
101
|
-
const styles = css(...items);
|
|
102
|
-
`,
|
|
103
|
-
errors: [{ messageId: 'no-array-arguments' }],
|
|
104
|
-
},
|
|
105
|
-
],
|
|
106
|
-
},
|
|
107
|
-
);
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import type { Expression, SpreadElement } from 'estree';
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
getImportSources,
|
|
5
|
-
hasStyleObjectArguments,
|
|
6
|
-
} from '@atlaskit/eslint-utils/is-supported-import';
|
|
7
|
-
import { createLintRule } from '../utils/create-rule';
|
|
8
|
-
import type { JSONSchema4 } from '@typescript-eslint/utils/dist/json-schema';
|
|
9
|
-
|
|
10
|
-
const schema: JSONSchema4 = [
|
|
11
|
-
{
|
|
12
|
-
type: 'object',
|
|
13
|
-
properties: {
|
|
14
|
-
importSources: {
|
|
15
|
-
type: 'array',
|
|
16
|
-
items: { type: 'string' },
|
|
17
|
-
uniqueItems: true,
|
|
18
|
-
},
|
|
19
|
-
},
|
|
20
|
-
},
|
|
21
|
-
];
|
|
22
|
-
|
|
23
|
-
export const rule = createLintRule({
|
|
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: 'error',
|
|
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.getScope();
|
|
44
|
-
|
|
45
|
-
if (!hasStyleObjectArguments(node.callee, references, importSources)) {
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
|
|
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
|
-
}
|
|
67
|
-
|
|
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.getSourceCode().getText(element));
|
|
75
|
-
|
|
76
|
-
return fixer.replaceText(argument, items.join(', '));
|
|
77
|
-
},
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
},
|
|
82
|
-
};
|
|
83
|
-
},
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
export default rule;
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
Blocks the `className` prop, which encourages unsafe global styles and cannot be statically
|
|
2
|
-
resolved.
|
|
3
|
-
|
|
4
|
-
Use the `css` prop for styling, with props for configuration and `xcss` for bounded overrides.
|
|
5
|
-
|
|
6
|
-
## Examples
|
|
7
|
-
|
|
8
|
-
### Incorrect
|
|
9
|
-
|
|
10
|
-
```tsx
|
|
11
|
-
<div className="my-class">
|
|
12
|
-
```
|
|
13
|
-
|
|
14
|
-
```tsx
|
|
15
|
-
<MyComponent className={isDisabled ? 'disabled' : undefined} />
|
|
16
|
-
```
|
|
17
|
-
|
|
18
|
-
### Correct
|
|
19
|
-
|
|
20
|
-
```tsx
|
|
21
|
-
import { css } from '@compiled/react';
|
|
22
|
-
import { token } from '@atlaskit/tokens';
|
|
23
|
-
|
|
24
|
-
const myStyles = css({ padding: token('space.100') });
|
|
25
|
-
|
|
26
|
-
<div css={myStyles} />;
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
```tsx
|
|
30
|
-
<MyComponent isDisabled={isDisabled} />
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
```tsx
|
|
34
|
-
import { Checkbox } from '@atlaskit/checkbox';
|
|
35
|
-
|
|
36
|
-
<Checkbox xcss={{ alignItems: 'center' }} />;
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
## FAQ
|
|
40
|
-
|
|
41
|
-
### What if I'm using `className` to target elements with JavaScript?
|
|
42
|
-
|
|
43
|
-
There are some cases where a selector is required to integrate with a 3rd party library, such as
|
|
44
|
-
legacy code using jQuery.
|
|
45
|
-
|
|
46
|
-
Use a `ref` if possible. Otherwise, if you _must_ have a selector, use a `data-*` attribute that
|
|
47
|
-
gives enough context and is unique enough, for example `data-editor-table-target="true"`.
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { tester } from '../../__tests__/utils/_tester';
|
|
2
|
-
import rule from '../index';
|
|
3
|
-
|
|
4
|
-
tester.run('no-classname-prop', rule, {
|
|
5
|
-
valid: [
|
|
6
|
-
{
|
|
7
|
-
code: `
|
|
8
|
-
<div />
|
|
9
|
-
`,
|
|
10
|
-
},
|
|
11
|
-
],
|
|
12
|
-
invalid: [
|
|
13
|
-
{
|
|
14
|
-
// Basic test case
|
|
15
|
-
code: `
|
|
16
|
-
<div className={myStyles} />
|
|
17
|
-
`,
|
|
18
|
-
errors: [{ messageId: 'no-classname-prop' }],
|
|
19
|
-
},
|
|
20
|
-
{
|
|
21
|
-
// String
|
|
22
|
-
code: `
|
|
23
|
-
<div className="my-class" />
|
|
24
|
-
`,
|
|
25
|
-
errors: [{ messageId: 'no-classname-prop' }],
|
|
26
|
-
},
|
|
27
|
-
{
|
|
28
|
-
// With non-primitive elements
|
|
29
|
-
code: `
|
|
30
|
-
import { styled } from '@compiled/react';
|
|
31
|
-
|
|
32
|
-
const Component = styled.div({});
|
|
33
|
-
|
|
34
|
-
<Component className="my-class" />
|
|
35
|
-
`,
|
|
36
|
-
errors: [{ messageId: 'no-classname-prop' }],
|
|
37
|
-
},
|
|
38
|
-
],
|
|
39
|
-
});
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { isNodeOfType, type Node } from 'eslint-codemod-utils';
|
|
2
|
-
|
|
3
|
-
import { createLintRule } from '../utils/create-rule';
|
|
4
|
-
|
|
5
|
-
export const rule = createLintRule({
|
|
6
|
-
meta: {
|
|
7
|
-
name: 'no-classname-prop',
|
|
8
|
-
docs: {
|
|
9
|
-
description: 'Disallows usage of the `className` prop in JSX',
|
|
10
|
-
recommended: true,
|
|
11
|
-
severity: 'error',
|
|
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
|
-
|
|
26
|
-
if (node.name.name === 'className') {
|
|
27
|
-
context.report({ node, messageId: 'no-classname-prop' });
|
|
28
|
-
}
|
|
29
|
-
},
|
|
30
|
-
};
|
|
31
|
-
},
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
export default rule;
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
Blocks `@container` at-rules
|
|
2
|
-
([container queries](https://developer.mozilla.org/en-US/docs/Web/CSS/@container)), which are
|
|
3
|
-
unsafe.
|
|
4
|
-
|
|
5
|
-
Container queries are unsafe because they:
|
|
6
|
-
|
|
7
|
-
- break the rules of scope
|
|
8
|
-
- aren't deterministic
|
|
9
|
-
- aren't type-safe
|
|
10
|
-
- aren't fully supported across our frontend tech stacks
|
|
11
|
-
|
|
12
|
-
Use [media queries](https://atlassian.design/components/primitives/responsive/breakpoints/examples),
|
|
13
|
-
a
|
|
14
|
-
[WidthObserver](https://atlaskit.atlassian.com/packages/design-system/width-detector/docs/migration-guide),
|
|
15
|
-
or a custom [ResizeObserver](https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver)
|
|
16
|
-
instead.
|
|
17
|
-
|
|
18
|
-
## Examples
|
|
19
|
-
|
|
20
|
-
### Incorrect
|
|
21
|
-
|
|
22
|
-
```tsx
|
|
23
|
-
import { css } from '@compiled/react';
|
|
24
|
-
import { token } from '@atlaskit/tokens';
|
|
25
|
-
|
|
26
|
-
const headingStyles = css({
|
|
27
|
-
'@container (width > 400px)': {
|
|
28
|
-
font: token('font.heading.large'),
|
|
29
|
-
},
|
|
30
|
-
});
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
### Correct
|
|
34
|
-
|
|
35
|
-
#### Media queries
|
|
36
|
-
|
|
37
|
-
```tsx
|
|
38
|
-
import { css } from '@compiled/react';
|
|
39
|
-
import { media } from '@atlaskit/primitives/responsive';
|
|
40
|
-
import { token } from '@atlaskit/tokens';
|
|
41
|
-
|
|
42
|
-
const headingStyles = css({
|
|
43
|
-
[media.above.sm]: {
|
|
44
|
-
font: token('font.heading.large'),
|
|
45
|
-
},
|
|
46
|
-
});
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
#### WidthObserver
|
|
50
|
-
|
|
51
|
-
```tsx
|
|
52
|
-
import { useState } from 'react';
|
|
53
|
-
import { css, cssMap } from '@compiled/react';
|
|
54
|
-
import throttle from 'lodash/throttle';
|
|
55
|
-
import { WidthObserver } from '@atlaskit/width-detector';
|
|
56
|
-
import { token } from '@atlaskit/tokens';
|
|
57
|
-
|
|
58
|
-
const containerStyles = css({
|
|
59
|
-
// Required for the `WidthObserver`, which is absolutely positioned
|
|
60
|
-
position: 'relative',
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
const headingStyles = cssMap({
|
|
64
|
-
small: {
|
|
65
|
-
font: token('font.heading.small'),
|
|
66
|
-
},
|
|
67
|
-
large: {
|
|
68
|
-
font: token('font.heading.large'),
|
|
69
|
-
},
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
const ResponsiveH2 = () => {
|
|
73
|
-
const [width = 0, setWidth] = useState<number | undefined>(undefined);
|
|
74
|
-
const throttledSetWidth = throttle(setWidth, 50);
|
|
75
|
-
|
|
76
|
-
return (
|
|
77
|
-
<div css={containerStyles}>
|
|
78
|
-
<WidthObserver setWidth={throttledSetWidth} />
|
|
79
|
-
<h2 css={width < 400 ? headingStyles.small : headingStyles.large}>Title</h2>
|
|
80
|
-
</div>
|
|
81
|
-
);
|
|
82
|
-
};
|
|
83
|
-
```
|
|
84
|
-
|
|
85
|
-
## Options
|
|
86
|
-
|
|
87
|
-
### `importSources: string[]`
|
|
88
|
-
|
|
89
|
-
By default, this rule will check styles using:
|
|
90
|
-
|
|
91
|
-
- `@atlaskit/css`
|
|
92
|
-
- `@atlaskit/primitives`
|
|
93
|
-
- `@compiled/react`
|
|
94
|
-
- `@emotion/react`
|
|
95
|
-
- `@emotion/core`
|
|
96
|
-
- `@emotion/styled`
|
|
97
|
-
- `styled-components`
|
|
98
|
-
|
|
99
|
-
Override this list with the `importSources` option, which accepts an array of package names.
|