Respect continuation indent size, make IndentationRule more intelligent #104
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.
closes #76
Motivation
In my project, indent size is 4, but continuation size is 6. It means, that condition
line.length % indent != 0
always fails.Implementation details
Rule now calculates indent size relatively to parent element and compares it to expected indent size. Rule knows several cases when continuation indent should be used. For sure, it's not a complete list of cases. These are emerged during testing on my code base and I expect to see more of them when other people start to use it.
Configuration
Continuation indent size can be specified via
continuation_indent_size
from.editorconfig
. By default, regular indent size is used.Backward compatibility
Due to the fact, that previous implementation was too permissive, I expected that current rule can find some new violation. But for well formatted code, it should return same result. Of course, for the cases when
continuation_indent_size % indent_size == 0
Performance
I haven't noticed any major performance impacts. I've tested it on codebase with approximately 1800 kt files.
0.12.1
takes ~16s and new version takes ~ 17sNevertheless, I think about current implementation as "first working approach". I'm pretty sure that it can be improved either by using existing "Utils" class, either my implementing more intelligent and fast parent indent size.