prefer-export-from
Added in v0.10.1Configuration
Rule details
Prefer export…from when forwarding bindings from another module. The rule
checks named, default and namespace imports, including single export const
aliases whose local name is unused. An attached JSDoc comment keeps such an
alias in place.
Example of incorrect code for this rule.
Example of correct code for this rule.
Fixes and suggestions
Fixes keep imports with other references and value imports that are re-exported only as types. Comments inside the declarations limit the rule to a diagnostic.
An export…from declaration exposes a live binding. When a fix replaces
export default value or export const alias = value, updates to the source
binding become visible to consumers of the re-export.
Options
checkUsedVariables
Type boolean. Default true.
Set this option to false to skip an entire import declaration when any of its
bindings is used outside a re-export. When the declaration contains both
re-exported and unused bindings, the rule offers a suggestion for the re-exports.
Differences from upstream
- Fixes preserve dependency evaluation order. If a file imports
./setup.jsbefore./consumer.js, the direct re-export of./setup.jsstays before./consumer.js. Re-exports with differentwithattributes stay separate. - Re-exporting
nsfromimport main, * as ns from 'lib'keeps the default import valid. Imports used as JSX factories also stay in place, including custom factories and imports used after a local binding shadows the factory elsewhere in the file. - With
verbatimModuleSyntaxenabled in the linted project,import {type T}stays in place when it is the only binding in the declaration. The import can still load the dependency at runtime. - Re-exports inside
declare moduleand re-exports ofimport deferbindings receive diagnostics only. Directeval()also blocks edits that would remove a local binding it could read. - For files using legacy
assert { … }import assertions, switch towith { … }import attributes before applying the rule.