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

Add detekt #5539

Merged
merged 14 commits into from
Feb 5, 2024
Merged

Add detekt #5539

merged 14 commits into from
Feb 5, 2024

Conversation

Rawa
Copy link
Contributor

@Rawa Rawa commented Dec 1, 2023

This PR adds detekt as a linting to ensure we have nice code quality in our project. We've done some evaluation and have opted not to use it for formatting. There we will keep using ktfmt until we see a clear benefit to switch to something else.


This change is Reviewable

Copy link

linear bot commented Dec 1, 2023

@Rawa Rawa force-pushed the try-replacing-ktfmt-with-detekt-droid-559 branch 2 times, most recently from f8d91fc to 0642523 Compare December 1, 2023 10:58
@Pururun Pururun added the Android Issues related to Android label Dec 1, 2023
@Rawa Rawa force-pushed the try-replacing-ktfmt-with-detekt-droid-559 branch 2 times, most recently from 5cc3fe2 to 556ebce Compare December 1, 2023 12:40
@Rawa Rawa self-assigned this Dec 5, 2023
@Rawa Rawa force-pushed the try-replacing-ktfmt-with-detekt-droid-559 branch from 0814fe4 to c1ccc7a Compare December 12, 2023 12:24
@Pururun Pururun added the On hold Means the PR is paused for some reason. No need to review it for now label Dec 19, 2023
@Rawa Rawa force-pushed the try-replacing-ktfmt-with-detekt-droid-559 branch from 074fd19 to 0596474 Compare January 22, 2024 15:33
@Rawa Rawa changed the title Replacing ktfmt with detekt Add detekt Jan 22, 2024
@Rawa Rawa force-pushed the try-replacing-ktfmt-with-detekt-droid-559 branch from cad019c to e756465 Compare January 24, 2024 08:13
@Rawa Rawa removed the On hold Means the PR is paused for some reason. No need to review it for now label Jan 24, 2024
@Rawa Rawa force-pushed the try-replacing-ktfmt-with-detekt-droid-559 branch from d711288 to 88ee6a2 Compare January 24, 2024 09:46
Copy link
Collaborator

@albin-mullvad albin-mullvad left a comment

Choose a reason for hiding this comment

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

Please add a description to the PR where you clarify how we intend to use detekt as of this PR.

Reviewed 20 of 22 files at r1, 1 of 1 files at r5.
Reviewable status: 20 of 24 files reviewed, 3 unresolved discussions (waiting on @Rawa)


android/build.gradle.kts line 32 at r2 (raw file):

