@atlaskit/eslint-plugin-ui-styling-standard 0.11.0 → 0.11.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 +6 -0
- package/README.md +1 -0
- package/constellation/index/overview.mdx +1 -0
- package/constellation/no-exported-styles/usage.mdx +87 -0
- 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-exported-styles/index.js +39 -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-exported-styles/index.js +33 -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-exported-styles/index.js +33 -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-exported-styles/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-exported-styles/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-exported-styles/README.md +85 -0
- package/src/rules/no-exported-styles/__tests__/rule.test.tsx +225 -0
- package/src/rules/no-exported-styles/index.tsx +52 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @atlaskit/eslint-plugin-ui-styling-standard
|
|
2
2
|
|
|
3
|
+
## 0.11.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#92963](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/92963) [`1bb8557fb0b6`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/1bb8557fb0b6) - Added no-exported-styles eslint rule to disallow exports of css, cssMap, keyframes, styled and xcss styling
|
|
8
|
+
|
|
3
9
|
## 0.11.0
|
|
4
10
|
|
|
5
11
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -20,6 +20,7 @@ Not intended for use outside the Atlassian frontend repository.
|
|
|
20
20
|
| <a href="./src/rules/no-classname-prop/README.md">no-classname-prop</a> | Disallows usage of the `className` prop in JSX | Yes | | |
|
|
21
21
|
| <a href="./src/rules/no-container-queries/README.md">no-container-queries</a> | Prevents usage of @container query within css styling | Yes | | |
|
|
22
22
|
| <a href="./src/rules/no-dynamic-styles/README.md">no-dynamic-styles</a> | Disallows use of dynamic styles in CSS-in-JS calls | Yes | | |
|
|
23
|
+
| <a href="./src/rules/no-exported-styles/README.md">no-exported-styles</a> | Disallows exports of css, keyframes, styled and xcss | Yes | | |
|
|
23
24
|
| <a href="./src/rules/no-important-styles/README.md">no-important-styles</a> | Disallows important style declarations | Yes | | |
|
|
24
25
|
| <a href="./src/rules/no-nested-selectors/README.md">no-nested-selectors</a> | Prevents usage of nested selectors within css styling | Yes | | |
|
|
25
26
|
| <a href="./src/rules/no-unsafe-values/README.md">no-unsafe-values</a> | Disallows styles that are difficult/impossible to statically anaylze. | Yes | | |
|
|
@@ -18,6 +18,7 @@ but more are planned to support the standard over time.
|
|
|
18
18
|
| <a href="no-classname-prop/usage">no-classname-prop</a> | Disallows usage of the `className` prop in JSX | Yes | | |
|
|
19
19
|
| <a href="no-container-queries/usage">no-container-queries</a> | Prevents usage of @container query within css styling | Yes | | |
|
|
20
20
|
| <a href="no-dynamic-styles/usage">no-dynamic-styles</a> | Disallows use of dynamic styles in CSS-in-JS calls | Yes | | |
|
|
21
|
+
| <a href="no-exported-styles/usage">no-exported-styles</a> | Disallows exports of css, keyframes, styled and xcss | Yes | | |
|
|
21
22
|
| <a href="no-important-styles/usage">no-important-styles</a> | Disallows important style declarations | Yes | | |
|
|
22
23
|
| <a href="no-nested-selectors/usage">no-nested-selectors</a> | Prevents usage of nested selectors within css styling | Yes | | |
|
|
23
24
|
| <a href="no-unsafe-values/usage">no-unsafe-values</a> | Disallows styles that are difficult/impossible to statically anaylze. | Yes | | |
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# no-exported-styles
|
|
2
|
+
|
|
3
|
+
This rule disallows exports of `css`, `cssMap`, `keyframes`, `styled`, `xcss` styles.
|
|
4
|
+
|
|
5
|
+
Exporting style declarations from these libraries may result in unexpected errors when imported, because its value will be null at runtime. Additionally, co-locating style definitions with their usage is considered best practice in order to improve code readability and build performance.
|
|
6
|
+
|
|
7
|
+
## Examples
|
|
8
|
+
|
|
9
|
+
### Incorrect
|
|
10
|
+
|
|
11
|
+
```js
|
|
12
|
+
import { css } from '@compiled/react';
|
|
13
|
+
|
|
14
|
+
export const styles = css({});
|
|
15
|
+
|
|
16
|
+
export default css({});
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
```js
|
|
20
|
+
import { keyframes } from '@compiled/react';
|
|
21
|
+
|
|
22
|
+
export const animation = keyframes({});
|
|
23
|
+
|
|
24
|
+
export default keyframes({});
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Avoid exporting any style-like objects or values for consumption as well as these will violate our `no-imported-style-values` rule which blocks consumption of imported styles.
|
|
28
|
+
|
|
29
|
+
```js
|
|
30
|
+
export default {
|
|
31
|
+
color: 'red',
|
|
32
|
+
margin: '0px',
|
|
33
|
+
};
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
```js
|
|
37
|
+
import { css } from '@compiled/react';
|
|
38
|
+
|
|
39
|
+
const color = css({
|
|
40
|
+
/* */
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
const styles = {
|
|
44
|
+
primary: {
|
|
45
|
+
text: {
|
|
46
|
+
color,
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export default styles.primary.text.color;
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### Correct
|
|
55
|
+
|
|
56
|
+
Co-locate your styles next to your components to improve code readability, linting, and build performance.
|
|
57
|
+
|
|
58
|
+
```js
|
|
59
|
+
import { css } from '@compiled/react';
|
|
60
|
+
|
|
61
|
+
const styles = css({});
|
|
62
|
+
export const Component = ({ children }) => <div css={styles}>{children}></div>;
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
```js
|
|
66
|
+
import { keyframes } from '@compiled/react';
|
|
67
|
+
|
|
68
|
+
const animation = keyframes({});
|
|
69
|
+
const styles = css({ animate: `${animation} 1s ease-in` });
|
|
70
|
+
export const Component = ({ children }) => <div css={styles}>{children}></div>;
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Options
|
|
74
|
+
|
|
75
|
+
### importSources
|
|
76
|
+
|
|
77
|
+
By default, this rule will check `css` usages from:
|
|
78
|
+
|
|
79
|
+
- `@atlaskit/css`
|
|
80
|
+
- `@atlaskit/primitives`
|
|
81
|
+
- `@compiled/react`
|
|
82
|
+
- `@emotion/react`
|
|
83
|
+
- `@emotion/core`
|
|
84
|
+
- `@emotion/styled`
|
|
85
|
+
- `styled-components`
|
|
86
|
+
|
|
87
|
+
To change this list of libraries, you can define a custom set of `importSources`, which accepts an array of package names (strings).
|
|
@@ -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::42dc97374e2e4fd9ea068b3564bdcb72>>
|
|
10
10
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
11
11
|
*/
|
|
12
12
|
var _default = exports.default = {
|
|
@@ -19,6 +19,7 @@ var _default = exports.default = {
|
|
|
19
19
|
'@atlaskit/ui-styling-standard/no-classname-prop': 'warn',
|
|
20
20
|
'@atlaskit/ui-styling-standard/no-container-queries': 'warn',
|
|
21
21
|
'@atlaskit/ui-styling-standard/no-dynamic-styles': 'warn',
|
|
22
|
+
'@atlaskit/ui-styling-standard/no-exported-styles': 'warn',
|
|
22
23
|
'@atlaskit/ui-styling-standard/no-important-styles': 'warn',
|
|
23
24
|
'@atlaskit/ui-styling-standard/no-nested-selectors': 'warn',
|
|
24
25
|
'@atlaskit/ui-styling-standard/no-unsafe-values': '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::42dc97374e2e4fd9ea068b3564bdcb72>>
|
|
10
10
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
11
11
|
*/
|
|
12
12
|
var _default = exports.default = {
|
|
@@ -19,6 +19,7 @@ var _default = exports.default = {
|
|
|
19
19
|
'@atlaskit/ui-styling-standard/no-classname-prop': 'warn',
|
|
20
20
|
'@atlaskit/ui-styling-standard/no-container-queries': 'warn',
|
|
21
21
|
'@atlaskit/ui-styling-standard/no-dynamic-styles': 'warn',
|
|
22
|
+
'@atlaskit/ui-styling-standard/no-exported-styles': 'warn',
|
|
22
23
|
'@atlaskit/ui-styling-standard/no-important-styles': 'warn',
|
|
23
24
|
'@atlaskit/ui-styling-standard/no-nested-selectors': 'warn',
|
|
24
25
|
'@atlaskit/ui-styling-standard/no-unsafe-values': 'warn',
|
|
@@ -12,12 +12,13 @@ var _noArrayArguments = _interopRequireDefault(require("./no-array-arguments"));
|
|
|
12
12
|
var _noClassnameProp = _interopRequireDefault(require("./no-classname-prop"));
|
|
13
13
|
var _noContainerQueries = _interopRequireDefault(require("./no-container-queries"));
|
|
14
14
|
var _noDynamicStyles = _interopRequireDefault(require("./no-dynamic-styles"));
|
|
15
|
+
var _noExportedStyles = _interopRequireDefault(require("./no-exported-styles"));
|
|
15
16
|
var _noImportantStyles = _interopRequireDefault(require("./no-important-styles"));
|
|
16
17
|
var _noNestedSelectors = _interopRequireDefault(require("./no-nested-selectors"));
|
|
17
18
|
var _noUnsafeValues = _interopRequireDefault(require("./no-unsafe-values"));
|
|
18
19
|
/**
|
|
19
20
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
20
|
-
* @codegen <<SignedSource::
|
|
21
|
+
* @codegen <<SignedSource::1c60c9984196cab3d54e3144c59ba97c>>
|
|
21
22
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
22
23
|
*/
|
|
23
24
|
var _default = exports.default = {
|
|
@@ -28,6 +29,7 @@ var _default = exports.default = {
|
|
|
28
29
|
'no-classname-prop': _noClassnameProp.default,
|
|
29
30
|
'no-container-queries': _noContainerQueries.default,
|
|
30
31
|
'no-dynamic-styles': _noDynamicStyles.default,
|
|
32
|
+
'no-exported-styles': _noExportedStyles.default,
|
|
31
33
|
'no-important-styles': _noImportantStyles.default,
|
|
32
34
|
'no-nested-selectors': _noNestedSelectors.default,
|
|
33
35
|
'no-unsafe-values': _noUnsafeValues.default
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.rule = exports.default = void 0;
|
|
7
|
+
var _createRule = require("../utils/create-rule");
|
|
8
|
+
var _isSupportedImport = require("@atlaskit/eslint-utils/is-supported-import");
|
|
9
|
+
var _createNoExportedRule = require("@atlaskit/eslint-utils/create-no-exported-rule");
|
|
10
|
+
var schema = [{
|
|
11
|
+
type: 'object',
|
|
12
|
+
properties: {
|
|
13
|
+
importSources: {
|
|
14
|
+
type: 'array',
|
|
15
|
+
items: {
|
|
16
|
+
type: 'string'
|
|
17
|
+
},
|
|
18
|
+
uniqueItems: true
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}];
|
|
22
|
+
var supportedImports = [_isSupportedImport.isCss, _isSupportedImport.isCssMap, _isSupportedImport.isKeyframes, _isSupportedImport.isXcss, _isSupportedImport.isStyled];
|
|
23
|
+
var rule = exports.rule = (0, _createRule.createLintRule)({
|
|
24
|
+
meta: {
|
|
25
|
+
name: 'no-exported-styles',
|
|
26
|
+
docs: {
|
|
27
|
+
description: 'Disallows exports of css, keyframes, styled and xcss',
|
|
28
|
+
recommended: true,
|
|
29
|
+
severity: 'warn'
|
|
30
|
+
},
|
|
31
|
+
messages: {
|
|
32
|
+
'no-exported-styles': 'Styles from css, cssMap, keyframes, styled and xcss should not be exported. All styles should be defined and used in the same file instead.'
|
|
33
|
+
},
|
|
34
|
+
type: 'problem',
|
|
35
|
+
schema: schema
|
|
36
|
+
},
|
|
37
|
+
create: (0, _createNoExportedRule.createNoExportedRule)(supportedImports, 'no-exported-styles')
|
|
38
|
+
});
|
|
39
|
+
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::42dc97374e2e4fd9ea068b3564bdcb72>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
export default {
|
|
@@ -13,6 +13,7 @@ export default {
|
|
|
13
13
|
'@atlaskit/ui-styling-standard/no-classname-prop': 'warn',
|
|
14
14
|
'@atlaskit/ui-styling-standard/no-container-queries': 'warn',
|
|
15
15
|
'@atlaskit/ui-styling-standard/no-dynamic-styles': 'warn',
|
|
16
|
+
'@atlaskit/ui-styling-standard/no-exported-styles': 'warn',
|
|
16
17
|
'@atlaskit/ui-styling-standard/no-important-styles': 'warn',
|
|
17
18
|
'@atlaskit/ui-styling-standard/no-nested-selectors': 'warn',
|
|
18
19
|
'@atlaskit/ui-styling-standard/no-unsafe-values': '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::42dc97374e2e4fd9ea068b3564bdcb72>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
export default {
|
|
@@ -13,6 +13,7 @@ export default {
|
|
|
13
13
|
'@atlaskit/ui-styling-standard/no-classname-prop': 'warn',
|
|
14
14
|
'@atlaskit/ui-styling-standard/no-container-queries': 'warn',
|
|
15
15
|
'@atlaskit/ui-styling-standard/no-dynamic-styles': 'warn',
|
|
16
|
+
'@atlaskit/ui-styling-standard/no-exported-styles': 'warn',
|
|
16
17
|
'@atlaskit/ui-styling-standard/no-important-styles': 'warn',
|
|
17
18
|
'@atlaskit/ui-styling-standard/no-nested-selectors': 'warn',
|
|
18
19
|
'@atlaskit/ui-styling-standard/no-unsafe-values': '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::1c60c9984196cab3d54e3144c59ba97c>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
import convertPropsSyntax from './convert-props-syntax';
|
|
@@ -10,6 +10,7 @@ import noArrayArguments from './no-array-arguments';
|
|
|
10
10
|
import noClassnameProp from './no-classname-prop';
|
|
11
11
|
import noContainerQueries from './no-container-queries';
|
|
12
12
|
import noDynamicStyles from './no-dynamic-styles';
|
|
13
|
+
import noExportedStyles from './no-exported-styles';
|
|
13
14
|
import noImportantStyles from './no-important-styles';
|
|
14
15
|
import noNestedSelectors from './no-nested-selectors';
|
|
15
16
|
import noUnsafeValues from './no-unsafe-values';
|
|
@@ -21,6 +22,7 @@ export default {
|
|
|
21
22
|
'no-classname-prop': noClassnameProp,
|
|
22
23
|
'no-container-queries': noContainerQueries,
|
|
23
24
|
'no-dynamic-styles': noDynamicStyles,
|
|
25
|
+
'no-exported-styles': noExportedStyles,
|
|
24
26
|
'no-important-styles': noImportantStyles,
|
|
25
27
|
'no-nested-selectors': noNestedSelectors,
|
|
26
28
|
'no-unsafe-values': noUnsafeValues
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { createLintRule } from '../utils/create-rule';
|
|
2
|
+
import { isCss, isStyled, isKeyframes, isCssMap, isXcss } from '@atlaskit/eslint-utils/is-supported-import';
|
|
3
|
+
import { createNoExportedRule } from '@atlaskit/eslint-utils/create-no-exported-rule';
|
|
4
|
+
const schema = [{
|
|
5
|
+
type: 'object',
|
|
6
|
+
properties: {
|
|
7
|
+
importSources: {
|
|
8
|
+
type: 'array',
|
|
9
|
+
items: {
|
|
10
|
+
type: 'string'
|
|
11
|
+
},
|
|
12
|
+
uniqueItems: true
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}];
|
|
16
|
+
const supportedImports = [isCss, isCssMap, isKeyframes, isXcss, isStyled];
|
|
17
|
+
export const rule = createLintRule({
|
|
18
|
+
meta: {
|
|
19
|
+
name: 'no-exported-styles',
|
|
20
|
+
docs: {
|
|
21
|
+
description: 'Disallows exports of css, keyframes, styled and xcss',
|
|
22
|
+
recommended: true,
|
|
23
|
+
severity: 'warn'
|
|
24
|
+
},
|
|
25
|
+
messages: {
|
|
26
|
+
'no-exported-styles': 'Styles from css, cssMap, keyframes, styled and xcss should not be exported. All styles should be defined and used in the same file instead.'
|
|
27
|
+
},
|
|
28
|
+
type: 'problem',
|
|
29
|
+
schema
|
|
30
|
+
},
|
|
31
|
+
create: createNoExportedRule(supportedImports, 'no-exported-styles')
|
|
32
|
+
});
|
|
33
|
+
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::42dc97374e2e4fd9ea068b3564bdcb72>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
export default {
|
|
@@ -13,6 +13,7 @@ export default {
|
|
|
13
13
|
'@atlaskit/ui-styling-standard/no-classname-prop': 'warn',
|
|
14
14
|
'@atlaskit/ui-styling-standard/no-container-queries': 'warn',
|
|
15
15
|
'@atlaskit/ui-styling-standard/no-dynamic-styles': 'warn',
|
|
16
|
+
'@atlaskit/ui-styling-standard/no-exported-styles': 'warn',
|
|
16
17
|
'@atlaskit/ui-styling-standard/no-important-styles': 'warn',
|
|
17
18
|
'@atlaskit/ui-styling-standard/no-nested-selectors': 'warn',
|
|
18
19
|
'@atlaskit/ui-styling-standard/no-unsafe-values': '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::42dc97374e2e4fd9ea068b3564bdcb72>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
export default {
|
|
@@ -13,6 +13,7 @@ export default {
|
|
|
13
13
|
'@atlaskit/ui-styling-standard/no-classname-prop': 'warn',
|
|
14
14
|
'@atlaskit/ui-styling-standard/no-container-queries': 'warn',
|
|
15
15
|
'@atlaskit/ui-styling-standard/no-dynamic-styles': 'warn',
|
|
16
|
+
'@atlaskit/ui-styling-standard/no-exported-styles': 'warn',
|
|
16
17
|
'@atlaskit/ui-styling-standard/no-important-styles': 'warn',
|
|
17
18
|
'@atlaskit/ui-styling-standard/no-nested-selectors': 'warn',
|
|
18
19
|
'@atlaskit/ui-styling-standard/no-unsafe-values': '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::1c60c9984196cab3d54e3144c59ba97c>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
import convertPropsSyntax from './convert-props-syntax';
|
|
@@ -10,6 +10,7 @@ import noArrayArguments from './no-array-arguments';
|
|
|
10
10
|
import noClassnameProp from './no-classname-prop';
|
|
11
11
|
import noContainerQueries from './no-container-queries';
|
|
12
12
|
import noDynamicStyles from './no-dynamic-styles';
|
|
13
|
+
import noExportedStyles from './no-exported-styles';
|
|
13
14
|
import noImportantStyles from './no-important-styles';
|
|
14
15
|
import noNestedSelectors from './no-nested-selectors';
|
|
15
16
|
import noUnsafeValues from './no-unsafe-values';
|
|
@@ -21,6 +22,7 @@ export default {
|
|
|
21
22
|
'no-classname-prop': noClassnameProp,
|
|
22
23
|
'no-container-queries': noContainerQueries,
|
|
23
24
|
'no-dynamic-styles': noDynamicStyles,
|
|
25
|
+
'no-exported-styles': noExportedStyles,
|
|
24
26
|
'no-important-styles': noImportantStyles,
|
|
25
27
|
'no-nested-selectors': noNestedSelectors,
|
|
26
28
|
'no-unsafe-values': noUnsafeValues
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { createLintRule } from '../utils/create-rule';
|
|
2
|
+
import { isCss, isStyled, isKeyframes, isCssMap, isXcss } from '@atlaskit/eslint-utils/is-supported-import';
|
|
3
|
+
import { createNoExportedRule } from '@atlaskit/eslint-utils/create-no-exported-rule';
|
|
4
|
+
var schema = [{
|
|
5
|
+
type: 'object',
|
|
6
|
+
properties: {
|
|
7
|
+
importSources: {
|
|
8
|
+
type: 'array',
|
|
9
|
+
items: {
|
|
10
|
+
type: 'string'
|
|
11
|
+
},
|
|
12
|
+
uniqueItems: true
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}];
|
|
16
|
+
var supportedImports = [isCss, isCssMap, isKeyframes, isXcss, isStyled];
|
|
17
|
+
export var rule = createLintRule({
|
|
18
|
+
meta: {
|
|
19
|
+
name: 'no-exported-styles',
|
|
20
|
+
docs: {
|
|
21
|
+
description: 'Disallows exports of css, keyframes, styled and xcss',
|
|
22
|
+
recommended: true,
|
|
23
|
+
severity: 'warn'
|
|
24
|
+
},
|
|
25
|
+
messages: {
|
|
26
|
+
'no-exported-styles': 'Styles from css, cssMap, keyframes, styled and xcss should not be exported. All styles should be defined and used in the same file instead.'
|
|
27
|
+
},
|
|
28
|
+
type: 'problem',
|
|
29
|
+
schema: schema
|
|
30
|
+
},
|
|
31
|
+
create: createNoExportedRule(supportedImports, 'no-exported-styles')
|
|
32
|
+
});
|
|
33
|
+
export default rule;
|
|
@@ -10,6 +10,7 @@ export declare const configs: {
|
|
|
10
10
|
'@atlaskit/ui-styling-standard/no-classname-prop': string;
|
|
11
11
|
'@atlaskit/ui-styling-standard/no-container-queries': string;
|
|
12
12
|
'@atlaskit/ui-styling-standard/no-dynamic-styles': string;
|
|
13
|
+
'@atlaskit/ui-styling-standard/no-exported-styles': string;
|
|
13
14
|
'@atlaskit/ui-styling-standard/no-important-styles': string;
|
|
14
15
|
'@atlaskit/ui-styling-standard/no-nested-selectors': string;
|
|
15
16
|
'@atlaskit/ui-styling-standard/no-unsafe-values': string;
|
|
@@ -45,6 +46,7 @@ export declare const configs: {
|
|
|
45
46
|
'@atlaskit/ui-styling-standard/no-classname-prop': string;
|
|
46
47
|
'@atlaskit/ui-styling-standard/no-container-queries': string;
|
|
47
48
|
'@atlaskit/ui-styling-standard/no-dynamic-styles': string;
|
|
49
|
+
'@atlaskit/ui-styling-standard/no-exported-styles': string;
|
|
48
50
|
'@atlaskit/ui-styling-standard/no-important-styles': string;
|
|
49
51
|
'@atlaskit/ui-styling-standard/no-nested-selectors': string;
|
|
50
52
|
'@atlaskit/ui-styling-standard/no-unsafe-values': 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::42dc97374e2e4fd9ea068b3564bdcb72>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
declare const _default: {
|
|
@@ -13,6 +13,7 @@ declare const _default: {
|
|
|
13
13
|
'@atlaskit/ui-styling-standard/no-classname-prop': string;
|
|
14
14
|
'@atlaskit/ui-styling-standard/no-container-queries': string;
|
|
15
15
|
'@atlaskit/ui-styling-standard/no-dynamic-styles': string;
|
|
16
|
+
'@atlaskit/ui-styling-standard/no-exported-styles': string;
|
|
16
17
|
'@atlaskit/ui-styling-standard/no-important-styles': string;
|
|
17
18
|
'@atlaskit/ui-styling-standard/no-nested-selectors': string;
|
|
18
19
|
'@atlaskit/ui-styling-standard/no-unsafe-values': 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::42dc97374e2e4fd9ea068b3564bdcb72>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
declare const _default: {
|
|
@@ -13,6 +13,7 @@ declare const _default: {
|
|
|
13
13
|
'@atlaskit/ui-styling-standard/no-classname-prop': string;
|
|
14
14
|
'@atlaskit/ui-styling-standard/no-container-queries': string;
|
|
15
15
|
'@atlaskit/ui-styling-standard/no-dynamic-styles': string;
|
|
16
|
+
'@atlaskit/ui-styling-standard/no-exported-styles': string;
|
|
16
17
|
'@atlaskit/ui-styling-standard/no-important-styles': string;
|
|
17
18
|
'@atlaskit/ui-styling-standard/no-nested-selectors': string;
|
|
18
19
|
'@atlaskit/ui-styling-standard/no-unsafe-values': string;
|
|
@@ -6,6 +6,7 @@ declare const _default: {
|
|
|
6
6
|
'no-classname-prop': import("eslint").Rule.RuleModule;
|
|
7
7
|
'no-container-queries': import("eslint").Rule.RuleModule;
|
|
8
8
|
'no-dynamic-styles': import("eslint").Rule.RuleModule;
|
|
9
|
+
'no-exported-styles': import("eslint").Rule.RuleModule;
|
|
9
10
|
'no-important-styles': import("eslint").Rule.RuleModule;
|
|
10
11
|
'no-nested-selectors': import("eslint").Rule.RuleModule;
|
|
11
12
|
'no-unsafe-values': import("eslint").Rule.RuleModule;
|
|
@@ -10,6 +10,7 @@ export declare const configs: {
|
|
|
10
10
|
'@atlaskit/ui-styling-standard/no-classname-prop': string;
|
|
11
11
|
'@atlaskit/ui-styling-standard/no-container-queries': string;
|
|
12
12
|
'@atlaskit/ui-styling-standard/no-dynamic-styles': string;
|
|
13
|
+
'@atlaskit/ui-styling-standard/no-exported-styles': string;
|
|
13
14
|
'@atlaskit/ui-styling-standard/no-important-styles': string;
|
|
14
15
|
'@atlaskit/ui-styling-standard/no-nested-selectors': string;
|
|
15
16
|
'@atlaskit/ui-styling-standard/no-unsafe-values': string;
|
|
@@ -45,6 +46,7 @@ export declare const configs: {
|
|
|
45
46
|
'@atlaskit/ui-styling-standard/no-classname-prop': string;
|
|
46
47
|
'@atlaskit/ui-styling-standard/no-container-queries': string;
|
|
47
48
|
'@atlaskit/ui-styling-standard/no-dynamic-styles': string;
|
|
49
|
+
'@atlaskit/ui-styling-standard/no-exported-styles': string;
|
|
48
50
|
'@atlaskit/ui-styling-standard/no-important-styles': string;
|
|
49
51
|
'@atlaskit/ui-styling-standard/no-nested-selectors': string;
|
|
50
52
|
'@atlaskit/ui-styling-standard/no-unsafe-values': 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::42dc97374e2e4fd9ea068b3564bdcb72>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
declare const _default: {
|
|
@@ -13,6 +13,7 @@ declare const _default: {
|
|
|
13
13
|
'@atlaskit/ui-styling-standard/no-classname-prop': string;
|
|
14
14
|
'@atlaskit/ui-styling-standard/no-container-queries': string;
|
|
15
15
|
'@atlaskit/ui-styling-standard/no-dynamic-styles': string;
|
|
16
|
+
'@atlaskit/ui-styling-standard/no-exported-styles': string;
|
|
16
17
|
'@atlaskit/ui-styling-standard/no-important-styles': string;
|
|
17
18
|
'@atlaskit/ui-styling-standard/no-nested-selectors': string;
|
|
18
19
|
'@atlaskit/ui-styling-standard/no-unsafe-values': 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::42dc97374e2e4fd9ea068b3564bdcb72>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
declare const _default: {
|
|
@@ -13,6 +13,7 @@ declare const _default: {
|
|
|
13
13
|
'@atlaskit/ui-styling-standard/no-classname-prop': string;
|
|
14
14
|
'@atlaskit/ui-styling-standard/no-container-queries': string;
|
|
15
15
|
'@atlaskit/ui-styling-standard/no-dynamic-styles': string;
|
|
16
|
+
'@atlaskit/ui-styling-standard/no-exported-styles': string;
|
|
16
17
|
'@atlaskit/ui-styling-standard/no-important-styles': string;
|
|
17
18
|
'@atlaskit/ui-styling-standard/no-nested-selectors': string;
|
|
18
19
|
'@atlaskit/ui-styling-standard/no-unsafe-values': string;
|
|
@@ -6,6 +6,7 @@ declare const _default: {
|
|
|
6
6
|
'no-classname-prop': import("eslint").Rule.RuleModule;
|
|
7
7
|
'no-container-queries': import("eslint").Rule.RuleModule;
|
|
8
8
|
'no-dynamic-styles': import("eslint").Rule.RuleModule;
|
|
9
|
+
'no-exported-styles': import("eslint").Rule.RuleModule;
|
|
9
10
|
'no-important-styles': import("eslint").Rule.RuleModule;
|
|
10
11
|
'no-nested-selectors': import("eslint").Rule.RuleModule;
|
|
11
12
|
'no-unsafe-values': import("eslint").Rule.RuleModule;
|
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::42dc97374e2e4fd9ea068b3564bdcb72>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
export default {
|
|
@@ -17,6 +17,7 @@ export default {
|
|
|
17
17
|
'@atlaskit/ui-styling-standard/no-classname-prop': 'warn',
|
|
18
18
|
'@atlaskit/ui-styling-standard/no-container-queries': 'warn',
|
|
19
19
|
'@atlaskit/ui-styling-standard/no-dynamic-styles': 'warn',
|
|
20
|
+
'@atlaskit/ui-styling-standard/no-exported-styles': 'warn',
|
|
20
21
|
'@atlaskit/ui-styling-standard/no-important-styles': 'warn',
|
|
21
22
|
'@atlaskit/ui-styling-standard/no-nested-selectors': 'warn',
|
|
22
23
|
'@atlaskit/ui-styling-standard/no-unsafe-values': '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::42dc97374e2e4fd9ea068b3564bdcb72>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
export default {
|
|
@@ -17,6 +17,7 @@ export default {
|
|
|
17
17
|
'@atlaskit/ui-styling-standard/no-classname-prop': 'warn',
|
|
18
18
|
'@atlaskit/ui-styling-standard/no-container-queries': 'warn',
|
|
19
19
|
'@atlaskit/ui-styling-standard/no-dynamic-styles': 'warn',
|
|
20
|
+
'@atlaskit/ui-styling-standard/no-exported-styles': 'warn',
|
|
20
21
|
'@atlaskit/ui-styling-standard/no-important-styles': 'warn',
|
|
21
22
|
'@atlaskit/ui-styling-standard/no-nested-selectors': 'warn',
|
|
22
23
|
'@atlaskit/ui-styling-standard/no-unsafe-values': '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::1c60c9984196cab3d54e3144c59ba97c>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
import convertPropsSyntax from './convert-props-syntax';
|
|
@@ -10,6 +10,7 @@ import noArrayArguments from './no-array-arguments';
|
|
|
10
10
|
import noClassnameProp from './no-classname-prop';
|
|
11
11
|
import noContainerQueries from './no-container-queries';
|
|
12
12
|
import noDynamicStyles from './no-dynamic-styles';
|
|
13
|
+
import noExportedStyles from './no-exported-styles';
|
|
13
14
|
import noImportantStyles from './no-important-styles';
|
|
14
15
|
import noNestedSelectors from './no-nested-selectors';
|
|
15
16
|
import noUnsafeValues from './no-unsafe-values';
|
|
@@ -22,6 +23,7 @@ export default {
|
|
|
22
23
|
'no-classname-prop': noClassnameProp,
|
|
23
24
|
'no-container-queries': noContainerQueries,
|
|
24
25
|
'no-dynamic-styles': noDynamicStyles,
|
|
26
|
+
'no-exported-styles': noExportedStyles,
|
|
25
27
|
'no-important-styles': noImportantStyles,
|
|
26
28
|
'no-nested-selectors': noNestedSelectors,
|
|
27
29
|
'no-unsafe-values': noUnsafeValues,
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
This rule disallows exports of `css`, `cssMap`, `keyframes`, `styled`, `xcss` styles.
|
|
2
|
+
|
|
3
|
+
Exporting style declarations from these libraries may result in unexpected errors when imported, because its value will be null at runtime. Additionally, co-locating style definitions with their usage is considered best practice in order to improve code readability and build performance.
|
|
4
|
+
|
|
5
|
+
## Examples
|
|
6
|
+
|
|
7
|
+
### Incorrect
|
|
8
|
+
|
|
9
|
+
```js
|
|
10
|
+
import { css } from '@compiled/react';
|
|
11
|
+
|
|
12
|
+
export const styles = css({});
|
|
13
|
+
|
|
14
|
+
export default css({});
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
```js
|
|
18
|
+
import { keyframes } from '@compiled/react';
|
|
19
|
+
|
|
20
|
+
export const animation = keyframes({});
|
|
21
|
+
|
|
22
|
+
export default keyframes({});
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Avoid exporting any style-like objects or values for consumption as well as these will violate our `no-imported-style-values` rule which blocks consumption of imported styles.
|
|
26
|
+
|
|
27
|
+
```js
|
|
28
|
+
export default {
|
|
29
|
+
color: 'red',
|
|
30
|
+
margin: '0px',
|
|
31
|
+
};
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
```js
|
|
35
|
+
import { css } from '@compiled/react';
|
|
36
|
+
|
|
37
|
+
const color = css({
|
|
38
|
+
/* */
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
const styles = {
|
|
42
|
+
primary: {
|
|
43
|
+
text: {
|
|
44
|
+
color,
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export default styles.primary.text.color;
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### Correct
|
|
53
|
+
|
|
54
|
+
Co-locate your styles next to your components to improve code readability, linting, and build performance.
|
|
55
|
+
|
|
56
|
+
```js
|
|
57
|
+
import { css } from '@compiled/react';
|
|
58
|
+
|
|
59
|
+
const styles = css({});
|
|
60
|
+
export const Component = ({ children }) => <div css={styles}>{children}></div>;
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
```js
|
|
64
|
+
import { keyframes } from '@compiled/react';
|
|
65
|
+
|
|
66
|
+
const animation = keyframes({});
|
|
67
|
+
const styles = css({ animate: `${animation} 1s ease-in` });
|
|
68
|
+
export const Component = ({ children }) => <div css={styles}>{children}></div>;
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Options
|
|
72
|
+
|
|
73
|
+
### importSources
|
|
74
|
+
|
|
75
|
+
By default, this rule will check `css` usages from:
|
|
76
|
+
|
|
77
|
+
- `@atlaskit/css`
|
|
78
|
+
- `@atlaskit/primitives`
|
|
79
|
+
- `@compiled/react`
|
|
80
|
+
- `@emotion/react`
|
|
81
|
+
- `@emotion/core`
|
|
82
|
+
- `@emotion/styled`
|
|
83
|
+
- `styled-components`
|
|
84
|
+
|
|
85
|
+
To change this list of libraries, you can define a custom set of `importSources`, which accepts an array of package names (strings).
|
|
@@ -0,0 +1,225 @@
|
|
|
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: [
|
|
79
|
+
{ messageId: 'no-exported-styles' },
|
|
80
|
+
{ messageId: 'no-exported-styles' },
|
|
81
|
+
],
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
name: 'Export of css from emotion',
|
|
85
|
+
code: `
|
|
86
|
+
import { css } from '@emotion/react';
|
|
87
|
+
|
|
88
|
+
export const styles = css(
|
|
89
|
+
{
|
|
90
|
+
display: 'flex',
|
|
91
|
+
position: 'relative',
|
|
92
|
+
},
|
|
93
|
+
borderRadius,
|
|
94
|
+
);
|
|
95
|
+
`,
|
|
96
|
+
errors: [{ messageId: 'no-exported-styles' }],
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
name: 'Export of cssMap',
|
|
100
|
+
code: `
|
|
101
|
+
import { cssMap } from '@compiled/react';
|
|
102
|
+
|
|
103
|
+
export const borderStyleMap = cssMap({
|
|
104
|
+
none: { borderStyle: 'none' },
|
|
105
|
+
solid: { borderStyle: 'solid' },
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
export default cssMap({});
|
|
109
|
+
`,
|
|
110
|
+
errors: [
|
|
111
|
+
{ messageId: 'no-exported-styles' },
|
|
112
|
+
{ messageId: 'no-exported-styles' },
|
|
113
|
+
],
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
name: 'Export of keyframes',
|
|
117
|
+
code: `
|
|
118
|
+
import { keyframes } from '@compiled/react';
|
|
119
|
+
|
|
120
|
+
export const animation = keyframes({});
|
|
121
|
+
|
|
122
|
+
export default keyframes({});
|
|
123
|
+
`,
|
|
124
|
+
errors: [
|
|
125
|
+
{ messageId: 'no-exported-styles' },
|
|
126
|
+
{ messageId: 'no-exported-styles' },
|
|
127
|
+
],
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
name: 'Exporting styled component',
|
|
131
|
+
code: `
|
|
132
|
+
import { styled } from '@compiled/react';
|
|
133
|
+
|
|
134
|
+
export const Component = styled.div({});
|
|
135
|
+
`,
|
|
136
|
+
errors: [{ messageId: 'no-exported-styles' }],
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
name: 'Exporting css styles',
|
|
140
|
+
code: `
|
|
141
|
+
import { css } from '@compiled/react';
|
|
142
|
+
import { colors, getColor } from '@mui/theme';
|
|
143
|
+
import { ff } from '@atlaskit/ff';
|
|
144
|
+
|
|
145
|
+
import { buttonStyles, cssShared, colorKey } from '../shared';
|
|
146
|
+
|
|
147
|
+
const sharedObject = { padding: 0 };
|
|
148
|
+
|
|
149
|
+
export const styles = css({
|
|
150
|
+
...cssShared,
|
|
151
|
+
...sharedObject,
|
|
152
|
+
[colorKey]: getColor('red'),
|
|
153
|
+
background: colors['red'],
|
|
154
|
+
});
|
|
155
|
+
`,
|
|
156
|
+
errors: [{ messageId: 'no-exported-styles' }],
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
name: 'Export let css',
|
|
160
|
+
code: `
|
|
161
|
+
import { css } from '@compiled/react';
|
|
162
|
+
|
|
163
|
+
export let styles = css({});
|
|
164
|
+
`,
|
|
165
|
+
errors: [{ messageId: 'no-exported-styles' }],
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
name: 'Export style in object',
|
|
169
|
+
code: `
|
|
170
|
+
import { css } from '@compiled/react';
|
|
171
|
+
|
|
172
|
+
const styles = css({});
|
|
173
|
+
|
|
174
|
+
export { styles };
|
|
175
|
+
`,
|
|
176
|
+
errors: [{ messageId: 'no-exported-styles' }],
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
name: 'Exporting nested style',
|
|
180
|
+
code: `
|
|
181
|
+
import { css } from '@compiled/react';
|
|
182
|
+
|
|
183
|
+
const styles = {
|
|
184
|
+
primary: css({}),
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
export { styles };
|
|
188
|
+
`,
|
|
189
|
+
errors: [{ messageId: 'no-exported-styles' }],
|
|
190
|
+
},
|
|
191
|
+
{
|
|
192
|
+
name: 'Exporting styled components',
|
|
193
|
+
code: `
|
|
194
|
+
import styled from 'styled-components'
|
|
195
|
+
|
|
196
|
+
export const PasswordInput = styled.input.attrs(props => ({
|
|
197
|
+
type: "password"
|
|
198
|
+
}))
|
|
199
|
+
`,
|
|
200
|
+
errors: [{ messageId: 'no-exported-styles' }],
|
|
201
|
+
},
|
|
202
|
+
{
|
|
203
|
+
name: 'Exporting styled component with base component',
|
|
204
|
+
code: `
|
|
205
|
+
import styled from 'styled-components'
|
|
206
|
+
|
|
207
|
+
const BaseComponent = styled.div({});
|
|
208
|
+
export const Component = styled(BaseComponent)({});
|
|
209
|
+
`,
|
|
210
|
+
errors: [{ messageId: 'no-exported-styles' }],
|
|
211
|
+
},
|
|
212
|
+
{
|
|
213
|
+
name: 'Exporting styled component from compiled',
|
|
214
|
+
code: `
|
|
215
|
+
import { styled as styled2 } from '@compiled/react'
|
|
216
|
+
|
|
217
|
+
export const Component = styled2.div({
|
|
218
|
+
margin: \`\${token('space.200', '16px')} 0\`,
|
|
219
|
+
})
|
|
220
|
+
`,
|
|
221
|
+
errors: [{ messageId: 'no-exported-styles' }],
|
|
222
|
+
},
|
|
223
|
+
],
|
|
224
|
+
},
|
|
225
|
+
);
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { createLintRule } from '../utils/create-rule';
|
|
2
|
+
import {
|
|
3
|
+
isCss,
|
|
4
|
+
isStyled,
|
|
5
|
+
isKeyframes,
|
|
6
|
+
isCssMap,
|
|
7
|
+
isXcss,
|
|
8
|
+
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: 'warn',
|
|
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;
|