@eslint/json 0.9.1 → 0.11.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.
@@ -5,20 +5,41 @@ export type SourceRange = import("@eslint/core").SourceRange;
5
5
  export type SourceLocation = import("@eslint/core").SourceLocation;
6
6
  export type File = import("@eslint/core").File;
7
7
  export type TraversalStep = import("@eslint/core").TraversalStep;
8
- export type TextSourceCode = import("@eslint/core").TextSourceCode;
9
8
  export type VisitTraversalStep = import("@eslint/core").VisitTraversalStep;
10
9
  export type FileProblem = import("@eslint/core").FileProblem;
11
10
  export type DirectiveType = import("@eslint/core").DirectiveType;
12
11
  export type RulesConfig = import("@eslint/core").RulesConfig;
12
+ export type IJSONSourceCode = import("./types.cts").IJSONSourceCode;
13
+ export type JSONSyntaxElement = import("./types.cts").JSONSyntaxElement;
13
14
  export type Language = import("@eslint/core").Language;
14
15
  export type OkParseResult = import("@eslint/core").OkParseResult<DocumentNode>;
15
16
  export type ParseResult = import("@eslint/core").ParseResult<DocumentNode>;
16
- export type JSONLanguageOptions = {
17
- /**
18
- * Whether to allow trailing commas.
19
- */
20
- allowTrailingCommas?: boolean;
17
+ export type IJSONLanguage = import("./types.cts").IJSONLanguage;
18
+ export type JSONLanguageOptions = import("./types.cts").JSONLanguageOptions;
19
+ export type NoDuplicateKeysMessageIds = "duplicateKey";
20
+ export type NoDuplicateKeysRuleDefinition = import("./types.cts").JSONRuleDefinition<[], NoDuplicateKeysMessageIds>;
21
+ export type MemberNode = import("@humanwhocodes/momoa").MemberNode;
22
+ export type NoEmptyKeysMessageIds = "emptyKey";
23
+ export type NoEmptyKeysRuleDefinition = import("./types.cts").JSONRuleDefinition<[], NoEmptyKeysMessageIds>;
24
+ export type NoUnsafeValuesMessageIds = "unsafeNumber" | "unsafeInteger" | "unsafeZero" | "subnormal" | "loneSurrogate";
25
+ export type NoUnsafeValuesRuleDefinition = import("./types.cts").JSONRuleDefinition<[], NoUnsafeValuesMessageIds>;
26
+ export type NoUnnormalizedKeysMessageIds = "unnormalizedKey";
27
+ export type NoUnnormalizedKeysRuleDefinition = import("./types.cts").JSONRuleDefinition<[{
28
+ form: string;
29
+ }], NoUnnormalizedKeysMessageIds>;
30
+ export type SortKeysMessageIds = "sortKeys";
31
+ export type SortOptions = {
32
+ caseSensitive: boolean;
33
+ natural: boolean;
34
+ minKeys: number;
35
+ allowLineSeparatedGroups: boolean;
21
36
  };
37
+ export type SortDirection = "asc" | "desc";
38
+ export type SortKeysRuleOptions = [SortDirection, SortOptions];
39
+ export type SortKeysRuleDefinition = import("./types.cts").JSONRuleDefinition<SortKeysRuleOptions, SortKeysMessageIds>;
40
+ export type Comparator = (a: string, b: string) => boolean;
41
+ export type TopLevelInteropMessageIds = "topLevel";
42
+ export type TopLevelInteropRuleDefinition = import("./types.cts").JSONRuleDefinition<[], TopLevelInteropMessageIds>;
22
43
  /**
23
44
  * @filedescription Functions to fix up rules to provide missing methods on the `context` object.
24
45
  * @author Nicholas C. Zakas
@@ -26,15 +47,13 @@ export type JSONLanguageOptions = {
26
47
  /** @typedef {import("@eslint/core").Language} Language */
27
48
  /** @typedef {import("@eslint/core").OkParseResult<DocumentNode>} OkParseResult */
28
49
  /** @typedef {import("@eslint/core").ParseResult<DocumentNode>} ParseResult */
29
- /**
30
- * @typedef {Object} JSONLanguageOptions
31
- * @property {boolean} [allowTrailingCommas] Whether to allow trailing commas.
32
- */
50
+ /** @typedef {import("./types.cts").IJSONLanguage} IJSONLanguage */
51
+ /** @typedef {import("./types.cts").JSONLanguageOptions} JSONLanguageOptions */
33
52
  /**
34
53
  * JSON Language Object
35
- * @implements {Language}
54
+ * @implements {IJSONLanguage}
36
55
  */
37
- export class JSONLanguage implements Language {
56
+ export class JSONLanguage implements IJSONLanguage {
38
57
  /**
39
58
  * Creates a new instance.
40
59
  * @param {Object} options The options to use for this instance.
@@ -95,8 +114,9 @@ export class JSONLanguage implements Language {
95
114
  }
96
115
  /**
97
116
  * JSON Source Code Object
117
+ * @implements {IJSONSourceCode}
98
118
  */
99
- export class JSONSourceCode extends TextSourceCodeBase {
119
+ export class JSONSourceCode extends TextSourceCodeBase implements IJSONSourceCode {
100
120
  /**
101
121
  * Creates a new instance.
102
122
  * @param {Object} options The options for the instance.
@@ -172,92 +192,12 @@ declare namespace plugin {
172
192
  let json5: JSONLanguage;
173
193
  }
174
194
  let rules: {
175
- "no-duplicate-keys": {
176
- meta: {
177
- type: "problem";
178
- docs: {
179
- description: string;
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
- "top-level-interop": {
248
- meta: {
249
- type: "problem";
250
- docs: {
251
- description: string;
252
- };
253
- messages: {
254
- topLevel: string;
255
- };
256
- };
257
- create(context: any): {
258
- Document(node: any): void;
259
- };
260
- };
195
+ "no-duplicate-keys": NoDuplicateKeysRuleDefinition;
196
+ "no-empty-keys": NoEmptyKeysRuleDefinition;
197
+ "no-unsafe-values": NoUnsafeValuesRuleDefinition;
198
+ "no-unnormalized-keys": NoUnnormalizedKeysRuleDefinition;
199
+ "sort-keys": SortKeysRuleDefinition;
200
+ "top-level-interop": TopLevelInteropRuleDefinition;
261
201
  };
262
202
  namespace configs {
263
203
  namespace recommended {
@@ -0,0 +1,138 @@
1
+ /**
2
+ * @fileoverview Additional types for this package.
3
+ * @author Nicholas C. Zakas
4
+ */
5
+
6
+ //------------------------------------------------------------------------------
7
+ // Imports
8
+ //------------------------------------------------------------------------------
9
+
10
+ import type {
11
+ RuleVisitor,
12
+ TextSourceCode,
13
+ Language,
14
+ LanguageOptions,
15
+ RuleDefinition,
16
+ } from "@eslint/core";
17
+ import {
18
+ DocumentNode,
19
+ MemberNode,
20
+ ElementNode,
21
+ ObjectNode,
22
+ ArrayNode,
23
+ StringNode,
24
+ NullNode,
25
+ NumberNode,
26
+ BooleanNode,
27
+ NaNNode,
28
+ InfinityNode,
29
+ IdentifierNode,
30
+ AnyNode,
31
+ Token,
32
+ } from "@humanwhocodes/momoa";
33
+
34
+ //------------------------------------------------------------------------------
35
+ // Types
36
+ //------------------------------------------------------------------------------
37
+
38
+ type ValueNodeParent = DocumentNode | MemberNode | ElementNode;
39
+
40
+ /**
41
+ * A JSON syntax element, including nodes and tokens.
42
+ */
43
+ export type JSONSyntaxElement = Token | AnyNode;
44
+
45
+ /**
46
+ * Language options provided for JSON files.
47
+ */
48
+ export interface JSONLanguageOptions extends LanguageOptions {
49
+ /**
50
+ * Whether to allow trailing commas. Only valid in JSONC.
51
+ */
52
+ allowTrailingCommas?: boolean;
53
+ }
54
+
55
+ /**
56
+ * The visitor format returned from rules in this package.
57
+ */
58
+ export interface JSONRuleVisitor extends RuleVisitor {
59
+ Document?(node: DocumentNode): void;
60
+ Member?(node: MemberNode, parent?: ObjectNode): void;
61
+ Element?(node: ElementNode, parent?: ArrayNode): void;
62
+ Object?(node: ObjectNode, parent?: ValueNodeParent): void;
63
+ Array?(node: ArrayNode, parent?: ValueNodeParent): void;
64
+ String?(node: StringNode, parent?: ValueNodeParent): void;
65
+ Null?(node: NullNode, parent?: ValueNodeParent): void;
66
+ Number?(node: NumberNode, parent?: ValueNodeParent): void;
67
+ Boolean?(node: BooleanNode, parent?: ValueNodeParent): void;
68
+ NaN?(node: NaNNode, parent?: ValueNodeParent): void;
69
+ Infinity?(node: InfinityNode, parent?: ValueNodeParent): void;
70
+ Identifier?(node: IdentifierNode, parent?: ValueNodeParent): void;
71
+
72
+ "Document:exit"?(node: DocumentNode): void;
73
+ "Member:exit"?(node: MemberNode, parent?: ObjectNode): void;
74
+ "Element:exit"?(node: ElementNode, parent?: ArrayNode): void;
75
+ "Object:exit"?(node: ObjectNode, parent?: ValueNodeParent): void;
76
+ "Array:exit"?(node: ArrayNode, parent?: ValueNodeParent): void;
77
+ "String:exit"?(node: StringNode, parent?: ValueNodeParent): void;
78
+ "Null:exit"?(node: NullNode, parent?: ValueNodeParent): void;
79
+ "Number:exit"?(node: NumberNode, parent?: ValueNodeParent): void;
80
+ "Boolean:exit"?(node: BooleanNode, parent?: ValueNodeParent): void;
81
+ "NaN:exit"?(node: NaNNode, parent?: ValueNodeParent): void;
82
+ "Infinity:exit"?(node: InfinityNode, parent?: ValueNodeParent): void;
83
+ "Identifier:exit"?(node: IdentifierNode, parent?: ValueNodeParent): void;
84
+ }
85
+
86
+ /**
87
+ * The `SourceCode` implementation for JSON files.
88
+ */
89
+ export interface IJSONSourceCode
90
+ extends TextSourceCode<{
91
+ LangOptions: JSONLanguageOptions;
92
+ RootNode: DocumentNode;
93
+ SyntaxElementWithLoc: JSONSyntaxElement;
94
+ ConfigNode: Token;
95
+ }> {
96
+ /**
97
+ * Get the text of a syntax element.
98
+ * @param syntaxElement The syntax element to get the text of.
99
+ * @param beforeCount The number of characters to include before the syntax element.
100
+ * @param afterCount The number of characters to include after the syntax element.
101
+ * @returns The text of the syntax element.
102
+ */
103
+ getText(
104
+ syntaxElement: JSONSyntaxElement,
105
+ beforeCount?: number,
106
+ afterCount?: number,
107
+ ): string;
108
+
109
+ /**
110
+ * Any comments found in a JSONC or JSON5 file.
111
+ */
112
+ comments: Array<Token> | undefined;
113
+
114
+ /**
115
+ * The lines of text found in the file.
116
+ */
117
+ lines: Array<string>;
118
+ }
119
+
120
+ export type IJSONLanguage = Language<{
121
+ LangOptions: JSONLanguageOptions;
122
+ Code: IJSONSourceCode;
123
+ RootNode: DocumentNode;
124
+ Node: AnyNode;
125
+ }>;
126
+
127
+ export type JSONRuleDefinition<
128
+ JSONRuleOptions extends unknown[],
129
+ JSONRuleMessageIds extends string = "",
130
+ > = RuleDefinition<{
131
+ LangOptions: JSONLanguageOptions;
132
+ Code: IJSONSourceCode;
133
+ RuleOptions: JSONRuleOptions;
134
+ Visitor: JSONRuleVisitor;
135
+ Node: AnyNode;
136
+ MessageIds: JSONRuleMessageIds;
137
+ ExtRuleDocs: {};
138
+ }>;
@@ -5,20 +5,41 @@ export type SourceRange = import("@eslint/core").SourceRange;
5
5
  export type SourceLocation = import("@eslint/core").SourceLocation;
6
6
  export type File = import("@eslint/core").File;
7
7
  export type TraversalStep = import("@eslint/core").TraversalStep;
8
- export type TextSourceCode = import("@eslint/core").TextSourceCode;
9
8
  export type VisitTraversalStep = import("@eslint/core").VisitTraversalStep;
10
9
  export type FileProblem = import("@eslint/core").FileProblem;
11
10
  export type DirectiveType = import("@eslint/core").DirectiveType;
12
11
  export type RulesConfig = import("@eslint/core").RulesConfig;
12
+ export type IJSONSourceCode = import("./types.ts").IJSONSourceCode;
13
+ export type JSONSyntaxElement = import("./types.ts").JSONSyntaxElement;
13
14
  export type Language = import("@eslint/core").Language;
14
15
  export type OkParseResult = import("@eslint/core").OkParseResult<DocumentNode>;
15
16
  export type ParseResult = import("@eslint/core").ParseResult<DocumentNode>;
16
- export type JSONLanguageOptions = {
17
- /**
18
- * Whether to allow trailing commas.
19
- */
20
- allowTrailingCommas?: boolean;
17
+ export type IJSONLanguage = import("./types.ts").IJSONLanguage;
18
+ export type JSONLanguageOptions = import("./types.ts").JSONLanguageOptions;
19
+ export type NoDuplicateKeysMessageIds = "duplicateKey";
20
+ export type NoDuplicateKeysRuleDefinition = import("./types.ts").JSONRuleDefinition<[], NoDuplicateKeysMessageIds>;
21
+ export type MemberNode = import("@humanwhocodes/momoa").MemberNode;
22
+ export type NoEmptyKeysMessageIds = "emptyKey";
23
+ export type NoEmptyKeysRuleDefinition = import("./types.ts").JSONRuleDefinition<[], NoEmptyKeysMessageIds>;
24
+ export type NoUnsafeValuesMessageIds = "unsafeNumber" | "unsafeInteger" | "unsafeZero" | "subnormal" | "loneSurrogate";
25
+ export type NoUnsafeValuesRuleDefinition = import("./types.ts").JSONRuleDefinition<[], NoUnsafeValuesMessageIds>;
26
+ export type NoUnnormalizedKeysMessageIds = "unnormalizedKey";
27
+ export type NoUnnormalizedKeysRuleDefinition = import("./types.ts").JSONRuleDefinition<[{
28
+ form: string;
29
+ }], NoUnnormalizedKeysMessageIds>;
30
+ export type SortKeysMessageIds = "sortKeys";
31
+ export type SortOptions = {
32
+ caseSensitive: boolean;
33
+ natural: boolean;
34
+ minKeys: number;
35
+ allowLineSeparatedGroups: boolean;
21
36
  };
37
+ export type SortDirection = "asc" | "desc";
38
+ export type SortKeysRuleOptions = [SortDirection, SortOptions];
39
+ export type SortKeysRuleDefinition = import("./types.ts").JSONRuleDefinition<SortKeysRuleOptions, SortKeysMessageIds>;
40
+ export type Comparator = (a: string, b: string) => boolean;
41
+ export type TopLevelInteropMessageIds = "topLevel";
42
+ export type TopLevelInteropRuleDefinition = import("./types.ts").JSONRuleDefinition<[], TopLevelInteropMessageIds>;
22
43
  /**
23
44
  * @filedescription Functions to fix up rules to provide missing methods on the `context` object.
24
45
  * @author Nicholas C. Zakas
@@ -26,15 +47,13 @@ export type JSONLanguageOptions = {
26
47
  /** @typedef {import("@eslint/core").Language} Language */
27
48
  /** @typedef {import("@eslint/core").OkParseResult<DocumentNode>} OkParseResult */
28
49
  /** @typedef {import("@eslint/core").ParseResult<DocumentNode>} ParseResult */
29
- /**
30
- * @typedef {Object} JSONLanguageOptions
31
- * @property {boolean} [allowTrailingCommas] Whether to allow trailing commas.
32
- */
50
+ /** @typedef {import("./types.ts").IJSONLanguage} IJSONLanguage */
51
+ /** @typedef {import("./types.ts").JSONLanguageOptions} JSONLanguageOptions */
33
52
  /**
34
53
  * JSON Language Object
35
- * @implements {Language}
54
+ * @implements {IJSONLanguage}
36
55
  */
37
- export class JSONLanguage implements Language {
56
+ export class JSONLanguage implements IJSONLanguage {
38
57
  /**
39
58
  * Creates a new instance.
40
59
  * @param {Object} options The options to use for this instance.
@@ -95,8 +114,9 @@ export class JSONLanguage implements Language {
95
114
  }
96
115
  /**
97
116
  * JSON Source Code Object
117
+ * @implements {IJSONSourceCode}
98
118
  */
99
- export class JSONSourceCode extends TextSourceCodeBase {
119
+ export class JSONSourceCode extends TextSourceCodeBase implements IJSONSourceCode {
100
120
  /**
101
121
  * Creates a new instance.
102
122
  * @param {Object} options The options for the instance.
@@ -172,92 +192,12 @@ declare namespace plugin {
172
192
  let json5: JSONLanguage;
173
193
  }
174
194
  let rules: {
175
- "no-duplicate-keys": {
176
- meta: {
177
- type: "problem";
178
- docs: {
179
- description: string;
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
- "top-level-interop": {
248
- meta: {
249
- type: "problem";
250
- docs: {
251
- description: string;
252
- };
253
- messages: {
254
- topLevel: string;
255
- };
256
- };
257
- create(context: any): {
258
- Document(node: any): void;
259
- };
260
- };
195
+ "no-duplicate-keys": NoDuplicateKeysRuleDefinition;
196
+ "no-empty-keys": NoEmptyKeysRuleDefinition;
197
+ "no-unsafe-values": NoUnsafeValuesRuleDefinition;
198
+ "no-unnormalized-keys": NoUnnormalizedKeysRuleDefinition;
199
+ "sort-keys": SortKeysRuleDefinition;
200
+ "top-level-interop": TopLevelInteropRuleDefinition;
261
201
  };
262
202
  namespace configs {
263
203
  namespace recommended {