eslint-plugin-json
eslint-plugin-json copied to clipboard
Support --fix to fix JSON issues
Currently there is no support for fixing the json errors using --fix flag.
That's a great idea! Will tag as help wanted
in case anyone wants to contribute
@aviranco That is because this library is not eslint. It's a thin wrapper around jshint and uses that library's default settings. Check the source (and package.json
) files of this module.
Man listen, I know you are upset that this plugin uses jshint but you need to stop spreading misinformation.
"This library is not eslint" makes no sense. It's an eslint plugin. Most plugins do linting without using eslint (because otherwise there would be no reason for them to exist). Additionally, being able to support --fix
is again independent of how the plugin implements linting. jshint doesn't make it easy to add the --fix
support but we could still implement it manually or by switching to something like https://github.com/zaach/jsonlint
@azeemba
- I think "I know you are upset" and the "spreading misinformation" bit are both really inappropriate here. @sirlancelot's statement is factual.
- Just to clarify - this plugin doesn't apply (or attempt to apply) any ESLint rules to JSON source, right? It literally just invokes a separate library. So if I have a certain setup for indentation, or use
eslint-plugin-prettier
, this plugin won't feed the JSON into that pipeline but would do its own thing. Correct?
This plugin does not attempt to apply general ESLint rules because it should not do so. JSON has stronger requirements than JavaScript.
If we deferred linting to ESLint then a lot of incorrect JSON will be marked as valid (since ESLint is simply following JS rules). Its also possible that if some rules like quote-props: "as-needed"
are enabled then valid JSON will be marked as invalid.
For this reason, the JSON parser must be separate from ESLint (unless of course ESLint starts adding native JSON support).
Regarding my tone from the previous post, there is some additional context in #13.
Hello people. I found a hacky way to help with this issue, but it's still kind of manual.
First, you add var x =
at the beginning of the .json
file you want to fix. (making this a javascript code..)
Second, you run eslint -c ./.eslintrc.json --fix your.json
and you ensure the
rules
of the .eslintrc.json
has "quote-props": "error"
(at least that's my intended purpose, to fix key quotes in json)
Voila, it works.. I wish there is another way, I've tried a lot of tools and this is only one I found working.
All other tools complain like "expecting STRING but found blabla.."
Hope it helps. (don't forget to remove var x =
..)
The above will fix { "rests": [ { host: "127.0.0.1" } ] }
to { "rests": [ { "host": "127.0.0.1" } ] }
Now that we have switched implementation away from JSHint and using VSCode's implementation, doing this might be feasible since the library provides a "format" method out of the box.
eslint's plugin interface doesn't make it easy for the plugins themselves to do the fixes but I believe it should be feasible. If anyone is interested in working on this, let me know and I can work with them to figure it out!
Are they any plans to add --fix
?
I started using eslint-plugin-json-format but it is less popular