@eslint/json 0.2.0 → 0.3.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
 
@@ -300,7 +300,7 @@ class JSONLanguage {
300
300
 
301
301
  /**
302
302
  * The parser mode.
303
- * @type {"json"|"jsonc"}
303
+ * @type {"json"|"jsonc"|"json5"}
304
304
  */
305
305
  #mode = "json";
306
306
 
@@ -313,7 +313,7 @@ class JSONLanguage {
313
313
  /**
314
314
  * Creates a new instance.
315
315
  * @param {Object} options The options to use for this instance.
316
- * @param {"json"|"jsonc"} options.mode The parser mode to use.
316
+ * @param {"json"|"jsonc"|"json5"} options.mode The parser mode to use.
317
317
  */
318
318
  constructor({ mode }) {
319
319
  this.#mode = mode;
@@ -397,7 +397,7 @@ class JSONLanguage {
397
397
  */
398
398
 
399
399
  //-----------------------------------------------------------------------------
400
- // Type Definitions
400
+ // Rule Definition
401
401
  //-----------------------------------------------------------------------------
402
402
 
403
403
  var noDuplicateKeys = {
@@ -424,7 +424,10 @@ var noDuplicateKeys = {
424
424
  },
425
425
 
426
426
  Member(node) {
427
- const key = node.name.value;
427
+ const key =
428
+ node.name.type === "String"
429
+ ? node.name.value
430
+ : node.name.name;
428
431
 
429
432
  if (keys.has(key)) {
430
433
  context.report({
@@ -466,7 +469,10 @@ var noEmptyKeys = {
466
469
  create(context) {
467
470
  return {
468
471
  Member(node) {
469
- const key = node.name.value;
472
+ const key =
473
+ node.name.type === "String"
474
+ ? node.name.value
475
+ : node.name.name;
470
476
 
471
477
  if (key.trim() === "") {
472
478
  context.report({
@@ -492,11 +498,12 @@ var noEmptyKeys = {
492
498
  const plugin = {
493
499
  meta: {
494
500
  name: "@eslint/json",
495
- version: "0.2.0", // x-release-please-version
501
+ version: "0.3.0", // x-release-please-version
496
502
  },
497
503
  languages: {
498
504
  json: new JSONLanguage({ mode: "json" }),
499
505
  jsonc: new JSONLanguage({ mode: "jsonc" }),
506
+ json5: new JSONLanguage({ mode: "json5" }),
500
507
  },
501
508
  rules: {
502
509
  "no-duplicate-keys": noDuplicateKeys,
@@ -19,6 +19,7 @@ declare namespace plugin {
19
19
  namespace languages {
20
20
  let json: JSONLanguage;
21
21
  let jsonc: JSONLanguage;
22
+ let json5: JSONLanguage;
22
23
  }
23
24
  let rules: {
24
25
  "no-duplicate-keys": {
@@ -69,10 +70,10 @@ declare class JSONLanguage implements Language {
69
70
  /**
70
71
  * Creates a new instance.
71
72
  * @param {Object} options The options to use for this instance.
72
- * @param {"json"|"jsonc"} options.mode The parser mode to use.
73
+ * @param {"json"|"jsonc"|"json5"} options.mode The parser mode to use.
73
74
  */
74
75
  constructor({ mode }: {
75
- mode: "json" | "jsonc";
76
+ mode: "json" | "jsonc" | "json5";
76
77
  });
77
78
  /**
78
79
  * The type of file to read.
@@ -19,6 +19,7 @@ declare namespace plugin {
19
19
  namespace languages {
20
20
  let json: JSONLanguage;
21
21
  let jsonc: JSONLanguage;
22
+ let json5: JSONLanguage;
22
23
  }
23
24
  let rules: {
24
25
  "no-duplicate-keys": {
@@ -69,10 +70,10 @@ declare class JSONLanguage implements Language {
69
70
  /**
70
71
  * Creates a new instance.
71
72
  * @param {Object} options The options to use for this instance.
72
- * @param {"json"|"jsonc"} options.mode The parser mode to use.
73
+ * @param {"json"|"jsonc"|"json5"} options.mode The parser mode to use.
73
74
  */
74
75
  constructor({ mode }: {
75
- mode: "json" | "jsonc";
76
+ mode: "json" | "jsonc" | "json5";
76
77
  });
77
78
  /**
78
79
  * The type of file to read.
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.3.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,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eslint/json",
3
- "version": "0.2.0",
3
+ "version": "0.3.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",