Skip to content

Latest commit

 

History

History
97 lines (70 loc) · 1.96 KB

prefer-export-from.md

File metadata and controls

97 lines (70 loc) · 1.96 KB

Prefer export…from when re-exporting

💼 This rule is enabled in the ✅ recommended config.

🔧💡 This rule is automatically fixable by the --fix CLI option and manually fixable by editor suggestions.

When re-exporting from a module, it's unnecessary to import and then export. It can be done in a single export…from declaration.

Fail

import defaultExport from './foo.js';
export default defaultExport;
import {named} from './foo.js';
export {named};
import * as namespace from './foo.js';
export {namespace};
import defaultExport, {named} from './foo.js';
export default defaultExport;
export {
	defaultExport as renamedDefault,
	named,
	named as renamedNamed,
};

Pass

export {default} from './foo.js';
export {named} from './foo.js';
export * as namespace from './foo.js';
export {
	default,
	default as renamedDefault,
	named,
	named as renamedNamed,
} from './foo.js';
// There is no substitution
import * as namespace from './foo.js';
export default namespace;

Options

ignoreUsedVariables

Type: boolean
Default: false

When true, if an import is used in other places than just a re-export, all variables in the import declaration will be ignored.

Fail

// eslint unicorn/prefer-export-from: ["error", {"ignoreUsedVariables": false}]
import {named1, named2} from './foo.js';

use(named1);

export {named1, named2};

Pass

// eslint unicorn/prefer-export-from: ["error", {"ignoreUsedVariables": true}]
import {named1, named2} from './foo.js';

use(named1);

export {named1, named2};