@atlaskit/eslint-plugin-ui-styling-standard 0.9.0 → 0.10.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 +2 -0
- package/constellation/enforce-style-prop/usage.mdx +38 -0
- package/constellation/index/overview.mdx +2 -0
- package/constellation/no-dynamic-styles/usage.mdx +128 -0
- package/dist/cjs/presets/all.codegen.js +3 -1
- package/dist/cjs/presets/recommended.codegen.js +3 -1
- package/dist/cjs/rules/enforce-style-prop/index.js +141 -0
- package/dist/cjs/rules/index.codegen.js +5 -1
- package/dist/cjs/rules/no-dynamic-styles/index.js +69 -0
- package/dist/es2019/presets/all.codegen.js +3 -1
- package/dist/es2019/presets/recommended.codegen.js +3 -1
- package/dist/es2019/rules/enforce-style-prop/index.js +133 -0
- package/dist/es2019/rules/index.codegen.js +5 -1
- package/dist/es2019/rules/no-dynamic-styles/index.js +51 -0
- package/dist/esm/presets/all.codegen.js +3 -1
- package/dist/esm/presets/recommended.codegen.js +3 -1
- package/dist/esm/rules/enforce-style-prop/index.js +135 -0
- package/dist/esm/rules/index.codegen.js +5 -1
- package/dist/esm/rules/no-dynamic-styles/index.js +62 -0
- package/dist/types/index.codegen.d.ts +4 -0
- package/dist/types/presets/all.codegen.d.ts +3 -1
- package/dist/types/presets/recommended.codegen.d.ts +3 -1
- package/dist/types/rules/enforce-style-prop/index.d.ts +3 -0
- package/dist/types/rules/index.codegen.d.ts +2 -0
- package/dist/types/rules/no-dynamic-styles/index.d.ts +2 -0
- package/dist/types-ts4.5/index.codegen.d.ts +4 -0
- package/dist/types-ts4.5/presets/all.codegen.d.ts +3 -1
- package/dist/types-ts4.5/presets/recommended.codegen.d.ts +3 -1
- package/dist/types-ts4.5/rules/enforce-style-prop/index.d.ts +3 -0
- package/dist/types-ts4.5/rules/index.codegen.d.ts +2 -0
- package/dist/types-ts4.5/rules/no-dynamic-styles/index.d.ts +2 -0
- package/package.json +3 -2
- package/src/presets/all.codegen.tsx +3 -1
- package/src/presets/recommended.codegen.tsx +3 -1
- package/src/rules/enforce-style-prop/README.md +36 -0
- package/src/rules/enforce-style-prop/__tests__/rule.test.tsx +231 -0
- package/src/rules/enforce-style-prop/index.tsx +169 -0
- package/src/rules/index.codegen.tsx +5 -1
- package/src/rules/no-dynamic-styles/README.md +126 -0
- package/src/rules/no-dynamic-styles/__tests__/rule.test.tsx +128 -0
- package/src/rules/no-dynamic-styles/index.tsx +63 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @atlaskit/eslint-plugin-ui-styling-standard
|
|
2
2
|
|
|
3
|
+
## 0.10.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#91611](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/91611) [`943056d22c36`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/943056d22c36) - Add `no-dynamic-styles` rule which blocks function expressions as values in style declarations.
|
|
8
|
+
|
|
9
|
+
## 0.9.1
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [#90977](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/90977) [`becda03f375e`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/becda03f375e) - Create eslint rule to enforce style prop usage by disallowing passing static css values
|
|
14
|
+
|
|
3
15
|
## 0.9.0
|
|
4
16
|
|
|
5
17
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -14,10 +14,12 @@ Not intended for use outside the Atlassian frontend repository.
|
|
|
14
14
|
| Rule | Description | Recommended | Fixable | Suggestions |
|
|
15
15
|
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------- | ------- | ----------- |
|
|
16
16
|
| <a href="./src/rules/convert-props-syntax/README.md">convert-props-syntax</a> | Convert props syntax that is unsupported by styled-components@<4 or @emotion/styled to props syntax that is supported. This is useful when used in conjunction with `no-styled-tagged-template-expression`, as output from the latter may use props syntax unsupported by those libraries. | Yes | Yes | |
|
|
17
|
+
| <a href="./src/rules/enforce-style-prop/README.md">enforce-style-prop</a> | Disallows usage of static styles in the `style` attribute in components | Yes | | |
|
|
17
18
|
| <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 | | |
|
|
18
19
|
| <a href="./src/rules/no-array-arguments/README.md">no-array-arguments</a> | Prevents usage of array arguments to style declaration functions | Yes | Yes | |
|
|
19
20
|
| <a href="./src/rules/no-classname-prop/README.md">no-classname-prop</a> | Disallows usage of the `className` prop in JSX | Yes | | |
|
|
20
21
|
| <a href="./src/rules/no-container-queries/README.md">no-container-queries</a> | Prevents usage of @container query within css styling | Yes | | |
|
|
22
|
+
| <a href="./src/rules/no-dynamic-styles/README.md">no-dynamic-styles</a> | Disallows use of dynamic styles in CSS-in-JS calls | Yes | | |
|
|
21
23
|
| <a href="./src/rules/no-important-styles/README.md">no-important-styles</a> | Disallows important style declarations | Yes | | |
|
|
22
24
|
| <a href="./src/rules/no-nested-selectors/README.md">no-nested-selectors</a> | Prevents usage of nested selectors within css styling | Yes | | |
|
|
23
25
|
| <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 | |
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# enforce-style-prop
|
|
2
|
+
|
|
3
|
+
This rule enforces passing dynamic CSS values to the `style` prop in JSX components.
|
|
4
|
+
|
|
5
|
+
We only want `props.style` to be used for dynamic values that cannot be easily determined at build time, e.g. `<div style={{ width: props.width }}>`. No statics values such as numbers, strings or any other statically analysable values should be passed to the `style` attribute. Instead, static CSS values should be passed into the `css` prop in JSX components.
|
|
6
|
+
|
|
7
|
+
## Examples
|
|
8
|
+
|
|
9
|
+
### Incorrect
|
|
10
|
+
|
|
11
|
+
```tsx
|
|
12
|
+
function Component() {
|
|
13
|
+
return (
|
|
14
|
+
<div
|
|
15
|
+
style={{
|
|
16
|
+
margin: 0,
|
|
17
|
+
color: 'red',
|
|
18
|
+
}}
|
|
19
|
+
/>
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
### Correct
|
|
25
|
+
|
|
26
|
+
```tsx
|
|
27
|
+
function Component(props) {
|
|
28
|
+
return (
|
|
29
|
+
<div
|
|
30
|
+
style={{
|
|
31
|
+
width: props.width,
|
|
32
|
+
'--my-nested-width': props.width,
|
|
33
|
+
}}
|
|
34
|
+
css={css({ margin: 0, color: 'red' })}
|
|
35
|
+
/>
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
```
|
|
@@ -12,10 +12,12 @@ but more are planned to support the standard over time.
|
|
|
12
12
|
| Rule | Description | Recommended | Fixable | Suggestions |
|
|
13
13
|
| --------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------- | ------- | ----------- |
|
|
14
14
|
| <a href="convert-props-syntax/usage">convert-props-syntax</a> | Convert props syntax that is unsupported by styled-components@<4 or @emotion/styled to props syntax that is supported. This is useful when used in conjunction with `no-styled-tagged-template-expression`, as output from the latter may use props syntax unsupported by those libraries. | Yes | Yes | |
|
|
15
|
+
| <a href="enforce-style-prop/usage">enforce-style-prop</a> | Disallows usage of static styles in the `style` attribute in components | Yes | | |
|
|
15
16
|
| <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 | | |
|
|
16
17
|
| <a href="no-array-arguments/usage">no-array-arguments</a> | Prevents usage of array arguments to style declaration functions | Yes | Yes | |
|
|
17
18
|
| <a href="no-classname-prop/usage">no-classname-prop</a> | Disallows usage of the `className` prop in JSX | Yes | | |
|
|
18
19
|
| <a href="no-container-queries/usage">no-container-queries</a> | Prevents usage of @container query within css styling | Yes | | |
|
|
20
|
+
| <a href="no-dynamic-styles/usage">no-dynamic-styles</a> | Disallows use of dynamic styles in CSS-in-JS calls | Yes | | |
|
|
19
21
|
| <a href="no-important-styles/usage">no-important-styles</a> | Disallows important style declarations | Yes | | |
|
|
20
22
|
| <a href="no-nested-selectors/usage">no-nested-selectors</a> | Prevents usage of nested selectors within css styling | Yes | | |
|
|
21
23
|
| <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 | |
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
# no-dynamic-styles
|
|
2
|
+
|
|
3
|
+
This rule prevents the use of dynamic styles (function expressions) in style declarations.
|
|
4
|
+
|
|
5
|
+
This ensures that style declarations:
|
|
6
|
+
|
|
7
|
+
- are statically analyzable
|
|
8
|
+
- can be efficiently extracted into atomic CSS
|
|
9
|
+
- are more readable, deterministic, and thus easier to maintain
|
|
10
|
+
|
|
11
|
+
## Examples
|
|
12
|
+
|
|
13
|
+
### Incorrect
|
|
14
|
+
|
|
15
|
+
```tsx
|
|
16
|
+
import { styled } from '@compiled/react';
|
|
17
|
+
|
|
18
|
+
const Component = styled.div<{ width: number }>((props) => ({
|
|
19
|
+
width: props.width,
|
|
20
|
+
}));
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
```tsx
|
|
24
|
+
import styled from 'styled-components';
|
|
25
|
+
|
|
26
|
+
const Component = styled.div<{ width: number }>({
|
|
27
|
+
width: (props) => props.width,
|
|
28
|
+
});
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
```tsx
|
|
32
|
+
import styled from 'styled-components';
|
|
33
|
+
|
|
34
|
+
const Container = styled.div<hasPadding>({
|
|
35
|
+
padding: ({ hasPadding }) =>
|
|
36
|
+
hasPadding ? token('space.100', '8px') : token('space.0', '0px'),
|
|
37
|
+
});
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### Correct
|
|
41
|
+
|
|
42
|
+
**Flags**
|
|
43
|
+
|
|
44
|
+
If you have a style that is on/off depending on a prop,
|
|
45
|
+
use the `css` prop to conditionally apply it.
|
|
46
|
+
|
|
47
|
+
```tsx
|
|
48
|
+
import { css } from '@compiled/react';
|
|
49
|
+
|
|
50
|
+
const baseStyles = css({ padding: token('space.0') });
|
|
51
|
+
const hasPaddingStyles = css({ padding: token('space.100') });
|
|
52
|
+
|
|
53
|
+
const Container = ({ hasPadding = false }: { hasPadding?: boolean }) => {
|
|
54
|
+
return <div css={[baseStyles, hasPadding && hasPaddingStyles]} />;
|
|
55
|
+
};
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
**Variants**
|
|
59
|
+
|
|
60
|
+
If you have variants which are known ahead of time,
|
|
61
|
+
use `cssMap` to define them and the `css` prop to conditionally apply it.
|
|
62
|
+
|
|
63
|
+
```tsx
|
|
64
|
+
import { css } from '@compiled/react';
|
|
65
|
+
|
|
66
|
+
const baseStyles = css({ width: 100 });
|
|
67
|
+
const stylesMap = cssMap({
|
|
68
|
+
primary: {
|
|
69
|
+
background: token('color.background.brand.bold'),
|
|
70
|
+
'&:hover': { background: token('color.background.brand.bold.hovered') },
|
|
71
|
+
},
|
|
72
|
+
error: {
|
|
73
|
+
background: token('color.background.warning.bold'),
|
|
74
|
+
'&:hover': { background: token('color.background.warning.bold.hovered') },
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
const Wrapper = ({ appearance = 'primary' }: { appearance?: 'primary' | 'error' }) => (
|
|
79
|
+
<div css={[baseStyles, stylesMap[appearance]} />
|
|
80
|
+
);
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
**Dynamic values**
|
|
84
|
+
|
|
85
|
+
If you have styles which are truly dynamic,
|
|
86
|
+
use the `style` prop.
|
|
87
|
+
|
|
88
|
+
This approach should be used as a last resort.
|
|
89
|
+
|
|
90
|
+
```tsx
|
|
91
|
+
import { css } from '@compiled/react';
|
|
92
|
+
|
|
93
|
+
const Component = ({ width }: { width: number }) => {
|
|
94
|
+
return <div style={{ width }} />;
|
|
95
|
+
};
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
```tsx
|
|
99
|
+
import { css } from '@compiled/react';
|
|
100
|
+
|
|
101
|
+
const containerStyles = css({
|
|
102
|
+
'::before': {
|
|
103
|
+
width: 'var(--ak-example-width)',
|
|
104
|
+
},
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
function Example({ width }: { width: number }) {
|
|
108
|
+
return (
|
|
109
|
+
<div css={containerStyles} style={{ '--ak-example-width': `${width}px` }} />
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## Options
|
|
115
|
+
|
|
116
|
+
### importSources
|
|
117
|
+
|
|
118
|
+
By default, this rule will check usages from:
|
|
119
|
+
|
|
120
|
+
- `@atlaskit/css`
|
|
121
|
+
- `@atlaskit/primitives`
|
|
122
|
+
- `@compiled/react`
|
|
123
|
+
- `@emotion/react`
|
|
124
|
+
- `@emotion/core`
|
|
125
|
+
- `@emotion/styled`
|
|
126
|
+
- `styled-components`
|
|
127
|
+
|
|
128
|
+
To change this list of libraries, you can define a custom set of `importSources`, which accepts an array of package names (strings).
|
|
@@ -6,17 +6,19 @@ 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::8859bbdd2c4bf68ed4a1780f0e776e47>>
|
|
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/convert-props-syntax': 'error',
|
|
16
|
+
'@atlaskit/ui-styling-standard/enforce-style-prop': 'warn',
|
|
16
17
|
'@atlaskit/ui-styling-standard/local-cx-xcss': 'warn',
|
|
17
18
|
'@atlaskit/ui-styling-standard/no-array-arguments': 'warn',
|
|
18
19
|
'@atlaskit/ui-styling-standard/no-classname-prop': 'warn',
|
|
19
20
|
'@atlaskit/ui-styling-standard/no-container-queries': 'warn',
|
|
21
|
+
'@atlaskit/ui-styling-standard/no-dynamic-styles': 'warn',
|
|
20
22
|
'@atlaskit/ui-styling-standard/no-important-styles': 'warn',
|
|
21
23
|
'@atlaskit/ui-styling-standard/no-nested-selectors': 'warn',
|
|
22
24
|
'@atlaskit/design-system/consistent-css-prop-usage': ['warn', {
|
|
@@ -6,17 +6,19 @@ 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::8859bbdd2c4bf68ed4a1780f0e776e47>>
|
|
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/convert-props-syntax': 'error',
|
|
16
|
+
'@atlaskit/ui-styling-standard/enforce-style-prop': 'warn',
|
|
16
17
|
'@atlaskit/ui-styling-standard/local-cx-xcss': 'warn',
|
|
17
18
|
'@atlaskit/ui-styling-standard/no-array-arguments': 'warn',
|
|
18
19
|
'@atlaskit/ui-styling-standard/no-classname-prop': 'warn',
|
|
19
20
|
'@atlaskit/ui-styling-standard/no-container-queries': 'warn',
|
|
21
|
+
'@atlaskit/ui-styling-standard/no-dynamic-styles': 'warn',
|
|
20
22
|
'@atlaskit/ui-styling-standard/no-important-styles': 'warn',
|
|
21
23
|
'@atlaskit/ui-styling-standard/no-nested-selectors': 'warn',
|
|
22
24
|
'@atlaskit/design-system/consistent-css-prop-usage': ['warn', {
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.rule = exports.default = void 0;
|
|
7
|
+
var _eslintCodemodUtils = require("eslint-codemod-utils");
|
|
8
|
+
var _createRule = require("../utils/create-rule");
|
|
9
|
+
var findVariable = function findVariable(context, name) {
|
|
10
|
+
return context.getScope().variables.find(function (varb) {
|
|
11
|
+
return varb.name === name;
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
var isParameter = function isParameter(context, variableName) {
|
|
15
|
+
var _findVariable;
|
|
16
|
+
var definitions = (_findVariable = findVariable(context, variableName)) === null || _findVariable === void 0 ? void 0 : _findVariable.defs;
|
|
17
|
+
if (!definitions || !definitions.length) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
var result = definitions[0];
|
|
21
|
+
return result.type === 'Parameter';
|
|
22
|
+
};
|
|
23
|
+
var checkIdentifier = function checkIdentifier(context, identifier) {
|
|
24
|
+
var _parent;
|
|
25
|
+
var val = identifier.name;
|
|
26
|
+
var variable = findVariable(context, val);
|
|
27
|
+
if (!variable) {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
var variableDefinition = variable.defs[0].node;
|
|
31
|
+
|
|
32
|
+
// If identifier is a RestElement, report warning
|
|
33
|
+
if (((_parent = variable.identifiers[0].parent) === null || _parent === void 0 ? void 0 : _parent.type) === 'RestElement') {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Checking if identifier has been destructured from props within function
|
|
38
|
+
if (variableDefinition.type === 'VariableDeclarator') {
|
|
39
|
+
var _variableDefinition$i, _variableDefinition$i2, _variableDefinition$i3;
|
|
40
|
+
// If it's a let variable, ignore
|
|
41
|
+
if (variableDefinition.parent.kind === 'let') {
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
// If it's initialised by a call expression, ignore
|
|
45
|
+
if (((_variableDefinition$i = variableDefinition.init) === null || _variableDefinition$i === void 0 ? void 0 : _variableDefinition$i.type) === 'CallExpression') {
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
// Destructured from member expression
|
|
49
|
+
// e.g. const width = props.width
|
|
50
|
+
if (((_variableDefinition$i2 = variableDefinition.init) === null || _variableDefinition$i2 === void 0 ? void 0 : _variableDefinition$i2.type) === 'MemberExpression') {
|
|
51
|
+
var memberIdentifierName = variableDefinition.init.object.name;
|
|
52
|
+
return isParameter(context, memberIdentifierName);
|
|
53
|
+
}
|
|
54
|
+
// Destructured from object pattern
|
|
55
|
+
// e.g. const { width } = props
|
|
56
|
+
var propName = (_variableDefinition$i3 = variableDefinition.init) === null || _variableDefinition$i3 === void 0 ? void 0 : _variableDefinition$i3.name;
|
|
57
|
+
return isParameter(context, propName);
|
|
58
|
+
}
|
|
59
|
+
// If identifier has not been deconstructed from parameter or is a RestElement, report warning
|
|
60
|
+
return isParameter(context, val);
|
|
61
|
+
};
|
|
62
|
+
function isPropertyValueAllowed(property, context) {
|
|
63
|
+
if (property.type === 'SpreadElement') {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
// property.type === 'Property', moving on to check if value is static
|
|
67
|
+
if (property.value.type === 'Literal') {
|
|
68
|
+
return false;
|
|
69
|
+
} else if (property.value.type === 'Identifier') {
|
|
70
|
+
return checkIdentifier(context, property.value);
|
|
71
|
+
} else if (property.value.type === 'CallExpression' && property.value.callee.type === 'Identifier' && property.value.callee.name === 'token') {
|
|
72
|
+
return false;
|
|
73
|
+
} else if (property.value.type === 'MemberExpression' && property.value.object.type === 'Identifier') {
|
|
74
|
+
var _findVariable2;
|
|
75
|
+
var val = property.value.object.name;
|
|
76
|
+
var definitions = (_findVariable2 = findVariable(context, val)) === null || _findVariable2 === void 0 ? void 0 : _findVariable2.defs;
|
|
77
|
+
if (!definitions || !definitions.length) {
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
var variable = definitions[0];
|
|
81
|
+
if (!variable) {
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
var varType = variable.type;
|
|
85
|
+
if (varType === 'Variable') {
|
|
86
|
+
if (!variable.node.init) {
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
var varSource = variable.node.init.type;
|
|
90
|
+
// Variables initialised by a call expression or object expression are ok
|
|
91
|
+
if (varSource === 'CallExpression' || varSource === 'ObjectExpression') {
|
|
92
|
+
return true;
|
|
93
|
+
}
|
|
94
|
+
// Check if member expression matches with function argument
|
|
95
|
+
} else if (varType !== 'Parameter') {
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return true;
|
|
100
|
+
}
|
|
101
|
+
var rule = exports.rule = (0, _createRule.createLintRule)({
|
|
102
|
+
meta: {
|
|
103
|
+
name: 'enforce-style-prop',
|
|
104
|
+
docs: {
|
|
105
|
+
description: 'Disallows usage of static styles in the `style` attribute in components',
|
|
106
|
+
recommended: true,
|
|
107
|
+
severity: 'warn'
|
|
108
|
+
},
|
|
109
|
+
messages: {
|
|
110
|
+
'enforce-style-prop': 'Avoid adding static values to the style prop. Use the css prop for static styles instead.'
|
|
111
|
+
},
|
|
112
|
+
type: 'problem'
|
|
113
|
+
},
|
|
114
|
+
create: function create(context) {
|
|
115
|
+
return {
|
|
116
|
+
'JSXAttribute[name.name="style"] > JSXExpressionContainer': function JSXAttributeNameNameStyleJSXExpressionContainer(node) {
|
|
117
|
+
if (!(0, _eslintCodemodUtils.isNodeOfType)(node, 'JSXExpressionContainer')) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
// we've reached an attribute named style
|
|
121
|
+
|
|
122
|
+
if (node.expression.type === 'ObjectExpression') {
|
|
123
|
+
node.expression.properties.forEach(function (value) {
|
|
124
|
+
if (!isPropertyValueAllowed(value, context)) {
|
|
125
|
+
context.report({
|
|
126
|
+
node: value,
|
|
127
|
+
messageId: 'enforce-style-prop'
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
} else {
|
|
132
|
+
context.report({
|
|
133
|
+
node: node,
|
|
134
|
+
messageId: 'enforce-style-prop'
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
var _default = exports.default = rule;
|
|
@@ -6,23 +6,27 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.default = void 0;
|
|
8
8
|
var _convertPropsSyntax = _interopRequireDefault(require("./convert-props-syntax"));
|
|
9
|
+
var _enforceStyleProp = _interopRequireDefault(require("./enforce-style-prop"));
|
|
9
10
|
var _localCxXcss = _interopRequireDefault(require("./local-cx-xcss"));
|
|
10
11
|
var _noArrayArguments = _interopRequireDefault(require("./no-array-arguments"));
|
|
11
12
|
var _noClassnameProp = _interopRequireDefault(require("./no-classname-prop"));
|
|
12
13
|
var _noContainerQueries = _interopRequireDefault(require("./no-container-queries"));
|
|
14
|
+
var _noDynamicStyles = _interopRequireDefault(require("./no-dynamic-styles"));
|
|
13
15
|
var _noImportantStyles = _interopRequireDefault(require("./no-important-styles"));
|
|
14
16
|
var _noNestedSelectors = _interopRequireDefault(require("./no-nested-selectors"));
|
|
15
17
|
/**
|
|
16
18
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
17
|
-
* @codegen <<SignedSource::
|
|
19
|
+
* @codegen <<SignedSource::12e455a3866637a2dc91ce8751babd54>>
|
|
18
20
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
19
21
|
*/
|
|
20
22
|
var _default = exports.default = {
|
|
21
23
|
'convert-props-syntax': _convertPropsSyntax.default,
|
|
24
|
+
'enforce-style-prop': _enforceStyleProp.default,
|
|
22
25
|
'local-cx-xcss': _localCxXcss.default,
|
|
23
26
|
'no-array-arguments': _noArrayArguments.default,
|
|
24
27
|
'no-classname-prop': _noClassnameProp.default,
|
|
25
28
|
'no-container-queries': _noContainerQueries.default,
|
|
29
|
+
'no-dynamic-styles': _noDynamicStyles.default,
|
|
26
30
|
'no-important-styles': _noImportantStyles.default,
|
|
27
31
|
'no-nested-selectors': _noNestedSelectors.default
|
|
28
32
|
};
|
|
@@ -0,0 +1,69 @@
|
|
|
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 _esquery = _interopRequireDefault(require("esquery"));
|
|
9
|
+
var _isSupportedImport = require("@atlaskit/eslint-utils/is-supported-import");
|
|
10
|
+
var _createRule = require("../utils/create-rule");
|
|
11
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
12
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
13
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
14
|
+
var schema = [{
|
|
15
|
+
type: 'object',
|
|
16
|
+
properties: {
|
|
17
|
+
importSources: {
|
|
18
|
+
type: 'array',
|
|
19
|
+
items: {
|
|
20
|
+
type: 'string'
|
|
21
|
+
},
|
|
22
|
+
uniqueItems: true
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}];
|
|
26
|
+
var rule = exports.rule = (0, _createRule.createLintRule)({
|
|
27
|
+
meta: {
|
|
28
|
+
name: 'no-dynamic-styles',
|
|
29
|
+
docs: {
|
|
30
|
+
description: 'Disallows use of dynamic styles in CSS-in-JS calls',
|
|
31
|
+
recommended: true,
|
|
32
|
+
severity: 'warn'
|
|
33
|
+
},
|
|
34
|
+
schema: schema,
|
|
35
|
+
messages: {
|
|
36
|
+
'no-dynamic-styles': 'Dynamic styles are not allowed. Instead use the style prop to apply styles derived from component props.'
|
|
37
|
+
},
|
|
38
|
+
type: 'problem'
|
|
39
|
+
},
|
|
40
|
+
create: function create(context) {
|
|
41
|
+
var importSources = (0, _isSupportedImport.getImportSources)(context);
|
|
42
|
+
return {
|
|
43
|
+
CallExpression: function CallExpression(node) {
|
|
44
|
+
var _context$sourceCode$g = context.sourceCode.getScope(node),
|
|
45
|
+
references = _context$sourceCode$g.references;
|
|
46
|
+
if (!(0, _isSupportedImport.hasStyleObjectArguments)(node.callee, references, importSources)) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
var matches = (0, _esquery.default)(node, 'ArrowFunctionExpression, FunctionExpression');
|
|
50
|
+
var _iterator = _createForOfIteratorHelper(matches),
|
|
51
|
+
_step;
|
|
52
|
+
try {
|
|
53
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
54
|
+
var match = _step.value;
|
|
55
|
+
context.report({
|
|
56
|
+
node: match,
|
|
57
|
+
messageId: 'no-dynamic-styles'
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
} catch (err) {
|
|
61
|
+
_iterator.e(err);
|
|
62
|
+
} finally {
|
|
63
|
+
_iterator.f();
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
var _default = exports.default = rule;
|
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
-
* @codegen <<SignedSource::
|
|
3
|
+
* @codegen <<SignedSource::8859bbdd2c4bf68ed4a1780f0e776e47>>
|
|
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/convert-props-syntax': 'error',
|
|
10
|
+
'@atlaskit/ui-styling-standard/enforce-style-prop': 'warn',
|
|
10
11
|
'@atlaskit/ui-styling-standard/local-cx-xcss': 'warn',
|
|
11
12
|
'@atlaskit/ui-styling-standard/no-array-arguments': 'warn',
|
|
12
13
|
'@atlaskit/ui-styling-standard/no-classname-prop': 'warn',
|
|
13
14
|
'@atlaskit/ui-styling-standard/no-container-queries': 'warn',
|
|
15
|
+
'@atlaskit/ui-styling-standard/no-dynamic-styles': 'warn',
|
|
14
16
|
'@atlaskit/ui-styling-standard/no-important-styles': 'warn',
|
|
15
17
|
'@atlaskit/ui-styling-standard/no-nested-selectors': 'warn',
|
|
16
18
|
'@atlaskit/design-system/consistent-css-prop-usage': ['warn', {
|
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
-
* @codegen <<SignedSource::
|
|
3
|
+
* @codegen <<SignedSource::8859bbdd2c4bf68ed4a1780f0e776e47>>
|
|
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/convert-props-syntax': 'error',
|
|
10
|
+
'@atlaskit/ui-styling-standard/enforce-style-prop': 'warn',
|
|
10
11
|
'@atlaskit/ui-styling-standard/local-cx-xcss': 'warn',
|
|
11
12
|
'@atlaskit/ui-styling-standard/no-array-arguments': 'warn',
|
|
12
13
|
'@atlaskit/ui-styling-standard/no-classname-prop': 'warn',
|
|
13
14
|
'@atlaskit/ui-styling-standard/no-container-queries': 'warn',
|
|
15
|
+
'@atlaskit/ui-styling-standard/no-dynamic-styles': 'warn',
|
|
14
16
|
'@atlaskit/ui-styling-standard/no-important-styles': 'warn',
|
|
15
17
|
'@atlaskit/ui-styling-standard/no-nested-selectors': 'warn',
|
|
16
18
|
'@atlaskit/design-system/consistent-css-prop-usage': ['warn', {
|