Skip to content

Upgrade Detekt from 1.23.8 to 2.0.0-alpha.2#69

Open
MariusVolkhart wants to merge 1 commit intomainfrom
mv/upgradeToDetekt2
Open

Upgrade Detekt from 1.23.8 to 2.0.0-alpha.2#69
MariusVolkhart wants to merge 1 commit intomainfrom
mv/upgradeToDetekt2

Conversation

@MariusVolkhart
Copy link
Copy Markdown
Member

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
  • 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

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>
@mbayerPK
Copy link
Copy Markdown
Collaborator

Whats the reasoning behind upgrading to an alpha version of detekt here?

@MariusVolkhart
Copy link
Copy Markdown
Member Author

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
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

we dont need var here

val code = """
fun main() {
value = 3.7
var value = 3.7
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

dont need var here

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants