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

Empty objects get split by newline with --pretty-print, then fails without #19

Open
swantzter opened this issue Mar 16, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@swantzter
Copy link

Reproduction: https://github.com/swantzter/jsonlint-repro

Hi, we're having an issue where there's inconsistent behaviours between --pretty-print and "just" linting when it comes to empty objects.

When pretty-print serialises an object it outputs {\n} whereas the lint want it to become just {}

Given the above reproduction and test.json:

{
  "obj1": {},
  "obj2": {
  }
}

running npm run lint:fix (jsonlint --in-place --pretty-print) changes the file and outputs the following

{
  "obj1": {
  },
  "obj2": {
  }
}

Running npm run lint (jsonlint) after that makes it complain:

test.json: 1 hunk differs
===================================================================
--- test.json.orig
+++ test.json
@@ -1,6 +1,4 @@
 {
-  "obj1": {
-  },
-  "obj2": {
-  }
+  "obj1": {},
+  "obj2": {}
 }
@prantlf prantlf added the bug Something isn't working label Aug 9, 2024
@prantlf
Copy link
Owner

prantlf commented Aug 9, 2024

Yes, --pretty-print will insert line breaks into empty objects, otherwise they'll be formatted only as two braces - {}.

This file can be checked by jsonlint --check:

{
  "obj1": {},
  "obj2": {}
}

And this file can be checked by jsonlint --check --pretty-print:

{
  "obj1": {
  },
  "obj2": {
  }
}

It's a clumsy workaround. I'll try to come up with some fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants