@atlaskit/eslint-plugin-design-system 8.27.0 → 8.29.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.
Files changed (107) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +31 -29
  3. package/constellation/consistent-css-prop-usage/usage.mdx +193 -0
  4. package/constellation/ensure-design-token-usage/usage.mdx +72 -0
  5. package/constellation/ensure-design-token-usage-preview/usage.mdx +5 -0
  6. package/constellation/icon-label/usage.mdx +39 -0
  7. package/constellation/index/usage.mdx +31 -1508
  8. package/constellation/local-cx-xcss/usage.mdx +37 -0
  9. package/constellation/no-banned-imports/usage.mdx +17 -0
  10. package/constellation/no-css-tagged-template-expression/usage.mdx +66 -0
  11. package/constellation/no-deprecated-apis/usage.mdx +76 -0
  12. package/constellation/no-deprecated-design-token-usage/usage.mdx +27 -0
  13. package/constellation/no-deprecated-imports/usage.mdx +62 -0
  14. package/constellation/no-empty-styled-expression/usage.mdx +77 -0
  15. package/constellation/no-exported-css/usage.mdx +50 -0
  16. package/constellation/no-exported-keyframes/usage.mdx +50 -0
  17. package/constellation/no-invalid-css-map/usage.mdx +199 -0
  18. package/constellation/no-keyframes-tagged-template-expression/usage.mdx +76 -0
  19. package/constellation/no-margin/usage.mdx +20 -0
  20. package/constellation/no-nested-styles/usage.mdx +47 -0
  21. package/constellation/no-physical-properties/usage.mdx +53 -0
  22. package/constellation/no-styled-tagged-template-expression/usage.mdx +90 -0
  23. package/constellation/no-unsafe-design-token-usage/usage.mdx +49 -0
  24. package/constellation/no-unsafe-style-overrides/usage.mdx +49 -0
  25. package/constellation/no-unsupported-drag-and-drop-libraries/usage.mdx +17 -0
  26. package/constellation/prefer-primitives/usage.mdx +31 -0
  27. package/constellation/use-button-group-label/usage.mdx +58 -0
  28. package/constellation/use-drawer-label/usage.mdx +53 -0
  29. package/constellation/use-heading-level-in-spotlight-card/usage.mdx +20 -0
  30. package/constellation/use-href-in-link-item/usage.mdx +18 -0
  31. package/constellation/use-primitives/usage.mdx +77 -0
  32. package/constellation/use-visually-hidden/usage.mdx +34 -0
  33. package/dist/cjs/presets/all.codegen.js +3 -1
  34. package/dist/cjs/rules/index.codegen.js +5 -1
  35. package/dist/cjs/rules/no-css-tagged-template-expression/index.js +3 -2
  36. package/dist/cjs/rules/no-keyframes-tagged-template-expression/index.js +27 -0
  37. package/dist/cjs/rules/no-styled-tagged-template-expression/index.js +27 -0
  38. package/dist/cjs/rules/no-styled-tagged-template-expression/is-styled.js +53 -0
  39. package/dist/cjs/rules/use-primitives/transformers/css-to-xcss.js +17 -3
  40. package/dist/cjs/rules/use-primitives/utils/is-valid-css-properties-to-transform.js +7 -0
  41. package/dist/cjs/rules/{no-css-tagged-template-expression → utils}/create-no-tagged-template-expression-rule/index.js +26 -6
  42. package/dist/cjs/rules/{no-css-tagged-template-expression → utils}/create-no-tagged-template-expression-rule/to-arguments.js +28 -2
  43. package/dist/cjs/rules/utils/create-rule.js +7 -5
  44. package/dist/cjs/rules/utils/is-supported-import.js +7 -10
  45. package/dist/es2019/presets/all.codegen.js +3 -1
  46. package/dist/es2019/rules/index.codegen.js +5 -1
  47. package/dist/es2019/rules/no-css-tagged-template-expression/index.js +3 -2
  48. package/dist/es2019/rules/no-keyframes-tagged-template-expression/index.js +21 -0
  49. package/dist/es2019/rules/no-styled-tagged-template-expression/index.js +21 -0
  50. package/dist/es2019/rules/no-styled-tagged-template-expression/is-styled.js +45 -0
  51. package/dist/es2019/rules/use-primitives/transformers/css-to-xcss.js +13 -1
  52. package/dist/es2019/rules/use-primitives/utils/is-valid-css-properties-to-transform.js +6 -1
  53. package/dist/es2019/rules/utils/create-no-tagged-template-expression-rule/index.js +84 -0
  54. package/dist/es2019/rules/{no-css-tagged-template-expression → utils}/create-no-tagged-template-expression-rule/to-arguments.js +28 -2
  55. package/dist/es2019/rules/utils/create-rule.js +7 -5
  56. package/dist/es2019/rules/utils/is-supported-import.js +7 -8
  57. package/dist/esm/presets/all.codegen.js +3 -1
  58. package/dist/esm/rules/index.codegen.js +5 -1
  59. package/dist/esm/rules/no-css-tagged-template-expression/index.js +3 -2
  60. package/dist/esm/rules/no-keyframes-tagged-template-expression/index.js +21 -0
  61. package/dist/esm/rules/no-styled-tagged-template-expression/index.js +21 -0
  62. package/dist/esm/rules/no-styled-tagged-template-expression/is-styled.js +47 -0
  63. package/dist/esm/rules/use-primitives/transformers/css-to-xcss.js +16 -2
  64. package/dist/esm/rules/use-primitives/utils/is-valid-css-properties-to-transform.js +8 -1
  65. package/dist/esm/rules/{no-css-tagged-template-expression → utils}/create-no-tagged-template-expression-rule/index.js +25 -5
  66. package/dist/esm/rules/{no-css-tagged-template-expression → utils}/create-no-tagged-template-expression-rule/to-arguments.js +28 -2
  67. package/dist/esm/rules/utils/create-rule.js +7 -5
  68. package/dist/esm/rules/utils/is-supported-import.js +7 -9
  69. package/dist/types/index.codegen.d.ts +2 -0
  70. package/dist/types/presets/all.codegen.d.ts +3 -1
  71. package/dist/types/rules/index.codegen.d.ts +2 -0
  72. package/dist/types/rules/no-keyframes-tagged-template-expression/index.d.ts +2 -0
  73. package/dist/types/rules/no-styled-tagged-template-expression/index.d.ts +2 -0
  74. package/dist/types/rules/no-styled-tagged-template-expression/is-styled.d.ts +7 -0
  75. package/dist/types/rules/use-primitives/config/index.d.ts +1 -1
  76. package/dist/types/rules/use-primitives/transformers/css-to-xcss.d.ts +6 -0
  77. package/dist/types/rules/{no-css-tagged-template-expression → utils}/create-no-tagged-template-expression-rule/index.d.ts +3 -1
  78. package/dist/types/rules/{no-css-tagged-template-expression → utils}/create-no-tagged-template-expression-rule/types.d.ts +3 -0
  79. package/dist/types/rules/utils/is-supported-import.d.ts +5 -5
  80. package/dist/types-ts4.5/index.codegen.d.ts +2 -0
  81. package/dist/types-ts4.5/presets/all.codegen.d.ts +3 -1
  82. package/dist/types-ts4.5/rules/index.codegen.d.ts +2 -0
  83. package/dist/types-ts4.5/rules/no-keyframes-tagged-template-expression/index.d.ts +2 -0
  84. package/dist/types-ts4.5/rules/no-styled-tagged-template-expression/index.d.ts +2 -0
  85. package/dist/types-ts4.5/rules/no-styled-tagged-template-expression/is-styled.d.ts +7 -0
  86. package/dist/types-ts4.5/rules/use-primitives/config/index.d.ts +1 -1
  87. package/dist/types-ts4.5/rules/use-primitives/transformers/css-to-xcss.d.ts +6 -0
  88. package/dist/types-ts4.5/rules/{no-css-tagged-template-expression → utils}/create-no-tagged-template-expression-rule/index.d.ts +3 -1
  89. package/dist/types-ts4.5/rules/{no-css-tagged-template-expression → utils}/create-no-tagged-template-expression-rule/types.d.ts +3 -0
  90. package/dist/types-ts4.5/rules/utils/is-supported-import.d.ts +5 -5
  91. package/package.json +1 -1
  92. package/dist/es2019/rules/no-css-tagged-template-expression/create-no-tagged-template-expression-rule/index.js +0 -62
  93. /package/dist/cjs/rules/{no-css-tagged-template-expression → utils}/create-no-tagged-template-expression-rule/generate.js +0 -0
  94. /package/dist/cjs/rules/{no-css-tagged-template-expression → utils}/create-no-tagged-template-expression-rule/get-tagged-template-expression-offset.js +0 -0
  95. /package/dist/cjs/rules/{no-css-tagged-template-expression → utils}/create-no-tagged-template-expression-rule/types.js +0 -0
  96. /package/dist/es2019/rules/{no-css-tagged-template-expression → utils}/create-no-tagged-template-expression-rule/generate.js +0 -0
  97. /package/dist/es2019/rules/{no-css-tagged-template-expression → utils}/create-no-tagged-template-expression-rule/get-tagged-template-expression-offset.js +0 -0
  98. /package/dist/es2019/rules/{no-css-tagged-template-expression → utils}/create-no-tagged-template-expression-rule/types.js +0 -0
  99. /package/dist/esm/rules/{no-css-tagged-template-expression → utils}/create-no-tagged-template-expression-rule/generate.js +0 -0
  100. /package/dist/esm/rules/{no-css-tagged-template-expression → utils}/create-no-tagged-template-expression-rule/get-tagged-template-expression-offset.js +0 -0
  101. /package/dist/esm/rules/{no-css-tagged-template-expression → utils}/create-no-tagged-template-expression-rule/types.js +0 -0
  102. /package/dist/types/rules/{no-css-tagged-template-expression → utils}/create-no-tagged-template-expression-rule/generate.d.ts +0 -0
  103. /package/dist/types/rules/{no-css-tagged-template-expression → utils}/create-no-tagged-template-expression-rule/get-tagged-template-expression-offset.d.ts +0 -0
  104. /package/dist/types/rules/{no-css-tagged-template-expression → utils}/create-no-tagged-template-expression-rule/to-arguments.d.ts +0 -0
  105. /package/dist/types-ts4.5/rules/{no-css-tagged-template-expression → utils}/create-no-tagged-template-expression-rule/generate.d.ts +0 -0
  106. /package/dist/types-ts4.5/rules/{no-css-tagged-template-expression → utils}/create-no-tagged-template-expression-rule/get-tagged-template-expression-offset.d.ts +0 -0
  107. /package/dist/types-ts4.5/rules/{no-css-tagged-template-expression → utils}/create-no-tagged-template-expression-rule/to-arguments.d.ts +0 -0
