Skip to content

Report SwallowedException on catchParameter #4158

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

Merged
merged 2 commits into from
Oct 18, 2021

Conversation

chao2zhang
Copy link
Member

This improves the ergonomics so that users can minimize the suppression scope.
Addresses #4154

I am using the detekt repo itself as the integration test for the PR change, otherwise I probably need to write an integration test in detekt-core which does not seem like the right place because the change is in detekt-rules-exceptions.

This improves the ergonomics so that users can minimize the suppression scope.
@chao2zhang chao2zhang linked an issue Oct 3, 2021 that may be closed by this pull request
@codecov
Copy link

codecov bot commented Oct 4, 2021

Codecov Report

Merging #4158 (0a1a994) into main (8894bc2) will decrease coverage by 0.01%.
The diff coverage is 57.14%.

Impacted file tree graph

@@             Coverage Diff              @@
##               main    #4158      +/-   ##
============================================
- Coverage     83.44%   83.43%   -0.02%     
- Complexity     3177     3190      +13     
============================================
  Files           465      465              
  Lines          9104     9121      +17     
  Branches       1775     1780       +5     
============================================
+ Hits           7597     7610      +13     
  Misses          572      572              
- Partials        935      939       +4     
Impacted Files Coverage Δ
...kotlin/io/gitlab/arturbosch/detekt/api/Location.kt 84.61% <0.00%> (ø)
...ain/kotlin/io/github/detekt/metrics/LinesOfCode.kt 95.00% <0.00%> (ø)
...osch/detekt/rules/exceptions/SwallowedException.kt 73.68% <57.14%> (-0.87%) ⬇️
...tekt/rules/exceptions/TooGenericExceptionCaught.kt 87.50% <66.66%> (ø)
...tlin/io/gitlab/arturbosch/detekt/cli/JCommander.kt 100.00% <100.00%> (ø)
...n/kotlin/io/github/detekt/report/html/HtmlUtils.kt 98.00% <100.00%> (ø)
...ab/arturbosch/detekt/rules/style/WildcardImport.kt 90.00% <0.00%> (-4.12%) ⬇️
...urbosch/detekt/rules/performance/ArrayPrimitive.kt 71.42% <0.00%> (-3.58%) ⬇️
.../detekt/rules/naming/ConstructorParameterNaming.kt 96.55% <0.00%> (-3.45%) ⬇️
...rbosch/detekt/rules/complexity/NestedBlockDepth.kt 91.83% <0.00%> (+0.72%) ⬆️
... and 2 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 8894bc2...0a1a994. Read the comment docs.

@chao2zhang chao2zhang added this to the 1.19.0 milestone Oct 4, 2021
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.

I am using the detekt repo itself as the integration test for the PR change, otherwise I probably need to write an integration test in detekt-core which does not seem like the right place because the change is in detekt-rules-exceptions.

No you don't need to write any integration test. The engine that runs the rules in test honor the @Suppress so you can unit test it easily.

Or, if you prefer, you can test that the reported text is the correct one.

try {
@Suppress("SpreadOperator")
jCommander.parse(*args)
} catch (ex: ParameterException) {
} catch (@Suppress("SwallowedException") ex: ParameterException) {
Copy link
Member

Choose a reason for hiding this comment

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

Will it still accept suppressing on try? because a change shouldn't force everyone to move suppressions.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, try is a parent of catch so the suppression engine should allow now both.

@BraisGabin
Copy link
Member

Now this fixes #4153 too.

@TWiStErRob
Copy link
Member

@BraisGabin in #4153 you said add a test, I don't see it here.

@chao2zhang chao2zhang merged commit 7b9ee70 into detekt:main Oct 18, 2021
@chao2zhang chao2zhang deleted the exceptionscope branch October 18, 2021 00:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot suppress SwallowedException on catch variable
4 participants