ota-meshi / eslint-plugin-jsonc

ESLint plugin for JSON(C|5)? files
https://ota-meshi.github.io/eslint-plugin-jsonc/
MIT License
199 stars 17 forks source link

JSON6 #4

Open brettz9 opened 4 years ago

brettz9 commented 4 years ago

Looks like a great tool...

Might you add tests and docs indicating support for JSON6 if it may work? https://github.com/d3x0r/JSON6

ota-meshi commented 4 years ago

Thank you for this issue!

I didn't know JSON6 so I read the documentation. JSON6 does not seem to be a syntax that extends JSON by incorporating ES syntax.

e.g.

{`a`:123}

https://github.com/d3x0r/JSON6/blob/cce1dd3faf8ba551d36ec7917610c2bbea83a778/test/json6Test.js#L207

If JSON6 has a syntax that is unrelated to ES syntax, I think it difficult to support JSON6 with this plugin.

brettz9 commented 4 years ago

Right, it is a superset, but it could still be useful to lint against the ES-safe subset of that superset. (I've asked at https://github.com/d3x0r/JSON6/issues/44#issuecomment-657477928 whether the ES-safe subset could be enforced at the level of the parser, but even if not, I'd think a caveat that the plugin only supports the safe subset might be enough.)

ota-meshi commented 4 years ago

Perhaps supporting some JSON6 syntax can be a useful case even for users who don't use JSON6.

Currently, the parser provided by this plugin treats AST that cannot be parsed by JSON5 as a parsing error. I think it would be useful for people to change the parser to accept static values and add new rules so that they can be autofix.

For example, autofix {foo: `bar`} with the new rule jsonc/no-template-literals will convert it to {foo: "bar"}. More, it is converted to {"foo": "bar"} by the existing jsonc/quote-props rule. This is useful when replacing .xxxrc.js to .xxxrc.json.

I probably need to make the following changes:

I will work on these when I have time.

However, the following JSON6 syntax still cannot be parsed:

(I'm not familiar with it, so there may be others.)

brettz9 commented 4 years ago

Re: underscores separating digits, just as an FYI, it looks like there is https://babeljs.io/docs/en/babel-plugin-syntax-numeric-separator for the syntax alone, and https://babeljs.io/docs/en/babel-plugin-proposal-numeric-separator if transforming it, so if users applied the plugin with babel-eslint, I'd think they could get that feature. I imagine it should come to espree eventually, however.

ota-meshi commented 4 years ago

I know that babel-eslint can parse Stage 3 syntax. However, I'm not understand of the side effects as JSON due to the other Stage3 syntax by making babel-eslint available. So, I still want to support only syntax that espree can parse.

If I have the time to learn a lot of syntax it might support it, but maybe it's faster to change the Numeric Separators to Stage 4 😅

brettz9 commented 4 years ago

FWIW, I've filed https://github.com/d3x0r/JSON6/issues/46 which also indicates a few other features where JSON6 diverges from ES.

ota-meshi commented 4 years ago

I changed the parser to allow some syntax, added rules to report the syntax allowed by the parser, and released it. https://github.com/ota-meshi/eslint-plugin-jsonc/releases/tag/v0.2.0

However, I do not yet provide a ruleset for JSON6. Now, additional configuration is required to make this plugin work with .json6. https://ota-meshi.github.io/eslint-plugin-jsonc/user-guide/#faq

I'm learning the syntax of JSON6 while also referring to the issue you posted in JSON6 repo.

brettz9 commented 4 years ago

Excellent, thanks!

If you find any, I'd be most grateful if you could mention on the issue any areas where JSON6 differs from ES (besides those I've mentioned).