@atlaskit/eslint-plugin-ui-styling-standard 0.16.3 → 0.16.5
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 +17 -0
- package/constellation/atlaskit-theme/usage.mdx +74 -55
- package/constellation/convert-props-syntax/usage.mdx +29 -24
- package/constellation/enforce-style-prop/usage.mdx +32 -26
- package/constellation/local-cx-xcss/usage.mdx +27 -15
- package/constellation/no-array-arguments/usage.mdx +12 -9
- package/constellation/no-classname-prop/usage.mdx +13 -5
- package/constellation/no-container-queries/usage.mdx +65 -16
- package/constellation/no-dynamic-styles/usage.mdx +16 -11
- package/constellation/no-exported-styles/usage.mdx +25 -30
- package/constellation/no-global-styles/usage.mdx +4 -3
- package/constellation/no-important-styles/usage.mdx +5 -3
- package/constellation/no-imported-style-values/usage.mdx +30 -27
- package/constellation/no-nested-selectors/usage.mdx +51 -18
- package/constellation/no-styled/usage.mdx +17 -14
- package/constellation/no-unsafe-selectors/usage.mdx +184 -58
- package/constellation/no-unsafe-values/usage.mdx +150 -48
- package/constellation/use-compiled/usage.mdx +8 -8
- package/dist/cjs/rules/no-imported-style-values/index.js +50 -2
- package/dist/es2019/rules/no-imported-style-values/index.js +49 -2
- package/dist/esm/rules/no-imported-style-values/index.js +50 -2
- package/package.json +1 -1
- package/src/rules/atlaskit-theme/README.md +74 -55
- package/src/rules/convert-props-syntax/README.md +29 -24
- package/src/rules/enforce-style-prop/README.md +32 -26
- package/src/rules/local-cx-xcss/README.md +27 -15
- package/src/rules/no-array-arguments/README.md +12 -9
- package/src/rules/no-classname-prop/README.md +13 -5
- package/src/rules/no-container-queries/README.md +65 -16
- package/src/rules/no-dynamic-styles/README.md +16 -11
- package/src/rules/no-exported-styles/README.md +25 -30
- package/src/rules/no-global-styles/README.md +4 -3
- package/src/rules/no-important-styles/README.md +5 -3
- package/src/rules/no-imported-style-values/README.md +30 -27
- package/src/rules/no-imported-style-values/__tests__/rule.test.tsx +208 -0
- package/src/rules/no-imported-style-values/index.tsx +51 -4
- package/src/rules/no-nested-selectors/README.md +51 -18
- package/src/rules/no-styled/README.md +17 -14
- package/src/rules/no-unsafe-selectors/README.md +184 -58
- package/src/rules/no-unsafe-values/README.md +150 -48
- package/src/rules/use-compiled/README.md +8 -8
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
# use-compiled
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Blocks CSS-in-JS libraries other than `@compiled/react`, including Emotion and styled-components.
|
|
4
4
|
|
|
5
5
|
**WARNING** It may be unsafe to mix usages of `@compiled/react` with other CSS-in-JS libraries on
|
|
6
6
|
the same component. When converting to `@compiled/react` verify ALL changes. For this reason, the
|
|
7
|
-
|
|
7
|
+
autofixer has been disabled by default, but it may be useful to enable to empower a migration.
|
|
8
8
|
|
|
9
9
|
## Examples
|
|
10
10
|
|
|
11
11
|
### Incorrect
|
|
12
12
|
|
|
13
|
-
```
|
|
13
|
+
```tsx
|
|
14
14
|
/** @jsx jsx */
|
|
15
15
|
import { css } from '@emotion/core';
|
|
16
16
|
import { jsx } from '@emotion/react';
|
|
17
17
|
import styled from '@emotion/styled';
|
|
18
18
|
```
|
|
19
19
|
|
|
20
|
-
```
|
|
20
|
+
```tsx
|
|
21
21
|
import styled, { css } from 'styled-components';
|
|
22
22
|
```
|
|
23
23
|
|
|
@@ -26,7 +26,7 @@ import styled, { css } from 'styled-components';
|
|
|
26
26
|
We expect usage of `xcss` with `@atlaskit/primitives` when working with Primitives, and `css` with
|
|
27
27
|
`@compiled/react` when working with custom or native code.
|
|
28
28
|
|
|
29
|
-
```
|
|
29
|
+
```tsx
|
|
30
30
|
/** @jsx jsx */
|
|
31
31
|
import { jsx, css, styled } from '@compiled/react';
|
|
32
32
|
|
|
@@ -34,7 +34,7 @@ const styles = css({ color: 'var(--ds-color-text)' });
|
|
|
34
34
|
export default () => <div css={styles}>…</div>;
|
|
35
35
|
```
|
|
36
36
|
|
|
37
|
-
```
|
|
37
|
+
```tsx
|
|
38
38
|
import { xcss, Box } from '@atlaskit/primitives';
|
|
39
39
|
|
|
40
40
|
const styles = xcss({ color: 'color.text' });
|
|
@@ -45,10 +45,10 @@ export default () => <Box xcss={styles}>…</Box>;
|
|
|
45
45
|
|
|
46
46
|
### `canAutoFix: boolean`
|
|
47
47
|
|
|
48
|
-
Determines whether or not the
|
|
48
|
+
Determines whether or not the autofixer is enabled.
|
|
49
49
|
|
|
50
50
|
Defaults to `false` due to safety concerns when mixing Compiled and other CSS-in-JS libraries on the
|
|
51
51
|
same component.
|
|
52
52
|
|
|
53
|
-
Even when enabled, the
|
|
53
|
+
Even when enabled, the autofixer will only convert usages that are deemed safe. Currently this is
|
|
54
54
|
limited to purely static styles where all keys and values are simple literals.
|
|
@@ -10,6 +10,7 @@ var _isSupportedImport = require("@atlaskit/eslint-utils/is-supported-import");
|
|
|
10
10
|
var _findVariable = require("@atlaskit/eslint-utils/find-variable");
|
|
11
11
|
var _allowedFunctionCalls = require("@atlaskit/eslint-utils/allowed-function-calls");
|
|
12
12
|
var _esquery = _interopRequireDefault(require("esquery"));
|
|
13
|
+
var _estraverse = _interopRequireDefault(require("estraverse"));
|
|
13
14
|
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; } } }; }
|
|
14
15
|
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); }
|
|
15
16
|
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; }
|
|
@@ -75,6 +76,22 @@ var isIdentifierImported = function isIdentifierImported(identifier, context, fu
|
|
|
75
76
|
});
|
|
76
77
|
};
|
|
77
78
|
var checkIdentifier = function checkIdentifier(identifier, context, functionAllowList, keysAllowList) {
|
|
79
|
+
var _ref = identifier,
|
|
80
|
+
parent = _ref.parent;
|
|
81
|
+
|
|
82
|
+
// Even though `member` in `object.member` is syntactically an identifier,
|
|
83
|
+
// it should be ignored as `.member` is syntax sugar for `['member']` here.
|
|
84
|
+
// We should still lint `object[member]` (when `parent.computed` === true)
|
|
85
|
+
if (parent.type === 'MemberExpression' && identifier === parent.property && !parent.computed) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// Even though `key` in `{ key: 'value' }` is syntactically an identifier,
|
|
90
|
+
// it should be ignored as `key` is syntax sugar for `'key'` here.
|
|
91
|
+
// We should still lint `[key]` (when `parent.computed` === true)
|
|
92
|
+
if (parent && parent.type === 'Property' && identifier === parent.key && !parent.computed) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
78
95
|
if (isIdentifierImported(identifier, context, functionAllowList, keysAllowList)) {
|
|
79
96
|
context.report({
|
|
80
97
|
node: identifier,
|
|
@@ -127,8 +144,39 @@ var rule = exports.rule = (0, _createRule.createLintRule)({
|
|
|
127
144
|
}
|
|
128
145
|
node.arguments.forEach(checkForIdentifiers);
|
|
129
146
|
},
|
|
130
|
-
'JSXAttribute[name.name=/^style|css$/]
|
|
131
|
-
|
|
147
|
+
'JSXAttribute[name.name=/^style|css$/]': function JSXAttributeNameNameStyleCss$(jsxAttribute) {
|
|
148
|
+
_estraverse.default.traverse(jsxAttribute, {
|
|
149
|
+
fallback: function fallback(node) {
|
|
150
|
+
// estraverse does not know about nodes not in the ESTree standard.
|
|
151
|
+
// This includes JSX nodes, so we must provide a fallback method to handle them.
|
|
152
|
+
// Using `fallback: 'iteration'` can cause cycles because it will iterate
|
|
153
|
+
// over the `parent` attribute on JSX nodes.
|
|
154
|
+
return Object.keys(node).filter(function (key) {
|
|
155
|
+
return key !== 'parent';
|
|
156
|
+
});
|
|
157
|
+
},
|
|
158
|
+
enter: function enter(node, parent) {
|
|
159
|
+
// Ignore type contexts
|
|
160
|
+
// Cast required because ESTree is not aware of TypeScript nodes
|
|
161
|
+
if (node.type === 'TSTypeReference') {
|
|
162
|
+
return _estraverse.default.VisitorOption.Skip;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// Ignore conditions of ternary expressions
|
|
166
|
+
if ((parent === null || parent === void 0 ? void 0 : parent.type) === 'ConditionalExpression' && node === parent.test) {
|
|
167
|
+
return _estraverse.default.VisitorOption.Skip;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// Ignore LHS of logical expressions (&&, ||)
|
|
171
|
+
if ((parent === null || parent === void 0 ? void 0 : parent.type) === 'LogicalExpression' && node === parent.left) {
|
|
172
|
+
return _estraverse.default.VisitorOption.Skip;
|
|
173
|
+
}
|
|
174
|
+
if (node.type !== 'Identifier') {
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
checkIdentifier(node, context, functionAllowList, keysAllowList);
|
|
178
|
+
}
|
|
179
|
+
});
|
|
132
180
|
}
|
|
133
181
|
};
|
|
134
182
|
}
|
|
@@ -3,6 +3,7 @@ import { getImportSources, hasStyleObjectArguments } from '@atlaskit/eslint-util
|
|
|
3
3
|
import { findVariable } from '@atlaskit/eslint-utils/find-variable';
|
|
4
4
|
import { getAllowedDynamicKeys, getAllowedFunctionCalls, isAllowListedVariable } from '@atlaskit/eslint-utils/allowed-function-calls';
|
|
5
5
|
import esquery from 'esquery';
|
|
6
|
+
import estraverse from 'estraverse';
|
|
6
7
|
const schema = [{
|
|
7
8
|
type: 'object',
|
|
8
9
|
properties: {
|
|
@@ -63,6 +64,23 @@ const isIdentifierImported = (identifier, context, functionAllowList, keysAllowL
|
|
|
63
64
|
});
|
|
64
65
|
};
|
|
65
66
|
const checkIdentifier = (identifier, context, functionAllowList, keysAllowList) => {
|
|
67
|
+
const {
|
|
68
|
+
parent
|
|
69
|
+
} = identifier;
|
|
70
|
+
|
|
71
|
+
// Even though `member` in `object.member` is syntactically an identifier,
|
|
72
|
+
// it should be ignored as `.member` is syntax sugar for `['member']` here.
|
|
73
|
+
// We should still lint `object[member]` (when `parent.computed` === true)
|
|
74
|
+
if (parent.type === 'MemberExpression' && identifier === parent.property && !parent.computed) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// Even though `key` in `{ key: 'value' }` is syntactically an identifier,
|
|
79
|
+
// it should be ignored as `key` is syntax sugar for `'key'` here.
|
|
80
|
+
// We should still lint `[key]` (when `parent.computed` === true)
|
|
81
|
+
if (parent && parent.type === 'Property' && identifier === parent.key && !parent.computed) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
66
84
|
if (isIdentifierImported(identifier, context, functionAllowList, keysAllowList)) {
|
|
67
85
|
context.report({
|
|
68
86
|
node: identifier,
|
|
@@ -107,8 +125,37 @@ export const rule = createLintRule({
|
|
|
107
125
|
}
|
|
108
126
|
node.arguments.forEach(checkForIdentifiers);
|
|
109
127
|
},
|
|
110
|
-
'JSXAttribute[name.name=/^style|css$/]
|
|
111
|
-
|
|
128
|
+
'JSXAttribute[name.name=/^style|css$/]'(jsxAttribute) {
|
|
129
|
+
estraverse.traverse(jsxAttribute, {
|
|
130
|
+
fallback(node) {
|
|
131
|
+
// estraverse does not know about nodes not in the ESTree standard.
|
|
132
|
+
// This includes JSX nodes, so we must provide a fallback method to handle them.
|
|
133
|
+
// Using `fallback: 'iteration'` can cause cycles because it will iterate
|
|
134
|
+
// over the `parent` attribute on JSX nodes.
|
|
135
|
+
return Object.keys(node).filter(key => key !== 'parent');
|
|
136
|
+
},
|
|
137
|
+
enter(node, parent) {
|
|
138
|
+
// Ignore type contexts
|
|
139
|
+
// Cast required because ESTree is not aware of TypeScript nodes
|
|
140
|
+
if (node.type === 'TSTypeReference') {
|
|
141
|
+
return estraverse.VisitorOption.Skip;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// Ignore conditions of ternary expressions
|
|
145
|
+
if ((parent === null || parent === void 0 ? void 0 : parent.type) === 'ConditionalExpression' && node === parent.test) {
|
|
146
|
+
return estraverse.VisitorOption.Skip;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// Ignore LHS of logical expressions (&&, ||)
|
|
150
|
+
if ((parent === null || parent === void 0 ? void 0 : parent.type) === 'LogicalExpression' && node === parent.left) {
|
|
151
|
+
return estraverse.VisitorOption.Skip;
|
|
152
|
+
}
|
|
153
|
+
if (node.type !== 'Identifier') {
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
checkIdentifier(node, context, functionAllowList, keysAllowList);
|
|
157
|
+
}
|
|
158
|
+
});
|
|
112
159
|
}
|
|
113
160
|
};
|
|
114
161
|
}
|
|
@@ -6,6 +6,7 @@ import { getImportSources, hasStyleObjectArguments } from '@atlaskit/eslint-util
|
|
|
6
6
|
import { findVariable } from '@atlaskit/eslint-utils/find-variable';
|
|
7
7
|
import { getAllowedDynamicKeys, getAllowedFunctionCalls, isAllowListedVariable } from '@atlaskit/eslint-utils/allowed-function-calls';
|
|
8
8
|
import esquery from 'esquery';
|
|
9
|
+
import estraverse from 'estraverse';
|
|
9
10
|
var schema = [{
|
|
10
11
|
type: 'object',
|
|
11
12
|
properties: {
|
|
@@ -68,6 +69,22 @@ var isIdentifierImported = function isIdentifierImported(identifier, context, fu
|
|
|
68
69
|
});
|
|
69
70
|
};
|
|
70
71
|
var checkIdentifier = function checkIdentifier(identifier, context, functionAllowList, keysAllowList) {
|
|
72
|
+
var _ref = identifier,
|
|
73
|
+
parent = _ref.parent;
|
|
74
|
+
|
|
75
|
+
// Even though `member` in `object.member` is syntactically an identifier,
|
|
76
|
+
// it should be ignored as `.member` is syntax sugar for `['member']` here.
|
|
77
|
+
// We should still lint `object[member]` (when `parent.computed` === true)
|
|
78
|
+
if (parent.type === 'MemberExpression' && identifier === parent.property && !parent.computed) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// Even though `key` in `{ key: 'value' }` is syntactically an identifier,
|
|
83
|
+
// it should be ignored as `key` is syntax sugar for `'key'` here.
|
|
84
|
+
// We should still lint `[key]` (when `parent.computed` === true)
|
|
85
|
+
if (parent && parent.type === 'Property' && identifier === parent.key && !parent.computed) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
71
88
|
if (isIdentifierImported(identifier, context, functionAllowList, keysAllowList)) {
|
|
72
89
|
context.report({
|
|
73
90
|
node: identifier,
|
|
@@ -120,8 +137,39 @@ export var rule = createLintRule({
|
|
|
120
137
|
}
|
|
121
138
|
node.arguments.forEach(checkForIdentifiers);
|
|
122
139
|
},
|
|
123
|
-
'JSXAttribute[name.name=/^style|css$/]
|
|
124
|
-
|
|
140
|
+
'JSXAttribute[name.name=/^style|css$/]': function JSXAttributeNameNameStyleCss$(jsxAttribute) {
|
|
141
|
+
estraverse.traverse(jsxAttribute, {
|
|
142
|
+
fallback: function fallback(node) {
|
|
143
|
+
// estraverse does not know about nodes not in the ESTree standard.
|
|
144
|
+
// This includes JSX nodes, so we must provide a fallback method to handle them.
|
|
145
|
+
// Using `fallback: 'iteration'` can cause cycles because it will iterate
|
|
146
|
+
// over the `parent` attribute on JSX nodes.
|
|
147
|
+
return Object.keys(node).filter(function (key) {
|
|
148
|
+
return key !== 'parent';
|
|
149
|
+
});
|
|
150
|
+
},
|
|
151
|
+
enter: function enter(node, parent) {
|
|
152
|
+
// Ignore type contexts
|
|
153
|
+
// Cast required because ESTree is not aware of TypeScript nodes
|
|
154
|
+
if (node.type === 'TSTypeReference') {
|
|
155
|
+
return estraverse.VisitorOption.Skip;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// Ignore conditions of ternary expressions
|
|
159
|
+
if ((parent === null || parent === void 0 ? void 0 : parent.type) === 'ConditionalExpression' && node === parent.test) {
|
|
160
|
+
return estraverse.VisitorOption.Skip;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// Ignore LHS of logical expressions (&&, ||)
|
|
164
|
+
if ((parent === null || parent === void 0 ? void 0 : parent.type) === 'LogicalExpression' && node === parent.left) {
|
|
165
|
+
return estraverse.VisitorOption.Skip;
|
|
166
|
+
}
|
|
167
|
+
if (node.type !== 'Identifier') {
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
checkIdentifier(node, context, functionAllowList, keysAllowList);
|
|
171
|
+
}
|
|
172
|
+
});
|
|
125
173
|
}
|
|
126
174
|
};
|
|
127
175
|
}
|
package/package.json
CHANGED
|
@@ -1,111 +1,130 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
Blocks legacy `@atlaskit/theme` mixins that `@compiled/react` cannot compile. This includes the
|
|
2
|
+
`typography`, `elevation` and `skeletonShimmer` mixins.
|
|
3
3
|
|
|
4
4
|
## Examples
|
|
5
5
|
|
|
6
6
|
### Typography
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
Don't use `typography` mixins.
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
Use [typography tokens](https://atlassian.design/foundations/typography-beta/applying-typography) or
|
|
11
|
+
the [Heading](https://atlassian.design/components/heading) and
|
|
12
|
+
[Text](https://atlassian.design/components/primitives/text) components.
|
|
11
13
|
|
|
12
|
-
|
|
13
|
-
import { styled } from '@compiled/react';
|
|
14
|
-
import { typography } from '@atlaskit/theme';
|
|
15
|
-
|
|
16
|
-
export const HeadingComponent = styled.h2`
|
|
17
|
-
${typography.h200()};
|
|
18
|
-
`;
|
|
19
|
-
```
|
|
14
|
+
#### Incorrect
|
|
20
15
|
|
|
21
16
|
```tsx
|
|
22
|
-
import {
|
|
17
|
+
import { css } from '@compiled/react';
|
|
23
18
|
import { typography } from '@atlaskit/theme';
|
|
24
19
|
|
|
25
|
-
|
|
20
|
+
const titleStyles = css(typography.h700());
|
|
26
21
|
```
|
|
27
22
|
|
|
28
|
-
|
|
23
|
+
#### Correct
|
|
29
24
|
|
|
30
25
|
```tsx
|
|
31
|
-
import {
|
|
26
|
+
import { css } from '@compiled/react';
|
|
27
|
+
import { token } from '@atlaskit/tokens';
|
|
32
28
|
|
|
33
|
-
const
|
|
34
|
-
|
|
29
|
+
const titleStyles = css({
|
|
30
|
+
font: token('font.heading.large'),
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
const paragraphStyles = css({
|
|
34
|
+
font: token('font.body.large'),
|
|
35
35
|
});
|
|
36
36
|
```
|
|
37
37
|
|
|
38
38
|
```tsx
|
|
39
|
+
import { css } from '@compiled/react';
|
|
39
40
|
import Heading from '@atlaskit/heading';
|
|
41
|
+
import { Stack, Text } from '@atlaskit/primitives';
|
|
40
42
|
import { token } from '@atlaskit/tokens';
|
|
41
|
-
import { styled } from '@compiled/react';
|
|
42
43
|
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
<Heading level="h200" as="h3">
|
|
49
|
-
<TitleComponent {...props} />
|
|
50
|
-
</Heading>
|
|
44
|
+
const Component = () => (
|
|
45
|
+
<Stack>
|
|
46
|
+
<Heading size="large">Title</Heading>
|
|
47
|
+
<Text size="large">Lorem ipsum</Text>
|
|
48
|
+
</Stack>
|
|
51
49
|
);
|
|
52
50
|
```
|
|
53
51
|
|
|
54
52
|
### Elevation
|
|
55
53
|
|
|
56
|
-
|
|
54
|
+
Don't use `elevation` mixins.
|
|
55
|
+
|
|
56
|
+
Use [elevation tokens](https://atlassian.design/foundations/elevation) instead.
|
|
57
57
|
|
|
58
|
-
|
|
58
|
+
#### Incorrect
|
|
59
59
|
|
|
60
60
|
```tsx
|
|
61
|
-
import {
|
|
61
|
+
import { css } from '@compiled/react';
|
|
62
62
|
import { elevation } from '@atlaskit/theme';
|
|
63
63
|
|
|
64
|
-
|
|
65
|
-
${elevation.e100()};
|
|
66
|
-
`;
|
|
64
|
+
const cardStyles = css(elevation.e100());
|
|
67
65
|
```
|
|
68
66
|
|
|
69
|
-
|
|
67
|
+
#### Correct
|
|
70
68
|
|
|
71
69
|
```tsx
|
|
72
70
|
import { styled } from '@compiled/react';
|
|
73
71
|
import { token } from '@atlaskit/tokens';
|
|
74
72
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
'0 1px 1px rgba(9,30,66,0.25),0 0 1px 1px rgba(9,30,66,0.13)',
|
|
79
|
-
),
|
|
73
|
+
const cardStyles = css({
|
|
74
|
+
backgroundColor: token('elevation.surface.raised'),
|
|
75
|
+
boxShadow: token('elevation.shadow.raised'),
|
|
80
76
|
});
|
|
81
77
|
```
|
|
82
78
|
|
|
83
79
|
### Skeleton Shimmer
|
|
84
80
|
|
|
85
|
-
|
|
86
|
-
[link](https://staging.atlassian.design/components/skeleton/examples)).
|
|
81
|
+
Don't use the `skeletonShimmer` mixin.
|
|
87
82
|
|
|
88
|
-
|
|
83
|
+
Preview our [Skeleton](https://staging.atlassian.design/components/skeleton/examples) component
|
|
84
|
+
(internal Atlassians only).
|
|
89
85
|
|
|
90
|
-
|
|
86
|
+
Otherwise:
|
|
87
|
+
|
|
88
|
+
- Use the `color.skeleton` and `color.skeleton.subtle` tokens to make your own component.
|
|
89
|
+
- Use `@atlassian/jira-skeletons` when working on Jira (internal Atlassians only).
|
|
90
|
+
|
|
91
|
+
#### Incorrect
|
|
91
92
|
|
|
92
93
|
```tsx
|
|
93
|
-
import {
|
|
94
|
+
import { css } from '@compiled/react';
|
|
94
95
|
import { skeletonShimmer } from '@atlaskit/theme/constants';
|
|
95
96
|
|
|
96
|
-
|
|
97
|
-
${skeletonShimmer};
|
|
98
|
-
`;
|
|
97
|
+
const skeletonStyles = css(skeletonShimmer());
|
|
99
98
|
```
|
|
100
99
|
|
|
101
|
-
|
|
100
|
+
#### Correct
|
|
101
|
+
|
|
102
|
+
```tsx
|
|
103
|
+
import Skeleton from '@atlaskit/skeleton';
|
|
104
|
+
|
|
105
|
+
<Skeleton width="200px" height="16px" isShimmering />;
|
|
106
|
+
```
|
|
102
107
|
|
|
103
108
|
```tsx
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
109
|
+
import { css, keyframes } from '@compiled/react';
|
|
110
|
+
|
|
111
|
+
const shimmer = keyframes({
|
|
112
|
+
from: { backgroundColor: token('color.skeleton') },
|
|
113
|
+
to: { backgroundColor: token('color.skeleton.subtle') },
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
const skeletonStyles = css({
|
|
117
|
+
backgroundColor: token('color.skeleton'),
|
|
118
|
+
animationName: shimmer,
|
|
119
|
+
animationDuration: '1.5s',
|
|
120
|
+
animationIterationCount: 'infinite',
|
|
121
|
+
animationTimingFunction: 'linear',
|
|
122
|
+
animationDirection: 'alternate',
|
|
123
|
+
});
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
```tsx
|
|
127
|
+
import { ListSkeleton } from '@atlassian/jira-skeletons';
|
|
128
|
+
|
|
129
|
+
<ListSkeleton numOfRows={3} />;
|
|
111
130
|
```
|
|
@@ -1,11 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
`no-styled-tagged-template-expression`, as output from the latter may use props syntax that results
|
|
4
|
-
in a type error.
|
|
1
|
+
Blocks dynamic styling syntax that is unsupported by `styled-components@<4` and `@emotion/styled`,
|
|
2
|
+
and provides an autofix for converting to a supported syntax.
|
|
5
3
|
|
|
6
|
-
|
|
4
|
+
Use this rule alongside `no-styled-tagged-template-expression`, which can output the unsupported
|
|
5
|
+
dynamic styling syntax.
|
|
7
6
|
|
|
8
|
-
|
|
7
|
+
This rule applies only to `styled` usages from `styled-components` and `@emotion/styled`.
|
|
8
|
+
|
|
9
|
+
## Autofix
|
|
10
|
+
|
|
11
|
+
The autofix will find style object values that are arrow functions,
|
|
12
|
+
|
|
13
|
+
```tsx
|
|
9
14
|
styled.div({
|
|
10
15
|
color: ({ myColor }) => myColor,
|
|
11
16
|
backgroundColor: (props) => props.someColor,
|
|
@@ -15,7 +20,7 @@ styled.div({
|
|
|
15
20
|
However, refactoring the arrow function so that it is the argument to `styled.div` will fix the
|
|
16
21
|
issue:
|
|
17
22
|
|
|
18
|
-
```
|
|
23
|
+
```tsx
|
|
19
24
|
styled.div((props) => ({
|
|
20
25
|
color: props.myColor,
|
|
21
26
|
backgroundColor: props.someColor,
|
|
@@ -38,47 +43,47 @@ manually fix the output, or migrate the code to `@compiled/react`.
|
|
|
38
43
|
Type annotations in the arrow function are not supported; you will need to remediate the lint error
|
|
39
44
|
manually. For example:
|
|
40
45
|
|
|
41
|
-
```
|
|
46
|
+
```tsx
|
|
42
47
|
type Props = {
|
|
43
|
-
|
|
44
|
-
|
|
48
|
+
myColor: string;
|
|
49
|
+
someColor: string;
|
|
45
50
|
};
|
|
46
51
|
|
|
47
52
|
styled.div({
|
|
48
|
-
|
|
49
|
-
|
|
53
|
+
color: ({ myColor }: Props) => myColor,
|
|
54
|
+
backgroundColor: (props: Props) => props.someColor,
|
|
50
55
|
});
|
|
51
56
|
```
|
|
52
57
|
|
|
53
|
-
|
|
58
|
+
could be refactored as
|
|
54
59
|
|
|
55
|
-
```
|
|
60
|
+
```tsx
|
|
56
61
|
type Props = {
|
|
57
|
-
|
|
58
|
-
|
|
62
|
+
myColor: string;
|
|
63
|
+
someColor: string;
|
|
59
64
|
};
|
|
60
65
|
|
|
61
66
|
styled.div((props: Props) => ({
|
|
62
|
-
|
|
63
|
-
|
|
67
|
+
color: props.myColor,
|
|
68
|
+
backgroundColor: props.someColor,
|
|
64
69
|
}));
|
|
65
70
|
```
|
|
66
71
|
|
|
67
|
-
### Special syntax in
|
|
72
|
+
### Special syntax in function parameters
|
|
68
73
|
|
|
69
74
|
Rest elements, default values, and so on in the parameter of an arrow function will need to be
|
|
70
75
|
remediated manually. For example:
|
|
71
76
|
|
|
72
|
-
```
|
|
77
|
+
```tsx
|
|
73
78
|
styled.div({
|
|
74
79
|
color: ({ myColor = '#fff' }) => myColor,
|
|
75
80
|
backgroundColor: ({ myColor = '#aaa' }) => myColor,
|
|
76
81
|
});
|
|
77
82
|
```
|
|
78
83
|
|
|
79
|
-
could
|
|
84
|
+
could be refactored as
|
|
80
85
|
|
|
81
|
-
```
|
|
86
|
+
```tsx
|
|
82
87
|
styled.div((props) => ({
|
|
83
88
|
color: myColor ?? '#fff',
|
|
84
89
|
backgroundColor: myColor ?? '#aaa',
|
|
@@ -89,7 +94,7 @@ styled.div((props) => ({
|
|
|
89
94
|
|
|
90
95
|
### Incorrect
|
|
91
96
|
|
|
92
|
-
```
|
|
97
|
+
```tsx
|
|
93
98
|
import styled from 'styled-components';
|
|
94
99
|
|
|
95
100
|
styled.div({
|
|
@@ -104,7 +109,7 @@ styled.div({
|
|
|
104
109
|
|
|
105
110
|
### Correct
|
|
106
111
|
|
|
107
|
-
```
|
|
112
|
+
```tsx
|
|
108
113
|
import styled from '@emotion/styled';
|
|
109
114
|
|
|
110
115
|
styled.div((props) => ({
|
|
@@ -1,39 +1,45 @@
|
|
|
1
|
-
|
|
1
|
+
Blocks providing static values through the `style` prop, which should only be used to provide
|
|
2
|
+
dynamic values (values unknown at build time).
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
time, e.g. `<div style={{ width: props.width }}>`. No statics values such as numbers, strings or any
|
|
5
|
-
other statically analysable values should be passed to the `style` attribute. Instead, static CSS
|
|
6
|
-
values should be passed into the `css` prop in JSX components.
|
|
4
|
+
Use the `css` prop for providing static values instead.
|
|
7
5
|
|
|
8
6
|
## Examples
|
|
9
7
|
|
|
10
8
|
### Incorrect
|
|
11
9
|
|
|
12
10
|
```tsx
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
11
|
+
import { token } from '@atlaskit/tokens';
|
|
12
|
+
|
|
13
|
+
const Component = () => (
|
|
14
|
+
<div
|
|
15
|
+
style={{
|
|
16
|
+
margin: 0,
|
|
17
|
+
color: token('color.text.danger'),
|
|
18
|
+
}}
|
|
19
|
+
/>
|
|
20
|
+
);
|
|
23
21
|
```
|
|
24
22
|
|
|
25
23
|
### Correct
|
|
26
24
|
|
|
25
|
+
Although `token` is a function call, it is statically resolvable by Compiled and should not be used
|
|
26
|
+
in the `style` prop.
|
|
27
|
+
|
|
27
28
|
```tsx
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
29
|
+
import { css } from '@compiled/react';
|
|
30
|
+
import { token } from '@atlaskit/tokens';
|
|
31
|
+
|
|
32
|
+
type Props = { width: string };
|
|
33
|
+
|
|
34
|
+
const baseStyles = css({ margin: 0, color: token('color.text.danger') });
|
|
35
|
+
|
|
36
|
+
const Component = ({ width }: Props) => (
|
|
37
|
+
<div
|
|
38
|
+
css={baseStyles}
|
|
39
|
+
style={{
|
|
40
|
+
width: props.width,
|
|
41
|
+
'--my-nested-width': props.width,
|
|
42
|
+
}}
|
|
43
|
+
/>
|
|
44
|
+
);
|
|
39
45
|
```
|