eslint-plugin-yml 3.1.2 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.d.mts +177 -24
- package/lib/index.mjs +32 -309
- package/package.json +4 -3
package/lib/index.d.mts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { AST } from "yaml-eslint-parser";
|
|
2
2
|
import { IDirective, TextSourceCodeBase, TraversalStep } from "@eslint/plugin-kit";
|
|
3
|
+
import { CursorWithCountOptionsWithComment, CursorWithCountOptionsWithFilter, CursorWithCountOptionsWithoutFilter, CursorWithSkipOptionsWithComment, CursorWithSkipOptionsWithFilter, CursorWithSkipOptionsWithoutFilter } from "@ota-meshi/ast-token-store";
|
|
3
4
|
import * as _eslint_core0 from "@eslint/core";
|
|
4
5
|
import { File, FileProblem, Language, OkParseResult, RuleDefinition, RulesConfig } from "@eslint/core";
|
|
5
6
|
import { Linter, Scope } from "eslint";
|
|
@@ -11,19 +12,6 @@ declare namespace meta_d_exports {
|
|
|
11
12
|
declare const name: string;
|
|
12
13
|
declare const version: string;
|
|
13
14
|
//#endregion
|
|
14
|
-
//#region src/language/token-store.d.ts
|
|
15
|
-
type FilterPredicate = (tokenOrComment: YAMLToken) => boolean;
|
|
16
|
-
type CursorWithSkipOptions = number | FilterPredicate | {
|
|
17
|
-
includeComments?: boolean;
|
|
18
|
-
filter?: FilterPredicate;
|
|
19
|
-
skip?: number;
|
|
20
|
-
};
|
|
21
|
-
type CursorWithCountOptions = number | FilterPredicate | {
|
|
22
|
-
includeComments?: boolean;
|
|
23
|
-
filter?: FilterPredicate;
|
|
24
|
-
count?: number;
|
|
25
|
-
};
|
|
26
|
-
//#endregion
|
|
27
15
|
//#region src/language/yaml-source-code.d.ts
|
|
28
16
|
/**
|
|
29
17
|
* YAML-specific syntax element type
|
|
@@ -95,21 +83,186 @@ declare class YAMLSourceCode extends TextSourceCodeBase<{
|
|
|
95
83
|
problems: FileProblem[];
|
|
96
84
|
};
|
|
97
85
|
getNodeByRangeIndex(index: number): AST.YAMLNode | null;
|
|
86
|
+
/**
|
|
87
|
+
* Gets the first token of the given node.
|
|
88
|
+
*/
|
|
98
89
|
getFirstToken(node: YAMLSyntaxElement): AST.Token;
|
|
99
|
-
|
|
90
|
+
/**
|
|
91
|
+
* Gets the first token of the given node with options.
|
|
92
|
+
*/
|
|
93
|
+
getFirstToken(node: YAMLSyntaxElement, options: CursorWithSkipOptionsWithoutFilter): AST.Token | null;
|
|
94
|
+
/**
|
|
95
|
+
* Gets the first token of the given node with filter options.
|
|
96
|
+
*/
|
|
97
|
+
getFirstToken<R extends AST.Token>(node: YAMLSyntaxElement, options: CursorWithSkipOptionsWithFilter<AST.Token, R>): R | null;
|
|
98
|
+
/**
|
|
99
|
+
* Gets the first token of the given node with comment options.
|
|
100
|
+
*/
|
|
101
|
+
getFirstToken<R extends AST.Token | AST.Comment>(node: YAMLSyntaxElement, options: CursorWithSkipOptionsWithComment<AST.Token, AST.Comment, R>): R | null;
|
|
102
|
+
/**
|
|
103
|
+
* Gets the first tokens of the given node.
|
|
104
|
+
*/
|
|
105
|
+
getFirstTokens(node: YAMLSyntaxElement, options?: CursorWithCountOptionsWithoutFilter): AST.Token[];
|
|
106
|
+
/**
|
|
107
|
+
* Gets the first tokens of the given node with filter options.
|
|
108
|
+
*/
|
|
109
|
+
getFirstTokens<R extends AST.Token>(node: YAMLSyntaxElement, options: CursorWithCountOptionsWithFilter<AST.Token, R>): R[];
|
|
110
|
+
/**
|
|
111
|
+
* Gets the first tokens of the given node with comment options.
|
|
112
|
+
*/
|
|
113
|
+
getFirstTokens<R extends AST.Token | AST.Comment>(node: YAMLSyntaxElement, options: CursorWithCountOptionsWithComment<AST.Token, AST.Comment, R>): R[];
|
|
114
|
+
/**
|
|
115
|
+
* Gets the last token of the given node.
|
|
116
|
+
*/
|
|
100
117
|
getLastToken(node: YAMLSyntaxElement): AST.Token;
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
118
|
+
/**
|
|
119
|
+
* Gets the last token of the given node with options.
|
|
120
|
+
*/
|
|
121
|
+
getLastToken(node: YAMLSyntaxElement, options: CursorWithSkipOptionsWithoutFilter): AST.Token | null;
|
|
122
|
+
/**
|
|
123
|
+
* Gets the last token of the given node with filter options.
|
|
124
|
+
*/
|
|
125
|
+
getLastToken<R extends AST.Token>(node: YAMLSyntaxElement, options: CursorWithSkipOptionsWithFilter<AST.Token, R>): R | null;
|
|
126
|
+
/**
|
|
127
|
+
* Gets the last token of the given node with comment options.
|
|
128
|
+
*/
|
|
129
|
+
getLastToken<R extends AST.Token | AST.Comment>(node: YAMLSyntaxElement, options: CursorWithSkipOptionsWithComment<AST.Token, AST.Comment, R>): R | null;
|
|
130
|
+
/**
|
|
131
|
+
* Get the last tokens of the given node.
|
|
132
|
+
*/
|
|
133
|
+
getLastTokens(node: YAMLSyntaxElement, options?: CursorWithCountOptionsWithoutFilter): AST.Token[];
|
|
134
|
+
/**
|
|
135
|
+
* Get the last tokens of the given node with filter options.
|
|
136
|
+
*/
|
|
137
|
+
getLastTokens<R extends AST.Token>(node: YAMLSyntaxElement, options: CursorWithCountOptionsWithFilter<AST.Token, R>): R[];
|
|
138
|
+
/**
|
|
139
|
+
* Get the last tokens of the given node with comment options.
|
|
140
|
+
*/
|
|
141
|
+
getLastTokens<R extends AST.Token | AST.Comment>(node: YAMLSyntaxElement, options: CursorWithCountOptionsWithComment<AST.Token, AST.Comment, R>): R[];
|
|
142
|
+
/**
|
|
143
|
+
* Gets the token that precedes a given node or token.
|
|
144
|
+
*/
|
|
145
|
+
getTokenBefore(node: YAMLSyntaxElement, options?: CursorWithSkipOptionsWithoutFilter): AST.Token | null;
|
|
146
|
+
/**
|
|
147
|
+
* Gets the token that precedes a given node or token with filter options.
|
|
148
|
+
*/
|
|
149
|
+
getTokenBefore<R extends AST.Token>(node: YAMLSyntaxElement, options: CursorWithSkipOptionsWithFilter<AST.Token, R>): R | null;
|
|
150
|
+
/**
|
|
151
|
+
* Gets the token that precedes a given node or token with comment options.
|
|
152
|
+
*/
|
|
153
|
+
getTokenBefore<R extends AST.Token | AST.Comment>(node: YAMLSyntaxElement, options: CursorWithSkipOptionsWithComment<AST.Token, AST.Comment, R>): R | null;
|
|
154
|
+
/**
|
|
155
|
+
* Gets the `count` tokens that precedes a given node or token.
|
|
156
|
+
*/
|
|
157
|
+
getTokensBefore(node: YAMLSyntaxElement, options?: CursorWithCountOptionsWithoutFilter): AST.Token[];
|
|
158
|
+
/**
|
|
159
|
+
* Gets the `count` tokens that precedes a given node or token with filter options.
|
|
160
|
+
*/
|
|
161
|
+
getTokensBefore<R extends AST.Token>(node: YAMLSyntaxElement, options: CursorWithCountOptionsWithFilter<AST.Token, R>): R[];
|
|
162
|
+
/**
|
|
163
|
+
* Gets the `count` tokens that precedes a given node or token with comment options.
|
|
164
|
+
*/
|
|
165
|
+
getTokensBefore<R extends AST.Token | AST.Comment>(node: YAMLSyntaxElement, options: CursorWithCountOptionsWithComment<AST.Token, AST.Comment, R>): R[];
|
|
166
|
+
/**
|
|
167
|
+
* Gets the token that follows a given node or token.
|
|
168
|
+
*/
|
|
169
|
+
getTokenAfter(node: YAMLSyntaxElement, options?: CursorWithSkipOptionsWithoutFilter): AST.Token | null;
|
|
170
|
+
/**
|
|
171
|
+
* Gets the token that follows a given node or token with filter options.
|
|
172
|
+
*/
|
|
173
|
+
getTokenAfter<R extends AST.Token>(node: YAMLSyntaxElement, options: CursorWithSkipOptionsWithFilter<AST.Token, R>): R | null;
|
|
174
|
+
/**
|
|
175
|
+
* Gets the token that follows a given node or token with comment options.
|
|
176
|
+
*/
|
|
177
|
+
getTokenAfter<R extends AST.Token | AST.Comment>(node: YAMLSyntaxElement, options: CursorWithSkipOptionsWithComment<AST.Token, AST.Comment, R>): R | null;
|
|
178
|
+
/**
|
|
179
|
+
* Gets the `count` tokens that follows a given node or token.
|
|
180
|
+
*/
|
|
181
|
+
getTokensAfter(node: YAMLSyntaxElement, options?: CursorWithCountOptionsWithoutFilter): AST.Token[];
|
|
182
|
+
/**
|
|
183
|
+
* Gets the `count` tokens that follows a given node or token with filter options.
|
|
184
|
+
*/
|
|
185
|
+
getTokensAfter<R extends AST.Token>(node: YAMLSyntaxElement, options: CursorWithCountOptionsWithFilter<AST.Token, R>): R[];
|
|
186
|
+
/**
|
|
187
|
+
* Gets the `count` tokens that follows a given node or token with comment options.
|
|
188
|
+
*/
|
|
189
|
+
getTokensAfter<R extends AST.Token | AST.Comment>(node: YAMLSyntaxElement, options: CursorWithCountOptionsWithComment<AST.Token, AST.Comment, R>): R[];
|
|
190
|
+
/**
|
|
191
|
+
* Gets the first token between two non-overlapping nodes.
|
|
192
|
+
*/
|
|
193
|
+
getFirstTokenBetween(left: YAMLSyntaxElement, right: YAMLSyntaxElement, options?: CursorWithSkipOptionsWithoutFilter): AST.Token | null;
|
|
194
|
+
/**
|
|
195
|
+
* Gets the first token between two non-overlapping nodes with filter options.
|
|
196
|
+
*/
|
|
197
|
+
getFirstTokenBetween<R extends AST.Token>(left: YAMLSyntaxElement, right: YAMLSyntaxElement, options: CursorWithSkipOptionsWithFilter<AST.Token, R>): R | null;
|
|
198
|
+
/**
|
|
199
|
+
* Gets the first token between two non-overlapping nodes with comment options.
|
|
200
|
+
*/
|
|
201
|
+
getFirstTokenBetween<R extends AST.Token | AST.Comment>(left: YAMLSyntaxElement, right: YAMLSyntaxElement, options: CursorWithSkipOptionsWithComment<AST.Token, AST.Comment, R>): R | null;
|
|
202
|
+
/**
|
|
203
|
+
* Gets the first tokens between two non-overlapping nodes.
|
|
204
|
+
*/
|
|
205
|
+
getFirstTokensBetween(left: YAMLSyntaxElement, right: YAMLSyntaxElement, options?: CursorWithCountOptionsWithoutFilter): AST.Token[];
|
|
206
|
+
/**
|
|
207
|
+
* Gets the first tokens between two non-overlapping nodes with filter options.
|
|
208
|
+
*/
|
|
209
|
+
getFirstTokensBetween<R extends AST.Token>(left: YAMLSyntaxElement, right: YAMLSyntaxElement, options: CursorWithCountOptionsWithFilter<AST.Token, R>): R[];
|
|
210
|
+
/**
|
|
211
|
+
* Gets the first tokens between two non-overlapping nodes with comment options.
|
|
212
|
+
*/
|
|
213
|
+
getFirstTokensBetween<R extends AST.Token | AST.Comment>(left: YAMLSyntaxElement, right: YAMLSyntaxElement, options: CursorWithCountOptionsWithComment<AST.Token, AST.Comment, R>): R[];
|
|
214
|
+
/**
|
|
215
|
+
* Gets the last token between two non-overlapping nodes.
|
|
216
|
+
*/
|
|
217
|
+
getLastTokenBetween(left: YAMLSyntaxElement, right: YAMLSyntaxElement, options?: CursorWithSkipOptionsWithoutFilter): AST.Token | null;
|
|
218
|
+
/**
|
|
219
|
+
* Gets the last token between two non-overlapping nodes with filter options.
|
|
220
|
+
*/
|
|
221
|
+
getLastTokenBetween<R extends AST.Token>(left: YAMLSyntaxElement, right: YAMLSyntaxElement, options: CursorWithSkipOptionsWithFilter<AST.Token, R>): R | null;
|
|
222
|
+
/**
|
|
223
|
+
* Gets the last token between two non-overlapping nodes with comment options.
|
|
224
|
+
*/
|
|
225
|
+
getLastTokenBetween<R extends AST.Token | AST.Comment>(left: YAMLSyntaxElement, right: YAMLSyntaxElement, options: CursorWithSkipOptionsWithComment<AST.Token, AST.Comment, R>): R | null;
|
|
226
|
+
/**
|
|
227
|
+
* Gets the last tokens between two non-overlapping nodes.
|
|
228
|
+
*/
|
|
229
|
+
getLastTokensBetween(left: YAMLSyntaxElement, right: YAMLSyntaxElement, options?: CursorWithCountOptionsWithoutFilter): AST.Token[];
|
|
230
|
+
/**
|
|
231
|
+
* Gets the last tokens between two non-overlapping nodes with filter options.
|
|
232
|
+
*/
|
|
233
|
+
getLastTokensBetween<R extends AST.Token>(left: YAMLSyntaxElement, right: YAMLSyntaxElement, options: CursorWithCountOptionsWithFilter<AST.Token, R>): R[];
|
|
234
|
+
/**
|
|
235
|
+
* Gets the last tokens between two non-overlapping nodes with comment options.
|
|
236
|
+
*/
|
|
237
|
+
getLastTokensBetween<R extends AST.Token | AST.Comment>(left: YAMLSyntaxElement, right: YAMLSyntaxElement, options: CursorWithCountOptionsWithComment<AST.Token, AST.Comment, R>): R[];
|
|
238
|
+
/**
|
|
239
|
+
* Gets all tokens that are related to the given node.
|
|
240
|
+
*/
|
|
241
|
+
getTokens(node: YAMLSyntaxElement, options?: CursorWithCountOptionsWithoutFilter): AST.Token[];
|
|
242
|
+
/**
|
|
243
|
+
* Gets all tokens that are related to the given node with filter options.
|
|
244
|
+
*/
|
|
245
|
+
getTokens<R extends AST.Token>(node: YAMLSyntaxElement, options: CursorWithCountOptionsWithFilter<AST.Token, R>): R[];
|
|
246
|
+
/**
|
|
247
|
+
* Gets all tokens that are related to the given node with comment options.
|
|
248
|
+
*/
|
|
249
|
+
getTokens<R extends AST.Token | AST.Comment>(node: YAMLSyntaxElement, options: CursorWithCountOptionsWithComment<AST.Token, AST.Comment, R>): R[];
|
|
250
|
+
/**
|
|
251
|
+
* Gets all of the tokens between two non-overlapping nodes.
|
|
252
|
+
*/
|
|
253
|
+
getTokensBetween(left: YAMLSyntaxElement, right: YAMLSyntaxElement, options?: CursorWithCountOptionsWithoutFilter): AST.Token[];
|
|
254
|
+
/**
|
|
255
|
+
* Gets all of the tokens between two non-overlapping nodes with filter options.
|
|
256
|
+
*/
|
|
257
|
+
getTokensBetween<R extends AST.Token>(left: YAMLSyntaxElement, right: YAMLSyntaxElement, options: CursorWithCountOptionsWithFilter<AST.Token, R>): R[];
|
|
258
|
+
/**
|
|
259
|
+
* Gets all of the tokens between two non-overlapping nodes with comment options.
|
|
260
|
+
*/
|
|
261
|
+
getTokensBetween<R extends AST.Token | AST.Comment>(left: YAMLSyntaxElement, right: YAMLSyntaxElement, options: CursorWithCountOptionsWithComment<AST.Token, AST.Comment, R>): R[];
|
|
262
|
+
getCommentsInside(nodeOrToken: YAMLSyntaxElement): AST.Comment[];
|
|
110
263
|
getCommentsBefore(nodeOrToken: YAMLSyntaxElement): AST.Comment[];
|
|
111
264
|
getCommentsAfter(nodeOrToken: YAMLSyntaxElement): AST.Comment[];
|
|
112
|
-
isSpaceBetween(first:
|
|
265
|
+
isSpaceBetween(first: AST.Token | AST.Comment, second: AST.Token | AST.Comment): boolean;
|
|
113
266
|
/**
|
|
114
267
|
* Compatibility for ESLint's SourceCode API
|
|
115
268
|
* @deprecated YAML does not have scopes
|
package/lib/index.mjs
CHANGED
|
@@ -6,6 +6,7 @@ import naturalCompare from "natural-compare";
|
|
|
6
6
|
import diffModule from "diff-sequences";
|
|
7
7
|
import escapeStringRegexp from "escape-string-regexp";
|
|
8
8
|
import { CallMethodStep, ConfigCommentParser, Directive, TextSourceCodeBase, VisitNodeStep } from "@eslint/plugin-kit";
|
|
9
|
+
import { TokenStore } from "@ota-meshi/ast-token-store";
|
|
9
10
|
|
|
10
11
|
//#region src/utils/index.ts
|
|
11
12
|
/**
|
|
@@ -5254,7 +5255,7 @@ var prettier_default = [...base_default, { rules: {
|
|
|
5254
5255
|
//#endregion
|
|
5255
5256
|
//#region package.json
|
|
5256
5257
|
var name$1 = "eslint-plugin-yml";
|
|
5257
|
-
var version$1 = "3.
|
|
5258
|
+
var version$1 = "3.2.0";
|
|
5258
5259
|
|
|
5259
5260
|
//#endregion
|
|
5260
5261
|
//#region src/meta.ts
|
|
@@ -5265,293 +5266,6 @@ var meta_exports = /* @__PURE__ */ __exportAll({
|
|
|
5265
5266
|
const name = name$1;
|
|
5266
5267
|
const version = version$1;
|
|
5267
5268
|
|
|
5268
|
-
//#endregion
|
|
5269
|
-
//#region src/language/token-store.ts
|
|
5270
|
-
/**
|
|
5271
|
-
* Binary search for the index of the first token that is after the given location.
|
|
5272
|
-
*/
|
|
5273
|
-
function search(tokens, location) {
|
|
5274
|
-
let minIndex = 0;
|
|
5275
|
-
let maxIndex = tokens.length - 1;
|
|
5276
|
-
while (minIndex <= maxIndex) {
|
|
5277
|
-
const index = Math.floor((minIndex + maxIndex) / 2);
|
|
5278
|
-
const tokenStartLocation = tokens[index].range[0];
|
|
5279
|
-
if (tokenStartLocation < location) minIndex = index + 1;
|
|
5280
|
-
else if (tokenStartLocation > location) maxIndex = index - 1;
|
|
5281
|
-
else return index;
|
|
5282
|
-
}
|
|
5283
|
-
return minIndex;
|
|
5284
|
-
}
|
|
5285
|
-
/**
|
|
5286
|
-
* Get the index of the first token that is after the given location.
|
|
5287
|
-
*/
|
|
5288
|
-
function getFirstIndex(tokens, indexMap, startLoc) {
|
|
5289
|
-
const index = indexMap.get(startLoc);
|
|
5290
|
-
if (index != null) return index;
|
|
5291
|
-
return search(tokens, startLoc);
|
|
5292
|
-
}
|
|
5293
|
-
/**
|
|
5294
|
-
* Get the index of the last token that is before the given location.
|
|
5295
|
-
*/
|
|
5296
|
-
function getLastIndex(tokens, indexMap, endLoc) {
|
|
5297
|
-
const index = indexMap.get(endLoc);
|
|
5298
|
-
if (index != null) return index - 1;
|
|
5299
|
-
return search(tokens, endLoc) - 1;
|
|
5300
|
-
}
|
|
5301
|
-
/**
|
|
5302
|
-
* Normalizes the options for cursor methods.
|
|
5303
|
-
*/
|
|
5304
|
-
function normalizeSkipOptions(options) {
|
|
5305
|
-
if (typeof options === "number") return {
|
|
5306
|
-
filter: isNotComment,
|
|
5307
|
-
skip: options
|
|
5308
|
-
};
|
|
5309
|
-
if (typeof options === "function") return {
|
|
5310
|
-
filter: (n) => {
|
|
5311
|
-
if (isComment(n)) return false;
|
|
5312
|
-
return options(n);
|
|
5313
|
-
},
|
|
5314
|
-
skip: 0
|
|
5315
|
-
};
|
|
5316
|
-
let filter;
|
|
5317
|
-
if (options?.includeComments) filter = options?.filter ?? (() => true);
|
|
5318
|
-
else if (options?.filter) {
|
|
5319
|
-
const baseFilter = options?.filter;
|
|
5320
|
-
filter = (token) => {
|
|
5321
|
-
if (isComment(token)) return false;
|
|
5322
|
-
return baseFilter(token);
|
|
5323
|
-
};
|
|
5324
|
-
} else filter = isNotComment;
|
|
5325
|
-
return {
|
|
5326
|
-
filter,
|
|
5327
|
-
skip: options?.skip ?? 0
|
|
5328
|
-
};
|
|
5329
|
-
}
|
|
5330
|
-
/**
|
|
5331
|
-
* Checks if a token is a comment.
|
|
5332
|
-
*/
|
|
5333
|
-
function isComment(token) {
|
|
5334
|
-
return token.type === "Block";
|
|
5335
|
-
}
|
|
5336
|
-
/**
|
|
5337
|
-
* Checks if a token is a not comment.
|
|
5338
|
-
*/
|
|
5339
|
-
function isNotComment(token) {
|
|
5340
|
-
return !isComment(token);
|
|
5341
|
-
}
|
|
5342
|
-
/**
|
|
5343
|
-
* Normalizes the options for cursor methods with count.
|
|
5344
|
-
*/
|
|
5345
|
-
function normalizeCountOptions(options) {
|
|
5346
|
-
if (typeof options === "number") return {
|
|
5347
|
-
filter: isNotComment,
|
|
5348
|
-
count: options
|
|
5349
|
-
};
|
|
5350
|
-
if (typeof options === "function") return {
|
|
5351
|
-
filter: (n) => {
|
|
5352
|
-
if (isComment(n)) return false;
|
|
5353
|
-
return options(n);
|
|
5354
|
-
},
|
|
5355
|
-
count: 0
|
|
5356
|
-
};
|
|
5357
|
-
let filter;
|
|
5358
|
-
if (options?.includeComments) filter = options?.filter ?? (() => true);
|
|
5359
|
-
else if (options?.filter) {
|
|
5360
|
-
const baseFilter = options?.filter;
|
|
5361
|
-
filter = (token) => {
|
|
5362
|
-
if (isComment(token)) return false;
|
|
5363
|
-
return baseFilter(token);
|
|
5364
|
-
};
|
|
5365
|
-
} else filter = isNotComment;
|
|
5366
|
-
return {
|
|
5367
|
-
filter,
|
|
5368
|
-
count: options?.count ?? 0
|
|
5369
|
-
};
|
|
5370
|
-
}
|
|
5371
|
-
var TokenStore = class {
|
|
5372
|
-
/**
|
|
5373
|
-
* Combined and sorted list of tokens and comments
|
|
5374
|
-
*/
|
|
5375
|
-
allTokens;
|
|
5376
|
-
/**
|
|
5377
|
-
* Map from token start location to index in allTokens
|
|
5378
|
-
*/
|
|
5379
|
-
tokenStartToIndex;
|
|
5380
|
-
constructor(params) {
|
|
5381
|
-
const tokens = params.ast.tokens || [];
|
|
5382
|
-
const comments = params.ast.comments || [];
|
|
5383
|
-
this.allTokens = [...tokens, ...comments].sort((a, b) => a.range[0] - b.range[0]);
|
|
5384
|
-
this.tokenStartToIndex = /* @__PURE__ */ new Map();
|
|
5385
|
-
for (let i = 0; i < this.allTokens.length; i++) this.tokenStartToIndex.set(this.allTokens[i].range[0], i);
|
|
5386
|
-
}
|
|
5387
|
-
/**
|
|
5388
|
-
* Gets the first token of the given node.
|
|
5389
|
-
*/
|
|
5390
|
-
getFirstToken(node, options) {
|
|
5391
|
-
const { filter, skip } = normalizeSkipOptions(options);
|
|
5392
|
-
const startIndex = getFirstIndex(this.allTokens, this.tokenStartToIndex, node.range[0]);
|
|
5393
|
-
const endIndex = getLastIndex(this.allTokens, this.tokenStartToIndex, node.range[1]);
|
|
5394
|
-
let skipped = 0;
|
|
5395
|
-
for (let i = startIndex; i <= endIndex && i < this.allTokens.length; i++) {
|
|
5396
|
-
const token = this.allTokens[i];
|
|
5397
|
-
if (filter && !filter(token)) continue;
|
|
5398
|
-
if (skipped < skip) {
|
|
5399
|
-
skipped++;
|
|
5400
|
-
continue;
|
|
5401
|
-
}
|
|
5402
|
-
return token;
|
|
5403
|
-
}
|
|
5404
|
-
return null;
|
|
5405
|
-
}
|
|
5406
|
-
/**
|
|
5407
|
-
* Gets the last token of the given node.
|
|
5408
|
-
*/
|
|
5409
|
-
getLastToken(node, options) {
|
|
5410
|
-
const { filter, skip } = normalizeSkipOptions(options);
|
|
5411
|
-
const startIndex = getFirstIndex(this.allTokens, this.tokenStartToIndex, node.range[0]);
|
|
5412
|
-
const endIndex = getLastIndex(this.allTokens, this.tokenStartToIndex, node.range[1]);
|
|
5413
|
-
let skipped = 0;
|
|
5414
|
-
for (let i = endIndex; i >= startIndex && i >= 0; i--) {
|
|
5415
|
-
const token = this.allTokens[i];
|
|
5416
|
-
if (filter && !filter(token)) continue;
|
|
5417
|
-
if (skipped < skip) {
|
|
5418
|
-
skipped++;
|
|
5419
|
-
continue;
|
|
5420
|
-
}
|
|
5421
|
-
return token;
|
|
5422
|
-
}
|
|
5423
|
-
return null;
|
|
5424
|
-
}
|
|
5425
|
-
/**
|
|
5426
|
-
* Gets the first token between two non-overlapping nodes.
|
|
5427
|
-
*/
|
|
5428
|
-
getFirstTokenBetween(left, right, options) {
|
|
5429
|
-
const { filter, skip } = normalizeSkipOptions(options);
|
|
5430
|
-
const startIndex = getFirstIndex(this.allTokens, this.tokenStartToIndex, left.range[1]);
|
|
5431
|
-
const endIndex = getLastIndex(this.allTokens, this.tokenStartToIndex, right.range[0]);
|
|
5432
|
-
let skipped = 0;
|
|
5433
|
-
for (let i = startIndex; i <= endIndex && i < this.allTokens.length; i++) {
|
|
5434
|
-
const token = this.allTokens[i];
|
|
5435
|
-
if (filter && !filter(token)) continue;
|
|
5436
|
-
if (skipped < skip) {
|
|
5437
|
-
skipped++;
|
|
5438
|
-
continue;
|
|
5439
|
-
}
|
|
5440
|
-
return token;
|
|
5441
|
-
}
|
|
5442
|
-
return null;
|
|
5443
|
-
}
|
|
5444
|
-
/**
|
|
5445
|
-
* Gets the token that precedes a given node or token.
|
|
5446
|
-
*/
|
|
5447
|
-
getTokenBefore(node, options) {
|
|
5448
|
-
const { filter, skip } = normalizeSkipOptions(options);
|
|
5449
|
-
const endIndex = getLastIndex(this.allTokens, this.tokenStartToIndex, node.range[0]);
|
|
5450
|
-
let skipped = 0;
|
|
5451
|
-
for (let i = endIndex; i >= 0; i--) {
|
|
5452
|
-
const token = this.allTokens[i];
|
|
5453
|
-
if (filter && !filter(token)) continue;
|
|
5454
|
-
if (skipped < skip) {
|
|
5455
|
-
skipped++;
|
|
5456
|
-
continue;
|
|
5457
|
-
}
|
|
5458
|
-
return token;
|
|
5459
|
-
}
|
|
5460
|
-
return null;
|
|
5461
|
-
}
|
|
5462
|
-
/**
|
|
5463
|
-
* Gets the token that follows a given node or token.
|
|
5464
|
-
*/
|
|
5465
|
-
getTokenAfter(node, options) {
|
|
5466
|
-
const { filter, skip } = normalizeSkipOptions(options);
|
|
5467
|
-
const startIndex = getFirstIndex(this.allTokens, this.tokenStartToIndex, node.range[1]);
|
|
5468
|
-
let skipped = 0;
|
|
5469
|
-
for (let i = startIndex; i < this.allTokens.length; i++) {
|
|
5470
|
-
const token = this.allTokens[i];
|
|
5471
|
-
if (filter && !filter(token)) continue;
|
|
5472
|
-
if (skipped < skip) {
|
|
5473
|
-
skipped++;
|
|
5474
|
-
continue;
|
|
5475
|
-
}
|
|
5476
|
-
return token;
|
|
5477
|
-
}
|
|
5478
|
-
return null;
|
|
5479
|
-
}
|
|
5480
|
-
/**
|
|
5481
|
-
* Gets the `count` tokens that precedes a given node or token.
|
|
5482
|
-
*/
|
|
5483
|
-
getTokensBefore(node, options) {
|
|
5484
|
-
const { filter, count } = normalizeCountOptions(options);
|
|
5485
|
-
const endIndex = getLastIndex(this.allTokens, this.tokenStartToIndex, node.range[0]);
|
|
5486
|
-
const result = [];
|
|
5487
|
-
for (let i = endIndex; i >= 0; i--) {
|
|
5488
|
-
const token = this.allTokens[i];
|
|
5489
|
-
if (filter && !filter(token)) continue;
|
|
5490
|
-
result.unshift(token);
|
|
5491
|
-
if (count > 0 && result.length >= count) break;
|
|
5492
|
-
}
|
|
5493
|
-
return result;
|
|
5494
|
-
}
|
|
5495
|
-
/**
|
|
5496
|
-
* Gets all tokens that are related to the given node.
|
|
5497
|
-
*/
|
|
5498
|
-
getTokens(node, options) {
|
|
5499
|
-
const { filter, count } = normalizeCountOptions(options);
|
|
5500
|
-
const startIndex = getFirstIndex(this.allTokens, this.tokenStartToIndex, node.range[0]);
|
|
5501
|
-
const endIndex = getLastIndex(this.allTokens, this.tokenStartToIndex, node.range[1]);
|
|
5502
|
-
const result = [];
|
|
5503
|
-
for (let i = startIndex; i <= endIndex && i < this.allTokens.length; i++) {
|
|
5504
|
-
const token = this.allTokens[i];
|
|
5505
|
-
if (filter && !filter(token)) continue;
|
|
5506
|
-
result.push(token);
|
|
5507
|
-
if (count > 0 && result.length >= count) break;
|
|
5508
|
-
}
|
|
5509
|
-
return result;
|
|
5510
|
-
}
|
|
5511
|
-
/**
|
|
5512
|
-
* Gets all of the tokens between two non-overlapping nodes.
|
|
5513
|
-
*/
|
|
5514
|
-
getTokensBetween(left, right, paddingOrOptions) {
|
|
5515
|
-
const { filter, count } = normalizeCountOptions(paddingOrOptions);
|
|
5516
|
-
const startIndex = getFirstIndex(this.allTokens, this.tokenStartToIndex, left.range[1]);
|
|
5517
|
-
const endIndex = getLastIndex(this.allTokens, this.tokenStartToIndex, right.range[0]);
|
|
5518
|
-
const result = [];
|
|
5519
|
-
for (let i = startIndex; i <= endIndex && i < this.allTokens.length; i++) {
|
|
5520
|
-
const token = this.allTokens[i];
|
|
5521
|
-
if (filter && !filter(token)) continue;
|
|
5522
|
-
result.push(token);
|
|
5523
|
-
if (count > 0 && result.length >= count) break;
|
|
5524
|
-
}
|
|
5525
|
-
return result;
|
|
5526
|
-
}
|
|
5527
|
-
/**
|
|
5528
|
-
* Gets all comment tokens directly before the given node or token.
|
|
5529
|
-
*/
|
|
5530
|
-
getCommentsBefore(nodeOrToken) {
|
|
5531
|
-
const endIndex = getLastIndex(this.allTokens, this.tokenStartToIndex, nodeOrToken.range[0]);
|
|
5532
|
-
const result = [];
|
|
5533
|
-
for (let i = endIndex; i >= 0; i--) {
|
|
5534
|
-
const token = this.allTokens[i];
|
|
5535
|
-
if (isComment(token)) result.unshift(token);
|
|
5536
|
-
else break;
|
|
5537
|
-
}
|
|
5538
|
-
return result;
|
|
5539
|
-
}
|
|
5540
|
-
/**
|
|
5541
|
-
* Gets all comment tokens directly after the given node or token.
|
|
5542
|
-
*/
|
|
5543
|
-
getCommentsAfter(nodeOrToken) {
|
|
5544
|
-
const startIndex = getFirstIndex(this.allTokens, this.tokenStartToIndex, nodeOrToken.range[1]);
|
|
5545
|
-
const result = [];
|
|
5546
|
-
for (let i = startIndex; i < this.allTokens.length; i++) {
|
|
5547
|
-
const token = this.allTokens[i];
|
|
5548
|
-
if (isComment(token)) result.push(token);
|
|
5549
|
-
else break;
|
|
5550
|
-
}
|
|
5551
|
-
return result;
|
|
5552
|
-
}
|
|
5553
|
-
};
|
|
5554
|
-
|
|
5555
5269
|
//#endregion
|
|
5556
5270
|
//#region src/language/yaml-source-code.ts
|
|
5557
5271
|
/**
|
|
@@ -5585,7 +5299,10 @@ var YAMLSourceCode = class extends TextSourceCodeBase {
|
|
|
5585
5299
|
this.hasBOM = Boolean(config.hasBOM);
|
|
5586
5300
|
this.parserServices = config.parserServices;
|
|
5587
5301
|
this.visitorKeys = config.visitorKeys || {};
|
|
5588
|
-
this.tokenStore = new TokenStore({
|
|
5302
|
+
this.tokenStore = new TokenStore({
|
|
5303
|
+
tokens: [...config.ast.tokens, ...config.ast.comments],
|
|
5304
|
+
isComment: (token) => token.type === "Block"
|
|
5305
|
+
});
|
|
5589
5306
|
}
|
|
5590
5307
|
traverse() {
|
|
5591
5308
|
if (this.#steps != null) return this.#steps;
|
|
@@ -5628,7 +5345,7 @@ var YAMLSourceCode = class extends TextSourceCodeBase {
|
|
|
5628
5345
|
return this.lines;
|
|
5629
5346
|
}
|
|
5630
5347
|
getAllComments() {
|
|
5631
|
-
return this.
|
|
5348
|
+
return this.tokenStore.getAllComments();
|
|
5632
5349
|
}
|
|
5633
5350
|
/**
|
|
5634
5351
|
* Returns an array of all inline configuration nodes found in the source code.
|
|
@@ -5728,9 +5445,15 @@ var YAMLSourceCode = class extends TextSourceCodeBase {
|
|
|
5728
5445
|
getFirstToken(node, options) {
|
|
5729
5446
|
return this.tokenStore.getFirstToken(node, options);
|
|
5730
5447
|
}
|
|
5448
|
+
getFirstTokens(node, options) {
|
|
5449
|
+
return this.tokenStore.getFirstTokens(node, options);
|
|
5450
|
+
}
|
|
5731
5451
|
getLastToken(node, options) {
|
|
5732
5452
|
return this.tokenStore.getLastToken(node, options);
|
|
5733
5453
|
}
|
|
5454
|
+
getLastTokens(node, options) {
|
|
5455
|
+
return this.tokenStore.getLastTokens(node, options);
|
|
5456
|
+
}
|
|
5734
5457
|
getTokenBefore(node, options) {
|
|
5735
5458
|
return this.tokenStore.getTokenBefore(node, options);
|
|
5736
5459
|
}
|
|
@@ -5740,15 +5463,30 @@ var YAMLSourceCode = class extends TextSourceCodeBase {
|
|
|
5740
5463
|
getTokenAfter(node, options) {
|
|
5741
5464
|
return this.tokenStore.getTokenAfter(node, options);
|
|
5742
5465
|
}
|
|
5466
|
+
getTokensAfter(node, options) {
|
|
5467
|
+
return this.tokenStore.getTokensAfter(node, options);
|
|
5468
|
+
}
|
|
5743
5469
|
getFirstTokenBetween(left, right, options) {
|
|
5744
5470
|
return this.tokenStore.getFirstTokenBetween(left, right, options);
|
|
5745
5471
|
}
|
|
5746
|
-
|
|
5747
|
-
return this.tokenStore.
|
|
5472
|
+
getFirstTokensBetween(left, right, options) {
|
|
5473
|
+
return this.tokenStore.getFirstTokensBetween(left, right, options);
|
|
5474
|
+
}
|
|
5475
|
+
getLastTokenBetween(left, right, options) {
|
|
5476
|
+
return this.tokenStore.getLastTokenBetween(left, right, options);
|
|
5477
|
+
}
|
|
5478
|
+
getLastTokensBetween(left, right, options) {
|
|
5479
|
+
return this.tokenStore.getLastTokensBetween(left, right, options);
|
|
5748
5480
|
}
|
|
5749
5481
|
getTokens(node, options) {
|
|
5750
5482
|
return this.tokenStore.getTokens(node, options);
|
|
5751
5483
|
}
|
|
5484
|
+
getTokensBetween(left, right, options) {
|
|
5485
|
+
return this.tokenStore.getTokensBetween(left, right, options);
|
|
5486
|
+
}
|
|
5487
|
+
getCommentsInside(nodeOrToken) {
|
|
5488
|
+
return this.tokenStore.getCommentsInside(nodeOrToken);
|
|
5489
|
+
}
|
|
5752
5490
|
getCommentsBefore(nodeOrToken) {
|
|
5753
5491
|
return this.tokenStore.getCommentsBefore(nodeOrToken);
|
|
5754
5492
|
}
|
|
@@ -5756,17 +5494,8 @@ var YAMLSourceCode = class extends TextSourceCodeBase {
|
|
|
5756
5494
|
return this.tokenStore.getCommentsAfter(nodeOrToken);
|
|
5757
5495
|
}
|
|
5758
5496
|
isSpaceBetween(first, second) {
|
|
5759
|
-
|
|
5760
|
-
|
|
5761
|
-
const firstToken = this.getLastToken(startingNodeOrToken) || startingNodeOrToken;
|
|
5762
|
-
const finalToken = this.getFirstToken(endingNodeOrToken) || endingNodeOrToken;
|
|
5763
|
-
let currentToken = firstToken;
|
|
5764
|
-
while (currentToken !== finalToken) {
|
|
5765
|
-
const nextToken = this.getTokenAfter(currentToken, { includeComments: true });
|
|
5766
|
-
if (currentToken.range[1] !== nextToken.range[0]) return true;
|
|
5767
|
-
currentToken = nextToken;
|
|
5768
|
-
}
|
|
5769
|
-
return false;
|
|
5497
|
+
const [left, right] = first.range[1] <= second.range[0] ? [first, second] : [second, first];
|
|
5498
|
+
return this.tokenStore.isSpaceBetween(left, right);
|
|
5770
5499
|
}
|
|
5771
5500
|
/**
|
|
5772
5501
|
* Compatibility for ESLint's SourceCode API
|
|
@@ -5818,12 +5547,6 @@ function isNode(value) {
|
|
|
5818
5547
|
return typeof value === "object" && value !== null && typeof value.type === "string" && Array.isArray(value.range) && Boolean(value.loc) && typeof value.loc === "object";
|
|
5819
5548
|
}
|
|
5820
5549
|
/**
|
|
5821
|
-
* Determines whether two nodes or tokens overlap.
|
|
5822
|
-
*/
|
|
5823
|
-
function nodesOrTokensOverlap(first, second) {
|
|
5824
|
-
return first.range[0] < second.range[1] && second.range[0] < first.range[1];
|
|
5825
|
-
}
|
|
5826
|
-
/**
|
|
5827
5550
|
* Creates a fake global scope for YAML files.
|
|
5828
5551
|
* @deprecated YAML does not have scopes
|
|
5829
5552
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-yml",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.2.0",
|
|
4
4
|
"description": "This ESLint plugin provides linting rules for YAML.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.mjs",
|
|
@@ -66,6 +66,7 @@
|
|
|
66
66
|
"dependencies": {
|
|
67
67
|
"@eslint/core": "^1.0.1",
|
|
68
68
|
"@eslint/plugin-kit": "^0.6.0",
|
|
69
|
+
"@ota-meshi/ast-token-store": "^0.2.0",
|
|
69
70
|
"debug": "^4.3.2",
|
|
70
71
|
"diff-sequences": "^29.0.0",
|
|
71
72
|
"escape-string-regexp": "5.0.0",
|
|
@@ -90,8 +91,8 @@
|
|
|
90
91
|
"@types/natural-compare": "^1.4.0",
|
|
91
92
|
"@types/node": "^24.0.0",
|
|
92
93
|
"@types/semver": "^7.3.1",
|
|
93
|
-
"@typescript-eslint/eslint-plugin": "~8.
|
|
94
|
-
"@typescript-eslint/parser": "~8.
|
|
94
|
+
"@typescript-eslint/eslint-plugin": "~8.56.0",
|
|
95
|
+
"@typescript-eslint/parser": "~8.56.0",
|
|
95
96
|
"cross-env": "^10.0.0",
|
|
96
97
|
"env-cmd": "^11.0.0",
|
|
97
98
|
"eslint": "^10.0.0",
|