@eslint/json 0.10.0 → 0.12.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/README.md +5 -4
- package/dist/cjs/index.cjs +195 -58
- package/dist/cjs/index.d.cts +82 -168
- package/dist/cjs/types.cts +92 -0
- package/dist/esm/index.d.ts +82 -168
- package/dist/esm/index.js +195 -58
- package/dist/esm/types.d.ts +53 -0
- package/dist/esm/types.ts +92 -0
- package/package.json +22 -12
package/dist/cjs/index.d.cts
CHANGED
|
@@ -1,38 +1,64 @@
|
|
|
1
|
-
export type
|
|
2
|
-
export type
|
|
3
|
-
export type JSONToken = import("@humanwhocodes/momoa").Token;
|
|
4
|
-
export type SourceRange = import("@eslint/core").SourceRange;
|
|
5
|
-
export type SourceLocation = import("@eslint/core").SourceLocation;
|
|
6
|
-
export type File = import("@eslint/core").File;
|
|
7
|
-
export type TraversalStep = import("@eslint/core").TraversalStep;
|
|
8
|
-
export type TextSourceCode = import("@eslint/core").TextSourceCode;
|
|
9
|
-
export type VisitTraversalStep = import("@eslint/core").VisitTraversalStep;
|
|
10
|
-
export type FileProblem = import("@eslint/core").FileProblem;
|
|
11
|
-
export type DirectiveType = import("@eslint/core").DirectiveType;
|
|
12
|
-
export type RulesConfig = import("@eslint/core").RulesConfig;
|
|
13
|
-
export type Language = import("@eslint/core").Language;
|
|
14
|
-
export type OkParseResult = import("@eslint/core").OkParseResult<DocumentNode>;
|
|
15
|
-
export type ParseResult = import("@eslint/core").ParseResult<DocumentNode>;
|
|
1
|
+
export type JSONOkParseResult = OkParseResult<DocumentNode>;
|
|
2
|
+
export type JSONParseResult = ParseResult<DocumentNode>;
|
|
16
3
|
export type JSONLanguageOptions = {
|
|
17
4
|
/**
|
|
18
|
-
* Whether to allow trailing commas.
|
|
5
|
+
* Whether to allow trailing commas in JSONC mode.
|
|
19
6
|
*/
|
|
20
7
|
allowTrailingCommas?: boolean;
|
|
21
8
|
};
|
|
9
|
+
export type NoDuplicateKeysMessageIds = "duplicateKey";
|
|
10
|
+
export type NoDuplicateKeysRuleDefinition = JSONRuleDefinition<{
|
|
11
|
+
MessageIds: NoDuplicateKeysMessageIds;
|
|
12
|
+
}>;
|
|
13
|
+
export type NoEmptyKeysMessageIds = "emptyKey";
|
|
14
|
+
export type NoEmptyKeysRuleDefinition = JSONRuleDefinition<{
|
|
15
|
+
MessageIds: NoEmptyKeysMessageIds;
|
|
16
|
+
}>;
|
|
17
|
+
export type NoUnsafeValuesMessageIds = "unsafeNumber" | "unsafeInteger" | "unsafeZero" | "subnormal" | "loneSurrogate";
|
|
18
|
+
export type NoUnsafeValuesRuleDefinition = JSONRuleDefinition<{
|
|
19
|
+
MessageIds: NoUnsafeValuesMessageIds;
|
|
20
|
+
}>;
|
|
21
|
+
export type NoUnnormalizedKeysMessageIds = "unnormalizedKey";
|
|
22
|
+
export type NoUnnormalizedKeysOptions = {
|
|
23
|
+
form: string;
|
|
24
|
+
};
|
|
25
|
+
export type NoUnnormalizedKeysRuleDefinition = JSONRuleDefinition<{
|
|
26
|
+
RuleOptions: [NoUnnormalizedKeysOptions];
|
|
27
|
+
MessageIds: NoUnnormalizedKeysMessageIds;
|
|
28
|
+
}>;
|
|
29
|
+
export type SortOptions = {
|
|
30
|
+
caseSensitive: boolean;
|
|
31
|
+
natural: boolean;
|
|
32
|
+
minKeys: number;
|
|
33
|
+
allowLineSeparatedGroups: boolean;
|
|
34
|
+
};
|
|
35
|
+
export type SortKeysMessageIds = "sortKeys";
|
|
36
|
+
export type SortDirection = "asc" | "desc";
|
|
37
|
+
export type SortKeysRuleOptions = [SortDirection, SortOptions];
|
|
38
|
+
export type SortKeysRuleDefinition = JSONRuleDefinition<{
|
|
39
|
+
RuleOptions: SortKeysRuleOptions;
|
|
40
|
+
MessageIds: SortKeysMessageIds;
|
|
41
|
+
}>;
|
|
42
|
+
export type Comparator = (a: string, b: string) => boolean;
|
|
43
|
+
export type TopLevelInteropMessageIds = "topLevel";
|
|
44
|
+
export type TopLevelInteropRuleDefinition = JSONRuleDefinition<{
|
|
45
|
+
MessageIds: TopLevelInteropMessageIds;
|
|
46
|
+
}>;
|
|
22
47
|
/**
|
|
23
48
|
* @filedescription Functions to fix up rules to provide missing methods on the `context` object.
|
|
24
49
|
* @author Nicholas C. Zakas
|
|
25
50
|
*/
|
|
26
|
-
/** @typedef {import("@eslint/core").Language} Language */
|
|
27
|
-
/** @typedef {import("@eslint/core").OkParseResult<DocumentNode>} OkParseResult */
|
|
28
|
-
/** @typedef {import("@eslint/core").ParseResult<DocumentNode>} ParseResult */
|
|
29
51
|
/**
|
|
52
|
+
*
|
|
53
|
+
* @typedef {OkParseResult<DocumentNode>} JSONOkParseResult
|
|
54
|
+
* @typedef {ParseResult<DocumentNode>} JSONParseResult
|
|
55
|
+
*
|
|
30
56
|
* @typedef {Object} JSONLanguageOptions
|
|
31
|
-
* @property {boolean} [allowTrailingCommas] Whether to allow trailing commas.
|
|
57
|
+
* @property {boolean} [allowTrailingCommas] Whether to allow trailing commas in JSONC mode.
|
|
32
58
|
*/
|
|
33
59
|
/**
|
|
34
60
|
* JSON Language Object
|
|
35
|
-
* @implements {Language}
|
|
61
|
+
* @implements {Language<{ LangOptions: JSONLanguageOptions; Code: JSONSourceCode; RootNode: DocumentNode; Node: AnyNode }>}
|
|
36
62
|
*/
|
|
37
63
|
export class JSONLanguage implements Language {
|
|
38
64
|
/**
|
|
@@ -79,24 +105,25 @@ export class JSONLanguage implements Language {
|
|
|
79
105
|
* Parses the given file into an AST.
|
|
80
106
|
* @param {File} file The virtual file to parse.
|
|
81
107
|
* @param {{languageOptions: JSONLanguageOptions}} context The options to use for parsing.
|
|
82
|
-
* @returns {
|
|
108
|
+
* @returns {JSONParseResult} The result of parsing.
|
|
83
109
|
*/
|
|
84
110
|
parse(file: File, context: {
|
|
85
111
|
languageOptions: JSONLanguageOptions;
|
|
86
|
-
}):
|
|
112
|
+
}): JSONParseResult;
|
|
87
113
|
/**
|
|
88
114
|
* Creates a new `JSONSourceCode` object from the given information.
|
|
89
115
|
* @param {File} file The virtual file to create a `JSONSourceCode` object from.
|
|
90
|
-
* @param {
|
|
116
|
+
* @param {JSONOkParseResult} parseResult The result returned from `parse()`.
|
|
91
117
|
* @returns {JSONSourceCode} The new `JSONSourceCode` object.
|
|
92
118
|
*/
|
|
93
|
-
createSourceCode(file: File, parseResult:
|
|
119
|
+
createSourceCode(file: File, parseResult: JSONOkParseResult): JSONSourceCode;
|
|
94
120
|
#private;
|
|
95
121
|
}
|
|
96
122
|
/**
|
|
97
123
|
* JSON Source Code Object
|
|
124
|
+
* @implements {TextSourceCode<{LangOptions: JSONLanguageOptions, RootNode: DocumentNode, SyntaxElementWithLoc: JSONSyntaxElement, ConfigNode: Token}>}
|
|
98
125
|
*/
|
|
99
|
-
export class JSONSourceCode extends TextSourceCodeBase {
|
|
126
|
+
export class JSONSourceCode extends TextSourceCodeBase implements TextSourceCode {
|
|
100
127
|
/**
|
|
101
128
|
* Creates a new instance.
|
|
102
129
|
* @param {Object} options The options for the instance.
|
|
@@ -114,15 +141,15 @@ export class JSONSourceCode extends TextSourceCodeBase {
|
|
|
114
141
|
ast: DocumentNode;
|
|
115
142
|
/**
|
|
116
143
|
* The comment node in the source code.
|
|
117
|
-
* @type {Array<
|
|
144
|
+
* @type {Array<Token>|undefined}
|
|
118
145
|
*/
|
|
119
|
-
comments: Array<
|
|
146
|
+
comments: Array<Token> | undefined;
|
|
120
147
|
/**
|
|
121
148
|
* Returns an array of all inline configuration nodes found in the
|
|
122
149
|
* source code.
|
|
123
|
-
* @returns {Array<
|
|
150
|
+
* @returns {Array<Token>} An array of all inline configuration nodes.
|
|
124
151
|
*/
|
|
125
|
-
getInlineConfigNodes(): Array<
|
|
152
|
+
getInlineConfigNodes(): Array<Token>;
|
|
126
153
|
/**
|
|
127
154
|
* Returns directives that enable or disable rules along with any problems
|
|
128
155
|
* encountered while parsing the directives.
|
|
@@ -150,10 +177,10 @@ export class JSONSourceCode extends TextSourceCodeBase {
|
|
|
150
177
|
};
|
|
151
178
|
/**
|
|
152
179
|
* Returns the parent of the given node.
|
|
153
|
-
* @param {
|
|
154
|
-
* @returns {
|
|
180
|
+
* @param {Node} node The node to get the parent of.
|
|
181
|
+
* @returns {Node|undefined} The parent of the node.
|
|
155
182
|
*/
|
|
156
|
-
getParent(node:
|
|
183
|
+
getParent(node: Node): Node | undefined;
|
|
157
184
|
/**
|
|
158
185
|
* Traverse the source code and return the steps that were taken.
|
|
159
186
|
* @returns {Iterable<JSONTraversalStep>} The steps that were taken while traversing the source code.
|
|
@@ -172,137 +199,12 @@ declare namespace plugin {
|
|
|
172
199
|
let json5: JSONLanguage;
|
|
173
200
|
}
|
|
174
201
|
let rules: {
|
|
175
|
-
"no-duplicate-keys":
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
messages: {
|
|
182
|
-
duplicateKey: string;
|
|
183
|
-
};
|
|
184
|
-
};
|
|
185
|
-
create(context: any): {
|
|
186
|
-
Object(): void;
|
|
187
|
-
Member(node: any): void;
|
|
188
|
-
"Object:exit"(): void;
|
|
189
|
-
};
|
|
190
|
-
};
|
|
191
|
-
"no-empty-keys": {
|
|
192
|
-
meta: {
|
|
193
|
-
type: "problem";
|
|
194
|
-
docs: {
|
|
195
|
-
description: string;
|
|
196
|
-
};
|
|
197
|
-
messages: {
|
|
198
|
-
emptyKey: string;
|
|
199
|
-
};
|
|
200
|
-
};
|
|
201
|
-
create(context: any): {
|
|
202
|
-
Member(node: any): void;
|
|
203
|
-
};
|
|
204
|
-
};
|
|
205
|
-
"no-unsafe-values": {
|
|
206
|
-
meta: {
|
|
207
|
-
type: "problem";
|
|
208
|
-
docs: {
|
|
209
|
-
description: string;
|
|
210
|
-
};
|
|
211
|
-
messages: {
|
|
212
|
-
unsafeNumber: string;
|
|
213
|
-
unsafeInteger: string;
|
|
214
|
-
unsafeZero: string;
|
|
215
|
-
subnormal: string;
|
|
216
|
-
loneSurrogate: string;
|
|
217
|
-
};
|
|
218
|
-
};
|
|
219
|
-
create(context: any): {
|
|
220
|
-
Number(node: any): void;
|
|
221
|
-
String(node: any): void;
|
|
222
|
-
};
|
|
223
|
-
};
|
|
224
|
-
"no-unnormalized-keys": {
|
|
225
|
-
meta: {
|
|
226
|
-
type: "problem";
|
|
227
|
-
docs: {
|
|
228
|
-
description: string;
|
|
229
|
-
};
|
|
230
|
-
messages: {
|
|
231
|
-
unnormalizedKey: string;
|
|
232
|
-
};
|
|
233
|
-
schema: {
|
|
234
|
-
type: string;
|
|
235
|
-
properties: {
|
|
236
|
-
form: {
|
|
237
|
-
enum: string[];
|
|
238
|
-
};
|
|
239
|
-
};
|
|
240
|
-
additionalProperties: boolean;
|
|
241
|
-
}[];
|
|
242
|
-
};
|
|
243
|
-
create(context: any): {
|
|
244
|
-
Member(node: any): void;
|
|
245
|
-
};
|
|
246
|
-
};
|
|
247
|
-
"sort-keys": {
|
|
248
|
-
meta: {
|
|
249
|
-
type: "suggestion";
|
|
250
|
-
defaultOptions: (string | {
|
|
251
|
-
allowLineSeparatedGroups: boolean;
|
|
252
|
-
caseSensitive: boolean;
|
|
253
|
-
minKeys: number;
|
|
254
|
-
natural: boolean;
|
|
255
|
-
})[];
|
|
256
|
-
docs: {
|
|
257
|
-
description: string;
|
|
258
|
-
};
|
|
259
|
-
messages: {
|
|
260
|
-
sortKeys: string;
|
|
261
|
-
};
|
|
262
|
-
schema: ({
|
|
263
|
-
enum: string[];
|
|
264
|
-
type?: undefined;
|
|
265
|
-
properties?: undefined;
|
|
266
|
-
additionalProperties?: undefined;
|
|
267
|
-
} | {
|
|
268
|
-
type: string;
|
|
269
|
-
properties: {
|
|
270
|
-
caseSensitive: {
|
|
271
|
-
type: string;
|
|
272
|
-
};
|
|
273
|
-
natural: {
|
|
274
|
-
type: string;
|
|
275
|
-
};
|
|
276
|
-
minKeys: {
|
|
277
|
-
type: string;
|
|
278
|
-
minimum: number;
|
|
279
|
-
};
|
|
280
|
-
allowLineSeparatedGroups: {
|
|
281
|
-
type: string;
|
|
282
|
-
};
|
|
283
|
-
};
|
|
284
|
-
additionalProperties: boolean;
|
|
285
|
-
enum?: undefined;
|
|
286
|
-
})[];
|
|
287
|
-
};
|
|
288
|
-
create(context: any): {
|
|
289
|
-
Object(node: any): void;
|
|
290
|
-
};
|
|
291
|
-
};
|
|
292
|
-
"top-level-interop": {
|
|
293
|
-
meta: {
|
|
294
|
-
type: "problem";
|
|
295
|
-
docs: {
|
|
296
|
-
description: string;
|
|
297
|
-
};
|
|
298
|
-
messages: {
|
|
299
|
-
topLevel: string;
|
|
300
|
-
};
|
|
301
|
-
};
|
|
302
|
-
create(context: any): {
|
|
303
|
-
Document(node: any): void;
|
|
304
|
-
};
|
|
305
|
-
};
|
|
202
|
+
"no-duplicate-keys": NoDuplicateKeysRuleDefinition;
|
|
203
|
+
"no-empty-keys": NoEmptyKeysRuleDefinition;
|
|
204
|
+
"no-unsafe-values": NoUnsafeValuesRuleDefinition;
|
|
205
|
+
"no-unnormalized-keys": NoUnnormalizedKeysRuleDefinition;
|
|
206
|
+
"sort-keys": SortKeysRuleDefinition;
|
|
207
|
+
"top-level-interop": TopLevelInteropRuleDefinition;
|
|
306
208
|
};
|
|
307
209
|
namespace configs {
|
|
308
210
|
namespace recommended {
|
|
@@ -317,8 +219,20 @@ declare namespace plugin {
|
|
|
317
219
|
}
|
|
318
220
|
}
|
|
319
221
|
}
|
|
222
|
+
import type { DocumentNode } from "@humanwhocodes/momoa";
|
|
223
|
+
import type { OkParseResult } from "@eslint/core";
|
|
224
|
+
import type { ParseResult } from "@eslint/core";
|
|
225
|
+
import type { JSONRuleDefinition } from "./types.cts";
|
|
226
|
+
import type { Language } from "@eslint/core";
|
|
227
|
+
import type { File } from "@eslint/core";
|
|
228
|
+
import type { TextSourceCode } from "@eslint/core";
|
|
320
229
|
import { TextSourceCodeBase } from '@eslint/plugin-kit';
|
|
230
|
+
import type { Token } from "@humanwhocodes/momoa";
|
|
231
|
+
import type { FileProblem } from "@eslint/core";
|
|
321
232
|
import { Directive } from '@eslint/plugin-kit';
|
|
233
|
+
import type { RulesConfig } from "@eslint/core";
|
|
234
|
+
import type { SourceLocation } from "@eslint/core";
|
|
235
|
+
import type { Node } from "@humanwhocodes/momoa";
|
|
322
236
|
/**
|
|
323
237
|
* A class to represent a step in the traversal process.
|
|
324
238
|
*/
|
|
@@ -326,20 +240,20 @@ declare class JSONTraversalStep extends VisitNodeStep {
|
|
|
326
240
|
/**
|
|
327
241
|
* Creates a new instance.
|
|
328
242
|
* @param {Object} options The options for the step.
|
|
329
|
-
* @param {
|
|
243
|
+
* @param {Node} options.target The target of the step.
|
|
330
244
|
* @param {1|2} options.phase The phase of the step.
|
|
331
245
|
* @param {Array<any>} options.args The arguments of the step.
|
|
332
246
|
*/
|
|
333
247
|
constructor({ target, phase, args }: {
|
|
334
|
-
target:
|
|
248
|
+
target: Node;
|
|
335
249
|
phase: 1 | 2;
|
|
336
250
|
args: Array<any>;
|
|
337
251
|
});
|
|
338
252
|
/**
|
|
339
253
|
* The target of the step.
|
|
340
|
-
* @type {
|
|
254
|
+
* @type {Node}
|
|
341
255
|
*/
|
|
342
|
-
target:
|
|
256
|
+
target: Node;
|
|
343
257
|
}
|
|
344
258
|
import { VisitNodeStep } from '@eslint/plugin-kit';
|
|
345
259
|
export { plugin as default };
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Additional types for this package.
|
|
3
|
+
* @author Nicholas C. Zakas
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
//------------------------------------------------------------------------------
|
|
7
|
+
// Imports
|
|
8
|
+
//------------------------------------------------------------------------------
|
|
9
|
+
|
|
10
|
+
import type { RuleVisitor, RuleDefinition } from "@eslint/core";
|
|
11
|
+
import type {
|
|
12
|
+
DocumentNode,
|
|
13
|
+
MemberNode,
|
|
14
|
+
ElementNode,
|
|
15
|
+
ObjectNode,
|
|
16
|
+
ArrayNode,
|
|
17
|
+
StringNode,
|
|
18
|
+
NullNode,
|
|
19
|
+
NumberNode,
|
|
20
|
+
BooleanNode,
|
|
21
|
+
NaNNode,
|
|
22
|
+
InfinityNode,
|
|
23
|
+
IdentifierNode,
|
|
24
|
+
AnyNode,
|
|
25
|
+
Token,
|
|
26
|
+
} from "@humanwhocodes/momoa";
|
|
27
|
+
import type { JSONLanguageOptions, JSONSourceCode } from "./index.cjs";
|
|
28
|
+
|
|
29
|
+
//------------------------------------------------------------------------------
|
|
30
|
+
// Types
|
|
31
|
+
//------------------------------------------------------------------------------
|
|
32
|
+
|
|
33
|
+
type ValueNodeParent = DocumentNode | MemberNode | ElementNode;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* A JSON syntax element, including nodes and tokens.
|
|
37
|
+
*/
|
|
38
|
+
export type JSONSyntaxElement = Token | AnyNode;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* The visitor format returned from rules in this package.
|
|
42
|
+
*/
|
|
43
|
+
export interface JSONRuleVisitor extends RuleVisitor {
|
|
44
|
+
Document?(node: DocumentNode): void;
|
|
45
|
+
Member?(node: MemberNode, parent?: ObjectNode): void;
|
|
46
|
+
Element?(node: ElementNode, parent?: ArrayNode): void;
|
|
47
|
+
Object?(node: ObjectNode, parent?: ValueNodeParent): void;
|
|
48
|
+
Array?(node: ArrayNode, parent?: ValueNodeParent): void;
|
|
49
|
+
String?(node: StringNode, parent?: ValueNodeParent): void;
|
|
50
|
+
Null?(node: NullNode, parent?: ValueNodeParent): void;
|
|
51
|
+
Number?(node: NumberNode, parent?: ValueNodeParent): void;
|
|
52
|
+
Boolean?(node: BooleanNode, parent?: ValueNodeParent): void;
|
|
53
|
+
NaN?(node: NaNNode, parent?: ValueNodeParent): void;
|
|
54
|
+
Infinity?(node: InfinityNode, parent?: ValueNodeParent): void;
|
|
55
|
+
Identifier?(node: IdentifierNode, parent?: ValueNodeParent): void;
|
|
56
|
+
|
|
57
|
+
"Document:exit"?(node: DocumentNode): void;
|
|
58
|
+
"Member:exit"?(node: MemberNode, parent?: ObjectNode): void;
|
|
59
|
+
"Element:exit"?(node: ElementNode, parent?: ArrayNode): void;
|
|
60
|
+
"Object:exit"?(node: ObjectNode, parent?: ValueNodeParent): void;
|
|
61
|
+
"Array:exit"?(node: ArrayNode, parent?: ValueNodeParent): void;
|
|
62
|
+
"String:exit"?(node: StringNode, parent?: ValueNodeParent): void;
|
|
63
|
+
"Null:exit"?(node: NullNode, parent?: ValueNodeParent): void;
|
|
64
|
+
"Number:exit"?(node: NumberNode, parent?: ValueNodeParent): void;
|
|
65
|
+
"Boolean:exit"?(node: BooleanNode, parent?: ValueNodeParent): void;
|
|
66
|
+
"NaN:exit"?(node: NaNNode, parent?: ValueNodeParent): void;
|
|
67
|
+
"Infinity:exit"?(node: InfinityNode, parent?: ValueNodeParent): void;
|
|
68
|
+
"Identifier:exit"?(node: IdentifierNode, parent?: ValueNodeParent): void;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export type JSONRuleDefinitionTypeOptions = {
|
|
72
|
+
RuleOptions: unknown[];
|
|
73
|
+
MessageIds: string;
|
|
74
|
+
ExtRuleDocs: Record<string, unknown>;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
export type JSONRuleDefinition<
|
|
78
|
+
Options extends Partial<JSONRuleDefinitionTypeOptions> = {},
|
|
79
|
+
> = RuleDefinition<
|
|
80
|
+
// Language specific type options (non-configurable)
|
|
81
|
+
{
|
|
82
|
+
LangOptions: JSONLanguageOptions;
|
|
83
|
+
Code: JSONSourceCode;
|
|
84
|
+
Visitor: JSONRuleVisitor;
|
|
85
|
+
Node: AnyNode;
|
|
86
|
+
} & Required<
|
|
87
|
+
// Rule specific type options (custom)
|
|
88
|
+
Options &
|
|
89
|
+
// Rule specific type options (defaults)
|
|
90
|
+
Omit<JSONRuleDefinitionTypeOptions, keyof Options>
|
|
91
|
+
>
|
|
92
|
+
>;
|