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

Bugfixes in Indentation Rule #376

Merged
merged 10 commits into from
Oct 9, 2020
Merged

Bugfixes in Indentation Rule #376

merged 10 commits into from
Oct 9, 2020

Conversation

petertrr
Copy link
Member

@petertrr petertrr commented Oct 7, 2020

What's done:

  • Increased indentation after an arrow in when expressions
  • Increased indentation before elvis
  • Fixed error in aligning parameters
  • when there are comments in dot-calls chain, indentation of statement right after a comment is too long
  • exceptional indentation is broken after a comment, even though it should spread on the statement after comment
  • as, is and other infix functions should increase indentation
  • Tests
  • Code style fixes

This pull request closes #349

### What's done:
* Increased indentation after an arrow in when expressions
* Increased indentation before elvis
* Fixed error in aligning parameters
* Tests
@codecov
Copy link

codecov bot commented Oct 7, 2020

Codecov Report

Merging #376 into master will increase coverage by 0.02%.
The diff coverage is 67.69%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #376      +/-   ##
============================================
+ Coverage     82.97%   83.00%   +0.02%     
- Complexity     1251     1252       +1     
============================================
  Files            61       61              
  Lines          3078     3101      +23     
  Branches        976      986      +10     
============================================
+ Hits           2554     2574      +20     
+ Misses          170      169       -1     
- Partials        354      358       +4     
Flag Coverage Δ Complexity Δ
#unittests 83.00% <67.69%> (+0.02%) 1252.00 <12.00> (+1.00)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ Complexity Δ
...fn/diktat/ruleset/rules/kdoc/CommentsFormatting.kt 71.11% <40.00%> (ø) 61.00 <0.00> (ø)
.../cqfn/diktat/ruleset/rules/BlockStructureBraces.kt 83.00% <50.00%> (+0.34%) 53.00 <5.00> (ø)
.../kotlin/org/cqfn/diktat/ruleset/utils/KDocUtils.kt 6.66% <50.00%> (ø) 0.00 <0.00> (ø)
.../cqfn/diktat/ruleset/utils/indentation/Checkers.kt 76.59% <70.00%> (+0.59%) 0.00 <0.00> (ø)
...cqfn/diktat/ruleset/rules/files/IndentationRule.kt 87.62% <75.00%> (+1.31%) 25.00 <4.00> (+1.00)
.../org/cqfn/diktat/ruleset/rules/IdentifierNaming.kt 83.18% <100.00%> (ø) 72.00 <0.00> (ø)
...n/diktat/ruleset/rules/StringTemplateFormatRule.kt 92.85% <100.00%> (ø) 9.00 <3.00> (ø)
...tlin/org/cqfn/diktat/ruleset/utils/AstNodeUtils.kt 82.91% <100.00%> (ø) 0.00 <0.00> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 021aad1...79b3f45. Read the comment docs.

### What's done:
* Code style
### What's done:
* Logic of comments
### What's done:
* Fixes
@petertrr petertrr force-pushed the feature/indentation#349 branch from 1073341 to c55a224 Compare October 8, 2020 12:27
@petertrr petertrr marked this pull request as ready for review October 8, 2020 13:00
@petertrr petertrr requested review from kentr0w and aktsay6 and removed request for kentr0w October 8, 2020 13:20
private fun ASTNode.getExceptionalIndentInitiator() = treeParent.let { parent ->
when (parent.psi) {
// fixme: custom logic for determining exceptional indent initiator, should be moved elsewhere
is KtDotQualifiedExpression -> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

braces not needed?
and yes I would also move it away

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At first there was hack for only one case, but now that there are several I think it should be extracted to CheckResult, for example. I think I'll better do it in the next PR, because this is for sure not the last bug in indentation logic.

val ktFile = whiteSpace.parents.last() as KtFile
ktFile.text
.lineSequence()
.scan(0 to "") { (length, _), s -> length + s.length + 1 to s }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add comments of what are you doing here or move to some method. Now it looks like some hack, I do not understand

Copy link
Member Author

@petertrr petertrr Oct 9, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I will add comments. Basically, I just find a particular line using node's offset and then calculate column number for this node. Ktlint does this already when formatting warning messages, but you can't access that method from visitors.

Copy link
Member

@orchestr7 orchestr7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

approved

### What's done:
* Code style
@petertrr petertrr merged commit 84bd80f into master Oct 9, 2020
@petertrr petertrr deleted the feature/indentation#349 branch October 9, 2020 13:38
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.

More bugs in IndentationRule
2 participants