2020-08-25 23:57:08 +00:00
# import/no-named-as-default
2024-03-28 02:25:32 +00:00
⚠️ This rule _warns_ in the following configs: ☑️ `recommended` , 🚸 `warnings` .
<!-- end auto - generated rule header -->
2020-08-25 23:57:08 +00:00
Reports use of an exported name as the locally imported name of a default export.
Rationale: using an exported name as the name of the default export is likely...
2024-03-28 02:25:32 +00:00
- _misleading_: others familiar with `foo.js` probably expect the name to be `foo`
- _a mistake_: only needed to import `bar` and forgot the brackets (the case that is prompting this)
2020-08-25 23:57:08 +00:00
## Rule Details
Given:
2024-03-28 02:25:32 +00:00
2020-08-25 23:57:08 +00:00
```js
// foo.js
export default 'foo';
export const bar = 'baz';
```
...this would be valid:
2024-03-28 02:25:32 +00:00
2020-08-25 23:57:08 +00:00
```js
import foo from './foo.js';
```
...and this would be reported:
2024-03-28 02:25:32 +00:00
2020-08-25 23:57:08 +00:00
```js
// message: Using exported name 'bar' as identifier for default export.
import bar from './foo.js';
```
For post-ES2015 `export` extensions, this also prevents exporting the default from a referenced module as a name within that module, for the same reasons:
```js
// valid:
2022-11-10 10:43:16 +00:00
export foo from './foo.js';
2020-08-25 23:57:08 +00:00
// message: Using exported name 'bar' as identifier for default export.
export bar from './foo.js';
```
## Further Reading
2024-03-28 02:25:32 +00:00
- ECMAScript Proposal: [export ns from]
- ECMAScript Proposal: [export default from]
2020-08-25 23:57:08 +00:00
[export ns from]: https://github.com/leebyron/ecmascript-export-ns-from
[export default from]: https://github.com/leebyron/ecmascript-export-default-from