-
-
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-named-as-default warn/error when value is both named export and default export #1594
Comments
This is intentional; since there’s a named export named “file”, the rule won’t let you use that name for the default when importing. |
What about a simpler example: // Bar.js
/** @private visible for testing */
export const foo = 42;
/** @private visible for testing */
export class BarHelper{}
export class Bar {
}
export default Bar; // Bar.test.js
import {foo, Bar, BarHelper} from '../src/Bar.js'
// write tests against Bar // index.js
// no-named-as-default error here
import Bar from './Bar.js';
// use Bar for real
const bar = new Bar(); In this case it will complain about the |
@markmsmith yeah, your example is more clear. Still I find that the issue triggering the warn/error of eslint is annoying for these use cases |
That makes no sense to me why you’d double-export Bar. Tests should be testing the same thing production uses - which in your case is the default export. |
Yeah, but I'm making a npm package and each "submodule" folder as an index file that re-exports everything + a default. It was easier to do it and have most of the "submodule" defaults only accessible by name (not default) outside of the npm package |
I have run into this too when trying to consume some npm packages. For instance the https://www.npmjs.com/package/abort-controller has the following exports: export default AbortController
export { AbortController, AbortSignal } It would be nice if doing I prefer keeping the rule in place so that if a package does the following: export default foo;
export { bar, bat }; I do get a warning if I do |
While I continue to think that it's utter nonsense to export the same value twice, I agree that in that case only, the rule should not warn. I'd be happy to accept a PR that handled that (perhaps under an option) |
Fair enough, it does seem like a really bad practice and I think it should be under an option. |
I can try this. I have lots of "false positives" for import userEvent from '@testing-library/user-event'; I'd like to get rid of. Forking the repo right now. |
I'm back at this and I'm trying to cover all possible cases. It's my first contribution to But what I have found so far it's that there are 2 distinct cases of this problem:
I am able to address the case no. 1, because the But I don't thing I'm able to verify that in the case no. 2 Or maybe I reached a dead-end trying to solve the case no. 2 with the If you have some ideas on which API I should use to solve the case no. 2 please let me know. For now I'll try to clean-up the PR with the solution for the re-export case. Footnotes
|
…is both a named and a default export - add tests for import-js#1594
…is both a named and a default export - add tests for import-js#1594
Example (here I want to export everything from one or merge more files, then set a default export):
The text was updated successfully, but these errors were encountered: