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

--indent option does not work if changes are only to indentation #54

Closed
raijinsetsu opened this issue May 21, 2021 · 1 comment
Closed

Comments

@raijinsetsu
Copy link

Description

  1. Execute syncpack format --source "PATH-TO-PACKAGE-JSON" to make sure properties are now in the correct order
  2. Execute syncpack format --indent '....' --source "PATH-TO-PACKAGE-JSON"
  3. Review package.json - notice that .... is not used as indentation.

The expected output is that indentation will be four periods (this is purely for demonstration purposes).

Suggested Solution

The issue appear to be here: https://github.com/JamieMason/syncpack/blob/master/src/commands/lib/write-if-changed.ts#L11
The comparison is the trimmed input line (meaning: no leading white space) with the indent added in front. When you compare that to the "after", there are no differences because the order of the keys is not changing at all.

Based on the fact that the parser does not take white-space into account, there are two options:

  1. use a parser other than JSON.parse which will take the white-space into account
  2. update the documentation to indicate that "--indent" only applies when other modifications are made; so from -i, --indent [value] override indentation. defaults to " " to -i, --indent [value] the indentation to use if other modifications are made. defaults to " "
@JamieMason
Copy link
Owner

Fix released in 5.8.14 🎉

Thanks for reporting this @raijinsetsu

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants