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

Bugfix. Bug in autofix in string templates #780

Merged
merged 12 commits into from
Mar 9, 2021

Conversation

aktsay6
Copy link
Collaborator

@aktsay6 aktsay6 commented Feb 17, 2021

What's done:

  • Fixed bug
  • Added to smoke test

This pull request closes #766

### What's done:
  * Fixed bug
@aktsay6 aktsay6 added the bug Something isn't working label Feb 17, 2021
@codecov
Copy link

codecov bot commented Feb 17, 2021

Codecov Report

Merging #780 (04640ff) into master (fbb6a20) will decrease coverage by 0.00%.
The diff coverage is 80.00%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #780      +/-   ##
============================================
- Coverage     80.93%   80.92%   -0.01%     
- Complexity     2194     2203       +9     
============================================
  Files            98       98              
  Lines          5653     5666      +13     
  Branches       1747     1753       +6     
============================================
+ Hits           4575     4585      +10     
- Misses          284      285       +1     
- Partials        794      796       +2     
Flag Coverage Δ Complexity Δ
unittests 80.92% <80.00%> (-0.01%) 0.00 <11.00> (ø)

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

Impacted Files Coverage Δ Complexity Δ
...at/ruleset/rules/chapter3/files/IndentationRule.kt 82.97% <80.00%> (-0.62%) 47.00 <11.00> (+9.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 fbb6a20...04640ff. Read the comment docs.

### What's done:
  * Fixed bug
templateEntries.forEach { node ->
if (!node.text.contains("\n") && node.text.isNotBlank()) {
val correctedText = StringBuilder()
when {
Copy link
Member

@orchestr7 orchestr7 Feb 17, 2021

Choose a reason for hiding this comment

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

very overloaded logic!
need to split it somehow (methods?)

or at least (!!) move node.treePrev.elementType in stringLiteralTokens to variable/method

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Moved it to method

@@ -18,3 +18,10 @@ val text =
x
"""

val dockerFileAsText =
Copy link
Member

Choose a reason for hiding this comment

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

not enough tests, you have created more conditions than in this testcase

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added to fix tests

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.

simplify logic

### What's done:
  * Fixed bug

val dockerFileAsText =
"""
FROM $baseImage
Copy link
Member

Choose a reason for hiding this comment

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

@aktsay6 the issue was about a bug with disappearing spaces. We shouldn't change indentation of different lines of a string, because this way we obviously change the string itself. We could only move all strings at once, if there is trimIdent or trimMargin.

### What's done:
  * Fixed bug
Copy link
Member

@petertrr petertrr left a comment

Choose a reason for hiding this comment

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

@aktsay6 please fix code style and we'll merge it

### What's done:
  * Fixed code style
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.

please change the logic

correctedText.append(node.firstChildNode.text.trimEnd())
}
// if string template is after literal_string
node.treePrev.elementType !in stringLiteralTokens && node.treeNext.elementType in stringLiteralTokens -> {
Copy link
Member

@orchestr7 orchestr7 Mar 2, 2021

Choose a reason for hiding this comment

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

Please create two expressions for node.treePrev.elementType in stringLiteralTokens and node.treeNext.elementType in stringLiteralTokens. And unify this logic

### What's done:
  * Fixed code style
### What's done:
  * Fixed code style
node.treePrev.elementType in stringLiteralTokens && node.treeNext.elementType !in stringLiteralTokens -> {
correctedText.append(node.firstChildNode.text.trimEnd())
}
isPrevStringTemplate && !isNextStringTemplate -> correctedText.append(node.firstChildNode.text.trimEnd())
Copy link
Member

Choose a reason for hiding this comment

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

Can these conditions be true simultaneously?

@@ -290,16 +283,10 @@ class IndentationRule(configRules: List<RulesConfig>) : DiktatRule(
private fun ASTNode.getExceptionalIndentInitiator() = treeParent.let { parent ->
when (parent.psi) {
// fixme: custom logic for determining exceptional indent initiator, should be moved elsewhere
is KtDotQualifiedExpression -> {
// get the topmost expression to keep extended indent for the whole chain of dot call expressions
Copy link
Member

Choose a reason for hiding this comment

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

This comment shouldn't be extracted outside of the code block. Is diktat doing this now? Seems like a bug

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

May be a possible bug. I will open an issue

### What's done:
  * Fixed code style
### What's done:
  * Fixed code style
### What's done:
  * Fixed code style
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.

lgtm

@petertrr petertrr merged commit 8891a13 into master Mar 9, 2021
@petertrr petertrr deleted the bugfix/string-templates-autofix(#766) branch March 9, 2021 10:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug in autofix in string templates
3 participants