@eslint/json 0.12.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.
@@ -14,10 +14,6 @@ export type NoEmptyKeysMessageIds = "emptyKey";
14
14
  export type NoEmptyKeysRuleDefinition = JSONRuleDefinition<{
15
15
  MessageIds: NoEmptyKeysMessageIds;
16
16
  }>;
17
- export type NoUnsafeValuesMessageIds = "unsafeNumber" | "unsafeInteger" | "unsafeZero" | "subnormal" | "loneSurrogate";
18
- export type NoUnsafeValuesRuleDefinition = JSONRuleDefinition<{
19
- MessageIds: NoUnsafeValuesMessageIds;
20
- }>;
21
17
  export type NoUnnormalizedKeysMessageIds = "unnormalizedKey";
22
18
  export type NoUnnormalizedKeysOptions = {
23
19
  form: string;
@@ -26,6 +22,10 @@ export type NoUnnormalizedKeysRuleDefinition = JSONRuleDefinition<{
26
22
  RuleOptions: [NoUnnormalizedKeysOptions];
27
23
  MessageIds: NoUnnormalizedKeysMessageIds;
28
24
  }>;
25
+ export type NoUnsafeValuesMessageIds = "unsafeNumber" | "unsafeInteger" | "unsafeZero" | "subnormal" | "loneSurrogate";
26
+ export type NoUnsafeValuesRuleDefinition = JSONRuleDefinition<{
27
+ MessageIds: NoUnsafeValuesMessageIds;
28
+ }>;
29
29
  export type SortOptions = {
30
30
  caseSensitive: boolean;
31
31
  natural: boolean;
@@ -45,7 +45,7 @@ export type TopLevelInteropRuleDefinition = JSONRuleDefinition<{
45
45
  MessageIds: TopLevelInteropMessageIds;
46
46
  }>;
47
47
  /**
48
- * @filedescription Functions to fix up rules to provide missing methods on the `context` object.
48
+ * @fileoverview The JSONLanguage class.
49
49
  * @author Nicholas C. Zakas
50
50
  */
51
51
  /**
@@ -121,9 +121,14 @@ export class JSONLanguage implements Language {
121
121
  }
122
122
  /**
123
123
  * JSON Source Code Object
124
- * @implements {TextSourceCode<{LangOptions: JSONLanguageOptions, RootNode: DocumentNode, SyntaxElementWithLoc: JSONSyntaxElement, ConfigNode: Token}>}
124
+ * @extends {TextSourceCodeBase<{LangOptions: JSONLanguageOptions, RootNode: DocumentNode, SyntaxElementWithLoc: JSONSyntaxElement, ConfigNode: Token}>}
125
125
  */
126
- export class JSONSourceCode extends TextSourceCodeBase implements TextSourceCode {
126
+ export class JSONSourceCode extends TextSourceCodeBase<{
127
+ LangOptions: JSONLanguageOptions;
128
+ RootNode: DocumentNode;
129
+ SyntaxElementWithLoc: JSONSyntaxElement;
130
+ ConfigNode: Token;
131
+ }> {
127
132
  /**
128
133
  * Creates a new instance.
129
134
  * @param {Object} options The options for the instance.
@@ -135,12 +140,7 @@ export class JSONSourceCode extends TextSourceCodeBase implements TextSourceCode
135
140
  ast: DocumentNode;
136
141
  });
137
142
  /**
138
- * The AST of the source code.
139
- * @type {DocumentNode}
140
- */
141
- ast: DocumentNode;
142
- /**
143
- * The comment node in the source code.
143
+ * The comment tokens in the source code.
144
144
  * @type {Array<Token>|undefined}
145
145
  */
146
146
  comments: Array<Token> | undefined;
@@ -177,45 +177,52 @@ export class JSONSourceCode extends TextSourceCodeBase implements TextSourceCode
177
177
  };
178
178
  /**
179
179
  * Returns the parent of the given node.
180
- * @param {Node} node The node to get the parent of.
181
- * @returns {Node|undefined} The parent of the node.
180
+ * @param {AnyNode} node The node to get the parent of.
181
+ * @returns {AnyNode|undefined} The parent of the node.
182
182
  */
183
- getParent(node: Node): Node | undefined;
183
+ getParent(node: AnyNode): AnyNode | undefined;
184
184
  /**
185
185
  * Traverse the source code and return the steps that were taken.
186
186
  * @returns {Iterable<JSONTraversalStep>} The steps that were taken while traversing the source code.
187
187
  */
188
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;
189
209
  #private;
190
210
  }
191
211
  declare namespace plugin {
192
- namespace meta {
212
+ export namespace meta {
193
213
  let name: string;
194
214
  let version: string;
195
215
  }
196
- namespace languages {
216
+ export namespace languages {
197
217
  let json: JSONLanguage;
198
218
  let jsonc: JSONLanguage;
199
219
  let json5: JSONLanguage;
200
220
  }
201
- let rules: {
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;
208
- };
209
- namespace configs {
221
+ export { rules };
222
+ export namespace configs {
210
223
  namespace recommended {
211
224
  export let plugins: {};
212
- let rules_1: {
213
- readonly "json/no-duplicate-keys": "error";
214
- readonly "json/no-empty-keys": "error";
215
- readonly "json/no-unsafe-values": "error";
216
- readonly "json/no-unnormalized-keys": "error";
217
- };
218
- export { rules_1 as rules };
225
+ export { rules$1 as rules };
219
226
  }
220
227
  }
221
228
  }
@@ -225,14 +232,14 @@ import type { ParseResult } from "@eslint/core";
225
232
  import type { JSONRuleDefinition } from "./types.cts";
226
233
  import type { Language } from "@eslint/core";
227
234
  import type { File } from "@eslint/core";
228
- import type { TextSourceCode } from "@eslint/core";
229
- import { TextSourceCodeBase } from '@eslint/plugin-kit';
235
+ import type { JSONSyntaxElement } from "./types.cts";
230
236
  import type { Token } from "@humanwhocodes/momoa";
237
+ import { TextSourceCodeBase } from '@eslint/plugin-kit';
231
238
  import type { FileProblem } from "@eslint/core";
232
239
  import { Directive } from '@eslint/plugin-kit';
233
240
  import type { RulesConfig } from "@eslint/core";
234
241
  import type { SourceLocation } from "@eslint/core";
235
- import type { Node } from "@humanwhocodes/momoa";
242
+ import type { AnyNode } from "@humanwhocodes/momoa";
236
243
  /**
237
244
  * A class to represent a step in the traversal process.
238
245
  */
@@ -240,20 +247,34 @@ declare class JSONTraversalStep extends VisitNodeStep {
240
247
  /**
241
248
  * Creates a new instance.
242
249
  * @param {Object} options The options for the step.
243
- * @param {Node} options.target The target of the step.
250
+ * @param {AnyNode} options.target The target of the step.
244
251
  * @param {1|2} options.phase The phase of the step.
245
252
  * @param {Array<any>} options.args The arguments of the step.
246
253
  */
247
254
  constructor({ target, phase, args }: {
248
- target: Node;
255
+ target: AnyNode;
249
256
  phase: 1 | 2;
250
257
  args: Array<any>;
251
258
  });
252
259
  /**
253
260
  * The target of the step.
254
- * @type {Node}
261
+ * @type {AnyNode}
255
262
  */
256
- target: Node;
263
+ target: AnyNode;
257
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
+ };
258
279
  import { VisitNodeStep } from '@eslint/plugin-kit';
259
280
  export { plugin as default };
@@ -14,10 +14,6 @@ export type NoEmptyKeysMessageIds = "emptyKey";
14
14
  export type NoEmptyKeysRuleDefinition = JSONRuleDefinition<{
15
15
  MessageIds: NoEmptyKeysMessageIds;
16
16
  }>;
17
- export type NoUnsafeValuesMessageIds = "unsafeNumber" | "unsafeInteger" | "unsafeZero" | "subnormal" | "loneSurrogate";
18
- export type NoUnsafeValuesRuleDefinition = JSONRuleDefinition<{
19
- MessageIds: NoUnsafeValuesMessageIds;
20
- }>;
21
17
  export type NoUnnormalizedKeysMessageIds = "unnormalizedKey";
22
18
  export type NoUnnormalizedKeysOptions = {
23
19
  form: string;
@@ -26,6 +22,10 @@ export type NoUnnormalizedKeysRuleDefinition = JSONRuleDefinition<{
26
22
  RuleOptions: [NoUnnormalizedKeysOptions];
27
23
  MessageIds: NoUnnormalizedKeysMessageIds;
28
24
  }>;
25
+ export type NoUnsafeValuesMessageIds = "unsafeNumber" | "unsafeInteger" | "unsafeZero" | "subnormal" | "loneSurrogate";
26
+ export type NoUnsafeValuesRuleDefinition = JSONRuleDefinition<{
27
+ MessageIds: NoUnsafeValuesMessageIds;
28
+ }>;
29
29
  export type SortOptions = {
30
30
  caseSensitive: boolean;
31
31
  natural: boolean;
@@ -45,7 +45,7 @@ export type TopLevelInteropRuleDefinition = JSONRuleDefinition<{
45
45
  MessageIds: TopLevelInteropMessageIds;
46
46
  }>;
47
47
  /**
48
- * @filedescription Functions to fix up rules to provide missing methods on the `context` object.
48
+ * @fileoverview The JSONLanguage class.
49
49
  * @author Nicholas C. Zakas
50
50
  */
51
51
  /**
@@ -121,9 +121,14 @@ export class JSONLanguage implements Language {
121
121
  }
122
122
  /**
123
123
  * JSON Source Code Object
124
- * @implements {TextSourceCode<{LangOptions: JSONLanguageOptions, RootNode: DocumentNode, SyntaxElementWithLoc: JSONSyntaxElement, ConfigNode: Token}>}
124
+ * @extends {TextSourceCodeBase<{LangOptions: JSONLanguageOptions, RootNode: DocumentNode, SyntaxElementWithLoc: JSONSyntaxElement, ConfigNode: Token}>}
125
125
  */
126
- export class JSONSourceCode extends TextSourceCodeBase implements TextSourceCode {
126
+ export class JSONSourceCode extends TextSourceCodeBase<{
127
+ LangOptions: JSONLanguageOptions;
128
+ RootNode: DocumentNode;
129
+ SyntaxElementWithLoc: JSONSyntaxElement;
130
+ ConfigNode: Token;
131
+ }> {
127
132
  /**
128
133
  * Creates a new instance.
129
134
  * @param {Object} options The options for the instance.
@@ -135,12 +140,7 @@ export class JSONSourceCode extends TextSourceCodeBase implements TextSourceCode
135
140
  ast: DocumentNode;
136
141
  });
137
142
  /**
138
- * The AST of the source code.
139
- * @type {DocumentNode}
140
- */
141
- ast: DocumentNode;
142
- /**
143
- * The comment node in the source code.
143
+ * The comment tokens in the source code.
144
144
  * @type {Array<Token>|undefined}
145
145
  */
146
146
  comments: Array<Token> | undefined;
@@ -177,45 +177,52 @@ export class JSONSourceCode extends TextSourceCodeBase implements TextSourceCode
177
177
  };
178
178
  /**
179
179
  * Returns the parent of the given node.
180
- * @param {Node} node The node to get the parent of.
181
- * @returns {Node|undefined} The parent of the node.
180
+ * @param {AnyNode} node The node to get the parent of.
181
+ * @returns {AnyNode|undefined} The parent of the node.
182
182
  */
183
- getParent(node: Node): Node | undefined;
183
+ getParent(node: AnyNode): AnyNode | undefined;
184
184
  /**
185
185
  * Traverse the source code and return the steps that were taken.
186
186
  * @returns {Iterable<JSONTraversalStep>} The steps that were taken while traversing the source code.
187
187
  */
188
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;
189
209
  #private;
190
210
  }
191
211
  declare namespace plugin {
192
- namespace meta {
212
+ export namespace meta {
193
213
  let name: string;
194
214
  let version: string;
195
215
  }
196
- namespace languages {
216
+ export namespace languages {
197
217
  let json: JSONLanguage;
198
218
  let jsonc: JSONLanguage;
199
219
  let json5: JSONLanguage;
200
220
  }
201
- let rules: {
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;
208
- };
209
- namespace configs {
221
+ export { rules };
222
+ export namespace configs {
210
223
  namespace recommended {
211
224
  export let plugins: {};
212
- let rules_1: {
213
- readonly "json/no-duplicate-keys": "error";
214
- readonly "json/no-empty-keys": "error";
215
- readonly "json/no-unsafe-values": "error";
216
- readonly "json/no-unnormalized-keys": "error";
217
- };
218
- export { rules_1 as rules };
225
+ export { rules$1 as rules };
219
226
  }
220
227
  }
221
228
  }
@@ -225,14 +232,14 @@ import type { ParseResult } from "@eslint/core";
225
232
  import type { JSONRuleDefinition } from "./types.ts";
226
233
  import type { Language } from "@eslint/core";
227
234
  import type { File } from "@eslint/core";
228
- import type { TextSourceCode } from "@eslint/core";
229
- import { TextSourceCodeBase } from '@eslint/plugin-kit';
235
+ import type { JSONSyntaxElement } from "./types.ts";
230
236
  import type { Token } from "@humanwhocodes/momoa";
237
+ import { TextSourceCodeBase } from '@eslint/plugin-kit';
231
238
  import type { FileProblem } from "@eslint/core";
232
239
  import { Directive } from '@eslint/plugin-kit';
233
240
  import type { RulesConfig } from "@eslint/core";
234
241
  import type { SourceLocation } from "@eslint/core";
235
- import type { Node } from "@humanwhocodes/momoa";
242
+ import type { AnyNode } from "@humanwhocodes/momoa";
236
243
  /**
237
244
  * A class to represent a step in the traversal process.
238
245
  */
@@ -240,20 +247,34 @@ declare class JSONTraversalStep extends VisitNodeStep {
240
247
  /**
241
248
  * Creates a new instance.
242
249
  * @param {Object} options The options for the step.
243
- * @param {Node} options.target The target of the step.
250
+ * @param {AnyNode} options.target The target of the step.
244
251
  * @param {1|2} options.phase The phase of the step.
245
252
  * @param {Array<any>} options.args The arguments of the step.
246
253
  */
247
254
  constructor({ target, phase, args }: {
248
- target: Node;
255
+ target: AnyNode;
249
256
  phase: 1 | 2;
250
257
  args: Array<any>;
251
258
  });
252
259
  /**
253
260
  * The target of the step.
254
- * @type {Node}
261
+ * @type {AnyNode}
255
262
  */
256
- target: Node;
263
+ target: AnyNode;
257
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
+ };
258
279
  import { VisitNodeStep } from '@eslint/plugin-kit';
259
280
  export { plugin as default };