@@ -2,8 +2,6 @@
2
2
  order: 0
3
3
  ---
4
4
 
5
- import SectionMessage from '@atlaskit/section-message';
6
-
7
5
  This plugin contains rules that should be used when working with the [Atlassian Design System](https://atlassian.design).
8
6
 
9
7
  ## Rules
@@ -11,1511 +9,36 @@ This plugin contains rules that should be used when working with the [Atlassian
11
9
  <!-- START_RULE_TABLE_CODEGEN -->
12
10
  <!-- @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen -->
13
11
 
14
- | Rule | Description | Recommended | Fixable | Suggestions |
15
- | -------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------- | ------- | ----------- |
16
- | <a href="#consistent-css-prop-usage">consistent-css-prop-usage</a> | Ensures consistency with `css` and `xcss` prop usages | Yes | Yes | |
17
- | <a href="#ensure-design-token-usage">ensure-design-token-usage</a> | Enforces usage of design tokens rather than hard-coded values. | Yes | Yes | Yes |
18
- | <a href="#ensure-design-token-usage-preview">ensure-design-token-usage/preview</a> | Enforces usage of pre-release design tokens rather than hard-coded values. | | Yes | Yes |
19
- | <a href="#icon-label">icon-label</a> | Enforces accessible usage of icon labels when composed with Atlassian Design System components. | Yes | Yes | |
20
- | <a href="#local-cx-xcss">local-cx-xcss</a> | Ensures the cx() function, which is part of the XCSS API, is only used within the xcss prop. This aids tracking what styles are applied to a jsx element. | Yes | | |
21
- | <a href="#no-banned-imports">no-banned-imports</a> | Disallow importing banned modules. | Yes | | |
22
- | <a href="#no-css-tagged-template-expression">no-css-tagged-template-expression</a> | Disallows any `css` tagged template expressions that originate from Emotion, Styled Components or Compiled | | Yes | |
23
- | <a href="#no-deprecated-apis">no-deprecated-apis</a> | Disallow using deprecated APIs. | Yes | | |
24
- | <a href="#no-deprecated-design-token-usage">no-deprecated-design-token-usage</a> | Disallow using deprecated design tokens. | Yes | Yes | |
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 | | |
30
- | <a href="#no-margin">no-margin</a> | Disallow using the margin CSS property. | | | |
31
- | <a href="#no-nested-styles">no-nested-styles</a> | Disallows use of nested styles in `css` functions. | Yes | | |
32
- | <a href="#no-physical-properties">no-physical-properties</a> | Disallow physical properties and values in `css` function calls. | | Yes | |
33
- | <a href="#no-unsafe-design-token-usage">no-unsafe-design-token-usage</a> | Enforces design token usage is statically and locally analyzable. | Yes | Yes | |
34
- | <a href="#no-unsafe-style-overrides">no-unsafe-style-overrides</a> | Discourage usage of unsafe style overrides used against the Atlassian Design System. | Yes | | |
35
- | <a href="#no-unsupported-drag-and-drop-libraries">no-unsupported-drag-and-drop-libraries</a> | Disallow importing unsupported drag and drop modules. | Yes | | |
36
- | <a href="#prefer-primitives">prefer-primitives</a> | Increase awareness of primitive components via code hints. Strictly used for education purposes and discoverability. To enforce usage please refer to the `use-primitives` rule. | | | |
37
- | <a href="#use-button-group-label">use-button-group-label</a> | Ensures button groups are described to assistive technology by a direct label or by another element. | Yes | | Yes |
38
- | <a href="#use-drawer-label">use-drawer-label</a> | Encourages to provide accessible name for Atlassian Design System Drawer component. | Yes | | Yes |
39
- | <a href="#use-heading-level-in-spotlight-card">use-heading-level-in-spotlight-card</a> | Inform developers of eventual requirement of `headingLevel` prop in `SpotlightCard` component. The heading level should be the appropriate level according to the surrounding context. | Yes | Yes | |
40
- | <a href="#use-href-in-link-item">use-href-in-link-item</a> | Inform developers of eventual requirement of `href` prop in `LinkItem` component. Elements with a `link` role require an `href` attribute for users to properly navigate, particularly those using assistive technologies. If no valid `href` is required for your use case, consider using a `ButtonItem` instead. | Yes | Yes | Yes |
41
- | <a href="#use-primitives">use-primitives</a> | Encourage the usage of primitives components. | | Yes | Yes |
42
- | <a href="#use-visually-hidden">use-visually-hidden</a> | Enforce usage of the visually hidden component. | Yes | Yes | |
12
+ | Rule | Description | Recommended | Fixable | Suggestions |
13
+ | --------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------- | ------- | ----------- |
14
+ | <a href="consistent-css-prop-usage/usage">consistent-css-prop-usage</a> | Ensures consistency with `css` and `xcss` prop usages | Yes | Yes | |
15
+ | <a href="ensure-design-token-usage/usage">ensure-design-token-usage</a> | Enforces usage of design tokens rather than hard-coded values. | Yes | Yes | Yes |
16
+ | <a href="ensure-design-token-usage-preview/usage">ensure-design-token-usage/preview</a> | Enforces usage of pre-release design tokens rather than hard-coded values. | | Yes | Yes |
17
+ | <a href="icon-label/usage">icon-label</a> | Enforces accessible usage of icon labels when composed with Atlassian Design System components. | Yes | Yes | |
18
+ | <a href="local-cx-xcss/usage">local-cx-xcss</a> | Ensures the cx() function, which is part of the XCSS API, is only used within the xcss prop. This aids tracking what styles are applied to a jsx element. | Yes | | |
19
+ | <a href="no-banned-imports/usage">no-banned-imports</a> | Disallow importing banned modules. | Yes | | |
20
+ | <a href="no-css-tagged-template-expression/usage">no-css-tagged-template-expression</a> | Disallows any `css` tagged template expressions that originate from Emotion, Styled Components or Compiled | | Yes | |
21
+ | <a href="no-deprecated-apis/usage">no-deprecated-apis</a> | Disallow using deprecated APIs. | Yes | | |
22
+ | <a href="no-deprecated-design-token-usage/usage">no-deprecated-design-token-usage</a> | Disallow using deprecated design tokens. | Yes | Yes | |
23
+ | <a href="no-deprecated-imports/usage">no-deprecated-imports</a> | Disallow importing deprecated modules. | Yes | | |
24
+ | <a href="no-empty-styled-expression/usage">no-empty-styled-expression</a> | Forbids any styled expression to be used when passing empty arguments to styled.div() (or other JSX elements). | Yes | | |
25
+ | <a href="no-exported-css/usage">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 | | |
26
+ | <a href="no-exported-keyframes/usage">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 | | |
27
+ | <a href="no-invalid-css-map/usage">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 | | |
28
+ | <a href="no-keyframes-tagged-template-expression/usage">no-keyframes-tagged-template-expression</a> | Disallows any `keyframe` tagged template expressions that originate from Emotion, Styled Components or Compiled | | Yes | |
29
+ | <a href="no-margin/usage">no-margin</a> | Disallow using the margin CSS property. | | | |
30
+ | <a href="no-nested-styles/usage">no-nested-styles</a> | Disallows use of nested styles in `css` functions. | Yes | | |
31
+ | <a href="no-physical-properties/usage">no-physical-properties</a> | Disallow physical properties and values in `css` function calls. | | Yes | |
32
+ | <a href="no-styled-tagged-template-expression/usage">no-styled-tagged-template-expression</a> | Disallows any `styled` tagged template expressions that originate from Emotion, Styled Components or Compiled | | Yes | |
33
+ | <a href="no-unsafe-design-token-usage/usage">no-unsafe-design-token-usage</a> | Enforces design token usage is statically and locally analyzable. | Yes | Yes | |
34
+ | <a href="no-unsafe-style-overrides/usage">no-unsafe-style-overrides</a> | Discourage usage of unsafe style overrides used against the Atlassian Design System. | Yes | | |
35
+ | <a href="no-unsupported-drag-and-drop-libraries/usage">no-unsupported-drag-and-drop-libraries</a> | Disallow importing unsupported drag and drop modules. | Yes | | |
36
+ | <a href="prefer-primitives/usage">prefer-primitives</a> | Increase awareness of primitive components via code hints. Strictly used for education purposes and discoverability. To enforce usage please refer to the `use-primitives` rule. | | | |
37
+ | <a href="use-button-group-label/usage">use-button-group-label</a> | Ensures button groups are described to assistive technology by a direct label or by another element. | Yes | | Yes |
38
+ | <a href="use-drawer-label/usage">use-drawer-label</a> | Encourages to provide accessible name for Atlassian Design System Drawer component. | Yes | | Yes |
39
+ | <a href="use-heading-level-in-spotlight-card/usage">use-heading-level-in-spotlight-card</a> | Inform developers of eventual requirement of `headingLevel` prop in `SpotlightCard` component. The heading level should be the appropriate level according to the surrounding context. | Yes | Yes | |
40
+ | <a href="use-href-in-link-item/usage">use-href-in-link-item</a> | Inform developers of eventual requirement of `href` prop in `LinkItem` component. Elements with a `link` role require an `href` attribute for users to properly navigate, particularly those using assistive technologies. If no valid `href` is required for your use case, consider using a `ButtonItem` instead. | Yes | Yes | Yes |
41
+ | <a href="use-primitives/usage">use-primitives</a> | Encourage the usage of primitives components. | | Yes | Yes |
42
+ | <a href="use-visually-hidden/usage">use-visually-hidden</a> | Enforce usage of the visually hidden component. | Yes | Yes | |
43
43
 
44
44
  <!-- END_RULE_TABLE_CODEGEN -->
45
-
46
- <!-- START_RULE_CONTENT_CODEGEN -->
47
- <!-- @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen -->
48
-
49
- ## consistent-css-prop-usage
50
-
51
- > Ensures consistency with CSS prop usage.
52
-
53
- <h3>Rationale</h3>
54
-
55
- Every product should be defining styles in the same way, using the same tools, enforced by the same linting rules, which we can then all evolve and scale together.
56
-
57
- <h3>How the rule works</h3>
58
-
59
- This rule checks for the following cases:
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.
70
-
71
- All the above can also work for custom `css` functions, such as `xcss` (https://atlassian.design/components/primitives/xcss/).
72
-
73
- This rule has several options - see below.
74
-
75
- <h3>Examples</h3>
76
-
77
- 👎 Example of **incorrect** code for this rule:
78
-
79
- **Calling a css/xcss function or direct objects inside the JSX attribute.**
80
-
81
- ```js
82
- function Button({ children }) {
83
- return <div css={css({...})}>{children}</div>;
84
- ^^^^^^^ css function call used inline (performance issue)
85
- }
86
- ```
87
-
88
- **Inserting a non css-function based object identifier into a css JSX attribute.**
89
-
90
- ```js
91
- const container = {
92
- ^^^^^^^^^ should be a css function call
93
- zIndex: 10,
94
- };
95
-
96
- function Button({ children }) {
97
- return <button css={container}>{children}</button>;
98
- }
99
- ```
100
-
101
- **Importing styles from another file.**
102
-
103
- ```js
104
- import { container } from './styles';
105
- ^^^^^^^^^ styles should be local, not shared
106
-
107
- function Button({ children }) {
108
- return <button css={container}>{children}</button>;
109
- }
110
- ```
111
-
112
- **Nesting styles with objects instead of arrays.**
113
-
114
- ```js
115
- const baseContainerStyles = css({
116
- zIndex: 5,
117
- });
118
-
119
- const containerStyles = css({
120
- ...baseContainerStyles,
121
- ^^^^^^^^^^^^^^^^^^^^^^ compose styles by providing an array to the css call instead (see example below)
122
- zIndex: 7,
123
- });
124
-
125
- function Button({ children }) {
126
- return <button css={containerStyles}>{children}</button>;
127
- }
128
- ```
129
-
130
- 👍 Example of **correct** code for this rule:
131
-
132
- **Using the css() function to create a style object that follows the naming convention (ends in Styles) and passing it as a variable into the css={...} JSX attribute.**
133
-
134
- With the following options turned on:
135
-
136
- - cssFunctions = ['css']
137
- - stylesPlacement = 'top'
138
-
139
- ```js
140
- const containerStyles = css({
141
- zIndex: 1,
142
- });
143
-
144
- function Button({ children }) {
145
- return <button css={containerStyles}>{children}</button>;
146
- }
147
- ```
148
-
149
- **Technically correct usage of the cssMap function.**
150
-
151
- With the following options turned on:
152
-
153
- - cssFunctions = ['css']
154
- - stylesPlacement = 'top'
155
-
156
- ```js
157
- const borderStyles = cssMap({
158
- 'solid': '1px solid';
159
- 'none': '0px';
160
- })
161
-
162
- function Button({ children }) {
163
- return <button css={borderStyles[solid]}>{children}</button>;
164
- }
165
- ```
166
-
167
- **Create composite styles with arrays, not objects.**
168
-
169
- With the following options turned on:
170
-
171
- - cssFunctions = ['css']
172
- - stylesPlacement = 'bottom'
173
-
174
- ```js
175
- function Button({ children }) {
176
- return (
177
- <button css={[baseContainerStyles, containerStyles]}>{children}</button>
178
- );
179
- }
180
-
181
- const baseContainerStyles = css({
182
- zIndex: 5,
183
- });
184
-
185
- const containerStyles = css({
186
- zIndex: 7,
187
- });
188
- ```
189
-
190
- **Ternaries can be used inline**
191
-
192
- ```js
193
- const baseStyles = css({ color: token('color.text.primary') });
194
- const disabledStyles = css({ color: token('color.text.disabled') });
195
-
196
- <div css={props.disabled ? disabledStyles : baseStyles}></div>;
197
- ```
198
-
199
- <h3>Options</h3>
200
-
201
- This rule comes with options to support different repository configurations.
202
-
203
- #### cssFunctions
204
-
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.
206
-
207
- #### stylesPlacement
208
-
209
- Either `top` or `bottom`.
210
-
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 (...)".
212
- Defaults to `top`.
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
-
243
- ## ensure-design-token-usage
244
-
245
- Using design tokens results in a harmonious experience for end users whilst providing theming and consistency.
246
- All experiences must use color tokens otherwise when switching between themes, unexpected incidents can occur where not all of the UI is themed.
247
- Space, typography, and shape tokens are strongly recommended to further align our experiences and make future changes easier.
248
-
249
- <h3>Examples</h3>
250
-
251
- Using anything other than design tokens such as hardcoded values or legacy theme colors will be considered violations.
252
-
253
- #### Incorrect
254
-
255
- ```js
256
- import { e100 } from '@atlaskit/theme/elevation';
257
- import { B100 } from '@atlaskit/theme/colors';
258
-
259
- css({ color: 'red' });
260
- ^^^
261
- css({ boxShadow: '0px 1px 1px #161A1D32' });
262
- ^^^^^^^^^
263
- css`${e100};`;
264
- ^^^^
265
- css({ color: B100 });
266
- ^^^^
267
- ```
268
-
269
- #### Correct
270
-
271
- ```js
272
- import { token } from '@atlaskit/tokens';
273
-
274
- css({ color: token('color.text.danger') });
275
-
276
- css({ boxShadow: token('elevation.shadow.card') });
277
- ```
278
-
279
- #### Incorrect
280
-
281
- ```js
282
- css({ padding: '16px' });
283
- ^^^
284
- css({ margin: gridSize() });
285
- ^^^^^^^^^^
286
- ```
287
-
288
- #### Correct
289
-
290
- ```js
291
- import { token } from '@atlaskit/tokens';
292
-
293
- css({ padding: token('space.100') });
294
- ```
295
-
296
- <h3>Options</h3>
297
-
298
- This rule comes with options to aid in migrating to design tokens.
299
-
300
- #### domains
301
-
302
- An array specifiying which token domains to lint against (`color`, `spacing`, `typography`, `shape`). Defaults to [`'color'`] if not provided.
303
-
304
- #### applyImport
305
-
306
- When `true`, the rule when automatically add imports to the `@atlaskit/tokens` package where tokens are auto-fixed. Defaults to `true` if not provided.
307
-
308
- #### shouldEnforceFallbacks
309
-
310
- When `true` the rule will add in stub fallbacks when choosing a suggestion in your IDE. Defaults to `false` if not provided.
311
-
312
- #### exceptions
313
-
314
- An array specifying strings to ingore when linting.
315
-
316
- ## ensure-design-token-usage/preview
317
-
318
- This rule is a clone of `ensure-design-token-usage` and is intended to allow you to set some domains to `warn` before they are set to `error` in the main rule.
319
-
320
- See `ensure-design-token-usage` for full usage documentation.
321
-
322
- ## icon-label
323
-
324
- Icon labels are used to describe what the icon is so the visually impaired can be described what the UI element is.
325
- There are cases where icons should have labels as well as cases where they shouldn't be labelled.
326
-
327
- <h3>Examples</h3>
328
-
329
- This rule will find violations for when an icon label is or isn't needed when composed with other Design System components.
330
-
331
- #### Incorrect
332
-
333
- ```js
334
- import ActivityIcon from '@atlaskit/icon/glyph/activity'
335
-
336
- <ActivityIcon>
337
- ^^^^^^^^^^^^^^ missing `label` prop
338
-
339
- <Button iconLeft={<ActivityIcon label="">} />
340
- ^^^^^ label should be defined
341
-
342
- <ButtonItem iconBefore={<ActivityIcon label="">}>
343
- ^^^^^ label should not be defined
344
- My activity
345
- </ButtonItem>
346
- ```
347
-
348
- #### Correct
349
-
350
- ```js
351
- import ActivityIcon from '@atlaskit/icon/glyph/activity'
352
-
353
- <ActivityIcon label="Activity">
354
-
355
- <Button iconLeft={<ActivityIcon label="Activity">} />
356
-
357
- <ButtonItem iconBefore={<ActivityIcon label="">}>
358
- My activity
359
- </ButtonItem>
360
- ```
361
-
362
- ## local-cx-xcss
363
-
364
- This rule ensures the `cx()` function is only used within the `xcss` prop. This aids tracking what styles are applied to a jsx element.
365
-
366
- The `cx` function is checked only if it is imported from `@compiled/react` or `@atlaskit/css`.
367
-
368
- Passing arguments to the `cx()` function is how you compose styles (combine more than one set of styles together) with XCSS. This is a workaround for the more conventional array syntax (e.g. [in Emotion](https://emotion.sh/docs/composition)) `<div xcss={[style1, style2]} />` not giving robust enough type checking.
369
-
370
- <h3>Examples</h3>
371
-
372
- #### Incorrect
373
-
374
- ```js
375
- import { cx, cssMap } from '@compiled/react';
376
-
377
- const styles = cssMap({
378
- text: { color: 'red' },
379
- bg: { background: 'blue' },
380
- });
381
-
382
- const joinedStyles = cx(styles.text, styles.bg);
383
-
384
- <Button xcss={joinedStyles} />;
385
- ```
386
-
387
- #### Correct
388
-
389
- ```js
390
- import { cx, cssMap } from '@compiled/react';
391
-
392
- const styles = cssMap({
393
- text: { color: 'red' },
394
- bg: { background: 'blue' },
395
- });
396
-
397
- <Button xcss={cx(styles.text, styles.bg)} />;
398
- ```
399
-
400
- ## no-banned-imports
401
-
402
- Using private or experimental packages is dangerous as they are not supported across major versions meaning you will not be able to migrate easily causing friction for yourself and the Atlassian Design System team.
403
-
404
- <h3>Examples</h3>
405
-
406
- Anything that is considered private or experimental will be marked as violations.
407
-
408
- #### Incorrect
409
-
410
- ```ts
411
- import noop from '@atlaskit/ds-lib/noop';
412
- ^^^^^^^^^^^^^^^^^^^^^
413
-
414
- import { Text } from '@atlaskit/ds-explorations';
415
- ^^^^^^^^^^^^^^^^^^^^^^^^^
416
- ```
417
-
418
- ## no-css-tagged-template-expression
419
-
420
- Disallows any `css` tagged template expressions that originate from `@emotion/react`, `@emotion/core`, `compiled/react` or `styled-components`.
421
-
422
- Tagged template expressions cannot be type safe and are difficult to parse correctly. Will auto fix ` css`` ` to the preferred `css({})` call expression syntax.
423
-
424
- Thank you to the [Compiled team for their rule](https://github.com/atlassian-labs/compiled/tree/master/packages/eslint-plugin/src/rules/no-css-tagged-template-expression) from which this was ported.
425
-
426
- <h3>Incorrect</h3>
427
-
428
- ```js
429
- import { css } from '@emotion/react';
430
-
431
- css`
432
- color: blue;
433
- `;
434
-
435
- const styles = css`
436
- color: blue;
437
- font-weight: 500;
438
- `;
439
- ```
440
-
441
- <h3>Correct</h3>
442
-
443
- ```js
444
- import { css } from '@emotion/react';
445
-
446
- css({ color: 'blue' });
447
-
448
- const styles = css({
449
- color: 'blue',
450
- fontWeight: 500,
451
- });
452
- ```
453
-
454
- <h3>Limitations</h3>
455
-
456
- - Comments are not auto-fixable. You will need to manually convert usages containing functions.
457
-
458
- ## no-deprecated-apis
459
-
460
- Props across the Atlassian Design System can be deprecated when they are deemed no-longer fit for purporse or dangerous and risk effective use at scale.
461
-
462
- <h3>Examples</h3>
463
-
464
- Anything that can be used as props from Atlassian Design System components can be violations when marked as deprecated.
465
-
466
- #### Incorrect
467
-
468
- ```tsx
469
- <ButtonItem cssFn={cssFn()} />
470
- ^^^^
471
-
472
- <Drawer overrides={overrides} />
473
- ^^^^^^^^^
474
- ```
475
-
476
- <h3>Options</h3>
477
-
478
- The rule can take one option: `deprecatedConfig`,
479
- if not provided the rule will use an internal config.
480
- If provided the rule will use the passed in config instead.
481
-
482
- #### deprecatedConfig
483
-
484
- The following fields can be defined in the config:
485
-
486
- - `deprecatedProp`, which is the deprecated props. Each prop has the following fields:
487
- - `moduleSpecifier`, which is the module specifier of the package in which the prop was deprecated. For example: `@atlaskit/button`.
488
- - `namedSpecifier` **(optional)**, which is an array of named specifiers of the package in which the prop was deprecated. For example: `Button`.
489
- - `actionableVersion` **(optional)**, which is the version of the package in which the prop can be actioned on. For example: `1.0.0`.
490
-
491
- ```json
492
- {
493
- "cssFn": [
494
- {
495
- "moduleSpecifier": "@atlaskit/menu"
496
- }
497
- ]
498
- }
499
- ```
500
-
501
- ```js
502
- import { configs } from '@atlaskit/eslint-plugin-design-system';
503
-
504
- module.exports = {
505
- rules: {
506
- '@atlaskit/design-system/no-deprecated-api': [
507
- 'error',
508
- {
509
- deprecatedConfig: {
510
- cssFn: [
511
- {
512
- moduleSpecifier: '@atlaskit/menu',
513
- },
514
- ],
515
- },
516
- },
517
- ],
518
- },
519
- };
520
- ```
521
-
522
- The plugin also provides a `filterActionableDeprecations` util function that accepts the `deprecated APIs config` and your root `package.json` as params and will filter the default deprecated APIs config based on the package versions installed.
523
-
524
- ```js
525
- import { configs, filterActionableDeprecations } from '@atlaskit/eslint-plugin-design-system';
526
- import packageJson from './package.json';
527
-
528
- rules: {
529
- '@atlaskit/design-system/no-deprecated-api': ['error', {
530
- 'deprecatedConfig': filterActionableDeprecations(configs.deprecatedConfig, packageJson),
531
- }]
532
- }
533
- ```
534
-
535
- ## no-deprecated-design-token-usage
536
-
537
- Using deprecated design tokens is dangerous as they will eventually be deleted after the sunset period.
538
- This rule helps you move to non-deprecated design tokens.
539
-
540
- <h3>Examples</h3>
541
-
542
- This rule will mark usage of deprecated design tokens as violations.
543
-
544
- <h3>Incorrect</h3>
545
-
546
- ```js
547
- import { token } from '@atlaskit/tokens';
548
-
549
- css({ color: token('i.am.deprecated') });
550
- ^^^^^^^^^^^^^^^
551
- css({ color: token('i.am.a.token') });
552
- ^^^^^^^^^^^^^
553
- ```
554
-
555
- <h3>Options</h3>
556
-
557
- It's recommended to set this rule to "warn" to allow for new and old tokens to exist side-by-side for the duration of the deprecation period and avoid big-bang migrations.
558
-
559
- Once the deprecation period is over for a design token it will be moved into `deleted` state at which point the counterpart of this rule `no-unsafe-design-token-usage` will mark violations as errors.
560
-
561
- Running `eslint --fix` will automatically apply replacement tokens if present.
562
-
563
- ## no-deprecated-imports
564
-
565
- Packages across the Atlassian Design System can be deprecated when they are deemed no-longer fit for purporse or dangerous and risk effective use at scale.
566
-
567
- <h3>Examples</h3>
568
-
569
- This rule will mark usage of deprecated modules as violations.
570
-
571
- #### Incorrect
572
-
573
- ```ts
574
- import Item from '@atlaskit/item';
575
- ^^^^^^^^^^^^^^
576
- import GlobalNav from '@atlaskit/global-navigation';
577
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
578
- ```
579
-
580
- <h3>Options</h3>
581
-
582
- The rule can take one option: `deprecatedConfig`,
583
- if not provided the rule will use an internal config.
584
- If provided the rule will use the passed in config instead.
585
-
586
- #### deprecatedConfig
587
-
588
- The following fields can be defined in the config:
589
-
590
- - `packagePath`, which is the name of the package. For example: `@atlaskit/navigation-next` and `@atlaskit/navigation`.
591
- With the package path as the key, you can either provide the values as:
592
- - `message` **(optional)**, the message to display when the deprecated packages path is used. For example: `multi-select is deprecated. Please use '@atlaskit/select' instead.`
593
- Or as:
594
- - `imports`, which is an array of named imports to be deprecated. Each named import has the following fields:
595
- - `importName`, which is the name of the import to be deprecated. For example: `assistive` and `visuallyHidden`.
596
- - `message` **(optional)**, which is the message to display when the deprecated import is used. For example: `The assistive mixin is deprecated. Please use `@atlaskit/visually-hidden` instead.`.
597
-
598
- ```json
599
- {
600
- "@atlaskit/navigation-next": {
601
- "message": "navigation-next is deprecated. Please use '@atlaskit/atlassian-navigation' instead."
602
- }
603
- }
604
- ```
605
-
606
- ```js
607
- import packageJson from './package.json';
608
-
609
- module.exports = {
610
- rules: {
611
- '@atlaskit/design-system/no-deprecated-imports': [
612
- 'error',
613
- {
614
- deprecatedConfig: {
615
- '@atlaskit/navigation-next': {
616
- message:
617
- "navigation-next is deprecated. Please use '@atlaskit/atlassian-navigation' instead.",
618
- },
619
- },
620
- },
621
- ],
622
- },
623
- };
624
- ```
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
-
982
- ## no-margin
983
-
984
- Using margins to define spacing results in components that can't be readily reused in other contexts breaking the composition model.
985
- Instead defining spacing in parents with flex and grid using the `gap` property will result in more resilient experiences.
986
-
987
- <h3>Examples</h3>
988
-
989
- This rule will mark all margin use as violations.
990
-
991
- #### Incorrect
992
-
993
- ```tsx
994
- css({ margin: '10px' });
995
- ```
996
-
997
- #### Correct
998
-
999
- ```tsx
1000
- css({ gap: token('spacing.100') });
1001
- ```
1002
-
1003
- ## no-nested-styles
1004
-
1005
- Disallows using nested styles. Nested styles can change unexpectedly when child markup changes and result in duplicates when extracting to CSS.
1006
-
1007
- <h3>Examples</h3>
1008
-
1009
- This rule checks for nested styles inside `css` objects.
1010
- This rule has no options.
1011
-
1012
- #### Incorrect
1013
-
1014
- ```js
1015
- css({
1016
- div: {
1017
- color: 'red',
1018
- },
1019
- });
1020
- ```
1021
-
1022
- ```js
1023
- css({
1024
- '@media (min-width: 480px)': {
1025
- color: 'red',
1026
- },
1027
- });
1028
- ```
1029
-
1030
- #### Correct
1031
-
1032
- ```js
1033
- css({
1034
- color: 'red',
1035
- ':hover': {
1036
- color: 'black',
1037
- },
1038
- });
1039
- ```
1040
-
1041
- ```js
1042
- import { media } from '@atlaskit/primitives';
1043
-
1044
- css({
1045
- [media.above.xs]: {
1046
- color: 'red',
1047
- },
1048
- });
1049
- ```
1050
-
1051
- ## no-physical-properties
1052
-
1053
- Disallows using physical properties. Physical properties
1054
- prevent correct support for different reading modes and languages and
1055
- should be avoided. Rule will autofix applicable physical properties
1056
- to instead use [logical properties](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_logical_properties_and_values/Basic_concepts_of_logical_properties_and_values).
1057
-
1058
- <h3>Examples</h3>
1059
-
1060
- This rule checks for physical property usage inside of `css` function calls.
1061
-
1062
- #### Incorrect
1063
-
1064
- ```js
1065
- css({
1066
- left: 0,
1067
- right: 0,
1068
- top: 0,
1069
- bottom: 0,
1070
- });
1071
- ```
1072
-
1073
- ```js
1074
- css({
1075
- marginLeft: 0,
1076
- });
1077
- ```
1078
-
1079
- ```js
1080
- css({
1081
- textAlign: 'left',
1082
- });
1083
- ```
1084
-
1085
- #### Correct
1086
-
1087
- ```js
1088
- css({
1089
- inset: 0,
1090
- });
1091
- ```
1092
-
1093
- ```js
1094
- css({
1095
- marginInlineStart: 0,
1096
- });
1097
- ```
1098
-
1099
- ```js
1100
- css({
1101
- textAlign: 'start',
1102
- });
1103
- ```
1104
-
1105
- ## no-unsafe-design-token-usage
1106
-
1107
- Using design tokens in an unsafe way risks the health of the system and will effect how fast your codebase can migrate between versions.
1108
-
1109
- <h3>Examples</h3>
1110
-
1111
- This rule will mark design token usage that is not statically and locally analyzable,
1112
- as well as design tokens that are considered deleted.
1113
-
1114
- <h3>Incorrect</h3>
1115
-
1116
- ```js
1117
- const textColor = 'red';
1118
-
1119
- css({ color: textColor });
1120
- ^^^^^^^^^ must be a string literal
1121
- ```
1122
-
1123
- ```js
1124
- css({ boxShadow: '0px 1px 1px var(--ds-accent-subtleBlue)' });
1125
- ^^^^^^^^^^^^^^^^^^^^^^^^^^ must use the token() function
1126
- ```
1127
-
1128
- <h3>Correct</h3>
1129
-
1130
- ```js
1131
- import { token } from '@atlaskit/tokens';
1132
-
1133
- css({ boxShadow: token('elevation.shadow.card') });
1134
-
1135
- css`
1136
- color: ${(token('color.text.highemphasis'), N20)};
1137
- `;
1138
- ```
1139
-
1140
- <h3>Options</h3>
1141
-
1142
- This rule comes with options to aid in migrating to design tokens.
1143
-
1144
- #### fallbackUsage
1145
-
1146
- - `forced`: Fallback values must always be provided
1147
- - `none`: Fallback values must never be provided. (Fixer will remove is provided)
1148
- - `optional`: Fallbacks are optional
1149
-
1150
- #### shouldEnforceFallbacks (deprecated)
1151
-
1152
- When `true` the rule will mark token function usage as violations when fallbacks aren't defined.
1153
- When `false` the rule will mark token function usage as violations when fallbacks are defined.
1154
-
1155
- ## no-unsafe-style-overrides
1156
-
1157
- Unsafe style overrides cause friction and incidents when internals of the component you're overriding change. They're inherently unbounded and everything is API that can change at a moments notice.
1158
-
1159
- Instead, lean on composition, primitive components, and safe style overrides via the `xcss` prop where component authors declare what styles they want to support.
1160
-
1161
- <h3>Examples</h3>
1162
-
1163
- #### Incorrect
1164
-
1165
- ```tsx
1166
- import Button from '@atlaskit/button';
1167
-
1168
- <Button css={{ fontWeight: 500 }}>foo</Button>;
1169
- ^^^
1170
- ```
1171
-
1172
- ```tsx
1173
- import { LinkItem } from '@atlaskit/menu';
1174
-
1175
- <LinkItem cssFn={() => ({ '> div > div': { padding: 2 } })} />;
1176
- ^^^^^
1177
- ```
1178
-
1179
- ```tsx
1180
- import { ButtonItem } from '@atlaskit/side-navigation';
1181
-
1182
- <ButtonItem className="text-neutral-400" />;
1183
- ^^^^^^^^^
1184
- ```
1185
-
1186
- #### Correct
1187
-
1188
- ```tsx
1189
- <Button>
1190
- <strong>foo</strong>
1191
- </Button>
1192
- ```
1193
-
1194
- ```tsx
1195
- const styles = css({ padding: 'var(--ds-space-100)' });
1196
-
1197
- <Box as="a" xcss={styles}>
1198
- <Stack>
1199
- <Inline />
1200
- <Inline />
1201
- </Stack>
1202
- </Box>;
1203
- ```
1204
-
1205
- ## no-unsupported-drag-and-drop-libraries
1206
-
1207
- We encourage the use of Pragmatic drag and drop to power all drag and drop experiences - from table to external files. Pragmatic drag and drop is a performance optimised drag and drop framework that has been designed to power any drag and drop experience on any tech stack. Please avoid using alternative drag and drop libraries as it will lead to poorer performance, increased maintenance costs, (likely) worse accessibility and fragmented user experiences. See https://staging.atlassian.design/components/pragmatic-drag-and-drop/
1208
-
1209
- <h3>Examples</h3>
1210
-
1211
- Libraries such as `react-beautiful-dnd` and `@atlassian/jira-dnd` that are no longer supported, as well as external libraries such as `react-dnd` and `react-sortable-hoc`.
1212
-
1213
- #### Incorrect
1214
-
1215
- ```ts
1216
- import { DraggableLocation } from 'react-beautiful-dnd';
1217
- ^^^^^^^^^^^^^^^^^^^
1218
-
1219
- import { useDrag } from 'react-dnd'
1220
- ^^^^^^^^^
1221
- ```
1222
-
1223
- ## prefer-primitives
1224
-
1225
- Using primitives allows you to delete bespoke component code and replace it with ready made solutions made by the Atlassian Design System Team.
1226
-
1227
- <h3>Examples</h3>
1228
-
1229
- This rule marks code as violations when it may be able to be replaced with a primitive component.
1230
-
1231
- #### Incorrect
1232
-
1233
- ```js
1234
- <div />
1235
- ^^^^^^^
1236
-
1237
- <Component>
1238
- <div css={someStyles}></div>
1239
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1240
- </Component>
1241
- ```
1242
-
1243
- #### Correct
1244
-
1245
- ```js
1246
- <Box />
1247
- ```
1248
-
1249
- ```js
1250
- <Component>
1251
- <Box xcss={someStyles}></Box>
1252
- </Component>
1253
- ```
1254
-
1255
- ## use-button-group-label
1256
-
1257
- ButtonGroup should have an accessible name or a reference to it, so that upon opening, users of assistive technologies could have contextual information of interaction with current element.
1258
-
1259
- <h3>Examples</h3>
1260
-
1261
- This rule will indicate user with warning to strongly recommend usage of either `label` or `titleId` prop.
1262
-
1263
- #### Incorrect
1264
-
1265
- ```tsx
1266
- <ButtonGroup>
1267
- ^^^^^^^^^^^ Missing either `label` or `titleId` prop.
1268
- <Button>Save</Button>
1269
- <Button>Edit</Button>
1270
- <Button>Delete</Button>
1271
- </ButtonGroup>
1272
-
1273
- <ButtonGroup label="">
1274
- ^^^^^ `label` prop is missing accessible name value.
1275
- <Button>Save</Button>
1276
- <Button>Edit</Button>
1277
- <Button>Delete</Button>
1278
- </ButtonGroup>
1279
-
1280
- <h2 id="button-group-title">ButtonGroup content title</hi>
1281
- <ButtonGroup titleId="">
1282
- ^^^^^^^ `titleId` prop is missing reference value.
1283
- <Button>Save</Button>
1284
- <Button>Edit</Button>
1285
- <Button>Delete</Button>
1286
- </ButtonGroup>
1287
-
1288
- <h2 id="button-group-title">ButtonGroup content title</h2>
1289
- <ButtonGroup titleId="button-group-title" label="">
1290
- ^^^^^^^ ^^^^^ Do not include both `titleId` and `label` properties. Use `titleId` if the label text is available in the DOM to reference it, otherwise use `label` to provide accessible name explicitly.
1291
- <Button>Save</Button>
1292
- <Button>Edit</Button>
1293
- <Button>Delete</Button>
1294
- </ButtonGroup>
1295
- ```
1296
-
1297
- #### Correct
1298
-
1299
- ```tsx
1300
- <ButtonGroup label="ButtonGroup content title">
1301
- <Button>Save</Button>
1302
- <Button>Edit</Button>
1303
- <Button>Delete</Button>
1304
- </ButtonGroup>
1305
-
1306
- <h2 id="button-group-title">ButtonGroup content title</h2>
1307
- <ButtonGroup titleId="button-group-title">
1308
- <Button>Save</Button>
1309
- <Button>Edit</Button>
1310
- <Button>Delete</Button>
1311
- </ButtonGroup>
1312
- ```
1313
-
1314
- ## use-drawer-label
1315
-
1316
- Drawer should have an accessible name or a reference to it, so that upon opening, users of assistive technologies could have contextual information of interaction with current element.
1317
-
1318
- <h3>Examples</h3>
1319
-
1320
- This rule will indicate user with warning to strongly recommend usage of either `label` or `titleId` prop.
1321
-
1322
- #### Incorrect
1323
-
1324
- ```tsx
1325
- <Drawer>
1326
- ^^^^^^ Missing either `label` or `titleId` prop.
1327
- Drawer content
1328
- </Drawer>
1329
-
1330
- <Drawer label>
1331
- ^^^^^ `label` prop is missing value.
1332
- Drawer content
1333
- </Drawer>
1334
-
1335
- <Drawer label="">
1336
- ^^^^^ `label` prop is missing accessible name value.
1337
- Drawer content
1338
- </Drawer>
1339
-
1340
- <Drawer titleId>
1341
- ^^^^^^^ `titleId` prop is missing reference value.
1342
- <h1 id="drawer-title">Drawer content title</hi>
1343
- </Drawer>
1344
-
1345
- <Drawer titleId="">
1346
- ^^^^^^^ `titleId` prop is missing reference value.
1347
- <h1 id="drawer-title">Drawer content title</hi>
1348
- </Drawer>
1349
-
1350
- <Drawer titleId="drawer-title" label="">
1351
- ^^^^^^^ ^^^^^ Do not include both `titleId` and `label` properties. Use `titleId` if the label text is available in the DOM to reference it, otherwise use `label` to provide accessible name explicitly.
1352
- <h1 id="drawer-title">Drawer content title</hi>
1353
- </Drawer>
1354
- ```
1355
-
1356
- #### Correct
1357
-
1358
- ```tsx
1359
- <Drawer label="Drawer content title">
1360
- Drawer content
1361
- </Drawer>
1362
-
1363
- <Drawer titleId="drawer-title">
1364
- <h1 id="drawer-title">Drawer content title</hi>
1365
- </Drawer>
1366
- ```
1367
-
1368
- ## use-heading-level-in-spotlight-card
1369
-
1370
- The `SpotlightCard` component in `@atlaskit/onboarding` will be requiring the `headingLevel` prop in future releases.
1371
-
1372
- <h3>Examples</h3>
1373
-
1374
- #### Incorrect
1375
-
1376
- ```tsx
1377
- <SpotlightCard heading="Heading">Spotlight card contents</SpotlightCard>
1378
- ^^^^^^^^^^^^^
1379
- ```
1380
-
1381
- #### Correct
1382
-
1383
- ```tsx
1384
- <SpotlightCard heading="Heading" headingLevel={2}>
1385
- Spotlight card contents
1386
- </SpotlightCard>
1387
- ```
1388
-
1389
- ## use-href-in-link-item
1390
-
1391
- The `LinkItem` component in `@atlaskit/menu` will be requiring the `href` prop in future releases. If no valid `href` prop is required, consider using the `ButtonItem` component.
1392
-
1393
- <h3>Examples</h3>
1394
-
1395
- #### Incorrect
1396
-
1397
- ```tsx
1398
- <LinkItem>Button</LinkItem>
1399
- ^^^^^^^^
1400
- ```
1401
-
1402
- #### Correct
1403
-
1404
- ```tsx
1405
- <LinkItem href="http://example.com">Link</LinkItem>
1406
- ```
1407
-
1408
- ## use-primitives
1409
-
1410
- Using primitives allows you to delete bespoke component code and replace it with ready made solutions made by the Atlassian Design System Team.
1411
-
1412
- <h3>Examples</h3>
1413
-
1414
- This rule marks code as violations when it can be replaced 1:1 with a primitive component.
1415
-
1416
- #### Incorrect
1417
-
1418
- ```jsx
1419
- const someStyles = css({
1420
- padding: '8px';
1421
- })
1422
-
1423
- <div css={someStyles}>
1424
- ^^^^^^^^^^^^^^^^^^^^^^
1425
- // ...
1426
- </div>
1427
- ```
1428
-
1429
- #### Correct
1430
-
1431
- ```jsx
1432
- const someStyles = xcss({
1433
- padding: 'space.100';
1434
- })
1435
-
1436
- <Box xcss={someStyles}>
1437
- // ...
1438
- </Box>
1439
- ```
1440
-
1441
- Currently, the rule is extremely defensive, only reporting on `css` styles that contain:
1442
-
1443
- - one, and only one, style property from this list:
1444
-
1445
- - padding
1446
- - paddingBlock
1447
- - paddingBlockEnd
1448
- - paddingBlockStart
1449
- - paddingBottom
1450
- - paddingInline
1451
- - paddingInlineEnd
1452
- - paddingInlineStart
1453
- - paddingLeft
1454
- - paddingRight
1455
- - paddingTop
1456
- - margin
1457
- - marginBlock
1458
- - marginBlockEnd
1459
- - marginBlockStart
1460
- - marginBottom
1461
- - marginInline
1462
- - marginInlineEnd
1463
- - marginInlineStart
1464
- - marginLeft
1465
- - marginRight
1466
- - marginTop
1467
-
1468
- - and where the style value is one of:
1469
- - 0px
1470
- - 2px
1471
- - 4px
1472
- - 6px
1473
- - 8px
1474
- - 12px
1475
- - 16px
1476
- - 20px
1477
- - 24px
1478
- - 32px
1479
- - 40px
1480
- - 48px
1481
- - 64px
1482
- - 80px
1483
-
1484
- If these conditions are not met, then no violation will be reported.
1485
-
1486
- ## use-visually-hidden
1487
-
1488
- Using the visually hidden component allows you to delete bespoke or legacy theme code and replace it with a ready made solution by the Atlassian Design System Team.
1489
-
1490
- <h3>Examples</h3>
1491
-
1492
- This rule marks code as violations when it can be replaced 1:1 with the visually hidden component.
1493
-
1494
- #### Incorrect
1495
-
1496
- ```js
1497
- import { css } from '@emotion/core';
1498
- import { visuallyHidden } from '@atlaskit/theme/constants';
1499
-
1500
- const visuallyHiddenStyles = css({
1501
- width: '1px',
1502
- height: '1px',
1503
- padding: '0',
1504
- position: 'absolute',
1505
- border: '0',
1506
- clip: 'rect(1px, 1px, 1px, 1px)',
1507
- overflow: 'hidden',
1508
- whiteSpace: 'nowrap',
1509
- });
1510
-
1511
- const VisuallyHidden = styled.span`${visuallyHidden()}`;
1512
- ^^^^^^^^^^^^^^
1513
- ```
1514
-
1515
- #### Correct
1516
-
1517
- ```js
1518
- import VisuallyHidden from '@atlaskit/visually-hidden';
1519
- ```
1520
-
1521
- <!-- END_RULE_CONTENT_CODEGEN -->