allprojects {
    apply(plugin = Dependencies.Plugin.dependencyCheckId)
    apply(plugin = Dependencies.Plugin.ktfmtId)

Are we completely removing ktfmt? Wasn't the plan to use it in combination with detekt? 🤔


android/lib/talpid/src/main/kotlin/net/mullvad/talpid/TalpidVpnService.kt line 144 at r2 (raw file):

            is Inet4Address -> 32
            is Inet6Address -> 128
            else -> throw IllegalArgumentException("Invalid IP address (not IPv4 nor IPv6)")

Just to double check; was this one incorrect before?

Code quote:

IllegalArgumentException

android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/SettingsListener.kt line 11 at r2 (raw file):

import net.mullvad.mullvadvpn.lib.ipc.Event
import net.mullvad.mullvadvpn.lib.ipc.Request
import net.mullvad.mullvadvpn.model.*

Is there a risk that expanding the imports might affect ktfmt or the android studio formatting?

Copy link
Contributor Author

@Rawa Rawa left a comment

Choose a reason for hiding this comment

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

Reviewable status: 20 of 24 files reviewed, 3 unresolved discussions (waiting on @albin-mullvad)


android/lib/talpid/src/main/kotlin/net/mullvad/talpid/TalpidVpnService.kt line 144 at r2 (raw file):

Previously, albin-mullvad wrote…

Just to double check; was this one incorrect before?

We got a warning for using a too generic exception. Thus I updated throw an IlleagalArgumentException


android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/SettingsListener.kt line 11 at r2 (raw file):

Previously, albin-mullvad wrote…

Is there a risk that expanding the imports might affect ktfmt or the android studio formatting?

I tried Android Studio Reformat Code and ktfmtFormat, none complained about expanding them. I believe the default in android studio should also not use wildcard.

Copy link
Contributor Author

@Rawa Rawa left a comment

Choose a reason for hiding this comment

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

Reviewable status: 17 of 24 files reviewed, 3 unresolved discussions (waiting on @albin-mullvad)


android/build.gradle.kts line 32 at r2 (raw file):

Previously, albin-mullvad wrote…

Are we completely removing ktfmt? Wasn't the plan to use it in combination with detekt? 🤔

Issue with Android Studio not showing diffs correctly. Restored now.

Copy link
Collaborator

@albin-mullvad albin-mullvad left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 2 files at r3, 1 of 1 files at r4, 4 of 4 files at r6, all commit messages.
Reviewable status: 23 of 24 files reviewed, 3 unresolved discussions (waiting on @Rawa)


-- commits line 1 at r6:
Reminder to clean up the commit history a bit before merging.


android/build.gradle.kts line 57 at r6 (raw file):

// Kotlin DSL
tasks.withType<Detekt>().configureEach { jvmTarget = "1.8" }

Is there a reason for not using Versions.jvmTarget? It's set to "17" btw. Same applies below.

Code quote:

jvmTarget = "1.8"

android/config/detekt.yml line 1 at r6 (raw file):

build:

Is this file based on some default suggestions? It might be nice to add some info or documentation regarding that to the file as a header. Also, if any deviations are made from the default suggestion, it would be nice clarify using comments.


android/config/detekt.yml line 94 at r6 (raw file):

      - '**/androidInstrumentedTest/**'
      - '**/jsTest/**'
      - '**/iosTest/**'

Are these needed? 🤔

This also applies to some more parts of this file.

Code quote:

      - '**/jsTest/**'
      - '**/iosTest/**'

android/lib/talpid/src/main/kotlin/net/mullvad/talpid/TalpidVpnService.kt line 144 at r2 (raw file):

Previously, Rawa (David Göransson) wrote…

We got a warning for using a too generic exception. Thus I updated throw an IlleagalArgumentException

Aha, so RuntimeException is counted as too generic?


android/service/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/SettingsListener.kt line 11 at r2 (raw file):

Previously, Rawa (David Göransson) wrote…

I tried Android Studio Reformat Code and ktfmtFormat, none complained about expanding them. I believe the default in android studio should also not use wildcard.

Alright 👍

@Rawa Rawa force-pushed the try-replacing-ktfmt-with-detekt-droid-559 branch 5 times, most recently from f037685 to 66a873f Compare January 25, 2024 09:22
@Rawa Rawa requested review from albin-mullvad and Pururun January 25, 2024 09:22
@Rawa Rawa force-pushed the try-replacing-ktfmt-with-detekt-droid-559 branch from 66a873f to 3b6e000 Compare January 25, 2024 11:05
Copy link
Contributor

@Pururun Pururun left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 22 files at r1, 1 of 21 files at r7, 1 of 19 files at r8, 19 of 19 files at r9, all commit messages.
Reviewable status: all files reviewed, 5 unresolved discussions (waiting on @Rawa)


android/build.gradle.kts line 32 at r9 (raw file):

allprojects {
    apply(plugin = Dependencies.Plugin.dependencyCheckId)
    apply(plugin = Dependencies.Plugin.ktfmtId)

Will this mean that we no longer will have formatting done by ktfmt


android/build.gradle.kts line 44 at r9 (raw file):

    }

    configure<com.ncorti.ktfmt.gradle.KtfmtExtension> {

See above

@Rawa Rawa force-pushed the try-replacing-ktfmt-with-detekt-droid-559 branch 2 times, most recently from f750af2 to a2dbf35 Compare January 30, 2024 08:38
Copy link
Contributor Author

@Rawa Rawa left a comment

Choose a reason for hiding this comment

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

Reviewable status: 3 of 24 files reviewed, 5 unresolved discussions (waiting on @albin-mullvad and @Pururun)


android/build.gradle.kts line 57 at r6 (raw file):

Previously, albin-mullvad wrote…

Is there a reason for not using Versions.jvmTarget? It's set to "17" btw. Same applies below.

Thanks, legacy, cleaned up :)


android/build.gradle.kts line 32 at r9 (raw file):

Previously, Pururun (Jonatan Rhodin) wrote…

Will this mean that we no longer will have formatting done by ktfmt

Reviewable shows these lines really weird for me, didn't show any change. Now it shows it as an addition. I've tried to restore them now.


android/build.gradle.kts line 44 at r9 (raw file):

Previously, Pururun (Jonatan Rhodin) wrote…

See above

See above


android/config/detekt.yml line 1 at r6 (raw file):

Previously, albin-mullvad wrote…

Is this file based on some default suggestions? It might be nice to add some info or documentation regarding that to the file as a header. Also, if any deviations are made from the default suggestion, it would be nice clarify using comments.

Yes, one can generate a basic config from ./gradlew detektGenerateConfig then I've done some corrections to make it play nice with compose etc.


android/config/detekt.yml line 94 at r6 (raw file):

Previously, albin-mullvad wrote…

Are these needed? 🤔

This also applies to some more parts of this file.

Not really, but part of the standard generated config. I was thinking less change makes us less prone to have unexpected behavior. Do you think we should remove it?


android/lib/talpid/src/main/kotlin/net/mullvad/talpid/TalpidVpnService.kt line 144 at r2 (raw file):
Yes, not sure exact logic for that rule but it warned it to be too generic in this case.

> Task :detekt FAILED
/Users/rawa/Code/mullvadvpn-app/android/lib/talpid/src/main/kotlin/net/mullvad/talpid/TalpidVpnService.kt:144:21: RuntimeException is a too generic Exception. Prefer throwing specific exceptions that indicate a specific error case. [TooGenericExceptionThrown]```

Copy link
Contributor

@Pururun Pururun left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewed 1 of 21 files at r10, 1 of 1 files at r11, 19 of 19 files at r12, all commit messages.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @albin-mullvad)

Copy link
Collaborator

@albin-mullvad albin-mullvad left a comment

Choose a reason for hiding this comment

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

@Rawa did you see my comment above? ⬆️

Reviewed 1 of 21 files at r10, 1 of 19 files at r12.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @Rawa)


android/config/detekt.yml line 1 at r6 (raw file):

Previously, Rawa (David Göransson) wrote…

Yes, one can generate a basic config from ./gradlew detektGenerateConfig then I've done some corrections to make it play nice with compose etc.

Can we add the generated config as a separate commit to clarify that it's genereated as well as easily see what we've changed from the default?


android/config/detekt.yml line 94 at r6 (raw file):

Previously, Rawa (David Göransson) wrote…

Not really, but part of the standard generated config. I was thinking less change makes us less prone to have unexpected behavior. Do you think we should remove it?

Alright 👍

Copy link
Collaborator

@albin-mullvad albin-mullvad left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 22 files at r1, 1 of 1 files at r11, 18 of 19 files at r12, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @Rawa)

@Rawa Rawa force-pushed the try-replacing-ktfmt-with-detekt-droid-559 branch from a2dbf35 to e94f876 Compare February 2, 2024 15:31
Copy link
Contributor Author

@Rawa Rawa left a comment

Choose a reason for hiding this comment

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

@albin-mullvad Fixed!

Reviewed 1 of 5 files at r13, all commit messages.
Reviewable status: 19 of 24 files reviewed, 1 unresolved discussion (waiting on @albin-mullvad and @Pururun)


android/config/detekt.yml line 1 at r6 (raw file):

Previously, albin-mullvad wrote…

Can we add the generated config as a separate commit to clarify that it's genereated as well as easily see what we've changed from the default?

I've now split them out to 2 separate commits

Copy link
Contributor Author

@Rawa Rawa left a comment

Choose a reason for hiding this comment

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

Reviewed 4 of 5 files at r13.
Reviewable status: 19 of 24 files reviewed, 1 unresolved discussion (waiting on @albin-mullvad)

@Rawa Rawa force-pushed the try-replacing-ktfmt-with-detekt-droid-559 branch from e94f876 to a9b53a2 Compare February 2, 2024 15:33
Copy link
Contributor Author

@Rawa Rawa left a comment

Choose a reason for hiding this comment

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

Reviewed all commit messages.
Reviewable status: 19 of 24 files reviewed, 1 unresolved discussion (waiting on @albin-mullvad and @Rawa)

Copy link
Collaborator

@albin-mullvad albin-mullvad left a comment

Choose a reason for hiding this comment

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

Reviewed 5 of 5 files at r13, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved

Copy link
Collaborator

@albin-mullvad albin-mullvad left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewable status: :shipit: complete! all files reviewed, all discussions resolved

@albin-mullvad albin-mullvad force-pushed the try-replacing-ktfmt-with-detekt-droid-559 branch 2 times, most recently from b15542a to 2249926 Compare February 5, 2024 15:50
Copy link
Collaborator

@albin-mullvad albin-mullvad left a comment

Choose a reason for hiding this comment

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

Reviewed 2 of 2 files at r15, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved

@albin-mullvad albin-mullvad force-pushed the try-replacing-ktfmt-with-detekt-droid-559 branch from 2249926 to f7cb264 Compare February 5, 2024 16:52
@albin-mullvad albin-mullvad merged commit d805c6e into main Feb 5, 2024
17 checks passed
@albin-mullvad albin-mullvad deleted the try-replacing-ktfmt-with-detekt-droid-559 branch February 5, 2024 16:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Android Issues related to Android
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants