Skip to content

Don't report UseDataClass if class contains non-property parameters - #6173

Merged
BraisGabin merged 2 commits into
detekt:mainfrom
VirtualParticle:fix-UseDataClass-parameter-bug
Jun 5, 2023
Merged

Don't report UseDataClass if class contains non-property parameters#6173
BraisGabin merged 2 commits into
detekt:mainfrom
VirtualParticle:fix-UseDataClass-parameter-bug

Conversation

@VirtualParticle

Copy link
Copy Markdown
Contributor

This fixes #6168. Currently, UseDataClass will report an error even if the class has a non-property parameter as seen in the example:

class Bar(
    val param1: String,
    foo: Int,
) {
    val baz = 2 * foo
}

Making this a data class would not compile, so the rule should not report it. This resolves that issue by checking to make sure that the class does not contain any non-property parameters before reporting it.

@codecov

codecov Bot commented Jun 1, 2023

Copy link
Copy Markdown

Codecov Report

Merging #6173 (0bcbc74) into main (9fb4353) will decrease coverage by 0.02%.
The diff coverage is 57.14%.

@@             Coverage Diff              @@
##               main    #6173      +/-   ##
============================================
- Coverage     84.45%   84.44%   -0.02%     
- Complexity     3994     3999       +5     
============================================
  Files           568      568              
  Lines         13428    13434       +6     
  Branches       2372     2377       +5     
============================================
+ Hits          11341    11344       +3     
  Misses          935      935              
- Partials       1152     1155       +3     
Impacted Files Coverage Δ
...tlab/arturbosch/detekt/rules/style/UseDataClass.kt 78.75% <57.14%> (-2.34%) ⬇️

@schalkms schalkms left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This looks good to me.
Thanks for picking this up!

@schalkms schalkms added this to the 2.0.0 milestone Jun 1, 2023
@BraisGabin
BraisGabin merged commit 03b87b2 into detekt:main Jun 5, 2023
@VirtualParticle
VirtualParticle deleted the fix-UseDataClass-parameter-bug branch June 6, 2023 00:45
@cortinico cortinico added the pick request Marker for PRs that should be ported to the 1.0 release branch label Jul 15, 2023
cortinico pushed a commit to cortinico/detekt that referenced this pull request Jul 15, 2023
mgroth0 pushed a commit to mgroth0/detekt that referenced this pull request Feb 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pick request Marker for PRs that should be ported to the 1.0 release branch rules

Projects

None yet

Development

Successfully merging this pull request may close these issues.

UseDataClass false positive: "class defines no functionality"

5 participants