question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[no-unused-modules] Feature Request: Option to ignore exports with usage inside the module

See original GitHub issue

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:

export const ACTION = 'I_AM_CONSTANT';

export default reducer(state, action) {
  if (action.type === ACTION) { ... }
}

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 and no-unused-modules specifically?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

3reactions
Ephemcommented, Jun 2, 2020

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! 💯

0reactions
ljharbcommented, Jun 2, 2020

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?

This rule and library is only, and should only be, concerned with imports and exports directly and that the proposed option and use case is outside of that scope

Yes, objectively.

There are no valid use cases for exporting unused things, so no-unused-modules should always be on, which lets no-unused-vars find the dead code

This is a bolder stance for me to take, but yes, that’s also my opinion.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[Feature request] Add flag for optionally disabling tree-shaking
Feature request A command line flag to opt-out of tree-shaking (or opt-in to tree-shaking, that defaults true). An alternative could also to ...
Read more >
Feature Requests - Revizto Help Center!
Include STP / STEP file format in list of importable file formats ... Feature request - Option to include individual clashes within groups ......
Read more >
Feature Requests | Minerva KB
Allow to import or export KB Articles from CSV (Excel comma-separated list file) without the use of extra plugins. 56 votes. Featured image...
Read more >
Magento Extensions:Magento Product Export Module
Export your products in almost any format and connect your store to ERPs, stock systems, marketplaces, shopping engines, price comparison sites and more....
Read more >
Modules supported for export - Sitefinity CMS Development
Learn what system elements and modules you can use to create an add-ons. Understand the dependencies between exported items.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found