Skip to content
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

Add an option to allow one to opt-out of adding empty import lists #118

Open
ThomasLamprecht opened this issue Jan 22, 2025 · 3 comments
Open

Comments

@ThomasLamprecht
Copy link

While it might be OK by default to add empty import () statement to use statements that do not already import something so that they are future proofed against new default-exports it still adds a lot of noise and in bigger code bases that are under control by the same org it doesn't gains much value.

That's why I'd like to request a new option to opt-out of adding such "empty import statements" (or however they are called).

E.g., as of now the following line:

use Foo::Bar;

Always becomes

use Foo::Bar ();

With the newly proposed option that line should stay the same, at least if Foo::Bar is used at all.

Thanks for your consideration and for this module in general!

@oalders
Copy link
Member

oalders commented Jan 22, 2025

Thanks for this! My proposal would be to try to do this with the existing functionality. A few options:

use Foo::Bar; ## no perlimports
perlimports --ignore-module Foo::Bar ...
perlimports --create-config-file perlimports.toml

The config file gives you various options for default ignores:

ignore_modules                  = []
ignore_modules_filename         = ""
ignore_modules_pattern          = "" # regex like "^(Foo|Foo::Bar)"
ignore_modules_pattern_filename = ""

See https://metacpan.org/dist/App-perlimports/view/script/perlimports#-ignore-modules for a summary of these. The *_filename options are probably not so useful if you're already using a config file, but they are available. The would be more useful as command line switches, I think.

@ThomasLamprecht
Copy link
Author

Thanks for your reply. The issue here is that we do not want to unconditionally ignore modules, just avoid adding the empty import by default for everything which is really not the same thing as ignoring them FWICT.

@oalders
Copy link
Member

oalders commented Jan 23, 2025

Can you give me some concrete examples of what perlimports is doing vs what you think it should be doing? Maybe a couple of diffs to illustrate the problem.

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

No branches or pull requests

2 participants