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 rules by default for 1.21 #4643

Closed
BraisGabin opened this issue Mar 19, 2022 · 13 comments · Fixed by #4875
Closed

Enable rules by default for 1.21 #4643

BraisGabin opened this issue Mar 19, 2022 · 13 comments · Fixed by #4875

Comments

@BraisGabin
Copy link
Member

All the rules that we add to detekt start disable by default. That's a good default because the early-adopters can give us feedback about them and we don't create a lot of noise for those users that prefer more stability.

But from time to time we should promote those rules and enable them by default. An example of rule that we could enable by default:

Which other rules do you think we should enable by default?

Note: There are some rules that are "controversial" and they will never become enable by default.

@marschwar
Copy link
Contributor

marschwar commented Mar 19, 2022

Thank you for taking the initiative. There are so many great rules that are not active by default right now. Here is the list of my candidates for 1.21. I am aware that some of them might not make the final cut.

Edit: Trying to keep track of the current state of discussion here.

@cortinico
Copy link
Member

Note: There are some rules that are "controversial" and they will never become enable by default.

IIRC we decided to annotate them but we never did so right?

@hfhbd
Copy link
Contributor

hfhbd commented Mar 23, 2022

I would like add HasPlatformType to the discussion as well.

@marschwar
Copy link
Contributor

Note: There are some rules that are "controversial" and they will never become enable by default.

IIRC we decided to annotate them but we never did so right?

Correct, we never did. Should we at least create the annotation so We have the option to do so in the future?

@BraisGabin
Copy link
Member Author

BraisGabin commented Mar 30, 2022

@marschwar thanks you so much for that list with all the links! It's so easy to follow it!

I'm not 100% bought with this one... I know in general it's a bad idea to have too much overload methods and probably that you are not using the polymorphism correctly. But to be honest 6 seems like a really good threshold to me.

This one will break lots of builds. This patter is really common: @Test fun foo() = runBlockingTest {}

And I don't agree with this part of its description:

Changing the type of the expression accidentally, changes the functions return type.

That issue is not related with functions returning implicit Unit that's generic for any implicit return value.

Edit: Thinking about this one... maybe if we exclude test by default on this one it have more sense to enable it.

  • I also like the idea of CanBeNonNullable but do not know how battle tested it is

I agree that it would be really nice but it was introduced in 1.20.0-RC1 so I'm not sure... we could talk about it once 1.20 is released.

  • ClassOrdering - would definitely break builds, but it enforces the official coding guidelines

I think this one is controversial too. I for sure will disable this one in my projects.

+1! I have them enabled in my code and they work perfectly fine.


The other ones that I didn't comment here I agree 100% that we should enable them

@marschwar
Copy link
Contributor

I agree with your concerns. I updated my comment above to keep track of the current state of the discussion. Hope that more users chime in as well.

@BraisGabin
Copy link
Member Author

BraisGabin commented Mar 30, 2022

My own list (I'm not adding the onces that were mentioned already)

And I would vote to disable UnsafeCallOnNullableType. I saw that it make a lot of devs to abuse from the safe call operator (?.) and to me that's even worst. I prefer a NPE than an unexpected behaviour that goes under the radar. But I suppose that this is very controversial so I'm ok maintaining the "status quo".

@hfhbd
Copy link
Contributor

hfhbd commented Mar 30, 2022

I am surprised NotImplementedDeclaration is not enabled by default :D

@marschwar
Copy link
Contributor

I could get behind most of your suggestions, other than:

strongly oppose -> candidates for @Controversial?

  • ReplaceSafeCallChainWithRun - it really depends on the use case if it improves the code or makes it harder to understand
  • NotImplementedDeclaration - while trying to use continuous delivery it is helpful to be able commit stubs that are not yet used
  • NullableToStringCall - never understood the rule

mildly oppose as that may cause many builds to break

  • IgnoredReturnValue
  • LateinitUsage

And I would vote to disable UnsafeCallOnNullableType.

To me this should stay active by default.

@BraisGabin BraisGabin added this to the 1.21.0 milestone Apr 11, 2022
@BraisGabin
Copy link
Member Author

I would like to give a more inside about two of those rules and why I think that they should be enabled:

NullableToStringCall: Usually, when you use toString() is to show that to the user in some way. But it's really strange to want to show "null" to the user. But kotlin is completely fine with this: null.toString(). What this rule does is to reduce that issue. I think that this one is important.

IgnoredReturnValue: I agree, it could fail a lot of buids. But what this rule is to "empower" the library authors to force the users to use theri library properly. By default we just flag the ignored values from functions that were explicitily annotated. I think that the false positives of this rule should be really low and it should find lots of real issues. But I'm fine with keeping it disabled until the next "bunch of enabled rules".

(I agree with you in the other ones and I crosslined them)

@marschwar
Copy link
Contributor

I guess our use cases differ. I usually work on the server side of things and when ever I use the implicit toString in string Interpolation in a log message, I actually want to see the "null" string.

@BraisGabin
Copy link
Member Author

Good point. I crosslined it from the list.

@BraisGabin
Copy link
Member Author

I'm changing my mind about enabling this rules:

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

Successfully merging a pull request may close this issue.

4 participants