@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.
Files changed (51) hide show
  1. package/CHANGELOG.md +180 -172
  2. package/constellation/atlaskit-theme/usage.mdx +17 -17
  3. package/constellation/convert-props-syntax/usage.mdx +14 -14
  4. package/constellation/enforce-style-prop/usage.mdx +17 -17
  5. package/constellation/index/overview.mdx +70 -70
  6. package/constellation/local-cx-xcss/usage.mdx +4 -4
  7. package/constellation/no-array-arguments/usage.mdx +7 -7
  8. package/constellation/no-container-queries/usage.mdx +14 -14
  9. package/constellation/no-dynamic-styles/usage.mdx +19 -19
  10. package/constellation/no-exported-styles/usage.mdx +15 -15
  11. package/constellation/no-global-styles/usage.mdx +13 -13
  12. package/constellation/no-important-styles/usage.mdx +2 -2
  13. package/constellation/no-imported-style-values/usage.mdx +16 -16
  14. package/constellation/no-nested-selectors/usage.mdx +18 -18
  15. package/constellation/no-styled/usage.mdx +6 -6
  16. package/constellation/no-unsafe-selectors/usage.mdx +90 -90
  17. package/constellation/no-unsafe-values/usage.mdx +33 -33
  18. package/dist/cjs/index.codegen.js +1 -1
  19. package/dist/cjs/presets/all.codegen.js +1 -1
  20. package/dist/cjs/presets/recommended.codegen.js +1 -1
  21. package/dist/cjs/rules/index.codegen.js +1 -1
  22. package/dist/cjs/rules/no-unsafe-selectors/index.js +4 -1
  23. package/dist/cjs/rules/no-unsafe-selectors/lint-selector.js +10 -1
  24. package/dist/es2019/index.codegen.js +1 -1
  25. package/dist/es2019/presets/all.codegen.js +1 -1
  26. package/dist/es2019/presets/recommended.codegen.js +1 -1
  27. package/dist/es2019/rules/index.codegen.js +1 -1
  28. package/dist/es2019/rules/no-unsafe-selectors/index.js +4 -1
  29. package/dist/es2019/rules/no-unsafe-selectors/lint-selector.js +10 -1
  30. package/dist/esm/index.codegen.js +1 -1
  31. package/dist/esm/presets/all.codegen.js +1 -1
  32. package/dist/esm/presets/recommended.codegen.js +1 -1
  33. package/dist/esm/rules/index.codegen.js +1 -1
  34. package/dist/esm/rules/no-unsafe-selectors/index.js +4 -1
  35. package/dist/esm/rules/no-unsafe-selectors/lint-selector.js +10 -1
  36. package/dist/types/presets/all.codegen.d.ts +1 -1
  37. package/dist/types/presets/recommended.codegen.d.ts +1 -1
  38. package/dist/types/rules/no-unsafe-selectors/lint-selector.d.ts +1 -0
  39. package/dist/types-ts4.5/presets/all.codegen.d.ts +1 -1
  40. package/dist/types-ts4.5/presets/recommended.codegen.d.ts +1 -1
  41. package/dist/types-ts4.5/rules/no-unsafe-selectors/lint-selector.d.ts +1 -0
  42. package/package.json +2 -4
  43. package/src/index.codegen.tsx +3 -3
  44. package/src/presets/all.codegen.tsx +70 -73
  45. package/src/presets/recommended.codegen.tsx +70 -73
  46. package/src/rules/index.codegen.tsx +18 -18
  47. package/src/rules/no-unsafe-selectors/__tests__/no-ambiguous-pseudos.test.tsx +211 -201
  48. package/src/rules/no-unsafe-selectors/index.tsx +174 -177
  49. package/src/rules/no-unsafe-selectors/lint-selector.tsx +128 -141
  50. package/tsconfig.app.json +45 -45
  51. 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
