| 1 | # import/default
|
|---|
| 2 |
|
|---|
| 3 | 💼 This rule is enabled in the following configs: ❗ `errors`, ☑️ `recommended`.
|
|---|
| 4 |
|
|---|
| 5 | <!-- end auto-generated rule header -->
|
|---|
| 6 |
|
|---|
| 7 | If a default import is requested, this rule will report if there is no default
|
|---|
| 8 | export in the imported module.
|
|---|
| 9 |
|
|---|
| 10 | For [ES7], reports if a default is named and exported but is not found in the
|
|---|
| 11 | referenced module.
|
|---|
| 12 |
|
|---|
| 13 | Note: for packages, the plugin will find exported names
|
|---|
| 14 | from [`jsnext:main`], if present in `package.json`.
|
|---|
| 15 | Redux's npm module includes this key, and thereby is lintable, for example.
|
|---|
| 16 |
|
|---|
| 17 | A module path that is [ignored] or not [unambiguously an ES module] will not be reported when imported.
|
|---|
| 18 |
|
|---|
| 19 | [ignored]: ../README.md#importignore
|
|---|
| 20 | [unambiguously an ES module]: https://github.com/bmeck/UnambiguousJavaScriptGrammar
|
|---|
| 21 |
|
|---|
| 22 | ## Rule Details
|
|---|
| 23 |
|
|---|
| 24 | Given:
|
|---|
| 25 |
|
|---|
| 26 | ```js
|
|---|
| 27 | // ./foo.js
|
|---|
| 28 | export default function () { return 42 }
|
|---|
| 29 |
|
|---|
| 30 | // ./bar.js
|
|---|
| 31 | export function bar() { return null }
|
|---|
| 32 |
|
|---|
| 33 | // ./baz.js
|
|---|
| 34 | module.exports = function () { /* ... */ }
|
|---|
| 35 |
|
|---|
| 36 | // node_modules/some-module/index.js
|
|---|
| 37 | exports.sharedFunction = function shared() { /* ... */ }
|
|---|
| 38 | ```
|
|---|
| 39 |
|
|---|
| 40 | The following is considered valid:
|
|---|
| 41 |
|
|---|
| 42 | ```js
|
|---|
| 43 | import foo from './foo'
|
|---|
| 44 |
|
|---|
| 45 | // assuming 'node_modules' are ignored (true by default)
|
|---|
| 46 | import someModule from 'some-module'
|
|---|
| 47 | ```
|
|---|
| 48 |
|
|---|
| 49 | ...and the following cases are reported:
|
|---|
| 50 |
|
|---|
| 51 | ```js
|
|---|
| 52 | import bar from './bar' // no default export found in ./bar
|
|---|
| 53 | import baz from './baz' // no default export found in ./baz
|
|---|
| 54 | ```
|
|---|
| 55 |
|
|---|
| 56 | ## When Not To Use It
|
|---|
| 57 |
|
|---|
| 58 | If you are using CommonJS and/or modifying the exported namespace of any module at
|
|---|
| 59 | runtime, you will likely see false positives with this rule.
|
|---|
| 60 |
|
|---|
| 61 | This rule currently does not interpret `module.exports = ...` as a `default` export,
|
|---|
| 62 | either, so such a situation will be reported in the importing module.
|
|---|
| 63 |
|
|---|
| 64 | ## Further Reading
|
|---|
| 65 |
|
|---|
| 66 | - Lee Byron's [ES7] export proposal
|
|---|
| 67 | - [`import/ignore`] setting
|
|---|
| 68 | - [`jsnext:main`] (Rollup)
|
|---|
| 69 |
|
|---|
| 70 | [ES7]: https://github.com/leebyron/ecmascript-more-export-from
|
|---|
| 71 | [`import/ignore`]: ../../README.md#importignore
|
|---|
| 72 | [`jsnext:main`]: https://github.com/rollup/rollup/wiki/jsnext:main
|
|---|