Skip to content

Commit

Permalink
Switch to @eslint/json (#1749)
Browse files Browse the repository at this point in the history
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/
  • Loading branch information
ericcornelissen authored Nov 1, 2024
1 parent ab52358 commit 2b7c59e
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 204 deletions.
97 changes: 21 additions & 76 deletions config/eslint.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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"],
},
},
{
Expand Down Expand Up @@ -775,6 +721,5 @@ export default [
],
},

...jsonc.configs["flat/base"],
...yml.configs["flat/base"],
];
152 changes: 25 additions & 127 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down

0 comments on commit 2b7c59e

Please sign in to comment.