@atlaskit/eslint-plugin-ui-styling-standard 0.14.2 → 0.15.1
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 +188 -167
- package/README.md +1 -0
- package/afm-cc/tsconfig.json +10 -3
- package/afm-jira/tsconfig.json +28 -0
- package/constellation/atlaskit-theme/usage.mdx +17 -17
- package/constellation/convert-props-syntax/usage.mdx +14 -14
- package/constellation/enforce-style-prop/usage.mdx +17 -17
- package/constellation/index/overview.mdx +99 -98
- package/constellation/local-cx-xcss/usage.mdx +4 -4
- package/constellation/no-array-arguments/usage.mdx +7 -7
- package/constellation/no-container-queries/usage.mdx +14 -14
- package/constellation/no-dynamic-styles/usage.mdx +19 -19
- package/constellation/no-exported-styles/usage.mdx +15 -15
- package/constellation/no-global-styles/usage.mdx +13 -13
- package/constellation/no-important-styles/usage.mdx +2 -2
- package/constellation/no-imported-style-values/usage.mdx +16 -16
- package/constellation/no-nested-selectors/usage.mdx +18 -18
- package/constellation/no-styled/usage.mdx +6 -6
- package/constellation/no-unsafe-selectors/usage.mdx +244 -0
- package/constellation/no-unsafe-values/usage.mdx +33 -33
- package/dist/cjs/index.codegen.js +1 -1
- 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-unsafe-selectors/constants.js +30 -0
- package/dist/cjs/rules/no-unsafe-selectors/index.js +188 -0
- package/dist/cjs/rules/no-unsafe-selectors/lint-selector.js +198 -0
- package/dist/cjs/rules/no-unsafe-selectors/source-position-utils.js +42 -0
- package/dist/cjs/rules/no-unsafe-selectors/walk-css-map.js +186 -0
- package/dist/es2019/index.codegen.js +1 -1
- 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-unsafe-selectors/constants.js +22 -0
- package/dist/es2019/rules/no-unsafe-selectors/index.js +176 -0
- package/dist/es2019/rules/no-unsafe-selectors/lint-selector.js +161 -0
- package/dist/es2019/rules/no-unsafe-selectors/source-position-utils.js +31 -0
- package/dist/es2019/rules/no-unsafe-selectors/walk-css-map.js +180 -0
- package/dist/esm/index.codegen.js +1 -1
- 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-unsafe-selectors/constants.js +24 -0
- package/dist/esm/rules/no-unsafe-selectors/index.js +181 -0
- package/dist/esm/rules/no-unsafe-selectors/lint-selector.js +191 -0
- package/dist/esm/rules/no-unsafe-selectors/source-position-utils.js +34 -0
- package/dist/esm/rules/no-unsafe-selectors/walk-css-map.js +179 -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-unsafe-selectors/constants.d.ts +23 -0
- package/dist/types/rules/no-unsafe-selectors/index.d.ts +3 -0
- package/dist/types/rules/no-unsafe-selectors/lint-selector.d.ts +14 -0
- package/dist/types/rules/no-unsafe-selectors/source-position-utils.d.ts +20 -0
- package/dist/types/rules/no-unsafe-selectors/walk-css-map.d.ts +23 -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-unsafe-selectors/constants.d.ts +84 -0
- package/dist/types-ts4.5/rules/no-unsafe-selectors/index.d.ts +3 -0
- package/dist/types-ts4.5/rules/no-unsafe-selectors/lint-selector.d.ts +14 -0
- package/dist/types-ts4.5/rules/no-unsafe-selectors/source-position-utils.d.ts +23 -0
- package/dist/types-ts4.5/rules/no-unsafe-selectors/walk-css-map.d.ts +23 -0
- package/package.json +7 -8
- package/scripts/codegen.tsx +3 -4
- package/src/index.codegen.tsx +3 -3
- package/src/presets/all.codegen.tsx +70 -72
- package/src/presets/recommended.codegen.tsx +70 -72
- package/src/rules/index.codegen.tsx +19 -17
- package/src/rules/no-classname-prop/index.tsx +1 -1
- package/src/rules/no-nested-selectors/index.tsx +1 -1
- package/src/rules/no-unsafe-selectors/README.md +232 -0
- package/src/rules/no-unsafe-selectors/__tests__/no-ambiguous-pseudos.test.tsx +368 -0
- package/src/rules/no-unsafe-selectors/__tests__/no-grouped-at-rules.test.tsx +60 -0
- package/src/rules/no-unsafe-selectors/__tests__/no-increased-specificity.test.tsx +73 -0
- package/src/rules/no-unsafe-selectors/__tests__/no-keyframes-at-rules.test.tsx +40 -0
- package/src/rules/no-unsafe-selectors/__tests__/no-legacy-pseudo-element-syntax.test.tsx +101 -0
- package/src/rules/no-unsafe-selectors/__tests__/no-restricted-at-rules.test.tsx +131 -0
- package/src/rules/no-unsafe-selectors/__tests__/no-restricted-pseudos.test.tsx +132 -0
- package/src/rules/no-unsafe-selectors/__tests__/no-selectors-object.test.tsx +25 -0
- package/src/rules/no-unsafe-selectors/__tests__/no-unparsable-selectors.test.tsx +35 -0
- package/src/rules/no-unsafe-selectors/__tests__/rule.test.tsx +238 -0
- package/src/rules/no-unsafe-selectors/constants.tsx +99 -0
- package/src/rules/no-unsafe-selectors/index.tsx +198 -0
- package/src/rules/no-unsafe-selectors/lint-selector.tsx +155 -0
- package/src/rules/no-unsafe-selectors/source-position-utils.tsx +55 -0
- package/src/rules/no-unsafe-selectors/walk-css-map.tsx +232 -0
- package/tsconfig.app.json +45 -45
- package/tsconfig.dev.json +43 -43
|
@@ -15,7 +15,7 @@ Function calls are not allowed as arguments or as values, unless they are specif
|
|
|
15
15
|
import { css } from '@compiled/react';
|
|
16
16
|
|
|
17
17
|
function getStyles() {
|
|
18
|
-
|
|
18
|
+
return { width: 100 };
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
const styles = css(getStyles());
|
|
@@ -25,11 +25,11 @@ const styles = css(getStyles());
|
|
|
25
25
|
import { css } from '@compiled/react';
|
|
26
26
|
|
|
27
27
|
function getWidth() {
|
|
28
|
-
|
|
28
|
+
return 100;
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
const styles = css({
|
|
32
|
-
|
|
32
|
+
width: getWidth(),
|
|
33
33
|
});
|
|
34
34
|
```
|
|
35
35
|
|
|
@@ -43,12 +43,12 @@ import { css } from '@compiled/react';
|
|
|
43
43
|
import { SELECTOR } from 'my-package';
|
|
44
44
|
|
|
45
45
|
const styles = css({
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
46
|
+
[SELECTOR]: {
|
|
47
|
+
color: 'red',
|
|
48
|
+
},
|
|
49
|
+
[`${SELECTOR} > p`]: {
|
|
50
|
+
width: 100,
|
|
51
|
+
},
|
|
52
52
|
});
|
|
53
53
|
```
|
|
54
54
|
|
|
@@ -56,19 +56,19 @@ const styles = css({
|
|
|
56
56
|
|
|
57
57
|
Variables are not allowed as values, unless they:
|
|
58
58
|
|
|
59
|
-
-
|
|
60
|
-
-
|
|
59
|
+
- Have a simple, static value
|
|
60
|
+
- Are defined in the same file
|
|
61
61
|
|
|
62
62
|
```tsx
|
|
63
63
|
import { css } from '@compiled/react';
|
|
64
64
|
import { SELECTOR } from 'my-package';
|
|
65
65
|
|
|
66
66
|
function myFunction() {
|
|
67
|
-
|
|
67
|
+
return '5px';
|
|
68
68
|
}
|
|
69
69
|
|
|
70
70
|
const styles = css({
|
|
71
|
-
|
|
71
|
+
height: myFunction,
|
|
72
72
|
});
|
|
73
73
|
```
|
|
74
74
|
|
|
@@ -81,11 +81,11 @@ import { css } from '@compiled/react';
|
|
|
81
81
|
import { token } from '@atlaskit/tokens';
|
|
82
82
|
|
|
83
83
|
const colors = {
|
|
84
|
-
|
|
84
|
+
text: token('color.text'),
|
|
85
85
|
};
|
|
86
86
|
|
|
87
87
|
const styles = css({
|
|
88
|
-
|
|
88
|
+
color: colors.text,
|
|
89
89
|
});
|
|
90
90
|
```
|
|
91
91
|
|
|
@@ -97,11 +97,11 @@ Spread elements are not allowed.
|
|
|
97
97
|
import { css } from '@compiled/react';
|
|
98
98
|
|
|
99
99
|
const buttonStyles = {
|
|
100
|
-
|
|
100
|
+
color: 'blue',
|
|
101
101
|
};
|
|
102
102
|
|
|
103
103
|
const styles = css({
|
|
104
|
-
|
|
104
|
+
...buttonStyles,
|
|
105
105
|
});
|
|
106
106
|
```
|
|
107
107
|
|
|
@@ -113,7 +113,7 @@ Array values are not allowed. This syntax is not supported by most styling libra
|
|
|
113
113
|
import { css } from '@compiled/react';
|
|
114
114
|
|
|
115
115
|
const styles = css({
|
|
116
|
-
|
|
116
|
+
'::before': [{ fontWeight: 'bold' }, { color: 'red' }],
|
|
117
117
|
});
|
|
118
118
|
```
|
|
119
119
|
|
|
@@ -121,26 +121,26 @@ const styles = css({
|
|
|
121
121
|
|
|
122
122
|
Things to note about the following example:
|
|
123
123
|
|
|
124
|
-
-
|
|
125
|
-
-
|
|
126
|
-
-
|
|
127
|
-
|
|
124
|
+
- The `warningStyles` are conditionally applied using the `css` prop
|
|
125
|
+
- The dynamic `width` is applied using the `style` prop
|
|
126
|
+
- The `token()` calls are allowed because they are statically analyzable (and in the default
|
|
127
|
+
allow-list)
|
|
128
128
|
|
|
129
129
|
```tsx
|
|
130
130
|
import { css } from '@compiled/react';
|
|
131
131
|
import { token } from '@atlaskit/tokens';
|
|
132
132
|
|
|
133
133
|
const baseStyles = css({
|
|
134
|
-
|
|
134
|
+
height: 100,
|
|
135
135
|
});
|
|
136
136
|
|
|
137
137
|
const warningStyles = css({
|
|
138
|
-
|
|
139
|
-
|
|
138
|
+
color: token('color.text.warning'),
|
|
139
|
+
backgroundColor: token('color.background.warning'),
|
|
140
140
|
});
|
|
141
141
|
|
|
142
142
|
const Component = ({ isWarning, width }: { isWarning: boolean; width: number }) => {
|
|
143
|
-
|
|
143
|
+
return <div style={{ width }} css={[baseStyles, isWarning && warningStyles]} />;
|
|
144
144
|
};
|
|
145
145
|
```
|
|
146
146
|
|
|
@@ -204,13 +204,13 @@ Default imports are not currently supported.
|
|
|
204
204
|
|
|
205
205
|
By default, this rule will check `css` usages from:
|
|
206
206
|
|
|
207
|
-
-
|
|
208
|
-
-
|
|
209
|
-
-
|
|
210
|
-
-
|
|
211
|
-
-
|
|
212
|
-
-
|
|
213
|
-
-
|
|
207
|
+
- `@atlaskit/css`
|
|
208
|
+
- `@atlaskit/primitives`
|
|
209
|
+
- `@compiled/react`
|
|
210
|
+
- `@emotion/react`
|
|
211
|
+
- `@emotion/core`
|
|
212
|
+
- `@emotion/styled`
|
|
213
|
+
- `styled-components`
|
|
214
214
|
|
|
215
215
|
To change this list of libraries, you can define a custom set of `importSources`, which accepts an
|
|
216
216
|
array of package names (strings). This will override the built-in allow-list.
|
|
@@ -16,7 +16,7 @@ var _recommended = _interopRequireDefault(require("./presets/recommended.codegen
|
|
|
16
16
|
var _index = _interopRequireDefault(require("./rules/index.codegen"));
|
|
17
17
|
/**
|
|
18
18
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
19
|
-
* @codegen <<SignedSource::
|
|
19
|
+
* @codegen <<SignedSource::aff3fad2b8534fad07ba5f0f1b981a55>>
|
|
20
20
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
21
21
|
*/
|
|
22
22
|
|
|
@@ -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::f240d1cd5b93827327b66c28ad47e698>>
|
|
10
10
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
11
11
|
*/
|
|
12
12
|
var _default = exports.default = {
|
|
@@ -26,6 +26,7 @@ var _default = exports.default = {
|
|
|
26
26
|
'@atlaskit/ui-styling-standard/no-imported-style-values': 'warn',
|
|
27
27
|
'@atlaskit/ui-styling-standard/no-nested-selectors': 'warn',
|
|
28
28
|
'@atlaskit/ui-styling-standard/no-styled': 'warn',
|
|
29
|
+
'@atlaskit/ui-styling-standard/no-unsafe-selectors': 'warn',
|
|
29
30
|
'@atlaskit/ui-styling-standard/no-unsafe-values': 'warn',
|
|
30
31
|
'@atlaskit/ui-styling-standard/use-compiled': 'warn',
|
|
31
32
|
'@atlaskit/design-system/consistent-css-prop-usage': ['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::f240d1cd5b93827327b66c28ad47e698>>
|
|
10
10
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
11
11
|
*/
|
|
12
12
|
var _default = exports.default = {
|
|
@@ -26,6 +26,7 @@ var _default = exports.default = {
|
|
|
26
26
|
'@atlaskit/ui-styling-standard/no-imported-style-values': 'warn',
|
|
27
27
|
'@atlaskit/ui-styling-standard/no-nested-selectors': 'warn',
|
|
28
28
|
'@atlaskit/ui-styling-standard/no-styled': 'warn',
|
|
29
|
+
'@atlaskit/ui-styling-standard/no-unsafe-selectors': 'warn',
|
|
29
30
|
'@atlaskit/ui-styling-standard/no-unsafe-values': 'warn',
|
|
30
31
|
'@atlaskit/ui-styling-standard/use-compiled': 'warn',
|
|
31
32
|
'@atlaskit/design-system/consistent-css-prop-usage': ['warn', {
|
|
@@ -19,11 +19,12 @@ var _noImportantStyles = _interopRequireDefault(require("./no-important-styles")
|
|
|
19
19
|
var _noImportedStyleValues = _interopRequireDefault(require("./no-imported-style-values"));
|
|
20
20
|
var _noNestedSelectors = _interopRequireDefault(require("./no-nested-selectors"));
|
|
21
21
|
var _noStyled = _interopRequireDefault(require("./no-styled"));
|
|
22
|
+
var _noUnsafeSelectors = _interopRequireDefault(require("./no-unsafe-selectors"));
|
|
22
23
|
var _noUnsafeValues = _interopRequireDefault(require("./no-unsafe-values"));
|
|
23
24
|
var _useCompiled = _interopRequireDefault(require("./use-compiled"));
|
|
24
25
|
/**
|
|
25
26
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
26
|
-
* @codegen <<SignedSource::
|
|
27
|
+
* @codegen <<SignedSource::6ad0de2d4bdac726387f27681ad9fcf4>>
|
|
27
28
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
28
29
|
*/
|
|
29
30
|
var _default = exports.default = {
|
|
@@ -41,6 +42,7 @@ var _default = exports.default = {
|
|
|
41
42
|
'no-imported-style-values': _noImportedStyleValues.default,
|
|
42
43
|
'no-nested-selectors': _noNestedSelectors.default,
|
|
43
44
|
'no-styled': _noStyled.default,
|
|
45
|
+
'no-unsafe-selectors': _noUnsafeSelectors.default,
|
|
44
46
|
'no-unsafe-values': _noUnsafeValues.default,
|
|
45
47
|
'use-compiled': _useCompiled.default
|
|
46
48
|
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.legacyPseudoElements = exports.ignoredAtRules = exports.allowedPseudos = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* Validation approach from
|
|
9
|
+
* https://stackoverflow.com/a/71236280
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Exporting this so it isn't considered unused.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
var cssPseudos = ['&:active', '&:autofill', '&:blank', '&:checked', '&:default', '&:defined', '&:disabled', '&:empty', '&:enabled', '&:first', '&:focus', '&:focus-visible', '&:focus-within', '&:fullscreen', '&:hover', '&:in-range', '&:indeterminate', '&:invalid', '&:left', '&:link', '&:local-link', '&:optional', '&:out-of-range', '&:paused', '&:picture-in-picture', '&:placeholder-shown', '&:playing', '&:read-only', '&:read-write', '&:required', '&:right', '&:target', '&:user-invalid', '&:user-valid', '&:valid', '&:visited', '&::after', '&::backdrop', '&::before', '&::cue', '&::cue-region', '&::first-letter', '&::first-line', '&::grammar-error', '&::marker', '&::placeholder', '&::selection', '&::spelling-error', '&::target-text', '&::view-transition'];
|
|
17
|
+
var allowedPseudos = exports.allowedPseudos = new Set(
|
|
18
|
+
/**
|
|
19
|
+
* The `&` is included above for type checking reasons,
|
|
20
|
+
* but we don't actually want it when consuming the values.
|
|
21
|
+
*/
|
|
22
|
+
cssPseudos.map(function (pseudo) {
|
|
23
|
+
return pseudo.slice(1);
|
|
24
|
+
}));
|
|
25
|
+
var legacyPseudoElements = exports.legacyPseudoElements = new Set([':after', ':before', ':first-letter', ':first-line']);
|
|
26
|
+
var ignoredAtRules = exports.ignoredAtRules = new Set(['@container',
|
|
27
|
+
// ignored because it's covered by `no-container-queries`
|
|
28
|
+
'@media',
|
|
29
|
+
// ignored because it's covered by `no-nested-styles`
|
|
30
|
+
'@supports', '@property']);
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = void 0;
|
|
8
|
+
var _postcssSelectorParser = _interopRequireDefault(require("postcss-selector-parser"));
|
|
9
|
+
var _isSupportedImport = require("@atlaskit/eslint-utils/is-supported-import");
|
|
10
|
+
var _schema = require("@atlaskit/eslint-utils/schema");
|
|
11
|
+
var _walkStyleProperties = require("@atlaskit/eslint-utils/walk-style-properties");
|
|
12
|
+
var _createRuleWithTypedConfig = require("../utils/create-rule-with-typed-config");
|
|
13
|
+
var _constants = require("./constants");
|
|
14
|
+
var _lintSelector = require("./lint-selector");
|
|
15
|
+
var _walkCssMap = require("./walk-css-map");
|
|
16
|
+
var cssSelectorProcessor = (0, _postcssSelectorParser.default)();
|
|
17
|
+
var rule = (0, _createRuleWithTypedConfig.createLintRuleWithTypedConfig)({
|
|
18
|
+
meta: {
|
|
19
|
+
name: 'no-unsafe-selectors',
|
|
20
|
+
docs: {
|
|
21
|
+
description: 'Disallows use of nested styles in `css` functions.',
|
|
22
|
+
recommended: true,
|
|
23
|
+
severity: 'warn'
|
|
24
|
+
},
|
|
25
|
+
fixable: 'code',
|
|
26
|
+
hasSuggestions: true,
|
|
27
|
+
messages: {
|
|
28
|
+
/**
|
|
29
|
+
* Selector messages
|
|
30
|
+
*/
|
|
31
|
+
'no-ambiguous-pseudos': 'Pseudo-classes and pseudo-elements without a leading selector are ambiguous. Use a more explicit selector.',
|
|
32
|
+
'no-increased-specificity': 'Do not chain the nesting selector.',
|
|
33
|
+
'no-restricted-pseudos': 'The {{pseudo}} pseudo is not allowed.',
|
|
34
|
+
'no-legacy-pseudo-element-syntax': 'Use a double colon for pseudo-elements. The single colon syntax is not supported for all pseudo-elements.',
|
|
35
|
+
'no-unparsable-selectors': "The selector '{{selectorText}}' could not be parsed and is likely an authoring mistake. If you think this is an error reach out in #help-ui-styling-standard.",
|
|
36
|
+
'no-selectors-object': 'Do not use the selectors object. Both nested and advanced selectors should be avoided.',
|
|
37
|
+
/**
|
|
38
|
+
* At-rule messages
|
|
39
|
+
*/
|
|
40
|
+
'no-keyframes-at-rules': 'Use the CSS-in-JS `keyframes` API instead of `@keyframes` at-rules.',
|
|
41
|
+
'no-restricted-at-rules': '{{atRule}} at-rule is not allowed.',
|
|
42
|
+
'no-grouped-at-rules': 'Do not group at-rules. Write flattened at-rules instead.',
|
|
43
|
+
/**
|
|
44
|
+
* Suggestion messages
|
|
45
|
+
*/
|
|
46
|
+
'insert-nesting-selector': 'Insert a nesting selector `&` to target the element itself. This is usually the intended behavior.'
|
|
47
|
+
},
|
|
48
|
+
schema: {
|
|
49
|
+
type: 'object',
|
|
50
|
+
properties: {
|
|
51
|
+
importSources: _schema.importSources,
|
|
52
|
+
shouldAlwaysInsertNestingSelectorForAmbiguousPseudos: {
|
|
53
|
+
type: 'boolean',
|
|
54
|
+
default: true
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
additionalProperties: false
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
create: function create(context, config) {
|
|
61
|
+
return {
|
|
62
|
+
Program: function Program(program) {
|
|
63
|
+
(0, _walkCssMap.walkCssMap)({
|
|
64
|
+
context: context,
|
|
65
|
+
program: program,
|
|
66
|
+
importSources: config.importSources,
|
|
67
|
+
visitor: function visitor(property) {
|
|
68
|
+
var type = property.type,
|
|
69
|
+
node = property.node;
|
|
70
|
+
if (type === 'grouped-at-rules') {
|
|
71
|
+
context.report({
|
|
72
|
+
node: node.key,
|
|
73
|
+
messageId: 'no-grouped-at-rules'
|
|
74
|
+
});
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
if (type === 'selectors') {
|
|
78
|
+
context.report({
|
|
79
|
+
node: node.key,
|
|
80
|
+
messageId: 'no-selectors-object'
|
|
81
|
+
});
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
},
|
|
87
|
+
CallExpression: function (_CallExpression) {
|
|
88
|
+
function CallExpression(_x) {
|
|
89
|
+
return _CallExpression.apply(this, arguments);
|
|
90
|
+
}
|
|
91
|
+
CallExpression.toString = function () {
|
|
92
|
+
return _CallExpression.toString();
|
|
93
|
+
};
|
|
94
|
+
return CallExpression;
|
|
95
|
+
}(function (node) {
|
|
96
|
+
var _context$getScope = context.getScope(),
|
|
97
|
+
references = _context$getScope.references;
|
|
98
|
+
var isXcssCall = (0, _isSupportedImport.isXcss)(node, references, config.importSources);
|
|
99
|
+
(0, _walkStyleProperties.walkStyleProperties)(node, references, config.importSources, function (_ref) {
|
|
100
|
+
var key = _ref.key,
|
|
101
|
+
value = _ref.value;
|
|
102
|
+
/**
|
|
103
|
+
* If the value isn't an object expression then the key can't be a selector.
|
|
104
|
+
*
|
|
105
|
+
* This assumes all styles have to be inline, which is enforced by `no-unsafe-values`
|
|
106
|
+
*/
|
|
107
|
+
if (value.type !== 'ObjectExpression') {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Technically the key could be an identifier too, e.g.
|
|
113
|
+
*
|
|
114
|
+
* ```ts
|
|
115
|
+
* css({
|
|
116
|
+
* // This key is an identifier, not a literal
|
|
117
|
+
* selector: {}
|
|
118
|
+
* });
|
|
119
|
+
* ```
|
|
120
|
+
*
|
|
121
|
+
* But an identifier couldn't violate anything in this rule,
|
|
122
|
+
* because it can't contain '@' or ':' characters.
|
|
123
|
+
*/
|
|
124
|
+
if (key.type !== 'Literal' || typeof key.value !== 'string') {
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
var selectorText = key.value;
|
|
128
|
+
if (selectorText.includes('@')) {
|
|
129
|
+
lintAtRule({
|
|
130
|
+
context: context,
|
|
131
|
+
sourceNode: key,
|
|
132
|
+
atRule: selectorText
|
|
133
|
+
});
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
try {
|
|
137
|
+
var selectorList = cssSelectorProcessor.astSync(selectorText);
|
|
138
|
+
selectorList.nodes.forEach(function (selector) {
|
|
139
|
+
return (0, _lintSelector.lintSelector)({
|
|
140
|
+
context: context,
|
|
141
|
+
sourceNode: key,
|
|
142
|
+
selector: selector,
|
|
143
|
+
config: config,
|
|
144
|
+
isXcssCall: isXcssCall
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
} catch (e) {
|
|
148
|
+
context.report({
|
|
149
|
+
node: key,
|
|
150
|
+
messageId: 'no-unparsable-selectors',
|
|
151
|
+
data: {
|
|
152
|
+
selectorText: selectorText
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
})
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
var _default = exports.default = rule;
|
|
162
|
+
function lintAtRule(_ref2) {
|
|
163
|
+
var context = _ref2.context,
|
|
164
|
+
sourceNode = _ref2.sourceNode,
|
|
165
|
+
atRule = _ref2.atRule;
|
|
166
|
+
var matches = atRule.trim().match(/^@[A-z-]+/);
|
|
167
|
+
if (!matches) {
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
var ruleName = matches[0];
|
|
171
|
+
if (_constants.ignoredAtRules.has(ruleName)) {
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
if (ruleName === '@keyframes') {
|
|
175
|
+
context.report({
|
|
176
|
+
node: sourceNode,
|
|
177
|
+
messageId: 'no-keyframes-at-rules'
|
|
178
|
+
});
|
|
179
|
+
} else {
|
|
180
|
+
context.report({
|
|
181
|
+
node: sourceNode,
|
|
182
|
+
messageId: 'no-restricted-at-rules',
|
|
183
|
+
data: {
|
|
184
|
+
atRule: ruleName
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
}
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.lintSelector = lintSelector;
|
|
8
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
9
|
+
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
10
|
+
var _constants = require("./constants");
|
|
11
|
+
var _postcssSelectorParser = require("postcss-selector-parser");
|
|
12
|
+
var _sourcePositionUtils = require("./source-position-utils");
|
|
13
|
+
function lintSelector(args) {
|
|
14
|
+
checkNoAmbiguousPseudos(args);
|
|
15
|
+
checkNoRestrictedPseudos(args);
|
|
16
|
+
checkNoLegacyPseudoElementSyntax(args);
|
|
17
|
+
checkNoIncreasedSpecificity(args);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Ensures the use of a nesting selector `&` with pseudo-selectors.
|
|
22
|
+
*/
|
|
23
|
+
function checkNoAmbiguousPseudos(_ref) {
|
|
24
|
+
var context = _ref.context,
|
|
25
|
+
sourceNode = _ref.sourceNode,
|
|
26
|
+
selector = _ref.selector,
|
|
27
|
+
config = _ref.config,
|
|
28
|
+
isXcssCall = _ref.isXcssCall;
|
|
29
|
+
if (isXcssCall) {
|
|
30
|
+
/**
|
|
31
|
+
* The `xcss` API does not currently support a leading `&`.
|
|
32
|
+
*
|
|
33
|
+
* This may change in the future, but we are ignoring `xcss` calls for now.
|
|
34
|
+
*/
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
if (selector.first.type !== 'pseudo') {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
var range = (0, _sourcePositionUtils.getRangeFromNode)({
|
|
41
|
+
node: selector.first,
|
|
42
|
+
sourceNode: sourceNode
|
|
43
|
+
});
|
|
44
|
+
var loc = (0, _sourcePositionUtils.getSourceLocationFromRange)(context, range);
|
|
45
|
+
if (config.shouldAlwaysInsertNestingSelectorForAmbiguousPseudos) {
|
|
46
|
+
context.report({
|
|
47
|
+
loc: loc,
|
|
48
|
+
messageId: 'no-ambiguous-pseudos',
|
|
49
|
+
fix: /*#__PURE__*/_regenerator.default.mark(function fix(fixer) {
|
|
50
|
+
return _regenerator.default.wrap(function fix$(_context) {
|
|
51
|
+
while (1) switch (_context.prev = _context.next) {
|
|
52
|
+
case 0:
|
|
53
|
+
_context.next = 2;
|
|
54
|
+
return fixer.insertTextBeforeRange(range, '&');
|
|
55
|
+
case 2:
|
|
56
|
+
case "end":
|
|
57
|
+
return _context.stop();
|
|
58
|
+
}
|
|
59
|
+
}, fix);
|
|
60
|
+
})
|
|
61
|
+
});
|
|
62
|
+
} else {
|
|
63
|
+
context.report({
|
|
64
|
+
loc: loc,
|
|
65
|
+
messageId: 'no-ambiguous-pseudos',
|
|
66
|
+
suggest: [{
|
|
67
|
+
messageId: 'insert-nesting-selector',
|
|
68
|
+
fix: /*#__PURE__*/_regenerator.default.mark(function fix(fixer) {
|
|
69
|
+
return _regenerator.default.wrap(function fix$(_context2) {
|
|
70
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
71
|
+
case 0:
|
|
72
|
+
_context2.next = 2;
|
|
73
|
+
return fixer.insertTextBeforeRange(range, '&');
|
|
74
|
+
case 2:
|
|
75
|
+
case "end":
|
|
76
|
+
return _context2.stop();
|
|
77
|
+
}
|
|
78
|
+
}, fix);
|
|
79
|
+
})
|
|
80
|
+
}]
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
function checkNoRestrictedPseudos(_ref2) {
|
|
85
|
+
var context = _ref2.context,
|
|
86
|
+
sourceNode = _ref2.sourceNode,
|
|
87
|
+
selector = _ref2.selector;
|
|
88
|
+
selector.walkPseudos(function (pseudo) {
|
|
89
|
+
if (_constants.allowedPseudos.has(pseudo.value)) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* If someone has written `:after` it is allowed,
|
|
95
|
+
* they've just used the legacy syntax.
|
|
96
|
+
*
|
|
97
|
+
* This will be caught by the `no-legacy-pseudo-element-syntax` check.
|
|
98
|
+
*/
|
|
99
|
+
if (_constants.legacyPseudoElements.has(pseudo.value) && _constants.allowedPseudos.has(":".concat(pseudo.value))) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
if (!_constants.allowedPseudos.has(pseudo.value)) {
|
|
103
|
+
var range = (0, _sourcePositionUtils.getRangeFromNode)({
|
|
104
|
+
node: pseudo,
|
|
105
|
+
sourceNode: sourceNode
|
|
106
|
+
});
|
|
107
|
+
var loc = (0, _sourcePositionUtils.getSourceLocationFromRange)(context, range);
|
|
108
|
+
context.report({
|
|
109
|
+
loc: loc,
|
|
110
|
+
messageId: 'no-restricted-pseudos',
|
|
111
|
+
data: {
|
|
112
|
+
pseudo: pseudo.value
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* The original four pseudo-elements have a legacy single colon syntax.
|
|
121
|
+
*
|
|
122
|
+
* https://developer.mozilla.org/en-US/docs/Web/CSS/Pseudo-elements
|
|
123
|
+
*/
|
|
124
|
+
function checkNoLegacyPseudoElementSyntax(_ref3) {
|
|
125
|
+
var context = _ref3.context,
|
|
126
|
+
sourceNode = _ref3.sourceNode,
|
|
127
|
+
selector = _ref3.selector;
|
|
128
|
+
selector.walkPseudos(function (pseudo) {
|
|
129
|
+
if (_constants.legacyPseudoElements.has(pseudo.value)) {
|
|
130
|
+
var range = (0, _sourcePositionUtils.getRangeFromNode)({
|
|
131
|
+
node: pseudo,
|
|
132
|
+
sourceNode: sourceNode
|
|
133
|
+
});
|
|
134
|
+
var loc = (0, _sourcePositionUtils.getSourceLocationFromRange)(context, range);
|
|
135
|
+
context.report({
|
|
136
|
+
loc: loc,
|
|
137
|
+
messageId: 'no-legacy-pseudo-element-syntax',
|
|
138
|
+
fix: /*#__PURE__*/_regenerator.default.mark(function fix(fixer) {
|
|
139
|
+
return _regenerator.default.wrap(function fix$(_context3) {
|
|
140
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
141
|
+
case 0:
|
|
142
|
+
_context3.next = 2;
|
|
143
|
+
return fixer.insertTextBeforeRange(range, ':');
|
|
144
|
+
case 2:
|
|
145
|
+
case "end":
|
|
146
|
+
return _context3.stop();
|
|
147
|
+
}
|
|
148
|
+
}, fix);
|
|
149
|
+
})
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
function checkNoIncreasedSpecificity(_ref4) {
|
|
155
|
+
var context = _ref4.context,
|
|
156
|
+
sourceNode = _ref4.sourceNode,
|
|
157
|
+
selector = _ref4.selector;
|
|
158
|
+
selector.walkNesting(function (nesting) {
|
|
159
|
+
/**
|
|
160
|
+
* If it's not the start of a chain, then it's already been reported.
|
|
161
|
+
*/
|
|
162
|
+
if ((0, _postcssSelectorParser.isNesting)(nesting.prev())) {
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
var next = nesting.next();
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* If it is followed by something other than another nesting selector,
|
|
169
|
+
* then it isn't just there to increase specificity — it is actually necessary.
|
|
170
|
+
*/
|
|
171
|
+
if (next && !(0, _postcssSelectorParser.isNesting)(next)) {
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
var lastNesting = nesting;
|
|
175
|
+
while ((0, _postcssSelectorParser.isNesting)(next)) {
|
|
176
|
+
lastNesting = next;
|
|
177
|
+
next = next.next();
|
|
178
|
+
}
|
|
179
|
+
var _getRangeFromNode = (0, _sourcePositionUtils.getRangeFromNode)({
|
|
180
|
+
node: nesting,
|
|
181
|
+
sourceNode: sourceNode
|
|
182
|
+
}),
|
|
183
|
+
_getRangeFromNode2 = (0, _slicedToArray2.default)(_getRangeFromNode, 1),
|
|
184
|
+
start = _getRangeFromNode2[0];
|
|
185
|
+
var _getRangeFromNode3 = (0, _sourcePositionUtils.getRangeFromNode)({
|
|
186
|
+
node: lastNesting,
|
|
187
|
+
sourceNode: sourceNode
|
|
188
|
+
}),
|
|
189
|
+
_getRangeFromNode4 = (0, _slicedToArray2.default)(_getRangeFromNode3, 2),
|
|
190
|
+
_ = _getRangeFromNode4[0],
|
|
191
|
+
end = _getRangeFromNode4[1];
|
|
192
|
+
var loc = (0, _sourcePositionUtils.getSourceLocationFromRange)(context, [start, end]);
|
|
193
|
+
context.report({
|
|
194
|
+
loc: loc,
|
|
195
|
+
messageId: 'no-increased-specificity'
|
|
196
|
+
});
|
|
197
|
+
});
|
|
198
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.getRangeFromNode = getRangeFromNode;
|
|
8
|
+
exports.getSourceLocationFromRange = getSourceLocationFromRange;
|
|
9
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
10
|
+
function getRangeFromNode(_ref) {
|
|
11
|
+
var node = _ref.node,
|
|
12
|
+
sourceNode = _ref.sourceNode;
|
|
13
|
+
/**
|
|
14
|
+
* The adjustment required to align the selector AST source position
|
|
15
|
+
* with the ESTree source position.
|
|
16
|
+
*/
|
|
17
|
+
var adjustment =
|
|
18
|
+
/**
|
|
19
|
+
* Using a non-null `!` is safe here because ESLint requires the parser to
|
|
20
|
+
* include a range value on nodes.
|
|
21
|
+
*
|
|
22
|
+
* https://eslint.org/docs/latest/extend/custom-parsers#all-nodes
|
|
23
|
+
*/
|
|
24
|
+
sourceNode.range[0] + (
|
|
25
|
+
/**
|
|
26
|
+
* We add +1 if it's a literal to account for the opening `'` or `"` character.
|
|
27
|
+
*/
|
|
28
|
+
sourceNode.type === 'Literal' ? 1 : 0);
|
|
29
|
+
var start = adjustment + node.sourceIndex;
|
|
30
|
+
var end = start + node.value.length;
|
|
31
|
+
return [start, end];
|
|
32
|
+
}
|
|
33
|
+
function getSourceLocationFromRange(context, _ref2) {
|
|
34
|
+
var _ref3 = (0, _slicedToArray2.default)(_ref2, 2),
|
|
35
|
+
start = _ref3[0],
|
|
36
|
+
end = _ref3[1];
|
|
37
|
+
var sourceCode = context.getSourceCode();
|
|
38
|
+
return {
|
|
39
|
+
start: sourceCode.getLocFromIndex(start),
|
|
40
|
+
end: sourceCode.getLocFromIndex(end)
|
|
41
|
+
};
|
|
42
|
+
}
|