@atlaskit/eslint-plugin-ui-styling-standard 0.15.0 → 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 +180 -172
- 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 +70 -70
- 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 +90 -90
- package/constellation/no-unsafe-values/usage.mdx +33 -33
- package/dist/cjs/index.codegen.js +1 -1
- package/dist/cjs/presets/all.codegen.js +1 -1
- package/dist/cjs/presets/recommended.codegen.js +1 -1
- package/dist/cjs/rules/index.codegen.js +1 -1
- package/dist/cjs/rules/no-unsafe-selectors/index.js +4 -1
- package/dist/cjs/rules/no-unsafe-selectors/lint-selector.js +10 -1
- package/dist/es2019/index.codegen.js +1 -1
- package/dist/es2019/presets/all.codegen.js +1 -1
- package/dist/es2019/presets/recommended.codegen.js +1 -1
- package/dist/es2019/rules/index.codegen.js +1 -1
- package/dist/es2019/rules/no-unsafe-selectors/index.js +4 -1
- package/dist/es2019/rules/no-unsafe-selectors/lint-selector.js +10 -1
- package/dist/esm/index.codegen.js +1 -1
- package/dist/esm/presets/all.codegen.js +1 -1
- package/dist/esm/presets/recommended.codegen.js +1 -1
- package/dist/esm/rules/index.codegen.js +1 -1
- package/dist/esm/rules/no-unsafe-selectors/index.js +4 -1
- package/dist/esm/rules/no-unsafe-selectors/lint-selector.js +10 -1
- package/dist/types/presets/all.codegen.d.ts +1 -1
- package/dist/types/presets/recommended.codegen.d.ts +1 -1
- package/dist/types/rules/no-unsafe-selectors/lint-selector.d.ts +1 -0
- package/dist/types-ts4.5/presets/all.codegen.d.ts +1 -1
- package/dist/types-ts4.5/presets/recommended.codegen.d.ts +1 -1
- package/dist/types-ts4.5/rules/no-unsafe-selectors/lint-selector.d.ts +1 -0
- package/package.json +2 -4
- package/src/index.codegen.tsx +3 -3
- package/src/presets/all.codegen.tsx +70 -73
- package/src/presets/recommended.codegen.tsx +70 -73
- package/src/rules/index.codegen.tsx +18 -18
- package/src/rules/no-unsafe-selectors/__tests__/no-ambiguous-pseudos.test.tsx +211 -201
- package/src/rules/no-unsafe-selectors/index.tsx +174 -177
- package/src/rules/no-unsafe-selectors/lint-selector.tsx +128 -141
- package/tsconfig.app.json +45 -45
- package/tsconfig.dev.json +43 -43
|
@@ -2,6 +2,7 @@ import type { Rule } from 'eslint';
|
|
|
2
2
|
import type * as ESTree from 'eslint-codemod-utils';
|
|
3
3
|
import cssSelectorParser from 'postcss-selector-parser';
|
|
4
4
|
|
|
5
|
+
import { isXcss } from '@atlaskit/eslint-utils/is-supported-import';
|
|
5
6
|
import { importSources } from '@atlaskit/eslint-utils/schema';
|
|
6
7
|
import { walkStyleProperties } from '@atlaskit/eslint-utils/walk-style-properties';
|
|
7
8
|
|
|
@@ -14,188 +15,184 @@ import { walkCssMap } from './walk-css-map';
|
|
|
14
15
|
const cssSelectorProcessor = cssSelectorParser();
|
|
15
16
|
|
|
16
17
|
const rule = createLintRuleWithTypedConfig({
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
);
|
|
160
|
-
},
|
|
161
|
-
};
|
|
162
|
-
},
|
|
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':
|
|
32
|
+
'Pseudo-classes and pseudo-elements without a leading selector are ambiguous. Use a more explicit selector.',
|
|
33
|
+
|
|
34
|
+
'no-increased-specificity': 'Do not chain the nesting selector.',
|
|
35
|
+
|
|
36
|
+
'no-restricted-pseudos': 'The {{pseudo}} pseudo is not allowed.',
|
|
37
|
+
|
|
38
|
+
'no-legacy-pseudo-element-syntax':
|
|
39
|
+
'Use a double colon for pseudo-elements. The single colon syntax is not supported for all pseudo-elements.',
|
|
40
|
+
|
|
41
|
+
'no-unparsable-selectors':
|
|
42
|
+
"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.",
|
|
43
|
+
|
|
44
|
+
'no-selectors-object':
|
|
45
|
+
'Do not use the selectors object. Both nested and advanced selectors should be avoided.',
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* At-rule messages
|
|
49
|
+
*/
|
|
50
|
+
'no-keyframes-at-rules':
|
|
51
|
+
'Use the CSS-in-JS `keyframes` API instead of `@keyframes` at-rules.',
|
|
52
|
+
|
|
53
|
+
'no-restricted-at-rules': '{{atRule}} at-rule is not allowed.',
|
|
54
|
+
|
|
55
|
+
'no-grouped-at-rules': 'Do not group at-rules. Write flattened at-rules instead.',
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Suggestion messages
|
|
59
|
+
*/
|
|
60
|
+
'insert-nesting-selector':
|
|
61
|
+
'Insert a nesting selector `&` to target the element itself. This is usually the intended behavior.',
|
|
62
|
+
},
|
|
63
|
+
|
|
64
|
+
schema: {
|
|
65
|
+
type: 'object',
|
|
66
|
+
properties: {
|
|
67
|
+
importSources,
|
|
68
|
+
shouldAlwaysInsertNestingSelectorForAmbiguousPseudos: {
|
|
69
|
+
type: 'boolean',
|
|
70
|
+
default: true,
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
additionalProperties: false,
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
create(context, config) {
|
|
77
|
+
return {
|
|
78
|
+
Program(program) {
|
|
79
|
+
walkCssMap({
|
|
80
|
+
context,
|
|
81
|
+
program,
|
|
82
|
+
importSources: config.importSources,
|
|
83
|
+
visitor(property) {
|
|
84
|
+
const { type, node } = property;
|
|
85
|
+
|
|
86
|
+
if (type === 'grouped-at-rules') {
|
|
87
|
+
context.report({
|
|
88
|
+
node: node.key,
|
|
89
|
+
messageId: 'no-grouped-at-rules',
|
|
90
|
+
});
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (type === 'selectors') {
|
|
95
|
+
context.report({
|
|
96
|
+
node: node.key,
|
|
97
|
+
messageId: 'no-selectors-object',
|
|
98
|
+
});
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
});
|
|
103
|
+
},
|
|
104
|
+
CallExpression(node: ESTree.CallExpression) {
|
|
105
|
+
const { references } = context.getScope();
|
|
106
|
+
|
|
107
|
+
const isXcssCall = isXcss(node, references, config.importSources);
|
|
108
|
+
|
|
109
|
+
walkStyleProperties(node, references, config.importSources, ({ key, value }) => {
|
|
110
|
+
/**
|
|
111
|
+
* If the value isn't an object expression then the key can't be a selector.
|
|
112
|
+
*
|
|
113
|
+
* This assumes all styles have to be inline, which is enforced by `no-unsafe-values`
|
|
114
|
+
*/
|
|
115
|
+
if (value.type !== 'ObjectExpression') {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Technically the key could be an identifier too, e.g.
|
|
121
|
+
*
|
|
122
|
+
* ```ts
|
|
123
|
+
* css({
|
|
124
|
+
* // This key is an identifier, not a literal
|
|
125
|
+
* selector: {}
|
|
126
|
+
* });
|
|
127
|
+
* ```
|
|
128
|
+
*
|
|
129
|
+
* But an identifier couldn't violate anything in this rule,
|
|
130
|
+
* because it can't contain '@' or ':' characters.
|
|
131
|
+
*/
|
|
132
|
+
if (key.type !== 'Literal' || typeof key.value !== 'string') {
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const selectorText = key.value;
|
|
137
|
+
|
|
138
|
+
if (selectorText.includes('@')) {
|
|
139
|
+
lintAtRule({ context, sourceNode: key, atRule: selectorText });
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
try {
|
|
144
|
+
const selectorList = cssSelectorProcessor.astSync(selectorText);
|
|
145
|
+
|
|
146
|
+
selectorList.nodes.forEach((selector) =>
|
|
147
|
+
lintSelector({ context, sourceNode: key, selector, config, isXcssCall }),
|
|
148
|
+
);
|
|
149
|
+
} catch (e) {
|
|
150
|
+
context.report({
|
|
151
|
+
node: key,
|
|
152
|
+
messageId: 'no-unparsable-selectors',
|
|
153
|
+
data: { selectorText },
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
},
|
|
158
|
+
};
|
|
159
|
+
},
|
|
163
160
|
});
|
|
164
161
|
|
|
165
162
|
export default rule;
|
|
166
163
|
|
|
167
164
|
function lintAtRule({
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
165
|
+
context,
|
|
166
|
+
sourceNode,
|
|
167
|
+
atRule,
|
|
171
168
|
}: {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
169
|
+
context: Rule.RuleContext;
|
|
170
|
+
sourceNode: ESTree.Node;
|
|
171
|
+
atRule: string;
|
|
175
172
|
}) {
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
173
|
+
const matches = atRule.trim().match(/^@[A-z-]+/);
|
|
174
|
+
if (!matches) {
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
const ruleName = matches[0];
|
|
179
|
+
|
|
180
|
+
if (ignoredAtRules.has(ruleName)) {
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
if (ruleName === '@keyframes') {
|
|
185
|
+
context.report({
|
|
186
|
+
node: sourceNode,
|
|
187
|
+
messageId: 'no-keyframes-at-rules',
|
|
188
|
+
});
|
|
189
|
+
} else {
|
|
190
|
+
context.report({
|
|
191
|
+
node: sourceNode,
|
|
192
|
+
messageId: 'no-restricted-at-rules',
|
|
193
|
+
data: {
|
|
194
|
+
atRule: ruleName,
|
|
195
|
+
},
|
|
196
|
+
});
|
|
197
|
+
}
|
|
201
198
|
}
|
|
@@ -3,101 +3,96 @@ import type * as ESTree from 'eslint-codemod-utils';
|
|
|
3
3
|
|
|
4
4
|
import { allowedPseudos, legacyPseudoElements } from './constants';
|
|
5
5
|
import { type Selector, isNesting } from 'postcss-selector-parser';
|
|
6
|
-
import {
|
|
7
|
-
getRangeFromNode,
|
|
8
|
-
getSourceLocationFromRange,
|
|
9
|
-
} from './source-position-utils';
|
|
6
|
+
import { getRangeFromNode, getSourceLocationFromRange } from './source-position-utils';
|
|
10
7
|
|
|
11
8
|
type CheckArgs = {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
9
|
+
context: Rule.RuleContext;
|
|
10
|
+
sourceNode: ESTree.Node;
|
|
11
|
+
selector: Selector;
|
|
12
|
+
config: { shouldAlwaysInsertNestingSelectorForAmbiguousPseudos: boolean };
|
|
13
|
+
isXcssCall: boolean;
|
|
16
14
|
};
|
|
17
15
|
|
|
18
16
|
export function lintSelector(args: CheckArgs) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
17
|
+
checkNoAmbiguousPseudos(args);
|
|
18
|
+
checkNoRestrictedPseudos(args);
|
|
19
|
+
checkNoLegacyPseudoElementSyntax(args);
|
|
20
|
+
checkNoIncreasedSpecificity(args);
|
|
23
21
|
}
|
|
24
22
|
|
|
25
23
|
/**
|
|
26
24
|
* Ensures the use of a nesting selector `&` with pseudo-selectors.
|
|
27
25
|
*/
|
|
28
|
-
function checkNoAmbiguousPseudos({
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
26
|
+
function checkNoAmbiguousPseudos({ context, sourceNode, selector, config, isXcssCall }: CheckArgs) {
|
|
27
|
+
if (isXcssCall) {
|
|
28
|
+
/**
|
|
29
|
+
* The `xcss` API does not currently support a leading `&`.
|
|
30
|
+
*
|
|
31
|
+
* This may change in the future, but we are ignoring `xcss` calls for now.
|
|
32
|
+
*/
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (selector.first.type !== 'pseudo') {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const range = getRangeFromNode({ node: selector.first, sourceNode });
|
|
41
|
+
const loc = getSourceLocationFromRange(context, range);
|
|
42
|
+
|
|
43
|
+
if (config.shouldAlwaysInsertNestingSelectorForAmbiguousPseudos) {
|
|
44
|
+
context.report({
|
|
45
|
+
loc,
|
|
46
|
+
messageId: 'no-ambiguous-pseudos',
|
|
47
|
+
*fix(fixer) {
|
|
48
|
+
yield fixer.insertTextBeforeRange(range, '&');
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
} else {
|
|
52
|
+
context.report({
|
|
53
|
+
loc,
|
|
54
|
+
messageId: 'no-ambiguous-pseudos',
|
|
55
|
+
suggest: [
|
|
56
|
+
{
|
|
57
|
+
messageId: 'insert-nesting-selector',
|
|
58
|
+
*fix(fixer) {
|
|
59
|
+
yield fixer.insertTextBeforeRange(range, '&');
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
],
|
|
63
|
+
});
|
|
64
|
+
}
|
|
63
65
|
}
|
|
64
66
|
|
|
65
|
-
function checkNoRestrictedPseudos({
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
messageId: 'no-restricted-pseudos',
|
|
95
|
-
data: {
|
|
96
|
-
pseudo: pseudo.value,
|
|
97
|
-
},
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
});
|
|
67
|
+
function checkNoRestrictedPseudos({ context, sourceNode, selector }: CheckArgs) {
|
|
68
|
+
selector.walkPseudos((pseudo) => {
|
|
69
|
+
if (allowedPseudos.has(pseudo.value)) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* If someone has written `:after` it is allowed,
|
|
75
|
+
* they've just used the legacy syntax.
|
|
76
|
+
*
|
|
77
|
+
* This will be caught by the `no-legacy-pseudo-element-syntax` check.
|
|
78
|
+
*/
|
|
79
|
+
if (legacyPseudoElements.has(pseudo.value) && allowedPseudos.has(`:${pseudo.value}`)) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (!allowedPseudos.has(pseudo.value)) {
|
|
84
|
+
const range = getRangeFromNode({ node: pseudo, sourceNode });
|
|
85
|
+
const loc = getSourceLocationFromRange(context, range);
|
|
86
|
+
|
|
87
|
+
context.report({
|
|
88
|
+
loc,
|
|
89
|
+
messageId: 'no-restricted-pseudos',
|
|
90
|
+
data: {
|
|
91
|
+
pseudo: pseudo.value,
|
|
92
|
+
},
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
});
|
|
101
96
|
}
|
|
102
97
|
|
|
103
98
|
/**
|
|
@@ -105,64 +100,56 @@ function checkNoRestrictedPseudos({
|
|
|
105
100
|
*
|
|
106
101
|
* https://developer.mozilla.org/en-US/docs/Web/CSS/Pseudo-elements
|
|
107
102
|
*/
|
|
108
|
-
function checkNoLegacyPseudoElementSyntax({
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
},
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
});
|
|
103
|
+
function checkNoLegacyPseudoElementSyntax({ context, sourceNode, selector }: CheckArgs) {
|
|
104
|
+
selector.walkPseudos((pseudo) => {
|
|
105
|
+
if (legacyPseudoElements.has(pseudo.value)) {
|
|
106
|
+
const range = getRangeFromNode({ node: pseudo, sourceNode });
|
|
107
|
+
const loc = getSourceLocationFromRange(context, range);
|
|
108
|
+
|
|
109
|
+
context.report({
|
|
110
|
+
loc,
|
|
111
|
+
messageId: 'no-legacy-pseudo-element-syntax',
|
|
112
|
+
*fix(fixer) {
|
|
113
|
+
yield fixer.insertTextBeforeRange(range, ':');
|
|
114
|
+
},
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
});
|
|
127
118
|
}
|
|
128
119
|
|
|
129
|
-
function checkNoIncreasedSpecificity({
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
loc,
|
|
165
|
-
messageId: 'no-increased-specificity',
|
|
166
|
-
});
|
|
167
|
-
});
|
|
120
|
+
function checkNoIncreasedSpecificity({ context, sourceNode, selector }: CheckArgs) {
|
|
121
|
+
selector.walkNesting((nesting) => {
|
|
122
|
+
/**
|
|
123
|
+
* If it's not the start of a chain, then it's already been reported.
|
|
124
|
+
*/
|
|
125
|
+
if (isNesting(nesting.prev())) {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
let next = nesting.next();
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* If it is followed by something other than another nesting selector,
|
|
133
|
+
* then it isn't just there to increase specificity — it is actually necessary.
|
|
134
|
+
*/
|
|
135
|
+
if (next && !isNesting(next)) {
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
let lastNesting = nesting;
|
|
140
|
+
while (isNesting(next)) {
|
|
141
|
+
lastNesting = next;
|
|
142
|
+
next = next.next();
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const [start] = getRangeFromNode({ node: nesting, sourceNode });
|
|
146
|
+
const [_, end] = getRangeFromNode({ node: lastNesting, sourceNode });
|
|
147
|
+
|
|
148
|
+
const loc = getSourceLocationFromRange(context, [start, end]);
|
|
149
|
+
|
|
150
|
+
context.report({
|
|
151
|
+
loc,
|
|
152
|
+
messageId: 'no-increased-specificity',
|
|
153
|
+
});
|
|
154
|
+
});
|
|
168
155
|
}
|