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

deno-fmt-ignore behavior in JSONC is unintuitive #15422

Open
kidonng opened this issue Aug 8, 2022 · 2 comments
Open

deno-fmt-ignore behavior in JSONC is unintuitive #15422

kidonng opened this issue Aug 8, 2022 · 2 comments
Labels
deno fmt Related to the "deno fmt" subcommand or dprint suggestion suggestions for new features (yet to be agreed)

Comments

@kidonng
Copy link
Contributor

kidonng commented Aug 8, 2022

deno fmt doesn't like trailing commas in JSONC, which is mostly fine since we can just let it ignore them, but the behavior is unintuitive.

This works:

{
  // deno-fmt-ignore
  "tasks": {
    "foo": "echo bar",
  }
}
$ deno fmt --check
Checked 240 files

But this doesn't work, which places the comment to the desired location:

{
  "tasks": {
    // deno-fmt-ignore
    "foo": "echo bar",
  }
}
$ deno fmt --check

from /workspaces/lume/tests/assets/deno.jsonc:
4 | -    "foo": "echo bar",
4 | +    "foo": "echo bar"

error: Found 1 not formatted file in 240 files

This doesn't work either, though I'm not sure if other formatters support this comment style:

{
  "tasks": {
    "foo": "echo bar", // deno-fmt-ignore
  }
}
@dsherret
Copy link
Member

dsherret commented Aug 8, 2022

The reason why this occurs is because the comma is controlled by the parent object and in this case the // deno-fmt-ignore only applies to "foo": "echo bar" and not "foo": "echo bar",.

I could update the behaviour to keep the trailing comma into account, but adding ignore comments to keep trailing commas seems kind of extreme to me. I've opened dprint/dprint-plugin-json#9

@dsherret dsherret added suggestion suggestions for new features (yet to be agreed) deno fmt Related to the "deno fmt" subcommand or dprint labels Aug 8, 2022
@kidonng
Copy link
Contributor Author

kidonng commented Aug 8, 2022

the comma is controlled by the parent object

Ah, that explains it. Not very obvious when most of the time the ignore comment is next to the thing being ignored though.

adding ignore comments to keep trailing commas seems kind of extreme to me

This is a test file for JSONC parsing. I do agree real use cases are rare.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deno fmt Related to the "deno fmt" subcommand or dprint suggestion suggestions for new features (yet to be agreed)
Projects
None yet
Development

No branches or pull requests

2 participants