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

Enable more rules by default #3229

Merged
merged 6 commits into from
Jan 19, 2021
Merged

Enable more rules by default #3229

merged 6 commits into from
Jan 19, 2021

Conversation

schalkms
Copy link
Member

This is a first draft for enabling more detekt rules by default.
This way users can benefit from a good default config.

Closes #2838

@@ -468,11 +468,11 @@ potential-bugs:
HasPlatformType:
active: false
IgnoredReturnValue:
active: false
active: true
Copy link
Member

Choose a reason for hiding this comment

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

I'm unsure about this. We had several false positives for this rules, specifically from RxJava users.

Copy link
Member

Choose a reason for hiding this comment

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

Agree here

Copy link
Member

@cortinico cortinico left a comment

Choose a reason for hiding this comment

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

We should also recall to annotate with @active since ... all the rules

@arturbosch arturbosch added this to the 1.16.0 milestone Nov 12, 2020
@arturbosch
Copy link
Member

The added rules look good to me 👍
Lets wait for 1.16.0 for this PR, okay?

We have also some more rules enabled in our analysis which are not active by default:
#2838 (comment)

@schalkms
Copy link
Member Author

Lets wait for 1.16.0 for this PR, okay?

That's okay for me. I'll also check the ones mentioned in your last comment.

@codecov
Copy link

codecov bot commented Nov 12, 2020

Codecov Report

Merging #3229 (b277d52) into master (f9e3e41) will increase coverage by 0.04%.
The diff coverage is 30.00%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #3229      +/-   ##
============================================
+ Coverage     80.43%   80.48%   +0.04%     
+ Complexity     2740     2739       -1     
============================================
  Files           448      448              
  Lines          8281     8275       -6     
  Branches       1573     1573              
============================================
- Hits           6661     6660       -1     
+ Misses          772      767       -5     
  Partials        848      848              
Impacted Files Coverage Δ Complexity Δ
...kotlin/io/gitlab/arturbosch/detekt/api/Location.kt 80.76% <ø> (ø) 7.00 <0.00> (ø)
...ain/kotlin/io/gitlab/arturbosch/detekt/api/Rule.kt 82.60% <0.00%> (ø) 16.00 <0.00> (ø)
...tlin/io/gitlab/arturbosch/detekt/cli/JCommander.kt 100.00% <ø> (ø) 0.00 <0.00> (ø)
...ab/arturbosch/detekt/core/config/Configurations.kt 83.33% <ø> (ø) 0.00 <0.00> (ø)
...gitlab/arturbosch/detekt/generator/out/Markdown.kt 21.42% <ø> (+0.73%) 4.00 <0.00> (ø)
...n/io/github/detekt/report/sarif/RuleDescriptors.kt 20.00% <0.00%> (-1.06%) 0.00 <0.00> (ø)
...lin/io/github/detekt/report/xml/XmlOutputReport.kt 91.30% <0.00%> (ø) 7.00 <1.00> (ø)
...urbosch/detekt/rules/bugs/ImplicitDefaultLocale.kt 74.19% <ø> (ø) 9.00 <0.00> (ø)
...ch/detekt/rules/bugs/UnnecessaryNotNullOperator.kt 80.00% <ø> (ø) 4.00 <0.00> (ø)
...rturbosch/detekt/rules/bugs/UnnecessarySafeCall.kt 75.00% <ø> (ø) 4.00 <0.00> (ø)
... and 23 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f9e3e41...b277d52. Read the comment docs.

Copy link
Member

@BraisGabin BraisGabin left a comment

Choose a reason for hiding this comment

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

As @cortinico said we need to add the @active. Then we could just regenerate the file and the values should be changed automatically.

detekt-core/src/main/resources/default-detekt-config.yml Outdated Show resolved Hide resolved
detekt-core/src/main/resources/default-detekt-config.yml Outdated Show resolved Hide resolved
@schalkms
Copy link
Member Author

we need to add the @active

Yep, this is the 2nd step. The 1st step should be the draft of the activated rules.
I’ll add the tag to the rules in the next few days. Fortunately, I had the pleasure to co-create and shape the detekt-verify as well as the -generator back then. 🙂

typos

Regarding the typos, it’s probably not a good idea to edit the config on the go with a smartphone web browser. Well, we luckily have a good CI system and carefully observing reviewers for those reasons.

Cheers and have a nice weekend,
Markus

@BraisGabin
Copy link
Member

BraisGabin commented Nov 15, 2020

What do you think about enable the coroutine ones? I think that all are quite safe. The more controversial is GlobalCoroutineUsage and the documentation of Kotlin always say "please don't use Global" so it should be safe.

So my list to be enabled is:

  • GlobalCoroutineUsage
  • RedundantSuspendModifier
  • SuspendFunWithFlowReturnType
  • InvalidPackageDeclaration
  • HasPlatformType
  • MapGetWithNotNullAssertionOperator
  • ForbiddenMethodCall
  • ForbiddenVoid
  • UnderscoresInNumericLiterals
  • UnnecessaryAnnotationUseSiteTarget
  • UnnecessaryLet
  • UseArrayLiteralsInAnnotations
  • UseCheckOrError
  • UseIfEmptyOrIfBlank
  • UseRequire
  • UseRequireNotNull We should probably merge this one with UseRequire. UseRequire already handles check and checkNotNull so there's not a good reason to have this one splitted

Not so sure:

  • MandatoryBracesIfStatements
  • MandatoryBracesLoops
  • NullableToStringCall 🤔 this one is too new but this issue creates bugs so often...

@schalkms
Copy link
Member Author

Thanks for your work, @BraisGabin.
I had reasons for not enabling all mentioned rules. Hence, I'm not okay with enabling the following rules.

  • UnderscoresInNumericLiterals => this one is really a matter of choice. I don't think all agree with using underscores for numeric literals. We shouldn't enable this by default.
  • UnnecessaryLet => this rule is not battle-tested IMHO. So there might be many false-positives.
  • UseCheckOrError, UseRequire & UseRequireNotNull=> we don't even use this throughout detekt's code base consistently. It's a matter of taste which style you use.
  • The rules in the not sure list should be disabled.

@BraisGabin
Copy link
Member

Thanks for your work, @BraisGabin.
I had reasons for not enabling all mentioned rules. Hence, I'm not okay with enabling the following rules.

  • UnderscoresInNumericLiterals => this one is really a matter of choice. I don't think all agree with using underscores for numeric literals. We shouldn't enable this by default.
  • UnnecessaryLet => this rule is not battle-tested IMHO. So there might be many false-positives.
  • UseCheckOrError, UseRequire & UseRequireNotNull=> we don't even use this throughout detekt's code base consistently. It's a matter of taste which style you use.
  • The rules in the not sure list should be disabled.

I agree with you. We should not enable the rules you list.

@cortinico
Copy link
Member

  • UnnecessaryLet => this rule is not battle-tested IMHO. So there might be many false-positives.

Agree on this

  • ForbiddenMethodCall

I think this should not be enabled as it's a rule users have to configure, with the list of Methods they want to restrict.

@BraisGabin
Copy link
Member

I think this should not be enabled as it's a rule users have to configure, with the list of Methods they want to restrict.

We have two default values there for println. And I think that we should forbid that for default.

Comment on lines +46 to +47
*
* @active since v1.16.0
Copy link
Member

Choose a reason for hiding this comment

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

I was wondering if we can add some documentation or update the existing documentation for why we enable certain rules. Below is a copy of the comment I had:
Printing a stacktrace may be useful for local development, but not for production code.

Copy link
Member

Choose a reason for hiding this comment

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

Every rule should have a descripction so any user can know why he/she should enable/disable it. If you think that in this case (or any other) the description is not good enough you can create an issue. Or, even better, if you know how to improve it, create a PR.

But I don't think that we should add any documentation about why a rule is or is not active by default.

@@ -37,6 +37,8 @@ import org.jetbrains.kotlin.psi.KtProperty
* }
* }
* </compliant>
*
* @active since v1.16.0
Copy link
Member

Choose a reason for hiding this comment

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

Note that Android context, Parcelable is preferred over Serializable. This rule is almost a no-op for Android code.

Copy link
Member

Choose a reason for hiding this comment

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

I agree that in Android we should not use Serializable, but, if we have, we should use the SerialVersionUID. So I think that it's safe to have this enabled.

We talked some times about an Android rule set. A good rule for there would be to flag any use of Serializable.

Copy link
Member

Choose a reason for hiding this comment

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

I just create a discussion to talk about it: #3303

Copy link
Member

@arturbosch arturbosch left a comment

Choose a reason for hiding this comment

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

@chao2zhang kudos for resolving the conflicts +1

@arturbosch arturbosch merged commit 5043656 into master Jan 19, 2021
@arturbosch arturbosch deleted the schalkms-enable_rules branch January 19, 2021 20:17
@arturbosch arturbosch added the migration Marker to add a migration step in the changelog label Jan 19, 2021
@schalkms
Copy link
Member Author

@chao2zhang thanks for pushing this over the finish line.

dbyron-sf added a commit to dbyron-sf/kork that referenced this pull request Jul 26, 2021
… it's available at maven central

1.17.0 (and its dependencies) is also available at maven central (see
https://detekt.github.io/detekt/changelog.html#notable-changes-2), but may as well pick up
the latest 1.17.x.

See https://detekt.github.io/detekt/changelog.html#changelog-3 /
detekt/detekt#3229.  SwallowedException and ImplicitDefaultLocale
rules are now enabled by default, so fix the warnings they generate.  Use Locale.US
because other code in kork and orca do.
dbyron-sf added a commit to dbyron-sf/kork that referenced this pull request Jul 26, 2021
… it's available at maven central

1.17.0 (and its dependencies) is also available at maven central (see
https://detekt.github.io/detekt/changelog.html#notable-changes-2), but may as well pick up
the latest 1.17.x.

See https://detekt.github.io/detekt/changelog.html#changelog-3 /
detekt/detekt#3229.  SwallowedException and ImplicitDefaultLocale
rules are enabled by default as of version 1.16.0, so fix the warnings they generate.  Use
Locale.US because other code in kork and orca do.
mergify bot pushed a commit to spinnaker/kork that referenced this pull request Jul 26, 2021
* chore(build): use dependencies that exist in maven central

some dependencies (or transitive dependencies of those) only existed in bintray, not maven
central, and now that bintray is gone, we need to adjust.

* chore(build): use version 1.17.1 of io.gitlab.arturbosch.detekt since it's available at maven central

1.17.0 (and its dependencies) is also available at maven central (see
https://detekt.github.io/detekt/changelog.html#notable-changes-2), but may as well pick up
the latest 1.17.x.

See https://detekt.github.io/detekt/changelog.html#changelog-3 /
detekt/detekt#3229.  SwallowedException and ImplicitDefaultLocale
rules are enabled by default as of version 1.16.0, so fix the warnings they generate.  Use
Locale.US because other code in kork and orca do.
ylebedeva pushed a commit to ylebedeva/kork that referenced this pull request May 3, 2022
…#873)

* chore(build): use dependencies that exist in maven central

some dependencies (or transitive dependencies of those) only existed in bintray, not maven
central, and now that bintray is gone, we need to adjust.

* chore(build): use version 1.17.1 of io.gitlab.arturbosch.detekt since it's available at maven central

1.17.0 (and its dependencies) is also available at maven central (see
https://detekt.github.io/detekt/changelog.html#notable-changes-2), but may as well pick up
the latest 1.17.x.

See https://detekt.github.io/detekt/changelog.html#changelog-3 /
detekt/detekt#3229.  SwallowedException and ImplicitDefaultLocale
rules are enabled by default as of version 1.16.0, so fix the warnings they generate.  Use
Locale.US because other code in kork and orca do.
richard-timpson pushed a commit to richard-timpson/kork that referenced this pull request May 3, 2023
This is based on spinnaker#873 and
spinnaker#846 with some tweaks since
kork-plugins/src/main/kotlin/com/netflix/spinnaker/kork/plugins/v2/SpringEventListenerAdapter.kt
doesn't exist in our version of kork.

* chore(build): use dependencies that exist in maven central

some dependencies (or transitive dependencies of those) only existed in bintray, not maven
central, and now that bintray is gone, we need to adjust.

* chore(build): use version 1.17.1 of io.gitlab.arturbosch.detekt since it's available at maven central

1.17.0 (and its dependencies) is also available at maven central (see
https://detekt.github.io/detekt/changelog.html#notable-changes-2), but may as well pick up
the latest 1.17.x.

See https://detekt.github.io/detekt/changelog.html#changelog-3 /
detekt/detekt#3229.  The ImplicitDefaultLocale rule is enabled by
default as of version 1.16.0, so fix the warnings it generates.  Use Locale.US because
other code in kork and orca do.

@W-9762454
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
migration Marker to add a migration step in the changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enable more rules by default
5 participants