@atlaskit/eslint-plugin-ui-styling-standard 0.12.0 → 0.13.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 +13 -0
- package/README.md +1 -0
- package/constellation/index/overview.mdx +2 -1
- package/constellation/no-global-styles/usage.mdx +59 -0
- package/constellation/use-compiled/usage.mdx +20 -17
- 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 +3 -1
- package/dist/cjs/rules/no-global-styles/index.js +100 -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 +3 -1
- package/dist/es2019/rules/no-global-styles/index.js +67 -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 +3 -1
- package/dist/esm/rules/no-global-styles/index.js +94 -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/no-global-styles/index.d.ts +2 -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/no-global-styles/index.d.ts +2 -0
- package/package.json +2 -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/no-global-styles/README.md +56 -0
- package/src/rules/no-global-styles/__tests__/no-css-modules.test.tsx +33 -0
- package/src/rules/no-global-styles/__tests__/no-global-styles.test.tsx +46 -0
- package/src/rules/no-global-styles/index.tsx +85 -0
- package/src/rules/use-compiled/README.md +16 -16
- package/src/rules/use-compiled/__tests__/imports.test.tsx +24 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @atlaskit/eslint-plugin-ui-styling-standard
|
|
2
2
|
|
|
3
|
+
## 0.13.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#99544](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/99544)
|
|
8
|
+
[`391edf6de450`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/391edf6de450) -
|
|
9
|
+
Added `no-global-styles` rule which prevents:
|
|
10
|
+
|
|
11
|
+
- The `Global` API from `@emotion`
|
|
12
|
+
- The `createGlobalStyle` and `injectGlobal` APIs from `styled-components`
|
|
13
|
+
- `<style>` elements in JSX
|
|
14
|
+
- CSS imports (including SASS and LESS)
|
|
15
|
+
|
|
3
16
|
## 0.12.0
|
|
4
17
|
|
|
5
18
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -51,6 +51,7 @@ module.exports = {
|
|
|
51
51
|
| <a href="./src/rules/no-container-queries/README.md">no-container-queries</a> | Prevents usage of @container query within css styling | Yes | | |
|
|
52
52
|
| <a href="./src/rules/no-dynamic-styles/README.md">no-dynamic-styles</a> | Disallows use of dynamic styles in CSS-in-JS calls | Yes | | |
|
|
53
53
|
| <a href="./src/rules/no-exported-styles/README.md">no-exported-styles</a> | Disallows exports of css, keyframes, styled and xcss | Yes | | |
|
|
54
|
+
| <a href="./src/rules/no-global-styles/README.md">no-global-styles</a> | Prevents global styles through CSS-in-JS or CSS module imports | Yes | | |
|
|
54
55
|
| <a href="./src/rules/no-important-styles/README.md">no-important-styles</a> | Disallows important style declarations | Yes | | |
|
|
55
56
|
| <a href="./src/rules/no-imported-style-values/README.md">no-imported-style-values</a> | Disallows imports of style values | Yes | | |
|
|
56
57
|
| <a href="./src/rules/no-nested-selectors/README.md">no-nested-selectors</a> | Prevents usage of nested selectors within css styling | Yes | | |
|
|
@@ -20,6 +20,7 @@ but more are planned to support the standard over time.
|
|
|
20
20
|
| <a href="no-container-queries/usage">no-container-queries</a> | Prevents usage of @container query within css styling | Yes | | |
|
|
21
21
|
| <a href="no-dynamic-styles/usage">no-dynamic-styles</a> | Disallows use of dynamic styles in CSS-in-JS calls | Yes | | |
|
|
22
22
|
| <a href="no-exported-styles/usage">no-exported-styles</a> | Disallows exports of css, keyframes, styled and xcss | Yes | | |
|
|
23
|
+
| <a href="no-global-styles/usage">no-global-styles</a> | Prevents global styles through CSS-in-JS or CSS module imports | Yes | | |
|
|
23
24
|
| <a href="no-important-styles/usage">no-important-styles</a> | Disallows important style declarations | Yes | | |
|
|
24
25
|
| <a href="no-imported-style-values/usage">no-imported-style-values</a> | Disallows imports of style values | Yes | | |
|
|
25
26
|
| <a href="no-nested-selectors/usage">no-nested-selectors</a> | Prevents usage of nested selectors within css styling | Yes | | |
|
|
@@ -154,7 +155,7 @@ export const Component = ({
|
|
|
154
155
|
Every element should be clear in isolation how it's styled, using locally and statically available
|
|
155
156
|
context so both humans and tooling can read this component in a performant and deterministic manner.
|
|
156
157
|
|
|
157
|
-
1. Use `@compiled
|
|
158
|
+
1. Use `@compiled/react` or [Primitives](/components/primitives/overview) wherever possible!
|
|
158
159
|
2. Instead of dynamic styles:
|
|
159
160
|
1. Use static `css()` calls everywhere.
|
|
160
161
|
2. Compose styles together, turning styles on or off.
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# no-global-styles
|
|
2
|
+
|
|
3
|
+
This rule prevents global styles through CSS-in-JS or CSS module imports.
|
|
4
|
+
|
|
5
|
+
Requiring local definition of styles helps to ensure that style dependencies are statically
|
|
6
|
+
resolvable.
|
|
7
|
+
|
|
8
|
+
## Examples
|
|
9
|
+
|
|
10
|
+
### Incorrect
|
|
11
|
+
|
|
12
|
+
```tsx
|
|
13
|
+
import { Global } from '@emotion/react';
|
|
14
|
+
|
|
15
|
+
<Global
|
|
16
|
+
styles={{
|
|
17
|
+
'.some-class': {
|
|
18
|
+
fontSize: 50,
|
|
19
|
+
textAlign: 'center',
|
|
20
|
+
},
|
|
21
|
+
}}
|
|
22
|
+
/>;
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
```tsx
|
|
26
|
+
import { createGlobalStyle } from 'styled-components';
|
|
27
|
+
|
|
28
|
+
const GlobalStyle = createGlobalStyle({
|
|
29
|
+
body: {
|
|
30
|
+
margin: 0,
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
```tsx
|
|
36
|
+
import { injectGlobal } from 'styled-components';
|
|
37
|
+
|
|
38
|
+
injectGlobal({
|
|
39
|
+
body: {
|
|
40
|
+
margin: 0,
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
```tsx
|
|
46
|
+
<style>
|
|
47
|
+
{`
|
|
48
|
+
.some-class {
|
|
49
|
+
color: red;
|
|
50
|
+
}
|
|
51
|
+
`}
|
|
52
|
+
</style>
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### Correct
|
|
56
|
+
|
|
57
|
+
```tsx
|
|
58
|
+
import '@atlaskit/css-reset';
|
|
59
|
+
```
|
|
@@ -1,27 +1,20 @@
|
|
|
1
1
|
# use-compiled
|
|
2
2
|
|
|
3
|
-
Ensures usage of `@compiled/react` over other CSS-in-JS libraries.
|
|
3
|
+
Ensures usage of `@compiled/react` over other CSS-in-JS libraries like Emotion or styled-components.
|
|
4
4
|
|
|
5
|
-
**WARNING**
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
When converting to `@compiled/react` verify ALL changes.
|
|
10
|
-
|
|
11
|
-
For this reason, the auto-fixer has been disabled by default.
|
|
5
|
+
**WARNING** It may be unsafe to mix usages of `@compiled/react` with other CSS-in-JS libraries on
|
|
6
|
+
the same component. When converting to `@compiled/react` verify ALL changes. For this reason, the
|
|
7
|
+
auto-fixer has been disabled by default, but it may be useful to enable to empower a migration.
|
|
12
8
|
|
|
13
9
|
## Examples
|
|
14
10
|
|
|
15
11
|
### Incorrect
|
|
16
12
|
|
|
17
|
-
```js
|
|
18
|
-
import { css } from '@emotion/core';
|
|
19
|
-
import styled from '@emotion/styled';
|
|
20
|
-
```
|
|
21
|
-
|
|
22
13
|
```js
|
|
23
14
|
/** @jsx jsx */
|
|
15
|
+
import { css } from '@emotion/core';
|
|
24
16
|
import { jsx } from '@emotion/react';
|
|
17
|
+
import styled from '@emotion/styled';
|
|
25
18
|
```
|
|
26
19
|
|
|
27
20
|
```js
|
|
@@ -30,13 +23,22 @@ import styled, { css } from 'styled-components';
|
|
|
30
23
|
|
|
31
24
|
### Correct
|
|
32
25
|
|
|
26
|
+
We expect usage of `@atlaskit/primitives.xcss` when working with Primitives and
|
|
27
|
+
`@compiled/react.css` when working with custom or native code.
|
|
28
|
+
|
|
33
29
|
```js
|
|
34
|
-
|
|
30
|
+
/** @jsx jsx */
|
|
31
|
+
import { jsx, css, styled } from '@compiled/react';
|
|
32
|
+
|
|
33
|
+
const styles = css({ color: 'var(--ds-color-text)' });
|
|
34
|
+
export default () => <div css={styles}>…</div>;
|
|
35
35
|
```
|
|
36
36
|
|
|
37
37
|
```js
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
import { xcss, Box } from '@atlaskit/primitives';
|
|
39
|
+
|
|
40
|
+
const styles = xcss({ color: 'color.text' });
|
|
41
|
+
export default () => <Box xcss={styles}>…</Box>;
|
|
40
42
|
```
|
|
41
43
|
|
|
42
44
|
## Options
|
|
@@ -45,7 +47,8 @@ import { jsx } from '@compiled/react';
|
|
|
45
47
|
|
|
46
48
|
Determines whether or not the auto-fixer is enabled.
|
|
47
49
|
|
|
48
|
-
Defaults to `false` due to safety concerns when mixing Compiled and other CSS-in-JS libraries
|
|
50
|
+
Defaults to `false` due to safety concerns when mixing Compiled and other CSS-in-JS libraries on the
|
|
51
|
+
same component.
|
|
49
52
|
|
|
50
53
|
Even when enabled, the auto-fixer will only convert usages that are deemed safe. Currently this is
|
|
51
54
|
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::9ac05c3cbd30f6209164b7a24f7a7a19>>
|
|
10
10
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
11
11
|
*/
|
|
12
12
|
var _default = exports.default = {
|
|
@@ -21,6 +21,7 @@ var _default = exports.default = {
|
|
|
21
21
|
'@atlaskit/ui-styling-standard/no-container-queries': 'warn',
|
|
22
22
|
'@atlaskit/ui-styling-standard/no-dynamic-styles': 'warn',
|
|
23
23
|
'@atlaskit/ui-styling-standard/no-exported-styles': 'warn',
|
|
24
|
+
'@atlaskit/ui-styling-standard/no-global-styles': 'warn',
|
|
24
25
|
'@atlaskit/ui-styling-standard/no-important-styles': 'warn',
|
|
25
26
|
'@atlaskit/ui-styling-standard/no-imported-style-values': 'warn',
|
|
26
27
|
'@atlaskit/ui-styling-standard/no-nested-selectors': 'warn',
|
|
@@ -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::9ac05c3cbd30f6209164b7a24f7a7a19>>
|
|
10
10
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
11
11
|
*/
|
|
12
12
|
var _default = exports.default = {
|
|
@@ -21,6 +21,7 @@ var _default = exports.default = {
|
|
|
21
21
|
'@atlaskit/ui-styling-standard/no-container-queries': 'warn',
|
|
22
22
|
'@atlaskit/ui-styling-standard/no-dynamic-styles': 'warn',
|
|
23
23
|
'@atlaskit/ui-styling-standard/no-exported-styles': 'warn',
|
|
24
|
+
'@atlaskit/ui-styling-standard/no-global-styles': 'warn',
|
|
24
25
|
'@atlaskit/ui-styling-standard/no-important-styles': 'warn',
|
|
25
26
|
'@atlaskit/ui-styling-standard/no-imported-style-values': 'warn',
|
|
26
27
|
'@atlaskit/ui-styling-standard/no-nested-selectors': 'warn',
|
|
@@ -14,6 +14,7 @@ var _noClassnameProp = _interopRequireDefault(require("./no-classname-prop"));
|
|
|
14
14
|
var _noContainerQueries = _interopRequireDefault(require("./no-container-queries"));
|
|
15
15
|
var _noDynamicStyles = _interopRequireDefault(require("./no-dynamic-styles"));
|
|
16
16
|
var _noExportedStyles = _interopRequireDefault(require("./no-exported-styles"));
|
|
17
|
+
var _noGlobalStyles = _interopRequireDefault(require("./no-global-styles"));
|
|
17
18
|
var _noImportantStyles = _interopRequireDefault(require("./no-important-styles"));
|
|
18
19
|
var _noImportedStyleValues = _interopRequireDefault(require("./no-imported-style-values"));
|
|
19
20
|
var _noNestedSelectors = _interopRequireDefault(require("./no-nested-selectors"));
|
|
@@ -21,7 +22,7 @@ var _noUnsafeValues = _interopRequireDefault(require("./no-unsafe-values"));
|
|
|
21
22
|
var _useCompiled = _interopRequireDefault(require("./use-compiled"));
|
|
22
23
|
/**
|
|
23
24
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
24
|
-
* @codegen <<SignedSource::
|
|
25
|
+
* @codegen <<SignedSource::3cea683df6e31f816db56abf1fd65c1e>>
|
|
25
26
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
26
27
|
*/
|
|
27
28
|
var _default = exports.default = {
|
|
@@ -34,6 +35,7 @@ var _default = exports.default = {
|
|
|
34
35
|
'no-container-queries': _noContainerQueries.default,
|
|
35
36
|
'no-dynamic-styles': _noDynamicStyles.default,
|
|
36
37
|
'no-exported-styles': _noExportedStyles.default,
|
|
38
|
+
'no-global-styles': _noGlobalStyles.default,
|
|
37
39
|
'no-important-styles': _noImportantStyles.default,
|
|
38
40
|
'no-imported-style-values': _noImportedStyleValues.default,
|
|
39
41
|
'no-nested-selectors': _noNestedSelectors.default,
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.rule = exports.default = void 0;
|
|
7
|
+
var _createRule = require("../utils/create-rule");
|
|
8
|
+
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; } } }; }
|
|
9
|
+
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); }
|
|
10
|
+
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; }
|
|
11
|
+
var restrictedFileTypes = ['.css', '.less', '.sass', '.scss'];
|
|
12
|
+
var restrictedImports = {
|
|
13
|
+
'@emotion/core': ['Global'],
|
|
14
|
+
'@emotion/react': ['Global'],
|
|
15
|
+
'styled-components': ['createGlobalStyle', 'injectGlobal']
|
|
16
|
+
};
|
|
17
|
+
function isRestrictedImportSource(importSource) {
|
|
18
|
+
return importSource in restrictedImports;
|
|
19
|
+
}
|
|
20
|
+
var rule = exports.rule = (0, _createRule.createLintRule)({
|
|
21
|
+
meta: {
|
|
22
|
+
name: 'no-global-styles',
|
|
23
|
+
docs: {
|
|
24
|
+
description: 'Prevents global styles through CSS-in-JS or CSS module imports',
|
|
25
|
+
recommended: true,
|
|
26
|
+
severity: 'warn'
|
|
27
|
+
},
|
|
28
|
+
messages: {
|
|
29
|
+
'no-global-styles': 'Global styles are not allowed.',
|
|
30
|
+
'no-css-modules': 'Importing CSS files is not allowed.'
|
|
31
|
+
},
|
|
32
|
+
type: 'problem'
|
|
33
|
+
},
|
|
34
|
+
create: function create(context) {
|
|
35
|
+
function checkFileType(node) {
|
|
36
|
+
var importSource = node.source.value;
|
|
37
|
+
if (restrictedFileTypes.some(function (suffix) {
|
|
38
|
+
return importSource.endsWith(suffix);
|
|
39
|
+
})) {
|
|
40
|
+
context.report({
|
|
41
|
+
node: node.source,
|
|
42
|
+
messageId: 'no-css-modules'
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
function checkImports(node) {
|
|
47
|
+
var importSource = node.source.value;
|
|
48
|
+
if (!isRestrictedImportSource(importSource)) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
var _iterator = _createForOfIteratorHelper(restrictedImports[importSource]),
|
|
52
|
+
_step;
|
|
53
|
+
try {
|
|
54
|
+
var _loop = function _loop() {
|
|
55
|
+
var importName = _step.value;
|
|
56
|
+
var specifier = node.specifiers.filter(isImportSpecifier).find(function (specifier) {
|
|
57
|
+
return specifier.imported.name === importName;
|
|
58
|
+
});
|
|
59
|
+
if (specifier) {
|
|
60
|
+
context.report({
|
|
61
|
+
node: specifier,
|
|
62
|
+
messageId: 'no-global-styles'
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
67
|
+
_loop();
|
|
68
|
+
}
|
|
69
|
+
} catch (err) {
|
|
70
|
+
_iterator.e(err);
|
|
71
|
+
} finally {
|
|
72
|
+
_iterator.f();
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return {
|
|
76
|
+
ImportDeclaration: function (_ImportDeclaration) {
|
|
77
|
+
function ImportDeclaration(_x) {
|
|
78
|
+
return _ImportDeclaration.apply(this, arguments);
|
|
79
|
+
}
|
|
80
|
+
ImportDeclaration.toString = function () {
|
|
81
|
+
return _ImportDeclaration.toString();
|
|
82
|
+
};
|
|
83
|
+
return ImportDeclaration;
|
|
84
|
+
}(function (node) {
|
|
85
|
+
checkFileType(node);
|
|
86
|
+
checkImports(node);
|
|
87
|
+
}),
|
|
88
|
+
'JSXOpeningElement[name.name="style"]': function JSXOpeningElementNameNameStyle(node) {
|
|
89
|
+
context.report({
|
|
90
|
+
node: node,
|
|
91
|
+
messageId: 'no-global-styles'
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
var _default = exports.default = rule;
|
|
98
|
+
function isImportSpecifier(node) {
|
|
99
|
+
return node.type === 'ImportSpecifier';
|
|
100
|
+
}
|
|
@@ -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::9ac05c3cbd30f6209164b7a24f7a7a19>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
export default {
|
|
@@ -15,6 +15,7 @@ export default {
|
|
|
15
15
|
'@atlaskit/ui-styling-standard/no-container-queries': 'warn',
|
|
16
16
|
'@atlaskit/ui-styling-standard/no-dynamic-styles': 'warn',
|
|
17
17
|
'@atlaskit/ui-styling-standard/no-exported-styles': 'warn',
|
|
18
|
+
'@atlaskit/ui-styling-standard/no-global-styles': 'warn',
|
|
18
19
|
'@atlaskit/ui-styling-standard/no-important-styles': 'warn',
|
|
19
20
|
'@atlaskit/ui-styling-standard/no-imported-style-values': 'warn',
|
|
20
21
|
'@atlaskit/ui-styling-standard/no-nested-selectors': 'warn',
|
|
@@ -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::9ac05c3cbd30f6209164b7a24f7a7a19>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
export default {
|
|
@@ -15,6 +15,7 @@ export default {
|
|
|
15
15
|
'@atlaskit/ui-styling-standard/no-container-queries': 'warn',
|
|
16
16
|
'@atlaskit/ui-styling-standard/no-dynamic-styles': 'warn',
|
|
17
17
|
'@atlaskit/ui-styling-standard/no-exported-styles': 'warn',
|
|
18
|
+
'@atlaskit/ui-styling-standard/no-global-styles': 'warn',
|
|
18
19
|
'@atlaskit/ui-styling-standard/no-important-styles': 'warn',
|
|
19
20
|
'@atlaskit/ui-styling-standard/no-imported-style-values': 'warn',
|
|
20
21
|
'@atlaskit/ui-styling-standard/no-nested-selectors': 'warn',
|
|
@@ -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::3cea683df6e31f816db56abf1fd65c1e>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
import atlaskitTheme from './atlaskit-theme';
|
|
@@ -12,6 +12,7 @@ import noClassnameProp from './no-classname-prop';
|
|
|
12
12
|
import noContainerQueries from './no-container-queries';
|
|
13
13
|
import noDynamicStyles from './no-dynamic-styles';
|
|
14
14
|
import noExportedStyles from './no-exported-styles';
|
|
15
|
+
import noGlobalStyles from './no-global-styles';
|
|
15
16
|
import noImportantStyles from './no-important-styles';
|
|
16
17
|
import noImportedStyleValues from './no-imported-style-values';
|
|
17
18
|
import noNestedSelectors from './no-nested-selectors';
|
|
@@ -27,6 +28,7 @@ export default {
|
|
|
27
28
|
'no-container-queries': noContainerQueries,
|
|
28
29
|
'no-dynamic-styles': noDynamicStyles,
|
|
29
30
|
'no-exported-styles': noExportedStyles,
|
|
31
|
+
'no-global-styles': noGlobalStyles,
|
|
30
32
|
'no-important-styles': noImportantStyles,
|
|
31
33
|
'no-imported-style-values': noImportedStyleValues,
|
|
32
34
|
'no-nested-selectors': noNestedSelectors,
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { createLintRule } from '../utils/create-rule';
|
|
2
|
+
const restrictedFileTypes = ['.css', '.less', '.sass', '.scss'];
|
|
3
|
+
const restrictedImports = {
|
|
4
|
+
'@emotion/core': ['Global'],
|
|
5
|
+
'@emotion/react': ['Global'],
|
|
6
|
+
'styled-components': ['createGlobalStyle', 'injectGlobal']
|
|
7
|
+
};
|
|
8
|
+
function isRestrictedImportSource(importSource) {
|
|
9
|
+
return importSource in restrictedImports;
|
|
10
|
+
}
|
|
11
|
+
export const rule = createLintRule({
|
|
12
|
+
meta: {
|
|
13
|
+
name: 'no-global-styles',
|
|
14
|
+
docs: {
|
|
15
|
+
description: 'Prevents global styles through CSS-in-JS or CSS module imports',
|
|
16
|
+
recommended: true,
|
|
17
|
+
severity: 'warn'
|
|
18
|
+
},
|
|
19
|
+
messages: {
|
|
20
|
+
'no-global-styles': 'Global styles are not allowed.',
|
|
21
|
+
'no-css-modules': 'Importing CSS files is not allowed.'
|
|
22
|
+
},
|
|
23
|
+
type: 'problem'
|
|
24
|
+
},
|
|
25
|
+
create(context) {
|
|
26
|
+
function checkFileType(node) {
|
|
27
|
+
const importSource = node.source.value;
|
|
28
|
+
if (restrictedFileTypes.some(suffix => importSource.endsWith(suffix))) {
|
|
29
|
+
context.report({
|
|
30
|
+
node: node.source,
|
|
31
|
+
messageId: 'no-css-modules'
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function checkImports(node) {
|
|
36
|
+
const importSource = node.source.value;
|
|
37
|
+
if (!isRestrictedImportSource(importSource)) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
for (const importName of restrictedImports[importSource]) {
|
|
41
|
+
const specifier = node.specifiers.filter(isImportSpecifier).find(specifier => specifier.imported.name === importName);
|
|
42
|
+
if (specifier) {
|
|
43
|
+
context.report({
|
|
44
|
+
node: specifier,
|
|
45
|
+
messageId: 'no-global-styles'
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
ImportDeclaration(node) {
|
|
52
|
+
checkFileType(node);
|
|
53
|
+
checkImports(node);
|
|
54
|
+
},
|
|
55
|
+
'JSXOpeningElement[name.name="style"]'(node) {
|
|
56
|
+
context.report({
|
|
57
|
+
node,
|
|
58
|
+
messageId: 'no-global-styles'
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
export default rule;
|
|
65
|
+
function isImportSpecifier(node) {
|
|
66
|
+
return node.type === 'ImportSpecifier';
|
|
67
|
+
}
|
|
@@ -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::9ac05c3cbd30f6209164b7a24f7a7a19>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
export default {
|
|
@@ -15,6 +15,7 @@ export default {
|
|
|
15
15
|
'@atlaskit/ui-styling-standard/no-container-queries': 'warn',
|
|
16
16
|
'@atlaskit/ui-styling-standard/no-dynamic-styles': 'warn',
|
|
17
17
|
'@atlaskit/ui-styling-standard/no-exported-styles': 'warn',
|
|
18
|
+
'@atlaskit/ui-styling-standard/no-global-styles': 'warn',
|
|
18
19
|
'@atlaskit/ui-styling-standard/no-important-styles': 'warn',
|
|
19
20
|
'@atlaskit/ui-styling-standard/no-imported-style-values': 'warn',
|
|
20
21
|
'@atlaskit/ui-styling-standard/no-nested-selectors': 'warn',
|
|
@@ -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::9ac05c3cbd30f6209164b7a24f7a7a19>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
export default {
|
|
@@ -15,6 +15,7 @@ export default {
|
|
|
15
15
|
'@atlaskit/ui-styling-standard/no-container-queries': 'warn',
|
|
16
16
|
'@atlaskit/ui-styling-standard/no-dynamic-styles': 'warn',
|
|
17
17
|
'@atlaskit/ui-styling-standard/no-exported-styles': 'warn',
|
|
18
|
+
'@atlaskit/ui-styling-standard/no-global-styles': 'warn',
|
|
18
19
|
'@atlaskit/ui-styling-standard/no-important-styles': 'warn',
|
|
19
20
|
'@atlaskit/ui-styling-standard/no-imported-style-values': 'warn',
|
|
20
21
|
'@atlaskit/ui-styling-standard/no-nested-selectors': 'warn',
|
|
@@ -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::3cea683df6e31f816db56abf1fd65c1e>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
import atlaskitTheme from './atlaskit-theme';
|
|
@@ -12,6 +12,7 @@ import noClassnameProp from './no-classname-prop';
|
|
|
12
12
|
import noContainerQueries from './no-container-queries';
|
|
13
13
|
import noDynamicStyles from './no-dynamic-styles';
|
|
14
14
|
import noExportedStyles from './no-exported-styles';
|
|
15
|
+
import noGlobalStyles from './no-global-styles';
|
|
15
16
|
import noImportantStyles from './no-important-styles';
|
|
16
17
|
import noImportedStyleValues from './no-imported-style-values';
|
|
17
18
|
import noNestedSelectors from './no-nested-selectors';
|
|
@@ -27,6 +28,7 @@ export default {
|
|
|
27
28
|
'no-container-queries': noContainerQueries,
|
|
28
29
|
'no-dynamic-styles': noDynamicStyles,
|
|
29
30
|
'no-exported-styles': noExportedStyles,
|
|
31
|
+
'no-global-styles': noGlobalStyles,
|
|
30
32
|
'no-important-styles': noImportantStyles,
|
|
31
33
|
'no-imported-style-values': noImportedStyleValues,
|
|
32
34
|
'no-nested-selectors': noNestedSelectors,
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
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; } } }; }
|
|
2
|
+
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); }
|
|
3
|
+
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; }
|
|
4
|
+
import { createLintRule } from '../utils/create-rule';
|
|
5
|
+
var restrictedFileTypes = ['.css', '.less', '.sass', '.scss'];
|
|
6
|
+
var restrictedImports = {
|
|
7
|
+
'@emotion/core': ['Global'],
|
|
8
|
+
'@emotion/react': ['Global'],
|
|
9
|
+
'styled-components': ['createGlobalStyle', 'injectGlobal']
|
|
10
|
+
};
|
|
11
|
+
function isRestrictedImportSource(importSource) {
|
|
12
|
+
return importSource in restrictedImports;
|
|
13
|
+
}
|
|
14
|
+
export var rule = createLintRule({
|
|
15
|
+
meta: {
|
|
16
|
+
name: 'no-global-styles',
|
|
17
|
+
docs: {
|
|
18
|
+
description: 'Prevents global styles through CSS-in-JS or CSS module imports',
|
|
19
|
+
recommended: true,
|
|
20
|
+
severity: 'warn'
|
|
21
|
+
},
|
|
22
|
+
messages: {
|
|
23
|
+
'no-global-styles': 'Global styles are not allowed.',
|
|
24
|
+
'no-css-modules': 'Importing CSS files is not allowed.'
|
|
25
|
+
},
|
|
26
|
+
type: 'problem'
|
|
27
|
+
},
|
|
28
|
+
create: function create(context) {
|
|
29
|
+
function checkFileType(node) {
|
|
30
|
+
var importSource = node.source.value;
|
|
31
|
+
if (restrictedFileTypes.some(function (suffix) {
|
|
32
|
+
return importSource.endsWith(suffix);
|
|
33
|
+
})) {
|
|
34
|
+
context.report({
|
|
35
|
+
node: node.source,
|
|
36
|
+
messageId: 'no-css-modules'
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
function checkImports(node) {
|
|
41
|
+
var importSource = node.source.value;
|
|
42
|
+
if (!isRestrictedImportSource(importSource)) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
var _iterator = _createForOfIteratorHelper(restrictedImports[importSource]),
|
|
46
|
+
_step;
|
|
47
|
+
try {
|
|
48
|
+
var _loop = function _loop() {
|
|
49
|
+
var importName = _step.value;
|
|
50
|
+
var specifier = node.specifiers.filter(isImportSpecifier).find(function (specifier) {
|
|
51
|
+
return specifier.imported.name === importName;
|
|
52
|
+
});
|
|
53
|
+
if (specifier) {
|
|
54
|
+
context.report({
|
|
55
|
+
node: specifier,
|
|
56
|
+
messageId: 'no-global-styles'
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
61
|
+
_loop();
|
|
62
|
+
}
|
|
63
|
+
} catch (err) {
|
|
64
|
+
_iterator.e(err);
|
|
65
|
+
} finally {
|
|
66
|
+
_iterator.f();
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return {
|
|
70
|
+
ImportDeclaration: function (_ImportDeclaration) {
|
|
71
|
+
function ImportDeclaration(_x) {
|
|
72
|
+
return _ImportDeclaration.apply(this, arguments);
|
|
73
|
+
}
|
|
74
|
+
ImportDeclaration.toString = function () {
|
|
75
|
+
return _ImportDeclaration.toString();
|
|
76
|
+
};
|
|
77
|
+
return ImportDeclaration;
|
|
78
|
+
}(function (node) {
|
|
79
|
+
checkFileType(node);
|
|
80
|
+
checkImports(node);
|
|
81
|
+
}),
|
|
82
|
+
'JSXOpeningElement[name.name="style"]': function JSXOpeningElementNameNameStyle(node) {
|
|
83
|
+
context.report({
|
|
84
|
+
node: node,
|
|
85
|
+
messageId: 'no-global-styles'
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
export default rule;
|
|
92
|
+
function isImportSpecifier(node) {
|
|
93
|
+
return node.type === 'ImportSpecifier';
|
|
94
|
+
}
|
|
@@ -12,6 +12,7 @@ export declare const configs: {
|
|
|
12
12
|
'@atlaskit/ui-styling-standard/no-container-queries': string;
|
|
13
13
|
'@atlaskit/ui-styling-standard/no-dynamic-styles': string;
|
|
14
14
|
'@atlaskit/ui-styling-standard/no-exported-styles': string;
|
|
15
|
+
'@atlaskit/ui-styling-standard/no-global-styles': string;
|
|
15
16
|
'@atlaskit/ui-styling-standard/no-important-styles': string;
|
|
16
17
|
'@atlaskit/ui-styling-standard/no-imported-style-values': string;
|
|
17
18
|
'@atlaskit/ui-styling-standard/no-nested-selectors': string;
|
|
@@ -51,6 +52,7 @@ export declare const configs: {
|
|
|
51
52
|
'@atlaskit/ui-styling-standard/no-container-queries': string;
|
|
52
53
|
'@atlaskit/ui-styling-standard/no-dynamic-styles': string;
|
|
53
54
|
'@atlaskit/ui-styling-standard/no-exported-styles': string;
|
|
55
|
+
'@atlaskit/ui-styling-standard/no-global-styles': string;
|
|
54
56
|
'@atlaskit/ui-styling-standard/no-important-styles': string;
|
|
55
57
|
'@atlaskit/ui-styling-standard/no-imported-style-values': string;
|
|
56
58
|
'@atlaskit/ui-styling-standard/no-nested-selectors': string;
|
|
@@ -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::9ac05c3cbd30f6209164b7a24f7a7a19>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
declare const _default: {
|
|
@@ -15,6 +15,7 @@ declare const _default: {
|
|
|
15
15
|
'@atlaskit/ui-styling-standard/no-container-queries': string;
|
|
16
16
|
'@atlaskit/ui-styling-standard/no-dynamic-styles': string;
|
|
17
17
|
'@atlaskit/ui-styling-standard/no-exported-styles': string;
|
|
18
|
+
'@atlaskit/ui-styling-standard/no-global-styles': string;
|
|
18
19
|
'@atlaskit/ui-styling-standard/no-important-styles': string;
|
|
19
20
|
'@atlaskit/ui-styling-standard/no-imported-style-values': string;
|
|
20
21
|
'@atlaskit/ui-styling-standard/no-nested-selectors': string;
|
|
@@ -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::9ac05c3cbd30f6209164b7a24f7a7a19>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
declare const _default: {
|
|
@@ -15,6 +15,7 @@ declare const _default: {
|
|
|
15
15
|
'@atlaskit/ui-styling-standard/no-container-queries': string;
|
|
16
16
|
'@atlaskit/ui-styling-standard/no-dynamic-styles': string;
|
|
17
17
|
'@atlaskit/ui-styling-standard/no-exported-styles': string;
|
|
18
|
+
'@atlaskit/ui-styling-standard/no-global-styles': string;
|
|
18
19
|
'@atlaskit/ui-styling-standard/no-important-styles': string;
|
|
19
20
|
'@atlaskit/ui-styling-standard/no-imported-style-values': string;
|
|
20
21
|
'@atlaskit/ui-styling-standard/no-nested-selectors': string;
|
|
@@ -8,6 +8,7 @@ declare const _default: {
|
|
|
8
8
|
'no-container-queries': import("eslint").Rule.RuleModule;
|
|
9
9
|
'no-dynamic-styles': import("eslint").Rule.RuleModule;
|
|
10
10
|
'no-exported-styles': import("eslint").Rule.RuleModule;
|
|
11
|
+
'no-global-styles': import("eslint").Rule.RuleModule;
|
|
11
12
|
'no-important-styles': import("eslint").Rule.RuleModule;
|
|
12
13
|
'no-imported-style-values': import("eslint").Rule.RuleModule;
|
|
13
14
|
'no-nested-selectors': import("eslint").Rule.RuleModule;
|
|
@@ -12,6 +12,7 @@ export declare const configs: {
|
|
|
12
12
|
'@atlaskit/ui-styling-standard/no-container-queries': string;
|
|
13
13
|
'@atlaskit/ui-styling-standard/no-dynamic-styles': string;
|
|
14
14
|
'@atlaskit/ui-styling-standard/no-exported-styles': string;
|
|
15
|
+
'@atlaskit/ui-styling-standard/no-global-styles': string;
|
|
15
16
|
'@atlaskit/ui-styling-standard/no-important-styles': string;
|
|
16
17
|
'@atlaskit/ui-styling-standard/no-imported-style-values': string;
|
|
17
18
|
'@atlaskit/ui-styling-standard/no-nested-selectors': string;
|
|
@@ -51,6 +52,7 @@ export declare const configs: {
|
|
|
51
52
|
'@atlaskit/ui-styling-standard/no-container-queries': string;
|
|
52
53
|
'@atlaskit/ui-styling-standard/no-dynamic-styles': string;
|
|
53
54
|
'@atlaskit/ui-styling-standard/no-exported-styles': string;
|
|
55
|
+
'@atlaskit/ui-styling-standard/no-global-styles': string;
|
|
54
56
|
'@atlaskit/ui-styling-standard/no-important-styles': string;
|
|
55
57
|
'@atlaskit/ui-styling-standard/no-imported-style-values': string;
|
|
56
58
|
'@atlaskit/ui-styling-standard/no-nested-selectors': string;
|
|
@@ -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::9ac05c3cbd30f6209164b7a24f7a7a19>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
declare const _default: {
|
|
@@ -15,6 +15,7 @@ declare const _default: {
|
|
|
15
15
|
'@atlaskit/ui-styling-standard/no-container-queries': string;
|
|
16
16
|
'@atlaskit/ui-styling-standard/no-dynamic-styles': string;
|
|
17
17
|
'@atlaskit/ui-styling-standard/no-exported-styles': string;
|
|
18
|
+
'@atlaskit/ui-styling-standard/no-global-styles': string;
|
|
18
19
|
'@atlaskit/ui-styling-standard/no-important-styles': string;
|
|
19
20
|
'@atlaskit/ui-styling-standard/no-imported-style-values': string;
|
|
20
21
|
'@atlaskit/ui-styling-standard/no-nested-selectors': string;
|
|
@@ -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::9ac05c3cbd30f6209164b7a24f7a7a19>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
declare const _default: {
|
|
@@ -15,6 +15,7 @@ declare const _default: {
|
|
|
15
15
|
'@atlaskit/ui-styling-standard/no-container-queries': string;
|
|
16
16
|
'@atlaskit/ui-styling-standard/no-dynamic-styles': string;
|
|
17
17
|
'@atlaskit/ui-styling-standard/no-exported-styles': string;
|
|
18
|
+
'@atlaskit/ui-styling-standard/no-global-styles': string;
|
|
18
19
|
'@atlaskit/ui-styling-standard/no-important-styles': string;
|
|
19
20
|
'@atlaskit/ui-styling-standard/no-imported-style-values': string;
|
|
20
21
|
'@atlaskit/ui-styling-standard/no-nested-selectors': string;
|
|
@@ -8,6 +8,7 @@ declare const _default: {
|
|
|
8
8
|
'no-container-queries': import("eslint").Rule.RuleModule;
|
|
9
9
|
'no-dynamic-styles': import("eslint").Rule.RuleModule;
|
|
10
10
|
'no-exported-styles': import("eslint").Rule.RuleModule;
|
|
11
|
+
'no-global-styles': import("eslint").Rule.RuleModule;
|
|
11
12
|
'no-important-styles': import("eslint").Rule.RuleModule;
|
|
12
13
|
'no-imported-style-values': import("eslint").Rule.RuleModule;
|
|
13
14
|
'no-nested-selectors': import("eslint").Rule.RuleModule;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/eslint-plugin-ui-styling-standard",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"author": "Atlassian Pty Ltd",
|
|
5
5
|
"description": "The eslint plugin to enforce and educate on Atlassian's UI Styling Standard",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"@af/formatting": "*",
|
|
53
53
|
"@atlaskit/ds-lib": "^2.3.0",
|
|
54
|
-
"@atlaskit/eslint-plugin-design-system": "^10.
|
|
54
|
+
"@atlaskit/eslint-plugin-design-system": "^10.2.0",
|
|
55
55
|
"@atlassian/atlassian-frontend-prettier-config-1.0.1": "npm:@atlassian/atlassian-frontend-prettier-config@1.0.1",
|
|
56
56
|
"@atlassian/codegen": "*",
|
|
57
57
|
"@compiled/eslint-plugin": "^0.13.6",
|
|
@@ -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::9ac05c3cbd30f6209164b7a24f7a7a19>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
export default {
|
|
@@ -15,6 +15,7 @@ export default {
|
|
|
15
15
|
'@atlaskit/ui-styling-standard/no-container-queries': 'warn',
|
|
16
16
|
'@atlaskit/ui-styling-standard/no-dynamic-styles': 'warn',
|
|
17
17
|
'@atlaskit/ui-styling-standard/no-exported-styles': 'warn',
|
|
18
|
+
'@atlaskit/ui-styling-standard/no-global-styles': 'warn',
|
|
18
19
|
'@atlaskit/ui-styling-standard/no-important-styles': 'warn',
|
|
19
20
|
'@atlaskit/ui-styling-standard/no-imported-style-values': 'warn',
|
|
20
21
|
'@atlaskit/ui-styling-standard/no-nested-selectors': 'warn',
|
|
@@ -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::9ac05c3cbd30f6209164b7a24f7a7a19>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
export default {
|
|
@@ -15,6 +15,7 @@ export default {
|
|
|
15
15
|
'@atlaskit/ui-styling-standard/no-container-queries': 'warn',
|
|
16
16
|
'@atlaskit/ui-styling-standard/no-dynamic-styles': 'warn',
|
|
17
17
|
'@atlaskit/ui-styling-standard/no-exported-styles': 'warn',
|
|
18
|
+
'@atlaskit/ui-styling-standard/no-global-styles': 'warn',
|
|
18
19
|
'@atlaskit/ui-styling-standard/no-important-styles': 'warn',
|
|
19
20
|
'@atlaskit/ui-styling-standard/no-imported-style-values': 'warn',
|
|
20
21
|
'@atlaskit/ui-styling-standard/no-nested-selectors': 'warn',
|
|
@@ -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::3cea683df6e31f816db56abf1fd65c1e>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
import atlaskitTheme from './atlaskit-theme';
|
|
@@ -12,6 +12,7 @@ import noClassnameProp from './no-classname-prop';
|
|
|
12
12
|
import noContainerQueries from './no-container-queries';
|
|
13
13
|
import noDynamicStyles from './no-dynamic-styles';
|
|
14
14
|
import noExportedStyles from './no-exported-styles';
|
|
15
|
+
import noGlobalStyles from './no-global-styles';
|
|
15
16
|
import noImportantStyles from './no-important-styles';
|
|
16
17
|
import noImportedStyleValues from './no-imported-style-values';
|
|
17
18
|
import noNestedSelectors from './no-nested-selectors';
|
|
@@ -28,6 +29,7 @@ export default {
|
|
|
28
29
|
'no-container-queries': noContainerQueries,
|
|
29
30
|
'no-dynamic-styles': noDynamicStyles,
|
|
30
31
|
'no-exported-styles': noExportedStyles,
|
|
32
|
+
'no-global-styles': noGlobalStyles,
|
|
31
33
|
'no-important-styles': noImportantStyles,
|
|
32
34
|
'no-imported-style-values': noImportedStyleValues,
|
|
33
35
|
'no-nested-selectors': noNestedSelectors,
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
This rule prevents global styles through CSS-in-JS or CSS module imports.
|
|
2
|
+
|
|
3
|
+
Requiring local definition of styles helps to ensure that style dependencies are statically resolvable.
|
|
4
|
+
|
|
5
|
+
## Examples
|
|
6
|
+
|
|
7
|
+
### Incorrect
|
|
8
|
+
|
|
9
|
+
```tsx
|
|
10
|
+
import { Global } from '@emotion/react';
|
|
11
|
+
|
|
12
|
+
<Global
|
|
13
|
+
styles={{
|
|
14
|
+
'.some-class': {
|
|
15
|
+
fontSize: 50,
|
|
16
|
+
textAlign: 'center',
|
|
17
|
+
},
|
|
18
|
+
}}
|
|
19
|
+
/>;
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
```tsx
|
|
23
|
+
import { createGlobalStyle } from 'styled-components';
|
|
24
|
+
|
|
25
|
+
const GlobalStyle = createGlobalStyle({
|
|
26
|
+
body: {
|
|
27
|
+
margin: 0,
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
```tsx
|
|
33
|
+
import { injectGlobal } from 'styled-components';
|
|
34
|
+
|
|
35
|
+
injectGlobal({
|
|
36
|
+
body: {
|
|
37
|
+
margin: 0,
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
```tsx
|
|
43
|
+
<style>
|
|
44
|
+
{`
|
|
45
|
+
.some-class {
|
|
46
|
+
color: red;
|
|
47
|
+
}
|
|
48
|
+
`}
|
|
49
|
+
</style>
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### Correct
|
|
53
|
+
|
|
54
|
+
```tsx
|
|
55
|
+
import '@atlaskit/css-reset';
|
|
56
|
+
```
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { tester } from '../../__tests__/utils/_tester';
|
|
2
|
+
import rule from '../index';
|
|
3
|
+
|
|
4
|
+
tester.run('no-css-modules', rule, {
|
|
5
|
+
valid: [
|
|
6
|
+
"import 'styles-css';",
|
|
7
|
+
"import 'less';",
|
|
8
|
+
"import 'sass-module';",
|
|
9
|
+
"import 'something-scss-something';",
|
|
10
|
+
],
|
|
11
|
+
invalid: [
|
|
12
|
+
{
|
|
13
|
+
name: '.css import',
|
|
14
|
+
code: "import 'styles.css';",
|
|
15
|
+
errors: [{ messageId: 'no-css-modules' }],
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
name: '.less import',
|
|
19
|
+
code: "import 'styles.less';",
|
|
20
|
+
errors: [{ messageId: 'no-css-modules' }],
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
name: '.sass import',
|
|
24
|
+
code: "import 'styles.sass';",
|
|
25
|
+
errors: [{ messageId: 'no-css-modules' }],
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
name: '.scss import',
|
|
29
|
+
code: "import 'styles.scss';",
|
|
30
|
+
errors: [{ messageId: 'no-css-modules' }],
|
|
31
|
+
},
|
|
32
|
+
],
|
|
33
|
+
});
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { tester } from '../../__tests__/utils/_tester';
|
|
2
|
+
import rule from '../index';
|
|
3
|
+
|
|
4
|
+
tester.run('no-global-styles', rule, {
|
|
5
|
+
valid: [
|
|
6
|
+
"import { css } from '@emotion/react';",
|
|
7
|
+
"import { keyframes } from '@emotion/core';",
|
|
8
|
+
"import styled from 'styled-components';",
|
|
9
|
+
],
|
|
10
|
+
invalid: [
|
|
11
|
+
{
|
|
12
|
+
name: '[@emotion/react] Global',
|
|
13
|
+
code: "import { Global } from '@emotion/react';",
|
|
14
|
+
errors: [{ messageId: 'no-global-styles' }],
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
name: '[@emotion/core] Global',
|
|
18
|
+
code: "import { Global } from '@emotion/core';",
|
|
19
|
+
errors: [{ messageId: 'no-global-styles' }],
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
name: '[styled-components] injectGlobal',
|
|
23
|
+
code: "import { injectGlobal } from 'styled-components';",
|
|
24
|
+
errors: [{ messageId: 'no-global-styles' }],
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
name: '[styled-components] createGlobalStyle',
|
|
28
|
+
code: "import { createGlobalStyle } from 'styled-components';",
|
|
29
|
+
errors: [{ messageId: 'no-global-styles' }],
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
name: 'aliasing',
|
|
33
|
+
code: "import { Global as EmotionGlobal } from '@emotion/react';",
|
|
34
|
+
errors: [{ messageId: 'no-global-styles' }],
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
name: 'style tag',
|
|
38
|
+
code: `
|
|
39
|
+
<style>
|
|
40
|
+
{'.my-class { color: red; }'}
|
|
41
|
+
</style>
|
|
42
|
+
`,
|
|
43
|
+
errors: [{ messageId: 'no-global-styles' }],
|
|
44
|
+
},
|
|
45
|
+
],
|
|
46
|
+
});
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import type * as ESTree from 'eslint-codemod-utils';
|
|
2
|
+
|
|
3
|
+
import { createLintRule } from '../utils/create-rule';
|
|
4
|
+
|
|
5
|
+
const restrictedFileTypes = ['.css', '.less', '.sass', '.scss'];
|
|
6
|
+
|
|
7
|
+
const restrictedImports = {
|
|
8
|
+
'@emotion/core': ['Global'],
|
|
9
|
+
'@emotion/react': ['Global'],
|
|
10
|
+
'styled-components': ['createGlobalStyle', 'injectGlobal'],
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
type RestrictedImportSource = keyof typeof restrictedImports;
|
|
14
|
+
function isRestrictedImportSource(
|
|
15
|
+
importSource: string,
|
|
16
|
+
): importSource is RestrictedImportSource {
|
|
17
|
+
return importSource in restrictedImports;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const rule = createLintRule({
|
|
21
|
+
meta: {
|
|
22
|
+
name: 'no-global-styles',
|
|
23
|
+
docs: {
|
|
24
|
+
description:
|
|
25
|
+
'Prevents global styles through CSS-in-JS or CSS module imports',
|
|
26
|
+
recommended: true,
|
|
27
|
+
severity: 'warn',
|
|
28
|
+
},
|
|
29
|
+
messages: {
|
|
30
|
+
'no-global-styles': 'Global styles are not allowed.',
|
|
31
|
+
'no-css-modules': 'Importing CSS files is not allowed.',
|
|
32
|
+
},
|
|
33
|
+
type: 'problem',
|
|
34
|
+
},
|
|
35
|
+
create(context) {
|
|
36
|
+
function checkFileType(node: ESTree.ImportDeclaration) {
|
|
37
|
+
const importSource = node.source.value as string;
|
|
38
|
+
if (restrictedFileTypes.some((suffix) => importSource.endsWith(suffix))) {
|
|
39
|
+
context.report({
|
|
40
|
+
node: node.source,
|
|
41
|
+
messageId: 'no-css-modules',
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function checkImports(node: ESTree.ImportDeclaration) {
|
|
47
|
+
const importSource = node.source.value as string;
|
|
48
|
+
if (!isRestrictedImportSource(importSource)) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
for (const importName of restrictedImports[importSource]) {
|
|
53
|
+
const specifier = node.specifiers
|
|
54
|
+
.filter(isImportSpecifier)
|
|
55
|
+
.find((specifier) => specifier.imported.name === importName);
|
|
56
|
+
|
|
57
|
+
if (specifier) {
|
|
58
|
+
context.report({
|
|
59
|
+
node: specifier,
|
|
60
|
+
messageId: 'no-global-styles',
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return {
|
|
67
|
+
ImportDeclaration(node: ESTree.ImportDeclaration) {
|
|
68
|
+
checkFileType(node);
|
|
69
|
+
checkImports(node);
|
|
70
|
+
},
|
|
71
|
+
'JSXOpeningElement[name.name="style"]'(node: ESTree.Node) {
|
|
72
|
+
context.report({
|
|
73
|
+
node,
|
|
74
|
+
messageId: 'no-global-styles',
|
|
75
|
+
});
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
},
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
export default rule;
|
|
82
|
+
|
|
83
|
+
function isImportSpecifier(node: ESTree.Node): node is ESTree.ImportSpecifier {
|
|
84
|
+
return node.type === 'ImportSpecifier';
|
|
85
|
+
}
|
|
@@ -1,25 +1,17 @@
|
|
|
1
|
-
Ensures usage of `@compiled/react` over other CSS-in-JS libraries.
|
|
1
|
+
Ensures usage of `@compiled/react` over other CSS-in-JS libraries like Emotion or styled-components.
|
|
2
2
|
|
|
3
3
|
**WARNING**
|
|
4
|
-
|
|
5
|
-
It may be unsafe to mix usages of `@compiled/react` with other CSS-in-JS libraries.
|
|
6
|
-
|
|
7
|
-
When converting to `@compiled/react` verify ALL changes.
|
|
8
|
-
|
|
9
|
-
For this reason, the auto-fixer has been disabled by default.
|
|
4
|
+
It may be unsafe to mix usages of `@compiled/react` with other CSS-in-JS libraries on the same component. When converting to `@compiled/react` verify ALL changes. For this reason, the auto-fixer has been disabled by default, but it may be useful to enable to empower a migration.
|
|
10
5
|
|
|
11
6
|
## Examples
|
|
12
7
|
|
|
13
8
|
### Incorrect
|
|
14
9
|
|
|
15
|
-
```js
|
|
16
|
-
import { css } from '@emotion/core';
|
|
17
|
-
import styled from '@emotion/styled';
|
|
18
|
-
```
|
|
19
|
-
|
|
20
10
|
```js
|
|
21
11
|
/** @jsx jsx */
|
|
12
|
+
import { css } from '@emotion/core';
|
|
22
13
|
import { jsx } from '@emotion/react';
|
|
14
|
+
import styled from '@emotion/styled';
|
|
23
15
|
```
|
|
24
16
|
|
|
25
17
|
```js
|
|
@@ -28,13 +20,21 @@ import styled, { css } from 'styled-components';
|
|
|
28
20
|
|
|
29
21
|
### Correct
|
|
30
22
|
|
|
23
|
+
We expect usage of `xcss` with `@atlaskit/primitives` when working with Primitives, and `css` with `@compiled/react` when working with custom or native code.
|
|
24
|
+
|
|
31
25
|
```js
|
|
32
|
-
|
|
26
|
+
/** @jsx jsx */
|
|
27
|
+
import { jsx, css, styled } from '@compiled/react';
|
|
28
|
+
|
|
29
|
+
const styles = css({ color: 'var(--ds-color-text)' });
|
|
30
|
+
export default () => <div css={styles}>…</div>
|
|
33
31
|
```
|
|
34
32
|
|
|
35
33
|
```js
|
|
36
|
-
|
|
37
|
-
|
|
34
|
+
import { xcss, Box } from '@atlaskit/primitives';
|
|
35
|
+
|
|
36
|
+
const styles = xcss({ color: 'color.text' });
|
|
37
|
+
export default () => <Box xcss={styles}>…</Box>
|
|
38
38
|
```
|
|
39
39
|
|
|
40
40
|
## Options
|
|
@@ -43,7 +43,7 @@ import { jsx } from '@compiled/react';
|
|
|
43
43
|
|
|
44
44
|
Determines whether or not the auto-fixer is enabled.
|
|
45
45
|
|
|
46
|
-
Defaults to `false` due to safety concerns when mixing Compiled and other CSS-in-JS libraries.
|
|
46
|
+
Defaults to `false` due to safety concerns when mixing Compiled and other CSS-in-JS libraries on the same component.
|
|
47
47
|
|
|
48
48
|
Even when enabled, the auto-fixer will only convert usages that are deemed safe.
|
|
49
49
|
Currently this is limited to purely static styles where all keys and values are simple literals.
|
|
@@ -10,6 +10,30 @@ const importSources = [
|
|
|
10
10
|
'styled-components',
|
|
11
11
|
];
|
|
12
12
|
|
|
13
|
+
tester.run('imports - ignored', rule, {
|
|
14
|
+
valid: [
|
|
15
|
+
{
|
|
16
|
+
name: '[@atlaskit/primitives.xcss] - is ignored (it\'s okay to use, for now)',
|
|
17
|
+
code: `
|
|
18
|
+
import { xcss, Box } from '@atlaskit/primitives';
|
|
19
|
+
`,
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
name: '[@atlaskit/css] - is ignored (it\'s okay to use)',
|
|
23
|
+
code: `
|
|
24
|
+
import { cssMap, keyframes } from '@atlaskit/css';
|
|
25
|
+
`,
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
name: '[@stylexjs/stylex] - is ignored (we don\'t maintain a list of all CSS-in-JS libraries, but we could)',
|
|
29
|
+
code: `
|
|
30
|
+
import * as stylex from '@stylexjs/stylex';
|
|
31
|
+
`,
|
|
32
|
+
}
|
|
33
|
+
],
|
|
34
|
+
invalid: [],
|
|
35
|
+
});
|
|
36
|
+
|
|
13
37
|
tester.run('imports - fixable', rule, {
|
|
14
38
|
valid: [],
|
|
15
39
|
invalid: [
|