import-linter icon indicating copy to clipboard operation
import-linter copied to clipboard

Support wildcards for modules in forbidden contracts

Open GitRon opened this issue 1 year ago • 3 comments

Hi there!

I found an issue I wasn't able to resolve. I browed through the closed tickets but couldn't find a match there, so I created this ticket.

I use the import-linter (v2.0) with Django and all my Django apps live in apps/. When I try to use a wildcard, the contract never fails. If I put the module explicitly, it works, thus fails.

Works:

[[tool.importlinter.contracts]]
name = "Config is intependent of everything else"
type = "forbidden"
source_modules = ["apps.config"]
forbidden_modules = [
    "apps.account",
]

Not working:

[[tool.importlinter.contracts]]
name = "Config is intependent of everything else"
type = "forbidden"
source_modules = ["apps.config"]
forbidden_modules = [
    "apps.*",
]

Am I missing something? Thanks for your help!

Best from Cologne
Ronny

GitRon avatar Aug 26 '24 14:08 GitRon

Hi Ronny, thanks for the issue.

It's because wildcards aren't supported for those fields, they're only supported (at present) for ignored_imports.

It's got nothing to do with TOML, so I've renamed this issue accordingly.

I'd be happy to support someone on a pull request if they wanted to add this. There is actually a pull request open for adding wildcard support for another contract type (independence), which I've left some feedback on, but it seems to have stalled. Let me know if you're interested in taking it on.

seddonym avatar Aug 27 '24 09:08 seddonym

Hi @seddonym

thanks for the quick reply!

Neither me nor my colleague @fbinz got that this feature is just not implemented. Since I feel not too comfortable with linter code, I could offer a PR for the docs to emphasis this fact.

What do you say?

Best
Ronny

GitRon avatar Aug 27 '24 09:08 GitRon

Sounds good, thanks!

seddonym avatar Aug 27 '24 09:08 seddonym

@seddonym I think this has been implemented now? Shall we close the issue?

Peter554 avatar Feb 12 '25 00:02 Peter554

Yes! Thank you.

seddonym avatar Feb 13 '25 14:02 seddonym