import-js/eslint-plugin-import

Rule to detect import of modules with and without directives

thomasballinger opened this issue · 3 comments

"use server" and "use client" are directives use in React that I might want to lint I'm including. In React it might be useful to lint that "use client" files cannot import "use server" files.

I'm personally interested in a rule that lint for a different directive, "use node", to enforce that modules without the "use node" directive do not import files with the "use node" directive.

A general version might be "modules with/without directive X must/cannot import modules with/without directive Y.

This seems like it would require similar machinery to default and named named.

Think there's general interest in this? Or if I'm looking at building my own plugin to provide this, suggestions on ways to reuse the machinery in eslint-plugin-import for it?

Since that's react-specific, it'd be more appropriate for eslint-plugin-react, but since it's cross-file-specific, this is basically the only plugin that checks that.

I'd say that if that's generally useful, it's something the react team should be providing. Either way, I'd caution you against building tooling for unreleased versions of React.

I'm particularly interested in a lint for my own directive "use node", which isn't a React thing. But similar to the React lint, it's probably my job to provide this to my users, not eslint-plugin-import's. While I'm curious about a more general version like "modules without directive X cannot import modules with directive X" that might be more configuration that is convenient.

I'll leave it to you to close this issue, maybe linting for directives like this is common enough for a general version to be useful? But I'll build my own for now.

Directives are widely considered to be an antipattern long predating React's attempt to add them (the language has long had a policy of "no more pragmas" post-strict-mode), and I don't think it's a good idea to encourage further usages of them. I think building your own is the best approach.