Upgrade Detekt from 1.23.8 to 2.0.0-alpha.2#69
Conversation
Detekt 2.0 changed its Maven coordinates from io.gitlab.arturbosch.detekt
to dev.detekt, migrated from K1 (BindingContext/descriptors) to the K2
Kotlin Analysis API, and made several API breaking changes.
Build changes:
- All detekt artifact coordinates updated to dev.detekt group
- Added detekt-psi-utils dependency (FunctionMatcher moved there from tooling)
- Detekt Gradle task properties migrated to lazy API: parallel.set(), jvmTarget.set(), buildUponDefaultConfig.set()
- Plugin IDs updated from io.gitlab.arturbosch.detekt to dev.detekt
Source changes:
- EnforceStaticImport: migrated from visitCallExpression + BindingContext to
visitDotQualifiedExpression + analyze { resolveToCall().singleFunctionCallOrNull() }
using the K2 Analysis API; Rule now takes description in constructor instead of
an issue property; CodeSmell replaced by Finding
- ImportExtensionProvider: instance() no longer takes Config; ruleSetId is now
RuleSetId type; RuleSet now takes Map<RuleName, (Config) -> Rule> not List<Rule>
- ImportConfigValidator: Notification changed from interface to final class;
added required id property from Extension interface
- EnforceStaticImportTest: migrated to KotlinEnvironmentContainer / lintWithContext;
external library tests replaced with JDK equivalents since the new test engine
only includes JDK, stdlib, and coroutines in the analysis session
Config changes (detekt.yml):
- ForbiddenImport: imports -> forbiddenImports, removed forbiddenPatterns
- RedundantVisibilityModifierRule -> RedundantVisibilityModifier
- SpacingBetweenPackageAndImports -> SpacingAfterPackageDeclaration
- UntilInsteadOfRangeTo -> RangeUntilInsteadOfRangeTo
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Whats the reasoning behind upgrading to an alpha version of detekt here? |
The 1.x line of Detekt isn't fully Compatible with Kotlin 2.x, and we're beginning to encounter incorrect analysis internally. The Detekt 2.x Alpha line is the best thing available right now. But also, "alpha" is a loose term here. It's a linter with a long history - it's not going to suddenly take down production or something. |
| val code = """ | ||
| fun main() { | ||
| val value = 3.3 | ||
| var value = 3.3 |
There was a problem hiding this comment.
This should still be val as its not re-set
| val code = """ | ||
| import com.google.common.truth.Truth | ||
| import com.google.common.truth.Truth.assertThat | ||
| import org.junit.jupiter.params.provider.Arguments |
There was a problem hiding this comment.
Not sure why it claude elected to change the imports used on this test since the old ones made it explicit as what was being tested and the new one(s) are less clear- especially with java.time.LocalDate.now not having an import declaration
| val code = """ | ||
| fun main() { | ||
| value = 3.7 | ||
| var value = 3.7 |
| val code = """ | ||
| fun main() { | ||
| value = 3.7 | ||
| var value = 3.7 |
Detekt 2.0 changed its Maven coordinates from io.gitlab.arturbosch.detekt to dev.detekt, migrated from K1 (BindingContext/descriptors) to the K2 Kotlin Analysis API, and made several API breaking changes.
Build changes:
Source changes:
Config changes (detekt.yml):