Skip to content

Config.valueOrNull more type safe#9049

Draft
BraisGabin wants to merge 16 commits intomainfrom
typed-valueOrNull
Draft

Config.valueOrNull more type safe#9049
BraisGabin wants to merge 16 commits intomainfrom
typed-valueOrNull

Conversation

@BraisGabin
Copy link
Copy Markdown
Member

Config.valueOrNull implementations where doing something like this as T. That cast isn't safe. The function could return a Map but saying that it's a List. It will fail as soon as you try to access it because the functions that you are looking for aren't there but that fail will happen too late and it's difficult to understand what happened. With this implementation if something like that happens the exception is thrown as soon as possible so it's easier to fix.

Also, this open the option to a similar refactor over ConfigProperty to make it safer and easier to make it support more types. For example, the current implementation of ValueWithReason at ConfigProperty.kt is really fragile.

Also this simplifies A LOT YamlConfig. No more BaseConfig (that was just code from YamlConfig moved to another file). And all the Config implemementations too. Now you don't need to implement two different functions. You just need to implement one. The other is implemented as an extension function over the other.

More context at #9035

Sorry for this PR, I know that it's big but I don't know how to make it smaller.

Waiting for:

Extra: We could rename this function getOrNull to align with the standard library but that can be done in another PR.

@codecov
Copy link
Copy Markdown

codecov bot commented Feb 10, 2026

Codecov Report

❌ Patch coverage is 92.15686% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.14%. Comparing base (5563786) to head (a79218e).
⚠️ Report is 66 commits behind head on main.

Files with missing lines Patch % Lines
...in/kotlin/dev/detekt/core/config/AllRulesConfig.kt 80.00% 0 Missing and 1 partial ⚠️
...c/main/kotlin/dev/detekt/core/config/YamlConfig.kt 95.23% 0 Missing and 1 partial ⚠️
...etekt/core/tooling/ProcessingSpecSettingsBridge.kt 80.00% 0 Missing and 1 partial ⚠️
...n/dev/detekt/rules/ktlintwrapper/ConfigProperty.kt 66.66% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##               main    #9049   +/-   ##
=========================================
  Coverage     85.14%   85.14%           
+ Complexity     4392     4388    -4     
=========================================
  Files           569      568    -1     
  Lines         12260    12214   -46     
  Branches       2648     2633   -15     
=========================================
- Hits          10439    10400   -39     
+ Misses          676      675    -1     
+ Partials       1145     1139    -6     

☔ 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants