@atlaskit/eslint-plugin-ui-styling-standard 0.13.0 → 0.14.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/README.md +1 -0
- package/constellation/index/overview.mdx +1 -0
- package/constellation/no-styled/usage.mdx +89 -0
- package/constellation/use-compiled/usage.mdx +2 -2
- package/dist/cjs/presets/all.codegen.js +2 -1
- package/dist/cjs/presets/recommended.codegen.js +2 -1
- package/dist/cjs/rules/index.codegen.js +3 -1
- package/dist/cjs/rules/no-styled/index.js +67 -0
- package/dist/es2019/presets/all.codegen.js +2 -1
- package/dist/es2019/presets/recommended.codegen.js +2 -1
- package/dist/es2019/rules/index.codegen.js +3 -1
- package/dist/es2019/rules/no-styled/index.js +45 -0
- package/dist/esm/presets/all.codegen.js +2 -1
- package/dist/esm/presets/recommended.codegen.js +2 -1
- package/dist/esm/rules/index.codegen.js +3 -1
- package/dist/esm/rules/no-styled/index.js +61 -0
- package/dist/types/index.codegen.d.ts +2 -0
- package/dist/types/presets/all.codegen.d.ts +2 -1
- package/dist/types/presets/recommended.codegen.d.ts +2 -1
- package/dist/types/rules/index.codegen.d.ts +1 -0
- package/dist/types/rules/no-styled/index.d.ts +2 -0
- package/dist/types-ts4.5/index.codegen.d.ts +2 -0
- package/dist/types-ts4.5/presets/all.codegen.d.ts +2 -1
- package/dist/types-ts4.5/presets/recommended.codegen.d.ts +2 -1
- package/dist/types-ts4.5/rules/index.codegen.d.ts +1 -0
- package/dist/types-ts4.5/rules/no-styled/index.d.ts +2 -0
- package/package.json +1 -1
- package/src/presets/all.codegen.tsx +2 -1
- package/src/presets/recommended.codegen.tsx +2 -1
- package/src/rules/index.codegen.tsx +3 -1
- package/src/rules/no-styled/README.md +82 -0
- package/src/rules/no-styled/__tests__/rule.test.tsx +73 -0
- package/src/rules/no-styled/index.tsx +52 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @atlaskit/eslint-plugin-ui-styling-standard
|
|
2
2
|
|
|
3
|
+
## 0.14.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#99733](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/99733)
|
|
8
|
+
[`7051e483ab6d`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/7051e483ab6d) -
|
|
9
|
+
Added no-styled eslint rule to prevent usage of styled imports
|
|
10
|
+
|
|
3
11
|
## 0.13.0
|
|
4
12
|
|
|
5
13
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -55,6 +55,7 @@ module.exports = {
|
|
|
55
55
|
| <a href="./src/rules/no-important-styles/README.md">no-important-styles</a> | Disallows important style declarations | Yes | | |
|
|
56
56
|
| <a href="./src/rules/no-imported-style-values/README.md">no-imported-style-values</a> | Disallows imports of style values | Yes | | |
|
|
57
57
|
| <a href="./src/rules/no-nested-selectors/README.md">no-nested-selectors</a> | Prevents usage of nested selectors within css styling | Yes | | |
|
|
58
|
+
| <a href="./src/rules/no-styled/README.md">no-styled</a> | Disallows usage of the `styled` imports | Yes | | |
|
|
58
59
|
| <a href="./src/rules/no-unsafe-values/README.md">no-unsafe-values</a> | Disallows styles that are difficult/impossible to statically anaylze. | Yes | | |
|
|
59
60
|
| <a href="./src/rules/use-compiled/README.md">use-compiled</a> | Ensures usage of `@compiled/react` instead of other CSS-in-JS libraries | Yes | Yes | |
|
|
60
61
|
| <a href="https://atlassian.design/components/eslint-plugin-ui-styling-standard/consistent-css-prop-usage/usage">@atlaskit/design-system/consistent-css-prop-usage</a> | Ensures consistency with `css` and `xcss` prop usages | Yes | Yes | |
|
|
@@ -24,6 +24,7 @@ but more are planned to support the standard over time.
|
|
|
24
24
|
| <a href="no-important-styles/usage">no-important-styles</a> | Disallows important style declarations | Yes | | |
|
|
25
25
|
| <a href="no-imported-style-values/usage">no-imported-style-values</a> | Disallows imports of style values | Yes | | |
|
|
26
26
|
| <a href="no-nested-selectors/usage">no-nested-selectors</a> | Prevents usage of nested selectors within css styling | Yes | | |
|
|
27
|
+
| <a href="no-styled/usage">no-styled</a> | Disallows usage of the `styled` imports | Yes | | |
|
|
27
28
|
| <a href="no-unsafe-values/usage">no-unsafe-values</a> | Disallows styles that are difficult/impossible to statically anaylze. | Yes | | |
|
|
28
29
|
| <a href="use-compiled/usage">use-compiled</a> | Ensures usage of `@compiled/react` instead of other CSS-in-JS libraries | Yes | Yes | |
|
|
29
30
|
| <a href="consistent-css-prop-usage/usage">@atlaskit/design-system/consistent-css-prop-usage</a> | Ensures consistency with `css` and `xcss` prop usages | Yes | Yes | |
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# no-styled
|
|
2
|
+
|
|
3
|
+
This rule prevents usage of `styled` imports'.
|
|
4
|
+
|
|
5
|
+
Avoid usages of styled, eg. `styled.div`, `styled('div')`, `styled(Component)`, etc.
|
|
6
|
+
|
|
7
|
+
## Examples
|
|
8
|
+
|
|
9
|
+
### Incorrect
|
|
10
|
+
|
|
11
|
+
```tsx
|
|
12
|
+
import styled from 'styled-components';
|
|
13
|
+
|
|
14
|
+
const Component = styled.div`
|
|
15
|
+
color: red;
|
|
16
|
+
`;
|
|
17
|
+
export default styled.div({ color: 'red' });
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
```tsx
|
|
21
|
+
import styled2 from '@emotion/styled';
|
|
22
|
+
|
|
23
|
+
export const Component = styled2('div')`…`;
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
```tsx
|
|
27
|
+
import styled from 'styled-components';
|
|
28
|
+
import { styled as styled3 } from '@compiled/react';
|
|
29
|
+
|
|
30
|
+
const Component = styled.div`color: red;`
|
|
31
|
+
export const ComponentTwo = styled3(Component)({ … });
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
```tsx
|
|
35
|
+
import styled from 'styled-components';
|
|
36
|
+
|
|
37
|
+
export default styled.div.attrs((props) => ({ 'data-testid': props.testId }))({
|
|
38
|
+
color: 'red',
|
|
39
|
+
});
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
```tsx
|
|
43
|
+
import styled from 'styled-components';
|
|
44
|
+
|
|
45
|
+
export default styled.div.attrs((props) => ({ 'data-testid': props.testId }))`
|
|
46
|
+
color: red;
|
|
47
|
+
`;
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### Correct
|
|
51
|
+
|
|
52
|
+
```tsx
|
|
53
|
+
import { css, jsx } from '@emotion/react';
|
|
54
|
+
|
|
55
|
+
const styles = css({ color: 'red' });
|
|
56
|
+
|
|
57
|
+
const Component = ({ children }) => {
|
|
58
|
+
return <div css={styles}>{children}</div>;
|
|
59
|
+
};
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
```tsx
|
|
63
|
+
// Using Primitives
|
|
64
|
+
import { Box, xcss } from '@atlaskit/primitives';
|
|
65
|
+
|
|
66
|
+
const styles = xcss({
|
|
67
|
+
color: 'color.text.subtlest',
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
const Component = ({ children }) => {
|
|
71
|
+
return <Box xcss={styles}>{children}</Box>;
|
|
72
|
+
};
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## FAQ
|
|
76
|
+
|
|
77
|
+
### Why avoid using `styled` imports?
|
|
78
|
+
|
|
79
|
+
Using `styled` imports impacts file readability, has TypeScript implications, adds linting
|
|
80
|
+
complexity, promotes exported styles, and potential refactoring efforts. Using `css()` with the
|
|
81
|
+
`<div css={…}>` syntax is more performant and clear.
|
|
82
|
+
|
|
83
|
+
### How will I extend like `styled(Button)`?
|
|
84
|
+
|
|
85
|
+
Primarily, we would suggest you don't extend styles of a component you don't own unless they have an
|
|
86
|
+
explicit bounded interface for you to customize against. The Atlassian Design System for example has
|
|
87
|
+
removed `styled(Button)` interactivity in our latest variants because they are unsafe for us to
|
|
88
|
+
evolve the system with. Instead, make use of reusable component patterns to pass props around which
|
|
89
|
+
impact the styles of that component.
|
|
@@ -23,8 +23,8 @@ import styled, { css } from 'styled-components';
|
|
|
23
23
|
|
|
24
24
|
### Correct
|
|
25
25
|
|
|
26
|
-
We expect usage of `@atlaskit/primitives
|
|
27
|
-
`@compiled/react
|
|
26
|
+
We expect usage of `xcss` with `@atlaskit/primitives` when working with Primitives, and `css` with
|
|
27
|
+
`@compiled/react` when working with custom or native code.
|
|
28
28
|
|
|
29
29
|
```js
|
|
30
30
|
/** @jsx jsx */
|
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
/**
|
|
8
8
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
9
|
-
* @codegen <<SignedSource::
|
|
9
|
+
* @codegen <<SignedSource::40bdd5a27731185ba04e0b279fc81ac9>>
|
|
10
10
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
11
11
|
*/
|
|
12
12
|
var _default = exports.default = {
|
|
@@ -25,6 +25,7 @@ var _default = exports.default = {
|
|
|
25
25
|
'@atlaskit/ui-styling-standard/no-important-styles': 'warn',
|
|
26
26
|
'@atlaskit/ui-styling-standard/no-imported-style-values': 'warn',
|
|
27
27
|
'@atlaskit/ui-styling-standard/no-nested-selectors': 'warn',
|
|
28
|
+
'@atlaskit/ui-styling-standard/no-styled': 'warn',
|
|
28
29
|
'@atlaskit/ui-styling-standard/no-unsafe-values': 'warn',
|
|
29
30
|
'@atlaskit/ui-styling-standard/use-compiled': 'warn',
|
|
30
31
|
'@atlaskit/design-system/consistent-css-prop-usage': ['warn', {
|
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
/**
|
|
8
8
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
9
|
-
* @codegen <<SignedSource::
|
|
9
|
+
* @codegen <<SignedSource::40bdd5a27731185ba04e0b279fc81ac9>>
|
|
10
10
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
11
11
|
*/
|
|
12
12
|
var _default = exports.default = {
|
|
@@ -25,6 +25,7 @@ var _default = exports.default = {
|
|
|
25
25
|
'@atlaskit/ui-styling-standard/no-important-styles': 'warn',
|
|
26
26
|
'@atlaskit/ui-styling-standard/no-imported-style-values': 'warn',
|
|
27
27
|
'@atlaskit/ui-styling-standard/no-nested-selectors': 'warn',
|
|
28
|
+
'@atlaskit/ui-styling-standard/no-styled': 'warn',
|
|
28
29
|
'@atlaskit/ui-styling-standard/no-unsafe-values': 'warn',
|
|
29
30
|
'@atlaskit/ui-styling-standard/use-compiled': 'warn',
|
|
30
31
|
'@atlaskit/design-system/consistent-css-prop-usage': ['warn', {
|
|
@@ -18,11 +18,12 @@ var _noGlobalStyles = _interopRequireDefault(require("./no-global-styles"));
|
|
|
18
18
|
var _noImportantStyles = _interopRequireDefault(require("./no-important-styles"));
|
|
19
19
|
var _noImportedStyleValues = _interopRequireDefault(require("./no-imported-style-values"));
|
|
20
20
|
var _noNestedSelectors = _interopRequireDefault(require("./no-nested-selectors"));
|
|
21
|
+
var _noStyled = _interopRequireDefault(require("./no-styled"));
|
|
21
22
|
var _noUnsafeValues = _interopRequireDefault(require("./no-unsafe-values"));
|
|
22
23
|
var _useCompiled = _interopRequireDefault(require("./use-compiled"));
|
|
23
24
|
/**
|
|
24
25
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
25
|
-
* @codegen <<SignedSource::
|
|
26
|
+
* @codegen <<SignedSource::417762b5fc4a56c3b69c22b8ac0d12e7>>
|
|
26
27
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
27
28
|
*/
|
|
28
29
|
var _default = exports.default = {
|
|
@@ -39,6 +40,7 @@ var _default = exports.default = {
|
|
|
39
40
|
'no-important-styles': _noImportantStyles.default,
|
|
40
41
|
'no-imported-style-values': _noImportedStyleValues.default,
|
|
41
42
|
'no-nested-selectors': _noNestedSelectors.default,
|
|
43
|
+
'no-styled': _noStyled.default,
|
|
42
44
|
'no-unsafe-values': _noUnsafeValues.default,
|
|
43
45
|
'use-compiled': _useCompiled.default
|
|
44
46
|
};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.rule = exports.default = void 0;
|
|
7
|
+
var _isSupportedImport = require("@atlaskit/eslint-utils/is-supported-import");
|
|
8
|
+
var _createRule = require("../utils/create-rule");
|
|
9
|
+
var rule = exports.rule = (0, _createRule.createLintRule)({
|
|
10
|
+
meta: {
|
|
11
|
+
name: 'no-styled',
|
|
12
|
+
docs: {
|
|
13
|
+
description: 'Disallows usage of the `styled` imports',
|
|
14
|
+
recommended: true,
|
|
15
|
+
severity: 'warn'
|
|
16
|
+
},
|
|
17
|
+
messages: {
|
|
18
|
+
'no-styled': "Avoid usages of styled, eg. styled.div, styled('div'), styled(Component), etc."
|
|
19
|
+
},
|
|
20
|
+
type: 'problem'
|
|
21
|
+
},
|
|
22
|
+
create: function create(context) {
|
|
23
|
+
return {
|
|
24
|
+
CallExpression: function (_CallExpression) {
|
|
25
|
+
function CallExpression(_x) {
|
|
26
|
+
return _CallExpression.apply(this, arguments);
|
|
27
|
+
}
|
|
28
|
+
CallExpression.toString = function () {
|
|
29
|
+
return _CallExpression.toString();
|
|
30
|
+
};
|
|
31
|
+
return CallExpression;
|
|
32
|
+
}(function (node) {
|
|
33
|
+
var references = context.getScope().references;
|
|
34
|
+
var importSources = (0, _isSupportedImport.getImportSources)(context);
|
|
35
|
+
if ((0, _isSupportedImport.isStyled)(node, references, importSources)) {
|
|
36
|
+
context.report({
|
|
37
|
+
node: node,
|
|
38
|
+
messageId: 'no-styled'
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}),
|
|
42
|
+
MemberExpression: function (_MemberExpression) {
|
|
43
|
+
function MemberExpression(_x2) {
|
|
44
|
+
return _MemberExpression.apply(this, arguments);
|
|
45
|
+
}
|
|
46
|
+
MemberExpression.toString = function () {
|
|
47
|
+
return _MemberExpression.toString();
|
|
48
|
+
};
|
|
49
|
+
return MemberExpression;
|
|
50
|
+
}(function (node) {
|
|
51
|
+
var references = context.getScope().references;
|
|
52
|
+
var importSources = (0, _isSupportedImport.getImportSources)(context);
|
|
53
|
+
if (node.object.type === 'Identifier' && (0, _isSupportedImport.isStyled)(node.object, references, importSources)) {
|
|
54
|
+
var parent = context.getAncestors().at(-1);
|
|
55
|
+
if (parent && (parent.type === 'CallExpression' || parent.type === 'MemberExpression')) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
context.report({
|
|
59
|
+
node: node,
|
|
60
|
+
messageId: 'no-styled'
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
})
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
var _default = exports.default = rule;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
-
* @codegen <<SignedSource::
|
|
3
|
+
* @codegen <<SignedSource::40bdd5a27731185ba04e0b279fc81ac9>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
export default {
|
|
@@ -19,6 +19,7 @@ export default {
|
|
|
19
19
|
'@atlaskit/ui-styling-standard/no-important-styles': 'warn',
|
|
20
20
|
'@atlaskit/ui-styling-standard/no-imported-style-values': 'warn',
|
|
21
21
|
'@atlaskit/ui-styling-standard/no-nested-selectors': 'warn',
|
|
22
|
+
'@atlaskit/ui-styling-standard/no-styled': 'warn',
|
|
22
23
|
'@atlaskit/ui-styling-standard/no-unsafe-values': 'warn',
|
|
23
24
|
'@atlaskit/ui-styling-standard/use-compiled': 'warn',
|
|
24
25
|
'@atlaskit/design-system/consistent-css-prop-usage': ['warn', {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
-
* @codegen <<SignedSource::
|
|
3
|
+
* @codegen <<SignedSource::40bdd5a27731185ba04e0b279fc81ac9>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
export default {
|
|
@@ -19,6 +19,7 @@ export default {
|
|
|
19
19
|
'@atlaskit/ui-styling-standard/no-important-styles': 'warn',
|
|
20
20
|
'@atlaskit/ui-styling-standard/no-imported-style-values': 'warn',
|
|
21
21
|
'@atlaskit/ui-styling-standard/no-nested-selectors': 'warn',
|
|
22
|
+
'@atlaskit/ui-styling-standard/no-styled': 'warn',
|
|
22
23
|
'@atlaskit/ui-styling-standard/no-unsafe-values': 'warn',
|
|
23
24
|
'@atlaskit/ui-styling-standard/use-compiled': 'warn',
|
|
24
25
|
'@atlaskit/design-system/consistent-css-prop-usage': ['warn', {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
-
* @codegen <<SignedSource::
|
|
3
|
+
* @codegen <<SignedSource::417762b5fc4a56c3b69c22b8ac0d12e7>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
import atlaskitTheme from './atlaskit-theme';
|
|
@@ -16,6 +16,7 @@ import noGlobalStyles from './no-global-styles';
|
|
|
16
16
|
import noImportantStyles from './no-important-styles';
|
|
17
17
|
import noImportedStyleValues from './no-imported-style-values';
|
|
18
18
|
import noNestedSelectors from './no-nested-selectors';
|
|
19
|
+
import noStyled from './no-styled';
|
|
19
20
|
import noUnsafeValues from './no-unsafe-values';
|
|
20
21
|
import useCompiled from './use-compiled';
|
|
21
22
|
export default {
|
|
@@ -32,6 +33,7 @@ export default {
|
|
|
32
33
|
'no-important-styles': noImportantStyles,
|
|
33
34
|
'no-imported-style-values': noImportedStyleValues,
|
|
34
35
|
'no-nested-selectors': noNestedSelectors,
|
|
36
|
+
'no-styled': noStyled,
|
|
35
37
|
'no-unsafe-values': noUnsafeValues,
|
|
36
38
|
'use-compiled': useCompiled
|
|
37
39
|
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { isStyled, getImportSources } from '@atlaskit/eslint-utils/is-supported-import';
|
|
2
|
+
import { createLintRule } from '../utils/create-rule';
|
|
3
|
+
export const rule = createLintRule({
|
|
4
|
+
meta: {
|
|
5
|
+
name: 'no-styled',
|
|
6
|
+
docs: {
|
|
7
|
+
description: 'Disallows usage of the `styled` imports',
|
|
8
|
+
recommended: true,
|
|
9
|
+
severity: 'warn'
|
|
10
|
+
},
|
|
11
|
+
messages: {
|
|
12
|
+
'no-styled': "Avoid usages of styled, eg. styled.div, styled('div'), styled(Component), etc."
|
|
13
|
+
},
|
|
14
|
+
type: 'problem'
|
|
15
|
+
},
|
|
16
|
+
create(context) {
|
|
17
|
+
return {
|
|
18
|
+
CallExpression: node => {
|
|
19
|
+
const references = context.getScope().references;
|
|
20
|
+
const importSources = getImportSources(context);
|
|
21
|
+
if (isStyled(node, references, importSources)) {
|
|
22
|
+
context.report({
|
|
23
|
+
node,
|
|
24
|
+
messageId: 'no-styled'
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
MemberExpression: node => {
|
|
29
|
+
const references = context.getScope().references;
|
|
30
|
+
const importSources = getImportSources(context);
|
|
31
|
+
if (node.object.type === 'Identifier' && isStyled(node.object, references, importSources)) {
|
|
32
|
+
const parent = context.getAncestors().at(-1);
|
|
33
|
+
if (parent && (parent.type === 'CallExpression' || parent.type === 'MemberExpression')) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
context.report({
|
|
37
|
+
node,
|
|
38
|
+
messageId: 'no-styled'
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
export default rule;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
-
* @codegen <<SignedSource::
|
|
3
|
+
* @codegen <<SignedSource::40bdd5a27731185ba04e0b279fc81ac9>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
export default {
|
|
@@ -19,6 +19,7 @@ export default {
|
|
|
19
19
|
'@atlaskit/ui-styling-standard/no-important-styles': 'warn',
|
|
20
20
|
'@atlaskit/ui-styling-standard/no-imported-style-values': 'warn',
|
|
21
21
|
'@atlaskit/ui-styling-standard/no-nested-selectors': 'warn',
|
|
22
|
+
'@atlaskit/ui-styling-standard/no-styled': 'warn',
|
|
22
23
|
'@atlaskit/ui-styling-standard/no-unsafe-values': 'warn',
|
|
23
24
|
'@atlaskit/ui-styling-standard/use-compiled': 'warn',
|
|
24
25
|
'@atlaskit/design-system/consistent-css-prop-usage': ['warn', {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
-
* @codegen <<SignedSource::
|
|
3
|
+
* @codegen <<SignedSource::40bdd5a27731185ba04e0b279fc81ac9>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
export default {
|
|
@@ -19,6 +19,7 @@ export default {
|
|
|
19
19
|
'@atlaskit/ui-styling-standard/no-important-styles': 'warn',
|
|
20
20
|
'@atlaskit/ui-styling-standard/no-imported-style-values': 'warn',
|
|
21
21
|
'@atlaskit/ui-styling-standard/no-nested-selectors': 'warn',
|
|
22
|
+
'@atlaskit/ui-styling-standard/no-styled': 'warn',
|
|
22
23
|
'@atlaskit/ui-styling-standard/no-unsafe-values': 'warn',
|
|
23
24
|
'@atlaskit/ui-styling-standard/use-compiled': 'warn',
|
|
24
25
|
'@atlaskit/design-system/consistent-css-prop-usage': ['warn', {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
-
* @codegen <<SignedSource::
|
|
3
|
+
* @codegen <<SignedSource::417762b5fc4a56c3b69c22b8ac0d12e7>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
import atlaskitTheme from './atlaskit-theme';
|
|
@@ -16,6 +16,7 @@ import noGlobalStyles from './no-global-styles';
|
|
|
16
16
|
import noImportantStyles from './no-important-styles';
|
|
17
17
|
import noImportedStyleValues from './no-imported-style-values';
|
|
18
18
|
import noNestedSelectors from './no-nested-selectors';
|
|
19
|
+
import noStyled from './no-styled';
|
|
19
20
|
import noUnsafeValues from './no-unsafe-values';
|
|
20
21
|
import useCompiled from './use-compiled';
|
|
21
22
|
export default {
|
|
@@ -32,6 +33,7 @@ export default {
|
|
|
32
33
|
'no-important-styles': noImportantStyles,
|
|
33
34
|
'no-imported-style-values': noImportedStyleValues,
|
|
34
35
|
'no-nested-selectors': noNestedSelectors,
|
|
36
|
+
'no-styled': noStyled,
|
|
35
37
|
'no-unsafe-values': noUnsafeValues,
|
|
36
38
|
'use-compiled': useCompiled
|
|
37
39
|
};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { isStyled, getImportSources } from '@atlaskit/eslint-utils/is-supported-import';
|
|
2
|
+
import { createLintRule } from '../utils/create-rule';
|
|
3
|
+
export var rule = createLintRule({
|
|
4
|
+
meta: {
|
|
5
|
+
name: 'no-styled',
|
|
6
|
+
docs: {
|
|
7
|
+
description: 'Disallows usage of the `styled` imports',
|
|
8
|
+
recommended: true,
|
|
9
|
+
severity: 'warn'
|
|
10
|
+
},
|
|
11
|
+
messages: {
|
|
12
|
+
'no-styled': "Avoid usages of styled, eg. styled.div, styled('div'), styled(Component), etc."
|
|
13
|
+
},
|
|
14
|
+
type: 'problem'
|
|
15
|
+
},
|
|
16
|
+
create: function create(context) {
|
|
17
|
+
return {
|
|
18
|
+
CallExpression: function (_CallExpression) {
|
|
19
|
+
function CallExpression(_x) {
|
|
20
|
+
return _CallExpression.apply(this, arguments);
|
|
21
|
+
}
|
|
22
|
+
CallExpression.toString = function () {
|
|
23
|
+
return _CallExpression.toString();
|
|
24
|
+
};
|
|
25
|
+
return CallExpression;
|
|
26
|
+
}(function (node) {
|
|
27
|
+
var references = context.getScope().references;
|
|
28
|
+
var importSources = getImportSources(context);
|
|
29
|
+
if (isStyled(node, references, importSources)) {
|
|
30
|
+
context.report({
|
|
31
|
+
node: node,
|
|
32
|
+
messageId: 'no-styled'
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
}),
|
|
36
|
+
MemberExpression: function (_MemberExpression) {
|
|
37
|
+
function MemberExpression(_x2) {
|
|
38
|
+
return _MemberExpression.apply(this, arguments);
|
|
39
|
+
}
|
|
40
|
+
MemberExpression.toString = function () {
|
|
41
|
+
return _MemberExpression.toString();
|
|
42
|
+
};
|
|
43
|
+
return MemberExpression;
|
|
44
|
+
}(function (node) {
|
|
45
|
+
var references = context.getScope().references;
|
|
46
|
+
var importSources = getImportSources(context);
|
|
47
|
+
if (node.object.type === 'Identifier' && isStyled(node.object, references, importSources)) {
|
|
48
|
+
var parent = context.getAncestors().at(-1);
|
|
49
|
+
if (parent && (parent.type === 'CallExpression' || parent.type === 'MemberExpression')) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
context.report({
|
|
53
|
+
node: node,
|
|
54
|
+
messageId: 'no-styled'
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
})
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
export default rule;
|
|
@@ -16,6 +16,7 @@ export declare const configs: {
|
|
|
16
16
|
'@atlaskit/ui-styling-standard/no-important-styles': string;
|
|
17
17
|
'@atlaskit/ui-styling-standard/no-imported-style-values': string;
|
|
18
18
|
'@atlaskit/ui-styling-standard/no-nested-selectors': string;
|
|
19
|
+
'@atlaskit/ui-styling-standard/no-styled': string;
|
|
19
20
|
'@atlaskit/ui-styling-standard/no-unsafe-values': string;
|
|
20
21
|
'@atlaskit/ui-styling-standard/use-compiled': string;
|
|
21
22
|
'@atlaskit/design-system/consistent-css-prop-usage': (string | {
|
|
@@ -56,6 +57,7 @@ export declare const configs: {
|
|
|
56
57
|
'@atlaskit/ui-styling-standard/no-important-styles': string;
|
|
57
58
|
'@atlaskit/ui-styling-standard/no-imported-style-values': string;
|
|
58
59
|
'@atlaskit/ui-styling-standard/no-nested-selectors': string;
|
|
60
|
+
'@atlaskit/ui-styling-standard/no-styled': string;
|
|
59
61
|
'@atlaskit/ui-styling-standard/no-unsafe-values': string;
|
|
60
62
|
'@atlaskit/ui-styling-standard/use-compiled': string;
|
|
61
63
|
'@atlaskit/design-system/consistent-css-prop-usage': (string | {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
-
* @codegen <<SignedSource::
|
|
3
|
+
* @codegen <<SignedSource::40bdd5a27731185ba04e0b279fc81ac9>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
declare const _default: {
|
|
@@ -19,6 +19,7 @@ declare const _default: {
|
|
|
19
19
|
'@atlaskit/ui-styling-standard/no-important-styles': string;
|
|
20
20
|
'@atlaskit/ui-styling-standard/no-imported-style-values': string;
|
|
21
21
|
'@atlaskit/ui-styling-standard/no-nested-selectors': string;
|
|
22
|
+
'@atlaskit/ui-styling-standard/no-styled': string;
|
|
22
23
|
'@atlaskit/ui-styling-standard/no-unsafe-values': string;
|
|
23
24
|
'@atlaskit/ui-styling-standard/use-compiled': string;
|
|
24
25
|
'@atlaskit/design-system/consistent-css-prop-usage': (string | {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
-
* @codegen <<SignedSource::
|
|
3
|
+
* @codegen <<SignedSource::40bdd5a27731185ba04e0b279fc81ac9>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
declare const _default: {
|
|
@@ -19,6 +19,7 @@ declare const _default: {
|
|
|
19
19
|
'@atlaskit/ui-styling-standard/no-important-styles': string;
|
|
20
20
|
'@atlaskit/ui-styling-standard/no-imported-style-values': string;
|
|
21
21
|
'@atlaskit/ui-styling-standard/no-nested-selectors': string;
|
|
22
|
+
'@atlaskit/ui-styling-standard/no-styled': string;
|
|
22
23
|
'@atlaskit/ui-styling-standard/no-unsafe-values': string;
|
|
23
24
|
'@atlaskit/ui-styling-standard/use-compiled': string;
|
|
24
25
|
'@atlaskit/design-system/consistent-css-prop-usage': (string | {
|
|
@@ -12,6 +12,7 @@ declare const _default: {
|
|
|
12
12
|
'no-important-styles': import("eslint").Rule.RuleModule;
|
|
13
13
|
'no-imported-style-values': import("eslint").Rule.RuleModule;
|
|
14
14
|
'no-nested-selectors': import("eslint").Rule.RuleModule;
|
|
15
|
+
'no-styled': import("eslint").Rule.RuleModule;
|
|
15
16
|
'no-unsafe-values': import("eslint").Rule.RuleModule;
|
|
16
17
|
'use-compiled': import("eslint").Rule.RuleModule;
|
|
17
18
|
};
|
|
@@ -16,6 +16,7 @@ export declare const configs: {
|
|
|
16
16
|
'@atlaskit/ui-styling-standard/no-important-styles': string;
|
|
17
17
|
'@atlaskit/ui-styling-standard/no-imported-style-values': string;
|
|
18
18
|
'@atlaskit/ui-styling-standard/no-nested-selectors': string;
|
|
19
|
+
'@atlaskit/ui-styling-standard/no-styled': string;
|
|
19
20
|
'@atlaskit/ui-styling-standard/no-unsafe-values': string;
|
|
20
21
|
'@atlaskit/ui-styling-standard/use-compiled': string;
|
|
21
22
|
'@atlaskit/design-system/consistent-css-prop-usage': (string | {
|
|
@@ -56,6 +57,7 @@ export declare const configs: {
|
|
|
56
57
|
'@atlaskit/ui-styling-standard/no-important-styles': string;
|
|
57
58
|
'@atlaskit/ui-styling-standard/no-imported-style-values': string;
|
|
58
59
|
'@atlaskit/ui-styling-standard/no-nested-selectors': string;
|
|
60
|
+
'@atlaskit/ui-styling-standard/no-styled': string;
|
|
59
61
|
'@atlaskit/ui-styling-standard/no-unsafe-values': string;
|
|
60
62
|
'@atlaskit/ui-styling-standard/use-compiled': string;
|
|
61
63
|
'@atlaskit/design-system/consistent-css-prop-usage': (string | {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
-
* @codegen <<SignedSource::
|
|
3
|
+
* @codegen <<SignedSource::40bdd5a27731185ba04e0b279fc81ac9>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
declare const _default: {
|
|
@@ -19,6 +19,7 @@ declare const _default: {
|
|
|
19
19
|
'@atlaskit/ui-styling-standard/no-important-styles': string;
|
|
20
20
|
'@atlaskit/ui-styling-standard/no-imported-style-values': string;
|
|
21
21
|
'@atlaskit/ui-styling-standard/no-nested-selectors': string;
|
|
22
|
+
'@atlaskit/ui-styling-standard/no-styled': string;
|
|
22
23
|
'@atlaskit/ui-styling-standard/no-unsafe-values': string;
|
|
23
24
|
'@atlaskit/ui-styling-standard/use-compiled': string;
|
|
24
25
|
'@atlaskit/design-system/consistent-css-prop-usage': (string | {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
-
* @codegen <<SignedSource::
|
|
3
|
+
* @codegen <<SignedSource::40bdd5a27731185ba04e0b279fc81ac9>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
declare const _default: {
|
|
@@ -19,6 +19,7 @@ declare const _default: {
|
|
|
19
19
|
'@atlaskit/ui-styling-standard/no-important-styles': string;
|
|
20
20
|
'@atlaskit/ui-styling-standard/no-imported-style-values': string;
|
|
21
21
|
'@atlaskit/ui-styling-standard/no-nested-selectors': string;
|
|
22
|
+
'@atlaskit/ui-styling-standard/no-styled': string;
|
|
22
23
|
'@atlaskit/ui-styling-standard/no-unsafe-values': string;
|
|
23
24
|
'@atlaskit/ui-styling-standard/use-compiled': string;
|
|
24
25
|
'@atlaskit/design-system/consistent-css-prop-usage': (string | {
|
|
@@ -12,6 +12,7 @@ declare const _default: {
|
|
|
12
12
|
'no-important-styles': import("eslint").Rule.RuleModule;
|
|
13
13
|
'no-imported-style-values': import("eslint").Rule.RuleModule;
|
|
14
14
|
'no-nested-selectors': import("eslint").Rule.RuleModule;
|
|
15
|
+
'no-styled': import("eslint").Rule.RuleModule;
|
|
15
16
|
'no-unsafe-values': import("eslint").Rule.RuleModule;
|
|
16
17
|
'use-compiled': import("eslint").Rule.RuleModule;
|
|
17
18
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
-
* @codegen <<SignedSource::
|
|
3
|
+
* @codegen <<SignedSource::40bdd5a27731185ba04e0b279fc81ac9>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
export default {
|
|
@@ -19,6 +19,7 @@ export default {
|
|
|
19
19
|
'@atlaskit/ui-styling-standard/no-important-styles': 'warn',
|
|
20
20
|
'@atlaskit/ui-styling-standard/no-imported-style-values': 'warn',
|
|
21
21
|
'@atlaskit/ui-styling-standard/no-nested-selectors': 'warn',
|
|
22
|
+
'@atlaskit/ui-styling-standard/no-styled': 'warn',
|
|
22
23
|
'@atlaskit/ui-styling-standard/no-unsafe-values': 'warn',
|
|
23
24
|
'@atlaskit/ui-styling-standard/use-compiled': 'warn',
|
|
24
25
|
'@atlaskit/design-system/consistent-css-prop-usage': [
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
-
* @codegen <<SignedSource::
|
|
3
|
+
* @codegen <<SignedSource::40bdd5a27731185ba04e0b279fc81ac9>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
export default {
|
|
@@ -19,6 +19,7 @@ export default {
|
|
|
19
19
|
'@atlaskit/ui-styling-standard/no-important-styles': 'warn',
|
|
20
20
|
'@atlaskit/ui-styling-standard/no-imported-style-values': 'warn',
|
|
21
21
|
'@atlaskit/ui-styling-standard/no-nested-selectors': 'warn',
|
|
22
|
+
'@atlaskit/ui-styling-standard/no-styled': 'warn',
|
|
22
23
|
'@atlaskit/ui-styling-standard/no-unsafe-values': 'warn',
|
|
23
24
|
'@atlaskit/ui-styling-standard/use-compiled': 'warn',
|
|
24
25
|
'@atlaskit/design-system/consistent-css-prop-usage': [
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
-
* @codegen <<SignedSource::
|
|
3
|
+
* @codegen <<SignedSource::417762b5fc4a56c3b69c22b8ac0d12e7>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
import atlaskitTheme from './atlaskit-theme';
|
|
@@ -16,6 +16,7 @@ import noGlobalStyles from './no-global-styles';
|
|
|
16
16
|
import noImportantStyles from './no-important-styles';
|
|
17
17
|
import noImportedStyleValues from './no-imported-style-values';
|
|
18
18
|
import noNestedSelectors from './no-nested-selectors';
|
|
19
|
+
import noStyled from './no-styled';
|
|
19
20
|
import noUnsafeValues from './no-unsafe-values';
|
|
20
21
|
import useCompiled from './use-compiled';
|
|
21
22
|
|
|
@@ -33,6 +34,7 @@ export default {
|
|
|
33
34
|
'no-important-styles': noImportantStyles,
|
|
34
35
|
'no-imported-style-values': noImportedStyleValues,
|
|
35
36
|
'no-nested-selectors': noNestedSelectors,
|
|
37
|
+
'no-styled': noStyled,
|
|
36
38
|
'no-unsafe-values': noUnsafeValues,
|
|
37
39
|
'use-compiled': useCompiled,
|
|
38
40
|
};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
This rule prevents usage of `styled` imports'.
|
|
2
|
+
|
|
3
|
+
Avoid usages of styled, eg. `styled.div`, `styled('div')`, `styled(Component)`, etc.
|
|
4
|
+
|
|
5
|
+
## Examples
|
|
6
|
+
|
|
7
|
+
### Incorrect
|
|
8
|
+
|
|
9
|
+
```tsx
|
|
10
|
+
import styled from 'styled-components';
|
|
11
|
+
|
|
12
|
+
const Component = styled.div`
|
|
13
|
+
color: red;
|
|
14
|
+
`;
|
|
15
|
+
export default styled.div({ color: 'red' });
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
```tsx
|
|
19
|
+
import styled2 from '@emotion/styled';
|
|
20
|
+
|
|
21
|
+
export const Component = styled2('div')`…`;
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
```tsx
|
|
25
|
+
import styled from 'styled-components';
|
|
26
|
+
import { styled as styled3 } from '@compiled/react';
|
|
27
|
+
|
|
28
|
+
const Component = styled.div`color: red;`
|
|
29
|
+
export const ComponentTwo = styled3(Component)({ … });
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
```tsx
|
|
33
|
+
import styled from 'styled-components';
|
|
34
|
+
|
|
35
|
+
export default styled.div.attrs((props) => ({ 'data-testid': props.testId }))({
|
|
36
|
+
color: 'red',
|
|
37
|
+
});
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
```tsx
|
|
41
|
+
import styled from 'styled-components';
|
|
42
|
+
|
|
43
|
+
export default styled.div.attrs((props) => ({ 'data-testid': props.testId }))`
|
|
44
|
+
color: red;
|
|
45
|
+
`;
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### Correct
|
|
49
|
+
|
|
50
|
+
```tsx
|
|
51
|
+
import { css, jsx } from '@emotion/react';
|
|
52
|
+
|
|
53
|
+
const styles = css({ color: 'red' });
|
|
54
|
+
|
|
55
|
+
const Component = ({ children }) => {
|
|
56
|
+
return <div css={styles}>{children}</div>;
|
|
57
|
+
};
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
```tsx
|
|
61
|
+
// Using Primitives
|
|
62
|
+
import { Box, xcss } from '@atlaskit/primitives';
|
|
63
|
+
|
|
64
|
+
const styles = xcss({
|
|
65
|
+
color: 'color.text.subtlest',
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
const Component = ({ children }) => {
|
|
69
|
+
return <Box xcss={styles}>{children}</Box>;
|
|
70
|
+
};
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## FAQ
|
|
74
|
+
|
|
75
|
+
### Why avoid using `styled` imports?
|
|
76
|
+
|
|
77
|
+
Using `styled` imports impacts file readability, has TypeScript implications, adds linting complexity, promotes exported styles, and potential refactoring efforts. Using `css()` with the `<div css={…}>` syntax is more performant and clear.
|
|
78
|
+
|
|
79
|
+
### How will I extend like `styled(Button)`?
|
|
80
|
+
|
|
81
|
+
Primarily, we would suggest you don't extend styles of a component you don't own unless they have an explicit bounded interface for you to customize against. The Atlassian Design System for example has removed `styled(Button)` interactivity in our latest variants because they are unsafe for us to evolve the system with.
|
|
82
|
+
Instead, make use of reusable component patterns to pass props around which impact the styles of that component.
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { tester } from '../../__tests__/utils/_tester';
|
|
2
|
+
import rule from '../index';
|
|
3
|
+
|
|
4
|
+
tester.run('no-styled', rule, {
|
|
5
|
+
valid: [
|
|
6
|
+
{
|
|
7
|
+
code: `
|
|
8
|
+
import { css, jsx } from '@emotion/react';
|
|
9
|
+
|
|
10
|
+
const styles = css({ color: 'red' });
|
|
11
|
+
|
|
12
|
+
const Component = ({ children }) => {
|
|
13
|
+
return <div css={styles}>{children}</div>;
|
|
14
|
+
};
|
|
15
|
+
`,
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
code: `
|
|
19
|
+
import { Box, xcss } from '@atlaskit/primitives';
|
|
20
|
+
|
|
21
|
+
const styles = xcss({
|
|
22
|
+
color: 'color.text.subtlest',
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
const Component = ({ children }) => {
|
|
26
|
+
return <Box xcss={styles}>{children}</Box>;
|
|
27
|
+
};
|
|
28
|
+
`
|
|
29
|
+
}
|
|
30
|
+
],
|
|
31
|
+
invalid: [
|
|
32
|
+
{
|
|
33
|
+
code: `
|
|
34
|
+
import styled from 'styled-components';
|
|
35
|
+
|
|
36
|
+
const Component = styled.div\`color: red;\`
|
|
37
|
+
`,
|
|
38
|
+
errors: [{ messageId: 'no-styled' }],
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
code: `
|
|
42
|
+
import styled from 'styled-components';
|
|
43
|
+
|
|
44
|
+
export default styled.div({ color: 'red' });
|
|
45
|
+
`,
|
|
46
|
+
errors: [{ messageId: 'no-styled' }],
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
code: `
|
|
50
|
+
import { styled as styled3 } from '@compiled/react';
|
|
51
|
+
|
|
52
|
+
export const ComponentTwo = styled3(Component)({ color: 'blue' });
|
|
53
|
+
`,
|
|
54
|
+
errors: [{ messageId: 'no-styled' }],
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
code: `
|
|
58
|
+
import styled from 'styled-components';
|
|
59
|
+
|
|
60
|
+
export default styled.div.attrs(props => ({ 'data-testid': props.testId }))({ color: 'red' });
|
|
61
|
+
`,
|
|
62
|
+
errors: [{ messageId: 'no-styled' }],
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
code: `
|
|
66
|
+
import styled from 'styled-components';
|
|
67
|
+
|
|
68
|
+
export default styled.div.attrs(props => ({ 'data-testid': props.testId }))\`color: red\`;
|
|
69
|
+
`,
|
|
70
|
+
errors: [{ messageId: 'no-styled' }],
|
|
71
|
+
}
|
|
72
|
+
],
|
|
73
|
+
});
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { type MemberExpression, type CallExpression } from 'eslint-codemod-utils';
|
|
2
|
+
import { isStyled, getImportSources } from '@atlaskit/eslint-utils/is-supported-import';
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
import { createLintRule } from '../utils/create-rule';
|
|
6
|
+
|
|
7
|
+
export const rule = createLintRule({
|
|
8
|
+
meta: {
|
|
9
|
+
name: 'no-styled',
|
|
10
|
+
docs: {
|
|
11
|
+
description: 'Disallows usage of the `styled` imports',
|
|
12
|
+
recommended: true,
|
|
13
|
+
severity: 'warn',
|
|
14
|
+
},
|
|
15
|
+
messages: {
|
|
16
|
+
'no-styled': "Avoid usages of styled, eg. styled.div, styled('div'), styled(Component), etc.",
|
|
17
|
+
},
|
|
18
|
+
type: 'problem',
|
|
19
|
+
},
|
|
20
|
+
create(context) {
|
|
21
|
+
return {
|
|
22
|
+
CallExpression: (node: CallExpression) => {
|
|
23
|
+
const references = context.getScope().references;
|
|
24
|
+
const importSources = getImportSources(context);
|
|
25
|
+
|
|
26
|
+
if (
|
|
27
|
+
isStyled(node, references, importSources)
|
|
28
|
+
) {
|
|
29
|
+
context.report({ node, messageId: 'no-styled' });
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
},
|
|
33
|
+
MemberExpression: (node: MemberExpression) => {
|
|
34
|
+
const references = context.getScope().references;
|
|
35
|
+
const importSources = getImportSources(context);
|
|
36
|
+
|
|
37
|
+
if (
|
|
38
|
+
node.object.type === 'Identifier' &&
|
|
39
|
+
isStyled(node.object, references, importSources)
|
|
40
|
+
) {
|
|
41
|
+
const parent = context.getAncestors().at(-1);
|
|
42
|
+
if (parent && (parent.type === 'CallExpression' || parent.type === 'MemberExpression')) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
context.report({ node, messageId: 'no-styled' });
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
export default rule;
|