Update: Make indent
report lines with mixed spaces/tabs (fixes #4274)
#7076
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.
What issue does this pull request address?
#4274
What changes did you make? (Give an overview)
This updates the
indent
rule to parse both tabs and spaces as indent characters, regardless of which character lines are supposed to have. For example, if a line is supposed to be indented with two spaces, and it starts with two spaces followed by a tab, the line will get reported because the tab isn't supposed to be there. (Previously, the line would not get reported because the tab wasn't considered an indentation character in "spaces mode".)Since it now has the ability to detect both spaces and tabs, the rule can also give more detailed error messages, e.g.
Expected indentation of 8 spaces but found 4 spaces and 2 tabs.
This PR also updates the
getNodeIndent
function to only check indentation up to the first non-whitespace character on the node's line, rather than up to the node itself. This makes the logic a bit simpler; for example, lines that start with commas are no longer a special case. This also avoids the issues referenced here where multiline comments could get mangled by the autofixer.Is there anything you'd like reviewers to focus on?
This PR makes a few significant changes to the autofix logic. For example, all of the indentation on a reported line is now always replaced by the fixer. We should verify that this change doesn't introduce any regressions.