@atlaskit/eslint-plugin-ui-styling-standard 0.12.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 +21 -0
- package/README.md +2 -0
- package/constellation/index/overview.mdx +3 -1
- package/constellation/no-global-styles/usage.mdx +59 -0
- package/constellation/no-styled/usage.mdx +89 -0
- package/constellation/use-compiled/usage.mdx +20 -17
- package/dist/cjs/presets/all.codegen.js +3 -1
- package/dist/cjs/presets/recommended.codegen.js +3 -1
- package/dist/cjs/rules/index.codegen.js +5 -1
- package/dist/cjs/rules/no-global-styles/index.js +100 -0
- package/dist/cjs/rules/no-styled/index.js +67 -0
- package/dist/es2019/presets/all.codegen.js +3 -1
- package/dist/es2019/presets/recommended.codegen.js +3 -1
- package/dist/es2019/rules/index.codegen.js +5 -1
- package/dist/es2019/rules/no-global-styles/index.js +67 -0
- package/dist/es2019/rules/no-styled/index.js +45 -0
- package/dist/esm/presets/all.codegen.js +3 -1
- package/dist/esm/presets/recommended.codegen.js +3 -1
- package/dist/esm/rules/index.codegen.js +5 -1
- package/dist/esm/rules/no-global-styles/index.js +94 -0
- package/dist/esm/rules/no-styled/index.js +61 -0
- package/dist/types/index.codegen.d.ts +4 -0
- package/dist/types/presets/all.codegen.d.ts +3 -1
- package/dist/types/presets/recommended.codegen.d.ts +3 -1
- package/dist/types/rules/index.codegen.d.ts +2 -0
- package/dist/types/rules/no-global-styles/index.d.ts +2 -0
- package/dist/types/rules/no-styled/index.d.ts +2 -0
- package/dist/types-ts4.5/index.codegen.d.ts +4 -0
- package/dist/types-ts4.5/presets/all.codegen.d.ts +3 -1
- package/dist/types-ts4.5/presets/recommended.codegen.d.ts +3 -1
- package/dist/types-ts4.5/rules/index.codegen.d.ts +2 -0
- package/dist/types-ts4.5/rules/no-global-styles/index.d.ts +2 -0
- package/dist/types-ts4.5/rules/no-styled/index.d.ts +2 -0
- package/package.json +2 -2
- package/src/presets/all.codegen.tsx +3 -1
- package/src/presets/recommended.codegen.tsx +3 -1
- package/src/rules/index.codegen.tsx +5 -1
- package/src/rules/no-global-styles/README.md +56 -0
- package/src/rules/no-global-styles/__tests__/no-css-modules.test.tsx +33 -0
- package/src/rules/no-global-styles/__tests__/no-global-styles.test.tsx +46 -0
- package/src/rules/no-global-styles/index.tsx +85 -0
- 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/src/rules/use-compiled/README.md +16 -16
- package/src/rules/use-compiled/__tests__/imports.test.tsx +24 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
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
|
+
|
|
11
|
+
## 0.13.0
|
|
12
|
+
|
|
13
|
+
### Minor Changes
|
|
14
|
+
|
|
15
|
+
- [#99544](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/99544)
|
|
16
|
+
[`391edf6de450`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/391edf6de450) -
|
|
17
|
+
Added `no-global-styles` rule which prevents:
|
|
18
|
+
|
|
19
|
+
- The `Global` API from `@emotion`
|
|
20
|
+
- The `createGlobalStyle` and `injectGlobal` APIs from `styled-components`
|
|
21
|
+
- `<style>` elements in JSX
|
|
22
|
+
- CSS imports (including SASS and LESS)
|
|
23
|
+
|
|
3
24
|
## 0.12.0
|
|
4
25
|
|
|
5
26
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -51,9 +51,11 @@ module.exports = {
|
|
|
51
51
|
| <a href="./src/rules/no-container-queries/README.md">no-container-queries</a> | Prevents usage of @container query within css styling | Yes | | |
|
|
52
52
|
| <a href="./src/rules/no-dynamic-styles/README.md">no-dynamic-styles</a> | Disallows use of dynamic styles in CSS-in-JS calls | Yes | | |
|
|
53
53
|
| <a href="./src/rules/no-exported-styles/README.md">no-exported-styles</a> | Disallows exports of css, keyframes, styled and xcss | Yes | | |
|
|
54
|
+
| <a href="./src/rules/no-global-styles/README.md">no-global-styles</a> | Prevents global styles through CSS-in-JS or CSS module imports | Yes | | |
|
|
54
55
|
| <a href="./src/rules/no-important-styles/README.md">no-important-styles</a> | Disallows important style declarations | Yes | | |
|
|
55
56
|
| <a href="./src/rules/no-imported-style-values/README.md">no-imported-style-values</a> | Disallows imports of style values | Yes | | |
|
|
56
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 | | |
|
|
57
59
|
| <a href="./src/rules/no-unsafe-values/README.md">no-unsafe-values</a> | Disallows styles that are difficult/impossible to statically anaylze. | Yes | | |
|
|
58
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 | |
|
|
59
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 | |
|
|
@@ -20,9 +20,11 @@ but more are planned to support the standard over time.
|
|
|
20
20
|
| <a href="no-container-queries/usage">no-container-queries</a> | Prevents usage of @container query within css styling | Yes | | |
|
|
21
21
|
| <a href="no-dynamic-styles/usage">no-dynamic-styles</a> | Disallows use of dynamic styles in CSS-in-JS calls | Yes | | |
|
|
22
22
|
| <a href="no-exported-styles/usage">no-exported-styles</a> | Disallows exports of css, keyframes, styled and xcss | Yes | | |
|
|
23
|
+
| <a href="no-global-styles/usage">no-global-styles</a> | Prevents global styles through CSS-in-JS or CSS module imports | Yes | | |
|
|
23
24
|
| <a href="no-important-styles/usage">no-important-styles</a> | Disallows important style declarations | Yes | | |
|
|
24
25
|
| <a href="no-imported-style-values/usage">no-imported-style-values</a> | Disallows imports of style values | Yes | | |
|
|
25
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 | | |
|
|
26
28
|
| <a href="no-unsafe-values/usage">no-unsafe-values</a> | Disallows styles that are difficult/impossible to statically anaylze. | Yes | | |
|
|
27
29
|
| <a href="use-compiled/usage">use-compiled</a> | Ensures usage of `@compiled/react` instead of other CSS-in-JS libraries | Yes | Yes | |
|
|
28
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 | |
|
|
@@ -154,7 +156,7 @@ export const Component = ({
|
|
|
154
156
|
Every element should be clear in isolation how it's styled, using locally and statically available
|
|
155
157
|
context so both humans and tooling can read this component in a performant and deterministic manner.
|
|
156
158
|
|
|
157
|
-
1. Use `@compiled
|
|
159
|
+
1. Use `@compiled/react` or [Primitives](/components/primitives/overview) wherever possible!
|
|
158
160
|
2. Instead of dynamic styles:
|
|
159
161
|
1. Use static `css()` calls everywhere.
|
|
160
162
|
2. Compose styles together, turning styles on or off.
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# no-global-styles
|
|
2
|
+
|
|
3
|
+
This rule prevents global styles through CSS-in-JS or CSS module imports.
|
|
4
|
+
|
|
5
|
+
Requiring local definition of styles helps to ensure that style dependencies are statically
|
|
6
|
+
resolvable.
|
|
7
|
+
|
|
8
|
+
## Examples
|
|
9
|
+
|
|
10
|
+
### Incorrect
|
|
11
|
+
|
|
12
|
+
```tsx
|
|
13
|
+
import { Global } from '@emotion/react';
|
|
14
|
+
|
|
15
|
+
<Global
|
|
16
|
+
styles={{
|
|
17
|
+
'.some-class': {
|
|
18
|
+
fontSize: 50,
|
|
19
|
+
textAlign: 'center',
|
|
20
|
+
},
|
|
21
|
+
}}
|
|
22
|
+
/>;
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
```tsx
|
|
26
|
+
import { createGlobalStyle } from 'styled-components';
|
|
27
|
+
|
|
28
|
+
const GlobalStyle = createGlobalStyle({
|
|
29
|
+
body: {
|
|
30
|
+
margin: 0,
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
```tsx
|
|
36
|
+
import { injectGlobal } from 'styled-components';
|
|
37
|
+
|
|
38
|
+
injectGlobal({
|
|
39
|
+
body: {
|
|
40
|
+
margin: 0,
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
```tsx
|
|
46
|
+
<style>
|
|
47
|
+
{`
|
|
48
|
+
.some-class {
|
|
49
|
+
color: red;
|
|
50
|
+
}
|
|
51
|
+
`}
|
|
52
|
+
</style>
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### Correct
|
|
56
|
+
|
|
57
|
+
```tsx
|
|
58
|
+
import '@atlaskit/css-reset';
|
|
59
|
+
```
|
|
@@ -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.
|
|
@@ -1,27 +1,20 @@
|
|
|
1
1
|
# use-compiled
|
|
2
2
|
|
|
3
|
-
Ensures usage of `@compiled/react` over other CSS-in-JS libraries.
|
|
3
|
+
Ensures usage of `@compiled/react` over other CSS-in-JS libraries like Emotion or styled-components.
|
|
4
4
|
|
|
5
|
-
**WARNING**
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
When converting to `@compiled/react` verify ALL changes.
|
|
10
|
-
|
|
11
|
-
For this reason, the auto-fixer has been disabled by default.
|
|
5
|
+
**WARNING** It may be unsafe to mix usages of `@compiled/react` with other CSS-in-JS libraries on
|
|
6
|
+
the same component. When converting to `@compiled/react` verify ALL changes. For this reason, the
|
|
7
|
+
auto-fixer has been disabled by default, but it may be useful to enable to empower a migration.
|
|
12
8
|
|
|
13
9
|
## Examples
|
|
14
10
|
|
|
15
11
|
### Incorrect
|
|
16
12
|
|
|
17
|
-
```js
|
|
18
|
-
import { css } from '@emotion/core';
|
|
19
|
-
import styled from '@emotion/styled';
|
|
20
|
-
```
|
|
21
|
-
|
|
22
13
|
```js
|
|
23
14
|
/** @jsx jsx */
|
|
15
|
+
import { css } from '@emotion/core';
|
|
24
16
|
import { jsx } from '@emotion/react';
|
|
17
|
+
import styled from '@emotion/styled';
|
|
25
18
|
```
|
|
26
19
|
|
|
27
20
|
```js
|
|
@@ -30,13 +23,22 @@ import styled, { css } from 'styled-components';
|
|
|
30
23
|
|
|
31
24
|
### Correct
|
|
32
25
|
|
|
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
|
+
|
|
33
29
|
```js
|
|
34
|
-
|
|
30
|
+
/** @jsx jsx */
|
|
31
|
+
import { jsx, css, styled } from '@compiled/react';
|
|
32
|
+
|
|
33
|
+
const styles = css({ color: 'var(--ds-color-text)' });
|
|
34
|
+
export default () => <div css={styles}>…</div>;
|
|
35
35
|
```
|
|
36
36
|
|
|
37
37
|
```js
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
import { xcss, Box } from '@atlaskit/primitives';
|
|
39
|
+
|
|
40
|
+
const styles = xcss({ color: 'color.text' });
|
|
41
|
+
export default () => <Box xcss={styles}>…</Box>;
|
|
40
42
|
```
|
|
41
43
|
|
|
42
44
|
## Options
|
|
@@ -45,7 +47,8 @@ import { jsx } from '@compiled/react';
|
|
|
45
47
|
|
|
46
48
|
Determines whether or not the auto-fixer is enabled.
|
|
47
49
|
|
|
48
|
-
Defaults to `false` due to safety concerns when mixing Compiled and other CSS-in-JS libraries
|
|
50
|
+
Defaults to `false` due to safety concerns when mixing Compiled and other CSS-in-JS libraries on the
|
|
51
|
+
same component.
|
|
49
52
|
|
|
50
53
|
Even when enabled, the auto-fixer will only convert usages that are deemed safe. Currently this is
|
|
51
54
|
limited to purely static styles where all keys and values are simple literals.
|
|
@@ -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 = {
|
|
@@ -21,9 +21,11 @@ var _default = exports.default = {
|
|
|
21
21
|
'@atlaskit/ui-styling-standard/no-container-queries': 'warn',
|
|
22
22
|
'@atlaskit/ui-styling-standard/no-dynamic-styles': 'warn',
|
|
23
23
|
'@atlaskit/ui-styling-standard/no-exported-styles': 'warn',
|
|
24
|
+
'@atlaskit/ui-styling-standard/no-global-styles': 'warn',
|
|
24
25
|
'@atlaskit/ui-styling-standard/no-important-styles': 'warn',
|
|
25
26
|
'@atlaskit/ui-styling-standard/no-imported-style-values': 'warn',
|
|
26
27
|
'@atlaskit/ui-styling-standard/no-nested-selectors': 'warn',
|
|
28
|
+
'@atlaskit/ui-styling-standard/no-styled': 'warn',
|
|
27
29
|
'@atlaskit/ui-styling-standard/no-unsafe-values': 'warn',
|
|
28
30
|
'@atlaskit/ui-styling-standard/use-compiled': 'warn',
|
|
29
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 = {
|
|
@@ -21,9 +21,11 @@ var _default = exports.default = {
|
|
|
21
21
|
'@atlaskit/ui-styling-standard/no-container-queries': 'warn',
|
|
22
22
|
'@atlaskit/ui-styling-standard/no-dynamic-styles': 'warn',
|
|
23
23
|
'@atlaskit/ui-styling-standard/no-exported-styles': 'warn',
|
|
24
|
+
'@atlaskit/ui-styling-standard/no-global-styles': 'warn',
|
|
24
25
|
'@atlaskit/ui-styling-standard/no-important-styles': 'warn',
|
|
25
26
|
'@atlaskit/ui-styling-standard/no-imported-style-values': 'warn',
|
|
26
27
|
'@atlaskit/ui-styling-standard/no-nested-selectors': 'warn',
|
|
28
|
+
'@atlaskit/ui-styling-standard/no-styled': 'warn',
|
|
27
29
|
'@atlaskit/ui-styling-standard/no-unsafe-values': 'warn',
|
|
28
30
|
'@atlaskit/ui-styling-standard/use-compiled': 'warn',
|
|
29
31
|
'@atlaskit/design-system/consistent-css-prop-usage': ['warn', {
|
|
@@ -14,14 +14,16 @@ var _noClassnameProp = _interopRequireDefault(require("./no-classname-prop"));
|
|
|
14
14
|
var _noContainerQueries = _interopRequireDefault(require("./no-container-queries"));
|
|
15
15
|
var _noDynamicStyles = _interopRequireDefault(require("./no-dynamic-styles"));
|
|
16
16
|
var _noExportedStyles = _interopRequireDefault(require("./no-exported-styles"));
|
|
17
|
+
var _noGlobalStyles = _interopRequireDefault(require("./no-global-styles"));
|
|
17
18
|
var _noImportantStyles = _interopRequireDefault(require("./no-important-styles"));
|
|
18
19
|
var _noImportedStyleValues = _interopRequireDefault(require("./no-imported-style-values"));
|
|
19
20
|
var _noNestedSelectors = _interopRequireDefault(require("./no-nested-selectors"));
|
|
21
|
+
var _noStyled = _interopRequireDefault(require("./no-styled"));
|
|
20
22
|
var _noUnsafeValues = _interopRequireDefault(require("./no-unsafe-values"));
|
|
21
23
|
var _useCompiled = _interopRequireDefault(require("./use-compiled"));
|
|
22
24
|
/**
|
|
23
25
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
24
|
-
* @codegen <<SignedSource::
|
|
26
|
+
* @codegen <<SignedSource::417762b5fc4a56c3b69c22b8ac0d12e7>>
|
|
25
27
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
26
28
|
*/
|
|
27
29
|
var _default = exports.default = {
|
|
@@ -34,9 +36,11 @@ var _default = exports.default = {
|
|
|
34
36
|
'no-container-queries': _noContainerQueries.default,
|
|
35
37
|
'no-dynamic-styles': _noDynamicStyles.default,
|
|
36
38
|
'no-exported-styles': _noExportedStyles.default,
|
|
39
|
+
'no-global-styles': _noGlobalStyles.default,
|
|
37
40
|
'no-important-styles': _noImportantStyles.default,
|
|
38
41
|
'no-imported-style-values': _noImportedStyleValues.default,
|
|
39
42
|
'no-nested-selectors': _noNestedSelectors.default,
|
|
43
|
+
'no-styled': _noStyled.default,
|
|
40
44
|
'no-unsafe-values': _noUnsafeValues.default,
|
|
41
45
|
'use-compiled': _useCompiled.default
|
|
42
46
|
};
|
|
@@ -0,0 +1,100 @@
|
|
|
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
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
9
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
10
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
11
|
+
var restrictedFileTypes = ['.css', '.less', '.sass', '.scss'];
|
|
12
|
+
var restrictedImports = {
|
|
13
|
+
'@emotion/core': ['Global'],
|
|
14
|
+
'@emotion/react': ['Global'],
|
|
15
|
+
'styled-components': ['createGlobalStyle', 'injectGlobal']
|
|
16
|
+
};
|
|
17
|
+
function isRestrictedImportSource(importSource) {
|
|
18
|
+
return importSource in restrictedImports;
|
|
19
|
+
}
|
|
20
|
+
var rule = exports.rule = (0, _createRule.createLintRule)({
|
|
21
|
+
meta: {
|
|
22
|
+
name: 'no-global-styles',
|
|
23
|
+
docs: {
|
|
24
|
+
description: 'Prevents global styles through CSS-in-JS or CSS module imports',
|
|
25
|
+
recommended: true,
|
|
26
|
+
severity: 'warn'
|
|
27
|
+
},
|
|
28
|
+
messages: {
|
|
29
|
+
'no-global-styles': 'Global styles are not allowed.',
|
|
30
|
+
'no-css-modules': 'Importing CSS files is not allowed.'
|
|
31
|
+
},
|
|
32
|
+
type: 'problem'
|
|
33
|
+
},
|
|
34
|
+
create: function create(context) {
|
|
35
|
+
function checkFileType(node) {
|
|
36
|
+
var importSource = node.source.value;
|
|
37
|
+
if (restrictedFileTypes.some(function (suffix) {
|
|
38
|
+
return importSource.endsWith(suffix);
|
|
39
|
+
})) {
|
|
40
|
+
context.report({
|
|
41
|
+
node: node.source,
|
|
42
|
+
messageId: 'no-css-modules'
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
function checkImports(node) {
|
|
47
|
+
var importSource = node.source.value;
|
|
48
|
+
if (!isRestrictedImportSource(importSource)) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
var _iterator = _createForOfIteratorHelper(restrictedImports[importSource]),
|
|
52
|
+
_step;
|
|
53
|
+
try {
|
|
54
|
+
var _loop = function _loop() {
|
|
55
|
+
var importName = _step.value;
|
|
56
|
+
var specifier = node.specifiers.filter(isImportSpecifier).find(function (specifier) {
|
|
57
|
+
return specifier.imported.name === importName;
|
|
58
|
+
});
|
|
59
|
+
if (specifier) {
|
|
60
|
+
context.report({
|
|
61
|
+
node: specifier,
|
|
62
|
+
messageId: 'no-global-styles'
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
67
|
+
_loop();
|
|
68
|
+
}
|
|
69
|
+
} catch (err) {
|
|
70
|
+
_iterator.e(err);
|
|
71
|
+
} finally {
|
|
72
|
+
_iterator.f();
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return {
|
|
76
|
+
ImportDeclaration: function (_ImportDeclaration) {
|
|
77
|
+
function ImportDeclaration(_x) {
|
|
78
|
+
return _ImportDeclaration.apply(this, arguments);
|
|
79
|
+
}
|
|
80
|
+
ImportDeclaration.toString = function () {
|
|
81
|
+
return _ImportDeclaration.toString();
|
|
82
|
+
};
|
|
83
|
+
return ImportDeclaration;
|
|
84
|
+
}(function (node) {
|
|
85
|
+
checkFileType(node);
|
|
86
|
+
checkImports(node);
|
|
87
|
+
}),
|
|
88
|
+
'JSXOpeningElement[name.name="style"]': function JSXOpeningElementNameNameStyle(node) {
|
|
89
|
+
context.report({
|
|
90
|
+
node: node,
|
|
91
|
+
messageId: 'no-global-styles'
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
var _default = exports.default = rule;
|
|
98
|
+
function isImportSpecifier(node) {
|
|
99
|
+
return node.type === 'ImportSpecifier';
|
|
100
|
+
}
|
|
@@ -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 {
|
|
@@ -15,9 +15,11 @@ export default {
|
|
|
15
15
|
'@atlaskit/ui-styling-standard/no-container-queries': 'warn',
|
|
16
16
|
'@atlaskit/ui-styling-standard/no-dynamic-styles': 'warn',
|
|
17
17
|
'@atlaskit/ui-styling-standard/no-exported-styles': 'warn',
|
|
18
|
+
'@atlaskit/ui-styling-standard/no-global-styles': 'warn',
|
|
18
19
|
'@atlaskit/ui-styling-standard/no-important-styles': 'warn',
|
|
19
20
|
'@atlaskit/ui-styling-standard/no-imported-style-values': 'warn',
|
|
20
21
|
'@atlaskit/ui-styling-standard/no-nested-selectors': 'warn',
|
|
22
|
+
'@atlaskit/ui-styling-standard/no-styled': 'warn',
|
|
21
23
|
'@atlaskit/ui-styling-standard/no-unsafe-values': 'warn',
|
|
22
24
|
'@atlaskit/ui-styling-standard/use-compiled': 'warn',
|
|
23
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 {
|
|
@@ -15,9 +15,11 @@ export default {
|
|
|
15
15
|
'@atlaskit/ui-styling-standard/no-container-queries': 'warn',
|
|
16
16
|
'@atlaskit/ui-styling-standard/no-dynamic-styles': 'warn',
|
|
17
17
|
'@atlaskit/ui-styling-standard/no-exported-styles': 'warn',
|
|
18
|
+
'@atlaskit/ui-styling-standard/no-global-styles': 'warn',
|
|
18
19
|
'@atlaskit/ui-styling-standard/no-important-styles': 'warn',
|
|
19
20
|
'@atlaskit/ui-styling-standard/no-imported-style-values': 'warn',
|
|
20
21
|
'@atlaskit/ui-styling-standard/no-nested-selectors': 'warn',
|
|
22
|
+
'@atlaskit/ui-styling-standard/no-styled': 'warn',
|
|
21
23
|
'@atlaskit/ui-styling-standard/no-unsafe-values': 'warn',
|
|
22
24
|
'@atlaskit/ui-styling-standard/use-compiled': 'warn',
|
|
23
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';
|
|
@@ -12,9 +12,11 @@ import noClassnameProp from './no-classname-prop';
|
|
|
12
12
|
import noContainerQueries from './no-container-queries';
|
|
13
13
|
import noDynamicStyles from './no-dynamic-styles';
|
|
14
14
|
import noExportedStyles from './no-exported-styles';
|
|
15
|
+
import noGlobalStyles from './no-global-styles';
|
|
15
16
|
import noImportantStyles from './no-important-styles';
|
|
16
17
|
import noImportedStyleValues from './no-imported-style-values';
|
|
17
18
|
import noNestedSelectors from './no-nested-selectors';
|
|
19
|
+
import noStyled from './no-styled';
|
|
18
20
|
import noUnsafeValues from './no-unsafe-values';
|
|
19
21
|
import useCompiled from './use-compiled';
|
|
20
22
|
export default {
|
|
@@ -27,9 +29,11 @@ export default {
|
|
|
27
29
|
'no-container-queries': noContainerQueries,
|
|
28
30
|
'no-dynamic-styles': noDynamicStyles,
|
|
29
31
|
'no-exported-styles': noExportedStyles,
|
|
32
|
+
'no-global-styles': noGlobalStyles,
|
|
30
33
|
'no-important-styles': noImportantStyles,
|
|
31
34
|
'no-imported-style-values': noImportedStyleValues,
|
|
32
35
|
'no-nested-selectors': noNestedSelectors,
|
|
36
|
+
'no-styled': noStyled,
|
|
33
37
|
'no-unsafe-values': noUnsafeValues,
|
|
34
38
|
'use-compiled': useCompiled
|
|
35
39
|
};
|