@atlaskit/eslint-plugin-ui-styling-standard 0.10.0 → 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 +10 -0
- package/README.md +1 -0
- package/constellation/index/overview.mdx +1 -0
- package/constellation/no-unsafe-values/usage.mdx +222 -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 +4 -2
- 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 +2 -1
- package/dist/es2019/presets/recommended.codegen.js +2 -1
- package/dist/es2019/rules/index.codegen.js +4 -2
- 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 +2 -1
- package/dist/esm/presets/recommended.codegen.js +2 -1
- package/dist/esm/rules/index.codegen.js +4 -2
- 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 +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-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 +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-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 +4 -4
- 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-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,15 @@
|
|
|
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
|
+
|
|
3
13
|
## 0.10.0
|
|
4
14
|
|
|
5
15
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -22,6 +22,7 @@ Not intended for use outside the Atlassian frontend repository.
|
|
|
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
23
|
| <a href="./src/rules/no-important-styles/README.md">no-important-styles</a> | Disallows important style declarations | Yes | | |
|
|
24
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 | | |
|
|
25
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 | |
|
|
26
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 | |
|
|
27
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 | |
|
|
@@ -20,6 +20,7 @@ but more are planned to support the standard over time.
|
|
|
20
20
|
| <a href="no-dynamic-styles/usage">no-dynamic-styles</a> | Disallows use of dynamic styles in CSS-in-JS calls | Yes | | |
|
|
21
21
|
| <a href="no-important-styles/usage">no-important-styles</a> | Disallows important style declarations | Yes | | |
|
|
22
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 | | |
|
|
23
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 | |
|
|
24
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 | |
|
|
25
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,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 = {
|
|
@@ -21,6 +21,7 @@ var _default = exports.default = {
|
|
|
21
21
|
'@atlaskit/ui-styling-standard/no-dynamic-styles': 'warn',
|
|
22
22
|
'@atlaskit/ui-styling-standard/no-important-styles': 'warn',
|
|
23
23
|
'@atlaskit/ui-styling-standard/no-nested-selectors': 'warn',
|
|
24
|
+
'@atlaskit/ui-styling-standard/no-unsafe-values': 'warn',
|
|
24
25
|
'@atlaskit/design-system/consistent-css-prop-usage': ['warn', {
|
|
25
26
|
excludeReactComponents: true
|
|
26
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 = {
|
|
@@ -21,6 +21,7 @@ var _default = exports.default = {
|
|
|
21
21
|
'@atlaskit/ui-styling-standard/no-dynamic-styles': 'warn',
|
|
22
22
|
'@atlaskit/ui-styling-standard/no-important-styles': 'warn',
|
|
23
23
|
'@atlaskit/ui-styling-standard/no-nested-selectors': 'warn',
|
|
24
|
+
'@atlaskit/ui-styling-standard/no-unsafe-values': 'warn',
|
|
24
25
|
'@atlaskit/design-system/consistent-css-prop-usage': ['warn', {
|
|
25
26
|
excludeReactComponents: true
|
|
26
27
|
}],
|
|
@@ -14,9 +14,10 @@ var _noContainerQueries = _interopRequireDefault(require("./no-container-queries
|
|
|
14
14
|
var _noDynamicStyles = _interopRequireDefault(require("./no-dynamic-styles"));
|
|
15
15
|
var _noImportantStyles = _interopRequireDefault(require("./no-important-styles"));
|
|
16
16
|
var _noNestedSelectors = _interopRequireDefault(require("./no-nested-selectors"));
|
|
17
|
+
var _noUnsafeValues = _interopRequireDefault(require("./no-unsafe-values"));
|
|
17
18
|
/**
|
|
18
19
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
19
|
-
* @codegen <<SignedSource::
|
|
20
|
+
* @codegen <<SignedSource::edaedcad824fed1e108f90d909287584>>
|
|
20
21
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
21
22
|
*/
|
|
22
23
|
var _default = exports.default = {
|
|
@@ -28,5 +29,6 @@ var _default = exports.default = {
|
|
|
28
29
|
'no-container-queries': _noContainerQueries.default,
|
|
29
30
|
'no-dynamic-styles': _noDynamicStyles.default,
|
|
30
31
|
'no-important-styles': _noImportantStyles.default,
|
|
31
|
-
'no-nested-selectors': _noNestedSelectors.default
|
|
32
|
+
'no-nested-selectors': _noNestedSelectors.default,
|
|
33
|
+
'no-unsafe-values': _noUnsafeValues.default
|
|
32
34
|
};
|
|
@@ -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
|
+
};
|