Skip to content

Commit b371b45

Browse files
committed
docs update for no-named-as-default
1 parent 2f5d72b commit b371b45

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

README.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,20 @@ This plugin intends to support linting of ES6 import syntax, and prevent issues
1313
* Ensure imported namespaces contain dereferenced properties as they are dereferenced. ([`namespace`](#namespace))
1414
* Report assignments (at any scope) to imported names/namespaces. ([`no-reassign`](#no-reassign))
1515
* Report CommonJS `require` of ES6 module. ([`no-require`](#no-require), off by default)
16+
* Report use of exported name as identifier of default export ([`no-named-as-default`](#no-named-as-default))
17+
18+
## Installation
19+
20+
```sh
21+
npm install eslint-plugin-import -g
22+
```
23+
24+
or if you manage ESLint as a dev dependency:
25+
26+
```sh
27+
# inside your project's working tree
28+
npm install eslint-plugin-import --save-dev
29+
```
1630

1731
## Rules
1832

@@ -66,6 +80,34 @@ Will also report shadowing (i.e. redeclaration as a variable, function, or param
6680

6781
Reports `require` of modules with ES named or default exports. Off by default.
6882

83+
### `no-named-as-default`
84+
85+
Reports use of an exported name as the locally imported name of a default export.
86+
87+
Given:
88+
```js
89+
// foo.js
90+
export default 'foo';
91+
export const bar = 'baz';
92+
```
93+
94+
...this would be valid:
95+
```js
96+
import foo from './foo.js';
97+
```
98+
99+
...and this would be reported:
100+
```js
101+
// message: Using exported name 'bar' as identifier for default export.
102+
import bar from './foo.js';
103+
```
104+
105+
Rationale: using an exported name as the name of the default export is likely
106+
107+
- misleading: others familiar with `foo.js` probably expect the name to be `foo`
108+
- a mistake: only needed to import `bar` and forgot the brackets (the case that is prompting this)
109+
110+
69111
## Debugging
70112

71113
### `no-errors`

0 commit comments

Comments
 (0)