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
ForbiddenImport matches on substring, not full class #1573
Comments
Thanks for reporting and having a look into it! |
josephlbarnett
added a commit
to josephlbarnett/detekt
that referenced
this issue
Apr 3, 2019
Shows that forbidding net.example.R.dimen also forbids net.example.R.dimension.
josephlbarnett
added a commit
to josephlbarnett/detekt
that referenced
this issue
Apr 3, 2019
Shows that forbidding net.example.R.dimen also forbids net.example.R.dimension.
josephlbarnett
added a commit
to josephlbarnett/detekt
that referenced
this issue
Apr 3, 2019
PR submitted: #1575 |
josephlbarnett
added a commit
to josephlbarnett/detekt
that referenced
this issue
Apr 3, 2019
Shows that forbidding net.example.R.dimen also forbids net.example.R.dimension.
josephlbarnett
added a commit
to josephlbarnett/detekt
that referenced
this issue
Apr 3, 2019
josephlbarnett
added a commit
to josephlbarnett/detekt
that referenced
this issue
Apr 4, 2019
arturbosch
pushed a commit
that referenced
this issue
Apr 7, 2019
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
The bug you're experiencing might have already be reported!
Please search in the issues before creating one.
Expected Behavior
There should be a way to forbid imports of specific classes and not match classes that are similar, but different.
Observed Behavior
because
ForbiddenImport
uses thecontains
method ofSplitPattern
, trying to forbid a class whose name is a substring of another class forbids both classes. I believe callingSplitPattern::equals
instead would fix the issue, but have not tested, and would probably break other usages (eg the wildcards in #1001 ).Steps to Reproduce
forbid
com.google.inject.Inject
, and run detekt against a class that importscom.google.inject.Injector
Context
We'd like to forbid imports of guice classes that exist in javax.inject, for example
javax.inject.Inject
should be used overcom.google.inject.Inject
. However, addingcom.google.inject.Inject
to theForbiddenImports
rule also forbids imports ofcom.google.inject.Injector
, which is a class that has no javax.inject equivalent that we do not want to forbid.Your Environment
The text was updated successfully, but these errors were encountered: