@atlaskit/eslint-plugin-ui-styling-standard 0.15.2 → 0.16.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 (105) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/constellation/consistent-css-prop-usage/usage.mdx +3 -1
  3. package/constellation/index/migration-guide.mdx +309 -0
  4. package/constellation/index/overview.mdx +4 -0
  5. package/constellation/index/props.mdx +9 -5
  6. package/constellation/no-css-tagged-template-expression/usage.mdx +5 -2
  7. package/constellation/no-empty-styled-expression/usage.mdx +5 -2
  8. package/constellation/no-exported-css/usage.mdx +5 -2
  9. package/constellation/no-exported-keyframes/usage.mdx +5 -2
  10. package/constellation/no-invalid-css-map/usage.mdx +5 -2
  11. package/constellation/no-js-xcss/usage.mdx +3 -1
  12. package/constellation/no-keyframes-tagged-template-expression/usage.mdx +5 -2
  13. package/constellation/no-styled-tagged-template-expression/usage.mdx +5 -2
  14. package/constellation/no-suppress-xcss/usage.mdx +6 -3
  15. package/dist/types/rules/no-unsafe-selectors/constants.d.ts +1 -4
  16. package/index.js +9 -9
  17. package/package.json +3 -3
  18. package/scripts/codegen.tsx +223 -284
  19. package/src/rules/__tests__/utils/_tester.tsx +24 -24
  20. package/src/rules/atlaskit-theme/README.md +21 -19
  21. package/src/rules/atlaskit-theme/__tests__/test.ts +53 -53
  22. package/src/rules/atlaskit-theme/index.ts +107 -115
  23. package/src/rules/convert-props-syntax/README.md +32 -22
  24. package/src/rules/convert-props-syntax/__tests__/invalid.test.tsx +46 -46
  25. package/src/rules/convert-props-syntax/__tests__/rule.test.tsx +175 -175
  26. package/src/rules/convert-props-syntax/__tests__/type-annotations.test.tsx +52 -52
  27. package/src/rules/convert-props-syntax/__tests__/unusual-properties.test.tsx +33 -33
  28. package/src/rules/convert-props-syntax/index.tsx +356 -386
  29. package/src/rules/enforce-style-prop/README.md +21 -18
  30. package/src/rules/enforce-style-prop/__tests__/rule.test.tsx +90 -96
  31. package/src/rules/enforce-style-prop/index.tsx +144 -160
  32. package/src/rules/external-rules.tsx +163 -164
  33. package/src/rules/local-cx-xcss/README.md +10 -6
  34. package/src/rules/local-cx-xcss/__tests__/rule.test.tsx +26 -26
  35. package/src/rules/local-cx-xcss/index.tsx +46 -56
  36. package/src/rules/no-array-arguments/README.md +2 -1
  37. package/src/rules/no-array-arguments/__tests__/rule.test.tsx +37 -46
  38. package/src/rules/no-array-arguments/index.tsx +68 -69
  39. package/src/rules/no-classname-prop/README.md +7 -4
  40. package/src/rules/no-classname-prop/__tests__/rule.test.tsx +22 -22
  41. package/src/rules/no-classname-prop/index.tsx +25 -25
  42. package/src/rules/no-container-queries/README.md +11 -9
  43. package/src/rules/no-container-queries/__tests__/rule.test.tsx +47 -50
  44. package/src/rules/no-container-queries/index.tsx +75 -81
  45. package/src/rules/no-dynamic-styles/README.md +16 -19
  46. package/src/rules/no-dynamic-styles/__tests__/rule.test.tsx +58 -67
  47. package/src/rules/no-dynamic-styles/index.tsx +45 -48
  48. package/src/rules/no-exported-styles/README.md +17 -12
  49. package/src/rules/no-exported-styles/__tests__/rule.test.tsx +102 -111
  50. package/src/rules/no-exported-styles/index.tsx +36 -36
  51. package/src/rules/no-global-styles/README.md +15 -14
  52. package/src/rules/no-global-styles/__tests__/no-css-modules.test.tsx +28 -28
  53. package/src/rules/no-global-styles/__tests__/no-global-styles.test.tsx +37 -37
  54. package/src/rules/no-global-styles/index.tsx +59 -62
  55. package/src/rules/no-important-styles/README.md +5 -3
  56. package/src/rules/no-important-styles/__tests__/rule.test.tsx +66 -66
  57. package/src/rules/no-important-styles/index.tsx +49 -49
  58. package/src/rules/no-imported-style-values/README.md +23 -15
  59. package/src/rules/no-imported-style-values/__tests__/rule.test.tsx +123 -123
  60. package/src/rules/no-imported-style-values/index.tsx +116 -120
  61. package/src/rules/no-nested-selectors/README.md +15 -13
  62. package/src/rules/no-nested-selectors/__tests__/rule.test.tsx +141 -128
  63. package/src/rules/no-styled/README.md +14 -9
  64. package/src/rules/no-styled/__tests__/rule.test.tsx +31 -31
  65. package/src/rules/no-styled/index.tsx +34 -41
  66. package/src/rules/no-unsafe-selectors/README.md +103 -93
  67. package/src/rules/no-unsafe-selectors/__tests__/no-grouped-at-rules.test.tsx +21 -24
  68. package/src/rules/no-unsafe-selectors/__tests__/no-increased-specificity.test.tsx +44 -44
  69. package/src/rules/no-unsafe-selectors/__tests__/no-keyframes-at-rules.test.tsx +21 -21
  70. package/src/rules/no-unsafe-selectors/__tests__/no-legacy-pseudo-element-syntax.test.tsx +57 -57
  71. package/src/rules/no-unsafe-selectors/__tests__/no-restricted-at-rules.test.tsx +58 -58
  72. package/src/rules/no-unsafe-selectors/__tests__/no-restricted-pseudos.test.tsx +85 -85
  73. package/src/rules/no-unsafe-selectors/__tests__/no-selectors-object.test.tsx +12 -12
  74. package/src/rules/no-unsafe-selectors/__tests__/no-unparsable-selectors.test.tsx +23 -23
  75. package/src/rules/no-unsafe-selectors/__tests__/rule.test.tsx +133 -114
  76. package/src/rules/no-unsafe-selectors/constants.tsx +69 -77
  77. package/src/rules/no-unsafe-selectors/source-position-utils.tsx +38 -38
  78. package/src/rules/no-unsafe-selectors/walk-css-map.tsx +178 -184
  79. package/src/rules/no-unsafe-values/README.md +34 -40
  80. package/src/rules/no-unsafe-values/__tests__/no-array-values.test.tsx +13 -13
  81. package/src/rules/no-unsafe-values/__tests__/no-conditional-values.test.tsx +18 -18
  82. package/src/rules/no-unsafe-values/__tests__/no-dynamic-keys.test.tsx +104 -104
  83. package/src/rules/no-unsafe-values/__tests__/no-function-calls.test.tsx +128 -128
  84. package/src/rules/no-unsafe-values/__tests__/no-identifier-arguments.test.tsx +23 -23
  85. package/src/rules/no-unsafe-values/__tests__/no-object-access.test.tsx +38 -38
  86. package/src/rules/no-unsafe-values/__tests__/no-object-references.test.tsx +18 -18
  87. package/src/rules/no-unsafe-values/__tests__/no-spread-elements.test.tsx +18 -18
  88. package/src/rules/no-unsafe-values/__tests__/no-unsafe-values.test.tsx +28 -28
  89. package/src/rules/no-unsafe-values/__tests__/no-variables.test.tsx +47 -47
  90. package/src/rules/no-unsafe-values/index.tsx +76 -78
  91. package/src/rules/no-unsafe-values/messages.tsx +12 -12
  92. package/src/rules/no-unsafe-values/utils.tsx +370 -382
  93. package/src/rules/use-compiled/README.md +11 -8
  94. package/src/rules/use-compiled/__tests__/can-auto-fix.test.tsx +32 -32
  95. package/src/rules/use-compiled/__tests__/css.test.tsx +53 -53
  96. package/src/rules/use-compiled/__tests__/imports.test.tsx +90 -95
  97. package/src/rules/use-compiled/__tests__/keyframes.test.tsx +47 -47
  98. package/src/rules/use-compiled/__tests__/pragma.test.tsx +64 -64
  99. package/src/rules/use-compiled/__tests__/styled.test.tsx +53 -53
  100. package/src/rules/use-compiled/__tests__/use-compiled.test.tsx +10 -10
  101. package/src/rules/use-compiled/index.tsx +203 -226
  102. package/src/rules/use-compiled/is-safe.tsx +113 -117
  103. package/src/rules/use-compiled/utils.tsx +14 -18
  104. package/src/rules/utils/create-rule-with-typed-config.tsx +62 -63
  105. package/src/rules/utils/create-rule.tsx +3 -6
@@ -3,10 +3,10 @@ import { tester } from '../../__tests__/utils/_tester';
3
3
  import rule from '../index';
4
4
 
5
5
  tester.run('no-unsafe-selectors', rule, {
6
- valid: [
7
- {
8
- name: 'css API valid usage',
9
- code: `
6
+ valid: [
7
+ {
8
+ name: 'css API valid usage',
9
+ code: `
10
10
  import { css } from '@compiled/react';
11
11
 
12
12
  css({
@@ -14,10 +14,10 @@ tester.run('no-unsafe-selectors', rule, {
14
14
  '&:focus, &:active': {},
15
15
  });
16
16
  `,
17
- },
18
- {
19
- name: 'styled API valid usage',
20
- code: `
17
+ },
18
+ {
19
+ name: 'styled API valid usage',
20
+ code: `
21
21
  import { styled } from '@compiled/react';
22
22
 
23
23
  styled.div({
@@ -25,10 +25,10 @@ tester.run('no-unsafe-selectors', rule, {
25
25
  '&:focus, &:active': {},
26
26
  });
27
27
  `,
28
- },
29
- {
30
- name: 'keyframes API valid usage',
31
- code: `
28
+ },
29
+ {
30
+ name: 'keyframes API valid usage',
31
+ code: `
32
32
  import { keyframes } from '@compiled/react';
33
33
 
34
34
  keyframes({
@@ -42,20 +42,20 @@ tester.run('no-unsafe-selectors', rule, {
42
42
  },
43
43
  });
44
44
  `,
45
- },
46
- {
47
- name: 'xcss API valid usage',
48
- code: `
45
+ },
46
+ {
47
+ name: 'xcss API valid usage',
48
+ code: `
49
49
  import { xcss } from '@atlaskit/primitives';
50
50
 
51
51
  xcss({
52
52
  '&:hover': {},
53
53
  });
54
54
  `,
55
- },
56
- {
57
- name: 'cssMap API valid usage',
58
- code: `
55
+ },
56
+ {
57
+ name: 'cssMap API valid usage',
58
+ code: `
59
59
  import { cssMap } from '@atlaskit/primitives';
60
60
 
61
61
  cssMap({
@@ -64,12 +64,12 @@ tester.run('no-unsafe-selectors', rule, {
64
64
  }
65
65
  });
66
66
  `,
67
- },
68
- ],
69
- invalid: [
70
- {
71
- name: 'css API invalid usage',
72
- code: outdent`
67
+ },
68
+ ],
69
+ invalid: [
70
+ {
71
+ name: 'css API invalid usage',
72
+ code: outdent`
73
73
  import { css } from '@compiled/react';
74
74
 
75
75
  css({
@@ -77,7 +77,7 @@ tester.run('no-unsafe-selectors', rule, {
77
77
  '&:after': {},
78
78
  });
79
79
  `,
80
- output: outdent`
80
+ output: outdent`
81
81
  import { css } from '@compiled/react';
82
82
 
83
83
  css({
@@ -85,24 +85,24 @@ tester.run('no-unsafe-selectors', rule, {
85
85
  '&::after': {},
86
86
  });
87
87
  `,
88
- errors: [
89
- {
90
- messageId: 'no-ambiguous-pseudos',
91
- line: 4,
92
- column: 4,
93
- endColumn: 10,
94
- },
95
- {
96
- messageId: 'no-legacy-pseudo-element-syntax',
97
- line: 5,
98
- column: 5,
99
- endColumn: 11,
100
- },
101
- ],
102
- },
103
- {
104
- name: 'styled API invalid usage',
105
- code: `
88
+ errors: [
89
+ {
90
+ messageId: 'no-ambiguous-pseudos',
91
+ line: 4,
92
+ column: 4,
93
+ endColumn: 10,
94
+ },
95
+ {
96
+ messageId: 'no-legacy-pseudo-element-syntax',
97
+ line: 5,
98
+ column: 5,
99
+ endColumn: 11,
100
+ },
101
+ ],
102
+ },
103
+ {
104
+ name: 'styled API invalid usage',
105
+ code: `
106
106
  import { styled } from '@compiled/react';
107
107
 
108
108
  styled.div({
@@ -112,24 +112,43 @@ tester.run('no-unsafe-selectors', rule, {
112
112
  '@scope (article) to (figure)': {},
113
113
  });
114
114
  `,
115
- errors: [
116
- {
117
- messageId: 'no-keyframes-at-rules',
118
- line: 5,
119
- column: 11,
120
- endColumn: 30,
121
- },
122
- {
123
- messageId: 'no-restricted-at-rules',
124
- line: 8,
125
- column: 11,
126
- endColumn: 41,
127
- },
128
- ],
129
- },
130
- {
131
- name: 'keyframes API invalid usage',
132
- code: outdent`
115
+ errors: [
116
+ {
117
+ messageId: 'no-keyframes-at-rules',
118
+ line: 5,
119
+ column: 11,
120
+ endColumn: 30,
121
+ },
122
+ {
123
+ messageId: 'no-restricted-at-rules',
124
+ line: 8,
125
+ column: 11,
126
+ endColumn: 41,
127
+ },
128
+ ],
129
+ },
130
+ {
131
+ name: 'styled API extending base component',
132
+ code: `
133
+ import { styled } from '@compiled/react';
134
+ import { BaseComponent } from './base-component';
135
+
136
+ styled(BaseComponent)({
137
+ '@keyframes fadeIn': {},
138
+ });
139
+ `,
140
+ errors: [
141
+ {
142
+ messageId: 'no-keyframes-at-rules',
143
+ line: 6,
144
+ column: 11,
145
+ endColumn: 30,
146
+ },
147
+ ],
148
+ },
149
+ {
150
+ name: 'keyframes API invalid usage',
151
+ code: outdent`
133
152
  import { keyframes } from '@emotion/react';
134
153
 
135
154
  keyframes({
@@ -142,7 +161,7 @@ tester.run('no-unsafe-selectors', rule, {
142
161
  ':hover': {}, // Not valid but shouldn't be picked up by this rule
143
162
  });
144
163
  `,
145
- output: outdent`
164
+ output: outdent`
146
165
  import { keyframes } from '@emotion/react';
147
166
 
148
167
  keyframes({
@@ -155,42 +174,42 @@ tester.run('no-unsafe-selectors', rule, {
155
174
  ':hover': {}, // Not valid but shouldn't be picked up by this rule
156
175
  });
157
176
  `,
158
- errors: [
159
- {
160
- messageId: 'no-ambiguous-pseudos',
161
- line: 5,
162
- column: 6,
163
- endColumn: 12,
164
- },
165
- {
166
- messageId: 'no-restricted-pseudos',
167
- line: 8,
168
- column: 7,
169
- endColumn: 12,
170
- },
171
- ],
172
- },
173
- {
174
- name: 'xcss API invalid usage',
175
- code: `
177
+ errors: [
178
+ {
179
+ messageId: 'no-ambiguous-pseudos',
180
+ line: 5,
181
+ column: 6,
182
+ endColumn: 12,
183
+ },
184
+ {
185
+ messageId: 'no-restricted-pseudos',
186
+ line: 8,
187
+ column: 7,
188
+ endColumn: 12,
189
+ },
190
+ ],
191
+ },
192
+ {
193
+ name: 'xcss API invalid usage',
194
+ code: `
176
195
  import { xcss } from '@atlaskit/primitives';
177
196
 
178
197
  xcss({
179
198
  '&&&&&&': {},
180
199
  });
181
200
  `,
182
- errors: [
183
- {
184
- messageId: 'no-increased-specificity',
185
- line: 5,
186
- column: 12,
187
- endColumn: 18,
188
- },
189
- ],
190
- },
191
- {
192
- name: 'cssMap API invalid usage',
193
- code: outdent`
201
+ errors: [
202
+ {
203
+ messageId: 'no-increased-specificity',
204
+ line: 5,
205
+ column: 12,
206
+ endColumn: 18,
207
+ },
208
+ ],
209
+ },
210
+ {
211
+ name: 'cssMap API invalid usage',
212
+ code: outdent`
194
213
  import { cssMap } from '@atlaskit/primitives';
195
214
 
196
215
  cssMap({
@@ -203,7 +222,7 @@ tester.run('no-unsafe-selectors', rule, {
203
222
  },
204
223
  });
205
224
  `,
206
- output: outdent`
225
+ output: outdent`
207
226
  import { cssMap } from '@atlaskit/primitives';
208
227
 
209
228
  cssMap({
@@ -216,23 +235,23 @@ tester.run('no-unsafe-selectors', rule, {
216
235
  },
217
236
  });
218
237
  `,
219
- errors: [
220
- {
221
- messageId: 'no-ambiguous-pseudos',
222
- line: 5,
223
- column: 6,
224
- endColumn: 12,
225
- },
226
- {
227
- messageId: 'no-restricted-pseudos',
228
- data: {
229
- pseudo: ':first-child',
230
- },
231
- line: 9,
232
- column: 7,
233
- endColumn: 19,
234
- },
235
- ],
236
- },
237
- ],
238
+ errors: [
239
+ {
240
+ messageId: 'no-ambiguous-pseudos',
241
+ line: 5,
242
+ column: 6,
243
+ endColumn: 12,
244
+ },
245
+ {
246
+ messageId: 'no-restricted-pseudos',
247
+ data: {
248
+ pseudo: ':first-child',
249
+ },
250
+ line: 9,
251
+ column: 7,
252
+ endColumn: 19,
253
+ },
254
+ ],
255
+ },
256
+ ],
238
257
  });
@@ -5,18 +5,15 @@ import type { CSSPseudos } from '@compiled/react';
5
5
  * https://stackoverflow.com/a/71236280
6
6
  */
7
7
  type Validate<T extends true> = T;
8
- type HasAllUnique<Tuple, Union, Seen = never> = Tuple extends readonly [
9
- infer Head,
10
- ...infer Tail,
11
- ]
12
- ? Head extends Seen
13
- ? {
14
- ERROR: ['The following key appears more than once in the tuple:', Head];
15
- }
16
- : HasAllUnique<Tail, Exclude<Union, Head>, Head | Seen>
17
- : [Union] extends [never]
18
- ? true
19
- : { ERROR: ['Some keys are missing from the tuple:', Union] };
8
+ type HasAllUnique<Tuple, Union, Seen = never> = Tuple extends readonly [infer Head, ...infer Tail]
9
+ ? Head extends Seen
10
+ ? {
11
+ ERROR: ['The following key appears more than once in the tuple:', Head];
12
+ }
13
+ : HasAllUnique<Tail, Exclude<Union, Head>, Head | Seen>
14
+ : [Union] extends [never]
15
+ ? true
16
+ : { ERROR: ['Some keys are missing from the tuple:', Union] };
20
17
 
21
18
  /**
22
19
  * Exporting this so it isn't considered unused.
@@ -24,76 +21,71 @@ type HasAllUnique<Tuple, Union, Seen = never> = Tuple extends readonly [
24
21
  export type _ = Validate<HasAllUnique<typeof cssPseudos, CSSPseudos>>;
25
22
 
26
23
  const cssPseudos = [
27
- '&:active',
28
- '&:autofill',
29
- '&:blank',
30
- '&:checked',
31
- '&:default',
32
- '&:defined',
33
- '&:disabled',
34
- '&:empty',
35
- '&:enabled',
36
- '&:first',
37
- '&:focus',
38
- '&:focus-visible',
39
- '&:focus-within',
40
- '&:fullscreen',
41
- '&:hover',
42
- '&:in-range',
43
- '&:indeterminate',
44
- '&:invalid',
45
- '&:left',
46
- '&:link',
47
- '&:local-link',
48
- '&:optional',
49
- '&:out-of-range',
50
- '&:paused',
51
- '&:picture-in-picture',
52
- '&:placeholder-shown',
53
- '&:playing',
54
- '&:read-only',
55
- '&:read-write',
56
- '&:required',
57
- '&:right',
58
- '&:target',
59
- '&:user-invalid',
60
- '&:user-valid',
61
- '&:valid',
62
- '&:visited',
63
- '&::after',
64
- '&::backdrop',
65
- '&::before',
66
- '&::cue',
67
- '&::cue-region',
68
- '&::first-letter',
69
- '&::first-line',
70
- '&::grammar-error',
71
- '&::marker',
72
- '&::placeholder',
73
- '&::selection',
74
- '&::spelling-error',
75
- '&::target-text',
76
- '&::view-transition',
24
+ '&:active',
25
+ '&:autofill',
26
+ '&:blank',
27
+ '&:checked',
28
+ '&:default',
29
+ '&:defined',
30
+ '&:disabled',
31
+ '&:empty',
32
+ '&:enabled',
33
+ '&:first',
34
+ '&:focus',
35
+ '&:focus-visible',
36
+ '&:focus-within',
37
+ '&:fullscreen',
38
+ '&:hover',
39
+ '&:in-range',
40
+ '&:indeterminate',
41
+ '&:invalid',
42
+ '&:left',
43
+ '&:link',
44
+ '&:local-link',
45
+ '&:optional',
46
+ '&:out-of-range',
47
+ '&:paused',
48
+ '&:picture-in-picture',
49
+ '&:placeholder-shown',
50
+ '&:playing',
51
+ '&:read-only',
52
+ '&:read-write',
53
+ '&:required',
54
+ '&:right',
55
+ '&:target',
56
+ '&:user-invalid',
57
+ '&:user-valid',
58
+ '&:valid',
59
+ '&:visited',
60
+ '&::after',
61
+ '&::backdrop',
62
+ '&::before',
63
+ '&::cue',
64
+ '&::cue-region',
65
+ '&::first-letter',
66
+ '&::first-line',
67
+ '&::grammar-error',
68
+ '&::marker',
69
+ '&::placeholder',
70
+ '&::selection',
71
+ '&::spelling-error',
72
+ '&::target-text',
73
+ '&::view-transition',
77
74
  ] as const;
78
75
 
79
76
  export const allowedPseudos = new Set(
80
- /**
81
- * The `&` is included above for type checking reasons,
82
- * but we don't actually want it when consuming the values.
83
- */
84
- cssPseudos.map((pseudo) => pseudo.slice(1)),
77
+ /**
78
+ * The `&` is included above for type checking reasons,
79
+ * but we don't actually want it when consuming the values.
80
+ */
81
+ cssPseudos.map((pseudo) => pseudo.slice(1)),
85
82
  );
86
83
 
87
- export const legacyPseudoElements = new Set([
88
- ':after',
89
- ':before',
90
- ':first-letter',
91
- ':first-line',
92
- ]);
84
+ export const legacyPseudoElements = new Set([':after', ':before', ':first-letter', ':first-line']);
93
85
 
94
86
  export const ignoredAtRules = new Set([
95
- '@container', // ignored because it's covered by `no-container-queries`
96
- '@media', // ignored because it's covered by `no-nested-styles`
97
- '@supports',
98
- '@property',
87
+ '@container', // ignored because it's covered by `no-container-queries`
88
+ '@media', // ignored because it's covered by `no-nested-styles`
89
+ '@supports',
90
+ '@property',
99
91
  ]);
@@ -6,50 +6,50 @@ import { type Node as SelectorNode } from 'postcss-selector-parser';
6
6
  type Range = [number, number];
7
7
 
8
8
  export function getRangeFromNode({
9
- node,
10
- sourceNode,
9
+ node,
10
+ sourceNode,
11
11
  }: {
12
- /**
13
- * The selector AST node to get the range of.
14
- */
15
- node: SelectorNode & { value: string };
16
- /**
17
- * The source ESTree node whose value was parsed to obtain the selector AST.
18
- *
19
- * The range is calculated relative to this node's range.
20
- */
21
- sourceNode: ESTree.Node;
12
+ /**
13
+ * The selector AST node to get the range of.
14
+ */
15
+ node: SelectorNode & { value: string };
16
+ /**
17
+ * The source ESTree node whose value was parsed to obtain the selector AST.
18
+ *
19
+ * The range is calculated relative to this node's range.
20
+ */
21
+ sourceNode: ESTree.Node;
22
22
  }): Range {
23
- /**
24
- * The adjustment required to align the selector AST source position
25
- * with the ESTree source position.
26
- */
27
- const adjustment =
28
- /**
29
- * Using a non-null `!` is safe here because ESLint requires the parser to
30
- * include a range value on nodes.
31
- *
32
- * https://eslint.org/docs/latest/extend/custom-parsers#all-nodes
33
- */
34
- sourceNode.range![0] +
35
- /**
36
- * We add +1 if it's a literal to account for the opening `'` or `"` character.
37
- */
38
- (sourceNode.type === 'Literal' ? 1 : 0);
23
+ /**
24
+ * The adjustment required to align the selector AST source position
25
+ * with the ESTree source position.
26
+ */
27
+ const adjustment =
28
+ /**
29
+ * Using a non-null `!` is safe here because ESLint requires the parser to
30
+ * include a range value on nodes.
31
+ *
32
+ * https://eslint.org/docs/latest/extend/custom-parsers#all-nodes
33
+ */
34
+ sourceNode.range![0] +
35
+ /**
36
+ * We add +1 if it's a literal to account for the opening `'` or `"` character.
37
+ */
38
+ (sourceNode.type === 'Literal' ? 1 : 0);
39
39
 
40
- const start = adjustment + node.sourceIndex;
41
- const end = start + node.value.length;
40
+ const start = adjustment + node.sourceIndex;
41
+ const end = start + node.value.length;
42
42
 
43
- return [start, end];
43
+ return [start, end];
44
44
  }
45
45
 
46
46
  export function getSourceLocationFromRange(
47
- context: Rule.RuleContext,
48
- [start, end]: Range,
47
+ context: Rule.RuleContext,
48
+ [start, end]: Range,
49
49
  ): AST.SourceLocation {
50
- const sourceCode = context.getSourceCode();
51
- return {
52
- start: sourceCode.getLocFromIndex(start),
53
- end: sourceCode.getLocFromIndex(end),
54
- };
50
+ const sourceCode = context.getSourceCode();
51
+ return {
52
+ start: sourceCode.getLocFromIndex(start),
53
+ end: sourceCode.getLocFromIndex(end),
54
+ };
55
55
  }