Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Respect continuation indent size, make IndentationRule more intelligent #104

Merged
merged 1 commit into from
Nov 21, 2017

Conversation

MyDogTom
Copy link
Contributor

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 ~ 17s
Nevertheless, 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.

Rule now verifies exact indent size relatively to parent.
By default, continuation indent size is equal to indent size.
It can be modified via "continuation_indent_size" from .editorconfig
@shyiko
Copy link
Collaborator

shyiko commented Nov 21, 2017

This is an amazing work, @MyDogTom! Thank You! 🏆

@shyiko shyiko merged commit ed443f4 into pinterest:master Nov 21, 2017
shyiko added a commit that referenced this pull request Nov 21, 2017
@MyDogTom MyDogTom deleted the mydogtom/indent-rule branch November 22, 2017 08:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support .editorconfig's continuation_indent_size
2 participants