- meta: {
18
- name: 'no-unsafe-selectors',
19
- docs: {
20
- description: 'Disallows use of nested styles in `css` functions.',
21
- recommended: true,
22
- severity: 'warn',
23
- },
24
- fixable: 'code',
25
- hasSuggestions: true,
26
- messages: {
27
- /**
28
- * Selector messages
29
- */
30
- 'no-ambiguous-pseudos':
31
- 'Pseudo-classes and pseudo-elements without a leading selector are ambiguous. Use a more explicit selector.',
32
-
33
- 'no-increased-specificity': 'Do not chain the nesting selector.',
34
-
35
- 'no-restricted-pseudos': 'The {{pseudo}} pseudo is not allowed.',
36
-
37
- 'no-legacy-pseudo-element-syntax':
38
- 'Use a double colon for pseudo-elements. The single colon syntax is not supported for all pseudo-elements.',
39
-
40
- 'no-unparsable-selectors':
41
- "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.",
42
-
43
- 'no-selectors-object':
44
- 'Do not use the selectors object. Both nested and advanced selectors should be avoided.',
45
-
46
- /**
47
- * At-rule messages
48
- */
49
- 'no-keyframes-at-rules':
50
- 'Use the CSS-in-JS `keyframes` API instead of `@keyframes` at-rules.',
51
-
52
- 'no-restricted-at-rules': '{{atRule}} at-rule is not allowed.',
53
-
54
- 'no-grouped-at-rules':
55
- '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
- walkStyleProperties(
108
- node,
109
- references,
110
- config.importSources,
111
- ({ key, value }) => {
112
- /**
113
- * If the value isn't an object expression then the key can't be a selector.
114
- *
115
- * This assumes all styles have to be inline, which is enforced by `no-unsafe-values`
116
- */
117
- if (value.type !== 'ObjectExpression') {
118
- return;
119
- }
120
-
121
- /**
122
- * Technically the key could be an identifier too, e.g.
123
- *
124
- * ```ts
125
- * css({
126
- * // This key is an identifier, not a literal
127
- * selector: {}
128
- * });
129
- * ```
130
- *
131
- * But an identifier couldn't violate anything in this rule,
132
- * because it can't contain '@' or ':' characters.
133
- */
134
- if (key.type !== 'Literal' || typeof key.value !== 'string') {
135
- return;
136
- }
137
-
138
- const selectorText = key.value;
139
-
140
- if (selectorText.includes('@')) {
141
- lintAtRule({ context, sourceNode: key, atRule: selectorText });
142
- return;
143
- }
144
-
145
- try {
146
- const selectorList = cssSelectorProcessor.astSync(selectorText);
147
-
148
- selectorList.nodes.forEach((selector) =>
149
- lintSelector({ context, sourceNode: key, selector, config }),
150
- );
151
- } catch (e) {
152
- context.report({
153
- node: key,
154
- messageId: 'no-unparsable-selectors',
155
- data: { selectorText },
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
- context,
169
- sourceNode,
170
- atRule,
165
+ context,
166
+ sourceNode,
167
+ atRule,
171
168
  }: {
172
- context: Rule.RuleContext;
173
- sourceNode: ESTree.Node;
174
- atRule: string;
169
+ context: Rule.RuleContext;
170
+ sourceNode: ESTree.Node;
171
+ atRule: string;
175
172
  }) {
176
- const matches = atRule.trim().match(/^@[A-z-]+/);
177
- if (!matches) {
178
- return;
179
- }
180
-
181
- const ruleName = matches[0];
182
-
183
- if (ignoredAtRules.has(ruleName)) {
184
- return;
185
- }
186
-
187
- if (ruleName === '@keyframes') {
188
- context.report({
189
- node: sourceNode,
190
- messageId: 'no-keyframes-at-rules',
191
- });
192
- } else {
193
- context.report({
194
- node: sourceNode,
195
- messageId: 'no-restricted-at-rules',
196
- data: {
197
- atRule: ruleName,
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
- context: Rule.RuleContext;
13
- sourceNode: ESTree.Node;
14
- selector: Selector;
15
- config: { shouldAlwaysInsertNestingSelectorForAmbiguousPseudos: boolean };
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
- checkNoAmbiguousPseudos(args);
20
- checkNoRestrictedPseudos(args);
21
- checkNoLegacyPseudoElementSyntax(args);
22
- checkNoIncreasedSpecificity(args);
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
- context,
30
- sourceNode,
31
- selector,
32
- config,
33
- }: CheckArgs) {
34
- if (selector.first.type !== 'pseudo') {
35
- return;
36
- }
37
-
38
- const range = getRangeFromNode({ node: selector.first, sourceNode });
39
- const loc = getSourceLocationFromRange(context, range);
40
-
41
- if (config.shouldAlwaysInsertNestingSelectorForAmbiguousPseudos) {
42
- context.report({
43
- loc,
44
- messageId: 'no-ambiguous-pseudos',
45
- *fix(fixer) {
46
- yield fixer.insertTextBeforeRange(range, '&');
47
- },
48
- });
49
- } else {
50
- context.report({
51
- loc,
52
- messageId: 'no-ambiguous-pseudos',
53
- suggest: [
54
- {
55
- messageId: 'insert-nesting-selector',
56
- *fix(fixer) {
57
- yield fixer.insertTextBeforeRange(range, '&');
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
- context,
67
- sourceNode,
68
- selector,
69
- }: CheckArgs) {
70
- selector.walkPseudos((pseudo) => {
71
- if (allowedPseudos.has(pseudo.value)) {
72
- return;
73
- }
74
-
75
- /**
76
- * If someone has written `:after` it is allowed,
77
- * they've just used the legacy syntax.
78
- *
79
- * This will be caught by the `no-legacy-pseudo-element-syntax` check.
80
- */
81
- if (
82
- legacyPseudoElements.has(pseudo.value) &&
83
- allowedPseudos.has(`:${pseudo.value}`)
84
- ) {
85
- return;
86
- }
87
-
88
- if (!allowedPseudos.has(pseudo.value)) {
89
- const range = getRangeFromNode({ node: pseudo, sourceNode });
90
- const loc = getSourceLocationFromRange(context, range);
91
-
92
- context.report({
93
- loc,
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
- context,
110
- sourceNode,
111
- selector,
112
- }: CheckArgs) {
113
- selector.walkPseudos((pseudo) => {
114
- if (legacyPseudoElements.has(pseudo.value)) {
115
- const range = getRangeFromNode({ node: pseudo, sourceNode });
116
- const loc = getSourceLocationFromRange(context, range);
117
-
118
- context.report({
119
- loc,
120
- messageId: 'no-legacy-pseudo-element-syntax',
121
- *fix(fixer) {
122
- yield fixer.insertTextBeforeRange(range, ':');
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
- context,
131
- sourceNode,
132
- selector,
133
- }: CheckArgs) {
134
- selector.walkNesting((nesting) => {
135
- /**
136
- * If it's not the start of a chain, then it's already been reported.
137
- */
138
- if (isNesting(nesting.prev())) {
139
- return;
140
- }
141
-
142
- let next = nesting.next();
143
-
144
- /**
145
- * If it is followed by something other than another nesting selector,
146
- * then it isn't just there to increase specificity — it is actually necessary.
147
- */
148
- if (next && !isNesting(next)) {
149
- return;
150
- }
151
-
152
- let lastNesting = nesting;
153
- while (isNesting(next)) {
154
- lastNesting = next;
155
- next = next.next();
156
- }
157
-
158
- const [start] = getRangeFromNode({ node: nesting, sourceNode });
159
- const [_, end] = getRangeFromNode({ node: lastNesting, sourceNode });
160
-
161
- const loc = getSourceLocationFromRange(context, [start, end]);
162
-
163
- context.report({
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
  }