@eslint/json 0.11.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 CHANGED
@@ -254,10 +254,11 @@ Apache 2.0
254
254
  The following companies, organizations, and individuals support ESLint's ongoing maintenance and development. [Become a Sponsor](https://eslint.org/donate)
255
255
  to get your logo on our READMEs and [website](https://eslint.org/sponsors).
256
256
 
257
- <h3>Platinum Sponsors</h3>
257
+ <h3>Diamond Sponsors</h3>
258
+ <p><a href="https://www.ag-grid.com/"><img src="https://images.opencollective.com/ag-grid/2c8d545/logo.png" alt="AG Grid" height="128"></a></p><h3>Platinum Sponsors</h3>
258
259
  <p><a href="https://automattic.com"><img src="https://images.opencollective.com/automattic/d0ef3e1/logo.png" alt="Automattic" height="128"></a> <a href="https://www.airbnb.com/"><img src="https://images.opencollective.com/airbnb/d327d66/logo.png" alt="Airbnb" height="128"></a></p><h3>Gold Sponsors</h3>
259
260
  <p><a href="https://qlty.sh/"><img src="https://images.opencollective.com/qltysh/33d157d/logo.png" alt="Qlty Software" height="96"></a> <a href="https://trunk.io/"><img src="https://images.opencollective.com/trunkio/fb92d60/avatar.png" alt="trunk.io" height="96"></a> <a href="https://shopify.engineering/"><img src="https://avatars.githubusercontent.com/u/8085" alt="Shopify" height="96"></a></p><h3>Silver Sponsors</h3>
260
- <p><a href="https://vite.dev/"><img src="https://images.opencollective.com/vite/e6d15e1/logo.png" alt="Vite" height="64"></a> <a href="https://www.jetbrains.com/"><img src="https://images.opencollective.com/jetbrains/fe76f99/logo.png" alt="JetBrains" height="64"></a> <a href="https://liftoff.io/"><img src="https://images.opencollective.com/liftoff/5c4fa84/logo.png" alt="Liftoff" height="64"></a> <a href="https://stackblitz.com"><img src="https://avatars.githubusercontent.com/u/28635252" alt="StackBlitz" height="64"></a></p><h3>Bronze Sponsors</h3>
261
+ <p><a href="https://vite.dev/"><img src="https://images.opencollective.com/vite/e6d15e1/logo.png" alt="Vite" height="64"></a> <a href="https://liftoff.io/"><img src="https://images.opencollective.com/liftoff/5c4fa84/logo.png" alt="Liftoff" height="64"></a> <a href="https://americanexpress.io"><img src="https://avatars.githubusercontent.com/u/3853301" alt="American Express" height="64"></a> <a href="https://stackblitz.com"><img src="https://avatars.githubusercontent.com/u/28635252" alt="StackBlitz" height="64"></a></p><h3>Bronze Sponsors</h3>
261
262
  <p><a href="https://cybozu.co.jp/"><img src="https://images.opencollective.com/cybozu/933e46d/logo.png" alt="Cybozu" height="32"></a> <a href="https://www.crosswordsolver.org/anagram-solver/"><img src="https://images.opencollective.com/anagram-solver/2666271/logo.png" alt="Anagram Solver" height="32"></a> <a href="https://icons8.com/"><img src="https://images.opencollective.com/icons8/7fa1641/logo.png" alt="Icons8" height="32"></a> <a href="https://discord.com"><img src="https://images.opencollective.com/discordapp/f9645d9/logo.png" alt="Discord" height="32"></a> <a href="https://www.gitbook.com"><img src="https://avatars.githubusercontent.com/u/7111340" alt="GitBook" height="32"></a> <a href="https://nolebase.ayaka.io"><img src="https://avatars.githubusercontent.com/u/11081491" alt="Neko" height="32"></a> <a href="https://nx.dev"><img src="https://avatars.githubusercontent.com/u/23692104" alt="Nx" height="32"></a> <a href="https://opensource.mercedes-benz.com/"><img src="https://avatars.githubusercontent.com/u/34240465" alt="Mercedes-Benz Group" height="32"></a> <a href="https://herocoders.com"><img src="https://avatars.githubusercontent.com/u/37549774" alt="HeroCoders" height="32"></a> <a href="https://www.lambdatest.com"><img src="https://avatars.githubusercontent.com/u/171592363" alt="LambdaTest" height="32"></a></p>
262
263
  <h3>Technology Sponsors</h3>
263
264
  Technology sponsors allow us to use their products and services for free as part of a contribution to the open source ecosystem and our work.
@@ -1,3 +1,9 @@
1
+
2
+ /**
3
+ * @import { DocumentNode, Node, Token, AnyNode, MemberNode } from "@humanwhocodes/momoa"
4
+ * @import { SourceLocation, FileProblem, DirectiveType, RulesConfig, TextSourceCode, Language, OkParseResult, ParseResult, File } from "@eslint/core"
5
+ * @import { JSONSyntaxElement, JSONRuleDefinition } from "./types.ts"
6
+ */
1
7
  'use strict';
2
8
 
3
9
  Object.defineProperty(exports, '__esModule', { value: true });
@@ -16,19 +22,8 @@ var naturalCompare = require('natural-compare');
16
22
  // Types
17
23
  //-----------------------------------------------------------------------------
18
24
 
19
- /** @typedef {import("@humanwhocodes/momoa").DocumentNode} DocumentNode */
20
- /** @typedef {import("@humanwhocodes/momoa").Node} JSONNode */
21
- /** @typedef {import("@humanwhocodes/momoa").Token} JSONToken */
22
- /** @typedef {import("@eslint/core").SourceRange} SourceRange */
23
- /** @typedef {import("@eslint/core").SourceLocation} SourceLocation */
24
- /** @typedef {import("@eslint/core").File} File */
25
- /** @typedef {import("@eslint/core").TraversalStep} TraversalStep */
26
- /** @typedef {import("@eslint/core").VisitTraversalStep} VisitTraversalStep */
27
- /** @typedef {import("@eslint/core").FileProblem} FileProblem */
28
- /** @typedef {import("@eslint/core").DirectiveType} DirectiveType */
29
- /** @typedef {import("@eslint/core").RulesConfig} RulesConfig */
30
- /** @typedef {import("./types.ts").IJSONSourceCode} IJSONSourceCode */
31
- /** @typedef {import("./types.ts").JSONSyntaxElement} JSONSyntaxElement */
25
+ /**
26
+ */
32
27
 
33
28
  //-----------------------------------------------------------------------------
34
29
  // Helpers
@@ -45,14 +40,14 @@ const INLINE_CONFIG =
45
40
  class JSONTraversalStep extends pluginKit.VisitNodeStep {
46
41
  /**
47
42
  * The target of the step.
48
- * @type {JSONNode}
43
+ * @type {Node}
49
44
  */
50
45
  target = undefined;
51
46
 
52
47
  /**
53
48
  * Creates a new instance.
54
49
  * @param {Object} options The options for the step.
55
- * @param {JSONNode} options.target The target of the step.
50
+ * @param {Node} options.target The target of the step.
56
51
  * @param {1|2} options.phase The phase of the step.
57
52
  * @param {Array<any>} options.args The arguments of the step.
58
53
  */
@@ -69,7 +64,7 @@ class JSONTraversalStep extends pluginKit.VisitNodeStep {
69
64
 
70
65
  /**
71
66
  * JSON Source Code Object
72
- * @implements {IJSONSourceCode}
67
+ * @implements {TextSourceCode<{LangOptions: JSONLanguageOptions, RootNode: DocumentNode, SyntaxElementWithLoc: JSONSyntaxElement, ConfigNode: Token}>}
73
68
  */
74
69
  class JSONSourceCode extends pluginKit.TextSourceCodeBase {
75
70
  /**
@@ -80,13 +75,13 @@ class JSONSourceCode extends pluginKit.TextSourceCodeBase {
80
75
 
81
76
  /**
82
77
  * Cache of parent nodes.
83
- * @type {WeakMap<JSONNode, JSONNode>}
78
+ * @type {WeakMap<Node, Node>}
84
79
  */
85
80
  #parents = new WeakMap();
86
81
 
87
82
  /**
88
83
  * Collection of inline configuration comments.
89
- * @type {Array<JSONToken>}
84
+ * @type {Array<Token>}
90
85
  */
91
86
  #inlineConfigComments;
92
87
 
@@ -98,7 +93,7 @@ class JSONSourceCode extends pluginKit.TextSourceCodeBase {
98
93
 
99
94
  /**
100
95
  * The comment node in the source code.
101
- * @type {Array<JSONToken>|undefined}
96
+ * @type {Array<Token>|undefined}
102
97
  */
103
98
  comments;
104
99
 
@@ -118,7 +113,7 @@ class JSONSourceCode extends pluginKit.TextSourceCodeBase {
118
113
 
119
114
  /**
120
115
  * Returns the value of the given comment.
121
- * @param {JSONToken} comment The comment to get the value of.
116
+ * @param {Token} comment The comment to get the value of.
122
117
  * @returns {string} The value of the comment.
123
118
  * @throws {Error} When an unexpected comment type is passed.
124
119
  */
@@ -137,7 +132,7 @@ class JSONSourceCode extends pluginKit.TextSourceCodeBase {
137
132
  /**
138
133
  * Returns an array of all inline configuration nodes found in the
139
134
  * source code.
140
- * @returns {Array<JSONToken>} An array of all inline configuration nodes.
135
+ * @returns {Array<Token>} An array of all inline configuration nodes.
141
136
  */
142
137
  getInlineConfigNodes() {
143
138
  if (!this.#inlineConfigComments) {
@@ -248,8 +243,8 @@ class JSONSourceCode extends pluginKit.TextSourceCodeBase {
248
243
 
249
244
  /**
250
245
  * Returns the parent of the given node.
251
- * @param {JSONNode} node The node to get the parent of.
252
- * @returns {JSONNode|undefined} The parent of the node.
246
+ * @param {Node} node The node to get the parent of.
247
+ * @returns {Node|undefined} The parent of the node.
253
248
  */
254
249
  getParent(node) {
255
250
  return this.#parents.get(node);
@@ -296,11 +291,14 @@ class JSONSourceCode extends pluginKit.TextSourceCodeBase {
296
291
  // Types
297
292
  //-----------------------------------------------------------------------------
298
293
 
299
- /** @typedef {import("@eslint/core").Language} Language */
300
- /** @typedef {import("@eslint/core").OkParseResult<DocumentNode>} OkParseResult */
301
- /** @typedef {import("@eslint/core").ParseResult<DocumentNode>} ParseResult */
302
- /** @typedef {import("./types.ts").IJSONLanguage} IJSONLanguage */
303
- /** @typedef {import("./types.ts").JSONLanguageOptions} JSONLanguageOptions */
294
+ /**
295
+ *
296
+ * @typedef {OkParseResult<DocumentNode>} JSONOkParseResult
297
+ * @typedef {ParseResult<DocumentNode>} JSONParseResult
298
+ *
299
+ * @typedef {Object} JSONLanguageOptions
300
+ * @property {boolean} [allowTrailingCommas] Whether to allow trailing commas in JSONC mode.
301
+ */
304
302
 
305
303
  //-----------------------------------------------------------------------------
306
304
  // Exports
@@ -308,7 +306,7 @@ class JSONSourceCode extends pluginKit.TextSourceCodeBase {
308
306
 
309
307
  /**
310
308
  * JSON Language Object
311
- * @implements {IJSONLanguage}
309
+ * @implements {Language<{ LangOptions: JSONLanguageOptions; Code: JSONSourceCode; RootNode: DocumentNode; Node: AnyNode }>}
312
310
  */
313
311
  class JSONLanguage {
314
312
  /**
@@ -385,7 +383,7 @@ class JSONLanguage {
385
383
  * Parses the given file into an AST.
386
384
  * @param {File} file The virtual file to parse.
387
385
  * @param {{languageOptions: JSONLanguageOptions}} context The options to use for parsing.
388
- * @returns {ParseResult} The result of parsing.
386
+ * @returns {JSONParseResult} The result of parsing.
389
387
  */
390
388
  parse(file, context) {
391
389
  // Note: BOM already removed
@@ -433,7 +431,7 @@ class JSONLanguage {
433
431
  /**
434
432
  * Creates a new `JSONSourceCode` object from the given information.
435
433
  * @param {File} file The virtual file to create a `JSONSourceCode` object from.
436
- * @param {OkParseResult} parseResult The result returned from `parse()`.
434
+ * @param {JSONOkParseResult} parseResult The result returned from `parse()`.
437
435
  * @returns {JSONSourceCode} The new `JSONSourceCode` object.
438
436
  */
439
437
  createSourceCode(file, parseResult) {
@@ -454,9 +452,11 @@ class JSONLanguage {
454
452
  // Type Definitions
455
453
  //-----------------------------------------------------------------------------
456
454
 
457
- /** @typedef {"duplicateKey"} NoDuplicateKeysMessageIds */
458
- /** @typedef {import("./types.ts").JSONRuleDefinition<[], NoDuplicateKeysMessageIds>} NoDuplicateKeysRuleDefinition */
459
- /** @typedef {import("@humanwhocodes/momoa").MemberNode} MemberNode */
455
+ /**
456
+ *
457
+ * @typedef {"duplicateKey"} NoDuplicateKeysMessageIds
458
+ * @typedef {JSONRuleDefinition<{ MessageIds: NoDuplicateKeysMessageIds }>} NoDuplicateKeysRuleDefinition
459
+ */
460
460
 
461
461
  //-----------------------------------------------------------------------------
462
462
  // Rule Definition
@@ -523,8 +523,11 @@ const rule$5 = {
523
523
  // Type Definitions
524
524
  //-----------------------------------------------------------------------------
525
525
 
526
- /** @typedef {"emptyKey"} NoEmptyKeysMessageIds */
527
- /** @typedef {import("./types.ts").JSONRuleDefinition<[], NoEmptyKeysMessageIds>} NoEmptyKeysRuleDefinition */
526
+ /**
527
+ *
528
+ * @typedef {"emptyKey"} NoEmptyKeysMessageIds
529
+ * @typedef {JSONRuleDefinition<{ MessageIds: NoEmptyKeysMessageIds }>} NoEmptyKeysRuleDefinition
530
+ */
528
531
 
529
532
  //-----------------------------------------------------------------------------
530
533
  // Rule Definition
@@ -572,8 +575,11 @@ const rule$4 = {
572
575
  // Type Definitions
573
576
  //-----------------------------------------------------------------------------
574
577
 
575
- /** @typedef {"unsafeNumber"|"unsafeInteger"|"unsafeZero"|"subnormal"|"loneSurrogate"} NoUnsafeValuesMessageIds */
576
- /** @typedef {import("./types.ts").JSONRuleDefinition<[], NoUnsafeValuesMessageIds>} NoUnsafeValuesRuleDefinition */
578
+ /**
579
+ *
580
+ * @typedef {"unsafeNumber"|"unsafeInteger"|"unsafeZero"|"subnormal"|"loneSurrogate"} NoUnsafeValuesMessageIds
581
+ * @typedef {JSONRuleDefinition<{ MessageIds: NoUnsafeValuesMessageIds }>} NoUnsafeValuesRuleDefinition
582
+ */
577
583
 
578
584
  //-----------------------------------------------------------------------------
579
585
  // Helpers
@@ -720,8 +726,12 @@ const rule$3 = {
720
726
  // Type Definitions
721
727
  //-----------------------------------------------------------------------------
722
728
 
723
- /** @typedef {"unnormalizedKey"} NoUnnormalizedKeysMessageIds */
724
- /** @typedef {import("./types.ts").JSONRuleDefinition<[{form:string}], NoUnnormalizedKeysMessageIds>} NoUnnormalizedKeysRuleDefinition */
729
+ /**
730
+ *
731
+ * @typedef {"unnormalizedKey"} NoUnnormalizedKeysMessageIds
732
+ * @typedef {{ form: string }} NoUnnormalizedKeysOptions
733
+ * @typedef {JSONRuleDefinition<{ RuleOptions: [NoUnnormalizedKeysOptions], MessageIds: NoUnnormalizedKeysMessageIds }>} NoUnnormalizedKeysRuleDefinition
734
+ */
725
735
 
726
736
  //-----------------------------------------------------------------------------
727
737
  // Rule Definition
@@ -790,21 +800,21 @@ const rule$2 = {
790
800
  // Type Definitions
791
801
  //-----------------------------------------------------------------------------
792
802
 
793
- /** @typedef {"sortKeys"} SortKeysMessageIds */
794
-
795
803
  /**
804
+ *
796
805
  * @typedef {Object} SortOptions
797
806
  * @property {boolean} caseSensitive
798
807
  * @property {boolean} natural
799
808
  * @property {number} minKeys
800
809
  * @property {boolean} allowLineSeparatedGroups
810
+ *
811
+ * @typedef {"sortKeys"} SortKeysMessageIds
812
+ * @typedef {"asc"|"desc"} SortDirection
813
+ * @typedef {[SortDirection, SortOptions]} SortKeysRuleOptions
814
+ * @typedef {JSONRuleDefinition<{ RuleOptions: SortKeysRuleOptions, MessageIds: SortKeysMessageIds }>} SortKeysRuleDefinition
815
+ * @typedef {(a:string,b:string) => boolean} Comparator
801
816
  */
802
817
 
803
- /** @typedef {"asc"|"desc"} SortDirection */
804
- /** @typedef {[SortDirection, SortOptions]} SortKeysRuleOptions */
805
- /** @typedef {import("./types.ts").JSONRuleDefinition<SortKeysRuleOptions, SortKeysMessageIds>} SortKeysRuleDefinition */
806
- /** @typedef {(a:string,b:string) => boolean} Comparator */
807
-
808
818
  //-----------------------------------------------------------------------------
809
819
  // Helpers
810
820
  //-----------------------------------------------------------------------------
@@ -1018,8 +1028,11 @@ const rule$1 = {
1018
1028
  // Type Definitions
1019
1029
  //-----------------------------------------------------------------------------
1020
1030
 
1021
- /** @typedef {"topLevel"} TopLevelInteropMessageIds */
1022
- /** @typedef {import("./types.ts").JSONRuleDefinition<[], TopLevelInteropMessageIds>} TopLevelInteropRuleDefinition */
1031
+ /**
1032
+ *
1033
+ * @typedef {"topLevel"} TopLevelInteropMessageIds
1034
+ * @typedef {JSONRuleDefinition<{ MessageIds: TopLevelInteropMessageIds }>} TopLevelInteropRuleDefinition
1035
+ */
1023
1036
 
1024
1037
  //-----------------------------------------------------------------------------
1025
1038
  // Rule Definition
@@ -1070,7 +1083,7 @@ const rule = {
1070
1083
  const plugin = {
1071
1084
  meta: {
1072
1085
  name: "@eslint/json",
1073
- version: "0.11.0", // x-release-please-version
1086
+ version: "0.12.0", // x-release-please-version
1074
1087
  },
1075
1088
  languages: {
1076
1089
  json: new JSONLanguage({ mode: "json" }),
@@ -1,59 +1,66 @@
1
- export type DocumentNode = import("@humanwhocodes/momoa").DocumentNode;
2
- export type JSONNode = import("@humanwhocodes/momoa").Node;
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 VisitTraversalStep = import("@eslint/core").VisitTraversalStep;
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.cts").IJSONSourceCode;
13
- export type JSONSyntaxElement = import("./types.cts").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.cts").IJSONLanguage;
18
- export type JSONLanguageOptions = import("./types.cts").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 = import("./types.cts").JSONRuleDefinition<[], NoDuplicateKeysMessageIds>;
21
- export type MemberNode = import("@humanwhocodes/momoa").MemberNode;
10
+ export type NoDuplicateKeysRuleDefinition = JSONRuleDefinition<{
11
+ MessageIds: NoDuplicateKeysMessageIds;
12
+ }>;
22
13
  export type NoEmptyKeysMessageIds = "emptyKey";
23
- export type NoEmptyKeysRuleDefinition = import("./types.cts").JSONRuleDefinition<[], NoEmptyKeysMessageIds>;
14
+ export type NoEmptyKeysRuleDefinition = JSONRuleDefinition<{
15
+ MessageIds: NoEmptyKeysMessageIds;
16
+ }>;
24
17
  export type NoUnsafeValuesMessageIds = "unsafeNumber" | "unsafeInteger" | "unsafeZero" | "subnormal" | "loneSurrogate";
25
- export type NoUnsafeValuesRuleDefinition = import("./types.cts").JSONRuleDefinition<[], NoUnsafeValuesMessageIds>;
18
+ export type NoUnsafeValuesRuleDefinition = JSONRuleDefinition<{
19
+ MessageIds: NoUnsafeValuesMessageIds;
20
+ }>;
26
21
  export type NoUnnormalizedKeysMessageIds = "unnormalizedKey";
27
- export type NoUnnormalizedKeysRuleDefinition = import("./types.cts").JSONRuleDefinition<[{
22
+ export type NoUnnormalizedKeysOptions = {
28
23
  form: string;
29
- }], NoUnnormalizedKeysMessageIds>;
30
- export type SortKeysMessageIds = "sortKeys";
24
+ };
25
+ export type NoUnnormalizedKeysRuleDefinition = JSONRuleDefinition<{
26
+ RuleOptions: [NoUnnormalizedKeysOptions];
27
+ MessageIds: NoUnnormalizedKeysMessageIds;
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 = import("./types.cts").JSONRuleDefinition<SortKeysRuleOptions, SortKeysMessageIds>;
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 = import("./types.cts").JSONRuleDefinition<[], TopLevelInteropMessageIds>;
44
+ export type TopLevelInteropRuleDefinition = JSONRuleDefinition<{
45
+ MessageIds: TopLevelInteropMessageIds;
46
+ }>;
43
47
  /**
44
48
  * @filedescription Functions to fix up rules to provide missing methods on the `context` object.
45
49
  * @author Nicholas C. Zakas
46
50
  */
47
- /** @typedef {import("@eslint/core").Language} Language */
48
- /** @typedef {import("@eslint/core").OkParseResult<DocumentNode>} OkParseResult */
49
- /** @typedef {import("@eslint/core").ParseResult<DocumentNode>} ParseResult */
50
- /** @typedef {import("./types.cts").IJSONLanguage} IJSONLanguage */
51
- /** @typedef {import("./types.cts").JSONLanguageOptions} JSONLanguageOptions */
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 {IJSONLanguage}
61
+ * @implements {Language<{ LangOptions: JSONLanguageOptions; Code: JSONSourceCode; RootNode: DocumentNode; Node: AnyNode }>}
55
62
  */
56
- export class JSONLanguage implements IJSONLanguage {
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,25 @@ 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 {ParseResult} The result of parsing.
108
+ * @returns {JSONParseResult} The result of parsing.
102
109
  */
103
110
  parse(file: File, context: {
104
111
  languageOptions: JSONLanguageOptions;
105
- }): ParseResult;
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 {OkParseResult} parseResult The result returned from `parse()`.
116
+ * @param {JSONOkParseResult} parseResult The result returned from `parse()`.
110
117
  * @returns {JSONSourceCode} The new `JSONSourceCode` object.
111
118
  */
112
- createSourceCode(file: File, parseResult: OkParseResult): JSONSourceCode;
119
+ createSourceCode(file: File, parseResult: JSONOkParseResult): JSONSourceCode;
113
120
  #private;
114
121
  }
115
122
  /**
116
123
  * JSON Source Code Object
117
- * @implements {IJSONSourceCode}
124
+ * @implements {TextSourceCode<{LangOptions: JSONLanguageOptions, RootNode: DocumentNode, SyntaxElementWithLoc: JSONSyntaxElement, ConfigNode: Token}>}
118
125
  */
119
- export class JSONSourceCode extends TextSourceCodeBase implements IJSONSourceCode {
126
+ export class JSONSourceCode extends TextSourceCodeBase implements TextSourceCode {
120
127
  /**
121
128
  * Creates a new instance.
122
129
  * @param {Object} options The options for the instance.
@@ -134,15 +141,15 @@ export class JSONSourceCode extends TextSourceCodeBase implements IJSONSourceCod
134
141
  ast: DocumentNode;
135
142
  /**
136
143
  * The comment node in the source code.
137
- * @type {Array<JSONToken>|undefined}
144
+ * @type {Array<Token>|undefined}
138
145
  */
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<JSONToken>} An array of all inline configuration nodes.
150
+ * @returns {Array<Token>} An array of all inline configuration nodes.
144
151
  */
145
- getInlineConfigNodes(): Array<JSONToken>;
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,10 +177,10 @@ export class JSONSourceCode extends TextSourceCodeBase implements IJSONSourceCod
170
177
  };
171
178
  /**
172
179
  * Returns the parent of the given node.
173
- * @param {JSONNode} node The node to get the parent of.
174
- * @returns {JSONNode|undefined} The parent of the node.
180
+ * @param {Node} node The node to get the parent of.
181
+ * @returns {Node|undefined} The parent of the node.
175
182
  */
176
- getParent(node: JSONNode): JSONNode | undefined;
183
+ getParent(node: Node): Node | 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.
@@ -212,8 +219,20 @@ declare namespace plugin {
212
219
  }
213
220
  }
214
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";
215
229
  import { TextSourceCodeBase } from '@eslint/plugin-kit';
230
+ import type { Token } from "@humanwhocodes/momoa";
231
+ import type { FileProblem } from "@eslint/core";
216
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";
217
236
  /**
218
237
  * A class to represent a step in the traversal process.
219
238
  */
@@ -221,20 +240,20 @@ declare class JSONTraversalStep extends VisitNodeStep {
221
240
  /**
222
241
  * Creates a new instance.
223
242
  * @param {Object} options The options for the step.
224
- * @param {JSONNode} options.target The target of the step.
243
+ * @param {Node} options.target The target of the step.
225
244
  * @param {1|2} options.phase The phase of the step.
226
245
  * @param {Array<any>} options.args The arguments of the step.
227
246
  */
228
247
  constructor({ target, phase, args }: {
229
- target: JSONNode;
248
+ target: Node;
230
249
  phase: 1 | 2;
231
250
  args: Array<any>;
232
251
  });
233
252
  /**
234
253
  * The target of the step.
235
- * @type {JSONNode}
254
+ * @type {Node}
236
255
  */
237
- target: JSONNode;
256
+ target: Node;
238
257
  }
239
258
  import { VisitNodeStep } from '@eslint/plugin-kit';
240
259
  export { plugin as default };
@@ -7,14 +7,8 @@
7
7
  // Imports
8
8
  //------------------------------------------------------------------------------
9
9
 
10
+ import type { RuleVisitor, RuleDefinition } from "@eslint/core";
10
11
  import type {
11
- RuleVisitor,
12
- TextSourceCode,
13
- Language,
14
- LanguageOptions,
15
- RuleDefinition,
16
- } from "@eslint/core";
17
- import {
18
12
  DocumentNode,
19
13
  MemberNode,
20
14
  ElementNode,
@@ -30,6 +24,7 @@ import {
30
24
  AnyNode,
31
25
  Token,
32
26
  } from "@humanwhocodes/momoa";
27
+ import type { JSONLanguageOptions, JSONSourceCode } from "./index.cjs";
33
28
 
34
29
  //------------------------------------------------------------------------------
35
30
  // Types
@@ -42,16 +37,6 @@ type ValueNodeParent = DocumentNode | MemberNode | ElementNode;
42
37
  */
43
38
  export type JSONSyntaxElement = Token | AnyNode;
44
39
 
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
40
  /**
56
41
  * The visitor format returned from rules in this package.
57
42
  */
@@ -83,56 +68,25 @@ export interface JSONRuleVisitor extends RuleVisitor {
83
68
  "Identifier:exit"?(node: IdentifierNode, parent?: ValueNodeParent): void;
84
69
  }
85
70
 
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
- }>;
71
+ export type JSONRuleDefinitionTypeOptions = {
72
+ RuleOptions: unknown[];
73
+ MessageIds: string;
74
+ ExtRuleDocs: Record<string, unknown>;
75
+ };
126
76
 
127
77
  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
- }>;
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
+ >;
@@ -1,59 +1,66 @@
1
- export type DocumentNode = import("@humanwhocodes/momoa").DocumentNode;
2
- export type JSONNode = import("@humanwhocodes/momoa").Node;
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 VisitTraversalStep = import("@eslint/core").VisitTraversalStep;
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 = import("./types.ts").JSONRuleDefinition<[], NoDuplicateKeysMessageIds>;
21
- export type MemberNode = import("@humanwhocodes/momoa").MemberNode;
10
+ export type NoDuplicateKeysRuleDefinition = JSONRuleDefinition<{
11
+ MessageIds: NoDuplicateKeysMessageIds;
12
+ }>;
22
13
  export type NoEmptyKeysMessageIds = "emptyKey";
23
- export type NoEmptyKeysRuleDefinition = import("./types.ts").JSONRuleDefinition<[], NoEmptyKeysMessageIds>;
14
+ export type NoEmptyKeysRuleDefinition = JSONRuleDefinition<{
15
+ MessageIds: NoEmptyKeysMessageIds;
16
+ }>;
24
17
  export type NoUnsafeValuesMessageIds = "unsafeNumber" | "unsafeInteger" | "unsafeZero" | "subnormal" | "loneSurrogate";
25
- export type NoUnsafeValuesRuleDefinition = import("./types.ts").JSONRuleDefinition<[], NoUnsafeValuesMessageIds>;
18
+ export type NoUnsafeValuesRuleDefinition = JSONRuleDefinition<{
19
+ MessageIds: NoUnsafeValuesMessageIds;
20
+ }>;
26
21
  export type NoUnnormalizedKeysMessageIds = "unnormalizedKey";
27
- export type NoUnnormalizedKeysRuleDefinition = import("./types.ts").JSONRuleDefinition<[{
22
+ export type NoUnnormalizedKeysOptions = {
28
23
  form: string;
29
- }], NoUnnormalizedKeysMessageIds>;
30
- export type SortKeysMessageIds = "sortKeys";
24
+ };
25
+ export type NoUnnormalizedKeysRuleDefinition = JSONRuleDefinition<{
26
+ RuleOptions: [NoUnnormalizedKeysOptions];
27
+ MessageIds: NoUnnormalizedKeysMessageIds;
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 = import("./types.ts").JSONRuleDefinition<SortKeysRuleOptions, SortKeysMessageIds>;
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 = import("./types.ts").JSONRuleDefinition<[], TopLevelInteropMessageIds>;
44
+ export type TopLevelInteropRuleDefinition = JSONRuleDefinition<{
45
+ MessageIds: TopLevelInteropMessageIds;
46
+ }>;
43
47
  /**
44
48
  * @filedescription Functions to fix up rules to provide missing methods on the `context` object.
45
49
  * @author Nicholas C. Zakas
46
50
  */
47
- /** @typedef {import("@eslint/core").Language} Language */
48
- /** @typedef {import("@eslint/core").OkParseResult<DocumentNode>} OkParseResult */
49
- /** @typedef {import("@eslint/core").ParseResult<DocumentNode>} ParseResult */
50
- /** @typedef {import("./types.ts").IJSONLanguage} IJSONLanguage */
51
- /** @typedef {import("./types.ts").JSONLanguageOptions} JSONLanguageOptions */
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 {IJSONLanguage}
61
+ * @implements {Language<{ LangOptions: JSONLanguageOptions; Code: JSONSourceCode; RootNode: DocumentNode; Node: AnyNode }>}
55
62
  */
56
- export class JSONLanguage implements IJSONLanguage {
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,25 @@ 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 {ParseResult} The result of parsing.
108
+ * @returns {JSONParseResult} The result of parsing.
102
109
  */
103
110
  parse(file: File, context: {
104
111
  languageOptions: JSONLanguageOptions;
105
- }): ParseResult;
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 {OkParseResult} parseResult The result returned from `parse()`.
116
+ * @param {JSONOkParseResult} parseResult The result returned from `parse()`.
110
117
  * @returns {JSONSourceCode} The new `JSONSourceCode` object.
111
118
  */
112
- createSourceCode(file: File, parseResult: OkParseResult): JSONSourceCode;
119
+ createSourceCode(file: File, parseResult: JSONOkParseResult): JSONSourceCode;
113
120
  #private;
114
121
  }
115
122
  /**
116
123
  * JSON Source Code Object
117
- * @implements {IJSONSourceCode}
124
+ * @implements {TextSourceCode<{LangOptions: JSONLanguageOptions, RootNode: DocumentNode, SyntaxElementWithLoc: JSONSyntaxElement, ConfigNode: Token}>}
118
125
  */
119
- export class JSONSourceCode extends TextSourceCodeBase implements IJSONSourceCode {
126
+ export class JSONSourceCode extends TextSourceCodeBase implements TextSourceCode {
120
127
  /**
121
128
  * Creates a new instance.
122
129
  * @param {Object} options The options for the instance.
@@ -134,15 +141,15 @@ export class JSONSourceCode extends TextSourceCodeBase implements IJSONSourceCod
134
141
  ast: DocumentNode;
135
142
  /**
136
143
  * The comment node in the source code.
137
- * @type {Array<JSONToken>|undefined}
144
+ * @type {Array<Token>|undefined}
138
145
  */
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<JSONToken>} An array of all inline configuration nodes.
150
+ * @returns {Array<Token>} An array of all inline configuration nodes.
144
151
  */
145
- getInlineConfigNodes(): Array<JSONToken>;
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,10 +177,10 @@ export class JSONSourceCode extends TextSourceCodeBase implements IJSONSourceCod
170
177
  };
171
178
  /**
172
179
  * Returns the parent of the given node.
173
- * @param {JSONNode} node The node to get the parent of.
174
- * @returns {JSONNode|undefined} The parent of the node.
180
+ * @param {Node} node The node to get the parent of.
181
+ * @returns {Node|undefined} The parent of the node.
175
182
  */
176
- getParent(node: JSONNode): JSONNode | undefined;
183
+ getParent(node: Node): Node | 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.
@@ -212,8 +219,20 @@ declare namespace plugin {
212
219
  }
213
220
  }
214
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.ts";
226
+ import type { Language } from "@eslint/core";
227
+ import type { File } from "@eslint/core";
228
+ import type { TextSourceCode } from "@eslint/core";
215
229
  import { TextSourceCodeBase } from '@eslint/plugin-kit';
230
+ import type { Token } from "@humanwhocodes/momoa";
231
+ import type { FileProblem } from "@eslint/core";
216
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";
217
236
  /**
218
237
  * A class to represent a step in the traversal process.
219
238
  */
@@ -221,20 +240,20 @@ declare class JSONTraversalStep extends VisitNodeStep {
221
240
  /**
222
241
  * Creates a new instance.
223
242
  * @param {Object} options The options for the step.
224
- * @param {JSONNode} options.target The target of the step.
243
+ * @param {Node} options.target The target of the step.
225
244
  * @param {1|2} options.phase The phase of the step.
226
245
  * @param {Array<any>} options.args The arguments of the step.
227
246
  */
228
247
  constructor({ target, phase, args }: {
229
- target: JSONNode;
248
+ target: Node;
230
249
  phase: 1 | 2;
231
250
  args: Array<any>;
232
251
  });
233
252
  /**
234
253
  * The target of the step.
235
- * @type {JSONNode}
254
+ * @type {Node}
236
255
  */
237
- target: JSONNode;
256
+ target: Node;
238
257
  }
239
258
  import { VisitNodeStep } from '@eslint/plugin-kit';
240
259
  export { plugin as default };
package/dist/esm/index.js CHANGED
@@ -1,3 +1,9 @@
1
+
2
+ /**
3
+ * @import { DocumentNode, Node, Token, AnyNode, MemberNode } from "@humanwhocodes/momoa"
4
+ * @import { SourceLocation, FileProblem, DirectiveType, RulesConfig, TextSourceCode, Language, OkParseResult, ParseResult, File } from "@eslint/core"
5
+ * @import { JSONSyntaxElement, JSONRuleDefinition } from "./types.ts"
6
+ */
1
7
  // @ts-self-types="./index.d.ts"
2
8
  import { iterator, visitorKeys, parse } from '@humanwhocodes/momoa';
3
9
  import { ConfigCommentParser, TextSourceCodeBase, Directive, VisitNodeStep } from '@eslint/plugin-kit';
@@ -13,19 +19,8 @@ import naturalCompare from 'natural-compare';
13
19
  // Types
14
20
  //-----------------------------------------------------------------------------
15
21
 
16
- /** @typedef {import("@humanwhocodes/momoa").DocumentNode} DocumentNode */
17
- /** @typedef {import("@humanwhocodes/momoa").Node} JSONNode */
18
- /** @typedef {import("@humanwhocodes/momoa").Token} JSONToken */
19
- /** @typedef {import("@eslint/core").SourceRange} SourceRange */
20
- /** @typedef {import("@eslint/core").SourceLocation} SourceLocation */
21
- /** @typedef {import("@eslint/core").File} File */
22
- /** @typedef {import("@eslint/core").TraversalStep} TraversalStep */
23
- /** @typedef {import("@eslint/core").VisitTraversalStep} VisitTraversalStep */
24
- /** @typedef {import("@eslint/core").FileProblem} FileProblem */
25
- /** @typedef {import("@eslint/core").DirectiveType} DirectiveType */
26
- /** @typedef {import("@eslint/core").RulesConfig} RulesConfig */
27
- /** @typedef {import("./types.ts").IJSONSourceCode} IJSONSourceCode */
28
- /** @typedef {import("./types.ts").JSONSyntaxElement} JSONSyntaxElement */
22
+ /**
23
+ */
29
24
 
30
25
  //-----------------------------------------------------------------------------
31
26
  // Helpers
@@ -42,14 +37,14 @@ const INLINE_CONFIG =
42
37
  class JSONTraversalStep extends VisitNodeStep {
43
38
  /**
44
39
  * The target of the step.
45
- * @type {JSONNode}
40
+ * @type {Node}
46
41
  */
47
42
  target = undefined;
48
43
 
49
44
  /**
50
45
  * Creates a new instance.
51
46
  * @param {Object} options The options for the step.
52
- * @param {JSONNode} options.target The target of the step.
47
+ * @param {Node} options.target The target of the step.
53
48
  * @param {1|2} options.phase The phase of the step.
54
49
  * @param {Array<any>} options.args The arguments of the step.
55
50
  */
@@ -66,7 +61,7 @@ class JSONTraversalStep extends VisitNodeStep {
66
61
 
67
62
  /**
68
63
  * JSON Source Code Object
69
- * @implements {IJSONSourceCode}
64
+ * @implements {TextSourceCode<{LangOptions: JSONLanguageOptions, RootNode: DocumentNode, SyntaxElementWithLoc: JSONSyntaxElement, ConfigNode: Token}>}
70
65
  */
71
66
  class JSONSourceCode extends TextSourceCodeBase {
72
67
  /**
@@ -77,13 +72,13 @@ class JSONSourceCode extends TextSourceCodeBase {
77
72
 
78
73
  /**
79
74
  * Cache of parent nodes.
80
- * @type {WeakMap<JSONNode, JSONNode>}
75
+ * @type {WeakMap<Node, Node>}
81
76
  */
82
77
  #parents = new WeakMap();
83
78
 
84
79
  /**
85
80
  * Collection of inline configuration comments.
86
- * @type {Array<JSONToken>}
81
+ * @type {Array<Token>}
87
82
  */
88
83
  #inlineConfigComments;
89
84
 
@@ -95,7 +90,7 @@ class JSONSourceCode extends TextSourceCodeBase {
95
90
 
96
91
  /**
97
92
  * The comment node in the source code.
98
- * @type {Array<JSONToken>|undefined}
93
+ * @type {Array<Token>|undefined}
99
94
  */
100
95
  comments;
101
96
 
@@ -115,7 +110,7 @@ class JSONSourceCode extends TextSourceCodeBase {
115
110
 
116
111
  /**
117
112
  * Returns the value of the given comment.
118
- * @param {JSONToken} comment The comment to get the value of.
113
+ * @param {Token} comment The comment to get the value of.
119
114
  * @returns {string} The value of the comment.
120
115
  * @throws {Error} When an unexpected comment type is passed.
121
116
  */
@@ -134,7 +129,7 @@ class JSONSourceCode extends TextSourceCodeBase {
134
129
  /**
135
130
  * Returns an array of all inline configuration nodes found in the
136
131
  * source code.
137
- * @returns {Array<JSONToken>} An array of all inline configuration nodes.
132
+ * @returns {Array<Token>} An array of all inline configuration nodes.
138
133
  */
139
134
  getInlineConfigNodes() {
140
135
  if (!this.#inlineConfigComments) {
@@ -245,8 +240,8 @@ class JSONSourceCode extends TextSourceCodeBase {
245
240
 
246
241
  /**
247
242
  * Returns the parent of the given node.
248
- * @param {JSONNode} node The node to get the parent of.
249
- * @returns {JSONNode|undefined} The parent of the node.
243
+ * @param {Node} node The node to get the parent of.
244
+ * @returns {Node|undefined} The parent of the node.
250
245
  */
251
246
  getParent(node) {
252
247
  return this.#parents.get(node);
@@ -293,11 +288,14 @@ class JSONSourceCode extends TextSourceCodeBase {
293
288
  // Types
294
289
  //-----------------------------------------------------------------------------
295
290
 
296
- /** @typedef {import("@eslint/core").Language} Language */
297
- /** @typedef {import("@eslint/core").OkParseResult<DocumentNode>} OkParseResult */
298
- /** @typedef {import("@eslint/core").ParseResult<DocumentNode>} ParseResult */
299
- /** @typedef {import("./types.ts").IJSONLanguage} IJSONLanguage */
300
- /** @typedef {import("./types.ts").JSONLanguageOptions} JSONLanguageOptions */
291
+ /**
292
+ *
293
+ * @typedef {OkParseResult<DocumentNode>} JSONOkParseResult
294
+ * @typedef {ParseResult<DocumentNode>} JSONParseResult
295
+ *
296
+ * @typedef {Object} JSONLanguageOptions
297
+ * @property {boolean} [allowTrailingCommas] Whether to allow trailing commas in JSONC mode.
298
+ */
301
299
 
302
300
  //-----------------------------------------------------------------------------
303
301
  // Exports
@@ -305,7 +303,7 @@ class JSONSourceCode extends TextSourceCodeBase {
305
303
 
306
304
  /**
307
305
  * JSON Language Object
308
- * @implements {IJSONLanguage}
306
+ * @implements {Language<{ LangOptions: JSONLanguageOptions; Code: JSONSourceCode; RootNode: DocumentNode; Node: AnyNode }>}
309
307
  */
310
308
  class JSONLanguage {
311
309
  /**
@@ -382,7 +380,7 @@ class JSONLanguage {
382
380
  * Parses the given file into an AST.
383
381
  * @param {File} file The virtual file to parse.
384
382
  * @param {{languageOptions: JSONLanguageOptions}} context The options to use for parsing.
385
- * @returns {ParseResult} The result of parsing.
383
+ * @returns {JSONParseResult} The result of parsing.
386
384
  */
387
385
  parse(file, context) {
388
386
  // Note: BOM already removed
@@ -430,7 +428,7 @@ class JSONLanguage {
430
428
  /**
431
429
  * Creates a new `JSONSourceCode` object from the given information.
432
430
  * @param {File} file The virtual file to create a `JSONSourceCode` object from.
433
- * @param {OkParseResult} parseResult The result returned from `parse()`.
431
+ * @param {JSONOkParseResult} parseResult The result returned from `parse()`.
434
432
  * @returns {JSONSourceCode} The new `JSONSourceCode` object.
435
433
  */
436
434
  createSourceCode(file, parseResult) {
@@ -451,9 +449,11 @@ class JSONLanguage {
451
449
  // Type Definitions
452
450
  //-----------------------------------------------------------------------------
453
451
 
454
- /** @typedef {"duplicateKey"} NoDuplicateKeysMessageIds */
455
- /** @typedef {import("./types.ts").JSONRuleDefinition<[], NoDuplicateKeysMessageIds>} NoDuplicateKeysRuleDefinition */
456
- /** @typedef {import("@humanwhocodes/momoa").MemberNode} MemberNode */
452
+ /**
453
+ *
454
+ * @typedef {"duplicateKey"} NoDuplicateKeysMessageIds
455
+ * @typedef {JSONRuleDefinition<{ MessageIds: NoDuplicateKeysMessageIds }>} NoDuplicateKeysRuleDefinition
456
+ */
457
457
 
458
458
  //-----------------------------------------------------------------------------
459
459
  // Rule Definition
@@ -520,8 +520,11 @@ const rule$5 = {
520
520
  // Type Definitions
521
521
  //-----------------------------------------------------------------------------
522
522
 
523
- /** @typedef {"emptyKey"} NoEmptyKeysMessageIds */
524
- /** @typedef {import("./types.ts").JSONRuleDefinition<[], NoEmptyKeysMessageIds>} NoEmptyKeysRuleDefinition */
523
+ /**
524
+ *
525
+ * @typedef {"emptyKey"} NoEmptyKeysMessageIds
526
+ * @typedef {JSONRuleDefinition<{ MessageIds: NoEmptyKeysMessageIds }>} NoEmptyKeysRuleDefinition
527
+ */
525
528
 
526
529
  //-----------------------------------------------------------------------------
527
530
  // Rule Definition
@@ -569,8 +572,11 @@ const rule$4 = {
569
572
  // Type Definitions
570
573
  //-----------------------------------------------------------------------------
571
574
 
572
- /** @typedef {"unsafeNumber"|"unsafeInteger"|"unsafeZero"|"subnormal"|"loneSurrogate"} NoUnsafeValuesMessageIds */
573
- /** @typedef {import("./types.ts").JSONRuleDefinition<[], NoUnsafeValuesMessageIds>} NoUnsafeValuesRuleDefinition */
575
+ /**
576
+ *
577
+ * @typedef {"unsafeNumber"|"unsafeInteger"|"unsafeZero"|"subnormal"|"loneSurrogate"} NoUnsafeValuesMessageIds
578
+ * @typedef {JSONRuleDefinition<{ MessageIds: NoUnsafeValuesMessageIds }>} NoUnsafeValuesRuleDefinition
579
+ */
574
580
 
575
581
  //-----------------------------------------------------------------------------
576
582
  // Helpers
@@ -717,8 +723,12 @@ const rule$3 = {
717
723
  // Type Definitions
718
724
  //-----------------------------------------------------------------------------
719
725
 
720
- /** @typedef {"unnormalizedKey"} NoUnnormalizedKeysMessageIds */
721
- /** @typedef {import("./types.ts").JSONRuleDefinition<[{form:string}], NoUnnormalizedKeysMessageIds>} NoUnnormalizedKeysRuleDefinition */
726
+ /**
727
+ *
728
+ * @typedef {"unnormalizedKey"} NoUnnormalizedKeysMessageIds
729
+ * @typedef {{ form: string }} NoUnnormalizedKeysOptions
730
+ * @typedef {JSONRuleDefinition<{ RuleOptions: [NoUnnormalizedKeysOptions], MessageIds: NoUnnormalizedKeysMessageIds }>} NoUnnormalizedKeysRuleDefinition
731
+ */
722
732
 
723
733
  //-----------------------------------------------------------------------------
724
734
  // Rule Definition
@@ -787,21 +797,21 @@ const rule$2 = {
787
797
  // Type Definitions
788
798
  //-----------------------------------------------------------------------------
789
799
 
790
- /** @typedef {"sortKeys"} SortKeysMessageIds */
791
-
792
800
  /**
801
+ *
793
802
  * @typedef {Object} SortOptions
794
803
  * @property {boolean} caseSensitive
795
804
  * @property {boolean} natural
796
805
  * @property {number} minKeys
797
806
  * @property {boolean} allowLineSeparatedGroups
807
+ *
808
+ * @typedef {"sortKeys"} SortKeysMessageIds
809
+ * @typedef {"asc"|"desc"} SortDirection
810
+ * @typedef {[SortDirection, SortOptions]} SortKeysRuleOptions
811
+ * @typedef {JSONRuleDefinition<{ RuleOptions: SortKeysRuleOptions, MessageIds: SortKeysMessageIds }>} SortKeysRuleDefinition
812
+ * @typedef {(a:string,b:string) => boolean} Comparator
798
813
  */
799
814
 
800
- /** @typedef {"asc"|"desc"} SortDirection */
801
- /** @typedef {[SortDirection, SortOptions]} SortKeysRuleOptions */
802
- /** @typedef {import("./types.ts").JSONRuleDefinition<SortKeysRuleOptions, SortKeysMessageIds>} SortKeysRuleDefinition */
803
- /** @typedef {(a:string,b:string) => boolean} Comparator */
804
-
805
815
  //-----------------------------------------------------------------------------
806
816
  // Helpers
807
817
  //-----------------------------------------------------------------------------
@@ -1015,8 +1025,11 @@ const rule$1 = {
1015
1025
  // Type Definitions
1016
1026
  //-----------------------------------------------------------------------------
1017
1027
 
1018
- /** @typedef {"topLevel"} TopLevelInteropMessageIds */
1019
- /** @typedef {import("./types.ts").JSONRuleDefinition<[], TopLevelInteropMessageIds>} TopLevelInteropRuleDefinition */
1028
+ /**
1029
+ *
1030
+ * @typedef {"topLevel"} TopLevelInteropMessageIds
1031
+ * @typedef {JSONRuleDefinition<{ MessageIds: TopLevelInteropMessageIds }>} TopLevelInteropRuleDefinition
1032
+ */
1020
1033
 
1021
1034
  //-----------------------------------------------------------------------------
1022
1035
  // Rule Definition
@@ -1067,7 +1080,7 @@ const rule = {
1067
1080
  const plugin = {
1068
1081
  meta: {
1069
1082
  name: "@eslint/json",
1070
- version: "0.11.0", // x-release-please-version
1083
+ version: "0.12.0", // x-release-please-version
1071
1084
  },
1072
1085
  languages: {
1073
1086
  json: new JSONLanguage({ mode: "json" }),
@@ -2,22 +2,14 @@
2
2
  * @fileoverview Additional types for this package.
3
3
  * @author Nicholas C. Zakas
4
4
  */
5
- import type { RuleVisitor, TextSourceCode, Language, LanguageOptions, RuleDefinition } from "@eslint/core";
6
- import { DocumentNode, MemberNode, ElementNode, ObjectNode, ArrayNode, StringNode, NullNode, NumberNode, BooleanNode, NaNNode, InfinityNode, IdentifierNode, AnyNode, Token } from "@humanwhocodes/momoa";
5
+ import type { RuleVisitor, RuleDefinition } from "@eslint/core";
6
+ import type { DocumentNode, MemberNode, ElementNode, ObjectNode, ArrayNode, StringNode, NullNode, NumberNode, BooleanNode, NaNNode, InfinityNode, IdentifierNode, AnyNode, Token } from "@humanwhocodes/momoa";
7
+ import type { JSONLanguageOptions, JSONSourceCode } from "./index.js";
7
8
  type ValueNodeParent = DocumentNode | MemberNode | ElementNode;
8
9
  /**
9
10
  * A JSON syntax element, including nodes and tokens.
10
11
  */
11
12
  export type JSONSyntaxElement = Token | AnyNode;
12
- /**
13
- * Language options provided for JSON files.
14
- */
15
- export interface JSONLanguageOptions extends LanguageOptions {
16
- /**
17
- * Whether to allow trailing commas. Only valid in JSONC.
18
- */
19
- allowTrailingCommas?: boolean;
20
- }
21
13
  /**
22
14
  * The visitor format returned from rules in this package.
23
15
  */
@@ -47,45 +39,15 @@ export interface JSONRuleVisitor extends RuleVisitor {
47
39
  "Infinity:exit"?(node: InfinityNode, parent?: ValueNodeParent): void;
48
40
  "Identifier:exit"?(node: IdentifierNode, parent?: ValueNodeParent): void;
49
41
  }
50
- /**
51
- * The `SourceCode` implementation for JSON files.
52
- */
53
- export interface IJSONSourceCode extends TextSourceCode<{
54
- LangOptions: JSONLanguageOptions;
55
- RootNode: DocumentNode;
56
- SyntaxElementWithLoc: JSONSyntaxElement;
57
- ConfigNode: Token;
58
- }> {
59
- /**
60
- * Get the text of a syntax element.
61
- * @param syntaxElement The syntax element to get the text of.
62
- * @param beforeCount The number of characters to include before the syntax element.
63
- * @param afterCount The number of characters to include after the syntax element.
64
- * @returns The text of the syntax element.
65
- */
66
- getText(syntaxElement: JSONSyntaxElement, beforeCount?: number, afterCount?: number): string;
67
- /**
68
- * Any comments found in a JSONC or JSON5 file.
69
- */
70
- comments: Array<Token> | undefined;
71
- /**
72
- * The lines of text found in the file.
73
- */
74
- lines: Array<string>;
75
- }
76
- export type IJSONLanguage = Language<{
77
- LangOptions: JSONLanguageOptions;
78
- Code: IJSONSourceCode;
79
- RootNode: DocumentNode;
80
- Node: AnyNode;
81
- }>;
82
- export type JSONRuleDefinition<JSONRuleOptions extends unknown[], JSONRuleMessageIds extends string = ""> = RuleDefinition<{
42
+ export type JSONRuleDefinitionTypeOptions = {
43
+ RuleOptions: unknown[];
44
+ MessageIds: string;
45
+ ExtRuleDocs: Record<string, unknown>;
46
+ };
47
+ export type JSONRuleDefinition<Options extends Partial<JSONRuleDefinitionTypeOptions> = {}> = RuleDefinition<{
83
48
  LangOptions: JSONLanguageOptions;
84
- Code: IJSONSourceCode;
85
- RuleOptions: JSONRuleOptions;
49
+ Code: JSONSourceCode;
86
50
  Visitor: JSONRuleVisitor;
87
51
  Node: AnyNode;
88
- MessageIds: JSONRuleMessageIds;
89
- ExtRuleDocs: {};
90
- }>;
52
+ } & Required<Options & Omit<JSONRuleDefinitionTypeOptions, keyof Options>>>;
91
53
  export {};
package/dist/esm/types.ts CHANGED
@@ -7,14 +7,8 @@
7
7
  // Imports
8
8
  //------------------------------------------------------------------------------
9
9
 
10
+ import type { RuleVisitor, RuleDefinition } from "@eslint/core";
10
11
  import type {
11
- RuleVisitor,
12
- TextSourceCode,
13
- Language,
14
- LanguageOptions,
15
- RuleDefinition,
16
- } from "@eslint/core";
17
- import {
18
12
  DocumentNode,
19
13
  MemberNode,
20
14
  ElementNode,
@@ -30,6 +24,7 @@ import {
30
24
  AnyNode,
31
25
  Token,
32
26
  } from "@humanwhocodes/momoa";
27
+ import type { JSONLanguageOptions, JSONSourceCode } from "./index.js";
33
28
 
34
29
  //------------------------------------------------------------------------------
35
30
  // Types
@@ -42,16 +37,6 @@ type ValueNodeParent = DocumentNode | MemberNode | ElementNode;
42
37
  */
43
38
  export type JSONSyntaxElement = Token | AnyNode;
44
39
 
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
40
  /**
56
41
  * The visitor format returned from rules in this package.
57
42
  */
@@ -83,56 +68,25 @@ export interface JSONRuleVisitor extends RuleVisitor {
83
68
  "Identifier:exit"?(node: IdentifierNode, parent?: ValueNodeParent): void;
84
69
  }
85
70
 
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
- }>;
71
+ export type JSONRuleDefinitionTypeOptions = {
72
+ RuleOptions: unknown[];
73
+ MessageIds: string;
74
+ ExtRuleDocs: Record<string, unknown>;
75
+ };
126
76
 
127
77
  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
- }>;
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
+ >;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eslint/json",
3
- "version": "0.11.0",
3
+ "version": "0.12.0",
4
4
  "description": "JSON linting plugin for ESLint",
5
5
  "author": "Nicholas C. Zakas",
6
6
  "type": "module",
@@ -81,7 +81,7 @@
81
81
  "devDependencies": {
82
82
  "c8": "^9.1.0",
83
83
  "dedent": "^1.5.3",
84
- "eslint": "^9.11.1",
84
+ "eslint": "^9.23.0",
85
85
  "eslint-config-eslint": "^11.0.0",
86
86
  "eslint-plugin-eslint-plugin": "^6.3.2",
87
87
  "got": "^14.4.2",
@@ -90,6 +90,7 @@
90
90
  "prettier": "^3.4.1",
91
91
  "rollup": "^4.16.2",
92
92
  "rollup-plugin-copy": "^3.5.0",
93
+ "rollup-plugin-delete": "^3.0.1",
93
94
  "typescript": "^5.4.5",
94
95
  "yorkie": "^2.0.0"
95
96
  },