feat(shfmt): add automatic indentation detection #481
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This adds the automatic setting of
-i
so thatshfmt
follows the current indentation settings of neovim. Whether it is manually set by the user or set through external factors such as.editorconfig
I also checked to see if this is done elsewhere for other formatters and found a couple others which I was able to improve the "correctness" of their indentation size calculations
EDIT: I was thinking about this and it seems like having the effective
shiftwidth
value is quite nice. And because this seems to be "contextual information" it seemed natural to put it in theconform.Context
type since it is virtually free to calculate performance wise. Let me know if you disagree. Another approach would be to make some sort of utility module that is imported by formatters on an as needed basis that calculates this. This is basically the same asvim.fn.shiftwidth
(:h shiftwidth()
) with the only difference being that it calculates it specifically for the buffer in the context rather than the "current buffer". This allowed for a very nice refactor across the formatters that utilize this field and is available for future formatters. Also nice to make sure we have a common method for calculating indentation size.Also
shiftwidth
andtabstop
are always integers according to the neovim docs so no need to have default fallbacks or check fornil