eslint / json

JSON language plugin for ESLint
Apache License 2.0
18 stars 2 forks source link

Bug: @eslint/json ir returning an error when it parse package.json file #31

Open Byron2016 opened 5 hours ago

Byron2016 commented 5 hours ago

Environment

ESLint version: 9.11.1 @eslint/json version: 9.11.1 Node version: v20.17.0 npm version: 10.8.3 Operating System: Windows 10 Pro 22H2 (19045.4894)

Which language are you using?

json

What did you do?

package.json

  {
    "name": "borrar_001",
    "version": "1.0.0",
    "description": "",
    "main": "index.js",
    "type": "module",
    "scripts": {
      "test": "echo \"Error: no test specified\" && exit 1",
      "inspector": "eslint --inspect-config",
      "lint": "eslint .",
      "lint:f": "eslint . --fix"
    },
    "keywords": [],
    "author": "",
    "license": "ISC",
    "devDependencies": {
      "@eslint/js": "^9.11.1",
      "@eslint/json": "^0.5.0",
      "@eslint/markdown": "^6.1.1",
      "eslint": "^9.11.1",
      "eslint-plugin-react": "^7.37.1",
      "globals": "^15.10.0",
      "typescript-eslint": "^8.8.0"
    }
  }

eslint.config.mjs

import globals from "globals";
import pluginJs from "@eslint/js";
import tseslint from "typescript-eslint";
import pluginReact from "eslint-plugin-react";

import json from "@eslint/json";
import markdown from "@eslint/markdown";

export default [
  {
    ignores: ["node_modules", "dist"],
  },
  {
    plugins: {
      json,
      markdown,
    },
  },
  // lint JSON files
  {
    files: ["**/*.json"],
    language: "json/json",
    rules: {
      "json/no-duplicate-keys": "error",
      // "no-irregular-whitespace": "off",
    },
  },

  // lint MARKDOWN files
  {
    files: ["**/*.md"],
    plugins: {
      markdown,
    },
    language: "markdown/commonmark",
    rules: {
      "markdown/no-html": "error",
    },
  },
  { files: ["**/*.{js,mjs,cjs,ts,jsx,tsx}"] },
  { languageOptions: { globals: globals.browser } },
  pluginJs.configs.recommended,
  ...tseslint.configs.recommended,
  pluginReact.configs.flat.recommended,
];

What did you expect to happen?

lint package.json without problem

What actually happened?

command executed

pnpm run lint

Error message

` Warning: React version not specified in eslint-plugin-react settings. See https://github.com/jsx-eslint/eslint-plugin-react#configuration .

Oops! Something went wrong! :(

ESLint: 9.11.1

TypeError: Error while loading rule 'no-irregular-whitespace': sourceCode.getAllComments is not a function Occurred while linting C:\Users\user_01\borrar_001\package.json at Object.create (C:\Users\user_01\borrar_001\node_modules.pnpm\eslint@9.11.1\node_modules\eslint\lib\rules\no-irregular-whitespace.js:87:41) at createRuleListeners (C:\Users\user_01\borrar_001\node_modules.pnpm\eslint@9.11.1\node_modules\eslint\lib\linter\linter.js:943:21) at C:\Users\user_01\borrar_001\node_modules.pnpm\eslint@9.11.1\node_modules\eslint\lib\linter\linter.js:1068:84 at Array.forEach () at runRules (C:\Users\user_01\borrar_001\node_modules.pnpm\eslint@9.11.1\node_modules\eslint\lib\linter\linter.js:999:34) at #flatVerifyWithoutProcessors (C:\Users\user_01\borrar_001\node_modules.pnpm\eslint@9.11.1\node_modules\eslint\lib\linter\linter.js:1914:31) at Linter._verifyWithFlatConfigArrayAndWithoutProcessors (C:\Users\user_01\borrar_001\node_modules.pnpm\eslint@9.11.1\node_modules\eslint\lib\linter\linter.js:1995:49) at Linter._verifyWithFlatConfigArray (C:\Users\user_01\borrar_001\node_modules.pnpm\eslint@9.11.1\node_modules\eslint\lib\linter\linter.js:2084:21) at Linter.verify (C:\Users\user_01\borrar_001\node_modules.pnpm\eslint@9.11.1\node_modules\eslint\lib\linter\linter.js:1528:61) at Linter.verifyAndFix (C:\Users\user_01\borrar_001\node_modules.pnpm\eslint@9.11.1\node_modules\eslint\lib\linter\linter.js:2322:29)  ELIFECYCLE  Command failed with exit code 2. `

Link to Minimal Reproducible Example

https://github.com/Byron2016/b_eslint_json_error_001

Participation

Additional comments

No response

bmeck commented 5 hours ago

Isn't no-irregular-whitespace a JS rule?

Byron2016 commented 4 hours ago

Isn't no-irregular-whitespace a JS rule?

@bmeck if you comment eslint/json configuration section (eslint.config.mjs) the error dissapear, I think could exist a conflict with eslint?