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
Mixing autocorrectable and non correctable rules results in obsolete issue locations for reports #2341
Comments
Could you provide a sample code to reproduce this issue? |
🤦♂ I fix the code and now is working fine, let me check the history |
I was able to reproduce it with the following snippet enum class SomeEnum {
VALUE1, VALUE2, VALUE3, UNKNOWN;
companion object {
fun from(string: String): SomeEnum =
try { valueOf(string) }
catch (e: Exception) { UNKNOWN }
}
} |
WOW Really strange behaviour. The problem is not related with the Exception but with the code itself. If I request the enum class SomeEnum {
VALUE1, VALUE2, VALUE3, UNKNOWN;
companion object {
fun from(string: String): SomeEnum =
try { valueOf(string) } catch (e: Exception) { UNKNOWN }
}
} the Any idea about why this is happening? It seems an error in PSI. |
@BraisGabin even if the Psi had a problem the HtmlReport shouldn’t crash. |
Good! This wasn't clear to me just by looking at this issue description.
That's really strange. In my opinion this is an issue with the PSI itself. |
I'm researching this issue. It's on our side. The extension function |
Found! |
Ok! I know what's going on:
How to fix it? I think that we need to do two different tasks:
What do you think? |
@BraisGabin your proposal sounds good to me. |
Autsch, good finding!
If I understand you correctly, we already do this here? Changing the default autoCorect from true to false would only be possible in a 2.0 release.
True that, we could introduce basic rule configuration options like
|
I think that we don't need this change to fix this problem.
I think tha, we don't need |
Yes, you are right. We can sort the rules here: What I additionally had in mind but didn't wrote down is that sorting via the In fact every I will open a PR to change private val ruleConfig: Config
get() = ruleSetConfig.subConfig(ruleId) to private val ruleConfig: Config by lazy(NoSynch) { ruleSetConfig.subConfig(ruleId) } and apply your suggestion to sort by Edit: regarding |
We can only sort the rules that are inside a |
* Sort and run correctable rules first - #2341 * Don't introduce supportsAutoCorrectable property - #2341 * Test correctable rules are run first - #2341 * Do not recreate id mapping for each file - #2341 * Update detekt-core/src/main/kotlin/io/gitlab/arturbosch/detekt/core/rules/RuleSets.kt Co-Authored-By: Brais Gabín <brais.gabin@adevinta.com> * Update detekt-core/src/main/kotlin/io/gitlab/arturbosch/detekt/core/Detektor.kt Co-Authored-By: Brais Gabín <brais.gabin@adevinta.com> * Fix import issue Co-authored-by: Brais Gabín <braisgabin@gmail.com>
I think that we should open this issue again or open a new one because we need to do this too:
This is important because, if the user don't enable the auto correct we are going to show incorrect locations for the issues (the html report will work but those snippets are not going to be the same as the user code). Or we can even not detect the issue at all. |
This can be fixed by wrapping the original config by a |
I don't get exactly how do you want to do that. But yes. The point is that if |
…alse - #2341 This way we make sure no KtFile is modified and our reporting calculates the right issue locations.
I found an error in the html report:
The text was updated successfully, but these errors were encountered: