@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.
- package/CHANGELOG.md +12 -0
- package/README.md +31 -29
- package/constellation/consistent-css-prop-usage/usage.mdx +193 -0
- package/constellation/ensure-design-token-usage/usage.mdx +72 -0
- package/constellation/ensure-design-token-usage-preview/usage.mdx +5 -0
- package/constellation/icon-label/usage.mdx +39 -0
- package/constellation/index/usage.mdx +31 -1508
- package/constellation/local-cx-xcss/usage.mdx +37 -0
- package/constellation/no-banned-imports/usage.mdx +17 -0
- package/constellation/no-css-tagged-template-expression/usage.mdx +66 -0
- package/constellation/no-deprecated-apis/usage.mdx +76 -0
- package/constellation/no-deprecated-design-token-usage/usage.mdx +27 -0
- package/constellation/no-deprecated-imports/usage.mdx +62 -0
- package/constellation/no-empty-styled-expression/usage.mdx +77 -0
- package/constellation/no-exported-css/usage.mdx +50 -0
- package/constellation/no-exported-keyframes/usage.mdx +50 -0
- package/constellation/no-invalid-css-map/usage.mdx +199 -0
- package/constellation/no-keyframes-tagged-template-expression/usage.mdx +76 -0
- package/constellation/no-margin/usage.mdx +20 -0
- package/constellation/no-nested-styles/usage.mdx +47 -0
- package/constellation/no-physical-properties/usage.mdx +53 -0
- package/constellation/no-styled-tagged-template-expression/usage.mdx +90 -0
- package/constellation/no-unsafe-design-token-usage/usage.mdx +49 -0
- package/constellation/no-unsafe-style-overrides/usage.mdx +49 -0
- package/constellation/no-unsupported-drag-and-drop-libraries/usage.mdx +17 -0
- package/constellation/prefer-primitives/usage.mdx +31 -0
- package/constellation/use-button-group-label/usage.mdx +58 -0
- package/constellation/use-drawer-label/usage.mdx +53 -0
- package/constellation/use-heading-level-in-spotlight-card/usage.mdx +20 -0
- package/constellation/use-href-in-link-item/usage.mdx +18 -0
- package/constellation/use-primitives/usage.mdx +77 -0
- package/constellation/use-visually-hidden/usage.mdx +34 -0
- package/dist/cjs/presets/all.codegen.js +3 -1
- package/dist/cjs/rules/index.codegen.js +5 -1
- package/dist/cjs/rules/no-css-tagged-template-expression/index.js +3 -2
- package/dist/cjs/rules/no-keyframes-tagged-template-expression/index.js +27 -0
- package/dist/cjs/rules/no-styled-tagged-template-expression/index.js +27 -0
- package/dist/cjs/rules/no-styled-tagged-template-expression/is-styled.js +53 -0
- package/dist/cjs/rules/use-primitives/transformers/css-to-xcss.js +17 -3
- package/dist/cjs/rules/use-primitives/utils/is-valid-css-properties-to-transform.js +7 -0
- package/dist/cjs/rules/{no-css-tagged-template-expression → utils}/create-no-tagged-template-expression-rule/index.js +26 -6
- package/dist/cjs/rules/{no-css-tagged-template-expression → utils}/create-no-tagged-template-expression-rule/to-arguments.js +28 -2
- package/dist/cjs/rules/utils/create-rule.js +7 -5
- package/dist/cjs/rules/utils/is-supported-import.js +7 -10
- package/dist/es2019/presets/all.codegen.js +3 -1
- package/dist/es2019/rules/index.codegen.js +5 -1
- package/dist/es2019/rules/no-css-tagged-template-expression/index.js +3 -2
- package/dist/es2019/rules/no-keyframes-tagged-template-expression/index.js +21 -0
- package/dist/es2019/rules/no-styled-tagged-template-expression/index.js +21 -0
- package/dist/es2019/rules/no-styled-tagged-template-expression/is-styled.js +45 -0
- package/dist/es2019/rules/use-primitives/transformers/css-to-xcss.js +13 -1
- package/dist/es2019/rules/use-primitives/utils/is-valid-css-properties-to-transform.js +6 -1
- package/dist/es2019/rules/utils/create-no-tagged-template-expression-rule/index.js +84 -0
- package/dist/es2019/rules/{no-css-tagged-template-expression → utils}/create-no-tagged-template-expression-rule/to-arguments.js +28 -2
- package/dist/es2019/rules/utils/create-rule.js +7 -5
- package/dist/es2019/rules/utils/is-supported-import.js +7 -8
- package/dist/esm/presets/all.codegen.js +3 -1
- package/dist/esm/rules/index.codegen.js +5 -1
- package/dist/esm/rules/no-css-tagged-template-expression/index.js +3 -2
- package/dist/esm/rules/no-keyframes-tagged-template-expression/index.js +21 -0
- package/dist/esm/rules/no-styled-tagged-template-expression/index.js +21 -0
- package/dist/esm/rules/no-styled-tagged-template-expression/is-styled.js +47 -0
- package/dist/esm/rules/use-primitives/transformers/css-to-xcss.js +16 -2
- package/dist/esm/rules/use-primitives/utils/is-valid-css-properties-to-transform.js +8 -1
- package/dist/esm/rules/{no-css-tagged-template-expression → utils}/create-no-tagged-template-expression-rule/index.js +25 -5
- package/dist/esm/rules/{no-css-tagged-template-expression → utils}/create-no-tagged-template-expression-rule/to-arguments.js +28 -2
- package/dist/esm/rules/utils/create-rule.js +7 -5
- package/dist/esm/rules/utils/is-supported-import.js +7 -9
- package/dist/types/index.codegen.d.ts +2 -0
- package/dist/types/presets/all.codegen.d.ts +3 -1
- package/dist/types/rules/index.codegen.d.ts +2 -0
- package/dist/types/rules/no-keyframes-tagged-template-expression/index.d.ts +2 -0
- package/dist/types/rules/no-styled-tagged-template-expression/index.d.ts +2 -0
- package/dist/types/rules/no-styled-tagged-template-expression/is-styled.d.ts +7 -0
- package/dist/types/rules/use-primitives/config/index.d.ts +1 -1
- package/dist/types/rules/use-primitives/transformers/css-to-xcss.d.ts +6 -0
- package/dist/types/rules/{no-css-tagged-template-expression → utils}/create-no-tagged-template-expression-rule/index.d.ts +3 -1
- package/dist/types/rules/{no-css-tagged-template-expression → utils}/create-no-tagged-template-expression-rule/types.d.ts +3 -0
- package/dist/types/rules/utils/is-supported-import.d.ts +5 -5
- package/dist/types-ts4.5/index.codegen.d.ts +2 -0
- package/dist/types-ts4.5/presets/all.codegen.d.ts +3 -1
- package/dist/types-ts4.5/rules/index.codegen.d.ts +2 -0
- package/dist/types-ts4.5/rules/no-keyframes-tagged-template-expression/index.d.ts +2 -0
- package/dist/types-ts4.5/rules/no-styled-tagged-template-expression/index.d.ts +2 -0
- package/dist/types-ts4.5/rules/no-styled-tagged-template-expression/is-styled.d.ts +7 -0
- package/dist/types-ts4.5/rules/use-primitives/config/index.d.ts +1 -1
- package/dist/types-ts4.5/rules/use-primitives/transformers/css-to-xcss.d.ts +6 -0
- package/dist/types-ts4.5/rules/{no-css-tagged-template-expression → utils}/create-no-tagged-template-expression-rule/index.d.ts +3 -1
- package/dist/types-ts4.5/rules/{no-css-tagged-template-expression → utils}/create-no-tagged-template-expression-rule/types.d.ts +3 -0
- package/dist/types-ts4.5/rules/utils/is-supported-import.d.ts +5 -5
- package/package.json +1 -1
- package/dist/es2019/rules/no-css-tagged-template-expression/create-no-tagged-template-expression-rule/index.js +0 -62
- /package/dist/cjs/rules/{no-css-tagged-template-expression → utils}/create-no-tagged-template-expression-rule/generate.js +0 -0
- /package/dist/cjs/rules/{no-css-tagged-template-expression → utils}/create-no-tagged-template-expression-rule/get-tagged-template-expression-offset.js +0 -0
- /package/dist/cjs/rules/{no-css-tagged-template-expression → utils}/create-no-tagged-template-expression-rule/types.js +0 -0
- /package/dist/es2019/rules/{no-css-tagged-template-expression → utils}/create-no-tagged-template-expression-rule/generate.js +0 -0
- /package/dist/es2019/rules/{no-css-tagged-template-expression → utils}/create-no-tagged-template-expression-rule/get-tagged-template-expression-offset.js +0 -0
- /package/dist/es2019/rules/{no-css-tagged-template-expression → utils}/create-no-tagged-template-expression-rule/types.js +0 -0
- /package/dist/esm/rules/{no-css-tagged-template-expression → utils}/create-no-tagged-template-expression-rule/generate.js +0 -0
- /package/dist/esm/rules/{no-css-tagged-template-expression → utils}/create-no-tagged-template-expression-rule/get-tagged-template-expression-offset.js +0 -0
- /package/dist/esm/rules/{no-css-tagged-template-expression → utils}/create-no-tagged-template-expression-rule/types.js +0 -0
- /package/dist/types/rules/{no-css-tagged-template-expression → utils}/create-no-tagged-template-expression-rule/generate.d.ts +0 -0
- /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
- /package/dist/types/rules/{no-css-tagged-template-expression → utils}/create-no-tagged-template-expression-rule/to-arguments.d.ts +0 -0
- /package/dist/types-ts4.5/rules/{no-css-tagged-template-expression → utils}/create-no-tagged-template-expression-rule/generate.d.ts +0 -0
- /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
- /package/dist/types-ts4.5/rules/{no-css-tagged-template-expression → utils}/create-no-tagged-template-expression-rule/to-arguments.d.ts +0 -0
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# local-cx-xcss
|
|
2
|
+
|
|
3
|
+
This rule ensures the `cx()` function is only used within the `xcss` prop. This aids tracking what styles are applied to a jsx element.
|
|
4
|
+
|
|
5
|
+
The `cx` function is checked only if it is imported from `@compiled/react` or `@atlaskit/css`.
|
|
6
|
+
|
|
7
|
+
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.
|
|
8
|
+
|
|
9
|
+
## Examples
|
|
10
|
+
|
|
11
|
+
### Incorrect
|
|
12
|
+
|
|
13
|
+
```js
|
|
14
|
+
import { cx, cssMap } from '@compiled/react';
|
|
15
|
+
|
|
16
|
+
const styles = cssMap({
|
|
17
|
+
text: { color: 'red' },
|
|
18
|
+
bg: { background: 'blue' },
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
const joinedStyles = cx(styles.text, styles.bg);
|
|
22
|
+
|
|
23
|
+
<Button xcss={joinedStyles} />;
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### Correct
|
|
27
|
+
|
|
28
|
+
```js
|
|
29
|
+
import { cx, cssMap } from '@compiled/react';
|
|
30
|
+
|
|
31
|
+
const styles = cssMap({
|
|
32
|
+
text: { color: 'red' },
|
|
33
|
+
bg: { background: 'blue' },
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
<Button xcss={cx(styles.text, styles.bg)} />;
|
|
37
|
+
```
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# no-banned-imports
|
|
2
|
+
|
|
3
|
+
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.
|
|
4
|
+
|
|
5
|
+
## Examples
|
|
6
|
+
|
|
7
|
+
Anything that is considered private or experimental will be marked as violations.
|
|
8
|
+
|
|
9
|
+
### Incorrect
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
import noop from '@atlaskit/ds-lib/noop';
|
|
13
|
+
^^^^^^^^^^^^^^^^^^^^^
|
|
14
|
+
|
|
15
|
+
import { Text } from '@atlaskit/ds-explorations';
|
|
16
|
+
^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
17
|
+
```
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# no-css-tagged-template-expression
|
|
2
|
+
|
|
3
|
+
Disallows any `css` tagged template expressions that originate from `@emotion/react`, `@emotion/core`, `compiled/react` or `styled-components`.
|
|
4
|
+
|
|
5
|
+
Tagged template expressions cannot be type safe and are difficult to parse correctly. Will auto fix ` css`` ` to the preferred `css({})` call expression syntax.
|
|
6
|
+
|
|
7
|
+
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.
|
|
8
|
+
|
|
9
|
+
## Examples
|
|
10
|
+
|
|
11
|
+
### Incorrect
|
|
12
|
+
|
|
13
|
+
```js
|
|
14
|
+
import { css } from '@emotion/react';
|
|
15
|
+
|
|
16
|
+
css`
|
|
17
|
+
color: blue;
|
|
18
|
+
`;
|
|
19
|
+
|
|
20
|
+
const styles = css`
|
|
21
|
+
color: blue;
|
|
22
|
+
font-weight: 500;
|
|
23
|
+
`;
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### Correct
|
|
27
|
+
|
|
28
|
+
```js
|
|
29
|
+
import { css } from '@emotion/react';
|
|
30
|
+
|
|
31
|
+
css({ color: 'blue' });
|
|
32
|
+
|
|
33
|
+
const styles = css({
|
|
34
|
+
color: 'blue',
|
|
35
|
+
fontWeight: 500,
|
|
36
|
+
});
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Options
|
|
40
|
+
|
|
41
|
+
### importSources
|
|
42
|
+
|
|
43
|
+
By default, this rule will check `css` usages from:
|
|
44
|
+
|
|
45
|
+
- `@atlaskit/css`
|
|
46
|
+
- `@atlaskit/primitives`
|
|
47
|
+
- `@compiled/react`
|
|
48
|
+
- `@emotion/react`
|
|
49
|
+
- `@emotion/core`
|
|
50
|
+
- `@emotion/styled`
|
|
51
|
+
- `styled-components`
|
|
52
|
+
|
|
53
|
+
To change this list of libraries, you can define a custom set of `importSources`, which accepts an array of package names (strings).
|
|
54
|
+
|
|
55
|
+
```tsx
|
|
56
|
+
// [{ importSources: ['other-lib'] }]
|
|
57
|
+
|
|
58
|
+
import { css } from 'other-lib';
|
|
59
|
+
|
|
60
|
+
// Invalid!
|
|
61
|
+
export const styles = css``;
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Limitations
|
|
65
|
+
|
|
66
|
+
- Comments are not auto-fixable. You will need to manually convert usages containing functions.
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# no-deprecated-apis
|
|
2
|
+
|
|
3
|
+
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.
|
|
4
|
+
|
|
5
|
+
## Examples
|
|
6
|
+
|
|
7
|
+
Anything that can be used as props from Atlassian Design System components can be violations when marked as deprecated.
|
|
8
|
+
|
|
9
|
+
### Incorrect
|
|
10
|
+
|
|
11
|
+
```tsx
|
|
12
|
+
<ButtonItem cssFn={cssFn()} />
|
|
13
|
+
^^^^
|
|
14
|
+
|
|
15
|
+
<Drawer overrides={overrides} />
|
|
16
|
+
^^^^^^^^^
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Options
|
|
20
|
+
|
|
21
|
+
The rule can take one option: `deprecatedConfig`,
|
|
22
|
+
if not provided the rule will use an internal config.
|
|
23
|
+
If provided the rule will use the passed in config instead.
|
|
24
|
+
|
|
25
|
+
### deprecatedConfig
|
|
26
|
+
|
|
27
|
+
The following fields can be defined in the config:
|
|
28
|
+
|
|
29
|
+
- `deprecatedProp`, which is the deprecated props. Each prop has the following fields:
|
|
30
|
+
- `moduleSpecifier`, which is the module specifier of the package in which the prop was deprecated. For example: `@atlaskit/button`.
|
|
31
|
+
- `namedSpecifier` **(optional)**, which is an array of named specifiers of the package in which the prop was deprecated. For example: `Button`.
|
|
32
|
+
- `actionableVersion` **(optional)**, which is the version of the package in which the prop can be actioned on. For example: `1.0.0`.
|
|
33
|
+
|
|
34
|
+
```json
|
|
35
|
+
{
|
|
36
|
+
"cssFn": [
|
|
37
|
+
{
|
|
38
|
+
"moduleSpecifier": "@atlaskit/menu"
|
|
39
|
+
}
|
|
40
|
+
]
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
```js
|
|
45
|
+
import { configs } from '@atlaskit/eslint-plugin-design-system';
|
|
46
|
+
|
|
47
|
+
module.exports = {
|
|
48
|
+
rules: {
|
|
49
|
+
'@atlaskit/design-system/no-deprecated-api': [
|
|
50
|
+
'error',
|
|
51
|
+
{
|
|
52
|
+
deprecatedConfig: {
|
|
53
|
+
cssFn: [
|
|
54
|
+
{
|
|
55
|
+
moduleSpecifier: '@atlaskit/menu',
|
|
56
|
+
},
|
|
57
|
+
],
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
],
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
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.
|
|
66
|
+
|
|
67
|
+
```js
|
|
68
|
+
import { configs, filterActionableDeprecations } from '@atlaskit/eslint-plugin-design-system';
|
|
69
|
+
import packageJson from './package.json';
|
|
70
|
+
|
|
71
|
+
rules: {
|
|
72
|
+
'@atlaskit/design-system/no-deprecated-api': ['error', {
|
|
73
|
+
'deprecatedConfig': filterActionableDeprecations(configs.deprecatedConfig, packageJson),
|
|
74
|
+
}]
|
|
75
|
+
}
|
|
76
|
+
```
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# no-deprecated-design-token-usage
|
|
2
|
+
|
|
3
|
+
Using deprecated design tokens is dangerous as they will eventually be deleted after the sunset period.
|
|
4
|
+
This rule helps you move to non-deprecated design tokens.
|
|
5
|
+
|
|
6
|
+
## Examples
|
|
7
|
+
|
|
8
|
+
This rule will mark usage of deprecated design tokens as violations.
|
|
9
|
+
|
|
10
|
+
## Incorrect
|
|
11
|
+
|
|
12
|
+
```js
|
|
13
|
+
import { token } from '@atlaskit/tokens';
|
|
14
|
+
|
|
15
|
+
css({ color: token('i.am.deprecated') });
|
|
16
|
+
^^^^^^^^^^^^^^^
|
|
17
|
+
css({ color: token('i.am.a.token') });
|
|
18
|
+
^^^^^^^^^^^^^
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Options
|
|
22
|
+
|
|
23
|
+
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.
|
|
24
|
+
|
|
25
|
+
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.
|
|
26
|
+
|
|
27
|
+
Running `eslint --fix` will automatically apply replacement tokens if present.
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# no-deprecated-imports
|
|
2
|
+
|
|
3
|
+
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.
|
|
4
|
+
|
|
5
|
+
## Examples
|
|
6
|
+
|
|
7
|
+
This rule will mark usage of deprecated modules as violations.
|
|
8
|
+
|
|
9
|
+
### Incorrect
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
import Item from '@atlaskit/item';
|
|
13
|
+
^^^^^^^^^^^^^^
|
|
14
|
+
import GlobalNav from '@atlaskit/global-navigation';
|
|
15
|
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Options
|
|
19
|
+
|
|
20
|
+
The rule can take one option: `deprecatedConfig`,
|
|
21
|
+
if not provided the rule will use an internal config.
|
|
22
|
+
If provided the rule will use the passed in config instead.
|
|
23
|
+
|
|
24
|
+
### deprecatedConfig
|
|
25
|
+
|
|
26
|
+
The following fields can be defined in the config:
|
|
27
|
+
|
|
28
|
+
- `packagePath`, which is the name of the package. For example: `@atlaskit/navigation-next` and `@atlaskit/navigation`.
|
|
29
|
+
With the package path as the key, you can either provide the values as:
|
|
30
|
+
- `message` **(optional)**, the message to display when the deprecated packages path is used. For example: `multi-select is deprecated. Please use '@atlaskit/select' instead.`
|
|
31
|
+
Or as:
|
|
32
|
+
- `imports`, which is an array of named imports to be deprecated. Each named import has the following fields:
|
|
33
|
+
- `importName`, which is the name of the import to be deprecated. For example: `assistive` and `visuallyHidden`.
|
|
34
|
+
- `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.`.
|
|
35
|
+
|
|
36
|
+
```json
|
|
37
|
+
{
|
|
38
|
+
"@atlaskit/navigation-next": {
|
|
39
|
+
"message": "navigation-next is deprecated. Please use '@atlaskit/atlassian-navigation' instead."
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
```js
|
|
45
|
+
import packageJson from './package.json';
|
|
46
|
+
|
|
47
|
+
module.exports = {
|
|
48
|
+
rules: {
|
|
49
|
+
'@atlaskit/design-system/no-deprecated-imports': [
|
|
50
|
+
'error',
|
|
51
|
+
{
|
|
52
|
+
deprecatedConfig: {
|
|
53
|
+
'@atlaskit/navigation-next': {
|
|
54
|
+
message:
|
|
55
|
+
"navigation-next is deprecated. Please use '@atlaskit/atlassian-navigation' instead.",
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
],
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
```
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# no-empty-styled-expression
|
|
2
|
+
|
|
3
|
+
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.
|
|
4
|
+
|
|
5
|
+
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> </>`.
|
|
6
|
+
|
|
7
|
+
## Examples
|
|
8
|
+
|
|
9
|
+
### Incorrect
|
|
10
|
+
|
|
11
|
+
```tsx
|
|
12
|
+
const EmptyStyledExpression = styled.div();
|
|
13
|
+
|
|
14
|
+
const EmptyStyledExpressionArgument = styled.div({});
|
|
15
|
+
|
|
16
|
+
const EmptyStyledExpressionArgument = styled.div([]);
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
### Correct
|
|
20
|
+
|
|
21
|
+
```tsx
|
|
22
|
+
const Wrapper = styled.div({
|
|
23
|
+
backgroundColor: 'red',
|
|
24
|
+
MyComponent: {
|
|
25
|
+
backgroundColor: 'green',
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## What to do instead?
|
|
31
|
+
|
|
32
|
+
### Use elements directly
|
|
33
|
+
|
|
34
|
+
```diff
|
|
35
|
+
- const Wrapper = styled.div({});
|
|
36
|
+
|
|
37
|
+
function App() {
|
|
38
|
+
- return <Wrapper>hello world</Wrapper>;
|
|
39
|
+
+ return <div>hello world</div>;
|
|
40
|
+
}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### Use a React fragment
|
|
44
|
+
|
|
45
|
+
```diff
|
|
46
|
+
- const Wrapper = styled.div({});
|
|
47
|
+
|
|
48
|
+
function App() {
|
|
49
|
+
- return <Wrapper>hello world</Wrapper>;
|
|
50
|
+
+ return <>hello world</>;
|
|
51
|
+
}
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Options
|
|
55
|
+
|
|
56
|
+
### importSources
|
|
57
|
+
|
|
58
|
+
By default, this rule will check `styled` usages from:
|
|
59
|
+
|
|
60
|
+
- `@atlaskit/css`
|
|
61
|
+
- `@atlaskit/primitives`
|
|
62
|
+
- `@compiled/react`
|
|
63
|
+
- `@emotion/react`
|
|
64
|
+
- `@emotion/core`
|
|
65
|
+
- `@emotion/styled`
|
|
66
|
+
- `styled-components`
|
|
67
|
+
|
|
68
|
+
To change this list of libraries, you can define a custom set of `importSources`, which accepts an array of package names (strings).
|
|
69
|
+
|
|
70
|
+
```tsx
|
|
71
|
+
// [{ importSources: ['other-lib'] }]
|
|
72
|
+
|
|
73
|
+
import { styled } from 'other-lib';
|
|
74
|
+
|
|
75
|
+
// Invalid!
|
|
76
|
+
export const Component = styled.div({});
|
|
77
|
+
```
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# no-exported-css
|
|
2
|
+
|
|
3
|
+
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.
|
|
4
|
+
|
|
5
|
+
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.
|
|
6
|
+
|
|
7
|
+
## Examples
|
|
8
|
+
|
|
9
|
+
### Incorrect
|
|
10
|
+
|
|
11
|
+
```tsx
|
|
12
|
+
import { css } from '@compiled/react';
|
|
13
|
+
|
|
14
|
+
export const styles = css({});
|
|
15
|
+
|
|
16
|
+
export default css({});
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
### Correct
|
|
20
|
+
|
|
21
|
+
```tsx
|
|
22
|
+
import { css } from '@compiled/react';
|
|
23
|
+
|
|
24
|
+
const styles = css({});
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Options
|
|
28
|
+
|
|
29
|
+
### importSources
|
|
30
|
+
|
|
31
|
+
By default, this rule will check `css` usages from:
|
|
32
|
+
|
|
33
|
+
- `@atlaskit/css`
|
|
34
|
+
- `@atlaskit/primitives`
|
|
35
|
+
- `@compiled/react`
|
|
36
|
+
- `@emotion/react`
|
|
37
|
+
- `@emotion/core`
|
|
38
|
+
- `@emotion/styled`
|
|
39
|
+
- `styled-components`
|
|
40
|
+
|
|
41
|
+
To change this list of libraries, you can define a custom set of `importSources`, which accepts an array of package names (strings).
|
|
42
|
+
|
|
43
|
+
```tsx
|
|
44
|
+
// [{ importSources: ['other-lib'] }]
|
|
45
|
+
|
|
46
|
+
import { css } from 'other-lib';
|
|
47
|
+
|
|
48
|
+
// Invalid!
|
|
49
|
+
export const styles = css({});
|
|
50
|
+
```
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# no-exported-keyframes
|
|
2
|
+
|
|
3
|
+
Disallows `keyframes` export declarations that originate from `@compiled/react`, as well as any other CSS-in-JS library defined through the `importSources` option.
|
|
4
|
+
|
|
5
|
+
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.
|
|
6
|
+
|
|
7
|
+
## Examples
|
|
8
|
+
|
|
9
|
+
### Incorrect
|
|
10
|
+
|
|
11
|
+
```tsx
|
|
12
|
+
import { keyframes } from '@compiled/react';
|
|
13
|
+
|
|
14
|
+
export const animation = keyframes({});
|
|
15
|
+
|
|
16
|
+
export default keyframes({});
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
### Correct
|
|
20
|
+
|
|
21
|
+
```tsx
|
|
22
|
+
import { keyframes } from '@compiled/react';
|
|
23
|
+
|
|
24
|
+
const animation = keyframes({});
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Options
|
|
28
|
+
|
|
29
|
+
### importSources
|
|
30
|
+
|
|
31
|
+
By default, this rule will check `keyframes` usages from:
|
|
32
|
+
|
|
33
|
+
- `@atlaskit/css`
|
|
34
|
+
- `@atlaskit/primitives`
|
|
35
|
+
- `@compiled/react`
|
|
36
|
+
- `@emotion/react`
|
|
37
|
+
- `@emotion/core`
|
|
38
|
+
- `@emotion/styled`
|
|
39
|
+
- `styled-components`
|
|
40
|
+
|
|
41
|
+
To change this list of libraries, you can define a custom set of `importSources`, which accepts an array of package names (strings).
|
|
42
|
+
|
|
43
|
+
```tsx
|
|
44
|
+
// [{ importSources: ['other-lib'] }]
|
|
45
|
+
|
|
46
|
+
import { keyframes } from 'other-lib';
|
|
47
|
+
|
|
48
|
+
// Invalid!
|
|
49
|
+
export const animation = keyframes({});
|
|
50
|
+
```
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
# no-invalid-css-map
|
|
2
|
+
|
|
3
|
+
Ensure that all usages of the `cssMap` API are valid, and enforces the format of the object that is passed to `cssMap`.
|
|
4
|
+
|
|
5
|
+
Please refer to the [Compiled documentation](https://compiledcssinjs.com/docs/api-cssmap) for more details and some examples.
|
|
6
|
+
|
|
7
|
+
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`.
|
|
8
|
+
|
|
9
|
+
This is intended to be used in conjunction with type checking (through TypeScript).
|
|
10
|
+
|
|
11
|
+
## Examples
|
|
12
|
+
|
|
13
|
+
### Incorrect
|
|
14
|
+
|
|
15
|
+
```tsx
|
|
16
|
+
import React from 'react';
|
|
17
|
+
import { cssMap } from '@compiled/react';
|
|
18
|
+
|
|
19
|
+
// cssMap needs to be declared in the top-most scope.
|
|
20
|
+
// (not within a function, class, etc.)
|
|
21
|
+
|
|
22
|
+
const Foo = () => {
|
|
23
|
+
const bar = cssMap({
|
|
24
|
+
danger: {
|
|
25
|
+
color: 'red',
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
```tsx
|
|
32
|
+
import React from 'react';
|
|
33
|
+
import { cssMap } from '@compiled/react';
|
|
34
|
+
import { importedVariable, importedFunction } from 'another-package';
|
|
35
|
+
|
|
36
|
+
// Cannot use imported functions as values in cssMap.
|
|
37
|
+
|
|
38
|
+
const myVariable = importedFunction();
|
|
39
|
+
|
|
40
|
+
const styles = cssMap({
|
|
41
|
+
danger: {
|
|
42
|
+
// Both invalid because they rely on an imported function.
|
|
43
|
+
color: myVariable,
|
|
44
|
+
padding: importedFunction(),
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
```tsx
|
|
50
|
+
import React from 'react';
|
|
51
|
+
import { cssMap } from '@compiled/react';
|
|
52
|
+
|
|
53
|
+
// Cannot export usages of cssMap.
|
|
54
|
+
// Any usages of cssMap must be in the same file.
|
|
55
|
+
|
|
56
|
+
export const foo = cssMap({
|
|
57
|
+
danger: {
|
|
58
|
+
color: 'red',
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
```tsx
|
|
64
|
+
import React from 'react';
|
|
65
|
+
import { cssMap } from '@compiled/react';
|
|
66
|
+
import { token } from '@atlaskit/tokens';
|
|
67
|
+
|
|
68
|
+
// Functions and object methods are not allowed as
|
|
69
|
+
// values in cssMap.
|
|
70
|
+
|
|
71
|
+
const styles = cssMap({
|
|
72
|
+
// Object method
|
|
73
|
+
get danger() {
|
|
74
|
+
return { color: '#123456' };
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
const styles2 = cssMap({
|
|
79
|
+
// Arrow function
|
|
80
|
+
danger: () => {
|
|
81
|
+
color: '#123456';
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
function customFunction(...args) {
|
|
86
|
+
return arguments.join('');
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const styles3 = cssMap({
|
|
90
|
+
danger: {
|
|
91
|
+
// Locally defined function
|
|
92
|
+
color: customFunction('red', 'blue'),
|
|
93
|
+
backgroundColor: 'red',
|
|
94
|
+
},
|
|
95
|
+
});
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
```tsx
|
|
99
|
+
import React from 'react';
|
|
100
|
+
import { cssMap } from '@compiled/react';
|
|
101
|
+
|
|
102
|
+
// Spread elements ("...") cannot be used in cssMap.
|
|
103
|
+
|
|
104
|
+
const base = {
|
|
105
|
+
success: {
|
|
106
|
+
color: 'green',
|
|
107
|
+
},
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
const bar = cssMap({
|
|
111
|
+
...base,
|
|
112
|
+
danger: {
|
|
113
|
+
color: 'red',
|
|
114
|
+
},
|
|
115
|
+
});
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### Correct
|
|
119
|
+
|
|
120
|
+
```tsx
|
|
121
|
+
import React from 'react';
|
|
122
|
+
import { cssMap } from '@compiled/react';
|
|
123
|
+
|
|
124
|
+
// Literals (strings, numbers, etc.) are used as values
|
|
125
|
+
// in cssMap.
|
|
126
|
+
|
|
127
|
+
const styles = cssMap({
|
|
128
|
+
danger: {
|
|
129
|
+
color: 'red',
|
|
130
|
+
backgroundColor: 'red',
|
|
131
|
+
},
|
|
132
|
+
success: {
|
|
133
|
+
color: 'green',
|
|
134
|
+
backgroundColor: 'green',
|
|
135
|
+
},
|
|
136
|
+
});
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
```tsx
|
|
140
|
+
import React from 'react';
|
|
141
|
+
import { cssMap } from '@compiled/react';
|
|
142
|
+
|
|
143
|
+
// A statically evaluable variable (known at build time)
|
|
144
|
+
// is used here.
|
|
145
|
+
|
|
146
|
+
const bap = 'blue';
|
|
147
|
+
|
|
148
|
+
const styles = cssMap({
|
|
149
|
+
danger: {
|
|
150
|
+
color: bap,
|
|
151
|
+
},
|
|
152
|
+
});
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### Options
|
|
156
|
+
|
|
157
|
+
#### `allowedFunctionCalls`: [string, string][]
|
|
158
|
+
|
|
159
|
+
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:
|
|
160
|
+
|
|
161
|
+
```tsx
|
|
162
|
+
import React from 'react';
|
|
163
|
+
import { cssMap } from '@compiled/react';
|
|
164
|
+
import { token } from '@atlaskit/tokens';
|
|
165
|
+
|
|
166
|
+
const styles = cssMap({
|
|
167
|
+
danger: {
|
|
168
|
+
color: token('my-color'),
|
|
169
|
+
backgroundColor: 'red',
|
|
170
|
+
},
|
|
171
|
+
success: {
|
|
172
|
+
color: 'green',
|
|
173
|
+
},
|
|
174
|
+
});
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
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.
|
|
178
|
+
|
|
179
|
+
For example, with the below configuration, the above code example would be okay.
|
|
180
|
+
|
|
181
|
+
```tsx
|
|
182
|
+
// .eslintrc.js
|
|
183
|
+
|
|
184
|
+
// ...
|
|
185
|
+
rules: {
|
|
186
|
+
'@atlaskit/eslint-plugin-design-system/no-invalid-css-map': [
|
|
187
|
+
'error',
|
|
188
|
+
{
|
|
189
|
+
allowedFunctionCalls: [
|
|
190
|
+
['@atlaskit/tokens', 'token'],
|
|
191
|
+
]
|
|
192
|
+
},
|
|
193
|
+
],
|
|
194
|
+
// ...
|
|
195
|
+
},
|
|
196
|
+
// ...
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
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`.
|