@atlaskit/eslint-plugin-ui-styling-standard 0.9.1 → 0.11.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 +16 -0
- package/README.md +2 -0
- package/constellation/index/overview.mdx +2 -0
- package/constellation/no-dynamic-styles/usage.mdx +128 -0
- package/constellation/no-unsafe-values/usage.mdx +222 -0
- 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 +6 -2
- package/dist/cjs/rules/no-dynamic-styles/index.js +69 -0
- package/dist/cjs/rules/no-unsafe-values/index.js +85 -0
- package/dist/cjs/rules/no-unsafe-values/messages.js +24 -0
- package/dist/cjs/rules/no-unsafe-values/utils.js +437 -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 +6 -2
- package/dist/es2019/rules/no-dynamic-styles/index.js +51 -0
- package/dist/es2019/rules/no-unsafe-values/index.js +80 -0
- package/dist/es2019/rules/no-unsafe-values/messages.js +72 -0
- package/dist/es2019/rules/no-unsafe-values/utils.js +350 -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 +6 -2
- package/dist/esm/rules/no-dynamic-styles/index.js +62 -0
- package/dist/esm/rules/no-unsafe-values/index.js +79 -0
- package/dist/esm/rules/no-unsafe-values/messages.js +17 -0
- package/dist/esm/rules/no-unsafe-values/utils.js +430 -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-dynamic-styles/index.d.ts +2 -0
- package/dist/types/rules/no-unsafe-values/index.d.ts +2 -0
- package/dist/types/rules/no-unsafe-values/messages.d.ts +13 -0
- package/dist/types/rules/no-unsafe-values/utils.d.ts +28 -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-dynamic-styles/index.d.ts +2 -0
- package/dist/types-ts4.5/rules/no-unsafe-values/index.d.ts +2 -0
- package/dist/types-ts4.5/rules/no-unsafe-values/messages.d.ts +13 -0
- package/dist/types-ts4.5/rules/no-unsafe-values/utils.d.ts +28 -0
- package/package.json +5 -4
- 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-dynamic-styles/README.md +126 -0
- package/src/rules/no-dynamic-styles/__tests__/rule.test.tsx +128 -0
- package/src/rules/no-dynamic-styles/index.tsx +63 -0
- package/src/rules/no-unsafe-values/README.md +220 -0
- package/src/rules/no-unsafe-values/__tests__/no-array-values.test.tsx +27 -0
- package/src/rules/no-unsafe-values/__tests__/no-conditional-values.test.tsx +37 -0
- package/src/rules/no-unsafe-values/__tests__/no-dynamic-keys.test.tsx +229 -0
- package/src/rules/no-unsafe-values/__tests__/no-function-calls.test.tsx +267 -0
- package/src/rules/no-unsafe-values/__tests__/no-identifier-arguments.test.tsx +52 -0
- package/src/rules/no-unsafe-values/__tests__/no-object-access.test.tsx +106 -0
- package/src/rules/no-unsafe-values/__tests__/no-object-references.test.tsx +44 -0
- package/src/rules/no-unsafe-values/__tests__/no-spread-elements.test.tsx +48 -0
- package/src/rules/no-unsafe-values/__tests__/no-unsafe-values.test.tsx +75 -0
- package/src/rules/no-unsafe-values/__tests__/no-variables.test.tsx +121 -0
- package/src/rules/no-unsafe-values/index.tsx +96 -0
- package/src/rules/no-unsafe-values/messages.tsx +86 -0
- package/src/rules/no-unsafe-values/utils.tsx +399 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @atlaskit/eslint-plugin-ui-styling-standard
|
|
2
2
|
|
|
3
|
+
## 0.11.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#87213](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/87213) [`fbfa5a58cf39`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/fbfa5a58cf39) - Adds `no-unsafe-values` rule, which forbids most dynamic styling in `css`/`styled`/`keyframes`/`cssMap`/`xcss` function calls. This includes object spreading, function calls, and so on.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies
|
|
12
|
+
|
|
13
|
+
## 0.10.0
|
|
14
|
+
|
|
15
|
+
### Minor Changes
|
|
16
|
+
|
|
17
|
+
- [#91611](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/91611) [`943056d22c36`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/943056d22c36) - Add `no-dynamic-styles` rule which blocks function expressions as values in style declarations.
|
|
18
|
+
|
|
3
19
|
## 0.9.1
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -19,8 +19,10 @@ Not intended for use outside the Atlassian frontend repository.
|
|
|
19
19
|
| <a href="./src/rules/no-array-arguments/README.md">no-array-arguments</a> | Prevents usage of array arguments to style declaration functions | Yes | Yes | |
|
|
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
|
+
| <a href="./src/rules/no-dynamic-styles/README.md">no-dynamic-styles</a> | Disallows use of dynamic styles in CSS-in-JS calls | Yes | | |
|
|
22
23
|
| <a href="./src/rules/no-important-styles/README.md">no-important-styles</a> | Disallows important style declarations | Yes | | |
|
|
23
24
|
| <a href="./src/rules/no-nested-selectors/README.md">no-nested-selectors</a> | Prevents usage of nested selectors within css styling | Yes | | |
|
|
25
|
+
| <a href="./src/rules/no-unsafe-values/README.md">no-unsafe-values</a> | Disallows styles that are difficult/impossible to statically anaylze. | Yes | | |
|
|
24
26
|
| <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 | |
|
|
25
27
|
| <a href="https://atlassian.design/components/eslint-plugin-ui-styling-standard/no-css-tagged-template-expression/usage">@atlaskit/design-system/no-css-tagged-template-expression</a> | Disallows any `css` tagged template expressions that originate from Emotion, Styled Components or Compiled | Yes | Yes | |
|
|
26
28
|
| <a href="https://atlassian.design/components/eslint-plugin-ui-styling-standard/no-keyframes-tagged-template-expression/usage">@atlaskit/design-system/no-keyframes-tagged-template-expression</a> | Disallows any `keyframe` tagged template expressions that originate from Emotion, Styled Components or Compiled | Yes | Yes | |
|
|
@@ -17,8 +17,10 @@ but more are planned to support the standard over time.
|
|
|
17
17
|
| <a href="no-array-arguments/usage">no-array-arguments</a> | Prevents usage of array arguments to style declaration functions | Yes | Yes | |
|
|
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
|
+
| <a href="no-dynamic-styles/usage">no-dynamic-styles</a> | Disallows use of dynamic styles in CSS-in-JS calls | Yes | | |
|
|
20
21
|
| <a href="no-important-styles/usage">no-important-styles</a> | Disallows important style declarations | Yes | | |
|
|
21
22
|
| <a href="no-nested-selectors/usage">no-nested-selectors</a> | Prevents usage of nested selectors within css styling | Yes | | |
|
|
23
|
+
| <a href="no-unsafe-values/usage">no-unsafe-values</a> | Disallows styles that are difficult/impossible to statically anaylze. | Yes | | |
|
|
22
24
|
| <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 | |
|
|
23
25
|
| <a href="no-css-tagged-template-expression/usage">@atlaskit/design-system/no-css-tagged-template-expression</a> | Disallows any `css` tagged template expressions that originate from Emotion, Styled Components or Compiled | Yes | Yes | |
|
|
24
26
|
| <a href="no-keyframes-tagged-template-expression/usage">@atlaskit/design-system/no-keyframes-tagged-template-expression</a> | Disallows any `keyframe` tagged template expressions that originate from Emotion, Styled Components or Compiled | Yes | Yes | |
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
# no-dynamic-styles
|
|
2
|
+
|
|
3
|
+
This rule prevents the use of dynamic styles (function expressions) in style declarations.
|
|
4
|
+
|
|
5
|
+
This ensures that style declarations:
|
|
6
|
+
|
|
7
|
+
- are statically analyzable
|
|
8
|
+
- can be efficiently extracted into atomic CSS
|
|
9
|
+
- are more readable, deterministic, and thus easier to maintain
|
|
10
|
+
|
|
11
|
+
## Examples
|
|
12
|
+
|
|
13
|
+
### Incorrect
|
|
14
|
+
|
|
15
|
+
```tsx
|
|
16
|
+
import { styled } from '@compiled/react';
|
|
17
|
+
|
|
18
|
+
const Component = styled.div<{ width: number }>((props) => ({
|
|
19
|
+
width: props.width,
|
|
20
|
+
}));
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
```tsx
|
|
24
|
+
import styled from 'styled-components';
|
|
25
|
+
|
|
26
|
+
const Component = styled.div<{ width: number }>({
|
|
27
|
+
width: (props) => props.width,
|
|
28
|
+
});
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
```tsx
|
|
32
|
+
import styled from 'styled-components';
|
|
33
|
+
|
|
34
|
+
const Container = styled.div<hasPadding>({
|
|
35
|
+
padding: ({ hasPadding }) =>
|
|
36
|
+
hasPadding ? token('space.100', '8px') : token('space.0', '0px'),
|
|
37
|
+
});
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### Correct
|
|
41
|
+
|
|
42
|
+
**Flags**
|
|
43
|
+
|
|
44
|
+
If you have a style that is on/off depending on a prop,
|
|
45
|
+
use the `css` prop to conditionally apply it.
|
|
46
|
+
|
|
47
|
+
```tsx
|
|
48
|
+
import { css } from '@compiled/react';
|
|
49
|
+
|
|
50
|
+
const baseStyles = css({ padding: token('space.0') });
|
|
51
|
+
const hasPaddingStyles = css({ padding: token('space.100') });
|
|
52
|
+
|
|
53
|
+
const Container = ({ hasPadding = false }: { hasPadding?: boolean }) => {
|
|
54
|
+
return <div css={[baseStyles, hasPadding && hasPaddingStyles]} />;
|
|
55
|
+
};
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
**Variants**
|
|
59
|
+
|
|
60
|
+
If you have variants which are known ahead of time,
|
|
61
|
+
use `cssMap` to define them and the `css` prop to conditionally apply it.
|
|
62
|
+
|
|
63
|
+
```tsx
|
|
64
|
+
import { css } from '@compiled/react';
|
|
65
|
+
|
|
66
|
+
const baseStyles = css({ width: 100 });
|
|
67
|
+
const stylesMap = cssMap({
|
|
68
|
+
primary: {
|
|
69
|
+
background: token('color.background.brand.bold'),
|
|
70
|
+
'&:hover': { background: token('color.background.brand.bold.hovered') },
|
|
71
|
+
},
|
|
72
|
+
error: {
|
|
73
|
+
background: token('color.background.warning.bold'),
|
|
74
|
+
'&:hover': { background: token('color.background.warning.bold.hovered') },
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
const Wrapper = ({ appearance = 'primary' }: { appearance?: 'primary' | 'error' }) => (
|
|
79
|
+
<div css={[baseStyles, stylesMap[appearance]} />
|
|
80
|
+
);
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
**Dynamic values**
|
|
84
|
+
|
|
85
|
+
If you have styles which are truly dynamic,
|
|
86
|
+
use the `style` prop.
|
|
87
|
+
|
|
88
|
+
This approach should be used as a last resort.
|
|
89
|
+
|
|
90
|
+
```tsx
|
|
91
|
+
import { css } from '@compiled/react';
|
|
92
|
+
|
|
93
|
+
const Component = ({ width }: { width: number }) => {
|
|
94
|
+
return <div style={{ width }} />;
|
|
95
|
+
};
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
```tsx
|
|
99
|
+
import { css } from '@compiled/react';
|
|
100
|
+
|
|
101
|
+
const containerStyles = css({
|
|
102
|
+
'::before': {
|
|
103
|
+
width: 'var(--ak-example-width)',
|
|
104
|
+
},
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
function Example({ width }: { width: number }) {
|
|
108
|
+
return (
|
|
109
|
+
<div css={containerStyles} style={{ '--ak-example-width': `${width}px` }} />
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## Options
|
|
115
|
+
|
|
116
|
+
### importSources
|
|
117
|
+
|
|
118
|
+
By default, this rule will check usages from:
|
|
119
|
+
|
|
120
|
+
- `@atlaskit/css`
|
|
121
|
+
- `@atlaskit/primitives`
|
|
122
|
+
- `@compiled/react`
|
|
123
|
+
- `@emotion/react`
|
|
124
|
+
- `@emotion/core`
|
|
125
|
+
- `@emotion/styled`
|
|
126
|
+
- `styled-components`
|
|
127
|
+
|
|
128
|
+
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,222 @@
|
|
|
1
|
+
# no-unsafe-values
|
|
2
|
+
|
|
3
|
+
This rule prevents the usage of styles that are difficult/impossible to statically anaylze.
|
|
4
|
+
|
|
5
|
+
## Examples
|
|
6
|
+
|
|
7
|
+
### Incorrect
|
|
8
|
+
|
|
9
|
+
**Function calls**
|
|
10
|
+
|
|
11
|
+
Function calls are not allowed as arguments or as values,
|
|
12
|
+
unless they are specified in `allowedFunctionCalls` (or in the default list).
|
|
13
|
+
|
|
14
|
+
```tsx
|
|
15
|
+
import { css } from '@compiled/react';
|
|
16
|
+
|
|
17
|
+
function getStyles() {
|
|
18
|
+
return { width: 100 };
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const styles = css(getStyles());
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
```tsx
|
|
25
|
+
import { css } from '@compiled/react';
|
|
26
|
+
|
|
27
|
+
function getWidth() {
|
|
28
|
+
return 100;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const styles = css({
|
|
32
|
+
width: getWidth(),
|
|
33
|
+
});
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
**Dynamic keys**
|
|
37
|
+
|
|
38
|
+
Dynamic keys are not allowed,
|
|
39
|
+
unless they are specified in `allowedDynamicKeys` (or in the default list).
|
|
40
|
+
|
|
41
|
+
```tsx
|
|
42
|
+
import { css } from '@compiled/react';
|
|
43
|
+
import { SELECTOR } from 'my-package';
|
|
44
|
+
|
|
45
|
+
const styles = css({
|
|
46
|
+
[SELECTOR]: {
|
|
47
|
+
color: 'red',
|
|
48
|
+
},
|
|
49
|
+
[`${SELECTOR} > p`]: {
|
|
50
|
+
width: 100,
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
**Variables**
|
|
56
|
+
|
|
57
|
+
Variables are not allowed as values, unless they:
|
|
58
|
+
|
|
59
|
+
- Have a simple, static value
|
|
60
|
+
- Are defined in the same file
|
|
61
|
+
|
|
62
|
+
```tsx
|
|
63
|
+
import { css } from '@compiled/react';
|
|
64
|
+
import { SELECTOR } from 'my-package';
|
|
65
|
+
|
|
66
|
+
function myFunction() {
|
|
67
|
+
return '5px';
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const styles = css({
|
|
71
|
+
height: myFunction,
|
|
72
|
+
});
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
**Object access**
|
|
76
|
+
|
|
77
|
+
Accessing object members is not allowed in values.
|
|
78
|
+
|
|
79
|
+
```tsx
|
|
80
|
+
import { css } from '@compiled/react';
|
|
81
|
+
import { token } from '@atlaskit/tokens';
|
|
82
|
+
|
|
83
|
+
const colors = {
|
|
84
|
+
text: token('color.text'),
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
const styles = css({
|
|
88
|
+
color: colors.text,
|
|
89
|
+
});
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
**Spread elements**
|
|
93
|
+
|
|
94
|
+
Spread elements are not allowed.
|
|
95
|
+
|
|
96
|
+
```tsx
|
|
97
|
+
import { css } from '@compiled/react';
|
|
98
|
+
|
|
99
|
+
const buttonStyles = {
|
|
100
|
+
color: 'blue',
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
const styles = css({
|
|
104
|
+
...buttonStyles,
|
|
105
|
+
});
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
**Array values**
|
|
109
|
+
|
|
110
|
+
Array values are not allowed.
|
|
111
|
+
This syntax is not supported by most styling libraries.
|
|
112
|
+
|
|
113
|
+
```tsx
|
|
114
|
+
import { css } from '@compiled/react';
|
|
115
|
+
|
|
116
|
+
const styles = css({
|
|
117
|
+
'::before': [{ fontWeight: 'bold' }, { color: 'red' }],
|
|
118
|
+
});
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### Correct
|
|
122
|
+
|
|
123
|
+
Things to note about the following example:
|
|
124
|
+
|
|
125
|
+
- The `warningStyles` are conditionally applied using the `css` prop
|
|
126
|
+
- The dynamic `width` is applied using the `style` prop
|
|
127
|
+
- The `token()` calls are allowed because they are statically analyzable (and in the default allow-list)
|
|
128
|
+
|
|
129
|
+
```tsx
|
|
130
|
+
import { css } from '@compiled/react';
|
|
131
|
+
import { token } from '@atlaskit/tokens';
|
|
132
|
+
|
|
133
|
+
const baseStyles = css({
|
|
134
|
+
height: 100,
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
const warningStyles = css({
|
|
138
|
+
color: token('color.text.warning'),
|
|
139
|
+
backgroundColor: token('color.background.warning'),
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
const Component = ({
|
|
143
|
+
isWarning,
|
|
144
|
+
width,
|
|
145
|
+
}: {
|
|
146
|
+
isWarning: boolean;
|
|
147
|
+
width: number;
|
|
148
|
+
}) => {
|
|
149
|
+
return (
|
|
150
|
+
<div style={{ width }} css={[baseStyles, isWarning && warningStyles]} />
|
|
151
|
+
);
|
|
152
|
+
};
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
## Options
|
|
156
|
+
|
|
157
|
+
### `allowedDynamicKeys: [string, string][]`
|
|
158
|
+
|
|
159
|
+
Use this to allow specified imports as dynamic keys, in addition to the built-in allow-list.
|
|
160
|
+
|
|
161
|
+
Each value should be a two-element array. The first item is the entrypoint, and the second item is a named export.
|
|
162
|
+
|
|
163
|
+
Default imports are not supported.
|
|
164
|
+
|
|
165
|
+
```tsx
|
|
166
|
+
// .eslintrc.js
|
|
167
|
+
|
|
168
|
+
// ...
|
|
169
|
+
rules: {
|
|
170
|
+
'@atlaskit/eslint-plugin-ui-styling-standard/no-unsafe-values': [
|
|
171
|
+
'error',
|
|
172
|
+
{
|
|
173
|
+
allowedDynamicKeys: [
|
|
174
|
+
['@atlaskit/primitives/responsive', 'media'],
|
|
175
|
+
]
|
|
176
|
+
},
|
|
177
|
+
],
|
|
178
|
+
// ...
|
|
179
|
+
},
|
|
180
|
+
// ...
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
### `allowedFunctionCalls: [string, string][]`
|
|
184
|
+
|
|
185
|
+
Use this to allow specific functions to be called, in addition to the built-in allow-list.
|
|
186
|
+
|
|
187
|
+
Each value should be a two-element array. The first item is the entrypoint, and the second item is a named export.
|
|
188
|
+
|
|
189
|
+
Default imports are not currently supported.
|
|
190
|
+
|
|
191
|
+
```tsx
|
|
192
|
+
// .eslintrc.js
|
|
193
|
+
|
|
194
|
+
// ...
|
|
195
|
+
rules: {
|
|
196
|
+
'@atlaskit/eslint-plugin-ui-styling-standard/no-unsafe-values': [
|
|
197
|
+
'error',
|
|
198
|
+
{
|
|
199
|
+
allowedFunctionCalls: [
|
|
200
|
+
['@atlaskit/tokens', 'token'],
|
|
201
|
+
]
|
|
202
|
+
},
|
|
203
|
+
],
|
|
204
|
+
// ...
|
|
205
|
+
},
|
|
206
|
+
// ...
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
### `importSources : string[]`
|
|
210
|
+
|
|
211
|
+
By default, this rule will check `css` usages from:
|
|
212
|
+
|
|
213
|
+
- `@atlaskit/css`
|
|
214
|
+
- `@atlaskit/primitives`
|
|
215
|
+
- `@compiled/react`
|
|
216
|
+
- `@emotion/react`
|
|
217
|
+
- `@emotion/core`
|
|
218
|
+
- `@emotion/styled`
|
|
219
|
+
- `styled-components`
|
|
220
|
+
|
|
221
|
+
To change this list of libraries, you can define a custom set of `importSources`, which accepts an array of package names (strings).
|
|
222
|
+
This will override the built-in allow-list.
|
|
@@ -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::544c8b1c0eb0d6329064dcf92e18e45e>>
|
|
10
10
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
11
11
|
*/
|
|
12
12
|
var _default = exports.default = {
|
|
@@ -18,8 +18,10 @@ var _default = exports.default = {
|
|
|
18
18
|
'@atlaskit/ui-styling-standard/no-array-arguments': 'warn',
|
|
19
19
|
'@atlaskit/ui-styling-standard/no-classname-prop': 'warn',
|
|
20
20
|
'@atlaskit/ui-styling-standard/no-container-queries': 'warn',
|
|
21
|
+
'@atlaskit/ui-styling-standard/no-dynamic-styles': 'warn',
|
|
21
22
|
'@atlaskit/ui-styling-standard/no-important-styles': 'warn',
|
|
22
23
|
'@atlaskit/ui-styling-standard/no-nested-selectors': 'warn',
|
|
24
|
+
'@atlaskit/ui-styling-standard/no-unsafe-values': 'warn',
|
|
23
25
|
'@atlaskit/design-system/consistent-css-prop-usage': ['warn', {
|
|
24
26
|
excludeReactComponents: true
|
|
25
27
|
}],
|
|
@@ -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::544c8b1c0eb0d6329064dcf92e18e45e>>
|
|
10
10
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
11
11
|
*/
|
|
12
12
|
var _default = exports.default = {
|
|
@@ -18,8 +18,10 @@ var _default = exports.default = {
|
|
|
18
18
|
'@atlaskit/ui-styling-standard/no-array-arguments': 'warn',
|
|
19
19
|
'@atlaskit/ui-styling-standard/no-classname-prop': 'warn',
|
|
20
20
|
'@atlaskit/ui-styling-standard/no-container-queries': 'warn',
|
|
21
|
+
'@atlaskit/ui-styling-standard/no-dynamic-styles': 'warn',
|
|
21
22
|
'@atlaskit/ui-styling-standard/no-important-styles': 'warn',
|
|
22
23
|
'@atlaskit/ui-styling-standard/no-nested-selectors': 'warn',
|
|
24
|
+
'@atlaskit/ui-styling-standard/no-unsafe-values': 'warn',
|
|
23
25
|
'@atlaskit/design-system/consistent-css-prop-usage': ['warn', {
|
|
24
26
|
excludeReactComponents: true
|
|
25
27
|
}],
|
|
@@ -11,11 +11,13 @@ var _localCxXcss = _interopRequireDefault(require("./local-cx-xcss"));
|
|
|
11
11
|
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
|
+
var _noDynamicStyles = _interopRequireDefault(require("./no-dynamic-styles"));
|
|
14
15
|
var _noImportantStyles = _interopRequireDefault(require("./no-important-styles"));
|
|
15
16
|
var _noNestedSelectors = _interopRequireDefault(require("./no-nested-selectors"));
|
|
17
|
+
var _noUnsafeValues = _interopRequireDefault(require("./no-unsafe-values"));
|
|
16
18
|
/**
|
|
17
19
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
18
|
-
* @codegen <<SignedSource::
|
|
20
|
+
* @codegen <<SignedSource::edaedcad824fed1e108f90d909287584>>
|
|
19
21
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
20
22
|
*/
|
|
21
23
|
var _default = exports.default = {
|
|
@@ -25,6 +27,8 @@ var _default = exports.default = {
|
|
|
25
27
|
'no-array-arguments': _noArrayArguments.default,
|
|
26
28
|
'no-classname-prop': _noClassnameProp.default,
|
|
27
29
|
'no-container-queries': _noContainerQueries.default,
|
|
30
|
+
'no-dynamic-styles': _noDynamicStyles.default,
|
|
28
31
|
'no-important-styles': _noImportantStyles.default,
|
|
29
|
-
'no-nested-selectors': _noNestedSelectors.default
|
|
32
|
+
'no-nested-selectors': _noNestedSelectors.default,
|
|
33
|
+
'no-unsafe-values': _noUnsafeValues.default
|
|
30
34
|
};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.rule = exports.default = void 0;
|
|
8
|
+
var _esquery = _interopRequireDefault(require("esquery"));
|
|
9
|
+
var _isSupportedImport = require("@atlaskit/eslint-utils/is-supported-import");
|
|
10
|
+
var _createRule = require("../utils/create-rule");
|
|
11
|
+
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; } } }; }
|
|
12
|
+
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); }
|
|
13
|
+
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; }
|
|
14
|
+
var schema = [{
|
|
15
|
+
type: 'object',
|
|
16
|
+
properties: {
|
|
17
|
+
importSources: {
|
|
18
|
+
type: 'array',
|
|
19
|
+
items: {
|
|
20
|
+
type: 'string'
|
|
21
|
+
},
|
|
22
|
+
uniqueItems: true
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}];
|
|
26
|
+
var rule = exports.rule = (0, _createRule.createLintRule)({
|
|
27
|
+
meta: {
|
|
28
|
+
name: 'no-dynamic-styles',
|
|
29
|
+
docs: {
|
|
30
|
+
description: 'Disallows use of dynamic styles in CSS-in-JS calls',
|
|
31
|
+
recommended: true,
|
|
32
|
+
severity: 'warn'
|
|
33
|
+
},
|
|
34
|
+
schema: schema,
|
|
35
|
+
messages: {
|
|
36
|
+
'no-dynamic-styles': 'Dynamic styles are not allowed. Instead use the style prop to apply styles derived from component props.'
|
|
37
|
+
},
|
|
38
|
+
type: 'problem'
|
|
39
|
+
},
|
|
40
|
+
create: function create(context) {
|
|
41
|
+
var importSources = (0, _isSupportedImport.getImportSources)(context);
|
|
42
|
+
return {
|
|
43
|
+
CallExpression: function CallExpression(node) {
|
|
44
|
+
var _context$sourceCode$g = context.sourceCode.getScope(node),
|
|
45
|
+
references = _context$sourceCode$g.references;
|
|
46
|
+
if (!(0, _isSupportedImport.hasStyleObjectArguments)(node.callee, references, importSources)) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
var matches = (0, _esquery.default)(node, 'ArrowFunctionExpression, FunctionExpression');
|
|
50
|
+
var _iterator = _createForOfIteratorHelper(matches),
|
|
51
|
+
_step;
|
|
52
|
+
try {
|
|
53
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
54
|
+
var match = _step.value;
|
|
55
|
+
context.report({
|
|
56
|
+
node: match,
|
|
57
|
+
messageId: 'no-dynamic-styles'
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
} catch (err) {
|
|
61
|
+
_iterator.e(err);
|
|
62
|
+
} finally {
|
|
63
|
+
_iterator.f();
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
var _default = exports.default = rule;
|
|
@@ -0,0 +1,85 @@
|
|
|
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 _utils = require("./utils");
|
|
10
|
+
var _messages = require("./messages");
|
|
11
|
+
var schema = [{
|
|
12
|
+
type: 'object',
|
|
13
|
+
additionalProperties: false,
|
|
14
|
+
properties: {
|
|
15
|
+
importSources: {
|
|
16
|
+
type: 'array',
|
|
17
|
+
items: {
|
|
18
|
+
type: 'string'
|
|
19
|
+
},
|
|
20
|
+
uniqueItems: true
|
|
21
|
+
},
|
|
22
|
+
allowedFunctionCalls: {
|
|
23
|
+
type: 'array',
|
|
24
|
+
items: {
|
|
25
|
+
type: 'array',
|
|
26
|
+
minItems: 2,
|
|
27
|
+
maxItems: 2,
|
|
28
|
+
items: [{
|
|
29
|
+
type: 'string'
|
|
30
|
+
}, {
|
|
31
|
+
type: 'string'
|
|
32
|
+
}]
|
|
33
|
+
},
|
|
34
|
+
uniqueItems: true
|
|
35
|
+
},
|
|
36
|
+
allowedDynamicKeys: {
|
|
37
|
+
type: 'array',
|
|
38
|
+
items: {
|
|
39
|
+
type: 'array',
|
|
40
|
+
minItems: 2,
|
|
41
|
+
maxItems: 2,
|
|
42
|
+
items: [{
|
|
43
|
+
type: 'string'
|
|
44
|
+
}, {
|
|
45
|
+
type: 'string'
|
|
46
|
+
}]
|
|
47
|
+
},
|
|
48
|
+
uniqueItems: true
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}];
|
|
52
|
+
var rule = exports.rule = (0, _createRule.createLintRule)({
|
|
53
|
+
meta: {
|
|
54
|
+
name: 'no-unsafe-values',
|
|
55
|
+
docs: {
|
|
56
|
+
description: 'Disallows styles that are difficult/impossible to statically anaylze.',
|
|
57
|
+
recommended: true,
|
|
58
|
+
severity: 'warn'
|
|
59
|
+
},
|
|
60
|
+
messages: _messages.messages,
|
|
61
|
+
type: 'problem',
|
|
62
|
+
schema: schema
|
|
63
|
+
},
|
|
64
|
+
create: function create(context) {
|
|
65
|
+
var importSources = (0, _isSupportedImport.getImportSources)(context);
|
|
66
|
+
return {
|
|
67
|
+
CallExpression: function CallExpression(node) {
|
|
68
|
+
var _context$sourceCode$g = context.sourceCode.getScope(node),
|
|
69
|
+
references = _context$sourceCode$g.references;
|
|
70
|
+
if (!(0, _isSupportedImport.isCss)(node.callee, references, importSources) && !(0, _isSupportedImport.isStyled)(node.callee, references, importSources) && !(0, _isSupportedImport.isKeyframes)(node.callee, references, importSources) && !(0, _isSupportedImport.isCssMap)(node.callee, references, importSources) && !(0, _isSupportedImport.isXcss)(node.callee, references, importSources)) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
if ((0, _isSupportedImport.isStyled)(node.callee, references, importSources) && (node.parent.type === 'CallExpression' || node.parent.type === 'TaggedTemplateExpression')) {
|
|
74
|
+
/**
|
|
75
|
+
* If it is of the form styled(Base)({}) we don't want to lint the inner function arguments.
|
|
76
|
+
*/
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
var linter = new _utils.Linter(context, node);
|
|
80
|
+
linter.run();
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
var _default = exports.default = rule;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.messages = void 0;
|
|
8
|
+
var _taggedTemplateLiteral2 = _interopRequireDefault(require("@babel/runtime/helpers/taggedTemplateLiteral"));
|
|
9
|
+
var _outdent = _interopRequireDefault(require("outdent"));
|
|
10
|
+
var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7, _templateObject8, _templateObject9, _templateObject10;
|
|
11
|
+
var whereToGetHelp = "If you think this should be allowed, or if you're running into issues, reach out in #help-ui-styling-standard";
|
|
12
|
+
var messages = exports.messages = {
|
|
13
|
+
'no-array-values': (0, _outdent.default)(_templateObject || (_templateObject = (0, _taggedTemplateLiteral2.default)(["\n Arrays are not allowed in style objects. Support is inconsistent between styling libraries.\n\n Compose styles with the css prop instead.\n\n ", "\n "])), whereToGetHelp),
|
|
14
|
+
'no-conditional-values': (0, _outdent.default)(_templateObject2 || (_templateObject2 = (0, _taggedTemplateLiteral2.default)(["\n Conditional expressions are not allowed in style objects.\n\n Conditionally apply styles with the css prop instead.\n\n ", "\n "])), whereToGetHelp),
|
|
15
|
+
'no-dynamic-keys': (0, _outdent.default)(_templateObject3 || (_templateObject3 = (0, _taggedTemplateLiteral2.default)(["\n Dynamic keys are not allowed in style objects.\n\n ", "\n "])), whereToGetHelp),
|
|
16
|
+
'no-function-calls': (0, _outdent.default)(_templateObject4 || (_templateObject4 = (0, _taggedTemplateLiteral2.default)(["\n Function calls are not allowed in style objects.\n\n ", "\n "])), whereToGetHelp),
|
|
17
|
+
'no-identifier-arguments': (0, _outdent.default)(_templateObject5 || (_templateObject5 = (0, _taggedTemplateLiteral2.default)(["\n Variable arguments are not allowed.\n\n Inline the object value, or compose styles with the css prop instead.\n\n ", "\n "])), whereToGetHelp),
|
|
18
|
+
'no-object-access': (0, _outdent.default)(_templateObject6 || (_templateObject6 = (0, _taggedTemplateLiteral2.default)(["\n Accessing object values is not allowed in style objects.\n\n If you are accessing the component's props, use the style prop to apply dynamic values instead.\n\n ", "\n "])), whereToGetHelp),
|
|
19
|
+
'no-object-references': (0, _outdent.default)(_templateObject7 || (_templateObject7 = (0, _taggedTemplateLiteral2.default)(["\n Referencing objects is not allowed in style objects.\n\n Inline the object value instead.\n\n ", "\n "])), whereToGetHelp),
|
|
20
|
+
'no-spread-elements': (0, _outdent.default)(_templateObject8 || (_templateObject8 = (0, _taggedTemplateLiteral2.default)(["\n Spread elements are not allowed in style objects.\n\n Compose styles with the css prop instead.\n\n ", "\n "])), whereToGetHelp),
|
|
21
|
+
// Fallback case if a more specific message is not applicable
|
|
22
|
+
'no-unsafe-values': (0, _outdent.default)(_templateObject9 || (_templateObject9 = (0, _taggedTemplateLiteral2.default)(["\n Unsafe values are not allowed in style objects.\n\n ", "\n "])), whereToGetHelp),
|
|
23
|
+
'no-variables': (0, _outdent.default)(_templateObject10 || (_templateObject10 = (0, _taggedTemplateLiteral2.default)(["\n Variables are not allowed in style objects, unless they:\n\n - Have a simple, static value.\n - Are defined in the same file.\n\n Use the style prop to apply dynamic values instead.\n\n ", "\n "])), whereToGetHelp)
|
|
24
|
+
};
|