I'd like to prevent myself from using `Color.*` or...
# detekt
c
I'd like to prevent myself from using
Color.*
or
MaterialTheme.colors.*
in my codebase and instead stick to my custom colors I have defined. What's the best way to enforce this with Detekt?
b
ForbiddenImport
. It will not prevent you for use it with the full qualified. But normally that’s good enought
c
I tried using that actually, but I couldn't get
forbiddenPatterns
to take a list of forbidden import patterns.
Let me try again. Maybe I didn't wrap it in an array correctly or something.
b
I would recommend you to use
imports
instead of
forbiddenPatterns
I like to use it like this:
Copy code
imports:
  - value: 'Colors.'
     reason: 'Use out custom colors `x.y.z` instead.'
  - value: ...
This way the person that reads the error knows how to solve the issue
c
Oh. I like that. TIL Let me try!
Just a question. for your example. Is that possible? "Colors."? Wouldn't the import be something like
x.y.Colors
?
Or can that section also take a regex essentially?
b
I think that the check is “starts with”. But’ I didn’t check.
So yes,
x.y.Colors
would do the work
Any update in the documentation to make the usage more clear is more than welcome.
We do our best but we need that the new people point us the issues and help us fixing it. There is a long time since I read that documentation blob sweat smile
c