-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
[no-unused-modules] Feature Request: Option to ignore exports with usage inside the module #1728
Comments
I did a very hacky proof of concept-version of this as a new rule ( I think trying to approach it by using |
I'm not entirely clear on your goal. In this case (for After doing so, What's the value of a rule that tells you both in one pass? |
The value would be for people who like my team don't consider extra A separate case is where you export internals from a module for testing purposes. While we don't do this heavily, there are definitely cases where we rely on it, so we can't remove the export-token. I guess this specific case could be solved by including the test-files for linting, but then I'm not sure if we would find dead exports that have remaining tests? For us, turning on As an aside, I think having this as a separate rule in |
Generally, exporting things just for tests is considered an antipattern, so if something is only imported in tests, it's dead code. If you get false positives with
The existing rule should be checking if it's actually imported somewhere - merely exporting something shouldn't be sufficient with the |
Thanks for engaging and I'm sorry for not expressing this more clearly, let me try to clear things up! 😄
It's rock stable! I was talking about
In this part I was talking about
While I agree (which is why we don't use it very often), there are definitely cases where this is useful, and differing opinions on this being an antipattern. So while I agree, this seems a bit prescriptive for this rule? To take a step back and reformulate. I want a rule that can find dead code, but To make sure I understand you correctly, are you expressing two arguments against this option?
I'm very much interpreting here, so please correct me if I'm putting words in your mouth! These are both sensible and kind of expected arguments. I guess what I'm arguing is part that there are valid use cases for not wanting to have Anecdotally I almost never see unused exports in open source, but in my experience from a bunch of commercial projects, it's a common pattern to signal parts of a module that are considered "public" for other developers of the same project. |
I think your analysis is correct (there's rules to remove unused vars, and unused exports, but not dead code entirely). However, if you remove all unused vars and all unused exports and all un-imported files, how would you have any dead code left?
Yes, objectively.
This is a bolder stance for me to take, but yes, that's also my opinion. |
Thanks for explaining! While we do things a bit differently I think this makes sense from the library point of view, supporting every usecase quickly gets a library diluted and unnecessarily complex. This issue has been open a while with no further interest expressed from others, so I'll go ahead and close it, thanks again for the discussion and your hard work! 💯 |
Both the original issues for this rule (#186, #361) mention finding dead code as the main motivation for implementing the rule. It is useful for that today, but I think this aspect can be improved further.
A common pattern I see is something like the following. The example is borrowed from Redux, but I see this in a lot of other contexts as well:
In the above case,
ACTION
is often not imported and used in another file, but is still exported to signal to other developers that it is fine to do so if they need it.ACTION
is not a dead variable, but it is a dead export, but what I want is to determine if it is dead code.What if this rule could be combined with something like the functionality from
no-unused-vars
to verify that an export is neither used in another module or in the same one? This would find actual dead code.The current use of the rule is something like "find out where you can remove the
export
statement, and possibly dead code", which is a fine use case in itself, so I propose adding this functionality behind an option, which also avoids a breaking change.Does this seem useful and like something that would fit into
eslint-plugin-import
in general andno-unused-modules
specifically?The text was updated successfully, but these errors were encountered: