@eslint/json 0.2.0 → 0.4.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
@@ -28,12 +28,13 @@ deno add @eslint/json
28
28
 
29
29
  ## Usage
30
30
 
31
- This package exports two different languages:
31
+ This package exports these languages:
32
32
 
33
33
  - `"json/json"` is for regular JSON files
34
- - `"json/jsonc"` is for JSON files that support comments (JSON-C) such as those used for Visual Studio Code configuration files
34
+ - `"json/jsonc"` is for JSON files that support comments ([JSONC](https://github.com/microsoft/node-jsonc-parser)) such as those used for Visual Studio Code configuration files
35
+ - `"json/json5"` is for [JSON5](https://json5.org) files
35
36
 
36
- Depending on which types of JSON files you'd like to lint, you can set up your `eslint.config.js` file to include just the files you'd like. Here's an example that lints both JSON and JSON-C files:
37
+ Depending on which types of JSON files you'd like to lint, you can set up your `eslint.config.js` file to include just the files you'd like. Here's an example that lints JSON, JSONC, and JSON5 files:
37
38
 
38
39
  ```js
39
40
  import json from "@eslint/json";
@@ -54,7 +55,7 @@ export default [
54
55
  },
55
56
  },
56
57
 
57
- // lint JSON-C files
58
+ // lint JSONC files
58
59
  {
59
60
  files: ["**/*.jsonc", ".vscode/*.json"],
60
61
  language: "json/jsonc",
@@ -62,6 +63,15 @@ export default [
62
63
  "json/no-duplicate-keys": "error",
63
64
  },
64
65
  },
66
+
67
+ // lint JSON5 files
68
+ {
69
+ files: ["**/*.json5"],
70
+ language: "json/json5",
71
+ rules: {
72
+ "json/no-duplicate-keys": "error",
73
+ },
74
+ },
65
75
  ];
66
76
  ```
67
77
 
@@ -81,12 +91,19 @@ export default [
81
91
  ...json.configs.recommended,
82
92
  },
83
93
 
84
- // lint JSON-C files
94
+ // lint JSONC files
85
95
  {
86
96
  files: ["**/*.jsonc"],
87
97
  language: "json/jsonc",
88
98
  ...json.configs.recommended,
89
99
  },
100
+
101
+ // lint JSON5 files
102
+ {
103
+ files: ["**/*.json5"],
104
+ language: "json/json5",
105
+ ...json.configs.recommended,
106
+ },
90
107
  ];
91
108
  ```
92
109
 
@@ -1,5 +1,7 @@
1
1
  'use strict';
2
2
 
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
3
5
  var momoa = require('@humanwhocodes/momoa');
4
6
 
5
7
  /**
@@ -300,7 +302,7 @@ class JSONLanguage {
300
302
 
301
303
  /**
302
304
  * The parser mode.
303
- * @type {"json"|"jsonc"}
305
+ * @type {"json"|"jsonc"|"json5"}
304
306
  */
305
307
  #mode = "json";
306
308
 
@@ -313,7 +315,7 @@ class JSONLanguage {
313
315
  /**
314
316
  * Creates a new instance.
315
317
  * @param {Object} options The options to use for this instance.
316
- * @param {"json"|"jsonc"} options.mode The parser mode to use.
318
+ * @param {"json"|"jsonc"|"json5"} options.mode The parser mode to use.
317
319
  */
318
320
  constructor({ mode }) {
319
321
  this.#mode = mode;
@@ -397,7 +399,7 @@ class JSONLanguage {
397
399
  */
398
400
 
399
401
  //-----------------------------------------------------------------------------
400
- // Type Definitions
402
+ // Rule Definition
401
403
  //-----------------------------------------------------------------------------
402
404
 
403
405
  var noDuplicateKeys = {
@@ -424,7 +426,10 @@ var noDuplicateKeys = {
424
426
  },
425
427
 
426
428
  Member(node) {
427
- const key = node.name.value;
429
+ const key =
430
+ node.name.type === "String"
431
+ ? node.name.value
432
+ : node.name.name;
428
433
 
429
434
  if (keys.has(key)) {
430
435
  context.report({
@@ -466,7 +471,10 @@ var noEmptyKeys = {
466
471
  create(context) {
467
472
  return {
468
473
  Member(node) {
469
- const key = node.name.value;
474
+ const key =
475
+ node.name.type === "String"
476
+ ? node.name.value
477
+ : node.name.name;
470
478
 
471
479
  if (key.trim() === "") {
472
480
  context.report({
@@ -492,11 +500,12 @@ var noEmptyKeys = {
492
500
  const plugin = {
493
501
  meta: {
494
502
  name: "@eslint/json",
495
- version: "0.2.0", // x-release-please-version
503
+ version: "0.4.0", // x-release-please-version
496
504
  },
497
505
  languages: {
498
506
  json: new JSONLanguage({ mode: "json" }),
499
507
  jsonc: new JSONLanguage({ mode: "jsonc" }),
508
+ json5: new JSONLanguage({ mode: "json5" }),
500
509
  },
501
510
  rules: {
502
511
  "no-duplicate-keys": noDuplicateKeys,
@@ -515,4 +524,6 @@ Object.assign(plugin.configs, {
515
524
  },
516
525
  });
517
526
 
518
- module.exports = plugin;
527
+ exports.JSONLanguage = JSONLanguage;
528
+ exports.JSONSourceCode = JSONSourceCode;
529
+ exports.default = plugin;
@@ -1,4 +1,3 @@
1
- export { plugin as default };
2
1
  export type DocumentNode = import("@humanwhocodes/momoa").DocumentNode;
3
2
  export type JSONNode = import("@humanwhocodes/momoa").Node;
4
3
  export type JSONToken = import("@humanwhocodes/momoa").Token;
@@ -11,49 +10,6 @@ export type VisitTraversalStep = import("@eslint/core").VisitTraversalStep;
11
10
  export type Language = import("@eslint/core").Language;
12
11
  export type OkParseResult = import("@eslint/core").OkParseResult<DocumentNode>;
13
12
  export type ParseResult = import("@eslint/core").ParseResult<DocumentNode>;
14
- declare namespace plugin {
15
- namespace meta {
16
- let name: string;
17
- let version: string;
18
- }
19
- namespace languages {
20
- let json: JSONLanguage;
21
- let jsonc: JSONLanguage;
22
- }
23
- let rules: {
24
- "no-duplicate-keys": {
25
- meta: {
26
- type: string;
27
- docs: {
28
- description: string;
29
- };
30
- messages: {
31
- duplicateKey: string;
32
- };
33
- };
34
- create(context: any): {
35
- Object(): void;
36
- Member(node: any): void;
37
- "Object:exit"(): void;
38
- };
39
- };
40
- "no-empty-keys": {
41
- meta: {
42
- type: string;
43
- docs: {
44
- description: string;
45
- };
46
- messages: {
47
- emptyKey: string;
48
- };
49
- };
50
- create(context: any): {
51
- Member(node: any): void;
52
- };
53
- };
54
- };
55
- let configs: {};
56
- }
57
13
  /**
58
14
  * @filedescription Functions to fix up rules to provide missing methods on the `context` object.
59
15
  * @author Nicholas C. Zakas
@@ -65,14 +21,14 @@ declare namespace plugin {
65
21
  * JSON Language Object
66
22
  * @implements {Language}
67
23
  */
68
- declare class JSONLanguage implements Language {
24
+ export class JSONLanguage implements Language {
69
25
  /**
70
26
  * Creates a new instance.
71
27
  * @param {Object} options The options to use for this instance.
72
- * @param {"json"|"jsonc"} options.mode The parser mode to use.
28
+ * @param {"json"|"jsonc"|"json5"} options.mode The parser mode to use.
73
29
  */
74
30
  constructor({ mode }: {
75
- mode: "json" | "jsonc";
31
+ mode: "json" | "jsonc" | "json5";
76
32
  });
77
33
  /**
78
34
  * The type of file to read.
@@ -125,7 +81,7 @@ declare class JSONLanguage implements Language {
125
81
  * JSON Source Code Object
126
82
  * @implements {TextSourceCode}
127
83
  */
128
- declare class JSONSourceCode implements TextSourceCode {
84
+ export class JSONSourceCode implements TextSourceCode {
129
85
  /**
130
86
  * Creates a new instance.
131
87
  * @param {Object} options The options for the instance.
@@ -199,6 +155,50 @@ declare class JSONSourceCode implements TextSourceCode {
199
155
  traverse(): Iterable<JSONTraversalStep>;
200
156
  #private;
201
157
  }
158
+ declare namespace plugin {
159
+ namespace meta {
160
+ let name: string;
161
+ let version: string;
162
+ }
163
+ namespace languages {
164
+ let json: JSONLanguage;
165
+ let jsonc: JSONLanguage;
166
+ let json5: JSONLanguage;
167
+ }
168
+ let rules: {
169
+ "no-duplicate-keys": {
170
+ meta: {
171
+ type: string;
172
+ docs: {
173
+ description: string;
174
+ };
175
+ messages: {
176
+ duplicateKey: string;
177
+ };
178
+ };
179
+ create(context: any): {
180
+ Object(): void;
181
+ Member(node: any): void;
182
+ "Object:exit"(): void;
183
+ };
184
+ };
185
+ "no-empty-keys": {
186
+ meta: {
187
+ type: string;
188
+ docs: {
189
+ description: string;
190
+ };
191
+ messages: {
192
+ emptyKey: string;
193
+ };
194
+ };
195
+ create(context: any): {
196
+ Member(node: any): void;
197
+ };
198
+ };
199
+ };
200
+ let configs: {};
201
+ }
202
202
  /**
203
203
  * @fileoverview The JSONSourceCode class.
204
204
  * @author Nicholas C. Zakas
@@ -258,3 +258,4 @@ declare class JSONTraversalStep implements VisitTraversalStep {
258
258
  */
259
259
  args: Array<any>;
260
260
  }
261
+ export { plugin as default };
@@ -1,4 +1,3 @@
1
- export { plugin as default };
2
1
  export type DocumentNode = import("@humanwhocodes/momoa").DocumentNode;
3
2
  export type JSONNode = import("@humanwhocodes/momoa").Node;
4
3
  export type JSONToken = import("@humanwhocodes/momoa").Token;
@@ -11,49 +10,6 @@ export type VisitTraversalStep = import("@eslint/core").VisitTraversalStep;
11
10
  export type Language = import("@eslint/core").Language;
12
11
  export type OkParseResult = import("@eslint/core").OkParseResult<DocumentNode>;
13
12
  export type ParseResult = import("@eslint/core").ParseResult<DocumentNode>;
14
- declare namespace plugin {
15
- namespace meta {
16
- let name: string;
17
- let version: string;
18
- }
19
- namespace languages {
20
- let json: JSONLanguage;
21
- let jsonc: JSONLanguage;
22
- }
23
- let rules: {
24
- "no-duplicate-keys": {
25
- meta: {
26
- type: string;
27
- docs: {
28
- description: string;
29
- };
30
- messages: {
31
- duplicateKey: string;
32
- };
33
- };
34
- create(context: any): {
35
- Object(): void;
36
- Member(node: any): void;
37
- "Object:exit"(): void;
38
- };
39
- };
40
- "no-empty-keys": {
41
- meta: {
42
- type: string;
43
- docs: {
44
- description: string;
45
- };
46
- messages: {
47
- emptyKey: string;
48
- };
49
- };
50
- create(context: any): {
51
- Member(node: any): void;
52
- };
53
- };
54
- };
55
- let configs: {};
56
- }
57
13
  /**
58
14
  * @filedescription Functions to fix up rules to provide missing methods on the `context` object.
59
15
  * @author Nicholas C. Zakas
@@ -65,14 +21,14 @@ declare namespace plugin {
65
21
  * JSON Language Object
66
22
  * @implements {Language}
67
23
  */
68
- declare class JSONLanguage implements Language {
24
+ export class JSONLanguage implements Language {
69
25
  /**
70
26
  * Creates a new instance.
71
27
  * @param {Object} options The options to use for this instance.
72
- * @param {"json"|"jsonc"} options.mode The parser mode to use.
28
+ * @param {"json"|"jsonc"|"json5"} options.mode The parser mode to use.
73
29
  */
74
30
  constructor({ mode }: {
75
- mode: "json" | "jsonc";
31
+ mode: "json" | "jsonc" | "json5";
76
32
  });
77
33
  /**
78
34
  * The type of file to read.
@@ -125,7 +81,7 @@ declare class JSONLanguage implements Language {
125
81
  * JSON Source Code Object
126
82
  * @implements {TextSourceCode}
127
83
  */
128
- declare class JSONSourceCode implements TextSourceCode {
84
+ export class JSONSourceCode implements TextSourceCode {
129
85
  /**
130
86
  * Creates a new instance.
131
87
  * @param {Object} options The options for the instance.
@@ -199,6 +155,50 @@ declare class JSONSourceCode implements TextSourceCode {
199
155
  traverse(): Iterable<JSONTraversalStep>;
200
156
  #private;
201
157
  }
158
+ declare namespace plugin {
159
+ namespace meta {
160
+ let name: string;
161
+ let version: string;
162
+ }
163
+ namespace languages {
164
+ let json: JSONLanguage;
165
+ let jsonc: JSONLanguage;
166
+ let json5: JSONLanguage;
167
+ }
168
+ let rules: {
169
+ "no-duplicate-keys": {
170
+ meta: {
171
+ type: string;
172
+ docs: {
173
+ description: string;
174
+ };
175
+ messages: {
176
+ duplicateKey: string;
177
+ };
178
+ };
179
+ create(context: any): {
180
+ Object(): void;
181
+ Member(node: any): void;
182
+ "Object:exit"(): void;
183
+ };
184
+ };
185
+ "no-empty-keys": {
186
+ meta: {
187
+ type: string;
188
+ docs: {
189
+ description: string;
190
+ };
191
+ messages: {
192
+ emptyKey: string;
193
+ };
194
+ };
195
+ create(context: any): {
196
+ Member(node: any): void;
197
+ };
198
+ };
199
+ };
200
+ let configs: {};
201
+ }
202
202
  /**
203
203
  * @fileoverview The JSONSourceCode class.
204
204
  * @author Nicholas C. Zakas
@@ -258,3 +258,4 @@ declare class JSONTraversalStep implements VisitTraversalStep {
258
258
  */
259
259
  args: Array<any>;
260
260
  }
261
+ export { plugin as default };
package/dist/esm/index.js CHANGED
@@ -299,7 +299,7 @@ class JSONLanguage {
299
299
 
300
300
  /**
301
301
  * The parser mode.
302
- * @type {"json"|"jsonc"}
302
+ * @type {"json"|"jsonc"|"json5"}
303
303
  */
304
304
  #mode = "json";
305
305
 
@@ -312,7 +312,7 @@ class JSONLanguage {
312
312
  /**
313
313
  * Creates a new instance.
314
314
  * @param {Object} options The options to use for this instance.
315
- * @param {"json"|"jsonc"} options.mode The parser mode to use.
315
+ * @param {"json"|"jsonc"|"json5"} options.mode The parser mode to use.
316
316
  */
317
317
  constructor({ mode }) {
318
318
  this.#mode = mode;
@@ -396,7 +396,7 @@ class JSONLanguage {
396
396
  */
397
397
 
398
398
  //-----------------------------------------------------------------------------
399
- // Type Definitions
399
+ // Rule Definition
400
400
  //-----------------------------------------------------------------------------
401
401
 
402
402
  var noDuplicateKeys = {
@@ -423,7 +423,10 @@ var noDuplicateKeys = {
423
423
  },
424
424
 
425
425
  Member(node) {
426
- const key = node.name.value;
426
+ const key =
427
+ node.name.type === "String"
428
+ ? node.name.value
429
+ : node.name.name;
427
430
 
428
431
  if (keys.has(key)) {
429
432
  context.report({
@@ -465,7 +468,10 @@ var noEmptyKeys = {
465
468
  create(context) {
466
469
  return {
467
470
  Member(node) {
468
- const key = node.name.value;
471
+ const key =
472
+ node.name.type === "String"
473
+ ? node.name.value
474
+ : node.name.name;
469
475
 
470
476
  if (key.trim() === "") {
471
477
  context.report({
@@ -491,11 +497,12 @@ var noEmptyKeys = {
491
497
  const plugin = {
492
498
  meta: {
493
499
  name: "@eslint/json",
494
- version: "0.2.0", // x-release-please-version
500
+ version: "0.4.0", // x-release-please-version
495
501
  },
496
502
  languages: {
497
503
  json: new JSONLanguage({ mode: "json" }),
498
504
  jsonc: new JSONLanguage({ mode: "jsonc" }),
505
+ json5: new JSONLanguage({ mode: "json5" }),
499
506
  },
500
507
  rules: {
501
508
  "no-duplicate-keys": noDuplicateKeys,
@@ -514,4 +521,4 @@ Object.assign(plugin.configs, {
514
521
  },
515
522
  });
516
523
 
517
- export { plugin as default };
524
+ export { JSONLanguage, JSONSourceCode, plugin as default };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eslint/json",
3
- "version": "0.2.0",
3
+ "version": "0.4.0",
4
4
  "description": "JSON linting plugin for ESLint",
5
5
  "author": "Nicholas C. Zakas",
6
6
  "type": "module",
@@ -61,7 +61,7 @@
61
61
  ],
62
62
  "license": "Apache-2.0",
63
63
  "dependencies": {
64
- "@humanwhocodes/momoa": "^3.1.1"
64
+ "@humanwhocodes/momoa": "^3.2.0"
65
65
  },
66
66
  "devDependencies": {
67
67
  "@eslint/core": "^0.3.0",