@atlaskit/eslint-plugin-design-system 8.25.2 → 8.27.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 +42 -0
- package/README.md +4 -0
- package/constellation/index/usage.mdx +402 -6
- package/dist/cjs/presets/all.codegen.js +5 -1
- package/dist/cjs/presets/recommended.codegen.js +5 -1
- package/dist/cjs/rules/consistent-css-prop-usage/index.js +254 -32
- package/dist/cjs/rules/index.codegen.js +9 -1
- package/dist/cjs/rules/no-empty-styled-expression/index.js +75 -0
- package/dist/cjs/rules/no-exported-css/index.js +37 -0
- package/dist/cjs/rules/no-exported-keyframes/index.js +37 -0
- package/dist/cjs/rules/no-invalid-css-map/index.js +102 -0
- package/dist/cjs/rules/no-invalid-css-map/utils.js +193 -0
- package/dist/cjs/rules/utils/create-no-exported-rule/check-if-supported-export.js +158 -0
- package/dist/cjs/rules/utils/create-no-exported-rule/is-styled-component.js +80 -0
- package/dist/cjs/rules/utils/create-no-exported-rule/main.js +66 -0
- package/dist/cjs/rules/utils/get-first-supported-import.js +28 -0
- package/dist/cjs/rules/utils/is-supported-import.js +53 -16
- package/dist/es2019/presets/all.codegen.js +5 -1
- package/dist/es2019/presets/recommended.codegen.js +5 -1
- package/dist/es2019/rules/consistent-css-prop-usage/index.js +251 -33
- package/dist/es2019/rules/index.codegen.js +9 -1
- package/dist/es2019/rules/no-empty-styled-expression/index.js +65 -0
- package/dist/es2019/rules/no-exported-css/index.js +31 -0
- package/dist/es2019/rules/no-exported-keyframes/index.js +31 -0
- package/dist/es2019/rules/no-invalid-css-map/index.js +95 -0
- package/dist/es2019/rules/no-invalid-css-map/utils.js +134 -0
- package/dist/es2019/rules/utils/create-no-exported-rule/check-if-supported-export.js +142 -0
- package/dist/es2019/rules/utils/create-no-exported-rule/is-styled-component.js +70 -0
- package/dist/es2019/rules/utils/create-no-exported-rule/main.js +59 -0
- package/dist/es2019/rules/utils/get-first-supported-import.js +22 -0
- package/dist/es2019/rules/utils/is-supported-import.js +50 -15
- package/dist/esm/presets/all.codegen.js +5 -1
- package/dist/esm/presets/recommended.codegen.js +5 -1
- package/dist/esm/rules/consistent-css-prop-usage/index.js +255 -33
- package/dist/esm/rules/index.codegen.js +9 -1
- package/dist/esm/rules/no-empty-styled-expression/index.js +68 -0
- package/dist/esm/rules/no-exported-css/index.js +31 -0
- package/dist/esm/rules/no-exported-keyframes/index.js +31 -0
- package/dist/esm/rules/no-invalid-css-map/index.js +96 -0
- package/dist/esm/rules/no-invalid-css-map/utils.js +186 -0
- package/dist/esm/rules/utils/create-no-exported-rule/check-if-supported-export.js +151 -0
- package/dist/esm/rules/utils/create-no-exported-rule/is-styled-component.js +74 -0
- package/dist/esm/rules/utils/create-no-exported-rule/main.js +60 -0
- package/dist/esm/rules/utils/get-first-supported-import.js +22 -0
- package/dist/esm/rules/utils/is-supported-import.js +51 -15
- package/dist/types/index.codegen.d.ts +8 -0
- package/dist/types/presets/all.codegen.d.ts +5 -1
- package/dist/types/presets/recommended.codegen.d.ts +5 -1
- package/dist/types/rules/consistent-css-prop-usage/types.d.ts +7 -2
- package/dist/types/rules/index.codegen.d.ts +4 -0
- package/dist/types/rules/no-empty-styled-expression/index.d.ts +3 -0
- package/dist/types/rules/no-exported-css/index.d.ts +3 -0
- package/dist/types/rules/no-exported-keyframes/index.d.ts +3 -0
- package/dist/types/rules/no-invalid-css-map/index.d.ts +3 -0
- package/dist/types/rules/no-invalid-css-map/utils.d.ts +14 -0
- package/dist/types/rules/use-primitives/utils/update-jsx-attribute-by-name.d.ts +1 -1
- package/dist/types/rules/utils/create-no-exported-rule/check-if-supported-export.d.ts +15 -0
- package/dist/types/rules/utils/create-no-exported-rule/is-styled-component.d.ts +14 -0
- package/dist/types/rules/utils/create-no-exported-rule/main.d.ts +19 -0
- package/dist/types/rules/utils/create-rule.d.ts +1 -1
- package/dist/types/rules/utils/get-first-supported-import.d.ts +17 -0
- package/dist/types/rules/utils/is-supported-import.d.ts +26 -8
- package/dist/types-ts4.5/index.codegen.d.ts +8 -0
- package/dist/types-ts4.5/presets/all.codegen.d.ts +5 -1
- package/dist/types-ts4.5/presets/recommended.codegen.d.ts +5 -1
- package/dist/types-ts4.5/rules/consistent-css-prop-usage/types.d.ts +7 -2
- package/dist/types-ts4.5/rules/index.codegen.d.ts +4 -0
- package/dist/types-ts4.5/rules/no-empty-styled-expression/index.d.ts +3 -0
- package/dist/types-ts4.5/rules/no-exported-css/index.d.ts +3 -0
- package/dist/types-ts4.5/rules/no-exported-keyframes/index.d.ts +3 -0
- package/dist/types-ts4.5/rules/no-invalid-css-map/index.d.ts +3 -0
- package/dist/types-ts4.5/rules/no-invalid-css-map/utils.d.ts +14 -0
- package/dist/types-ts4.5/rules/use-primitives/utils/update-jsx-attribute-by-name.d.ts +1 -1
- package/dist/types-ts4.5/rules/utils/create-no-exported-rule/check-if-supported-export.d.ts +15 -0
- package/dist/types-ts4.5/rules/utils/create-no-exported-rule/is-styled-component.d.ts +14 -0
- package/dist/types-ts4.5/rules/utils/create-no-exported-rule/main.d.ts +19 -0
- package/dist/types-ts4.5/rules/utils/create-rule.d.ts +1 -1
- package/dist/types-ts4.5/rules/utils/get-first-supported-import.d.ts +17 -0
- package/dist/types-ts4.5/rules/utils/is-supported-import.d.ts +26 -8
- package/package.json +3 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,47 @@
|
|
|
1
1
|
# @atlaskit/eslint-plugin-design-system
|
|
2
2
|
|
|
3
|
+
## 8.27.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#72966](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/72966) [`ec187f466e23`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/ec187f466e23) - Update `consistent-css-prop-usage` to incorporate some updates previously made to the `@compiled/eslint-plugin` equivalent.
|
|
8
|
+
|
|
9
|
+
1. Add autofixer to add the `css` function for the following scenario:
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
const styles = { ... };
|
|
13
|
+
<div css={styles} />
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Note that this autofixer will not run if local variables are used inside the style object (e.g. `{ height: makeTaller ? '5px' : '2px' }`), or if there are spread elements, template literals, and other tricky-to-parse code. These continue to require fixing manually.
|
|
17
|
+
|
|
18
|
+
(This rule would previously only autofix if the file was originally `<div css={{ ... }} />`)
|
|
19
|
+
|
|
20
|
+
2. Add `import { css } from '@compiled/react'` (or `xcss`) automatically when fixing. The package from which to import the `css` function can be specified through the `importSource` option.
|
|
21
|
+
|
|
22
|
+
3. Add `excludeReactComponents` to exclude linting React components (i.e. components that start with uppercase). Sometimes it may not be desirable to have this rule apply to React components (e.g. `@atlaskit/button`), which could either use the Emotion or Compiled APIs when they expose a `css` prop. Passing a function from the wrong library can result in the styling erroneously not being applied.
|
|
23
|
+
|
|
24
|
+
4. Treat `{ ... } as const` statements the same way as `{ ... }` objects.
|
|
25
|
+
|
|
26
|
+
5. Add `fixNamesOnly` to disable all autofixers _except_ the autofixer that adds `styles` to the end of existing style variables. For example, in `<div css={buttonComponent} />; const buttonComponent = css({ ... })`, `buttonComponent` will continue to be renamed to `buttonComponentStyles`. Autofixers that will be _disabled_ include hoisting the styles to the top-most scope, and adding the `css` function call around style objects.
|
|
27
|
+
|
|
28
|
+
## 8.26.0
|
|
29
|
+
|
|
30
|
+
### Minor Changes
|
|
31
|
+
|
|
32
|
+
- [#71429](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/71429) [`457122c5d002`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/457122c5d002) - Add some ESLint rules from Compiled CSS-in-JS, and adapt them for the UI Styling Standard.
|
|
33
|
+
|
|
34
|
+
Rules added:
|
|
35
|
+
|
|
36
|
+
- `no-empty-styled-expression`: ban `styled({})` usages
|
|
37
|
+
- `no-exported-css` and `no-exported-keyframes`: ban `css` and `keyframes` function calls that are exported
|
|
38
|
+
- `no-invalid-css-map`: ban usages of the Compiled/`@atlaskit/css` `cssMap` function call that are not valid
|
|
39
|
+
|
|
40
|
+
Changes made:
|
|
41
|
+
|
|
42
|
+
- Add them to monorepo, modify to use the existing utility functions
|
|
43
|
+
- Add support for CSS-in-JS libraries other than Compiled (styled-components, Emotion, `@atlaskit/css`, etc.) and `xcss` where appropriate
|
|
44
|
+
|
|
3
45
|
## 8.25.2
|
|
4
46
|
|
|
5
47
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -59,6 +59,10 @@ module.exports = {
|
|
|
59
59
|
| <a href="./src/rules/no-deprecated-apis/README.md">no-deprecated-apis</a> | Disallow using deprecated APIs. | Yes | | |
|
|
60
60
|
| <a href="./src/rules/no-deprecated-design-token-usage/README.md">no-deprecated-design-token-usage</a> | Disallow using deprecated design tokens. | Yes | Yes | |
|
|
61
61
|
| <a href="./src/rules/no-deprecated-imports/README.md">no-deprecated-imports</a> | Disallow importing deprecated modules. | Yes | | |
|
|
62
|
+
| <a href="./src/rules/no-empty-styled-expression/README.md">no-empty-styled-expression</a> | Forbids any styled expression to be used when passing empty arguments to styled.div() (or other JSX elements). | Yes | | |
|
|
63
|
+
| <a href="./src/rules/no-exported-css/README.md">no-exported-css</a> | Forbid exporting `css` function calls. Exporting `css` function calls can result in unexpected behaviour at runtime, and is not statically analysable. | Yes | | |
|
|
64
|
+
| <a href="./src/rules/no-exported-keyframes/README.md">no-exported-keyframes</a> | Forbid exporting `keyframes` function calls. Exporting `css` function calls can result in unexpected behaviour at runtime, and is not statically analysable. | Yes | | |
|
|
65
|
+
| <a href="./src/rules/no-invalid-css-map/README.md">no-invalid-css-map</a> | Checks the validity of a CSS map created through cssMap. This is intended to be used alongside TypeScript's type-checking. | Yes | | |
|
|
62
66
|
| <a href="./src/rules/no-margin/README.md">no-margin</a> | Disallow using the margin CSS property. | | | |
|
|
63
67
|
| <a href="./src/rules/no-nested-styles/README.md">no-nested-styles</a> | Disallows use of nested styles in `css` functions. | Yes | | |
|
|
64
68
|
| <a href="./src/rules/no-physical-properties/README.md">no-physical-properties</a> | Disallow physical properties and values in `css` function calls. | | Yes | |
|
|
@@ -23,6 +23,10 @@ This plugin contains rules that should be used when working with the [Atlassian
|
|
|
23
23
|
| <a href="#no-deprecated-apis">no-deprecated-apis</a> | Disallow using deprecated APIs. | Yes | | |
|
|
24
24
|
| <a href="#no-deprecated-design-token-usage">no-deprecated-design-token-usage</a> | Disallow using deprecated design tokens. | Yes | Yes | |
|
|
25
25
|
| <a href="#no-deprecated-imports">no-deprecated-imports</a> | Disallow importing deprecated modules. | Yes | | |
|
|
26
|
+
| <a href="#no-empty-styled-expression">no-empty-styled-expression</a> | Forbids any styled expression to be used when passing empty arguments to styled.div() (or other JSX elements). | Yes | | |
|
|
27
|
+
| <a href="#no-exported-css">no-exported-css</a> | Forbid exporting `css` function calls. Exporting `css` function calls can result in unexpected behaviour at runtime, and is not statically analysable. | Yes | | |
|
|
28
|
+
| <a href="#no-exported-keyframes">no-exported-keyframes</a> | Forbid exporting `keyframes` function calls. Exporting `css` function calls can result in unexpected behaviour at runtime, and is not statically analysable. | Yes | | |
|
|
29
|
+
| <a href="#no-invalid-css-map">no-invalid-css-map</a> | Checks the validity of a CSS map created through cssMap. This is intended to be used alongside TypeScript's type-checking. | Yes | | |
|
|
26
30
|
| <a href="#no-margin">no-margin</a> | Disallow using the margin CSS property. | | | |
|
|
27
31
|
| <a href="#no-nested-styles">no-nested-styles</a> | Disallows use of nested styles in `css` functions. | Yes | | |
|
|
28
32
|
| <a href="#no-physical-properties">no-physical-properties</a> | Disallow physical properties and values in `css` function calls. | | Yes | |
|
|
@@ -54,14 +58,19 @@ Every product should be defining styles in the same way, using the same tools, e
|
|
|
54
58
|
|
|
55
59
|
This rule checks for the following cases:
|
|
56
60
|
|
|
57
|
-
-
|
|
58
|
-
-
|
|
59
|
-
-
|
|
60
|
-
-
|
|
61
|
+
- Styles should not be defined inline; it should instead be in a standalone variable.
|
|
62
|
+
- The exception for this is style composition (e.g. `<div css={[baseStyles, moreStyles]} />`), which is a way to combine styles from two variables.
|
|
63
|
+
- Styles must be wrapped in a `css` function call.
|
|
64
|
+
- Styles must be defined in the same file as their usage, and not be imported.
|
|
65
|
+
- Styles should not contain spread operators (e.g. `css({ ...spreadStyles })`).
|
|
66
|
+
- Styles must all be defined at the top of the file, or at the bottom of the file.
|
|
67
|
+
- Styles must be in a variable whose name ends in `styles` (or `Styles`).
|
|
68
|
+
|
|
69
|
+
This rule also has an autofixer that enforces and fixes the code (where practical) to meet the above requirements.
|
|
61
70
|
|
|
62
71
|
All the above can also work for custom `css` functions, such as `xcss` (https://atlassian.design/components/primitives/xcss/).
|
|
63
72
|
|
|
64
|
-
This rule has options - see below.
|
|
73
|
+
This rule has several options - see below.
|
|
65
74
|
|
|
66
75
|
<h3>Examples</h3>
|
|
67
76
|
|
|
@@ -193,13 +202,44 @@ This rule comes with options to support different repository configurations.
|
|
|
193
202
|
|
|
194
203
|
#### cssFunctions
|
|
195
204
|
|
|
196
|
-
An array of function names the linting rule should target. Defaults to `['css', 'xcss']`.
|
|
205
|
+
An array of function names the linting rule should target. Defaults to `['css', 'xcss']`. The functionality of `cssMap` will be linted regardless of the configuration of `cssFunctions`, as it can be used with either attribute.
|
|
197
206
|
|
|
198
207
|
#### stylesPlacement
|
|
199
208
|
|
|
209
|
+
Either `top` or `bottom`.
|
|
210
|
+
|
|
200
211
|
The rule prevents inline styles from being created. This option defines what the error message should say: "(...) styles at the top (...)" or "(...) styles at the bottom (...)".
|
|
201
212
|
Defaults to `top`.
|
|
202
213
|
|
|
214
|
+
#### cssImportSource
|
|
215
|
+
|
|
216
|
+
When auto-fixing the contents of the `css` attribute, this rule will wrap CSS styles in a `css(...)` function call or `` css\`...\` `` template expression, and it will add an import declaration for the `css` function. `cssImportSource` is a string that determines what package `css` should be imported from.
|
|
217
|
+
|
|
218
|
+
This is `@compiled/react` by default.
|
|
219
|
+
|
|
220
|
+
#### xcssImportSource
|
|
221
|
+
|
|
222
|
+
When auto-fixing the contents of the `xcss` attribute, this rule will wrap XCSS styles in a `xcss(...)` function call, and it will add an import declaration for the `xcss` function. `cssImportSource` is a string that determines what package `xcss` should be imported from.
|
|
223
|
+
|
|
224
|
+
This is `@atlaskit/primitives` by default.
|
|
225
|
+
|
|
226
|
+
#### excludeReactComponents
|
|
227
|
+
|
|
228
|
+
Whether to exclude `css` attributes of React components from being affected by this ESLint rule. We assume that an element is a React component if its name starts with a capital letter, e.g. `<Button />`.
|
|
229
|
+
|
|
230
|
+
This is `false` by default.
|
|
231
|
+
|
|
232
|
+
#### fixNamesOnly
|
|
233
|
+
|
|
234
|
+
When enabled, this rule will only add `styles` at the end of existing style variables. All other autofixers will be disabled. For example:
|
|
235
|
+
|
|
236
|
+
```tsx
|
|
237
|
+
// vvvvv will be renamed to `myCssStyles`
|
|
238
|
+
const myCss = { color: 'blue' };
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
This is `false` by default.
|
|
242
|
+
|
|
203
243
|
## ensure-design-token-usage
|
|
204
244
|
|
|
205
245
|
Using design tokens results in a harmonious experience for end users whilst providing theming and consistency.
|
|
@@ -583,6 +623,362 @@ module.exports = {
|
|
|
583
623
|
};
|
|
584
624
|
```
|
|
585
625
|
|
|
626
|
+
## no-empty-styled-expression
|
|
627
|
+
|
|
628
|
+
Disallows/discourages passing empty arguments to any `styled` expression when using `@compiled/react`, as well as any other CSS-in-JS library defined through the `importSources` option.
|
|
629
|
+
|
|
630
|
+
If Compiled is used in the file, passing an empty object or no object at all causes Compiled to build extra `div/span` elements, as opposed to simply using a `div`. This leads to reduced performance and is greatly discouraged. If a wrapper is necessary, opt to use a `div` or wrap it in the empty React fragment `<> <YourComponentHere></YourComponentHere> </>`.
|
|
631
|
+
|
|
632
|
+
<h3>Examples</h3>
|
|
633
|
+
|
|
634
|
+
#### Incorrect
|
|
635
|
+
|
|
636
|
+
```tsx
|
|
637
|
+
const EmptyStyledExpression = styled.div();
|
|
638
|
+
|
|
639
|
+
const EmptyStyledExpressionArgument = styled.div({});
|
|
640
|
+
|
|
641
|
+
const EmptyStyledExpressionArgument = styled.div([]);
|
|
642
|
+
```
|
|
643
|
+
|
|
644
|
+
#### Correct
|
|
645
|
+
|
|
646
|
+
```tsx
|
|
647
|
+
const Wrapper = styled.div({
|
|
648
|
+
backgroundColor: 'red',
|
|
649
|
+
MyComponent: {
|
|
650
|
+
backgroundColor: 'green',
|
|
651
|
+
},
|
|
652
|
+
});
|
|
653
|
+
```
|
|
654
|
+
|
|
655
|
+
<h3>What to do instead?</h3>
|
|
656
|
+
|
|
657
|
+
#### Use elements directly
|
|
658
|
+
|
|
659
|
+
```diff
|
|
660
|
+
- const Wrapper = styled.div({});
|
|
661
|
+
|
|
662
|
+
function App() {
|
|
663
|
+
- return <Wrapper>hello world</Wrapper>;
|
|
664
|
+
+ return <div>hello world</div>;
|
|
665
|
+
}
|
|
666
|
+
```
|
|
667
|
+
|
|
668
|
+
#### Use a React fragment
|
|
669
|
+
|
|
670
|
+
```diff
|
|
671
|
+
- const Wrapper = styled.div({});
|
|
672
|
+
|
|
673
|
+
function App() {
|
|
674
|
+
- return <Wrapper>hello world</Wrapper>;
|
|
675
|
+
+ return <>hello world</>;
|
|
676
|
+
}
|
|
677
|
+
```
|
|
678
|
+
|
|
679
|
+
<h3>Options</h3>
|
|
680
|
+
|
|
681
|
+
#### importSources
|
|
682
|
+
|
|
683
|
+
By default, this rule will check `styled` usages from `@compiled/react`. To check `styled` usages from other CSS-in-JS libraries, you can add the library's package name to `importSources`.
|
|
684
|
+
|
|
685
|
+
`importSources` accepts an array of package names (strings). `styled` usages from `@compiled/react` will always be checked, regardless of the value of `importSources`.
|
|
686
|
+
|
|
687
|
+
```tsx
|
|
688
|
+
// [{ importSources: ['styled-components'] }]
|
|
689
|
+
|
|
690
|
+
import styled from 'styled-components';
|
|
691
|
+
|
|
692
|
+
// Invalid!
|
|
693
|
+
const styles = styled({});
|
|
694
|
+
```
|
|
695
|
+
|
|
696
|
+
## no-exported-css
|
|
697
|
+
|
|
698
|
+
Disallows `css` export declarations that originate from `@compiled/react` and `@atlaskit/css`, as well as any other CSS-in-JS library defined through the `importSources` option.
|
|
699
|
+
|
|
700
|
+
In Compiled, exporting css declarations may result in unexpected errors when imported, because its value will be `null` at runtime. Additionally, co-locating css definitions with their usage is considered best practice in order to improve code readability and build performance.
|
|
701
|
+
|
|
702
|
+
<h3>Examples</h3>
|
|
703
|
+
|
|
704
|
+
#### Incorrect
|
|
705
|
+
|
|
706
|
+
```tsx
|
|
707
|
+
import { css } from '@compiled/react';
|
|
708
|
+
|
|
709
|
+
export const styles = css({});
|
|
710
|
+
|
|
711
|
+
export default css({});
|
|
712
|
+
```
|
|
713
|
+
|
|
714
|
+
#### Correct
|
|
715
|
+
|
|
716
|
+
```tsx
|
|
717
|
+
import { css } from '@compiled/react';
|
|
718
|
+
|
|
719
|
+
const styles = css({});
|
|
720
|
+
```
|
|
721
|
+
|
|
722
|
+
<h3>Options</h3>
|
|
723
|
+
|
|
724
|
+
#### importSources
|
|
725
|
+
|
|
726
|
+
By default, this rule will check `css` usages from `@compiled/react` and `@atlaskit/css`. To check `css` usages from other CSS-in-JS libraries, you can add the library's package name to `importSources`.
|
|
727
|
+
|
|
728
|
+
`importSources` accepts an array of package names (strings). `css` usages from `@compiled/react` and `@atlaskit/css` will always be checked, regardless of the value of `importSources`.
|
|
729
|
+
|
|
730
|
+
```tsx
|
|
731
|
+
// [{ importSources: ['@emotion/css'] }]
|
|
732
|
+
|
|
733
|
+
import { css } from '@emotion/css';
|
|
734
|
+
|
|
735
|
+
// Invalid!
|
|
736
|
+
export const styles = css({});
|
|
737
|
+
```
|
|
738
|
+
|
|
739
|
+
## no-exported-keyframes
|
|
740
|
+
|
|
741
|
+
Disallows `keyframes` export declarations that originate from `@compiled/react`, as well as any other CSS-in-JS library defined through the `importSources` option.
|
|
742
|
+
|
|
743
|
+
In Compiled, exporting keyframes declarations may result in unexpected errors when imported, because its value will be `null` at runtime. Additionally, co-locating keyframes definitions with their usage is considered best practice in order to improve code readability and build performance.
|
|
744
|
+
|
|
745
|
+
<h3>Examples</h3>
|
|
746
|
+
|
|
747
|
+
#### Incorrect
|
|
748
|
+
|
|
749
|
+
```tsx
|
|
750
|
+
import { keyframes } from '@compiled/react';
|
|
751
|
+
|
|
752
|
+
export const animation = keyframes({});
|
|
753
|
+
|
|
754
|
+
export default keyframes({});
|
|
755
|
+
```
|
|
756
|
+
|
|
757
|
+
#### Correct
|
|
758
|
+
|
|
759
|
+
```tsx
|
|
760
|
+
import { keyframes } from '@compiled/react';
|
|
761
|
+
|
|
762
|
+
const animation = keyframes({});
|
|
763
|
+
```
|
|
764
|
+
|
|
765
|
+
<h3>Options</h3>
|
|
766
|
+
|
|
767
|
+
#### importSources
|
|
768
|
+
|
|
769
|
+
By default, this rule will check `keyframes` usages from `@compiled/react`. To check `keyframes` usages from other CSS-in-JS libraries, you can add the library's package name to `importSources`.
|
|
770
|
+
|
|
771
|
+
`importSources` accepts an array of package names (strings). `keyframes` usages from `@compiled/react` will always be checked, regardless of the value of `importSources`.
|
|
772
|
+
|
|
773
|
+
```tsx
|
|
774
|
+
// [{ importSources: ['@emotion/css'] }]
|
|
775
|
+
|
|
776
|
+
import { keyframes } from '@emotion/css';
|
|
777
|
+
|
|
778
|
+
// Invalid!
|
|
779
|
+
export const styles = keyframes({});
|
|
780
|
+
```
|
|
781
|
+
|
|
782
|
+
## no-invalid-css-map
|
|
783
|
+
|
|
784
|
+
Ensure that all usages of the `cssMap` API are valid, and enforces the format of the object that is passed to `cssMap`.
|
|
785
|
+
|
|
786
|
+
Please refer to the [Compiled documentation](https://compiledcssinjs.com/docs/api-cssmap) for more details and some examples.
|
|
787
|
+
|
|
788
|
+
Note that this version of the `no-invalid-css-map` rule differs from `@compiled/eslint-plugin/no-invalid-css-map` in that this will apply to both `@compiled/react` and `@atlaskit/css`.
|
|
789
|
+
|
|
790
|
+
This is intended to be used in conjunction with type checking (through TypeScript).
|
|
791
|
+
|
|
792
|
+
<h3>Examples</h3>
|
|
793
|
+
|
|
794
|
+
#### Incorrect
|
|
795
|
+
|
|
796
|
+
```tsx
|
|
797
|
+
import React from 'react';
|
|
798
|
+
import { cssMap } from '@compiled/react';
|
|
799
|
+
|
|
800
|
+
// cssMap needs to be declared in the top-most scope.
|
|
801
|
+
// (not within a function, class, etc.)
|
|
802
|
+
|
|
803
|
+
const Foo = () => {
|
|
804
|
+
const bar = cssMap({
|
|
805
|
+
danger: {
|
|
806
|
+
color: 'red',
|
|
807
|
+
},
|
|
808
|
+
});
|
|
809
|
+
};
|
|
810
|
+
```
|
|
811
|
+
|
|
812
|
+
```tsx
|
|
813
|
+
import React from 'react';
|
|
814
|
+
import { cssMap } from '@compiled/react';
|
|
815
|
+
import { importedVariable, importedFunction } from 'another-package';
|
|
816
|
+
|
|
817
|
+
// Cannot use imported functions as values in cssMap.
|
|
818
|
+
|
|
819
|
+
const myVariable = importedFunction();
|
|
820
|
+
|
|
821
|
+
const styles = cssMap({
|
|
822
|
+
danger: {
|
|
823
|
+
// Both invalid because they rely on an imported function.
|
|
824
|
+
color: myVariable,
|
|
825
|
+
padding: importedFunction(),
|
|
826
|
+
},
|
|
827
|
+
});
|
|
828
|
+
```
|
|
829
|
+
|
|
830
|
+
```tsx
|
|
831
|
+
import React from 'react';
|
|
832
|
+
import { cssMap } from '@compiled/react';
|
|
833
|
+
|
|
834
|
+
// Cannot export usages of cssMap.
|
|
835
|
+
// Any usages of cssMap must be in the same file.
|
|
836
|
+
|
|
837
|
+
export const foo = cssMap({
|
|
838
|
+
danger: {
|
|
839
|
+
color: 'red',
|
|
840
|
+
},
|
|
841
|
+
});
|
|
842
|
+
```
|
|
843
|
+
|
|
844
|
+
```tsx
|
|
845
|
+
import React from 'react';
|
|
846
|
+
import { cssMap } from '@compiled/react';
|
|
847
|
+
import { token } from '@atlaskit/tokens';
|
|
848
|
+
|
|
849
|
+
// Functions and object methods are not allowed as
|
|
850
|
+
// values in cssMap.
|
|
851
|
+
|
|
852
|
+
const styles = cssMap({
|
|
853
|
+
// Object method
|
|
854
|
+
get danger() {
|
|
855
|
+
return { color: '#123456' };
|
|
856
|
+
},
|
|
857
|
+
});
|
|
858
|
+
|
|
859
|
+
const styles2 = cssMap({
|
|
860
|
+
// Arrow function
|
|
861
|
+
danger: () => {
|
|
862
|
+
color: '#123456';
|
|
863
|
+
},
|
|
864
|
+
});
|
|
865
|
+
|
|
866
|
+
function customFunction(...args) {
|
|
867
|
+
return arguments.join('');
|
|
868
|
+
}
|
|
869
|
+
|
|
870
|
+
const styles3 = cssMap({
|
|
871
|
+
danger: {
|
|
872
|
+
// Locally defined function
|
|
873
|
+
color: customFunction('red', 'blue'),
|
|
874
|
+
backgroundColor: 'red',
|
|
875
|
+
},
|
|
876
|
+
});
|
|
877
|
+
```
|
|
878
|
+
|
|
879
|
+
```tsx
|
|
880
|
+
import React from 'react';
|
|
881
|
+
import { cssMap } from '@compiled/react';
|
|
882
|
+
|
|
883
|
+
// Spread elements ("...") cannot be used in cssMap.
|
|
884
|
+
|
|
885
|
+
const base = {
|
|
886
|
+
success: {
|
|
887
|
+
color: 'green',
|
|
888
|
+
},
|
|
889
|
+
};
|
|
890
|
+
|
|
891
|
+
const bar = cssMap({
|
|
892
|
+
...base,
|
|
893
|
+
danger: {
|
|
894
|
+
color: 'red',
|
|
895
|
+
},
|
|
896
|
+
});
|
|
897
|
+
```
|
|
898
|
+
|
|
899
|
+
#### Correct
|
|
900
|
+
|
|
901
|
+
```tsx
|
|
902
|
+
import React from 'react';
|
|
903
|
+
import { cssMap } from '@compiled/react';
|
|
904
|
+
|
|
905
|
+
// Literals (strings, numbers, etc.) are used as values
|
|
906
|
+
// in cssMap.
|
|
907
|
+
|
|
908
|
+
const styles = cssMap({
|
|
909
|
+
danger: {
|
|
910
|
+
color: 'red',
|
|
911
|
+
backgroundColor: 'red',
|
|
912
|
+
},
|
|
913
|
+
success: {
|
|
914
|
+
color: 'green',
|
|
915
|
+
backgroundColor: 'green',
|
|
916
|
+
},
|
|
917
|
+
});
|
|
918
|
+
```
|
|
919
|
+
|
|
920
|
+
```tsx
|
|
921
|
+
import React from 'react';
|
|
922
|
+
import { cssMap } from '@compiled/react';
|
|
923
|
+
|
|
924
|
+
// A statically evaluable variable (known at build time)
|
|
925
|
+
// is used here.
|
|
926
|
+
|
|
927
|
+
const bap = 'blue';
|
|
928
|
+
|
|
929
|
+
const styles = cssMap({
|
|
930
|
+
danger: {
|
|
931
|
+
color: bap,
|
|
932
|
+
},
|
|
933
|
+
});
|
|
934
|
+
```
|
|
935
|
+
|
|
936
|
+
#### Options
|
|
937
|
+
|
|
938
|
+
##### `allowedFunctionCalls`: [string, string][]
|
|
939
|
+
|
|
940
|
+
Normally, this ESLint rule forbids all function calls from being used inside the `cssMap(...)` function call. For example, this would be invalid using default settings:
|
|
941
|
+
|
|
942
|
+
```tsx
|
|
943
|
+
import React from 'react';
|
|
944
|
+
import { cssMap } from '@compiled/react';
|
|
945
|
+
import { token } from '@atlaskit/tokens';
|
|
946
|
+
|
|
947
|
+
const styles = cssMap({
|
|
948
|
+
danger: {
|
|
949
|
+
color: token('my-color'),
|
|
950
|
+
backgroundColor: 'red',
|
|
951
|
+
},
|
|
952
|
+
success: {
|
|
953
|
+
color: 'green',
|
|
954
|
+
},
|
|
955
|
+
});
|
|
956
|
+
```
|
|
957
|
+
|
|
958
|
+
If you would like to whitelist certain functions (e.g. `token` from `@atlaskit/tokens`), you can include the names of the functions as part of the `allowedFunctionCalls` argument. Each function should be represented as a two-element array, with the first element being the package the function is from, and the second element being the name of the function.
|
|
959
|
+
|
|
960
|
+
For example, with the below configuration, the above code example would be okay.
|
|
961
|
+
|
|
962
|
+
```tsx
|
|
963
|
+
// .eslintrc.js
|
|
964
|
+
|
|
965
|
+
// ...
|
|
966
|
+
rules: {
|
|
967
|
+
'@atlaskit/eslint-plugin-design-system/no-invalid-css-map': [
|
|
968
|
+
'error',
|
|
969
|
+
{
|
|
970
|
+
allowedFunctionCalls: [
|
|
971
|
+
['@atlaskit/tokens', 'token'],
|
|
972
|
+
]
|
|
973
|
+
},
|
|
974
|
+
],
|
|
975
|
+
// ...
|
|
976
|
+
},
|
|
977
|
+
// ...
|
|
978
|
+
```
|
|
979
|
+
|
|
980
|
+
Please note that this ESLint rule only supports whitelisting imports in the form `import { myFunctionOrVariable } from 'my-package'`; we do not currently support whitelisting default imports, so `import myFunctionOrVariable from 'my-package'` would always be invalid when used in `cssMap`.
|
|
981
|
+
|
|
586
982
|
## no-margin
|
|
587
983
|
|
|
588
984
|
Using margins to define spacing results in components that can't be readily reused in other contexts breaking the composition model.
|
|
@@ -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::914085544778f4543f43e3e30d0982e0>>
|
|
10
10
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
|
|
11
11
|
*/
|
|
12
12
|
var _default = exports.default = {
|
|
@@ -22,6 +22,10 @@ var _default = exports.default = {
|
|
|
22
22
|
'@atlaskit/design-system/no-deprecated-apis': 'error',
|
|
23
23
|
'@atlaskit/design-system/no-deprecated-design-token-usage': 'warn',
|
|
24
24
|
'@atlaskit/design-system/no-deprecated-imports': 'error',
|
|
25
|
+
'@atlaskit/design-system/no-empty-styled-expression': 'warn',
|
|
26
|
+
'@atlaskit/design-system/no-exported-css': 'warn',
|
|
27
|
+
'@atlaskit/design-system/no-exported-keyframes': 'warn',
|
|
28
|
+
'@atlaskit/design-system/no-invalid-css-map': 'error',
|
|
25
29
|
'@atlaskit/design-system/no-margin': 'warn',
|
|
26
30
|
'@atlaskit/design-system/no-nested-styles': 'error',
|
|
27
31
|
'@atlaskit/design-system/no-physical-properties': 'error',
|
|
@@ -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::577269c832952ce359cde6a50f26f4e0>>
|
|
10
10
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
|
|
11
11
|
*/
|
|
12
12
|
var _default = exports.default = {
|
|
@@ -20,6 +20,10 @@ var _default = exports.default = {
|
|
|
20
20
|
'@atlaskit/design-system/no-deprecated-apis': 'error',
|
|
21
21
|
'@atlaskit/design-system/no-deprecated-design-token-usage': 'warn',
|
|
22
22
|
'@atlaskit/design-system/no-deprecated-imports': 'error',
|
|
23
|
+
'@atlaskit/design-system/no-empty-styled-expression': 'warn',
|
|
24
|
+
'@atlaskit/design-system/no-exported-css': 'warn',
|
|
25
|
+
'@atlaskit/design-system/no-exported-keyframes': 'warn',
|
|
26
|
+
'@atlaskit/design-system/no-invalid-css-map': 'error',
|
|
23
27
|
'@atlaskit/design-system/no-nested-styles': 'error',
|
|
24
28
|
'@atlaskit/design-system/no-unsafe-design-token-usage': 'error',
|
|
25
29
|
'@atlaskit/design-system/no-unsafe-style-overrides': 'warn',
|