add option to skip outputting empty import lists in use statements #123
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This adds an option flag that, when enabled, causes perlimports to stop outputting empty import lists for use statements where there is no symbol to be imported.
While some projects and people want empty import lists to increase clarity and prevent the used module from having default exports in the future, others see them as unnecessary visual noise and would like to avoid them.
The CLI option is named
--skip-empty-imports, and the configuration option is namedskip_empty_imports. Both default to false, maintaining the current behavior that provides more deterministic clarity and future-proofs against export changes in the used modules.Thanks to the existing code infrastructure, the implementation is relatively straightforward. We just add new options and wire them up so that they are available in the Include module when outputting. Since there is already a dedicated code branch for modules that never export or from which nothing is imported, we can modify the output format string template there to differentiate between the respective values of the new skip_empty_imports flag.
Add two tests to ensure that enabling and disabling explicitly work. Reuse the existing original-imports.pl test data module, as it is a fitting test asset.
Closes: #118
Open questions/tasks:
--range-beginand--range-endflags, and there the experimental status was only mentioned in the respective entry for the Changes file (ref commit e412e9c), so I opted for doing the same thing. Is that OK, or should I add other experimental markings somewhere?--skip-empty-importsand the config property nameskip_empty_importsOK as is?And FWICT from implementing this my available time should be more than enough to stick around for bug fixes, albeit–for full transparency–I might need a few days, and seldomly even one or two weeks to respond, depending on work crunch/time-off/etc.