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 support for local suppression inside formatting #5876

Merged
merged 2 commits into from
Mar 16, 2023

Conversation

cortinico
Copy link
Member

Fixes #5547
Fixes #5566
Related to #1999 also

This introduced the possibility to do more fine grained suppression on detekt-formatting rules. Specifically I'm dropping the custom logic we apply to the Entity we receive and just pass over the PsiElement that KtLint passes us.

Some of the location in the tests changed due to this, so this is a disruptive change at least for baselines (as the signature also changes). If we decide to merge it we should flag it in the release notes.

At the same time with KtLint you could only suppress at the @file: level so, aside from baseline, this won't disrupt other workflows.

Comment on lines +63 to +65
io.gitlab.arturbosch.detekt.test.assertThat(findings).hasSize(2)
io.gitlab.arturbosch.detekt.test.assertThat(findings[0]).hasSourceLocation(7, 8)
io.gitlab.arturbosch.detekt.test.assertThat(findings[1]).hasSourceLocation(13, 12)
Copy link
Member Author

Choose a reason for hiding this comment

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

I have a follow-up PR to clean all the detekt-formatting from using non detekt's assertThat function here: cortinico@d9a4ea9

@cortinico
Copy link
Member Author

Can someone take a look at this one?

@cortinico cortinico requested review from chao2zhang, 3flex and BraisGabin and removed request for chao2zhang and 3flex March 15, 2023 18:54
@@ -41,32 +36,6 @@ abstract class FormattingRule(config: Config) : Rule(config) {
val runAsLateAsPossible
get() = RunAsLateAsPossible in wrapping.visitorModifiers

private val emit = { offset: Int, message: String, canBeAutoCorrected: Boolean ->
val (line, column) = positionByOffset(offset)
val location = Location(
Copy link
Member

Choose a reason for hiding this comment

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

Would you mind adding a unit test for the location if such test has not existed

Copy link
Member Author

Choose a reason for hiding this comment

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

I've updated the tests to follow the logic here (i.e. previously we had a test that was checking file suppression as valid and local suprresion as not. Now the test checks that both suppressions are valid).

@chao2zhang chao2zhang enabled auto-merge (squash) March 16, 2023 14:48
@github-actions
Copy link

Warnings
⚠️ This PR is approved with no milestone set. If merged, it won't appear in the Detekt release notes.

Generated by 🚫 dangerJS against 202b2f7

@codecov
Copy link

codecov bot commented Mar 16, 2023

Codecov Report

Merging #5876 (202b2f7) into main (8997201) will decrease coverage by 0.14%.
The diff coverage is 88.88%.

@@             Coverage Diff              @@
##               main    #5876      +/-   ##
============================================
- Coverage     84.59%   84.46%   -0.14%     
  Complexity     3784     3784              
============================================
  Files           546      546              
  Lines         12944    12923      -21     
  Branches       2273     2268       -5     
============================================
- Hits          10950    10915      -35     
- Misses          861      877      +16     
+ Partials       1133     1131       -2     
Impacted Files Coverage Δ
...lab/arturbosch/detekt/formatting/FormattingRule.kt 90.56% <88.88%> (-1.50%) ⬇️

... and 6 files with indirect coverage changes

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

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