eslint-plugin-toml 1.0.3 → 1.1.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/{chunk-15K8U1wQ.mjs → chunk-DQk6qfdC.mjs} +3 -3
- package/lib/index.d.mts +177 -25
- package/lib/index.mjs +83 -350
- package/package.json +11 -13
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
//#region
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
|
-
var __exportAll = (all,
|
|
3
|
+
var __exportAll = (all, no_symbols) => {
|
|
4
4
|
let target = {};
|
|
5
5
|
for (var name in all) {
|
|
6
6
|
__defProp(target, name, {
|
|
@@ -8,7 +8,7 @@ var __exportAll = (all, symbols) => {
|
|
|
8
8
|
enumerable: true
|
|
9
9
|
});
|
|
10
10
|
}
|
|
11
|
-
if (
|
|
11
|
+
if (!no_symbols) {
|
|
12
12
|
__defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
13
13
|
}
|
|
14
14
|
return target;
|
package/lib/index.d.mts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { AST, TOMLVersionOption } from "toml-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,20 +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
|
-
|
|
16
|
-
type FilterPredicate = (tokenOrComment: TOMLToken) => boolean;
|
|
17
|
-
type CursorWithSkipOptions = number | FilterPredicate | {
|
|
18
|
-
includeComments?: boolean;
|
|
19
|
-
filter?: FilterPredicate;
|
|
20
|
-
skip?: number;
|
|
21
|
-
};
|
|
22
|
-
type CursorWithCountOptions = number | FilterPredicate | {
|
|
23
|
-
includeComments?: boolean;
|
|
24
|
-
filter?: FilterPredicate;
|
|
25
|
-
count?: number;
|
|
26
|
-
};
|
|
27
|
-
//#endregion
|
|
28
15
|
//#region src/language/toml-source-code.d.ts
|
|
29
16
|
/**
|
|
30
17
|
* TOML-specific syntax element type
|
|
@@ -96,21 +83,186 @@ declare class TOMLSourceCode extends TextSourceCodeBase<{
|
|
|
96
83
|
problems: FileProblem[];
|
|
97
84
|
};
|
|
98
85
|
getNodeByRangeIndex(index: number): AST.TOMLNode | null;
|
|
86
|
+
/**
|
|
87
|
+
* Gets the first token of the given node.
|
|
88
|
+
*/
|
|
99
89
|
getFirstToken(node: TOMLSyntaxElement): AST.Token;
|
|
100
|
-
|
|
90
|
+
/**
|
|
91
|
+
* Gets the first token of the given node with options.
|
|
92
|
+
*/
|
|
93
|
+
getFirstToken(node: TOMLSyntaxElement, 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: TOMLSyntaxElement, 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: TOMLSyntaxElement, options: CursorWithSkipOptionsWithComment<AST.Token, AST.Comment, R>): R | null;
|
|
102
|
+
/**
|
|
103
|
+
* Gets the first tokens of the given node.
|
|
104
|
+
*/
|
|
105
|
+
getFirstTokens(node: TOMLSyntaxElement, 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: TOMLSyntaxElement, 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: TOMLSyntaxElement, options: CursorWithCountOptionsWithComment<AST.Token, AST.Comment, R>): R[];
|
|
114
|
+
/**
|
|
115
|
+
* Gets the last token of the given node.
|
|
116
|
+
*/
|
|
101
117
|
getLastToken(node: TOMLSyntaxElement): AST.Token;
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
118
|
+
/**
|
|
119
|
+
* Gets the last token of the given node with options.
|
|
120
|
+
*/
|
|
121
|
+
getLastToken(node: TOMLSyntaxElement, 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: TOMLSyntaxElement, 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: TOMLSyntaxElement, options: CursorWithSkipOptionsWithComment<AST.Token, AST.Comment, R>): R | null;
|
|
130
|
+
/**
|
|
131
|
+
* Get the last tokens of the given node.
|
|
132
|
+
*/
|
|
133
|
+
getLastTokens(node: TOMLSyntaxElement, 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: TOMLSyntaxElement, 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: TOMLSyntaxElement, options: CursorWithCountOptionsWithComment<AST.Token, AST.Comment, R>): R[];
|
|
142
|
+
/**
|
|
143
|
+
* Gets the token that precedes a given node or token.
|
|
144
|
+
*/
|
|
145
|
+
getTokenBefore(node: TOMLSyntaxElement, 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: TOMLSyntaxElement, 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: TOMLSyntaxElement, 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: TOMLSyntaxElement, 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: TOMLSyntaxElement, 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: TOMLSyntaxElement, options: CursorWithCountOptionsWithComment<AST.Token, AST.Comment, R>): R[];
|
|
166
|
+
/**
|
|
167
|
+
* Gets the token that follows a given node or token.
|
|
168
|
+
*/
|
|
169
|
+
getTokenAfter(node: TOMLSyntaxElement, 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: TOMLSyntaxElement, 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: TOMLSyntaxElement, 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: TOMLSyntaxElement, 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: TOMLSyntaxElement, 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: TOMLSyntaxElement, options: CursorWithCountOptionsWithComment<AST.Token, AST.Comment, R>): R[];
|
|
190
|
+
/**
|
|
191
|
+
* Gets the first token between two non-overlapping nodes.
|
|
192
|
+
*/
|
|
193
|
+
getFirstTokenBetween(left: TOMLSyntaxElement, right: TOMLSyntaxElement, 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: TOMLSyntaxElement, right: TOMLSyntaxElement, 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: TOMLSyntaxElement, right: TOMLSyntaxElement, options: CursorWithSkipOptionsWithComment<AST.Token, AST.Comment, R>): R | null;
|
|
202
|
+
/**
|
|
203
|
+
* Gets the first tokens between two non-overlapping nodes.
|
|
204
|
+
*/
|
|
205
|
+
getFirstTokensBetween(left: TOMLSyntaxElement, right: TOMLSyntaxElement, 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: TOMLSyntaxElement, right: TOMLSyntaxElement, 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: TOMLSyntaxElement, right: TOMLSyntaxElement, options: CursorWithCountOptionsWithComment<AST.Token, AST.Comment, R>): R[];
|
|
214
|
+
/**
|
|
215
|
+
* Gets the last token between two non-overlapping nodes.
|
|
216
|
+
*/
|
|
217
|
+
getLastTokenBetween(left: TOMLSyntaxElement, right: TOMLSyntaxElement, 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: TOMLSyntaxElement, right: TOMLSyntaxElement, 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: TOMLSyntaxElement, right: TOMLSyntaxElement, options: CursorWithSkipOptionsWithComment<AST.Token, AST.Comment, R>): R | null;
|
|
226
|
+
/**
|
|
227
|
+
* Gets the last tokens between two non-overlapping nodes.
|
|
228
|
+
*/
|
|
229
|
+
getLastTokensBetween(left: TOMLSyntaxElement, right: TOMLSyntaxElement, 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: TOMLSyntaxElement, right: TOMLSyntaxElement, 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: TOMLSyntaxElement, right: TOMLSyntaxElement, options: CursorWithCountOptionsWithComment<AST.Token, AST.Comment, R>): R[];
|
|
238
|
+
/**
|
|
239
|
+
* Gets all tokens that are related to the given node.
|
|
240
|
+
*/
|
|
241
|
+
getTokens(node: TOMLSyntaxElement, 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: TOMLSyntaxElement, 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: TOMLSyntaxElement, options: CursorWithCountOptionsWithComment<AST.Token, AST.Comment, R>): R[];
|
|
250
|
+
/**
|
|
251
|
+
* Gets all of the tokens between two non-overlapping nodes.
|
|
252
|
+
*/
|
|
253
|
+
getTokensBetween(left: TOMLSyntaxElement, right: TOMLSyntaxElement, 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: TOMLSyntaxElement, right: TOMLSyntaxElement, 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: TOMLSyntaxElement, right: TOMLSyntaxElement, options: CursorWithCountOptionsWithComment<AST.Token, AST.Comment, R>): R[];
|
|
262
|
+
getCommentsInside(nodeOrToken: TOMLSyntaxElement): AST.Comment[];
|
|
111
263
|
getCommentsBefore(nodeOrToken: TOMLSyntaxElement): AST.Comment[];
|
|
112
264
|
getCommentsAfter(nodeOrToken: TOMLSyntaxElement): AST.Comment[];
|
|
113
|
-
isSpaceBetween(first:
|
|
265
|
+
isSpaceBetween(first: AST.Token | AST.Comment, second: AST.Token | AST.Comment): boolean;
|
|
114
266
|
/**
|
|
115
267
|
* Compatibility for ESLint's SourceCode API
|
|
116
268
|
* @deprecated TOML does not have scopes
|
package/lib/index.mjs
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { t as __exportAll } from "./chunk-
|
|
1
|
+
import { t as __exportAll } from "./chunk-DQk6qfdC.mjs";
|
|
2
2
|
import * as tomlESLintParser from "toml-eslint-parser";
|
|
3
3
|
import { VisitorKeys, getStaticTOMLValue, parseTOML, traverseNodes } from "toml-eslint-parser";
|
|
4
4
|
import path from "path";
|
|
5
5
|
import { CallMethodStep, ConfigCommentParser, Directive, TextSourceCodeBase, VisitNodeStep } from "@eslint/plugin-kit";
|
|
6
|
+
import { TokenStore } from "@ota-meshi/ast-token-store";
|
|
6
7
|
|
|
7
8
|
//#region src/utils/index.ts
|
|
8
9
|
/**
|
|
@@ -257,7 +258,7 @@ var array_bracket_newline_default = createRule("array-bracket-newline", {
|
|
|
257
258
|
const firstIncComment = sourceCode.getTokenAfter(openBracket, { includeComments: true });
|
|
258
259
|
const lastIncComment = sourceCode.getTokenBefore(closeBracket, { includeComments: true });
|
|
259
260
|
const first = sourceCode.getTokenAfter(openBracket);
|
|
260
|
-
const last
|
|
261
|
+
const last = sourceCode.getTokenBefore(closeBracket);
|
|
261
262
|
/**
|
|
262
263
|
* Use tokens or comments to check multiline or not.
|
|
263
264
|
* But use only tokens to check whether linebreaks are needed.
|
|
@@ -268,10 +269,10 @@ var array_bracket_newline_default = createRule("array-bracket-newline", {
|
|
|
268
269
|
*/
|
|
269
270
|
if (elements.length >= options.minItems || options.multiline && elements.length > 0 && firstIncComment.loc.start.line !== lastIncComment.loc.end.line || elements.length === 0 && firstIncComment.type === "Block" && firstIncComment.loc.start.line !== lastIncComment.loc.end.line && firstIncComment === lastIncComment || options.consistent && openBracket.loc.end.line !== first.loc.start.line) {
|
|
270
271
|
if (isTokenOnSameLine(openBracket, first)) reportRequiredBeginningLinebreak(node, openBracket);
|
|
271
|
-
if (isTokenOnSameLine(last
|
|
272
|
+
if (isTokenOnSameLine(last, closeBracket)) reportRequiredEndingLinebreak(node, closeBracket);
|
|
272
273
|
} else {
|
|
273
274
|
if (!isTokenOnSameLine(openBracket, first)) reportNoBeginningLinebreak(node, openBracket);
|
|
274
|
-
if (!isTokenOnSameLine(last
|
|
275
|
+
if (!isTokenOnSameLine(last, closeBracket)) reportNoEndingLinebreak(node, closeBracket);
|
|
275
276
|
}
|
|
276
277
|
}
|
|
277
278
|
return { TOMLArray: check };
|
|
@@ -433,18 +434,18 @@ var array_bracket_spacing_default = createRule("array-bracket-spacing", {
|
|
|
433
434
|
function validateArraySpacing(node) {
|
|
434
435
|
if (options.spaced && node.elements.length === 0) return;
|
|
435
436
|
const first = sourceCode.getFirstToken(node);
|
|
436
|
-
const last
|
|
437
|
+
const last = sourceCode.getLastToken(node);
|
|
437
438
|
const second = sourceCode.getTokenAfter(first, { includeComments: true });
|
|
438
|
-
const penultimate = sourceCode.getTokenBefore(last
|
|
439
|
+
const penultimate = sourceCode.getTokenBefore(last, { includeComments: true });
|
|
439
440
|
if (isTokenOnSameLine(first, second)) {
|
|
440
441
|
if (options.isOpeningBracketMustBeSpaced(node)) {
|
|
441
442
|
if (!sourceCode.isSpaceBetween(first, second)) reportRequiredBeginningSpace(node, first);
|
|
442
443
|
} else if (sourceCode.isSpaceBetween(first, second)) reportNoBeginningSpace(node, first);
|
|
443
444
|
}
|
|
444
|
-
if (first !== penultimate && isTokenOnSameLine(penultimate, last
|
|
445
|
+
if (first !== penultimate && isTokenOnSameLine(penultimate, last)) {
|
|
445
446
|
if (options.isClosingBracketMustBeSpaced(node)) {
|
|
446
|
-
if (!sourceCode.isSpaceBetween(penultimate, last
|
|
447
|
-
} else if (sourceCode.isSpaceBetween(penultimate, last
|
|
447
|
+
if (!sourceCode.isSpaceBetween(penultimate, last)) reportRequiredEndingSpace(node, last);
|
|
448
|
+
} else if (sourceCode.isSpaceBetween(penultimate, last)) reportNoEndingSpace(node, last);
|
|
448
449
|
}
|
|
449
450
|
}
|
|
450
451
|
return { TOMLArray: validateArraySpacing };
|
|
@@ -809,8 +810,8 @@ function buildIndentUtility(optionValue) {
|
|
|
809
810
|
const textIndent = typeof indent === "number" ? " ".repeat(indent) : " ";
|
|
810
811
|
return {
|
|
811
812
|
getIndentText: (offset) => offset === 1 ? textIndent : textIndent.repeat(offset),
|
|
812
|
-
outdent(indent
|
|
813
|
-
return indent
|
|
813
|
+
outdent(indent) {
|
|
814
|
+
return indent.slice(0, -textIndent.length);
|
|
814
815
|
}
|
|
815
816
|
};
|
|
816
817
|
}
|
|
@@ -913,16 +914,16 @@ var indent_default = createRule("indent", {
|
|
|
913
914
|
let tableKeyStack = [];
|
|
914
915
|
/** Get offset from given table keys */
|
|
915
916
|
function getTableOffset(keys) {
|
|
916
|
-
let last
|
|
917
|
-
while (last
|
|
918
|
-
if (last
|
|
919
|
-
if (last
|
|
920
|
-
tableKeyStack.push(last
|
|
921
|
-
return last
|
|
917
|
+
let last = tableKeyStack.pop();
|
|
918
|
+
while (last) {
|
|
919
|
+
if (last.keys.length && last.keys.length <= keys.length && last.keys.every((k, i) => k === keys[i])) {
|
|
920
|
+
if (last.keys.length < keys.length) {
|
|
921
|
+
tableKeyStack.push(last);
|
|
922
|
+
return last.offset + subTablesOffset;
|
|
922
923
|
}
|
|
923
|
-
return last
|
|
924
|
+
return last.offset;
|
|
924
925
|
}
|
|
925
|
-
last
|
|
926
|
+
last = tableKeyStack.pop();
|
|
926
927
|
}
|
|
927
928
|
return 0;
|
|
928
929
|
}
|
|
@@ -1038,10 +1039,10 @@ var indent_default = createRule("indent", {
|
|
|
1038
1039
|
if (!lineIndent) continue;
|
|
1039
1040
|
const line = lineIndent.line;
|
|
1040
1041
|
if (isCommentToken(lineIndent.firstToken)) {
|
|
1041
|
-
const last
|
|
1042
|
-
if (last
|
|
1043
|
-
last
|
|
1044
|
-
last
|
|
1042
|
+
const last = commentLines[commentLines.length - 1];
|
|
1043
|
+
if (last && last.range[1] === line - 1) {
|
|
1044
|
+
last.range[1] = line;
|
|
1045
|
+
last.commentLineIndents.push(lineIndent);
|
|
1045
1046
|
} else commentLines.push({
|
|
1046
1047
|
range: [line, line],
|
|
1047
1048
|
commentLineIndents: [lineIndent]
|
|
@@ -1061,8 +1062,8 @@ var indent_default = createRule("indent", {
|
|
|
1061
1062
|
/**
|
|
1062
1063
|
* Process comments.
|
|
1063
1064
|
*/
|
|
1064
|
-
function processComments(commentLines
|
|
1065
|
-
for (const { range, commentLineIndents } of commentLines
|
|
1065
|
+
function processComments(commentLines) {
|
|
1066
|
+
for (const { range, commentLineIndents } of commentLines) {
|
|
1066
1067
|
const prev = results.slice(0, range[0]).filter((data) => data).pop();
|
|
1067
1068
|
const next = results.slice(range[1] + 1).filter((data) => data).shift();
|
|
1068
1069
|
const expectedIndents = [];
|
|
@@ -1307,18 +1308,18 @@ var inline_table_curly_spacing_default = createRule("inline-table-curly-spacing"
|
|
|
1307
1308
|
* @param penultimate The penultimate token to check (should be last before closing brace)
|
|
1308
1309
|
* @param last The last token to check (should be closing brace)
|
|
1309
1310
|
*/
|
|
1310
|
-
function validateBraceSpacing(node, first, second, penultimate, last
|
|
1311
|
+
function validateBraceSpacing(node, first, second, penultimate, last) {
|
|
1311
1312
|
if (isTokenOnSameLine(first, second)) {
|
|
1312
1313
|
const firstSpaced = sourceCode.isSpaceBetween(first, second);
|
|
1313
1314
|
if (options.isOpeningCurlyBraceMustBeSpaced(second)) {
|
|
1314
1315
|
if (!firstSpaced) reportRequiredBeginningSpace(node, first);
|
|
1315
1316
|
} else if (firstSpaced && second.type !== "Block") reportNoBeginningSpace(node, first);
|
|
1316
1317
|
}
|
|
1317
|
-
if (isTokenOnSameLine(penultimate, last
|
|
1318
|
-
const lastSpaced = sourceCode.isSpaceBetween(penultimate, last
|
|
1318
|
+
if (isTokenOnSameLine(penultimate, last)) {
|
|
1319
|
+
const lastSpaced = sourceCode.isSpaceBetween(penultimate, last);
|
|
1319
1320
|
if (options.isClosingCurlyBraceMustBeSpaced(penultimate)) {
|
|
1320
|
-
if (!lastSpaced) reportRequiredEndingSpace(node, last
|
|
1321
|
-
} else if (lastSpaced) reportNoEndingSpace(node, last
|
|
1321
|
+
if (!lastSpaced) reportRequiredEndingSpace(node, last);
|
|
1322
|
+
} else if (lastSpaced) reportNoEndingSpace(node, last);
|
|
1322
1323
|
}
|
|
1323
1324
|
}
|
|
1324
1325
|
/**
|
|
@@ -1343,8 +1344,8 @@ var inline_table_curly_spacing_default = createRule("inline-table-curly-spacing"
|
|
|
1343
1344
|
function checkForObject(node) {
|
|
1344
1345
|
if (node.body.length === 0) return;
|
|
1345
1346
|
const first = sourceCode.getFirstToken(node);
|
|
1346
|
-
const last
|
|
1347
|
-
validateBraceSpacing(node, first, sourceCode.getTokenAfter(first, { includeComments: true }), sourceCode.getTokenBefore(last
|
|
1347
|
+
const last = getClosingBraceOfObject(node);
|
|
1348
|
+
validateBraceSpacing(node, first, sourceCode.getTokenAfter(first, { includeComments: true }), sourceCode.getTokenBefore(last, { includeComments: true }), last);
|
|
1348
1349
|
}
|
|
1349
1350
|
return { TOMLInlineTable: checkForObject };
|
|
1350
1351
|
}
|
|
@@ -1659,7 +1660,7 @@ function create(context) {
|
|
|
1659
1660
|
/**
|
|
1660
1661
|
* Define alignment rule visitor
|
|
1661
1662
|
*/
|
|
1662
|
-
function defineAlignmentVisitor(alignmentOptions
|
|
1663
|
+
function defineAlignmentVisitor(alignmentOptions) {
|
|
1663
1664
|
return { "TOMLTopLevelTable, TOMLTable, TOMLInlineTable"(node) {
|
|
1664
1665
|
if (isSingleLine(node)) {
|
|
1665
1666
|
const body = node.body;
|
|
@@ -1674,17 +1675,17 @@ function create(context) {
|
|
|
1674
1675
|
function verifyGroupAlignment(properties) {
|
|
1675
1676
|
const length = properties.length;
|
|
1676
1677
|
const widths = properties.map(getKeyWidth);
|
|
1677
|
-
const align = alignmentOptions
|
|
1678
|
+
const align = alignmentOptions.on;
|
|
1678
1679
|
let targetWidth = Math.max(...widths);
|
|
1679
1680
|
let beforeEqual, afterEqual, mode;
|
|
1680
|
-
if (alignmentOptions
|
|
1681
|
-
beforeEqual = alignmentOptions
|
|
1682
|
-
afterEqual = alignmentOptions
|
|
1683
|
-
mode = alignmentOptions
|
|
1681
|
+
if (alignmentOptions && length > 1) {
|
|
1682
|
+
beforeEqual = alignmentOptions.beforeEqual ? 1 : 0;
|
|
1683
|
+
afterEqual = alignmentOptions.afterEqual ? 1 : 0;
|
|
1684
|
+
mode = alignmentOptions.mode;
|
|
1684
1685
|
} else {
|
|
1685
1686
|
beforeEqual = multiLineOptions.beforeEqual ? 1 : 0;
|
|
1686
1687
|
afterEqual = multiLineOptions.afterEqual ? 1 : 0;
|
|
1687
|
-
mode = alignmentOptions
|
|
1688
|
+
mode = alignmentOptions.mode;
|
|
1688
1689
|
}
|
|
1689
1690
|
targetWidth += align === "equal" ? beforeEqual : afterEqual;
|
|
1690
1691
|
for (let i = 0; i < length; i++) {
|
|
@@ -2838,11 +2839,11 @@ var table_bracket_spacing_default = createRule("table-bracket-spacing", {
|
|
|
2838
2839
|
function validateArraySpacing(node) {
|
|
2839
2840
|
const key = node.key;
|
|
2840
2841
|
const first = sourceCode.getTokenBefore(key);
|
|
2841
|
-
const last
|
|
2842
|
+
const last = sourceCode.getTokenAfter(key);
|
|
2842
2843
|
if (prefer === "always" && first.range[1] === key.range[0]) reportRequiredBeginningSpace(node, first);
|
|
2843
2844
|
if (prefer === "never" && first.range[1] < key.range[0]) reportNoBeginningSpace(node, first);
|
|
2844
|
-
if (prefer === "always" && key.range[1] === last
|
|
2845
|
-
if (prefer === "never" && key.range[1] < last
|
|
2845
|
+
if (prefer === "always" && key.range[1] === last.range[0]) reportRequiredEndingSpace(node, last);
|
|
2846
|
+
if (prefer === "never" && key.range[1] < last.range[0]) reportNoEndingSpace(node, last);
|
|
2846
2847
|
}
|
|
2847
2848
|
return { TOMLTable: validateArraySpacing };
|
|
2848
2849
|
}
|
|
@@ -2862,8 +2863,8 @@ function getFirst(keys) {
|
|
|
2862
2863
|
* Get last key node
|
|
2863
2864
|
*/
|
|
2864
2865
|
function getLast(keys) {
|
|
2865
|
-
const last
|
|
2866
|
-
if (last
|
|
2866
|
+
const last = keys[keys.length - 1];
|
|
2867
|
+
if (last) return getLast(last.keys) || last.node;
|
|
2867
2868
|
return null;
|
|
2868
2869
|
}
|
|
2869
2870
|
var tables_order_default = createRule("tables-order", {
|
|
@@ -3070,7 +3071,7 @@ var standard_default = [...base_default, { rules: {
|
|
|
3070
3071
|
//#endregion
|
|
3071
3072
|
//#region package.json
|
|
3072
3073
|
var name$1 = "eslint-plugin-toml";
|
|
3073
|
-
var version$1 = "1.0
|
|
3074
|
+
var version$1 = "1.1.0";
|
|
3074
3075
|
|
|
3075
3076
|
//#endregion
|
|
3076
3077
|
//#region src/meta.ts
|
|
@@ -3081,285 +3082,6 @@ var meta_exports = /* @__PURE__ */ __exportAll({
|
|
|
3081
3082
|
const name = name$1;
|
|
3082
3083
|
const version = version$1;
|
|
3083
3084
|
|
|
3084
|
-
//#endregion
|
|
3085
|
-
//#region src/language/token-store.ts
|
|
3086
|
-
/**
|
|
3087
|
-
* Binary search for the index of the first token that is after the given location.
|
|
3088
|
-
*/
|
|
3089
|
-
function search(tokens, location) {
|
|
3090
|
-
let minIndex = 0;
|
|
3091
|
-
let maxIndex = tokens.length - 1;
|
|
3092
|
-
while (minIndex <= maxIndex) {
|
|
3093
|
-
const index = Math.floor((minIndex + maxIndex) / 2);
|
|
3094
|
-
const tokenStartLocation = tokens[index].range[0];
|
|
3095
|
-
if (tokenStartLocation < location) minIndex = index + 1;
|
|
3096
|
-
else if (tokenStartLocation > location) maxIndex = index - 1;
|
|
3097
|
-
else return index;
|
|
3098
|
-
}
|
|
3099
|
-
return minIndex;
|
|
3100
|
-
}
|
|
3101
|
-
/**
|
|
3102
|
-
* Get the index of the first token that is after the given location.
|
|
3103
|
-
*/
|
|
3104
|
-
function getFirstIndex(tokens, indexMap, startLoc) {
|
|
3105
|
-
const index = indexMap.get(startLoc);
|
|
3106
|
-
if (index != null) return index;
|
|
3107
|
-
return search(tokens, startLoc);
|
|
3108
|
-
}
|
|
3109
|
-
/**
|
|
3110
|
-
* Get the index of the last token that is before the given location.
|
|
3111
|
-
*/
|
|
3112
|
-
function getLastIndex(tokens, indexMap, endLoc) {
|
|
3113
|
-
const index = indexMap.get(endLoc);
|
|
3114
|
-
if (index != null) return index - 1;
|
|
3115
|
-
return search(tokens, endLoc) - 1;
|
|
3116
|
-
}
|
|
3117
|
-
/**
|
|
3118
|
-
* Normalizes the options for cursor methods.
|
|
3119
|
-
*/
|
|
3120
|
-
function normalizeSkipOptions(options) {
|
|
3121
|
-
if (typeof options === "number") return {
|
|
3122
|
-
filter: isNotComment,
|
|
3123
|
-
skip: options
|
|
3124
|
-
};
|
|
3125
|
-
if (typeof options === "function") return {
|
|
3126
|
-
filter: (n) => {
|
|
3127
|
-
if (isComment(n)) return false;
|
|
3128
|
-
return options(n);
|
|
3129
|
-
},
|
|
3130
|
-
skip: 0
|
|
3131
|
-
};
|
|
3132
|
-
let filter;
|
|
3133
|
-
if (options?.includeComments) filter = options?.filter ?? (() => true);
|
|
3134
|
-
else if (options?.filter) {
|
|
3135
|
-
const baseFilter = options?.filter;
|
|
3136
|
-
filter = (token) => {
|
|
3137
|
-
if (isComment(token)) return false;
|
|
3138
|
-
return baseFilter(token);
|
|
3139
|
-
};
|
|
3140
|
-
} else filter = isNotComment;
|
|
3141
|
-
return {
|
|
3142
|
-
filter,
|
|
3143
|
-
skip: options?.skip ?? 0
|
|
3144
|
-
};
|
|
3145
|
-
}
|
|
3146
|
-
/**
|
|
3147
|
-
* Checks if a token is a comment.
|
|
3148
|
-
*/
|
|
3149
|
-
function isComment(token) {
|
|
3150
|
-
return token.type === "Block";
|
|
3151
|
-
}
|
|
3152
|
-
/**
|
|
3153
|
-
* Checks if a token is a not comment.
|
|
3154
|
-
*/
|
|
3155
|
-
function isNotComment(token) {
|
|
3156
|
-
return !isComment(token);
|
|
3157
|
-
}
|
|
3158
|
-
/**
|
|
3159
|
-
* Normalizes the options for cursor methods with count.
|
|
3160
|
-
*/
|
|
3161
|
-
function normalizeCountOptions(options) {
|
|
3162
|
-
if (typeof options === "number") return {
|
|
3163
|
-
filter: isNotComment,
|
|
3164
|
-
count: options
|
|
3165
|
-
};
|
|
3166
|
-
if (typeof options === "function") return {
|
|
3167
|
-
filter: (n) => {
|
|
3168
|
-
if (isComment(n)) return false;
|
|
3169
|
-
return options(n);
|
|
3170
|
-
},
|
|
3171
|
-
count: 0
|
|
3172
|
-
};
|
|
3173
|
-
let filter;
|
|
3174
|
-
if (options?.includeComments) filter = options?.filter ?? (() => true);
|
|
3175
|
-
else if (options?.filter) {
|
|
3176
|
-
const baseFilter = options?.filter;
|
|
3177
|
-
filter = (token) => {
|
|
3178
|
-
if (isComment(token)) return false;
|
|
3179
|
-
return baseFilter(token);
|
|
3180
|
-
};
|
|
3181
|
-
} else filter = isNotComment;
|
|
3182
|
-
return {
|
|
3183
|
-
filter,
|
|
3184
|
-
count: options?.count ?? 0
|
|
3185
|
-
};
|
|
3186
|
-
}
|
|
3187
|
-
var TokenStore = class {
|
|
3188
|
-
constructor(params) {
|
|
3189
|
-
const tokens = params.ast.tokens || [];
|
|
3190
|
-
const comments = params.ast.comments || [];
|
|
3191
|
-
this.allTokens = [...tokens, ...comments].sort((a, b) => a.range[0] - b.range[0]);
|
|
3192
|
-
this.tokenStartToIndex = /* @__PURE__ */ new Map();
|
|
3193
|
-
for (let i = 0; i < this.allTokens.length; i++) this.tokenStartToIndex.set(this.allTokens[i].range[0], i);
|
|
3194
|
-
}
|
|
3195
|
-
/**
|
|
3196
|
-
* Gets the first token of the given node.
|
|
3197
|
-
*/
|
|
3198
|
-
getFirstToken(node, options) {
|
|
3199
|
-
const { filter, skip } = normalizeSkipOptions(options);
|
|
3200
|
-
const startIndex = getFirstIndex(this.allTokens, this.tokenStartToIndex, node.range[0]);
|
|
3201
|
-
const endIndex = getLastIndex(this.allTokens, this.tokenStartToIndex, node.range[1]);
|
|
3202
|
-
let skipped = 0;
|
|
3203
|
-
for (let i = startIndex; i <= endIndex && i < this.allTokens.length; i++) {
|
|
3204
|
-
const token = this.allTokens[i];
|
|
3205
|
-
if (filter && !filter(token)) continue;
|
|
3206
|
-
if (skipped < skip) {
|
|
3207
|
-
skipped++;
|
|
3208
|
-
continue;
|
|
3209
|
-
}
|
|
3210
|
-
return token;
|
|
3211
|
-
}
|
|
3212
|
-
return null;
|
|
3213
|
-
}
|
|
3214
|
-
/**
|
|
3215
|
-
* Gets the last token of the given node.
|
|
3216
|
-
*/
|
|
3217
|
-
getLastToken(node, options) {
|
|
3218
|
-
const { filter, skip } = normalizeSkipOptions(options);
|
|
3219
|
-
const startIndex = getFirstIndex(this.allTokens, this.tokenStartToIndex, node.range[0]);
|
|
3220
|
-
const endIndex = getLastIndex(this.allTokens, this.tokenStartToIndex, node.range[1]);
|
|
3221
|
-
let skipped = 0;
|
|
3222
|
-
for (let i = endIndex; i >= startIndex && i >= 0; i--) {
|
|
3223
|
-
const token = this.allTokens[i];
|
|
3224
|
-
if (filter && !filter(token)) continue;
|
|
3225
|
-
if (skipped < skip) {
|
|
3226
|
-
skipped++;
|
|
3227
|
-
continue;
|
|
3228
|
-
}
|
|
3229
|
-
return token;
|
|
3230
|
-
}
|
|
3231
|
-
return null;
|
|
3232
|
-
}
|
|
3233
|
-
/**
|
|
3234
|
-
* Gets the first token between two non-overlapping nodes.
|
|
3235
|
-
*/
|
|
3236
|
-
getFirstTokenBetween(left, right, options) {
|
|
3237
|
-
const { filter, skip } = normalizeSkipOptions(options);
|
|
3238
|
-
const startIndex = getFirstIndex(this.allTokens, this.tokenStartToIndex, left.range[1]);
|
|
3239
|
-
const endIndex = getLastIndex(this.allTokens, this.tokenStartToIndex, right.range[0]);
|
|
3240
|
-
let skipped = 0;
|
|
3241
|
-
for (let i = startIndex; i <= endIndex && i < this.allTokens.length; i++) {
|
|
3242
|
-
const token = this.allTokens[i];
|
|
3243
|
-
if (filter && !filter(token)) continue;
|
|
3244
|
-
if (skipped < skip) {
|
|
3245
|
-
skipped++;
|
|
3246
|
-
continue;
|
|
3247
|
-
}
|
|
3248
|
-
return token;
|
|
3249
|
-
}
|
|
3250
|
-
return null;
|
|
3251
|
-
}
|
|
3252
|
-
/**
|
|
3253
|
-
* Gets the token that precedes a given node or token.
|
|
3254
|
-
*/
|
|
3255
|
-
getTokenBefore(node, options) {
|
|
3256
|
-
const { filter, skip } = normalizeSkipOptions(options);
|
|
3257
|
-
const endIndex = getLastIndex(this.allTokens, this.tokenStartToIndex, node.range[0]);
|
|
3258
|
-
let skipped = 0;
|
|
3259
|
-
for (let i = endIndex; i >= 0; i--) {
|
|
3260
|
-
const token = this.allTokens[i];
|
|
3261
|
-
if (filter && !filter(token)) continue;
|
|
3262
|
-
if (skipped < skip) {
|
|
3263
|
-
skipped++;
|
|
3264
|
-
continue;
|
|
3265
|
-
}
|
|
3266
|
-
return token;
|
|
3267
|
-
}
|
|
3268
|
-
return null;
|
|
3269
|
-
}
|
|
3270
|
-
/**
|
|
3271
|
-
* Gets the token that follows a given node or token.
|
|
3272
|
-
*/
|
|
3273
|
-
getTokenAfter(node, options) {
|
|
3274
|
-
const { filter, skip } = normalizeSkipOptions(options);
|
|
3275
|
-
const startIndex = getFirstIndex(this.allTokens, this.tokenStartToIndex, node.range[1]);
|
|
3276
|
-
let skipped = 0;
|
|
3277
|
-
for (let i = startIndex; i < this.allTokens.length; i++) {
|
|
3278
|
-
const token = this.allTokens[i];
|
|
3279
|
-
if (filter && !filter(token)) continue;
|
|
3280
|
-
if (skipped < skip) {
|
|
3281
|
-
skipped++;
|
|
3282
|
-
continue;
|
|
3283
|
-
}
|
|
3284
|
-
return token;
|
|
3285
|
-
}
|
|
3286
|
-
return null;
|
|
3287
|
-
}
|
|
3288
|
-
/**
|
|
3289
|
-
* Gets the `count` tokens that precedes a given node or token.
|
|
3290
|
-
*/
|
|
3291
|
-
getTokensBefore(node, options) {
|
|
3292
|
-
const { filter, count } = normalizeCountOptions(options);
|
|
3293
|
-
const endIndex = getLastIndex(this.allTokens, this.tokenStartToIndex, node.range[0]);
|
|
3294
|
-
const result = [];
|
|
3295
|
-
for (let i = endIndex; i >= 0; i--) {
|
|
3296
|
-
const token = this.allTokens[i];
|
|
3297
|
-
if (filter && !filter(token)) continue;
|
|
3298
|
-
result.unshift(token);
|
|
3299
|
-
if (count > 0 && result.length >= count) break;
|
|
3300
|
-
}
|
|
3301
|
-
return result;
|
|
3302
|
-
}
|
|
3303
|
-
/**
|
|
3304
|
-
* Gets all tokens that are related to the given node.
|
|
3305
|
-
*/
|
|
3306
|
-
getTokens(node, options) {
|
|
3307
|
-
const { filter, count } = normalizeCountOptions(options);
|
|
3308
|
-
const startIndex = getFirstIndex(this.allTokens, this.tokenStartToIndex, node.range[0]);
|
|
3309
|
-
const endIndex = getLastIndex(this.allTokens, this.tokenStartToIndex, node.range[1]);
|
|
3310
|
-
const result = [];
|
|
3311
|
-
for (let i = startIndex; i <= endIndex && i < this.allTokens.length; i++) {
|
|
3312
|
-
const token = this.allTokens[i];
|
|
3313
|
-
if (filter && !filter(token)) continue;
|
|
3314
|
-
result.push(token);
|
|
3315
|
-
if (count > 0 && result.length >= count) break;
|
|
3316
|
-
}
|
|
3317
|
-
return result;
|
|
3318
|
-
}
|
|
3319
|
-
/**
|
|
3320
|
-
* Gets all of the tokens between two non-overlapping nodes.
|
|
3321
|
-
*/
|
|
3322
|
-
getTokensBetween(left, right, paddingOrOptions) {
|
|
3323
|
-
const { filter, count } = normalizeCountOptions(paddingOrOptions);
|
|
3324
|
-
const startIndex = getFirstIndex(this.allTokens, this.tokenStartToIndex, left.range[1]);
|
|
3325
|
-
const endIndex = getLastIndex(this.allTokens, this.tokenStartToIndex, right.range[0]);
|
|
3326
|
-
const result = [];
|
|
3327
|
-
for (let i = startIndex; i <= endIndex && i < this.allTokens.length; i++) {
|
|
3328
|
-
const token = this.allTokens[i];
|
|
3329
|
-
if (filter && !filter(token)) continue;
|
|
3330
|
-
result.push(token);
|
|
3331
|
-
if (count > 0 && result.length >= count) break;
|
|
3332
|
-
}
|
|
3333
|
-
return result;
|
|
3334
|
-
}
|
|
3335
|
-
/**
|
|
3336
|
-
* Gets all comment tokens directly before the given node or token.
|
|
3337
|
-
*/
|
|
3338
|
-
getCommentsBefore(nodeOrToken) {
|
|
3339
|
-
const endIndex = getLastIndex(this.allTokens, this.tokenStartToIndex, nodeOrToken.range[0]);
|
|
3340
|
-
const result = [];
|
|
3341
|
-
for (let i = endIndex; i >= 0; i--) {
|
|
3342
|
-
const token = this.allTokens[i];
|
|
3343
|
-
if (isComment(token)) result.unshift(token);
|
|
3344
|
-
else break;
|
|
3345
|
-
}
|
|
3346
|
-
return result;
|
|
3347
|
-
}
|
|
3348
|
-
/**
|
|
3349
|
-
* Gets all comment tokens directly after the given node or token.
|
|
3350
|
-
*/
|
|
3351
|
-
getCommentsAfter(nodeOrToken) {
|
|
3352
|
-
const startIndex = getFirstIndex(this.allTokens, this.tokenStartToIndex, nodeOrToken.range[1]);
|
|
3353
|
-
const result = [];
|
|
3354
|
-
for (let i = startIndex; i < this.allTokens.length; i++) {
|
|
3355
|
-
const token = this.allTokens[i];
|
|
3356
|
-
if (isComment(token)) result.push(token);
|
|
3357
|
-
else break;
|
|
3358
|
-
}
|
|
3359
|
-
return result;
|
|
3360
|
-
}
|
|
3361
|
-
};
|
|
3362
|
-
|
|
3363
3085
|
//#endregion
|
|
3364
3086
|
//#region src/language/toml-source-code.ts
|
|
3365
3087
|
/**
|
|
@@ -3389,7 +3111,10 @@ var TOMLSourceCode = class extends TextSourceCodeBase {
|
|
|
3389
3111
|
this.hasBOM = Boolean(config.hasBOM);
|
|
3390
3112
|
this.parserServices = config.parserServices;
|
|
3391
3113
|
this.visitorKeys = config.visitorKeys || {};
|
|
3392
|
-
this.tokenStore = new TokenStore({
|
|
3114
|
+
this.tokenStore = new TokenStore({
|
|
3115
|
+
tokens: [...config.ast.tokens, ...config.ast.comments],
|
|
3116
|
+
isComment: (token) => token.type === "Block"
|
|
3117
|
+
});
|
|
3393
3118
|
}
|
|
3394
3119
|
traverse() {
|
|
3395
3120
|
if (this.#steps != null) return this.#steps;
|
|
@@ -3432,7 +3157,7 @@ var TOMLSourceCode = class extends TextSourceCodeBase {
|
|
|
3432
3157
|
return this.lines;
|
|
3433
3158
|
}
|
|
3434
3159
|
getAllComments() {
|
|
3435
|
-
return this.
|
|
3160
|
+
return this.tokenStore.getAllComments();
|
|
3436
3161
|
}
|
|
3437
3162
|
/**
|
|
3438
3163
|
* Returns an array of all inline configuration nodes found in the source code.
|
|
@@ -3490,14 +3215,14 @@ var TOMLSourceCode = class extends TextSourceCodeBase {
|
|
|
3490
3215
|
*/
|
|
3491
3216
|
applyInlineConfig() {
|
|
3492
3217
|
const problems = [];
|
|
3493
|
-
const configs
|
|
3218
|
+
const configs = [];
|
|
3494
3219
|
this.getInlineConfigNodes().forEach((comment) => {
|
|
3495
3220
|
const directive = commentParser.parseDirective(comment.value);
|
|
3496
3221
|
if (!directive) return;
|
|
3497
3222
|
const { label, value } = directive;
|
|
3498
3223
|
if (label === "eslint") {
|
|
3499
3224
|
const parseResult = commentParser.parseJSONLikeConfig(value);
|
|
3500
|
-
if (parseResult.ok) configs
|
|
3225
|
+
if (parseResult.ok) configs.push({
|
|
3501
3226
|
config: { rules: parseResult.config },
|
|
3502
3227
|
loc: comment.loc
|
|
3503
3228
|
});
|
|
@@ -3509,7 +3234,7 @@ var TOMLSourceCode = class extends TextSourceCodeBase {
|
|
|
3509
3234
|
}
|
|
3510
3235
|
});
|
|
3511
3236
|
return {
|
|
3512
|
-
configs
|
|
3237
|
+
configs,
|
|
3513
3238
|
problems
|
|
3514
3239
|
};
|
|
3515
3240
|
}
|
|
@@ -3525,16 +3250,22 @@ var TOMLSourceCode = class extends TextSourceCodeBase {
|
|
|
3525
3250
|
* Finds a node that contains the given index.
|
|
3526
3251
|
*/
|
|
3527
3252
|
function find(nodes) {
|
|
3528
|
-
for (const node
|
|
3253
|
+
for (const node of nodes) if (node.range[0] <= index && index < node.range[1]) return node;
|
|
3529
3254
|
return null;
|
|
3530
3255
|
}
|
|
3531
3256
|
}
|
|
3532
3257
|
getFirstToken(node, options) {
|
|
3533
3258
|
return this.tokenStore.getFirstToken(node, options);
|
|
3534
3259
|
}
|
|
3260
|
+
getFirstTokens(node, options) {
|
|
3261
|
+
return this.tokenStore.getFirstTokens(node, options);
|
|
3262
|
+
}
|
|
3535
3263
|
getLastToken(node, options) {
|
|
3536
3264
|
return this.tokenStore.getLastToken(node, options);
|
|
3537
3265
|
}
|
|
3266
|
+
getLastTokens(node, options) {
|
|
3267
|
+
return this.tokenStore.getLastTokens(node, options);
|
|
3268
|
+
}
|
|
3538
3269
|
getTokenBefore(node, options) {
|
|
3539
3270
|
return this.tokenStore.getTokenBefore(node, options);
|
|
3540
3271
|
}
|
|
@@ -3544,15 +3275,30 @@ var TOMLSourceCode = class extends TextSourceCodeBase {
|
|
|
3544
3275
|
getTokenAfter(node, options) {
|
|
3545
3276
|
return this.tokenStore.getTokenAfter(node, options);
|
|
3546
3277
|
}
|
|
3278
|
+
getTokensAfter(node, options) {
|
|
3279
|
+
return this.tokenStore.getTokensAfter(node, options);
|
|
3280
|
+
}
|
|
3547
3281
|
getFirstTokenBetween(left, right, options) {
|
|
3548
3282
|
return this.tokenStore.getFirstTokenBetween(left, right, options);
|
|
3549
3283
|
}
|
|
3550
|
-
|
|
3551
|
-
return this.tokenStore.
|
|
3284
|
+
getFirstTokensBetween(left, right, options) {
|
|
3285
|
+
return this.tokenStore.getFirstTokensBetween(left, right, options);
|
|
3286
|
+
}
|
|
3287
|
+
getLastTokenBetween(left, right, options) {
|
|
3288
|
+
return this.tokenStore.getLastTokenBetween(left, right, options);
|
|
3289
|
+
}
|
|
3290
|
+
getLastTokensBetween(left, right, options) {
|
|
3291
|
+
return this.tokenStore.getLastTokensBetween(left, right, options);
|
|
3552
3292
|
}
|
|
3553
3293
|
getTokens(node, options) {
|
|
3554
3294
|
return this.tokenStore.getTokens(node, options);
|
|
3555
3295
|
}
|
|
3296
|
+
getTokensBetween(left, right, options) {
|
|
3297
|
+
return this.tokenStore.getTokensBetween(left, right, options);
|
|
3298
|
+
}
|
|
3299
|
+
getCommentsInside(nodeOrToken) {
|
|
3300
|
+
return this.tokenStore.getCommentsInside(nodeOrToken);
|
|
3301
|
+
}
|
|
3556
3302
|
getCommentsBefore(nodeOrToken) {
|
|
3557
3303
|
return this.tokenStore.getCommentsBefore(nodeOrToken);
|
|
3558
3304
|
}
|
|
@@ -3560,17 +3306,8 @@ var TOMLSourceCode = class extends TextSourceCodeBase {
|
|
|
3560
3306
|
return this.tokenStore.getCommentsAfter(nodeOrToken);
|
|
3561
3307
|
}
|
|
3562
3308
|
isSpaceBetween(first, second) {
|
|
3563
|
-
|
|
3564
|
-
|
|
3565
|
-
const firstToken = this.getLastToken(startingNodeOrToken) || startingNodeOrToken;
|
|
3566
|
-
const finalToken = this.getFirstToken(endingNodeOrToken) || endingNodeOrToken;
|
|
3567
|
-
let currentToken = firstToken;
|
|
3568
|
-
while (currentToken !== finalToken) {
|
|
3569
|
-
const nextToken = this.getTokenAfter(currentToken, { includeComments: true });
|
|
3570
|
-
if (currentToken.range[1] !== nextToken.range[0]) return true;
|
|
3571
|
-
currentToken = nextToken;
|
|
3572
|
-
}
|
|
3573
|
-
return false;
|
|
3309
|
+
const [left, right] = first.range[1] <= second.range[0] ? [first, second] : [second, first];
|
|
3310
|
+
return this.tokenStore.isSpaceBetween(left, right);
|
|
3574
3311
|
}
|
|
3575
3312
|
/**
|
|
3576
3313
|
* Compatibility for ESLint's SourceCode API
|
|
@@ -3592,7 +3329,8 @@ var TOMLSourceCode = class extends TextSourceCodeBase {
|
|
|
3592
3329
|
if (node.type === "Program") return createFakeGlobalScope(this.ast);
|
|
3593
3330
|
return null;
|
|
3594
3331
|
},
|
|
3595
|
-
getDeclaredVariables: () => []
|
|
3332
|
+
getDeclaredVariables: () => [],
|
|
3333
|
+
addGlobals: () => {}
|
|
3596
3334
|
};
|
|
3597
3335
|
}
|
|
3598
3336
|
/**
|
|
@@ -3621,12 +3359,6 @@ function isNode(value) {
|
|
|
3621
3359
|
return typeof value === "object" && value !== null && typeof value.type === "string" && Array.isArray(value.range) && Boolean(value.loc) && typeof value.loc === "object";
|
|
3622
3360
|
}
|
|
3623
3361
|
/**
|
|
3624
|
-
* Determines whether two nodes or tokens overlap.
|
|
3625
|
-
*/
|
|
3626
|
-
function nodesOrTokensOverlap(first, second) {
|
|
3627
|
-
return first.range[0] < second.range[1] && second.range[0] < first.range[1];
|
|
3628
|
-
}
|
|
3629
|
-
/**
|
|
3630
3362
|
* Creates a fake global scope for TOML files.
|
|
3631
3363
|
* @deprecated TOML does not have scopes
|
|
3632
3364
|
*/
|
|
@@ -3670,6 +3402,7 @@ var TOMLLanguage = class {
|
|
|
3670
3402
|
validateLanguageOptions(_languageOptions) {}
|
|
3671
3403
|
normalizeLanguageOptions(languageOptions) {
|
|
3672
3404
|
return {
|
|
3405
|
+
ecmaVersion: "latest",
|
|
3673
3406
|
...languageOptions,
|
|
3674
3407
|
parserOptions: { ...languageOptions.parserOptions }
|
|
3675
3408
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-toml",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "This ESLint plugin provides linting rules for TOML.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -65,7 +65,8 @@
|
|
|
65
65
|
},
|
|
66
66
|
"dependencies": {
|
|
67
67
|
"@eslint/core": "^1.0.1",
|
|
68
|
-
"@eslint/plugin-kit": "^0.
|
|
68
|
+
"@eslint/plugin-kit": "^0.6.0",
|
|
69
|
+
"@ota-meshi/ast-token-store": "^0.2.0",
|
|
69
70
|
"debug": "^4.1.1",
|
|
70
71
|
"toml-eslint-parser": "^1.0.1"
|
|
71
72
|
},
|
|
@@ -73,14 +74,11 @@
|
|
|
73
74
|
"@changesets/changelog-github": "^0.5.0",
|
|
74
75
|
"@changesets/cli": "^2.27.5",
|
|
75
76
|
"@eslint-community/eslint-plugin-eslint-comments": "^4.3.0",
|
|
76
|
-
"@eslint/json": "^0.
|
|
77
|
-
"@ota-meshi/eslint-plugin": "^0.
|
|
77
|
+
"@eslint/json": "^1.0.0",
|
|
78
|
+
"@ota-meshi/eslint-plugin": "^0.20.0",
|
|
78
79
|
"@ota-meshi/site-kit-eslint-editor-vue": "^0.2.1",
|
|
80
|
+
"@stylistic/eslint-plugin": "^5.7.1",
|
|
79
81
|
"@types/debug": "^4.1.12",
|
|
80
|
-
"@types/eslint": "^9.0.0",
|
|
81
|
-
"@types/eslint-scope": "^8.0.0",
|
|
82
|
-
"@types/eslint-visitor-keys": "^3.3.0",
|
|
83
|
-
"@types/estree": "^1.0.5",
|
|
84
82
|
"@types/mocha": "^10.0.7",
|
|
85
83
|
"@types/node": "^24.0.0",
|
|
86
84
|
"@types/semver": "^7.5.8",
|
|
@@ -89,20 +87,20 @@
|
|
|
89
87
|
"cross-env": "^10.0.0",
|
|
90
88
|
"env-cmd": "^11.0.0",
|
|
91
89
|
"esbuild": "^0.27.0",
|
|
92
|
-
"eslint": "^
|
|
90
|
+
"eslint": "^10.0.0",
|
|
93
91
|
"eslint-config-prettier": "^10.0.0",
|
|
94
92
|
"eslint-plugin-eslint-plugin": "^7.0.0",
|
|
95
93
|
"eslint-plugin-jsdoc": "^62.0.0",
|
|
96
|
-
"eslint-plugin-json-schema-validator": "^
|
|
94
|
+
"eslint-plugin-json-schema-validator": "^6.0.0",
|
|
97
95
|
"eslint-plugin-jsonc": "^2.16.0",
|
|
98
96
|
"eslint-plugin-markdown": "^5.0.0",
|
|
99
97
|
"eslint-plugin-n": "^17.9.0",
|
|
100
98
|
"eslint-plugin-node-dependencies": "^1.0.0",
|
|
101
99
|
"eslint-plugin-prettier": "^5.1.3",
|
|
102
|
-
"eslint-plugin-regexp": "^
|
|
100
|
+
"eslint-plugin-regexp": "^3.0.0",
|
|
103
101
|
"eslint-plugin-toml": "^1.0.0",
|
|
104
102
|
"eslint-plugin-vue": "^10.0.0",
|
|
105
|
-
"eslint-plugin-yml": "^
|
|
103
|
+
"eslint-plugin-yml": "^3.0.0",
|
|
106
104
|
"events": "^3.3.0",
|
|
107
105
|
"mocha": "^11.0.0",
|
|
108
106
|
"nyc": "^17.0.0",
|
|
@@ -114,7 +112,7 @@
|
|
|
114
112
|
"stylelint-config-standard": "^40.0.0",
|
|
115
113
|
"stylelint-config-standard-vue": "^1.0.0",
|
|
116
114
|
"stylelint-stylus": "^1.0.0",
|
|
117
|
-
"tsdown": "^0.
|
|
115
|
+
"tsdown": "^0.20.0",
|
|
118
116
|
"tsx": "^4.21.0",
|
|
119
117
|
"typescript": "~5.9.0",
|
|
120
118
|
"typescript-eslint": "^8.16.0",
|