@atlaskit/eslint-plugin-design-system 8.25.1 → 8.26.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 +23 -0
- package/README.md +4 -0
- package/constellation/index/usage.mdx +362 -0
- package/dist/cjs/ast-nodes/object.js +8 -1
- package/dist/cjs/presets/all.codegen.js +5 -1
- package/dist/cjs/presets/recommended.codegen.js +5 -1
- 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/use-primitives/utils/is-valid-css-properties-to-transform.js +5 -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 +84 -0
- package/dist/cjs/rules/utils/create-no-exported-rule/main.js +66 -0
- package/dist/cjs/rules/utils/is-supported-import.js +51 -15
- package/dist/es2019/ast-nodes/object.js +8 -1
- package/dist/es2019/presets/all.codegen.js +5 -1
- package/dist/es2019/presets/recommended.codegen.js +5 -1
- 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/use-primitives/utils/is-valid-css-properties-to-transform.js +5 -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 +74 -0
- package/dist/es2019/rules/utils/create-no-exported-rule/main.js +59 -0
- package/dist/es2019/rules/utils/is-supported-import.js +48 -14
- package/dist/esm/ast-nodes/object.js +8 -1
- package/dist/esm/presets/all.codegen.js +5 -1
- package/dist/esm/presets/recommended.codegen.js +5 -1
- 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/use-primitives/utils/is-valid-css-properties-to-transform.js +5 -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 +78 -0
- package/dist/esm/rules/utils/create-no-exported-rule/main.js +60 -0
- package/dist/esm/rules/utils/is-supported-import.js +49 -14
- package/dist/types/ast-nodes/object.d.ts +7 -2
- 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/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/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/is-supported-import.d.ts +25 -8
- package/dist/types-ts4.5/ast-nodes/object.d.ts +7 -2
- 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/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/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/is-supported-import.d.ts +25 -8
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,28 @@
|
|
|
1
1
|
# @atlaskit/eslint-plugin-design-system
|
|
2
2
|
|
|
3
|
+
## 8.26.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#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.
|
|
8
|
+
|
|
9
|
+
Rules added:
|
|
10
|
+
|
|
11
|
+
- `no-empty-styled-expression`: ban `styled({})` usages
|
|
12
|
+
- `no-exported-css` and `no-exported-keyframes`: ban `css` and `keyframes` function calls that are exported
|
|
13
|
+
- `no-invalid-css-map`: ban usages of the Compiled/`@atlaskit/css` `cssMap` function call that are not valid
|
|
14
|
+
|
|
15
|
+
Changes made:
|
|
16
|
+
|
|
17
|
+
- Add them to monorepo, modify to use the existing utility functions
|
|
18
|
+
- Add support for CSS-in-JS libraries other than Compiled (styled-components, Emotion, `@atlaskit/css`, etc.) and `xcss` where appropriate
|
|
19
|
+
|
|
20
|
+
## 8.25.2
|
|
21
|
+
|
|
22
|
+
### Patch Changes
|
|
23
|
+
|
|
24
|
+
- [#71361](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/71361) [`0f3be2c76337`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/0f3be2c76337) - `use-primitives` no longer reports elements that have empty style objects.
|
|
25
|
+
|
|
3
26
|
## 8.25.1
|
|
4
27
|
|
|
5
28
|
### 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 | |
|
|
@@ -583,6 +587,364 @@ module.exports = {
|
|
|
583
587
|
};
|
|
584
588
|
```
|
|
585
589
|
|
|
590
|
+
## no-empty-styled-expression
|
|
591
|
+
|
|
592
|
+
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.
|
|
593
|
+
|
|
594
|
+
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> </>`.
|
|
595
|
+
|
|
596
|
+
<h3>Examples</h3>
|
|
597
|
+
|
|
598
|
+
#### Incorrect
|
|
599
|
+
|
|
600
|
+
```tsx
|
|
601
|
+
const EmptyStyledExpression = styled.div();
|
|
602
|
+
|
|
603
|
+
const EmptyStyledExpressionArgument = styled.div({});
|
|
604
|
+
|
|
605
|
+
const EmptyStyledExpressionArgument = styled.div([]);
|
|
606
|
+
```
|
|
607
|
+
|
|
608
|
+
#### Correct
|
|
609
|
+
|
|
610
|
+
```tsx
|
|
611
|
+
const Wrapper = styled.div({
|
|
612
|
+
backgroundColor: 'red',
|
|
613
|
+
MyComponent: {
|
|
614
|
+
backgroundColor: 'green',
|
|
615
|
+
},
|
|
616
|
+
});
|
|
617
|
+
```
|
|
618
|
+
|
|
619
|
+
<h3>What to do instead?</h3>
|
|
620
|
+
|
|
621
|
+
#### Use elements directly
|
|
622
|
+
|
|
623
|
+
```diff
|
|
624
|
+
- const Wrapper = styled.div({});
|
|
625
|
+
|
|
626
|
+
function App() {
|
|
627
|
+
- return <Wrapper>hello world</Wrapper>;
|
|
628
|
+
+ return <div>hello world</div>;
|
|
629
|
+
}
|
|
630
|
+
```
|
|
631
|
+
|
|
632
|
+
#### Use a React fragment
|
|
633
|
+
|
|
634
|
+
```diff
|
|
635
|
+
- const Wrapper = styled.div({});
|
|
636
|
+
|
|
637
|
+
function App() {
|
|
638
|
+
- return <Wrapper>hello world</Wrapper>;
|
|
639
|
+
+ return <>hello world</>;
|
|
640
|
+
}
|
|
641
|
+
```
|
|
642
|
+
|
|
643
|
+
<h3>Options</h3>
|
|
644
|
+
|
|
645
|
+
#### importSources
|
|
646
|
+
|
|
647
|
+
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`.
|
|
648
|
+
|
|
649
|
+
`importSources` accepts an array of package names (strings). `styled` usages from `@compiled/react` will always be checked, regardless of the value of `importSources`.
|
|
650
|
+
|
|
651
|
+
```tsx
|
|
652
|
+
// [{ importSources: ['styled-components'] }]
|
|
653
|
+
|
|
654
|
+
import styled from 'styled-components';
|
|
655
|
+
|
|
656
|
+
// Invalid!
|
|
657
|
+
const styles = styled({});
|
|
658
|
+
```
|
|
659
|
+
|
|
660
|
+
## no-exported-css
|
|
661
|
+
|
|
662
|
+
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.
|
|
663
|
+
|
|
664
|
+
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.
|
|
665
|
+
|
|
666
|
+
<h3>Examples</h3>
|
|
667
|
+
|
|
668
|
+
#### Incorrect
|
|
669
|
+
|
|
670
|
+
```tsx
|
|
671
|
+
import { css } from '@compiled/react';
|
|
672
|
+
|
|
673
|
+
export const styles = css({});
|
|
674
|
+
|
|
675
|
+
export default css({});
|
|
676
|
+
```
|
|
677
|
+
|
|
678
|
+
#### Correct
|
|
679
|
+
|
|
680
|
+
```tsx
|
|
681
|
+
import { css } from '@compiled/react';
|
|
682
|
+
|
|
683
|
+
const styles = css({});
|
|
684
|
+
```
|
|
685
|
+
|
|
686
|
+
<h3>Options</h3>
|
|
687
|
+
|
|
688
|
+
#### importSources
|
|
689
|
+
|
|
690
|
+
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`.
|
|
691
|
+
|
|
692
|
+
`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`.
|
|
693
|
+
|
|
694
|
+
```tsx
|
|
695
|
+
// [{ importSources: ['@emotion/css'] }]
|
|
696
|
+
|
|
697
|
+
import { css } from '@emotion/css';
|
|
698
|
+
|
|
699
|
+
// Invalid!
|
|
700
|
+
export const styles = css({});
|
|
701
|
+
```
|
|
702
|
+
|
|
703
|
+
## no-exported-keyframes
|
|
704
|
+
|
|
705
|
+
Disallows `keyframes` export declarations that originate from `@compiled/react`, as well as any other CSS-in-JS library defined through the `importSources` option.
|
|
706
|
+
|
|
707
|
+
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.
|
|
708
|
+
|
|
709
|
+
<h3>Examples</h3>
|
|
710
|
+
|
|
711
|
+
<!-- To fill out -- tell us when this rule will mark violations. -->
|
|
712
|
+
|
|
713
|
+
#### Incorrect
|
|
714
|
+
|
|
715
|
+
```tsx
|
|
716
|
+
import { keyframes } from '@compiled/react';
|
|
717
|
+
|
|
718
|
+
export const animation = keyframes({});
|
|
719
|
+
|
|
720
|
+
export default keyframes({});
|
|
721
|
+
```
|
|
722
|
+
|
|
723
|
+
#### Correct
|
|
724
|
+
|
|
725
|
+
```tsx
|
|
726
|
+
import { keyframes } from '@compiled/react';
|
|
727
|
+
|
|
728
|
+
const animation = keyframes({});
|
|
729
|
+
```
|
|
730
|
+
|
|
731
|
+
<h3>Options</h3>
|
|
732
|
+
|
|
733
|
+
#### importSources
|
|
734
|
+
|
|
735
|
+
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`.
|
|
736
|
+
|
|
737
|
+
`importSources` accepts an array of package names (strings). `keyframes` usages from `@compiled/react` will always be checked, regardless of the value of `importSources`.
|
|
738
|
+
|
|
739
|
+
```tsx
|
|
740
|
+
// [{ importSources: ['@emotion/css'] }]
|
|
741
|
+
|
|
742
|
+
import { keyframes } from '@emotion/css';
|
|
743
|
+
|
|
744
|
+
// Invalid!
|
|
745
|
+
export const styles = keyframes({});
|
|
746
|
+
```
|
|
747
|
+
|
|
748
|
+
## no-invalid-css-map
|
|
749
|
+
|
|
750
|
+
Ensure that all usages of the `cssMap` API are valid, and enforces the format of the object that is passed to `cssMap`.
|
|
751
|
+
|
|
752
|
+
Please refer to the [Compiled documentation](https://compiledcssinjs.com/docs/api-cssmap) for more details and some examples.
|
|
753
|
+
|
|
754
|
+
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`.
|
|
755
|
+
|
|
756
|
+
This is intended to be used in conjunction with type checking (through TypeScript).
|
|
757
|
+
|
|
758
|
+
<h3>Examples</h3>
|
|
759
|
+
|
|
760
|
+
#### Incorrect
|
|
761
|
+
|
|
762
|
+
```tsx
|
|
763
|
+
import React from 'react';
|
|
764
|
+
import { cssMap } from '@compiled/react';
|
|
765
|
+
|
|
766
|
+
// cssMap needs to be declared in the top-most scope.
|
|
767
|
+
// (not within a function, class, etc.)
|
|
768
|
+
|
|
769
|
+
const Foo = () => {
|
|
770
|
+
const bar = cssMap({
|
|
771
|
+
danger: {
|
|
772
|
+
color: 'red',
|
|
773
|
+
},
|
|
774
|
+
});
|
|
775
|
+
};
|
|
776
|
+
```
|
|
777
|
+
|
|
778
|
+
```tsx
|
|
779
|
+
import React from 'react';
|
|
780
|
+
import { cssMap } from '@compiled/react';
|
|
781
|
+
import { importedVariable, importedFunction } from 'another-package';
|
|
782
|
+
|
|
783
|
+
// Cannot use imported functions as values in cssMap.
|
|
784
|
+
|
|
785
|
+
const myVariable = importedFunction();
|
|
786
|
+
|
|
787
|
+
const styles = cssMap({
|
|
788
|
+
danger: {
|
|
789
|
+
// Both invalid because they rely on an imported function.
|
|
790
|
+
color: myVariable,
|
|
791
|
+
padding: importedFunction(),
|
|
792
|
+
},
|
|
793
|
+
});
|
|
794
|
+
```
|
|
795
|
+
|
|
796
|
+
```tsx
|
|
797
|
+
import React from 'react';
|
|
798
|
+
import { cssMap } from '@compiled/react';
|
|
799
|
+
|
|
800
|
+
// Cannot export usages of cssMap.
|
|
801
|
+
// Any usages of cssMap must be in the same file.
|
|
802
|
+
|
|
803
|
+
export const foo = cssMap({
|
|
804
|
+
danger: {
|
|
805
|
+
color: 'red',
|
|
806
|
+
},
|
|
807
|
+
});
|
|
808
|
+
```
|
|
809
|
+
|
|
810
|
+
```tsx
|
|
811
|
+
import React from 'react';
|
|
812
|
+
import { cssMap } from '@compiled/react';
|
|
813
|
+
import { token } from '@atlaskit/tokens';
|
|
814
|
+
|
|
815
|
+
// Functions and object methods are not allowed as
|
|
816
|
+
// values in cssMap.
|
|
817
|
+
|
|
818
|
+
const styles = cssMap({
|
|
819
|
+
// Object method
|
|
820
|
+
get danger() {
|
|
821
|
+
return { color: '#123456' };
|
|
822
|
+
},
|
|
823
|
+
});
|
|
824
|
+
|
|
825
|
+
const styles2 = cssMap({
|
|
826
|
+
// Arrow function
|
|
827
|
+
danger: () => {
|
|
828
|
+
color: '#123456';
|
|
829
|
+
},
|
|
830
|
+
});
|
|
831
|
+
|
|
832
|
+
function customFunction(...args) {
|
|
833
|
+
return arguments.join('');
|
|
834
|
+
}
|
|
835
|
+
|
|
836
|
+
const styles3 = cssMap({
|
|
837
|
+
danger: {
|
|
838
|
+
// Locally defined function
|
|
839
|
+
color: customFunction('red', 'blue'),
|
|
840
|
+
backgroundColor: 'red',
|
|
841
|
+
},
|
|
842
|
+
});
|
|
843
|
+
```
|
|
844
|
+
|
|
845
|
+
```tsx
|
|
846
|
+
import React from 'react';
|
|
847
|
+
import { cssMap } from '@compiled/react';
|
|
848
|
+
|
|
849
|
+
// Spread elements ("...") cannot be used in cssMap.
|
|
850
|
+
|
|
851
|
+
const base = {
|
|
852
|
+
success: {
|
|
853
|
+
color: 'green',
|
|
854
|
+
},
|
|
855
|
+
};
|
|
856
|
+
|
|
857
|
+
const bar = cssMap({
|
|
858
|
+
...base,
|
|
859
|
+
danger: {
|
|
860
|
+
color: 'red',
|
|
861
|
+
},
|
|
862
|
+
});
|
|
863
|
+
```
|
|
864
|
+
|
|
865
|
+
#### Correct
|
|
866
|
+
|
|
867
|
+
```tsx
|
|
868
|
+
import React from 'react';
|
|
869
|
+
import { cssMap } from '@compiled/react';
|
|
870
|
+
|
|
871
|
+
// Literals (strings, numbers, etc.) are used as values
|
|
872
|
+
// in cssMap.
|
|
873
|
+
|
|
874
|
+
const styles = cssMap({
|
|
875
|
+
danger: {
|
|
876
|
+
color: 'red',
|
|
877
|
+
backgroundColor: 'red',
|
|
878
|
+
},
|
|
879
|
+
success: {
|
|
880
|
+
color: 'green',
|
|
881
|
+
backgroundColor: 'green',
|
|
882
|
+
},
|
|
883
|
+
});
|
|
884
|
+
```
|
|
885
|
+
|
|
886
|
+
```tsx
|
|
887
|
+
import React from 'react';
|
|
888
|
+
import { cssMap } from '@compiled/react';
|
|
889
|
+
|
|
890
|
+
// A statically evaluable variable (known at build time)
|
|
891
|
+
// is used here.
|
|
892
|
+
|
|
893
|
+
const bap = 'blue';
|
|
894
|
+
|
|
895
|
+
const styles = cssMap({
|
|
896
|
+
danger: {
|
|
897
|
+
color: bap,
|
|
898
|
+
},
|
|
899
|
+
});
|
|
900
|
+
```
|
|
901
|
+
|
|
902
|
+
#### Options
|
|
903
|
+
|
|
904
|
+
##### `allowedFunctionCalls`: [string, string][]
|
|
905
|
+
|
|
906
|
+
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:
|
|
907
|
+
|
|
908
|
+
```tsx
|
|
909
|
+
import React from 'react';
|
|
910
|
+
import { cssMap } from '@compiled/react';
|
|
911
|
+
import { token } from '@atlaskit/tokens';
|
|
912
|
+
|
|
913
|
+
const styles = cssMap({
|
|
914
|
+
danger: {
|
|
915
|
+
color: token('my-color'),
|
|
916
|
+
backgroundColor: 'red',
|
|
917
|
+
},
|
|
918
|
+
success: {
|
|
919
|
+
color: 'green',
|
|
920
|
+
},
|
|
921
|
+
});
|
|
922
|
+
```
|
|
923
|
+
|
|
924
|
+
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.
|
|
925
|
+
|
|
926
|
+
For example, with the below configuration, the above code example would be okay.
|
|
927
|
+
|
|
928
|
+
```tsx
|
|
929
|
+
// .eslintrc.js
|
|
930
|
+
|
|
931
|
+
// ...
|
|
932
|
+
rules: {
|
|
933
|
+
'@atlaskit/eslint-plugin-design-system/no-invalid-css-map': [
|
|
934
|
+
'error',
|
|
935
|
+
{
|
|
936
|
+
allowedFunctionCalls: [
|
|
937
|
+
['@atlaskit/tokens', 'token'],
|
|
938
|
+
]
|
|
939
|
+
},
|
|
940
|
+
],
|
|
941
|
+
// ...
|
|
942
|
+
},
|
|
943
|
+
// ...
|
|
944
|
+
```
|
|
945
|
+
|
|
946
|
+
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`.
|
|
947
|
+
|
|
586
948
|
## no-margin
|
|
587
949
|
|
|
588
950
|
Using margins to define spacing results in components that can't be readily reused in other contexts breaking the composition model.
|
|
@@ -54,12 +54,19 @@ var ASTObjectExpression = exports.Object = {
|
|
|
54
54
|
return [fixer.remove(entry)];
|
|
55
55
|
},
|
|
56
56
|
/**
|
|
57
|
-
* Returns
|
|
57
|
+
* Returns only the property @type {Property['key']} like: `padding` from: `{ padding: '8px' }`.
|
|
58
|
+
* If you want the key/value pair, use `getEntryByPropertyName`.
|
|
58
59
|
*/
|
|
59
60
|
getProperty: function getProperty(node, name) {
|
|
60
61
|
var _ASTObjectExpression$;
|
|
61
62
|
return (_ASTObjectExpression$ = ASTObjectExpression.getEntryByPropertyName(node, name)) === null || _ASTObjectExpression$ === void 0 ? void 0 : _ASTObjectExpression$.key;
|
|
62
63
|
},
|
|
64
|
+
/**
|
|
65
|
+
* Gets the array of key/value pairs in an ObjectExpression.
|
|
66
|
+
*/
|
|
67
|
+
getEntries: function getEntries(node) {
|
|
68
|
+
return node.properties;
|
|
69
|
+
},
|
|
63
70
|
/**
|
|
64
71
|
* Returns a only the property @type {Property['value']} like: `'8px` from: `{ padding: '8px' }`.
|
|
65
72
|
*
|
|
@@ -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',
|
|
@@ -15,6 +15,10 @@ var _noCssTaggedTemplateExpression = _interopRequireDefault(require("./no-css-ta
|
|
|
15
15
|
var _noDeprecatedApis = _interopRequireDefault(require("./no-deprecated-apis"));
|
|
16
16
|
var _noDeprecatedDesignTokenUsage = _interopRequireDefault(require("./no-deprecated-design-token-usage"));
|
|
17
17
|
var _noDeprecatedImports = _interopRequireDefault(require("./no-deprecated-imports"));
|
|
18
|
+
var _noEmptyStyledExpression = _interopRequireDefault(require("./no-empty-styled-expression"));
|
|
19
|
+
var _noExportedCss = _interopRequireDefault(require("./no-exported-css"));
|
|
20
|
+
var _noExportedKeyframes = _interopRequireDefault(require("./no-exported-keyframes"));
|
|
21
|
+
var _noInvalidCssMap = _interopRequireDefault(require("./no-invalid-css-map"));
|
|
18
22
|
var _noMargin = _interopRequireDefault(require("./no-margin"));
|
|
19
23
|
var _noNestedStyles = _interopRequireDefault(require("./no-nested-styles"));
|
|
20
24
|
var _noPhysicalProperties = _interopRequireDefault(require("./no-physical-properties"));
|
|
@@ -30,7 +34,7 @@ var _usePrimitives = _interopRequireDefault(require("./use-primitives"));
|
|
|
30
34
|
var _useVisuallyHidden = _interopRequireDefault(require("./use-visually-hidden"));
|
|
31
35
|
/**
|
|
32
36
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
33
|
-
* @codegen <<SignedSource::
|
|
37
|
+
* @codegen <<SignedSource::0a2d88c9772eb438048415f13550f592>>
|
|
34
38
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
|
|
35
39
|
*/
|
|
36
40
|
var _default = exports.default = {
|
|
@@ -44,6 +48,10 @@ var _default = exports.default = {
|
|
|
44
48
|
'no-deprecated-apis': _noDeprecatedApis.default,
|
|
45
49
|
'no-deprecated-design-token-usage': _noDeprecatedDesignTokenUsage.default,
|
|
46
50
|
'no-deprecated-imports': _noDeprecatedImports.default,
|
|
51
|
+
'no-empty-styled-expression': _noEmptyStyledExpression.default,
|
|
52
|
+
'no-exported-css': _noExportedCss.default,
|
|
53
|
+
'no-exported-keyframes': _noExportedKeyframes.default,
|
|
54
|
+
'no-invalid-css-map': _noInvalidCssMap.default,
|
|
47
55
|
'no-margin': _noMargin.default,
|
|
48
56
|
'no-nested-styles': _noNestedStyles.default,
|
|
49
57
|
'no-physical-properties': _noPhysicalProperties.default,
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = void 0;
|
|
8
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
9
|
+
var _createRule = require("../utils/create-rule");
|
|
10
|
+
var _isSupportedImport = require("../utils/is-supported-import");
|
|
11
|
+
var isEmptyStyledExpression = function isEmptyStyledExpression(node) {
|
|
12
|
+
var _node$arguments = (0, _slicedToArray2.default)(node.arguments, 1),
|
|
13
|
+
firstArg = _node$arguments[0];
|
|
14
|
+
if (node.arguments.length === 0) {
|
|
15
|
+
return true;
|
|
16
|
+
} else if (node.arguments.length === 1 && (firstArg === null || firstArg === void 0 ? void 0 : firstArg.type) === 'ArrayExpression') {
|
|
17
|
+
return firstArg.elements.length === 0;
|
|
18
|
+
} else if (node.arguments.length === 1 && (firstArg === null || firstArg === void 0 ? void 0 : firstArg.type) === 'ObjectExpression') {
|
|
19
|
+
return firstArg.properties.length === 0;
|
|
20
|
+
}
|
|
21
|
+
return false;
|
|
22
|
+
};
|
|
23
|
+
var createNoEmptyStyledExpressionRule = function createNoEmptyStyledExpressionRule(isEmptyStyledExpression, messageId) {
|
|
24
|
+
return function (context) {
|
|
25
|
+
var importSources = (0, _isSupportedImport.getImportSources)(context);
|
|
26
|
+
return {
|
|
27
|
+
'CallExpression[callee.type="MemberExpression"]': function CallExpressionCalleeTypeMemberExpression(node) {
|
|
28
|
+
var _context$getScope = context.getScope(),
|
|
29
|
+
references = _context$getScope.references;
|
|
30
|
+
|
|
31
|
+
// If we have styled.div(...), make sure `callee` only refers to the
|
|
32
|
+
// `styled` part instead of the whole `styled.div` expression.
|
|
33
|
+
var callee = node.callee.type === 'MemberExpression' ? node.callee.object : node.callee;
|
|
34
|
+
if (!(0, _isSupportedImport.isStyled)(callee, references, importSources)) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
if (!isEmptyStyledExpression(node)) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
context.report({
|
|
41
|
+
messageId: messageId,
|
|
42
|
+
node: node
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
var noEmptyStyledExpressionRule = (0, _createRule.createLintRule)({
|
|
49
|
+
meta: {
|
|
50
|
+
name: 'no-empty-styled-expression',
|
|
51
|
+
docs: {
|
|
52
|
+
description: 'Forbids any styled expression to be used when passing empty arguments to styled.div() (or other JSX elements).',
|
|
53
|
+
recommended: true,
|
|
54
|
+
severity: 'warn'
|
|
55
|
+
},
|
|
56
|
+
messages: {
|
|
57
|
+
unexpected: 'Found an empty expression, or empty object argument passed to `styled` function call. This unnecessarily causes a major performance penalty - please use a plain JSX element or a React fragment instead (e.g. `<div>Hello</div>` or `<>Hello</>`).'
|
|
58
|
+
},
|
|
59
|
+
type: 'problem',
|
|
60
|
+
schema: [{
|
|
61
|
+
type: 'object',
|
|
62
|
+
properties: {
|
|
63
|
+
importSources: {
|
|
64
|
+
type: 'array',
|
|
65
|
+
items: [{
|
|
66
|
+
type: 'string'
|
|
67
|
+
}]
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
additionalProperties: false
|
|
71
|
+
}]
|
|
72
|
+
},
|
|
73
|
+
create: createNoEmptyStyledExpressionRule(isEmptyStyledExpression, 'unexpected')
|
|
74
|
+
});
|
|
75
|
+
var _default = exports.default = noEmptyStyledExpressionRule;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _main = require("../utils/create-no-exported-rule/main");
|
|
8
|
+
var _createRule = require("../utils/create-rule");
|
|
9
|
+
var _isSupportedImport = require("../utils/is-supported-import");
|
|
10
|
+
var noExportedCssRule = (0, _createRule.createLintRule)({
|
|
11
|
+
meta: {
|
|
12
|
+
name: 'no-exported-css',
|
|
13
|
+
type: 'problem',
|
|
14
|
+
docs: {
|
|
15
|
+
description: 'Forbid exporting `css` function calls. Exporting `css` function calls can result in unexpected behaviour at runtime, and is not statically analysable.',
|
|
16
|
+
recommended: true,
|
|
17
|
+
severity: 'warn'
|
|
18
|
+
},
|
|
19
|
+
messages: {
|
|
20
|
+
unexpected: "`css` can't be exported - this will cause unexpected behaviour at runtime. Instead, please move your `css(...)` code to the same file where these styles are being used."
|
|
21
|
+
},
|
|
22
|
+
schema: [{
|
|
23
|
+
type: 'object',
|
|
24
|
+
properties: {
|
|
25
|
+
importSources: {
|
|
26
|
+
type: 'array',
|
|
27
|
+
items: [{
|
|
28
|
+
type: 'string'
|
|
29
|
+
}]
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
additionalProperties: false
|
|
33
|
+
}]
|
|
34
|
+
},
|
|
35
|
+
create: (0, _main.createNoExportedRule)(_isSupportedImport.isCss, 'unexpected')
|
|
36
|
+
});
|
|
37
|
+
var _default = exports.default = noExportedCssRule;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _main = require("../utils/create-no-exported-rule/main");
|
|
8
|
+
var _createRule = require("../utils/create-rule");
|
|
9
|
+
var _isSupportedImport = require("../utils/is-supported-import");
|
|
10
|
+
var noExportedKeyframesRule = (0, _createRule.createLintRule)({
|
|
11
|
+
meta: {
|
|
12
|
+
name: 'no-exported-keyframes',
|
|
13
|
+
type: 'problem',
|
|
14
|
+
docs: {
|
|
15
|
+
description: 'Forbid exporting `keyframes` function calls. Exporting `css` function calls can result in unexpected behaviour at runtime, and is not statically analysable.',
|
|
16
|
+
recommended: true,
|
|
17
|
+
severity: 'warn'
|
|
18
|
+
},
|
|
19
|
+
messages: {
|
|
20
|
+
unexpected: "`keyframes` can't be exported - this will cause unexpected behaviour at runtime. Instead, please move your `keyframes(...)` code to the same file where these styles are being used."
|
|
21
|
+
},
|
|
22
|
+
schema: [{
|
|
23
|
+
type: 'object',
|
|
24
|
+
properties: {
|
|
25
|
+
importSources: {
|
|
26
|
+
type: 'array',
|
|
27
|
+
items: [{
|
|
28
|
+
type: 'string'
|
|
29
|
+
}]
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
additionalProperties: false
|
|
33
|
+
}]
|
|
34
|
+
},
|
|
35
|
+
create: (0, _main.createNoExportedRule)(_isSupportedImport.isKeyframes, 'unexpected')
|
|
36
|
+
});
|
|
37
|
+
var _default = exports.default = noExportedKeyframesRule;
|