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

KotlinParseException on string concatenation for if expression #1190

Merged
merged 1 commit into from
Jan 27, 2022

Conversation

Cheshiriks
Copy link
Member

@Cheshiriks Cheshiriks commented Jan 26, 2022

@codecov
Copy link

codecov bot commented Jan 26, 2022

Codecov Report

Merging #1190 (7d89624) into master (237cb2c) will decrease coverage by 0.03%.
The diff coverage is 50.00%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #1190      +/-   ##
============================================
- Coverage     84.52%   84.49%   -0.04%     
+ Complexity     2515     2511       -4     
============================================
  Files           103      103              
  Lines          7055     7054       -1     
  Branches       1902     1902              
============================================
- Hits           5963     5960       -3     
  Misses          306      306              
- Partials        786      788       +2     
Flag Coverage Δ
unittests 84.49% <50.00%> (-0.04%) ⬇️

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

Impacted Files Coverage Δ
.../ruleset/rules/chapter3/StringConcatenationRule.kt 73.19% <50.00%> (-2.32%) ⬇️

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 237cb2c...7d89624. Read the comment docs.

val myTest25 = "String ${valueStr?.value}"
Copy link
Member

Choose a reason for hiding this comment

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

two issues contained 2 tests. Or they are the same?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is one problem caused by the lack of an IfExpression check.

@@ -155,7 +156,8 @@ class StringConcatenationRule(configRules: List<RulesConfig>) : DiktatRule(
val rvalueTextNew = rvalueText?.trim('"')
return "$lvalueText$rvalueTextNew"
} else if (binaryExpressionPsi.isRvalueCallExpression() || binaryExpressionPsi.isRvalueDotQualifiedExpression() ||
binaryExpressionPsi.isRvalueOperation() || binaryExpressionPsi.isRvalueSafeQualifiedExpression()) {
Copy link
Member

Choose a reason for hiding this comment

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

Do we need this branch at all? Or can it be the default behaviour (like the last branch of if) when right side is a general KtExpression? I don't like that we need to add so many types here, I bet it will fire once again on something else.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I agree.
Fixed

Copy link
Member

Choose a reason for hiding this comment

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

What is the reason to leave separate branch for call expression?

Copy link
Member Author

@Cheshiriks Cheshiriks Jan 26, 2022

Choose a reason for hiding this comment

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

ReferenceExpression is always a child for the CallExpression. That's why the CallExpression requires a separate condition.
example

  • -foo() [CallExpression]
  • -- foo [ReferenceExpression]

Copy link
Member

Choose a reason for hiding this comment

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

But then isRvalueReferenceExpression() will be false and we'll get in .isRvalueExpression() condition, won't we?

Copy link
Member Author

@Cheshiriks Cheshiriks Jan 26, 2022

Choose a reason for hiding this comment

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

No isRvalueReferenceExpression return true if parent or first child will be True
Снимок экрана 2022-01-26 в 18 57 20

@Cheshiriks Cheshiriks force-pushed the bugfix/if-expression branch 2 times, most recently from 3aad270 to a4e4d51 Compare January 26, 2022 13:53
### What's done:
* fixed if expression in rule
closes #1076, #1141
@Cheshiriks Cheshiriks merged commit 2df05de into master Jan 27, 2022
@Cheshiriks Cheshiriks deleted the bugfix/if-expression branch January 27, 2022 13:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants