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

BooleanPropertyNaming reports double for local variables (in some TBD case) #5392

Closed
TWiStErRob opened this issue Oct 8, 2022 · 6 comments
Closed
Labels
bug good first issue Issue that is easy to pickup for people that are new to the project help wanted

Comments

@TWiStErRob
Copy link
Member

TWiStErRob commented Oct 8, 2022

Context

Consider code like this (note the inferred types of all isEmpty() are Boolean):

val feed2: Feed = generateSequence { fixture.build<Feed>() }
	.first { feed2 ->
		val uniqueFilms = feed2.films.isEmpty()
		val uniqueFilms2 =
			feed2.films.map(Feed.Film::id).isEmpty()
		val uniqueAttributes =
			feed2.attributes.map(Feed.Attribute::code)
				.isEmpty()
		uniqueFilms && uniqueFilms2 && uniqueAttributes
	}

Observed Behavior

Notice the line numbers: 18, 19, 21, 18, 19, 21

> Task :backend:feed:detektTest FAILED
naming - 30min debt
        BooleanPropertyNaming - [Boolean property name should match a ^(is|has|are) pattern. Actual name is uniqu(...)] at backend\feed\src\test\kotlin\net\twisterrob\cinema\cineworld\sync\syndication\FeedTest.kt:18:5
        BooleanPropertyNaming - [Boolean property name should match a ^(is|has|are) pattern. Actual name is uniqu(...)] at backend\feed\src\test\kotlin\net\twisterrob\cinema\cineworld\sync\syndication\FeedTest.kt:19:5
        BooleanPropertyNaming - [Boolean property name should match a ^(is|has|are) pattern. Actual name is uniqu(...)] at backend\feed\src\test\kotlin\net\twisterrob\cinema\cineworld\sync\syndication\FeedTest.kt:21:5
        BooleanPropertyNaming - [Boolean property name should match a ^(is|has|are) pattern. Actual name is uniqu(...)] at backend\feed\src\test\kotlin\net\twisterrob\cinema\cineworld\sync\syndication\FeedTest.kt:18:5
        BooleanPropertyNaming - [Boolean property name should match a ^(is|has|are) pattern. Actual name is uniqu(...)] at backend\feed\src\test\kotlin\net\twisterrob\cinema\cineworld\sync\syndication\FeedTest.kt:19:5
        BooleanPropertyNaming - [Boolean property name should match a ^(is|has|are) pattern. Actual name is uniqu(...)] at backend\feed\src\test\kotlin\net\twisterrob\cinema\cineworld\sync\syndication\FeedTest.kt:21:5

Expected Behavior

1 report for each local variable.

> Task :backend:feed:detektTest FAILED
naming - 30min debt
        BooleanPropertyNaming - [Boolean property name should match a ^(is|has|are) pattern. Actual name is uniqu(...)] at backend\feed\src\test\kotlin\net\twisterrob\cinema\cineworld\sync\syndication\FeedTest.kt:18:5
        BooleanPropertyNaming - [Boolean property name should match a ^(is|has|are) pattern. Actual name is uniqu(...)] at backend\feed\src\test\kotlin\net\twisterrob\cinema\cineworld\sync\syndication\FeedTest.kt:19:5
        BooleanPropertyNaming - [Boolean property name should match a ^(is|has|are) pattern. Actual name is uniqu(...)] at backend\feed\src\test\kotlin\net\twisterrob\cinema\cineworld\sync\syndication\FeedTest.kt:21:5

Steps to Reproduce

Couldn't figure a simple way, so:

Your Environment

@TWiStErRob TWiStErRob added the bug label Oct 8, 2022
@cortinico cortinico added help wanted good first issue Issue that is easy to pickup for people that are new to the project labels Oct 14, 2022
@schalkms
Copy link
Member

Putting this code in our test environment doesn't report the same code location twice.
@TWiStErRob do you run detekt in parallel mode?

@TWiStErRob
Copy link
Member Author

TWiStErRob commented Oct 16, 2022

I'm trying to narrow it down:

  • my repro in compileAndLintWithContext doesn't always find all problems #5391 also failed, it only show 3 warnings, BUT if I copy that code into the same project and do the repro above, it shows 6 findings.
  • I tried removing all sources of from my test sourceSet, same behavior.
  • I tried removing all sources of from my main sourceSet, same behavior.
  • I tried removing all dependencies and other modules of from my Gradle projects, same behavior.
  • hint: if I remove the val feed2: Feed = part, it reduces to 3 findings. (if I just rename it, it stays); I cannot conclude anything from this
  • Removed kapt and java plugins, same behavior.
  • Removed all other mentions of detekt in configuration and inlined my plugin... same behavior
  • Moved it to the main source set, same behavior.
  • I removed all other build gradle code, same behavior.
  • I moved code to : submodule, same behavior.
  • I removed all extra detekt config (except allrules = true), same behavior.
  • ... getting there, but so far it's a big wot?
  • removed all detekt config except config = files("detekt.yml"), same behavior.
  • removed package, same behavior.
  • removed all Gradle properties, same behavior.

This is the point where I cannot think of any more simplifications, and no conclusive cause found. Creating minimalish self-contained repro:

Note: I have enabled UseDataClass as well for control, as it doesn't duplicate findings.

> Task :detektMain FAILED
. root project> 0% CONFIGURING [86ms]

1 kotlin file was analyzed.
...\src\main\kotlin\f.kt:11:4: Boolean property name should match a ^(is|has|are) pattern. Actual name is uniqueFilms [BooleanPropertyNaming]
...\src\main\kotlin\f.kt:12:4: Boolean property name should match a ^(is|has|are) pattern. Actual name is uniqueFilms2 [BooleanPropertyNaming]
...\src\main\kotlin\f.kt:14:4: Boolean property name should match a ^(is|has|are) pattern. Actual name is uniqueAttributes [BooleanPropertyNaming]
...\src\main\kotlin\f.kt:11:4: Boolean property name should match a ^(is|has|are) pattern. Actual name is uniqueFilms [BooleanPropertyNaming]
...\src\main\kotlin\f.kt:12:4: Boolean property name should match a ^(is|has|are) pattern. Actual name is uniqueFilms2 [BooleanPropertyNaming]
...\src\main\kotlin\f.kt:14:4: Boolean property name should match a ^(is|has|are) pattern. Actual name is uniqueAttributes [BooleanPropertyNaming]
...\src\main\kotlin\f.kt:1:1: The class Feed defines no functionality and only holds data. Consider converting it to a data class. [UseDataClass]
...\src\main\kotlin\f.kt:5:1: The class Film defines no functionality and only holds data. Consider converting it to a data class. [UseDataClass]
...\src\main\kotlin\f.kt:6:1: The class Attribute defines no functionality and only holds data. Consider converting it to a data class. [UseDataClass]

...\src\main\kotlin\f.kt - 45min debt
        BooleanPropertyNaming - [Boolean property name should match a ^(is|has|are) pattern. Actual name is uniqu(...)] at ...\src\main\kotlin\f.kt:11:4
        BooleanPropertyNaming - [Boolean property name should match a ^(is|has|are) pattern. Actual name is uniqu(...)] at ...\src\main\kotlin\f.kt:12:4
        BooleanPropertyNaming - [Boolean property name should match a ^(is|has|are) pattern. Actual name is uniqu(...)] at ...\src\main\kotlin\f.kt:14:4
        BooleanPropertyNaming - [Boolean property name should match a ^(is|has|are) pattern. Actual name is uniqu(...)] at ...\src\main\kotlin\f.kt:11:4
        BooleanPropertyNaming - [Boolean property name should match a ^(is|has|are) pattern. Actual name is uniqu(...)] at ...\src\main\kotlin\f.kt:12:4
        BooleanPropertyNaming - [Boolean property name should match a ^(is|has|are) pattern. Actual name is uniqu(...)] at ...\src\main\kotlin\f.kt:14:4
        UseDataClass - [The class Feed defines no functionality and only holds data. Consider converting(...)] at ...\src\main\kotlin\f.kt:1:1
        UseDataClass - [The class Film defines no functionality and only holds data. Consider converting(...)] at ...\src\main\kotlin\f.kt:5:1
        UseDataClass - [The class Attribute defines no functionality and only holds data. Consider conve(...)] at ...\src\main\kotlin\f.kt:6:1

Overall debt: 45min

naming - 30min debt
        BooleanPropertyNaming - [Boolean property name should match a ^(is|has|are) pattern. Actual name is uniqu(...)] at ...\src\main\kotlin\f.kt:11:4
        BooleanPropertyNaming - [Boolean property name should match a ^(is|has|are) pattern. Actual name is uniqu(...)] at ...\src\main\kotlin\f.kt:12:4
        BooleanPropertyNaming - [Boolean property name should match a ^(is|has|are) pattern. Actual name is uniqu(...)] at ...\src\main\kotlin\f.kt:14:4
        BooleanPropertyNaming - [Boolean property name should match a ^(is|has|are) pattern. Actual name is uniqu(...)] at ...\src\main\kotlin\f.kt:11:4
        BooleanPropertyNaming - [Boolean property name should match a ^(is|has|are) pattern. Actual name is uniqu(...)] at ...\src\main\kotlin\f.kt:12:4
        BooleanPropertyNaming - [Boolean property name should match a ^(is|has|are) pattern. Actual name is uniqu(...)] at ...\src\main\kotlin\f.kt:14:4
style - 15min debt
        UseDataClass - [The class Feed defines no functionality and only holds data. Consider converting(...)] at ...\src\main\kotlin\f.kt:1:1
        UseDataClass - [The class Film defines no functionality and only holds data. Consider converting(...)] at ...\src\main\kotlin\f.kt:5:1
        UseDataClass - [The class Attribute defines no functionality and only holds data. Consider conve(...)] at ...\src\main\kotlin\f.kt:6:1

Overall debt: 45min

Complexity Report:
        - 20 lines of code (loc)
        - 19 source lines of code (sloc)
        - 16 logical lines of code (lloc)
        - 0 comment lines of code (cloc)
        - 3 cyclomatic complexity (mcc)
        - 1 cognitive complexity
        - 9 number of total code smells
        - 0% comment source ratio
        - 187 mcc per 1,000 lloc
        - 562 code smells per 1,000 lloc

Project Statistics:
        - number of properties: 4
        - number of functions: 1
        - number of classes: 3
        - number of packages: 1
        - number of kt files: 1

Successfully generated Checkstyle XML report at ...\build\reports\detekt\main.xml
Successfully generated plain text report at ...\build\reports\detekt\main.txt
Successfully generated HTML report at ...\build\reports\detekt\main.html
Successfully generated SARIF: a standard format for the output of static analysis tools at ...\build\reports\detekt\main.sarif
Successfully generated Markdown report at ...\build\reports\detekt\main.md

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':detektMain'.
> Analysis failed with 9 weighted issues.

TWiStErRob added a commit to TWiStErRob/repros that referenced this issue Oct 16, 2022
@TWiStErRob
Copy link
Member Author

Based on the repro I did a gradlew detektMain -Dorg.gradle.debug=true --no-daemon with a breakpoint on report() in BooleanPropertyNaming and it seems the duplication comes from the super.visitProperty + validateDeclaration call, because there's that extra val feed2: Feed variable (as seen in hint above). This is the point where my PSI knowledge lacks: I cannot see why for the outer declaration it would still find the inner violations. @schalkms please pick up from here.

@TWiStErRob
Copy link
Member Author

oh, no-repro on rc2

@TWiStErRob
Copy link
Member Author

Fixed by #5212 which was first available in v1.22.0-RC1

@TWiStErRob TWiStErRob closed this as not planned Won't fix, can't repro, duplicate, stale Oct 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug good first issue Issue that is easy to pickup for people that are new to the project help wanted
Projects
None yet
Development

No branches or pull requests

3 participants