Skip to content

[Deprecation] Add config ignoreImport #7878

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

atulgpt
Copy link
Contributor

@atulgpt atulgpt commented Jan 9, 2025

This allows deprecation in imports

Fixes: #7402

@@ -31,7 +31,7 @@ class ArgumentListWrapping(config: Config) : FormattingRule(
@Configuration("maximum line length")
private val maxLineLength by configWithAndroidVariants(120, 100)

@Configuration("paremeter threshold to ignore rule")
@Configuration("parameter threshold to ignore rule")
Copy link
Member

Choose a reason for hiding this comment

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

If you move this change to other PR it will be merged automatically.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have added the PR #7881

Copy link
Contributor Author

Choose a reason for hiding this comment

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

And reverted from here

@BraisGabin
Copy link
Member

The title of this PR is wrong, right? There is nothing related with ignoreRuleParameterThreshold.

}
""".trimIndent()
assertThat(ignoredImportSubject.lintWithContext(env, code, deprecatedFile))
.isEmpty()
Copy link
Member

Choose a reason for hiding this comment

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

I don't like ignoreImport because it creates false negatives. Here the code is using deprecated code but the rule says nothing even when there are more usages of LegacyFeatureFlags outside the imports block.

I also don't like that we can't suppress an issue over an import. It bothers me a lot and I end up using full qualified names in places where I don't want but I think that's better than false negatives.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I also don't like that we can't suppress an issue over an import. same, and most of the users end up suppressing the whole file which prevents any future issue from surfacing

More general issue here is that people tend to suppress at unnecessarily higher level which could be lowered down. Import becomes especially problematic as you don't have option other than file suppression

I end up using full qualified names this is very hard to enforce across the team, also in most of cases using fully qualified name will report the line length violation

there are more usages of LegacyFeatureFlags outside the imports block I didn't get this? there are three usages, two are suppressed and since we are using ignoredImportSubject deprecation in Import is not being reported

Copy link
Member

Choose a reason for hiding this comment

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

Wow! My bad, I didn't see the @Suppress 🤦‍♂️. That have way more sense. I'll re-review this.

@atulgpt atulgpt changed the title [Deprecation] Add config ignoreRuleParameterThreshold [Deprecation] Add config ignoreImport Jan 10, 2025
@atulgpt atulgpt force-pushed the fixes/7402/config-for-ignoring-import-deprecation branch from 3532aab to f08ddb3 Compare January 10, 2025 11:30
@@ -21,15 +25,30 @@ class Deprecation(config: Config) : Rule(
"Deprecated elements should not be used."
) {

@Configuration("Ignore deprecation in import statements")
private val ignoreImport: Boolean by config(false)
Copy link
Member

Choose a reason for hiding this comment

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

This should be plurals as we have excludeImports in another rule

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for pointing out, I have renamed it to excludeImportStatements which is also being used in MaxLineLength rule

@atulgpt atulgpt force-pushed the fixes/7402/config-for-ignoring-import-deprecation branch from 9e23d63 to 18b2297 Compare February 23, 2025 19:44
@atulgpt atulgpt force-pushed the fixes/7402/config-for-ignoring-import-deprecation branch from 18b2297 to e0df908 Compare February 23, 2025 20:00
Copy link

codecov bot commented Feb 23, 2025

Codecov Report

Attention: Patch coverage is 88.88889% with 1 line in your changes missing coverage. Please review.

Project coverage is 85.61%. Comparing base (acfffd3) to head (e0df908).
Report is 76 commits behind head on main.

Files with missing lines Patch % Lines
...gitlab/arturbosch/detekt/rules/bugs/Deprecation.kt 88.88% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##               main    #7878   +/-   ##
=========================================
  Coverage     85.60%   85.61%           
- Complexity     4224     4229    +5     
=========================================
  Files           574      574           
  Lines         13365    13372    +7     
  Branches       2540     2541    +1     
=========================================
+ Hits          11441    11448    +7     
  Misses          653      653           
  Partials       1271     1271           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Test
fun `does not report import location`() {
val deprecatedFile = """
package com.example.detekt.featureflag
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @BraisGabin now my TC is failing when I pass -Pcompile-test-snippets=true. I think this started failing after test api changes. Do you know if anything needs to be changed here?

@detekt-ci
Copy link
Collaborator

This PR is stale because it has been open 90 days with no activity. Please comment or this will be closed in 7 days.

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

Successfully merging this pull request may close these issues.

Can't suppress the Deprecation rule due to reference in import
4 participants