Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
NoUnusedImportsFixer - Do not remove imports of the same namespace (if configured) #4243
Removing imports of the same namespace is harmful (see #4159).
This PR disables this behaviour by default in the
I will submit a fixed to add imports for classes of the same namespace in a separate PR.
referenced this pull request
Jan 7, 2019
2 times, most recently
Jan 7, 2019
Hi @arnaud-lb and thanks for all your work here!
Am I correct to see that you change the default behavior of the rule? If so it would be a BC break (at least in this project ;) ) so maybe it would be better to add the option here and later on propose to change the default behavior (on the next major) as it would allow for discussion on that topic :)
@kubawerlos: YAGNI is one of my favorite acronym principles. When following it, we lean towards thinking that if a hypothetical feature is easy to add later, we should do so. This prevents introducing complexity that may not actually be needed in the future, or worse, that may not match the use-cases when the feature is eventually needed.
However, I don't think that it applies here. We are not keeping imports for a hypothetical need: We are keeping them for an actual, current threat: When some code uses a class of the same namespace, and this class is not explicitly imported, it's easy to accidentally shadow it by importing an other class with the same name from an other namespace.
Our goal as developpers is to make the code easy to read and to change.
I don't really understand the need for removing imports of the same namespace. They make the code clearer / more explicit IMHO. I also don't see how they could hurt in any way (performance wise, they are completely free, in case this is the motivation).
(edit: typo / wording)
What do you mean? Have you seen my example from the issue?
Easy to read? Definitely. But easy to change? I would'n say it so important to keep unused imports to be prepared for it.
I look at it from the opposite side - they don't do any good - let's get rid of them.
I've just answered to your comment in the issue
I've shown that in some cases, they do at least some good :) They also have the merit of making things more explicit, which have some value for readability IMHO.