From 2b7c59e6a351ccf0f95bb57f2bb2696d413dc2a0 Mon Sep 17 00:00:00 2001 From: Eric Cornelissen Date: Fri, 1 Nov 2024 09:19:21 +0100 Subject: [PATCH] Switch to `@eslint/json` (#1749) Replaces `eslint-plugin-jsonc` by `@eslint/json`. Following [1] this replaces `eslint-plugin-jsonc` by `@eslint/json` for linting JSON(C) in this project. The motivation for this change is supported by the FAQ of the new package. The reduction in rules is further motivated by ESLint's general move away from formatting-like rules to lint-like rules, which I believe makes sense for the present project given the use of Prettier. -- 1. https://eslint.org/blog/2024/10/eslint-json-markdown-support/ --- config/eslint.js | 97 +++++++---------------------- package-lock.json | 152 ++++++++-------------------------------------- package.json | 2 +- 3 files changed, 47 insertions(+), 204 deletions(-) diff --git a/config/eslint.js b/config/eslint.js index ffc39932a..95192c2d3 100644 --- a/config/eslint.js +++ b/config/eslint.js @@ -2,7 +2,7 @@ import ava from "eslint-plugin-ava"; import jsdoc from "eslint-plugin-jsdoc"; -import jsonc from "eslint-plugin-jsonc"; +import json from "@eslint/json"; import regexp from "eslint-plugin-regexp"; import top from "@ericcornelissen/eslint-plugin-top"; import yml from "eslint-plugin-yml"; @@ -622,81 +622,27 @@ export default [ }, { name: "JSON", - files: [ - "config/**/*.json", - "config/**/*.jsonc", - ".licensee.json", - "package-lock.json", - "package.json", - ], - plugins: { jsonc }, + files: ["config/**/*.json", ".licensee.json", "package.json"], + plugins: { json }, + language: "json/json", rules: { - "no-irregular-whitespace": ["off"], - - // https://ota-meshi.github.io/eslint-plugin-jsonc/rules/ - "jsonc/array-bracket-newline": ["off"], - "jsonc/array-bracket-spacing": ["off"], - "jsonc/array-element-newline": ["off"], - "jsonc/comma-dangle": ["off"], - "jsonc/comma-style": ["error", "last"], - "jsonc/indent": ["error", 2], - "jsonc/key-name-casing": ["off"], - "jsonc/key-spacing": [ - "error", - { - afterColon: true, - beforeColon: false, - mode: "strict", - }, - ], - "jsonc/no-bigint-literals": ["error"], - "jsonc/no-binary-expression": ["error"], - "jsonc/no-binary-numeric-literals": ["error"], - "jsonc/no-comments": ["off"], - "jsonc/no-dupe-keys": ["error"], - "jsonc/no-escape-sequence-in-identifier": ["error"], - "jsonc/no-floating-decimal": ["error"], - "jsonc/no-hexadecimal-numeric-literals": ["error"], - "jsonc/no-infinity": ["error"], - "jsonc/no-irregular-whitespace": [ - "error", - { - skipStrings: true, - skipComments: false, - skipRegExps: false, - skipTemplates: false, - }, - ], - "jsonc/no-multi-str": ["error"], - "jsonc/no-nan": ["error"], - "jsonc/no-number-props": ["error"], - "jsonc/no-numeric-separators": ["error"], - "jsonc/no-octal": ["error"], - "jsonc/no-octal-escape": ["error"], - "jsonc/no-octal-numeric-literals": ["error"], - "jsonc/no-parenthesized": ["error"], - "jsonc/no-plus-sign": ["error"], - "jsonc/no-regexp-literals": ["error"], - "jsonc/no-sparse-arrays": ["error"], - "jsonc/no-template-literals": ["error"], - "jsonc/no-undefined-value": ["error"], - "jsonc/no-unicode-codepoint-escapes": ["error"], - "jsonc/no-useless-escape": ["error"], - "jsonc/object-curly-newline": ["off"], - "jsonc/object-curly-spacing": ["off"], - "jsonc/object-property-newline": ["off"], - "jsonc/quote-props": ["error", "always"], - "jsonc/quotes": [ - "error", - "double", - { - avoidEscape: false, - }, - ], - "jsonc/sort-array-values": ["off"], - "jsonc/sort-keys": ["off"], - "jsonc/space-unary-ops": ["error"], - "jsonc/valid-json-number": ["error"], + // https://github.com/eslint/json/blob/main/README.md#rules + "json/no-duplicate-keys": ["error"], + "json/no-empty-keys": ["error"], + }, + }, + { + name: "JSONC", + files: ["config/**/*.jsonc"], + plugins: { json }, + language: "json/jsonc", + languageOptions: { + allowTrailingCommas: true, + }, + rules: { + // https://github.com/eslint/json/blob/main/README.md#rules + "json/no-duplicate-keys": ["error"], + "json/no-empty-keys": ["error"], }, }, { @@ -775,6 +721,5 @@ export default [ ], }, - ...jsonc.configs["flat/base"], ...yml.configs["flat/base"], ]; diff --git a/package-lock.json b/package-lock.json index 2c250a94e..9106e3cdd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,6 +14,7 @@ "devDependencies": { "@arethetypeswrong/cli": "0.16.4", "@ericcornelissen/eslint-plugin-top": "3.4.0", + "@eslint/json": "0.6.0", "@fast-check/ava": "2.0.1", "@stryker-mutator/core": "8.6.0", "@stryker-mutator/tap-runner": "8.6.0", @@ -24,7 +25,6 @@ "eslint": "9.13.0", "eslint-plugin-ava": "15.0.0", "eslint-plugin-jsdoc": "50.4.1", - "eslint-plugin-jsonc": "2.15.1", "eslint-plugin-regexp": "2.6.0", "eslint-plugin-yml": "1.14.0", "fast-check": "3.22.0", @@ -1015,6 +1015,20 @@ "node": "^18.18.0 || ^20.9.0 || >=21.1.0" } }, + "node_modules/@eslint/json": { + "version": "0.6.0", + "resolved": "https://registry.npmjs.org/@eslint/json/-/json-0.6.0.tgz", + "integrity": "sha512-xlYoULv2QIeJnjFP4RVbPMpaGplsYo0vSIBpXP/QRnoi7oDYhVZ4u3wE5UUwI8hnhTQUMozrDhyuVFXMQ1HkMQ==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "@eslint/plugin-kit": "^0.2.0", + "@humanwhocodes/momoa": "^3.3.0" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + } + }, "node_modules/@eslint/object-schema": { "version": "2.1.4", "resolved": "https://registry.npmjs.org/@eslint/object-schema/-/object-schema-2.1.4.tgz", @@ -1106,6 +1120,16 @@ "url": "https://github.com/sponsors/nzakas" } }, + "node_modules/@humanwhocodes/momoa": { + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/@humanwhocodes/momoa/-/momoa-3.3.0.tgz", + "integrity": "sha512-X7kFLCbAQqadYJl0K9LbCZk4XZbMpG+/7OyABi6fNpYOMKei434zEfLxS5HcZV0vy/0gTDwDRFc4PzjSRsPg0w==", + "dev": true, + "license": "Apache-2.0", + "engines": { + "node": ">=18" + } + }, "node_modules/@humanwhocodes/retry": { "version": "0.3.1", "resolved": "https://registry.npmjs.org/@humanwhocodes/retry/-/retry-0.3.1.tgz", @@ -5566,75 +5590,6 @@ "eslint": "^7.0.0 || ^8.0.0 || ^9.0.0" } }, - "node_modules/eslint-plugin-jsonc": { - "version": "2.15.1", - "resolved": "https://registry.npmjs.org/eslint-plugin-jsonc/-/eslint-plugin-jsonc-2.15.1.tgz", - "integrity": "sha512-PVFrqIJa8BbM/e828RSn0SwB/Z5ye+2LDuy2XqG6AymNgPsfApRRcznsbxP7VrjdLEU4Nb+g9n/d6opyp0jp9A==", - "dev": true, - "license": "MIT", - "dependencies": { - "@eslint-community/eslint-utils": "^4.2.0", - "eslint-compat-utils": "^0.5.0", - "espree": "^9.6.1", - "graphemer": "^1.4.0", - "jsonc-eslint-parser": "^2.0.4", - "natural-compare": "^1.4.0", - "synckit": "^0.6.0" - }, - "engines": { - "node": "^12.22.0 || ^14.17.0 || >=16.0.0" - }, - "funding": { - "url": "https://github.com/sponsors/ota-meshi" - }, - "peerDependencies": { - "eslint": ">=6.0.0" - } - }, - "node_modules/eslint-plugin-jsonc/node_modules/eslint-visitor-keys": { - "version": "3.4.3", - "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-3.4.3.tgz", - "integrity": "sha512-wpc+LXeiyiisxPlEkUzU6svyS1frIO3Mgxj1fdy7Pm8Ygzguax2N3Fa/D/ag1WqbOprdI+uY6wMUl8/a2G+iag==", - "dev": true, - "license": "Apache-2.0", - "engines": { - "node": "^12.22.0 || ^14.17.0 || >=16.0.0" - }, - "funding": { - "url": "https://opencollective.com/eslint" - } - }, - "node_modules/eslint-plugin-jsonc/node_modules/espree": { - "version": "9.6.1", - "resolved": "https://registry.npmjs.org/espree/-/espree-9.6.1.tgz", - "integrity": "sha512-oruZaFkjorTpF32kDSI5/75ViwGeZginGGy2NoOSg3Q9bnwlnmDm4HLnkl0RE3n+njDXR037aY1+x58Z/zFdwQ==", - "dev": true, - "license": "BSD-2-Clause", - "dependencies": { - "acorn": "^8.9.0", - "acorn-jsx": "^5.3.2", - "eslint-visitor-keys": "^3.4.1" - }, - "engines": { - "node": "^12.22.0 || ^14.17.0 || >=16.0.0" - }, - "funding": { - "url": "https://opencollective.com/eslint" - } - }, - "node_modules/eslint-plugin-jsonc/node_modules/synckit": { - "version": "0.6.2", - "resolved": "https://registry.npmjs.org/synckit/-/synckit-0.6.2.tgz", - "integrity": "sha512-Vhf+bUa//YSTYKseDiiEuQmhGCoIF3CVBhunm3r/DQnYiGT4JssmnKQc44BIyOZRK2pKjXXAgbhfmbeoC9CJpA==", - "dev": true, - "license": "MIT", - "dependencies": { - "tslib": "^2.3.1" - }, - "engines": { - "node": ">=12.20" - } - }, "node_modules/eslint-plugin-regexp": { "version": "2.6.0", "resolved": "https://registry.npmjs.org/eslint-plugin-regexp/-/eslint-plugin-regexp-2.6.0.tgz", @@ -7894,13 +7849,6 @@ "dev": true, "license": "ISC" }, - "node_modules/graphemer": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/graphemer/-/graphemer-1.4.0.tgz", - "integrity": "sha512-EtKwoO6kxCL9WO5xipiHTZlSzBm7WLT627TqC/uVRd0HKmq8NXyebnNYxDoBi7wt8eTWrUrKXCOVaFq9x1kgag==", - "dev": true, - "license": "MIT" - }, "node_modules/handle-cli-error": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/handle-cli-error/-/handle-cli-error-5.0.0.tgz", @@ -9177,56 +9125,6 @@ "node": ">=6" } }, - "node_modules/jsonc-eslint-parser": { - "version": "2.4.0", - "resolved": "https://registry.npmjs.org/jsonc-eslint-parser/-/jsonc-eslint-parser-2.4.0.tgz", - "integrity": "sha512-WYDyuc/uFcGp6YtM2H0uKmUwieOuzeE/5YocFJLnLfclZ4inf3mRn8ZVy1s7Hxji7Jxm6Ss8gqpexD/GlKoGgg==", - "dev": true, - "license": "MIT", - "dependencies": { - "acorn": "^8.5.0", - "eslint-visitor-keys": "^3.0.0", - "espree": "^9.0.0", - "semver": "^7.3.5" - }, - "engines": { - "node": "^12.22.0 || ^14.17.0 || >=16.0.0" - }, - "funding": { - "url": "https://github.com/sponsors/ota-meshi" - } - }, - "node_modules/jsonc-eslint-parser/node_modules/eslint-visitor-keys": { - "version": "3.4.3", - "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-3.4.3.tgz", - "integrity": "sha512-wpc+LXeiyiisxPlEkUzU6svyS1frIO3Mgxj1fdy7Pm8Ygzguax2N3Fa/D/ag1WqbOprdI+uY6wMUl8/a2G+iag==", - "dev": true, - "license": "Apache-2.0", - "engines": { - "node": "^12.22.0 || ^14.17.0 || >=16.0.0" - }, - "funding": { - "url": "https://opencollective.com/eslint" - } - }, - "node_modules/jsonc-eslint-parser/node_modules/espree": { - "version": "9.6.1", - "resolved": "https://registry.npmjs.org/espree/-/espree-9.6.1.tgz", - "integrity": "sha512-oruZaFkjorTpF32kDSI5/75ViwGeZginGGy2NoOSg3Q9bnwlnmDm4HLnkl0RE3n+njDXR037aY1+x58Z/zFdwQ==", - "dev": true, - "license": "BSD-2-Clause", - "dependencies": { - "acorn": "^8.9.0", - "acorn-jsx": "^5.3.2", - "eslint-visitor-keys": "^3.4.1" - }, - "engines": { - "node": "^12.22.0 || ^14.17.0 || >=16.0.0" - }, - "funding": { - "url": "https://opencollective.com/eslint" - } - }, "node_modules/jsonc-parser": { "version": "3.3.1", "resolved": "https://registry.npmjs.org/jsonc-parser/-/jsonc-parser-3.3.1.tgz", diff --git a/package.json b/package.json index b898e2f3b..250fccd70 100644 --- a/package.json +++ b/package.json @@ -64,6 +64,7 @@ "devDependencies": { "@arethetypeswrong/cli": "0.16.4", "@ericcornelissen/eslint-plugin-top": "3.4.0", + "@eslint/json": "0.6.0", "@fast-check/ava": "2.0.1", "@stryker-mutator/core": "8.6.0", "@stryker-mutator/tap-runner": "8.6.0", @@ -74,7 +75,6 @@ "eslint": "9.13.0", "eslint-plugin-ava": "15.0.0", "eslint-plugin-jsdoc": "50.4.1", - "eslint-plugin-jsonc": "2.15.1", "eslint-plugin-regexp": "2.6.0", "eslint-plugin-yml": "1.14.0", "fast-check": "3.22.0",