You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If my root tsconfig contains comments, running nx format:write deletes them.
Expected Behavior
For the comments to be preserved. This is a pretty serious concern because users may lose their work if they run nx format:write prior to committing. This is very dangerous.
I think this should also be up to the appropriate codebase's formatting rules and Nx shouldn't enforce un-configurable formatting rules. And I believe with Nx 20, there's less emphasis on using tsconfig to resolve peer packages, so this feels unnecessary.
If Nx really wants to impose formatting... Formatting is an extremely complex task and it should be delegated to the appropriate tools that have been thoroughly tested. For example, eslint-plugin-jsonc handles JSON key sorting well while preserving comments.
Also, it should be documented in the format:write docs that it imposes a sorting order to your tsconfig that's unconfigurable.
GitHub Repo
No response
Steps to Reproduce
Add comments to the root tsconfig file (e.g. tsconfig.base.json)
Run nx format:write
Observe that the comments in the tsconfig file get deleted
Current Behavior
If my root tsconfig contains comments, running
nx format:write
deletes them.Expected Behavior
For the comments to be preserved. This is a pretty serious concern because users may lose their work if they run
nx format:write
prior to committing. This is very dangerous.I think this should also be up to the appropriate codebase's formatting rules and Nx shouldn't enforce un-configurable formatting rules. And I believe with Nx 20, there's less emphasis on using tsconfig to resolve peer packages, so this feels unnecessary.
If Nx really wants to impose formatting... Formatting is an extremely complex task and it should be delegated to the appropriate tools that have been thoroughly tested. For example, eslint-plugin-jsonc handles JSON key sorting well while preserving comments.
Also, it should be documented in the
format:write
docs that it imposes a sorting order to your tsconfig that's unconfigurable.GitHub Repo
No response
Steps to Reproduce
tsconfig.base.json
)nx format:write
Nx Report
Not relevant
Failure Logs
No response
Package Manager Version
N/A
Operating System
Additional Information
This is happening because of this:
nx/packages/nx/src/command-line/format/format.ts
Lines 256 to 266 in 1dd401c
It reads the tsconfig JSON, parses it with a JSONC parser (which doesn't retain comment data), sorts it, and overrides the file.
The text was updated successfully, but these errors were encountered: