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. Inspect the logic of the data class rule #761

Merged
merged 6 commits into from
Feb 9, 2021

Conversation

aktsay6
Copy link
Collaborator

@aktsay6 aktsay6 commented Feb 8, 2021

What's done:

  • Logic extended

This pull request closes #750

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

codecov bot commented Feb 8, 2021

Codecov Report

Merging #761 (c4284b9) into master (2551330) will increase coverage by 0.00%.
The diff coverage is 81.81%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master     #761   +/-   ##
=========================================
  Coverage     79.79%   79.79%           
- Complexity     2019     2025    +6     
=========================================
  Files            97       97           
  Lines          5078     5089   +11     
  Branches       1621     1626    +5     
=========================================
+ Hits           4052     4061    +9     
  Misses          246      246           
- Partials        780      782    +2     
Flag Coverage Δ Complexity Δ
unittests 79.79% <81.81%> (+<0.01%) 0.00 <0.00> (ø)

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

Impacted Files Coverage Δ Complexity Δ
.../ruleset/rules/chapter6/classes/DataClassesRule.kt 71.18% <81.81%> (+2.43%) 36.00 <0.00> (+6.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 2551330...c4284b9. Read the comment docs.

val hasPropertyInConstructor = findChildByType(PRIMARY_CONSTRUCTOR)
?.let { constructor ->
(constructor.psi as KtPrimaryConstructor)
.valueParameters
.run { isNotEmpty() && all { it.hasValOrVar() } }
.run { isNotEmpty() && all { if (it.hasValOrVar()) true else { constructorParametersNames.add(it.name!!); false } } }
Copy link
Member

Choose a reason for hiding this comment

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

I'd move this add into separate onEach before run, now it's not very readable

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed

val initBlocks = findChildByType(CLASS_BODY)?.getAllChildrenWithType(CLASS_INITIALIZER)
initBlocks?.forEach { init ->
val refExpressions = init.findAllNodesWithSpecificType(REFERENCE_EXPRESSION)
if (refExpressions.any { it.text !in constructorParametersNames }) {
Copy link
Member

Choose a reason for hiding this comment

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

Is it right? Shouldn't it be 'any in'? Also please add tests with more parameters and more complex init blocks

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Should be. Added more tests

### What's done:
  * Added tests
  * Fixed bugs
val initBlocks = findChildByType(CLASS_BODY)?.getAllChildrenWithType(CLASS_INITIALIZER)
initBlocks?.forEach { init ->
val refExpressions = init.findAllNodesWithSpecificType(REFERENCE_EXPRESSION)
if (refExpressions.any { it.text in constructorParametersNames }) {
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 a test that would have passed when there was a mistake with !in and shouldn't actually pass.

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

### What's done:
  * Added tests
  * Fixed bugs
@aktsay6 aktsay6 merged commit 208c1ed into master Feb 9, 2021
@aktsay6 aktsay6 deleted the bugfix/data-classes-secondary-constructor(#750) branch February 9, 2021 13:30
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.

Inspect the logic of the data class rule
2 participants