@atlaskit/eslint-plugin-ui-styling-standard 0.11.6 → 0.12.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 +9 -0
- package/README.md +1 -0
- package/constellation/index/overview.mdx +1 -0
- package/constellation/use-compiled/usage.mdx +51 -0
- package/dist/cjs/presets/all.codegen.js +2 -1
- package/dist/cjs/presets/recommended.codegen.js +2 -1
- package/dist/cjs/rules/index.codegen.js +4 -2
- package/dist/cjs/rules/use-compiled/index.js +257 -0
- package/dist/cjs/rules/use-compiled/is-safe.js +130 -0
- package/dist/cjs/rules/use-compiled/utils.js +26 -0
- package/dist/es2019/presets/all.codegen.js +2 -1
- package/dist/es2019/presets/recommended.codegen.js +2 -1
- package/dist/es2019/rules/index.codegen.js +4 -2
- package/dist/es2019/rules/use-compiled/index.js +182 -0
- package/dist/es2019/rules/use-compiled/is-safe.js +118 -0
- package/dist/es2019/rules/use-compiled/utils.js +15 -0
- package/dist/esm/presets/all.codegen.js +2 -1
- package/dist/esm/presets/recommended.codegen.js +2 -1
- package/dist/esm/rules/index.codegen.js +4 -2
- package/dist/esm/rules/use-compiled/index.js +250 -0
- package/dist/esm/rules/use-compiled/is-safe.js +121 -0
- package/dist/esm/rules/use-compiled/utils.js +17 -0
- package/dist/types/index.codegen.d.ts +2 -0
- package/dist/types/presets/all.codegen.d.ts +2 -1
- package/dist/types/presets/recommended.codegen.d.ts +2 -1
- package/dist/types/rules/index.codegen.d.ts +1 -0
- package/dist/types/rules/use-compiled/index.d.ts +3 -0
- package/dist/types/rules/use-compiled/is-safe.d.ts +10 -0
- package/dist/types/rules/use-compiled/utils.d.ts +6 -0
- package/dist/types-ts4.5/index.codegen.d.ts +2 -0
- package/dist/types-ts4.5/presets/all.codegen.d.ts +2 -1
- package/dist/types-ts4.5/presets/recommended.codegen.d.ts +2 -1
- package/dist/types-ts4.5/rules/index.codegen.d.ts +1 -0
- package/dist/types-ts4.5/rules/use-compiled/index.d.ts +3 -0
- package/dist/types-ts4.5/rules/use-compiled/is-safe.d.ts +10 -0
- package/dist/types-ts4.5/rules/use-compiled/utils.d.ts +6 -0
- package/package.json +3 -2
- package/src/presets/all.codegen.tsx +2 -1
- package/src/presets/recommended.codegen.tsx +2 -1
- package/src/rules/index.codegen.tsx +3 -1
- package/src/rules/use-compiled/README.md +49 -0
- package/src/rules/use-compiled/__tests__/can-auto-fix.test.tsx +73 -0
- package/src/rules/use-compiled/__tests__/css.test.tsx +126 -0
- package/src/rules/use-compiled/__tests__/imports.test.tsx +139 -0
- package/src/rules/use-compiled/__tests__/keyframes.test.tsx +140 -0
- package/src/rules/use-compiled/__tests__/pragma.test.tsx +108 -0
- package/src/rules/use-compiled/__tests__/styled.test.tsx +114 -0
- package/src/rules/use-compiled/__tests__/use-compiled.test.tsx +15 -0
- package/src/rules/use-compiled/index.tsx +275 -0
- package/src/rules/use-compiled/is-safe.tsx +163 -0
- package/src/rules/use-compiled/utils.tsx +37 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# @atlaskit/eslint-plugin-ui-styling-standard
|
|
2
2
|
|
|
3
|
+
## 0.12.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#96162](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/96162)
|
|
8
|
+
[`d68864c620d0`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/d68864c620d0) -
|
|
9
|
+
Add `use-compiled` rule to enforce usage of `@compiled/react` instead of other CSS-in-JS
|
|
10
|
+
libraries
|
|
11
|
+
|
|
3
12
|
## 0.11.6
|
|
4
13
|
|
|
5
14
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -55,6 +55,7 @@ module.exports = {
|
|
|
55
55
|
| <a href="./src/rules/no-imported-style-values/README.md">no-imported-style-values</a> | Disallows imports of style values | Yes | | |
|
|
56
56
|
| <a href="./src/rules/no-nested-selectors/README.md">no-nested-selectors</a> | Prevents usage of nested selectors within css styling | Yes | | |
|
|
57
57
|
| <a href="./src/rules/no-unsafe-values/README.md">no-unsafe-values</a> | Disallows styles that are difficult/impossible to statically anaylze. | Yes | | |
|
|
58
|
+
| <a href="./src/rules/use-compiled/README.md">use-compiled</a> | Ensures usage of `@compiled/react` instead of other CSS-in-JS libraries | Yes | Yes | |
|
|
58
59
|
| <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 | |
|
|
59
60
|
| <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 | |
|
|
60
61
|
| <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 | |
|
|
@@ -24,6 +24,7 @@ but more are planned to support the standard over time.
|
|
|
24
24
|
| <a href="no-imported-style-values/usage">no-imported-style-values</a> | Disallows imports of style values | Yes | | |
|
|
25
25
|
| <a href="no-nested-selectors/usage">no-nested-selectors</a> | Prevents usage of nested selectors within css styling | Yes | | |
|
|
26
26
|
| <a href="no-unsafe-values/usage">no-unsafe-values</a> | Disallows styles that are difficult/impossible to statically anaylze. | Yes | | |
|
|
27
|
+
| <a href="use-compiled/usage">use-compiled</a> | Ensures usage of `@compiled/react` instead of other CSS-in-JS libraries | Yes | Yes | |
|
|
27
28
|
| <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 | |
|
|
28
29
|
| <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 | |
|
|
29
30
|
| <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 | |
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# use-compiled
|
|
2
|
+
|
|
3
|
+
Ensures usage of `@compiled/react` over other CSS-in-JS libraries.
|
|
4
|
+
|
|
5
|
+
**WARNING**
|
|
6
|
+
|
|
7
|
+
It may be unsafe to mix usages of `@compiled/react` with other CSS-in-JS libraries.
|
|
8
|
+
|
|
9
|
+
When converting to `@compiled/react` verify ALL changes.
|
|
10
|
+
|
|
11
|
+
For this reason, the auto-fixer has been disabled by default.
|
|
12
|
+
|
|
13
|
+
## Examples
|
|
14
|
+
|
|
15
|
+
### Incorrect
|
|
16
|
+
|
|
17
|
+
```js
|
|
18
|
+
import { css } from '@emotion/core';
|
|
19
|
+
import styled from '@emotion/styled';
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
```js
|
|
23
|
+
/** @jsx jsx */
|
|
24
|
+
import { jsx } from '@emotion/react';
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
```js
|
|
28
|
+
import styled, { css } from 'styled-components';
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### Correct
|
|
32
|
+
|
|
33
|
+
```js
|
|
34
|
+
import { css, styled } from '@compiled/react';
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
```js
|
|
38
|
+
/** @jsx jsx */
|
|
39
|
+
import { jsx } from '@compiled/react';
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Options
|
|
43
|
+
|
|
44
|
+
### `canAutoFix: boolean`
|
|
45
|
+
|
|
46
|
+
Determines whether or not the auto-fixer is enabled.
|
|
47
|
+
|
|
48
|
+
Defaults to `false` due to safety concerns when mixing Compiled and other CSS-in-JS libraries.
|
|
49
|
+
|
|
50
|
+
Even when enabled, the auto-fixer will only convert usages that are deemed safe. Currently this is
|
|
51
|
+
limited to purely static styles where all keys and values are simple literals.
|
|
@@ -6,7 +6,7 @@ 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::752a442dd46681814ab73f7fa9c05374>>
|
|
10
10
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
11
11
|
*/
|
|
12
12
|
var _default = exports.default = {
|
|
@@ -25,6 +25,7 @@ var _default = exports.default = {
|
|
|
25
25
|
'@atlaskit/ui-styling-standard/no-imported-style-values': 'warn',
|
|
26
26
|
'@atlaskit/ui-styling-standard/no-nested-selectors': 'warn',
|
|
27
27
|
'@atlaskit/ui-styling-standard/no-unsafe-values': 'warn',
|
|
28
|
+
'@atlaskit/ui-styling-standard/use-compiled': 'warn',
|
|
28
29
|
'@atlaskit/design-system/consistent-css-prop-usage': ['warn', {
|
|
29
30
|
excludeReactComponents: true
|
|
30
31
|
}],
|
|
@@ -6,7 +6,7 @@ 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::752a442dd46681814ab73f7fa9c05374>>
|
|
10
10
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
11
11
|
*/
|
|
12
12
|
var _default = exports.default = {
|
|
@@ -25,6 +25,7 @@ var _default = exports.default = {
|
|
|
25
25
|
'@atlaskit/ui-styling-standard/no-imported-style-values': 'warn',
|
|
26
26
|
'@atlaskit/ui-styling-standard/no-nested-selectors': 'warn',
|
|
27
27
|
'@atlaskit/ui-styling-standard/no-unsafe-values': 'warn',
|
|
28
|
+
'@atlaskit/ui-styling-standard/use-compiled': 'warn',
|
|
28
29
|
'@atlaskit/design-system/consistent-css-prop-usage': ['warn', {
|
|
29
30
|
excludeReactComponents: true
|
|
30
31
|
}],
|
|
@@ -18,9 +18,10 @@ var _noImportantStyles = _interopRequireDefault(require("./no-important-styles")
|
|
|
18
18
|
var _noImportedStyleValues = _interopRequireDefault(require("./no-imported-style-values"));
|
|
19
19
|
var _noNestedSelectors = _interopRequireDefault(require("./no-nested-selectors"));
|
|
20
20
|
var _noUnsafeValues = _interopRequireDefault(require("./no-unsafe-values"));
|
|
21
|
+
var _useCompiled = _interopRequireDefault(require("./use-compiled"));
|
|
21
22
|
/**
|
|
22
23
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
23
|
-
* @codegen <<SignedSource::
|
|
24
|
+
* @codegen <<SignedSource::be177a361ddc1a7a41d843680299e318>>
|
|
24
25
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
25
26
|
*/
|
|
26
27
|
var _default = exports.default = {
|
|
@@ -36,5 +37,6 @@ var _default = exports.default = {
|
|
|
36
37
|
'no-important-styles': _noImportantStyles.default,
|
|
37
38
|
'no-imported-style-values': _noImportedStyleValues.default,
|
|
38
39
|
'no-nested-selectors': _noNestedSelectors.default,
|
|
39
|
-
'no-unsafe-values': _noUnsafeValues.default
|
|
40
|
+
'no-unsafe-values': _noUnsafeValues.default,
|
|
41
|
+
'use-compiled': _useCompiled.default
|
|
40
42
|
};
|
|
@@ -0,0 +1,257 @@
|
|
|
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 _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
9
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
10
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
11
|
+
var _eslintCodemodUtils = require("eslint-codemod-utils");
|
|
12
|
+
var _findVariable = require("@atlaskit/eslint-utils/find-variable");
|
|
13
|
+
var _createRule = require("../utils/create-rule");
|
|
14
|
+
var _utils = require("./utils");
|
|
15
|
+
var _isSafe = require("./is-safe");
|
|
16
|
+
var SUPPORTED_EMOTION_IMPORTS = new Set(['css', 'keyframes', 'ClassNames', 'jsx']);
|
|
17
|
+
var SUPPORTED_IMPORT_MAP = {
|
|
18
|
+
'@emotion/core': SUPPORTED_EMOTION_IMPORTS,
|
|
19
|
+
'@emotion/react': SUPPORTED_EMOTION_IMPORTS,
|
|
20
|
+
'@emotion/styled': new Set(['default']),
|
|
21
|
+
'styled-components': new Set(['default', 'css', 'keyframes'])
|
|
22
|
+
};
|
|
23
|
+
function isSupportedImportSource(importSource) {
|
|
24
|
+
return importSource in SUPPORTED_IMPORT_MAP;
|
|
25
|
+
}
|
|
26
|
+
var schema = {
|
|
27
|
+
type: 'array',
|
|
28
|
+
items: [{
|
|
29
|
+
type: 'object',
|
|
30
|
+
properties: {
|
|
31
|
+
canAutoFix: {
|
|
32
|
+
type: 'boolean'
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
additionalProperties: false
|
|
36
|
+
}]
|
|
37
|
+
};
|
|
38
|
+
var defaultConfig = {
|
|
39
|
+
canAutoFix: false
|
|
40
|
+
};
|
|
41
|
+
function readConfig(context) {
|
|
42
|
+
var _ref = context.options,
|
|
43
|
+
_ref2 = (0, _slicedToArray2.default)(_ref, 1),
|
|
44
|
+
config = _ref2[0];
|
|
45
|
+
return Object.assign({}, defaultConfig, config);
|
|
46
|
+
}
|
|
47
|
+
var rule = exports.rule = (0, _createRule.createLintRule)({
|
|
48
|
+
meta: {
|
|
49
|
+
name: 'use-compiled',
|
|
50
|
+
type: 'problem',
|
|
51
|
+
fixable: 'code',
|
|
52
|
+
docs: {
|
|
53
|
+
description: 'Ensures usage of `@compiled/react` instead of other CSS-in-JS libraries',
|
|
54
|
+
recommended: true,
|
|
55
|
+
severity: 'warn'
|
|
56
|
+
},
|
|
57
|
+
messages: {
|
|
58
|
+
'use-compiled': "Use '@compiled/react' instead of '{{importSource}}'"
|
|
59
|
+
},
|
|
60
|
+
schema: schema
|
|
61
|
+
},
|
|
62
|
+
create: function create(context) {
|
|
63
|
+
var config = readConfig(context);
|
|
64
|
+
return {
|
|
65
|
+
Program: function Program() {
|
|
66
|
+
var pragma = context.getSourceCode().getAllComments().find(function (n) {
|
|
67
|
+
return n.value.includes('@jsxImportSource @emotion/react');
|
|
68
|
+
});
|
|
69
|
+
if (!pragma) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
context.report({
|
|
73
|
+
messageId: 'use-compiled',
|
|
74
|
+
data: {
|
|
75
|
+
importSource: '@emotion/react'
|
|
76
|
+
},
|
|
77
|
+
loc: pragma.loc,
|
|
78
|
+
fix: /*#__PURE__*/_regenerator.default.mark(function fix(fixer) {
|
|
79
|
+
var importDeclarations, hasEmotionImport, hasCompiledImport;
|
|
80
|
+
return _regenerator.default.wrap(function fix$(_context) {
|
|
81
|
+
while (1) switch (_context.prev = _context.next) {
|
|
82
|
+
case 0:
|
|
83
|
+
if (config.canAutoFix) {
|
|
84
|
+
_context.next = 2;
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
return _context.abrupt("return");
|
|
88
|
+
case 2:
|
|
89
|
+
importDeclarations = context.getSourceCode().ast.body.filter(function (node) {
|
|
90
|
+
return node.type === 'ImportDeclaration';
|
|
91
|
+
});
|
|
92
|
+
hasEmotionImport = importDeclarations.some(function (importDeclaration) {
|
|
93
|
+
var importSource = importDeclaration.source.value;
|
|
94
|
+
return importSource.startsWith('@emotion/');
|
|
95
|
+
});
|
|
96
|
+
hasCompiledImport = importDeclarations.some(function (importDeclaration) {
|
|
97
|
+
return importDeclaration.source.value === '@compiled/react';
|
|
98
|
+
});
|
|
99
|
+
if (!(hasEmotionImport || !hasCompiledImport)) {
|
|
100
|
+
_context.next = 7;
|
|
101
|
+
break;
|
|
102
|
+
}
|
|
103
|
+
return _context.abrupt("return");
|
|
104
|
+
case 7:
|
|
105
|
+
_context.next = 9;
|
|
106
|
+
return fixer.replaceText(
|
|
107
|
+
// @ts-expect-error - types don't accept comment nodes
|
|
108
|
+
pragma, "/** @jsxImportSource @compiled/react */");
|
|
109
|
+
case 9:
|
|
110
|
+
case "end":
|
|
111
|
+
return _context.stop();
|
|
112
|
+
}
|
|
113
|
+
}, fix);
|
|
114
|
+
})
|
|
115
|
+
});
|
|
116
|
+
},
|
|
117
|
+
ImportDeclaration: function (_ImportDeclaration) {
|
|
118
|
+
function ImportDeclaration(_x) {
|
|
119
|
+
return _ImportDeclaration.apply(this, arguments);
|
|
120
|
+
}
|
|
121
|
+
ImportDeclaration.toString = function () {
|
|
122
|
+
return _ImportDeclaration.toString();
|
|
123
|
+
};
|
|
124
|
+
return ImportDeclaration;
|
|
125
|
+
}(function (node) {
|
|
126
|
+
var importSource = node.source.value;
|
|
127
|
+
if (!isSupportedImportSource(importSource)) {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
context.report({
|
|
131
|
+
node: node.source,
|
|
132
|
+
messageId: 'use-compiled',
|
|
133
|
+
data: {
|
|
134
|
+
importSource: importSource
|
|
135
|
+
},
|
|
136
|
+
fix: /*#__PURE__*/_regenerator.default.mark(function fix(fixer) {
|
|
137
|
+
var specifiers;
|
|
138
|
+
return _regenerator.default.wrap(function fix$(_context2) {
|
|
139
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
140
|
+
case 0:
|
|
141
|
+
if (config.canAutoFix) {
|
|
142
|
+
_context2.next = 2;
|
|
143
|
+
break;
|
|
144
|
+
}
|
|
145
|
+
return _context2.abrupt("return");
|
|
146
|
+
case 2:
|
|
147
|
+
specifiers = getSpecifiers({
|
|
148
|
+
context: context,
|
|
149
|
+
node: node,
|
|
150
|
+
importSource: importSource
|
|
151
|
+
});
|
|
152
|
+
if (specifiers) {
|
|
153
|
+
_context2.next = 5;
|
|
154
|
+
break;
|
|
155
|
+
}
|
|
156
|
+
return _context2.abrupt("return");
|
|
157
|
+
case 5:
|
|
158
|
+
return _context2.delegateYield(fixImport({
|
|
159
|
+
context: context,
|
|
160
|
+
fixer: fixer,
|
|
161
|
+
node: node,
|
|
162
|
+
specifiers: specifiers
|
|
163
|
+
}), "t0", 6);
|
|
164
|
+
case 6:
|
|
165
|
+
case "end":
|
|
166
|
+
return _context2.stop();
|
|
167
|
+
}
|
|
168
|
+
}, fix);
|
|
169
|
+
})
|
|
170
|
+
});
|
|
171
|
+
})
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
var _default = exports.default = rule;
|
|
176
|
+
function getSpecifiers(_ref3) {
|
|
177
|
+
var context = _ref3.context,
|
|
178
|
+
node = _ref3.node,
|
|
179
|
+
importSource = _ref3.importSource;
|
|
180
|
+
var supportedImports = SUPPORTED_IMPORT_MAP[importSource];
|
|
181
|
+
|
|
182
|
+
// We aren't supporting namespace imports
|
|
183
|
+
if (node.specifiers.some(_utils.isImportNamespaceSpecifier)) {
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
var defaultSpecifier = node.specifiers.find(_utils.isImportDefaultSpecifier);
|
|
187
|
+
if (defaultSpecifier) {
|
|
188
|
+
if (!supportedImports.has('default')) {
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
var styled = (0, _findVariable.findVariable)({
|
|
192
|
+
identifier: defaultSpecifier.local,
|
|
193
|
+
sourceCode: context.getSourceCode()
|
|
194
|
+
});
|
|
195
|
+
if (!styled || !(0, _isSafe.isSafeStyled)(styled)) {
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
var namedSpecifiers = node.specifiers.filter(_utils.isImportSpecifier);
|
|
200
|
+
if (!namedSpecifiers.every(function (specifier) {
|
|
201
|
+
return (0, _isSafe.isSafeUsage)({
|
|
202
|
+
context: context,
|
|
203
|
+
specifier: specifier,
|
|
204
|
+
supportedImports: supportedImports
|
|
205
|
+
});
|
|
206
|
+
})) {
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
if (defaultSpecifier) {
|
|
210
|
+
return [].concat((0, _toConsumableArray2.default)(namedSpecifiers), [
|
|
211
|
+
// ASSUMPTION: the default import, if allowed, is for `styled`
|
|
212
|
+
(0, _eslintCodemodUtils.importSpecifier)({
|
|
213
|
+
imported: (0, _eslintCodemodUtils.identifier)('styled'),
|
|
214
|
+
local: node.specifiers[0].local
|
|
215
|
+
})]);
|
|
216
|
+
}
|
|
217
|
+
return namedSpecifiers;
|
|
218
|
+
}
|
|
219
|
+
function fixImport(_ref4) {
|
|
220
|
+
var context = _ref4.context,
|
|
221
|
+
fixer = _ref4.fixer,
|
|
222
|
+
node = _ref4.node,
|
|
223
|
+
specifiers = _ref4.specifiers;
|
|
224
|
+
return /*#__PURE__*/_regenerator.default.mark(function _callee() {
|
|
225
|
+
var compiledImport;
|
|
226
|
+
return _regenerator.default.wrap(function _callee$(_context3) {
|
|
227
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
228
|
+
case 0:
|
|
229
|
+
compiledImport = (0, _utils.getFirstImportFromSource)(context, '@compiled/react');
|
|
230
|
+
if (!compiledImport) {
|
|
231
|
+
_context3.next = 8;
|
|
232
|
+
break;
|
|
233
|
+
}
|
|
234
|
+
_context3.next = 4;
|
|
235
|
+
return fixer.remove(node);
|
|
236
|
+
case 4:
|
|
237
|
+
_context3.next = 6;
|
|
238
|
+
return fixer.replaceText(compiledImport, buildImportDeclaration(compiledImport.specifiers.concat(specifiers), '@compiled/react'));
|
|
239
|
+
case 6:
|
|
240
|
+
_context3.next = 10;
|
|
241
|
+
break;
|
|
242
|
+
case 8:
|
|
243
|
+
_context3.next = 10;
|
|
244
|
+
return fixer.replaceText(node, buildImportDeclaration(specifiers, '@compiled/react'));
|
|
245
|
+
case 10:
|
|
246
|
+
case "end":
|
|
247
|
+
return _context3.stop();
|
|
248
|
+
}
|
|
249
|
+
}, _callee);
|
|
250
|
+
})();
|
|
251
|
+
}
|
|
252
|
+
function buildImportDeclaration(specifiers, source) {
|
|
253
|
+
return "".concat((0, _eslintCodemodUtils.importDeclaration)({
|
|
254
|
+
specifiers: specifiers,
|
|
255
|
+
source: (0, _eslintCodemodUtils.literal)(source)
|
|
256
|
+
}), ";");
|
|
257
|
+
}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.isSafeCss = isSafeCss;
|
|
7
|
+
exports.isSafeKeyframes = isSafeKeyframes;
|
|
8
|
+
exports.isSafeStyled = isSafeStyled;
|
|
9
|
+
exports.isSafeUsage = isSafeUsage;
|
|
10
|
+
var _eslintCodemodUtils = require("eslint-codemod-utils");
|
|
11
|
+
var _findVariable = require("@atlaskit/eslint-utils/find-variable");
|
|
12
|
+
function isSafeUsage(_ref) {
|
|
13
|
+
var context = _ref.context,
|
|
14
|
+
specifier = _ref.specifier,
|
|
15
|
+
supportedImports = _ref.supportedImports;
|
|
16
|
+
var importName = specifier.imported.name;
|
|
17
|
+
if (!supportedImports.has(importName)) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
if (importName === 'css') {
|
|
21
|
+
var css = (0, _findVariable.findVariable)({
|
|
22
|
+
identifier: specifier.local,
|
|
23
|
+
sourceCode: context.getSourceCode()
|
|
24
|
+
});
|
|
25
|
+
return css !== null && isSafeCss(css);
|
|
26
|
+
}
|
|
27
|
+
if (importName === 'keyframes') {
|
|
28
|
+
var keyframes = (0, _findVariable.findVariable)({
|
|
29
|
+
identifier: specifier.local,
|
|
30
|
+
sourceCode: context.getSourceCode()
|
|
31
|
+
});
|
|
32
|
+
return keyframes !== null && isSafeKeyframes(keyframes);
|
|
33
|
+
}
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
function isSafeKeyframes(keyframes) {
|
|
37
|
+
return keyframes.references.every(function (ref) {
|
|
38
|
+
var callExpression = (0, _eslintCodemodUtils.closestOfType)(ref.identifier, 'CallExpression');
|
|
39
|
+
if (!callExpression) {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
if (callExpression.callee !== ref.identifier) {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
if (callExpression.arguments.length !== 1) {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
var argument = callExpression.arguments[0];
|
|
49
|
+
if (argument.type !== 'ObjectExpression') {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
return argument.properties.every(function (property) {
|
|
53
|
+
return isSafeProperty(property, isSafeKeyframePropertyValue);
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
function isSafeKeyframePropertyValue(value) {
|
|
58
|
+
if (value.type !== 'ObjectExpression') {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
return isSafeStyleObject(value);
|
|
62
|
+
}
|
|
63
|
+
function isSafeCss(css) {
|
|
64
|
+
return css.references.every(function (ref) {
|
|
65
|
+
var callExpression = (0, _eslintCodemodUtils.closestOfType)(ref.identifier, 'CallExpression');
|
|
66
|
+
if (!callExpression) {
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
if (callExpression.callee !== ref.identifier) {
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
return callExpression.arguments.every(isSafeStyleArgument);
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
function isSafeStyled(styled) {
|
|
76
|
+
return styled.references.every(function (ref) {
|
|
77
|
+
var callExpression = (0, _eslintCodemodUtils.closestOfType)(ref.identifier, 'CallExpression');
|
|
78
|
+
if (!callExpression) {
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* If it's not in the form `styled.tagName()`
|
|
84
|
+
* then we consider it unsafe to auto-fix.
|
|
85
|
+
*/
|
|
86
|
+
if (callExpression.callee.type !== 'MemberExpression' || callExpression.callee.object !== ref.identifier) {
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
return callExpression.arguments.every(isSafeStyleArgument);
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Determines if a style argument is safe for auto-fix conversion.
|
|
95
|
+
*/
|
|
96
|
+
function isSafeStyleArgument(arg) {
|
|
97
|
+
if (arg.type === 'ObjectExpression') {
|
|
98
|
+
return isSafeStyleObject(arg);
|
|
99
|
+
}
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
function isSafeStyleObject(object) {
|
|
103
|
+
return object.properties.every(function (property) {
|
|
104
|
+
return isSafeProperty(property, isSafeStyleValue);
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
function isSafeStyleValue(value) {
|
|
108
|
+
if (value.type === 'Literal') {
|
|
109
|
+
return true;
|
|
110
|
+
}
|
|
111
|
+
return false;
|
|
112
|
+
}
|
|
113
|
+
function isSafeProperty(property, isSafePropertyValue) {
|
|
114
|
+
if (property.type === 'SpreadElement') {
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
if (property.method || property.shorthand || property.kind !== 'init') {
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
120
|
+
if (!hasSafeKey(property)) {
|
|
121
|
+
return false;
|
|
122
|
+
}
|
|
123
|
+
return isSafePropertyValue(property.value);
|
|
124
|
+
}
|
|
125
|
+
function hasSafeKey(property) {
|
|
126
|
+
if (property.computed) {
|
|
127
|
+
return property.key.type === 'Literal';
|
|
128
|
+
}
|
|
129
|
+
return true;
|
|
130
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getFirstImportFromSource = getFirstImportFromSource;
|
|
7
|
+
exports.isImportDefaultSpecifier = isImportDefaultSpecifier;
|
|
8
|
+
exports.isImportNamespaceSpecifier = isImportNamespaceSpecifier;
|
|
9
|
+
exports.isImportSpecifier = isImportSpecifier;
|
|
10
|
+
function getFirstImportFromSource(context, source) {
|
|
11
|
+
return context.getSourceCode().ast.body.filter(isImportDeclaration).find(function (node) {
|
|
12
|
+
return node.source.value === source;
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
function isImportDeclaration(node) {
|
|
16
|
+
return node.type === 'ImportDeclaration';
|
|
17
|
+
}
|
|
18
|
+
function isImportSpecifier(specifier) {
|
|
19
|
+
return specifier.type === 'ImportSpecifier';
|
|
20
|
+
}
|
|
21
|
+
function isImportDefaultSpecifier(specifier) {
|
|
22
|
+
return specifier.type === 'ImportDefaultSpecifier';
|
|
23
|
+
}
|
|
24
|
+
function isImportNamespaceSpecifier(specifier) {
|
|
25
|
+
return specifier.type === 'ImportNamespaceSpecifier';
|
|
26
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
-
* @codegen <<SignedSource::
|
|
3
|
+
* @codegen <<SignedSource::752a442dd46681814ab73f7fa9c05374>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
export default {
|
|
@@ -19,6 +19,7 @@ export default {
|
|
|
19
19
|
'@atlaskit/ui-styling-standard/no-imported-style-values': 'warn',
|
|
20
20
|
'@atlaskit/ui-styling-standard/no-nested-selectors': 'warn',
|
|
21
21
|
'@atlaskit/ui-styling-standard/no-unsafe-values': 'warn',
|
|
22
|
+
'@atlaskit/ui-styling-standard/use-compiled': 'warn',
|
|
22
23
|
'@atlaskit/design-system/consistent-css-prop-usage': ['warn', {
|
|
23
24
|
excludeReactComponents: true
|
|
24
25
|
}],
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
-
* @codegen <<SignedSource::
|
|
3
|
+
* @codegen <<SignedSource::752a442dd46681814ab73f7fa9c05374>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
export default {
|
|
@@ -19,6 +19,7 @@ export default {
|
|
|
19
19
|
'@atlaskit/ui-styling-standard/no-imported-style-values': 'warn',
|
|
20
20
|
'@atlaskit/ui-styling-standard/no-nested-selectors': 'warn',
|
|
21
21
|
'@atlaskit/ui-styling-standard/no-unsafe-values': 'warn',
|
|
22
|
+
'@atlaskit/ui-styling-standard/use-compiled': 'warn',
|
|
22
23
|
'@atlaskit/design-system/consistent-css-prop-usage': ['warn', {
|
|
23
24
|
excludeReactComponents: true
|
|
24
25
|
}],
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
-
* @codegen <<SignedSource::
|
|
3
|
+
* @codegen <<SignedSource::be177a361ddc1a7a41d843680299e318>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
import atlaskitTheme from './atlaskit-theme';
|
|
@@ -16,6 +16,7 @@ import noImportantStyles from './no-important-styles';
|
|
|
16
16
|
import noImportedStyleValues from './no-imported-style-values';
|
|
17
17
|
import noNestedSelectors from './no-nested-selectors';
|
|
18
18
|
import noUnsafeValues from './no-unsafe-values';
|
|
19
|
+
import useCompiled from './use-compiled';
|
|
19
20
|
export default {
|
|
20
21
|
'atlaskit-theme': atlaskitTheme,
|
|
21
22
|
'convert-props-syntax': convertPropsSyntax,
|
|
@@ -29,5 +30,6 @@ export default {
|
|
|
29
30
|
'no-important-styles': noImportantStyles,
|
|
30
31
|
'no-imported-style-values': noImportedStyleValues,
|
|
31
32
|
'no-nested-selectors': noNestedSelectors,
|
|
32
|
-
'no-unsafe-values': noUnsafeValues
|
|
33
|
+
'no-unsafe-values': noUnsafeValues,
|
|
34
|
+
'use-compiled': useCompiled
|
|
33
35
|
};
|