Skip to content
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

prefer-export-from shouldn't report re-export of variable that is used in other statements #1577

Closed
FloEdelmann opened this issue Nov 6, 2021 · 5 comments · Fixed by #1590
Assignees
Labels

Comments

@FloEdelmann
Copy link
Contributor

FloEdelmann commented Nov 6, 2021

import { a } from './my-module.js';

export const exportA = a;
export const exportB = a.b;

The prefer-export-from rule warns about the first export and wants to change it to:

import { a } from './my-module.js';


export const exportB = a.b;
export { a as exportA } from './my-module.js';

I think that this duplication is more confusing: a imported as a, but also re-exported with a different name.

I therefore suggest to ignore exports of variables that are used in other statements.

Real-life reproduction: OpenLightingProject/open-fixture-library@dependabot/npm_and_yarn/eslint-plugin-unicorn-38.0.1/lib/schema-properties.js

@fisker
Copy link
Collaborator

fisker commented Nov 6, 2021

Check this comment and related comments #1453 (comment)

@fregante
Copy link
Collaborator

fregante commented Nov 6, 2021

@fisker those comments seems a bit reasonable with a foo module, but re-exporting other npm modules is rare and not really advised, especially export default from

The example should use local files:

import {MyTinyForm} from '../components/forms/tiny.js';
export {MyTinyForm} from '../components/forms/tiny.js';

console.log('Registered', MyTinyForm.getName());

… and that's awful compared to

import {MyTinyForm} from '../components/forms/tiny.js';
export {MyTinyForm};

console.log('Registered', MyTinyForm.getName());

Even OP’s example shows that the rule does not suggest cleaner code.

@fisker
Copy link
Collaborator

fisker commented Nov 8, 2021

A ignoredUsedVariables option?

@fisker
Copy link
Collaborator

fisker commented Nov 8, 2021

@sindresorhus ^

@sindresorhus
Copy link
Owner

Sure. ignoredUsedVariables => ignoreUsedVariables

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants