Skip to content

Handle case when reference is provided#8895

Merged
schalkms merged 2 commits into
detekt:mainfrom
atulgpt:fix/8893/fix-false-pos-ref
Dec 27, 2025
Merged

Handle case when reference is provided#8895
schalkms merged 2 commits into
detekt:mainfrom
atulgpt:fix/8893/fix-false-pos-ref

Conversation

@atulgpt
Copy link
Copy Markdown
Contributor

@atulgpt atulgpt commented Dec 3, 2025

Fixes #8893

@detekt-ci detekt-ci added the rules label Dec 3, 2025
@codecov
Copy link
Copy Markdown

codecov Bot commented Dec 3, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.38%. Comparing base (fadb1b1) to head (b16a6f5).
⚠️ Report is 16 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #8895      +/-   ##
============================================
+ Coverage     85.36%   85.38%   +0.01%     
- Complexity     4383     4386       +3     
============================================
  Files           570      570              
  Lines         12557    12559       +2     
  Branches       2625     2627       +2     
============================================
+ Hits          10719    10723       +4     
  Misses          695      695              
+ Partials       1143     1141       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@atulgpt atulgpt force-pushed the fix/8893/fix-false-pos-ref branch from abedf35 to 20cee7a Compare December 12, 2025 16:00
val qualifiedName = privateProperty.qualifiedName()
val matchesPublicProperty = publicPropertyNames.contains(qualifiedName)
if (!matchesPublicProperty && comment.contains("[$qualifiedName]")) {
if (!matchesPublicProperty && comment.contains("\\[${Regex.escape(qualifiedName)}](?!\\[.*])".toRegex())) {
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.

Is it possible to solve this somehow without regular expression?
The reason for asking is that this is potentially a very expensive operation to recompile the regex in each loop iteration.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I have removed the regex. There could be false negatives, for example when there is an opening [ without a closing one, but I believe such cases will be very rare. If the need arises, we can address it at that time.

klass.registerProperty(parameter)
}
}
},
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.

Suggested change
},
}

}

@Test
fun `does not report when ref is used with fully qualifies name same as private property`() {
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.

Suggested change
fun `does not report when ref is used with fully qualifies name same as private property`() {
fun `does not report when ref is used with fully qualified name same as private property`() {

fun `does not report when ref is used with fully qualifies name same as private property`() {
val code = """
/**
* This is wrapper which internally maintains a [list][java.util.LinkedList] variable
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.

Suggested change
* This is wrapper which internally maintains a [list][java.util.LinkedList] variable
* This is a wrapper which internally maintains a [list][java.util.LinkedList] variable

@atulgpt atulgpt force-pushed the fix/8893/fix-false-pos-ref branch from c084319 to 6e45649 Compare December 14, 2025 10:31
@atulgpt atulgpt requested a review from schalkms December 14, 2025 10:34
Copy link
Copy Markdown
Member

@schalkms schalkms left a comment

Choose a reason for hiding this comment

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

Thanks!

@atulgpt atulgpt force-pushed the fix/8893/fix-false-pos-ref branch from 6e45649 to b16a6f5 Compare December 17, 2025 18:52
@detekt-ci
Copy link
Copy Markdown
Collaborator

Warnings
⚠️ This PR is approved with no milestone set. If merged, it won't appear in the detekt release notes.

Generated by 🚫 dangerJS against b16a6f5

@atulgpt
Copy link
Copy Markdown
Contributor Author

atulgpt commented Dec 26, 2025

Hi @schalkms should we merge this PR?

@schalkms schalkms merged commit a7ec7c1 into detekt:main Dec 27, 2025
20 of 21 checks passed
@atulgpt atulgpt deleted the fix/8893/fix-false-pos-ref branch December 28, 2025 18:29
@cortinico cortinico added this to the 2.0.0 milestone Dec 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

False positive on KDocReferencesNonPublicProperty

4 participants