-
EnvironmentESLint version: 9.14.0 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 Examplehttps://github.com/ajslater/eslint-json-example Participation
Additional commentsThis 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? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
Experiencing the same issue. I've been looking at it for a long time assuming I did something wrong. |
Beta Was this translation helpful? Give feedback.
-
Thanks for the issue @ajslater. The recommended usage for import js from "@eslint/js";
import json from "@eslint/json";
export default [
{
files: ["**/*.js"],
rules: js.configs.recommended.rules,
},
{
files: ["**/*.json"],
language: "json/json",
...json.configs.recommended,
},
]; The Note that unlike |
Beta Was this translation helpful? Give feedback.
-
Thanks for your response. The behavior seemed so different from what I expected that I suspected I was misunderstanding the intended usage. Your example above as a minimal case of intended usage might be useful on the main README. I guess to use this module properly I'll have to move all my many plugins into a |
Beta Was this translation helpful? Give feedback.
Thanks for the issue @ajslater. The recommended usage for
@eslint/js
(and also for@eslint/json
) is to include afiles
specifier along with the other config properties. I.e. in the case of your config:The
files
list in the first config object causes the rules injs.configs.recommended
to apply only to files with the .js extension, if that's what you are using for your JavaScript files, and .json files won't be linted by those rules any more…