@atlaskit/eslint-plugin-ui-styling-standard 0.4.0 → 0.5.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 +1 -0
- package/constellation/consistent-css-prop-usage/usage.mdx +2 -2
- package/constellation/index/overview.mdx +9 -11
- package/constellation/no-css-tagged-template-expression/usage.mdx +2 -2
- package/constellation/no-empty-styled-expression/usage.mdx +2 -2
- package/constellation/no-exported-css/usage.mdx +2 -2
- package/constellation/no-exported-keyframes/usage.mdx +2 -2
- package/constellation/no-important-styles/usage.mdx +29 -0
- package/constellation/no-invalid-css-map/usage.mdx +2 -2
- package/constellation/no-js-xcss/usage.mdx +1 -19
- package/constellation/no-keyframes-tagged-template-expression/usage.mdx +2 -2
- package/constellation/no-styled-tagged-template-expression/usage.mdx +2 -2
- package/dist/cjs/presets/all.codegen.js +5 -2
- package/dist/cjs/presets/recommended.codegen.js +5 -2
- package/dist/cjs/rules/external-rules.js +27 -1
- package/dist/cjs/rules/index.codegen.js +4 -2
- package/dist/cjs/rules/no-important-styles/index.js +75 -0
- package/dist/cjs/rules/utils/is-supported-import.js +72 -20
- package/dist/es2019/presets/all.codegen.js +5 -2
- package/dist/es2019/presets/recommended.codegen.js +5 -2
- package/dist/es2019/rules/external-rules.js +27 -1
- package/dist/es2019/rules/index.codegen.js +4 -2
- package/dist/es2019/rules/no-important-styles/index.js +69 -0
- package/dist/es2019/rules/utils/is-supported-import.js +69 -18
- package/dist/esm/presets/all.codegen.js +5 -2
- package/dist/esm/presets/recommended.codegen.js +5 -2
- package/dist/esm/rules/external-rules.js +27 -1
- package/dist/esm/rules/index.codegen.js +4 -2
- package/dist/esm/rules/no-important-styles/index.js +68 -0
- package/dist/esm/rules/utils/is-supported-import.js +72 -18
- package/dist/types/index.codegen.d.ts +8 -2
- package/dist/types/presets/all.codegen.d.ts +5 -2
- package/dist/types/presets/recommended.codegen.d.ts +5 -2
- package/dist/types/rules/index.codegen.d.ts +1 -0
- package/dist/types/rules/no-important-styles/index.d.ts +2 -0
- package/dist/types/rules/utils/is-supported-import.d.ts +17 -5
- package/dist/types-ts4.5/index.codegen.d.ts +8 -2
- package/dist/types-ts4.5/presets/all.codegen.d.ts +5 -2
- package/dist/types-ts4.5/presets/recommended.codegen.d.ts +5 -2
- package/dist/types-ts4.5/rules/index.codegen.d.ts +1 -0
- package/dist/types-ts4.5/rules/no-important-styles/index.d.ts +2 -0
- package/dist/types-ts4.5/rules/utils/is-supported-import.d.ts +17 -5
- package/package.json +5 -3
- package/scripts/codegen.tsx +1 -1
- package/src/presets/all.codegen.tsx +14 -2
- package/src/presets/recommended.codegen.tsx +14 -2
- package/src/rules/external-rules.tsx +30 -0
- package/src/rules/index.codegen.tsx +3 -1
- package/src/rules/no-important-styles/README.md +27 -0
- package/src/rules/no-important-styles/__tests__/rule.test.tsx +140 -0
- package/src/rules/no-important-styles/index.tsx +88 -0
- package/src/rules/utils/is-supported-import.tsx +99 -20
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @atlaskit/eslint-plugin-ui-styling-standard
|
|
2
2
|
|
|
3
|
+
## 0.5.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#80523](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/80523) [`1fbc903e5b7b`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/1fbc903e5b7b) - Adds `no-important-styles` rule which prevents the use of `!important` flags in style declarations.
|
|
8
|
+
|
|
9
|
+
## 0.4.1
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [#76885](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/76885) [`06030bc18dd4`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/06030bc18dd4) - Disable `styled-components` handling for `no-styled-tagged-template-expression` rule, due to edge case where props are converted to output that fails typechecking.
|
|
14
|
+
|
|
3
15
|
## 0.4.0
|
|
4
16
|
|
|
5
17
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -14,6 +14,7 @@ Not intended for use outside the Atlassian frontend repository.
|
|
|
14
14
|
| Rule | Description | Recommended | Fixable | Suggestions |
|
|
15
15
|
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------- | ------- | ----------- |
|
|
16
16
|
| <a href="./src/rules/local-cx-xcss/README.md">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 | | |
|
|
17
|
+
| <a href="./src/rules/no-important-styles/README.md">no-important-styles</a> | Disallows important style declarations | Yes | | |
|
|
17
18
|
| <a href="https://atlassian.design/components/eslint-plugin-ui-styling-standard/consistent-css-prop-usage/usage">@atlaskit/design-system/consistent-css-prop-usage</a> | Ensures consistency with `css` and `xcss` prop usages | Yes | Yes | |
|
|
18
19
|
| <a href="https://atlassian.design/components/eslint-plugin-ui-styling-standard/no-css-tagged-template-expression/usage">@atlaskit/design-system/no-css-tagged-template-expression</a> | Disallows any `css` tagged template expressions that originate from Emotion, Styled Components or Compiled | Yes | Yes | |
|
|
19
20
|
| <a href="https://atlassian.design/components/eslint-plugin-ui-styling-standard/no-keyframes-tagged-template-expression/usage">@atlaskit/design-system/no-keyframes-tagged-template-expression</a> | Disallows any `keyframe` tagged template expressions that originate from Emotion, Styled Components or Compiled | Yes | Yes | |
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
# @atlaskit/design-system/consistent-css-prop-usage
|
|
2
2
|
|
|
3
|
-
Ensures consistency with `css` and `xcss` prop usages
|
|
3
|
+
Ensures consistency with all `css` and `xcss` prop usages.
|
|
4
4
|
|
|
5
|
-
This rule is maintained by another package and configured here
|
|
5
|
+
This rule is maintained by another package and configured here; refer to https://atlassian.design/components/eslint-plugin-design-system/consistent-css-prop-usage/usage for more details.
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
The UI Styling Standard is a set of ESLint rules and principles to guide building web styling code
|
|
1
|
+
The UI Styling Standard is a set of principles to guide styling UI code
|
|
4
2
|
across Atlassian's frontend codebases and ecosystem.
|
|
5
3
|
|
|
4
|
+
These are the current ESLint rules that enforce and help comply with the UI Styling Standard today,
|
|
5
|
+
but more are planned to support the standard over time.
|
|
6
|
+
|
|
6
7
|
## Rules
|
|
7
8
|
|
|
8
9
|
<!-- START_RULE_TABLE_CODEGEN -->
|
|
@@ -11,6 +12,7 @@ across Atlassian's frontend codebases and ecosystem.
|
|
|
11
12
|
| Rule | Description | Recommended | Fixable | Suggestions |
|
|
12
13
|
| --------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------- | ------- | ----------- |
|
|
13
14
|
| <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 | | |
|
|
15
|
+
| <a href="no-important-styles/usage">no-important-styles</a> | Disallows important style declarations | Yes | | |
|
|
14
16
|
| <a href="consistent-css-prop-usage/usage">@atlaskit/design-system/consistent-css-prop-usage</a> | Ensures consistency with `css` and `xcss` prop usages | Yes | Yes | |
|
|
15
17
|
| <a href="no-css-tagged-template-expression/usage">@atlaskit/design-system/no-css-tagged-template-expression</a> | Disallows any `css` tagged template expressions that originate from Emotion, Styled Components or Compiled | Yes | Yes | |
|
|
16
18
|
| <a href="no-keyframes-tagged-template-expression/usage">@atlaskit/design-system/no-keyframes-tagged-template-expression</a> | Disallows any `keyframe` tagged template expressions that originate from Emotion, Styled Components or Compiled | Yes | Yes | |
|
|
@@ -26,6 +28,8 @@ across Atlassian's frontend codebases and ecosystem.
|
|
|
26
28
|
|
|
27
29
|
## Purpose of the UI Styling Standard
|
|
28
30
|
|
|
31
|
+
For Atlassians, refer to the [internal UI Styling Standard policy](https://go.atlassian.com/ui-styling-standard-policy).
|
|
32
|
+
|
|
29
33
|
To enforce scoped encapsulation, type safety, and deterministic behavior in styling code that is
|
|
30
34
|
present in other programming languages. This is a stepping stone to large performance improvements,
|
|
31
35
|
reduced visual regressions, and enables testing and maintainability at scale.
|
|
@@ -41,7 +45,7 @@ code migrations, and future advancements like generative AI.
|
|
|
41
45
|
- To reduce the amount of overall custom styling code written while supporting customization without without the need for hacks and technical debt.
|
|
42
46
|
- We aim to see a reduction of the “average styles per component”, reducing the effort to build and maintain UIs.
|
|
43
47
|
|
|
44
|
-
## Basic
|
|
48
|
+
## Basic principles
|
|
45
49
|
|
|
46
50
|
We want the styling ecosystem (CSS, CSS-in-JS, and parts of JSX) at Atlassian and the wider ecosystem
|
|
47
51
|
we support to be as mature as the other code we write, such as TypeScript/JavaScript, Java, Go, etc.
|
|
@@ -58,15 +62,9 @@ we support to be as mature as the other code we write, such as TypeScript/JavaSc
|
|
|
58
62
|
As the W3C CSS spec and wider industry grows, having our styling code meet these principles will mean we
|
|
59
63
|
can programatically evolve that a better future state.
|
|
60
64
|
|
|
61
|
-
## How we'll achieve this
|
|
62
|
-
|
|
63
|
-
Within Atlassian, most frontend code will have this enforced over time through ESLint rules and engineering standardization.
|
|
64
|
-
|
|
65
|
-
Refer to the eslint rules for more details: _documentation coming soon_
|
|
66
|
-
|
|
67
65
|
## Examples
|
|
68
66
|
|
|
69
|
-
|
|
67
|
+
Refer to the [eslint rules](#rules) for more in-depth examples.
|
|
70
68
|
|
|
71
69
|
### Incorrect code
|
|
72
70
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
# @atlaskit/design-system/no-css-tagged-template-expression
|
|
2
2
|
|
|
3
|
-
Disallows any css tagged template expressions that originate from
|
|
3
|
+
Disallows any `css` tagged template expressions that originate from a CSS-in-JS library, including `@atlaskit/css`, `@compiled/react`, Emotion, and `styled-components`.
|
|
4
4
|
|
|
5
|
-
This rule is maintained by another package and configured here
|
|
5
|
+
This rule is maintained by another package and configured here; refer to https://atlassian.design/components/eslint-plugin-design-system/no-css-tagged-template-expression/usage for more details.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
# @atlaskit/design-system/no-empty-styled-expression
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Forbids any styled expression to be used when passing empty arguments to styled.div() (or other JSX elements).
|
|
4
4
|
|
|
5
|
-
This rule is maintained by another package and configured here
|
|
5
|
+
This rule is maintained by another package and configured here; refer to https://atlassian.design/components/eslint-plugin-design-system/no-empty-styled-expression/usage for more details.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
# @atlaskit/design-system/no-exported-css
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Forbid exporting `css` function calls. Exporting `css` function calls can result in unexpected behaviour at runtime, and is not statically analysable.
|
|
4
4
|
|
|
5
|
-
This rule is maintained by another package and configured here
|
|
5
|
+
This rule is maintained by another package and configured here; refer to https://atlassian.design/components/eslint-plugin-design-system/no-exported-css/usage for more details.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
# @atlaskit/design-system/no-exported-keyframes
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Forbid exporting `keyframes` function calls. Exporting `css` function calls can result in unexpected behaviour at runtime, and is not statically analysable.
|
|
4
4
|
|
|
5
|
-
This rule is maintained by another package and configured here
|
|
5
|
+
This rule is maintained by another package and configured here; refer to https://atlassian.design/components/eslint-plugin-design-system/no-exported-keyframes/usage for more details.
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# no-important-styles
|
|
2
|
+
|
|
3
|
+
This rule prevents the usage of the `!important` flag in style declarations.
|
|
4
|
+
|
|
5
|
+
Properly composed styles will never need an `!important` flag. It is used to override specificity when working across different scopes, and the UI Styling Standard enforces styles with minimal scope.
|
|
6
|
+
|
|
7
|
+
The use of `!important` is a code smell and greatly impacts readability and determinism.
|
|
8
|
+
|
|
9
|
+
## Examples
|
|
10
|
+
|
|
11
|
+
### Incorrect
|
|
12
|
+
|
|
13
|
+
```js
|
|
14
|
+
import { css } from '@compiled/react';
|
|
15
|
+
|
|
16
|
+
const styles = css({
|
|
17
|
+
color: 'red!important',
|
|
18
|
+
});
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
### Correct
|
|
22
|
+
|
|
23
|
+
```js
|
|
24
|
+
import { css } from '@compiled/react';
|
|
25
|
+
|
|
26
|
+
const styles = css({
|
|
27
|
+
color: 'red',
|
|
28
|
+
});
|
|
29
|
+
```
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
# @atlaskit/design-system/no-invalid-css-map
|
|
2
2
|
|
|
3
|
-
Ensure that all usages of the cssMap API are valid, and enforces the format of the object that is passed to cssMap.
|
|
3
|
+
Ensure that all usages of the cssMap API are valid, and enforces the format of the object that is passed to cssMap. This is intended to be used alongside TypeScript's type-checking.
|
|
4
4
|
|
|
5
|
-
This rule is maintained by another package and configured here
|
|
5
|
+
This rule is maintained by another package and configured here; refer to https://atlassian.design/components/eslint-plugin-design-system/no-invalid-css-map/usage for more details.
|
|
@@ -2,22 +2,4 @@
|
|
|
2
2
|
|
|
3
3
|
Disallows using xcss prop inside JavaScript files.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
## Incorrect
|
|
8
|
-
|
|
9
|
-
Do not use xcss in a JavaScript file as type safety is required to ensure compatability and support
|
|
10
|
-
|
|
11
|
-
```js
|
|
12
|
-
// my-component.js
|
|
13
|
-
<Button xcss={{ fill: 'var(--ds-text)' }} />
|
|
14
|
-
```
|
|
15
|
-
|
|
16
|
-
## Correct
|
|
17
|
-
|
|
18
|
-
Using xcss in a TypeScript file is perfectly fine
|
|
19
|
-
|
|
20
|
-
```tsx
|
|
21
|
-
// my-component.tsx
|
|
22
|
-
<Button xcss={{ color: 'var(--ds-text)' }} />
|
|
23
|
-
```
|
|
5
|
+
This rule is maintained by another package and configured here; refer to https://github.com/atlassian-labs/compiled/tree/master/packages/eslint-plugin/src/rules/no-js-xcss for more details.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
# @atlaskit/design-system/no-keyframes-tagged-template-expression
|
|
2
2
|
|
|
3
|
-
Disallows any keyframes tagged template expressions that originate from
|
|
3
|
+
Disallows any `keyframes` tagged template expressions that originate from a CSS-in-JS library, including `@atlaskit/css`, `@compiled/react`, Emotion, and `styled-components`.
|
|
4
4
|
|
|
5
|
-
This rule is maintained by another package and configured here
|
|
5
|
+
This rule is maintained by another package and configured here; refer to https://atlassian.design/components/eslint-plugin-design-system/no-keyframes-tagged-template-expression/usage for more details.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
# @atlaskit/design-system/no-styled-tagged-template-expression
|
|
2
2
|
|
|
3
|
-
Disallows any styled tagged template expressions that originate from
|
|
3
|
+
Disallows any `styled` tagged template expressions that originate from from a CSS-in-JS library, including `@atlaskit/css`, `@compiled/react`, Emotion, and `styled-components`.
|
|
4
4
|
|
|
5
|
-
This rule is maintained by another package and configured here
|
|
5
|
+
This rule is maintained by another package and configured here; refer to https://atlassian.design/components/eslint-plugin-design-system/no-styled-tagged-template-expression/usage for more details.
|
|
@@ -6,19 +6,22 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
/**
|
|
8
8
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
9
|
-
* @codegen <<SignedSource::
|
|
9
|
+
* @codegen <<SignedSource::c0973784c8a5047835032781219885ce>>
|
|
10
10
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
11
11
|
*/
|
|
12
12
|
var _default = exports.default = {
|
|
13
13
|
plugins: ['@atlaskit/ui-styling-standard', '@atlaskit/design-system', '@compiled'],
|
|
14
14
|
rules: {
|
|
15
15
|
'@atlaskit/ui-styling-standard/local-cx-xcss': 'warn',
|
|
16
|
+
'@atlaskit/ui-styling-standard/no-important-styles': 'warn',
|
|
16
17
|
'@atlaskit/design-system/consistent-css-prop-usage': ['warn', {
|
|
17
18
|
excludeReactComponents: true
|
|
18
19
|
}],
|
|
19
20
|
'@atlaskit/design-system/no-css-tagged-template-expression': 'warn',
|
|
20
21
|
'@atlaskit/design-system/no-keyframes-tagged-template-expression': 'warn',
|
|
21
|
-
'@atlaskit/design-system/no-styled-tagged-template-expression': 'warn',
|
|
22
|
+
'@atlaskit/design-system/no-styled-tagged-template-expression': ['warn', {
|
|
23
|
+
importSources: ['@compiled/react', '@atlaskit/css', '@emotion/core', '@emotion/react', '@emotion/styled']
|
|
24
|
+
}],
|
|
22
25
|
'@compiled/no-suppress-xcss': 'warn',
|
|
23
26
|
'@compiled/no-js-xcss': 'warn',
|
|
24
27
|
'@atlaskit/design-system/no-empty-styled-expression': ['warn', {
|
|
@@ -6,19 +6,22 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
/**
|
|
8
8
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
9
|
-
* @codegen <<SignedSource::
|
|
9
|
+
* @codegen <<SignedSource::c0973784c8a5047835032781219885ce>>
|
|
10
10
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
11
11
|
*/
|
|
12
12
|
var _default = exports.default = {
|
|
13
13
|
plugins: ['@atlaskit/ui-styling-standard', '@atlaskit/design-system', '@compiled'],
|
|
14
14
|
rules: {
|
|
15
15
|
'@atlaskit/ui-styling-standard/local-cx-xcss': 'warn',
|
|
16
|
+
'@atlaskit/ui-styling-standard/no-important-styles': 'warn',
|
|
16
17
|
'@atlaskit/design-system/consistent-css-prop-usage': ['warn', {
|
|
17
18
|
excludeReactComponents: true
|
|
18
19
|
}],
|
|
19
20
|
'@atlaskit/design-system/no-css-tagged-template-expression': 'warn',
|
|
20
21
|
'@atlaskit/design-system/no-keyframes-tagged-template-expression': 'warn',
|
|
21
|
-
'@atlaskit/design-system/no-styled-tagged-template-expression': 'warn',
|
|
22
|
+
'@atlaskit/design-system/no-styled-tagged-template-expression': ['warn', {
|
|
23
|
+
importSources: ['@compiled/react', '@atlaskit/css', '@emotion/core', '@emotion/react', '@emotion/styled']
|
|
24
|
+
}],
|
|
22
25
|
'@compiled/no-suppress-xcss': 'warn',
|
|
23
26
|
'@compiled/no-js-xcss': 'warn',
|
|
24
27
|
'@atlaskit/design-system/no-empty-styled-expression': ['warn', {
|
|
@@ -8,6 +8,29 @@ var _createRule = require("./utils/create-rule");
|
|
|
8
8
|
/** External rules must be scoped, have a display name, and external urls. */
|
|
9
9
|
|
|
10
10
|
var importSources = ['@compiled/react', '@atlaskit/css', '@emotion/core', '@emotion/react', '@emotion/styled', 'styled-components'];
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Same as importSources, but excludes `styled-components` because the type-checking
|
|
14
|
+
* for `styled-components` does not support the `no-styled-tagged-template-expression`
|
|
15
|
+
* lint output for this:
|
|
16
|
+
*
|
|
17
|
+
* export const Container = styled(Section)`
|
|
18
|
+
* max-height: ${gridSize * 46}px;
|
|
19
|
+
* overflow: auto;
|
|
20
|
+
* `;
|
|
21
|
+
*
|
|
22
|
+
* export const ErrorStateContainer = styled(Container)`
|
|
23
|
+
* margin: ${
|
|
24
|
+
* (props: any) =>
|
|
25
|
+
* props.canManageAutomations // Use negative margin to reduce whitespace when the Footer component is shown
|
|
26
|
+
* ? `${gridSize * -4}px ${gridSize * 2}px`
|
|
27
|
+
* : `0 ${gridSize * 2}px`
|
|
28
|
+
* };
|
|
29
|
+
* `;
|
|
30
|
+
*/
|
|
31
|
+
var noStyledTaggedTemplateExpressionImportSources = ['@compiled/react', '@atlaskit/css',
|
|
32
|
+
// doesn't do anything because @atlaskit/css doesn't expose a styled API
|
|
33
|
+
'@emotion/core', '@emotion/react', '@emotion/styled'];
|
|
11
34
|
var externalRules = exports.externalRules = [{
|
|
12
35
|
name: '@atlaskit/design-system/consistent-css-prop-usage',
|
|
13
36
|
displayName: 'consistent-css-prop-usage',
|
|
@@ -60,7 +83,10 @@ var externalRules = exports.externalRules = [{
|
|
|
60
83
|
url: (0, _createRule.getRuleUrl)('no-styled-tagged-template-expression'),
|
|
61
84
|
externalUrl: 'https://atlassian.design/components/eslint-plugin-design-system/no-styled-tagged-template-expression/usage',
|
|
62
85
|
recommended: true,
|
|
63
|
-
severity: 'warn'
|
|
86
|
+
severity: 'warn',
|
|
87
|
+
pluginConfig: {
|
|
88
|
+
importSources: noStyledTaggedTemplateExpressionImportSources
|
|
89
|
+
}
|
|
64
90
|
}
|
|
65
91
|
}, {
|
|
66
92
|
name: '@compiled/no-suppress-xcss',
|
|
@@ -6,11 +6,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.default = void 0;
|
|
8
8
|
var _localCxXcss = _interopRequireDefault(require("./local-cx-xcss"));
|
|
9
|
+
var _noImportantStyles = _interopRequireDefault(require("./no-important-styles"));
|
|
9
10
|
/**
|
|
10
11
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
11
|
-
* @codegen <<SignedSource::
|
|
12
|
+
* @codegen <<SignedSource::4e0d0cd3ebc010cebc70fb1564055574>>
|
|
12
13
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
13
14
|
*/
|
|
14
15
|
var _default = exports.default = {
|
|
15
|
-
'local-cx-xcss': _localCxXcss.default
|
|
16
|
+
'local-cx-xcss': _localCxXcss.default,
|
|
17
|
+
'no-important-styles': _noImportantStyles.default
|
|
16
18
|
};
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.rule = exports.default = void 0;
|
|
8
|
+
var _estraverse = _interopRequireDefault(require("estraverse"));
|
|
9
|
+
var _createRule = require("../utils/create-rule");
|
|
10
|
+
var _isSupportedImport = require("../utils/is-supported-import");
|
|
11
|
+
var schema = [{
|
|
12
|
+
type: 'object',
|
|
13
|
+
properties: {
|
|
14
|
+
importSources: {
|
|
15
|
+
type: 'array',
|
|
16
|
+
items: {
|
|
17
|
+
type: 'string'
|
|
18
|
+
},
|
|
19
|
+
uniqueItems: true
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}];
|
|
23
|
+
var rule = exports.rule = (0, _createRule.createLintRule)({
|
|
24
|
+
meta: {
|
|
25
|
+
name: 'no-important-styles',
|
|
26
|
+
docs: {
|
|
27
|
+
description: 'Disallows important style declarations',
|
|
28
|
+
recommended: true,
|
|
29
|
+
severity: 'warn'
|
|
30
|
+
},
|
|
31
|
+
messages: {
|
|
32
|
+
'no-important-styles': 'Important style declarations are disallowed. Refactor so the `!important` flag is not needed.'
|
|
33
|
+
},
|
|
34
|
+
type: 'problem',
|
|
35
|
+
schema: schema
|
|
36
|
+
},
|
|
37
|
+
create: function create(context) {
|
|
38
|
+
var importSources = (0, _isSupportedImport.getImportSources)(context);
|
|
39
|
+
return {
|
|
40
|
+
CallExpression: function CallExpression(node) {
|
|
41
|
+
var _context$getScope = context.getScope(),
|
|
42
|
+
references = _context$getScope.references;
|
|
43
|
+
if ((0, _isSupportedImport.isCss)(node.callee, references, importSources) || (0, _isSupportedImport.isStyled)(node.callee, references, importSources) || (0, _isSupportedImport.isKeyframes)(node.callee, references, importSources) || (0, _isSupportedImport.isCssMap)(node.callee, references, importSources) || (0, _isSupportedImport.isXcss)(node.callee, references, importSources)) {
|
|
44
|
+
_estraverse.default.traverse(node, {
|
|
45
|
+
enter: function enter(node) {
|
|
46
|
+
var _node$value$value;
|
|
47
|
+
if (node.type !== 'Property') {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
if (node.value.type !== 'Literal') {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* There can be whitespace between the `!` and the `important` keyword.
|
|
56
|
+
* There can also be whitespace after the `important` keyword.
|
|
57
|
+
*/
|
|
58
|
+
if ((_node$value$value = node.value.value) !== null && _node$value$value !== void 0 && _node$value$value.toString().match(/!\s*important\s*$/gm)) {
|
|
59
|
+
context.report({
|
|
60
|
+
node: node.value,
|
|
61
|
+
messageId: 'no-important-styles'
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
/**
|
|
66
|
+
* This is needed to handle unknown node types. Otherwise an error is thrown.
|
|
67
|
+
*/
|
|
68
|
+
fallback: 'iteration'
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
var _default = exports.default = rule;
|
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
3
|
Object.defineProperty(exports, "__esModule", {
|
|
5
4
|
value: true
|
|
6
5
|
});
|
|
7
|
-
exports.isStyled = exports.isKeyframes = exports.isCxFunction = exports.isCssMap = exports.isCss = exports.getImportSources = exports.DEFAULT_IMPORT_SOURCES = exports.CSS_IN_JS_IMPORTS = void 0;
|
|
8
|
-
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
6
|
+
exports.isXcss = exports.isStyledComponents = exports.isStyled = exports.isKeyframes = exports.isImportedFrom = exports.isEmotion = exports.isCxFunction = exports.isCssMap = exports.isCss = exports.isCompiled = exports.getImportSources = exports.DEFAULT_IMPORT_SOURCES = exports.CSS_IN_JS_IMPORTS = void 0;
|
|
9
7
|
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
10
8
|
|
|
11
9
|
var CSS_IN_JS_IMPORTS = exports.CSS_IN_JS_IMPORTS = {
|
|
12
10
|
compiled: '@compiled/react',
|
|
13
11
|
emotionReact: '@emotion/react',
|
|
14
12
|
emotionCore: '@emotion/core',
|
|
13
|
+
emotionStyled: '@emotion/styled',
|
|
15
14
|
styledComponents: 'styled-components',
|
|
16
15
|
atlaskitCss: '@atlaskit/css',
|
|
17
16
|
atlaskitPrimitives: '@atlaskit/primitives'
|
|
@@ -20,16 +19,29 @@ var CSS_IN_JS_IMPORTS = exports.CSS_IN_JS_IMPORTS = {
|
|
|
20
19
|
// A CSS-in-JS library an import of a valid css, cx, cssMap, etc.
|
|
21
20
|
// function might originate from, e.g. @compiled/react, @emotion/core.
|
|
22
21
|
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
/**
|
|
23
|
+
* By default all known import sources are checked against.
|
|
24
|
+
*/
|
|
25
|
+
var DEFAULT_IMPORT_SOURCES = exports.DEFAULT_IMPORT_SOURCES = Object.values(CSS_IN_JS_IMPORTS);
|
|
26
|
+
var getIdentifierNode = function getIdentifierNode(node) {
|
|
27
|
+
var identifierNode = node.type === 'Identifier' ? node : undefined;
|
|
28
|
+
if (!identifierNode) {
|
|
29
|
+
// Handles styled.div`` case
|
|
30
|
+
if (node.type === 'MemberExpression' && node.object.type === 'Identifier') {
|
|
31
|
+
identifierNode = node.object;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Handles styled(Component)`` case
|
|
35
|
+
if (node.type === 'CallExpression' && node.callee.type === 'Identifier') {
|
|
36
|
+
identifierNode = node.callee;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return identifierNode;
|
|
40
|
+
};
|
|
25
41
|
|
|
26
42
|
/**
|
|
27
43
|
* Given the ESLint rule context, extract and parse the value of the importSources rule option.
|
|
28
|
-
* The importSources option is used to
|
|
29
|
-
* should apply to.
|
|
30
|
-
*
|
|
31
|
-
* Note that `@compiled/react` and `@atlaskit/css` are always included in importSources, regardless
|
|
32
|
-
* of what importSources is configured to by the user.
|
|
44
|
+
* The importSources option is used to override which libraries an ESLint rule applies to.
|
|
33
45
|
*
|
|
34
46
|
* @param context The rule context.
|
|
35
47
|
* @returns An array of strings representing what CSS-in-JS packages that should be checked, based
|
|
@@ -41,11 +53,12 @@ var getImportSources = exports.getImportSources = function getImportSources(cont
|
|
|
41
53
|
return DEFAULT_IMPORT_SOURCES;
|
|
42
54
|
}
|
|
43
55
|
if (options[0].importSources && Array.isArray(options[0].importSources)) {
|
|
44
|
-
return
|
|
56
|
+
return options[0].importSources;
|
|
45
57
|
}
|
|
46
58
|
return DEFAULT_IMPORT_SOURCES;
|
|
47
59
|
};
|
|
48
60
|
var isSupportedImportWrapper = function isSupportedImportWrapper(functionName) {
|
|
61
|
+
var defaultFromImportSources = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
49
62
|
var checkDefinitionHasImport = function checkDefinitionHasImport(def, importSources) {
|
|
50
63
|
if (def.type !== 'ImportBinding') {
|
|
51
64
|
return false;
|
|
@@ -53,12 +66,19 @@ var isSupportedImportWrapper = function isSupportedImportWrapper(functionName) {
|
|
|
53
66
|
if (!def.parent || !importSources.includes(def.parent.source.value)) {
|
|
54
67
|
return false;
|
|
55
68
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
69
|
+
|
|
70
|
+
// Matches the imported name from a named import
|
|
71
|
+
// import { functionName, functioName as otherName } from 'import-source';
|
|
72
|
+
var isNamedImport = def.node.type === 'ImportSpecifier' && def.node.imported.name === functionName;
|
|
73
|
+
|
|
74
|
+
// Must explicitly match the local name from a default import
|
|
75
|
+
// import functionName from 'import-source';
|
|
76
|
+
var isDefaultImportMatchingLocal = def.node.type === 'ImportDefaultSpecifier' && def.node.local.name === functionName;
|
|
77
|
+
|
|
78
|
+
// Can match any local name from a default import
|
|
79
|
+
// import anything from 'import-source'
|
|
80
|
+
var isKnownDefaultImport = def.node.type === 'ImportDefaultSpecifier' && defaultFromImportSources.includes(def.parent.source.value);
|
|
81
|
+
return isNamedImport || isDefaultImportMatchingLocal || isKnownDefaultImport;
|
|
62
82
|
};
|
|
63
83
|
|
|
64
84
|
/**
|
|
@@ -78,9 +98,10 @@ var isSupportedImportWrapper = function isSupportedImportWrapper(functionName) {
|
|
|
78
98
|
* @returns Whether the above conditions are true.
|
|
79
99
|
*/
|
|
80
100
|
var isSupportedImport = function isSupportedImport(nodeToCheck, referencesInScope, importSources) {
|
|
81
|
-
|
|
101
|
+
var identifierNode = getIdentifierNode(nodeToCheck);
|
|
102
|
+
return (identifierNode === null || identifierNode === void 0 ? void 0 : identifierNode.type) === 'Identifier' && referencesInScope.some(function (reference) {
|
|
82
103
|
var _reference$resolved;
|
|
83
|
-
return reference.identifier ===
|
|
104
|
+
return reference.identifier === identifierNode && ((_reference$resolved = reference.resolved) === null || _reference$resolved === void 0 ? void 0 : _reference$resolved.defs.some(function (def) {
|
|
84
105
|
return checkDefinitionHasImport(def, importSources);
|
|
85
106
|
}));
|
|
86
107
|
});
|
|
@@ -95,4 +116,35 @@ var isCss = exports.isCss = isSupportedImportWrapper('css');
|
|
|
95
116
|
var isCxFunction = exports.isCxFunction = isSupportedImportWrapper('cx');
|
|
96
117
|
var isCssMap = exports.isCssMap = isSupportedImportWrapper('cssMap');
|
|
97
118
|
var isKeyframes = exports.isKeyframes = isSupportedImportWrapper('keyframes');
|
|
98
|
-
|
|
119
|
+
// `styled` is also the explicit default of `styled-components` and `@emotion/styled`, so we also match on default imports generally
|
|
120
|
+
var isStyled = exports.isStyled = isSupportedImportWrapper('styled', ['styled-components', '@emotion/styled']);
|
|
121
|
+
var isXcss = exports.isXcss = isSupportedImportWrapper('xcss');
|
|
122
|
+
var isImportedFrom = exports.isImportedFrom = function isImportedFrom(moduleName) {
|
|
123
|
+
var exactMatch = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
124
|
+
return function (nodeToCheck, referencesInScope, importSources) {
|
|
125
|
+
if (!importSources.includes(moduleName)) {
|
|
126
|
+
// Don't go through the trouble of checking the import sources does not include this
|
|
127
|
+
// We'll assume this is skipped elsewhere.
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
var identifierNode = getIdentifierNode(nodeToCheck);
|
|
131
|
+
return (identifierNode === null || identifierNode === void 0 ? void 0 : identifierNode.type) === 'Identifier' && referencesInScope.some(function (reference) {
|
|
132
|
+
var _reference$resolved2;
|
|
133
|
+
return reference.identifier === identifierNode && ((_reference$resolved2 = reference.resolved) === null || _reference$resolved2 === void 0 ? void 0 : _reference$resolved2.defs.some(function (def) {
|
|
134
|
+
var _def$parent, _String, _def$parent2;
|
|
135
|
+
return def.type === 'ImportBinding' && (((_def$parent = def.parent) === null || _def$parent === void 0 ? void 0 : _def$parent.source.value) === moduleName || !exactMatch && ((_String = String((_def$parent2 = def.parent) === null || _def$parent2 === void 0 ? void 0 : _def$parent2.source.value)) === null || _String === void 0 ? void 0 : _String.startsWith(moduleName)));
|
|
136
|
+
}));
|
|
137
|
+
});
|
|
138
|
+
};
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Determine if this node is specifically from a `'styled-components'` import.
|
|
143
|
+
* This is because `styled-components@3.4` APIs are not consistent with Emotion and Compiled,
|
|
144
|
+
* we need to handle them differently in a few scenarios.
|
|
145
|
+
*
|
|
146
|
+
* This can be cleaned up when `'styled-components'` is no longer a valid ImportSource.
|
|
147
|
+
*/
|
|
148
|
+
var isStyledComponents = exports.isStyledComponents = isImportedFrom('styled-components');
|
|
149
|
+
var isCompiled = exports.isCompiled = isImportedFrom('@compiled/', false);
|
|
150
|
+
var isEmotion = exports.isEmotion = isImportedFrom('@emotion/', false);
|
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
-
* @codegen <<SignedSource::
|
|
3
|
+
* @codegen <<SignedSource::c0973784c8a5047835032781219885ce>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
export default {
|
|
7
7
|
plugins: ['@atlaskit/ui-styling-standard', '@atlaskit/design-system', '@compiled'],
|
|
8
8
|
rules: {
|
|
9
9
|
'@atlaskit/ui-styling-standard/local-cx-xcss': 'warn',
|
|
10
|
+
'@atlaskit/ui-styling-standard/no-important-styles': 'warn',
|
|
10
11
|
'@atlaskit/design-system/consistent-css-prop-usage': ['warn', {
|
|
11
12
|
excludeReactComponents: true
|
|
12
13
|
}],
|
|
13
14
|
'@atlaskit/design-system/no-css-tagged-template-expression': 'warn',
|
|
14
15
|
'@atlaskit/design-system/no-keyframes-tagged-template-expression': 'warn',
|
|
15
|
-
'@atlaskit/design-system/no-styled-tagged-template-expression': 'warn',
|
|
16
|
+
'@atlaskit/design-system/no-styled-tagged-template-expression': ['warn', {
|
|
17
|
+
importSources: ['@compiled/react', '@atlaskit/css', '@emotion/core', '@emotion/react', '@emotion/styled']
|
|
18
|
+
}],
|
|
16
19
|
'@compiled/no-suppress-xcss': 'warn',
|
|
17
20
|
'@compiled/no-js-xcss': 'warn',
|
|
18
21
|
'@atlaskit/design-system/no-empty-styled-expression': ['warn', {
|
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
-
* @codegen <<SignedSource::
|
|
3
|
+
* @codegen <<SignedSource::c0973784c8a5047835032781219885ce>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
export default {
|
|
7
7
|
plugins: ['@atlaskit/ui-styling-standard', '@atlaskit/design-system', '@compiled'],
|
|
8
8
|
rules: {
|
|
9
9
|
'@atlaskit/ui-styling-standard/local-cx-xcss': 'warn',
|
|
10
|
+
'@atlaskit/ui-styling-standard/no-important-styles': 'warn',
|
|
10
11
|
'@atlaskit/design-system/consistent-css-prop-usage': ['warn', {
|
|
11
12
|
excludeReactComponents: true
|
|
12
13
|
}],
|
|
13
14
|
'@atlaskit/design-system/no-css-tagged-template-expression': 'warn',
|
|
14
15
|
'@atlaskit/design-system/no-keyframes-tagged-template-expression': 'warn',
|
|
15
|
-
'@atlaskit/design-system/no-styled-tagged-template-expression': 'warn',
|
|
16
|
+
'@atlaskit/design-system/no-styled-tagged-template-expression': ['warn', {
|
|
17
|
+
importSources: ['@compiled/react', '@atlaskit/css', '@emotion/core', '@emotion/react', '@emotion/styled']
|
|
18
|
+
}],
|
|
16
19
|
'@compiled/no-suppress-xcss': 'warn',
|
|
17
20
|
'@compiled/no-js-xcss': 'warn',
|
|
18
21
|
'@atlaskit/design-system/no-empty-styled-expression': ['warn', {
|