Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON6 #4

Open
brettz9 opened this issue Jul 12, 2020 · 8 comments
Open

JSON6 #4

brettz9 opened this issue Jul 12, 2020 · 8 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@brettz9
Copy link

brettz9 commented Jul 12, 2020

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
Copy link
Owner

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
Copy link
Author

brettz9 commented Jul 13, 2020

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 d3x0r/JSON6#44 (comment) 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
Copy link
Owner

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:

  • The parser allows static template literals.
  • The parser allows undefined identifier.
  • The parser allows empty slots in array literals.
  • Add jsonc/no-template-literals rule.
  • Add jsonc/no-undefined rule.
  • Add jsonc/no-sparse-arrays rule.

I will work on these when I have time.

However, the following JSON6 syntax still cannot be parsed:

  • back-tick quoted key.
  • multiple minus signs.
  • underscores separating digits. (current espree cannot parsed it.)

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

@brettz9
Copy link
Author

brettz9 commented Jul 14, 2020

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
Copy link
Owner

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
Copy link
Author

brettz9 commented Jul 14, 2020

FWIW, I've filed d3x0r/JSON6#46 which also indicates a few other features where JSON6 diverges from ES.

@ota-meshi
Copy link
Owner

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
Copy link
Author

brettz9 commented Jul 16, 2020

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).

@ota-meshi ota-meshi added the enhancement New feature or request label Dec 14, 2020
@JounQin JounQin added the help wanted Extra attention is needed label Jul 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants