@eslint/json 0.11.0 → 0.13.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 +72 -33
- package/dist/cjs/index.cjs +295 -139
- package/dist/cjs/index.d.cts +117 -77
- package/dist/cjs/types.cts +22 -68
- package/dist/esm/index.d.ts +117 -77
- package/dist/esm/index.js +295 -139
- package/dist/esm/types.d.ts +11 -49
- package/dist/esm/types.ts +22 -68
- package/package.json +23 -11
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,59 +1,66 @@
|
|
|
1
|
-
export type
|
|
2
|
-
export type
|
|
3
|
-
export type
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
export type FileProblem = import("@eslint/core").FileProblem;
|
|
10
|
-
export type DirectiveType = import("@eslint/core").DirectiveType;
|
|
11
|
-
export type RulesConfig = import("@eslint/core").RulesConfig;
|
|
12
|
-
export type IJSONSourceCode = import("./types.ts").IJSONSourceCode;
|
|
13
|
-
export type JSONSyntaxElement = import("./types.ts").JSONSyntaxElement;
|
|
14
|
-
export type Language = import("@eslint/core").Language;
|
|
15
|
-
export type OkParseResult = import("@eslint/core").OkParseResult<DocumentNode>;
|
|
16
|
-
export type ParseResult = import("@eslint/core").ParseResult<DocumentNode>;
|
|
17
|
-
export type IJSONLanguage = import("./types.ts").IJSONLanguage;
|
|
18
|
-
export type JSONLanguageOptions = import("./types.ts").JSONLanguageOptions;
|
|
1
|
+
export type JSONOkParseResult = OkParseResult<DocumentNode>;
|
|
2
|
+
export type JSONParseResult = ParseResult<DocumentNode>;
|
|
3
|
+
export type JSONLanguageOptions = {
|
|
4
|
+
/**
|
|
5
|
+
* Whether to allow trailing commas in JSONC mode.
|
|
6
|
+
*/
|
|
7
|
+
allowTrailingCommas?: boolean;
|
|
8
|
+
};
|
|
19
9
|
export type NoDuplicateKeysMessageIds = "duplicateKey";
|
|
20
|
-
export type NoDuplicateKeysRuleDefinition =
|
|
21
|
-
|
|
10
|
+
export type NoDuplicateKeysRuleDefinition = JSONRuleDefinition<{
|
|
11
|
+
MessageIds: NoDuplicateKeysMessageIds;
|
|
12
|
+
}>;
|
|
22
13
|
export type NoEmptyKeysMessageIds = "emptyKey";
|
|
23
|
-
export type NoEmptyKeysRuleDefinition =
|
|
24
|
-
|
|
25
|
-
|
|
14
|
+
export type NoEmptyKeysRuleDefinition = JSONRuleDefinition<{
|
|
15
|
+
MessageIds: NoEmptyKeysMessageIds;
|
|
16
|
+
}>;
|
|
26
17
|
export type NoUnnormalizedKeysMessageIds = "unnormalizedKey";
|
|
27
|
-
export type
|
|
18
|
+
export type NoUnnormalizedKeysOptions = {
|
|
28
19
|
form: string;
|
|
29
|
-
}
|
|
30
|
-
export type
|
|
20
|
+
};
|
|
21
|
+
export type NoUnnormalizedKeysRuleDefinition = JSONRuleDefinition<{
|
|
22
|
+
RuleOptions: [NoUnnormalizedKeysOptions];
|
|
23
|
+
MessageIds: NoUnnormalizedKeysMessageIds;
|
|
24
|
+
}>;
|
|
25
|
+
export type NoUnsafeValuesMessageIds = "unsafeNumber" | "unsafeInteger" | "unsafeZero" | "subnormal" | "loneSurrogate";
|
|
26
|
+
export type NoUnsafeValuesRuleDefinition = JSONRuleDefinition<{
|
|
27
|
+
MessageIds: NoUnsafeValuesMessageIds;
|
|
28
|
+
}>;
|
|
31
29
|
export type SortOptions = {
|
|
32
30
|
caseSensitive: boolean;
|
|
33
31
|
natural: boolean;
|
|
34
32
|
minKeys: number;
|
|
35
33
|
allowLineSeparatedGroups: boolean;
|
|
36
34
|
};
|
|
35
|
+
export type SortKeysMessageIds = "sortKeys";
|
|
37
36
|
export type SortDirection = "asc" | "desc";
|
|
38
37
|
export type SortKeysRuleOptions = [SortDirection, SortOptions];
|
|
39
|
-
export type SortKeysRuleDefinition =
|
|
38
|
+
export type SortKeysRuleDefinition = JSONRuleDefinition<{
|
|
39
|
+
RuleOptions: SortKeysRuleOptions;
|
|
40
|
+
MessageIds: SortKeysMessageIds;
|
|
41
|
+
}>;
|
|
40
42
|
export type Comparator = (a: string, b: string) => boolean;
|
|
41
43
|
export type TopLevelInteropMessageIds = "topLevel";
|
|
42
|
-
export type TopLevelInteropRuleDefinition =
|
|
44
|
+
export type TopLevelInteropRuleDefinition = JSONRuleDefinition<{
|
|
45
|
+
MessageIds: TopLevelInteropMessageIds;
|
|
46
|
+
}>;
|
|
43
47
|
/**
|
|
44
|
-
* @
|
|
48
|
+
* @fileoverview The JSONLanguage class.
|
|
45
49
|
* @author Nicholas C. Zakas
|
|
46
50
|
*/
|
|
47
|
-
/**
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
51
|
+
/**
|
|
52
|
+
*
|
|
53
|
+
* @typedef {OkParseResult<DocumentNode>} JSONOkParseResult
|
|
54
|
+
* @typedef {ParseResult<DocumentNode>} JSONParseResult
|
|
55
|
+
*
|
|
56
|
+
* @typedef {Object} JSONLanguageOptions
|
|
57
|
+
* @property {boolean} [allowTrailingCommas] Whether to allow trailing commas in JSONC mode.
|
|
58
|
+
*/
|
|
52
59
|
/**
|
|
53
60
|
* JSON Language Object
|
|
54
|
-
* @implements {
|
|
61
|
+
* @implements {Language<{ LangOptions: JSONLanguageOptions; Code: JSONSourceCode; RootNode: DocumentNode; Node: AnyNode }>}
|
|
55
62
|
*/
|
|
56
|
-
export class JSONLanguage implements
|
|
63
|
+
export class JSONLanguage implements Language {
|
|
57
64
|
/**
|
|
58
65
|
* Creates a new instance.
|
|
59
66
|
* @param {Object} options The options to use for this instance.
|
|
@@ -98,25 +105,30 @@ export class JSONLanguage implements IJSONLanguage {
|
|
|
98
105
|
* Parses the given file into an AST.
|
|
99
106
|
* @param {File} file The virtual file to parse.
|
|
100
107
|
* @param {{languageOptions: JSONLanguageOptions}} context The options to use for parsing.
|
|
101
|
-
* @returns {
|
|
108
|
+
* @returns {JSONParseResult} The result of parsing.
|
|
102
109
|
*/
|
|
103
110
|
parse(file: File, context: {
|
|
104
111
|
languageOptions: JSONLanguageOptions;
|
|
105
|
-
}):
|
|
112
|
+
}): JSONParseResult;
|
|
106
113
|
/**
|
|
107
114
|
* Creates a new `JSONSourceCode` object from the given information.
|
|
108
115
|
* @param {File} file The virtual file to create a `JSONSourceCode` object from.
|
|
109
|
-
* @param {
|
|
116
|
+
* @param {JSONOkParseResult} parseResult The result returned from `parse()`.
|
|
110
117
|
* @returns {JSONSourceCode} The new `JSONSourceCode` object.
|
|
111
118
|
*/
|
|
112
|
-
createSourceCode(file: File, parseResult:
|
|
119
|
+
createSourceCode(file: File, parseResult: JSONOkParseResult): JSONSourceCode;
|
|
113
120
|
#private;
|
|
114
121
|
}
|
|
115
122
|
/**
|
|
116
123
|
* JSON Source Code Object
|
|
117
|
-
* @
|
|
124
|
+
* @extends {TextSourceCodeBase<{LangOptions: JSONLanguageOptions, RootNode: DocumentNode, SyntaxElementWithLoc: JSONSyntaxElement, ConfigNode: Token}>}
|
|
118
125
|
*/
|
|
119
|
-
export class JSONSourceCode extends TextSourceCodeBase
|
|
126
|
+
export class JSONSourceCode extends TextSourceCodeBase<{
|
|
127
|
+
LangOptions: JSONLanguageOptions;
|
|
128
|
+
RootNode: DocumentNode;
|
|
129
|
+
SyntaxElementWithLoc: JSONSyntaxElement;
|
|
130
|
+
ConfigNode: Token;
|
|
131
|
+
}> {
|
|
120
132
|
/**
|
|
121
133
|
* Creates a new instance.
|
|
122
134
|
* @param {Object} options The options for the instance.
|
|
@@ -128,21 +140,16 @@ export class JSONSourceCode extends TextSourceCodeBase implements IJSONSourceCod
|
|
|
128
140
|
ast: DocumentNode;
|
|
129
141
|
});
|
|
130
142
|
/**
|
|
131
|
-
* The
|
|
132
|
-
* @type {
|
|
143
|
+
* The comment tokens in the source code.
|
|
144
|
+
* @type {Array<Token>|undefined}
|
|
133
145
|
*/
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* The comment node in the source code.
|
|
137
|
-
* @type {Array<JSONToken>|undefined}
|
|
138
|
-
*/
|
|
139
|
-
comments: Array<JSONToken> | undefined;
|
|
146
|
+
comments: Array<Token> | undefined;
|
|
140
147
|
/**
|
|
141
148
|
* Returns an array of all inline configuration nodes found in the
|
|
142
149
|
* source code.
|
|
143
|
-
* @returns {Array<
|
|
150
|
+
* @returns {Array<Token>} An array of all inline configuration nodes.
|
|
144
151
|
*/
|
|
145
|
-
getInlineConfigNodes(): Array<
|
|
152
|
+
getInlineConfigNodes(): Array<Token>;
|
|
146
153
|
/**
|
|
147
154
|
* Returns directives that enable or disable rules along with any problems
|
|
148
155
|
* encountered while parsing the directives.
|
|
@@ -170,50 +177,69 @@ export class JSONSourceCode extends TextSourceCodeBase implements IJSONSourceCod
|
|
|
170
177
|
};
|
|
171
178
|
/**
|
|
172
179
|
* Returns the parent of the given node.
|
|
173
|
-
* @param {
|
|
174
|
-
* @returns {
|
|
180
|
+
* @param {AnyNode} node The node to get the parent of.
|
|
181
|
+
* @returns {AnyNode|undefined} The parent of the node.
|
|
175
182
|
*/
|
|
176
|
-
getParent(node:
|
|
183
|
+
getParent(node: AnyNode): AnyNode | undefined;
|
|
177
184
|
/**
|
|
178
185
|
* Traverse the source code and return the steps that were taken.
|
|
179
186
|
* @returns {Iterable<JSONTraversalStep>} The steps that were taken while traversing the source code.
|
|
180
187
|
*/
|
|
181
188
|
traverse(): Iterable<JSONTraversalStep>;
|
|
189
|
+
/**
|
|
190
|
+
* Gets the token before the given node or token, optionally including comments.
|
|
191
|
+
* @param {AnyNode|Token} nodeOrToken The node or token to get the previous token for.
|
|
192
|
+
* @param {Object} [options] Options object.
|
|
193
|
+
* @param {boolean} [options.includeComments] If true, return comments when they are present.
|
|
194
|
+
* @returns {Token|null} The previous token or comment, or null if there is none.
|
|
195
|
+
*/
|
|
196
|
+
getTokenBefore(nodeOrToken: AnyNode | Token, { includeComments }?: {
|
|
197
|
+
includeComments?: boolean;
|
|
198
|
+
}): Token | null;
|
|
199
|
+
/**
|
|
200
|
+
* Gets the token after the given node or token, skipping any comments unless includeComments is true.
|
|
201
|
+
* @param {AnyNode|Token} nodeOrToken The node or token to get the next token for.
|
|
202
|
+
* @param {Object} [options] Options object.
|
|
203
|
+
* @param {boolean} [options.includeComments=false] If true, return comments when they are present.
|
|
204
|
+
* @returns {Token|null} The next token or comment, or null if there is none.
|
|
205
|
+
*/
|
|
206
|
+
getTokenAfter(nodeOrToken: AnyNode | Token, { includeComments }?: {
|
|
207
|
+
includeComments?: boolean;
|
|
208
|
+
}): Token | null;
|
|
182
209
|
#private;
|
|
183
210
|
}
|
|
184
211
|
declare namespace plugin {
|
|
185
|
-
namespace meta {
|
|
212
|
+
export namespace meta {
|
|
186
213
|
let name: string;
|
|
187
214
|
let version: string;
|
|
188
215
|
}
|
|
189
|
-
namespace languages {
|
|
216
|
+
export namespace languages {
|
|
190
217
|
let json: JSONLanguage;
|
|
191
218
|
let jsonc: JSONLanguage;
|
|
192
219
|
let json5: JSONLanguage;
|
|
193
220
|
}
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
"no-empty-keys": NoEmptyKeysRuleDefinition;
|
|
197
|
-
"no-unsafe-values": NoUnsafeValuesRuleDefinition;
|
|
198
|
-
"no-unnormalized-keys": NoUnnormalizedKeysRuleDefinition;
|
|
199
|
-
"sort-keys": SortKeysRuleDefinition;
|
|
200
|
-
"top-level-interop": TopLevelInteropRuleDefinition;
|
|
201
|
-
};
|
|
202
|
-
namespace configs {
|
|
221
|
+
export { rules };
|
|
222
|
+
export namespace configs {
|
|
203
223
|
namespace recommended {
|
|
204
224
|
export let plugins: {};
|
|
205
|
-
|
|
206
|
-
readonly "json/no-duplicate-keys": "error";
|
|
207
|
-
readonly "json/no-empty-keys": "error";
|
|
208
|
-
readonly "json/no-unsafe-values": "error";
|
|
209
|
-
readonly "json/no-unnormalized-keys": "error";
|
|
210
|
-
};
|
|
211
|
-
export { rules_1 as rules };
|
|
225
|
+
export { rules$1 as rules };
|
|
212
226
|
}
|
|
213
227
|
}
|
|
214
228
|
}
|
|
229
|
+
import type { DocumentNode } from "@humanwhocodes/momoa";
|
|
230
|
+
import type { OkParseResult } from "@eslint/core";
|
|
231
|
+
import type { ParseResult } from "@eslint/core";
|
|
232
|
+
import type { JSONRuleDefinition } from "./types.ts";
|
|
233
|
+
import type { Language } from "@eslint/core";
|
|
234
|
+
import type { File } from "@eslint/core";
|
|
235
|
+
import type { JSONSyntaxElement } from "./types.ts";
|
|
236
|
+
import type { Token } from "@humanwhocodes/momoa";
|
|
215
237
|
import { TextSourceCodeBase } from '@eslint/plugin-kit';
|
|
238
|
+
import type { FileProblem } from "@eslint/core";
|
|
216
239
|
import { Directive } from '@eslint/plugin-kit';
|
|
240
|
+
import type { RulesConfig } from "@eslint/core";
|
|
241
|
+
import type { SourceLocation } from "@eslint/core";
|
|
242
|
+
import type { AnyNode } from "@humanwhocodes/momoa";
|
|
217
243
|
/**
|
|
218
244
|
* A class to represent a step in the traversal process.
|
|
219
245
|
*/
|
|
@@ -221,20 +247,34 @@ declare class JSONTraversalStep extends VisitNodeStep {
|
|
|
221
247
|
/**
|
|
222
248
|
* Creates a new instance.
|
|
223
249
|
* @param {Object} options The options for the step.
|
|
224
|
-
* @param {
|
|
250
|
+
* @param {AnyNode} options.target The target of the step.
|
|
225
251
|
* @param {1|2} options.phase The phase of the step.
|
|
226
252
|
* @param {Array<any>} options.args The arguments of the step.
|
|
227
253
|
*/
|
|
228
254
|
constructor({ target, phase, args }: {
|
|
229
|
-
target:
|
|
255
|
+
target: AnyNode;
|
|
230
256
|
phase: 1 | 2;
|
|
231
257
|
args: Array<any>;
|
|
232
258
|
});
|
|
233
259
|
/**
|
|
234
260
|
* The target of the step.
|
|
235
|
-
* @type {
|
|
261
|
+
* @type {AnyNode}
|
|
236
262
|
*/
|
|
237
|
-
target:
|
|
263
|
+
target: AnyNode;
|
|
238
264
|
}
|
|
265
|
+
declare var rules: {
|
|
266
|
+
"no-duplicate-keys": NoDuplicateKeysRuleDefinition;
|
|
267
|
+
"no-empty-keys": NoEmptyKeysRuleDefinition;
|
|
268
|
+
"no-unnormalized-keys": NoUnnormalizedKeysRuleDefinition;
|
|
269
|
+
"no-unsafe-values": NoUnsafeValuesRuleDefinition;
|
|
270
|
+
"sort-keys": SortKeysRuleDefinition;
|
|
271
|
+
"top-level-interop": TopLevelInteropRuleDefinition;
|
|
272
|
+
};
|
|
273
|
+
declare const rules$1: {
|
|
274
|
+
readonly "json/no-duplicate-keys": "error";
|
|
275
|
+
readonly "json/no-empty-keys": "error";
|
|
276
|
+
readonly "json/no-unnormalized-keys": "error";
|
|
277
|
+
readonly "json/no-unsafe-values": "error";
|
|
278
|
+
};
|
|
239
279
|
import { VisitNodeStep } from '@eslint/plugin-kit';
|
|
240
280
|
export { plugin as default };
|