nixfmt
nixfmt copied to clipboard
Formatting only specific line ranges
The context for this is here.
For a more future-proof solution, we should consider implementing a partial formatter mode, which can be told to format only specific line ranges of a file. This way we can extend the conflict-avoiding trick to format all line ranges that aren't touched by recent PRs.
The alternative of just ripping the band-aid off and formatting all files at some point also works, and would be much simpler at the expense of more conflicts. But especially as we change the formatter again over time we'll run into the same problem over and over again, whereas the line range conflict-avoiding trick would enable a smooth mode of operation that almost never causes any churn for other users.
Nixfmt works by pretty-printing parsed AST nodes. How should it deal with partial nodes, especially at the line boundaries? Also, how does it know the base indentation to use? It could calculate that from the global AST but it may differ from the unformatted parts