Tim van der Lippe | fdbd42e | 2020-04-07 14:14:36 | [diff] [blame] | 1 | # import/no-named-as-default |
| 2 | |
| 3 | Reports use of an exported name as the locally imported name of a default export. |
| 4 | |
| 5 | Rationale: using an exported name as the name of the default export is likely... |
| 6 | |
| 7 | - *misleading*: others familiar with `foo.js` probably expect the name to be `foo` |
| 8 | - *a mistake*: only needed to import `bar` and forgot the brackets (the case that is prompting this) |
| 9 | |
| 10 | ## Rule Details |
| 11 | |
| 12 | Given: |
| 13 | ```js |
| 14 | // foo.js |
| 15 | export default 'foo'; |
| 16 | export const bar = 'baz'; |
| 17 | ``` |
| 18 | |
| 19 | ...this would be valid: |
| 20 | ```js |
| 21 | import foo from './foo.js'; |
| 22 | ``` |
| 23 | |
| 24 | ...and this would be reported: |
| 25 | ```js |
| 26 | // message: Using exported name 'bar' as identifier for default export. |
| 27 | import bar from './foo.js'; |
| 28 | ``` |
| 29 | |
| 30 | 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: |
| 31 | |
| 32 | ```js |
| 33 | // valid: |
| 34 | export foo from './foo.js' |
| 35 | |
| 36 | // message: Using exported name 'bar' as identifier for default export. |
| 37 | export bar from './foo.js'; |
| 38 | ``` |
| 39 | |
| 40 | ## Further Reading |
| 41 | |
| 42 | - ECMAScript Proposal: [export ns from] |
| 43 | - ECMAScript Proposal: [export default from] |
| 44 | |
| 45 | [export ns from]: https://github.com/leebyron/ecmascript-export-ns-from |
| 46 | [export default from]: https://github.com/leebyron/ecmascript-export-default-from |