Skip to content

Bug: (fill in) #46

Description

@ajslater

Environment

ESLint version: 9.14.0
@eslint/json version: 0.6.0
Node version: 23.1.0
npm version: 10.9.0
Operating System: macOS

Which language are you using?

json

What did you do?

Javascript rules are run on json and eslint crashes.

package.json

{
  "devDependencies": {
    "@eslint/json": "^0.6.0",
    "eslint": "^9.14.0"
  }
}

eslint.config.js:

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

export default [
  js.configs.recommended,
  {
    files: ["**/*.json"],
    language: "json/json",
    ...json.configs.recommended,
  },
];

Test case output:

$ npx eslint package.json 
(node:43669) ExperimentalWarning: CommonJS module /opt/homebrew/lib/node_modules/npm/node_modules/debug/src/node.js is loading ES Module /opt/homebrew/lib/node_modules/npm/node_modules/supports-color/index.js using require().
Support for loading ES Module in require() is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
(node:43698) [MODULE_TYPELESS_PACKAGE_JSON] Warning: Module type of file:///Users/aj/Code/testjson/eslint.config.js?mtime=1730854966249 is not specified and it doesn't parse as CommonJS.
Reparsing as ES module because module syntax was detected. This incurs a performance overhead.
To eliminate this warning, add "type": "module" to /Users/aj/Code/testjson/package.json.
(Use `node --trace-warnings ...` to show where the warning was created)

Oops! Something went wrong! :(

ESLint: 9.14.0

TypeError: Error while loading rule 'no-irregular-whitespace': sourceCode.getAllComments is not a function
Occurred while linting /Users/aj/Code/testjson/package.json
    at Object.create (/Users/aj/Code/testjson/node_modules/eslint/lib/rules/no-irregular-whitespace.js:87:41)
    at createRuleListeners (/Users/aj/Code/testjson/node_modules/eslint/lib/linter/linter.js:943:21)
    at /Users/aj/Code/testjson/node_modules/eslint/lib/linter/linter.js:1068:84
    at Array.forEach (<anonymous>)
    at runRules (/Users/aj/Code/testjson/node_modules/eslint/lib/linter/linter.js:999:34)
    at #flatVerifyWithoutProcessors (/Users/aj/Code/testjson/node_modules/eslint/lib/linter/linter.js:1911:31)
    at Linter._verifyWithFlatConfigArrayAndWithoutProcessors (/Users/aj/Code/testjson/node_modules/eslint/lib/linter/linter.js:1992:49)
    at Linter._verifyWithFlatConfigArray (/Users/aj/Code/testjson/node_modules/eslint/lib/linter/linter.js:2081:21)
    at Linter.verify (/Users/aj/Code/testjson/node_modules/eslint/lib/linter/linter.js:1528:61)
    at Linter.verifyAndFix (/Users/aj/Code/testjson/node_modules/eslint/lib/linter/linter.js:2319:29)

What did you expect to happen?

using @eslint/json should be possible an eslint.config.js along side other rules for javascript. This is possible with @eslint/markdown if you specify the markdown processor, but @eslint/json has no included separate processor.

eslint-plugin-json and the more capable eslint-plugin-jsonc do not fail in this manner, I think because they, by default, use their own processors.

I was expecting this plugin to be able to be used to lint json included in a largely javascript project, and not only for an exclusively json project.

What actually happened?

eslint crashes trying to use javascript rules on a JSONSourceCode object. If these rules are disabled. rules from every plugin in the eslint.config.js must be disabled in the *.json section.

Link to Minimal Reproducible Example

https://github.com/ajslater/eslint-json-example

Participation

  • I am willing to submit a pull request for this issue.

Additional comments

This plugin seemed to be advertised to be a replacement fro eslint-plugin-json and eslint-plugin-jsonc, but isn't if it can't exist alongside other plugins. Perhaps I'm misunderstanding it's utility?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingrepro:neededThis issue should include a reproducible example

    Type

    No type

    Projects

    • Status
      Complete

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions