-
-
Notifications
You must be signed in to change notification settings - Fork 21
Description
So I've done the following:
1. Install the package:
npm i -D eslint-plugin-jsonc`
2. Added only to the extends
section in my .eslintrc.json
, like so:
"extends": [
"eslint:recommended",
"plugin:jsonc/recommended-with-jsonc",
"next"
],
I did not configure anything else there. Just this!
And yes, it's a Next.js project. Shouldn't matter, but there you go.
3. Added the following configuration to my workspace settings: (in ./.vscode/settings.json
)
"eslint.enable": true,
"eslint.useESLintClass": true,
"eslint.alwaysShowStatus": true,
"editor.codeActionsOnSave": {
"source.fixAll": false,
"source.fixAll.eslint": true
},
"[json]": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
},
"[jsonc]": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
},
"eslint.validate": [
"javascript",
"javascriptreact",
"typescript",
"typescriptreact",
"json",
"jsonc"
],
And restarted VSCode.
(It doesn't actually matter where (workspace/user settings) or if at all this is added, as you'll see further on. It'll break on the commandline before anything else, so I might as well leave this whole step out, frankly. I'm going to leave it in for completeness though.)
4. Time to test it out!
So I've added a dead simple file, called test.json
:
{
"foo": "bar"
}
Results
On the commandline
First I installed eslint globally:
npm i -g eslint
When executing eslint test.json
I get the following error:
D:\[redacted]\test.json
2:7 error Parsing error: D:\[redacted]\test.json: Missing semicolon. (2:7)
1 | {
> 2 | "foo": "bar"
| ^
3 | }
4 |
✖ 1 problem (1 error, 0 warnings)
Semicolons in JSON 🤨 It doesn't feel quite right to me...
In VSCode
Opening that marvellously simple test file again, I get the same error on the problems panel.
When pressing Ctrl+S, I get a message on the status bar that says:
Extension 'ESLint' is configured as formatter but it cannot format `JSON`-files
This makes sense given that ESLint cannot even seem to parse a super simple json file... If it can't parse them properly, how could it ever format them, right?
What's going on? It's probably some stupid setting or a tiny little thing I've missed, because I can't believe this package being utterly broken. It doesn't feel like that kind of package 😊 It feels professional 😎 So maybe something is borking things up 🤔