Skip to content

Commit

Permalink
no-named-as-default separate doc
Browse files Browse the repository at this point in the history
  • Loading branch information
benmosher committed Dec 17, 2015
1 parent d1718ea commit 645743a
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 40 deletions.
43 changes: 3 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ This plugin intends to support linting of ES2015+ (ES6+) import/export syntax, a

Helpful warnings:

* Report use of exported name as identifier of default export ([`no-named-as-default`](#no-named-as-default))
* Report use of exported name as identifier of default export ([`no-named-as-default`])

[`no-named-as-default`]: ./docs/rules/no-named-as-default.md

Style guide:

Expand Down Expand Up @@ -73,45 +75,6 @@ rules:

# Rule Details



### `no-named-as-default`

Reports use of an exported name as the locally imported name of a default export.

Given:
```js
// foo.js
export default 'foo';
export const bar = 'baz';
```

...this would be valid:
```js
import foo from './foo.js';
```

...and this would be reported:
```js
// message: Using exported name 'bar' as identifier for default export.
import bar from './foo.js';
```

Rationale: using an exported name as the name of the default export is likely...

- *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)

For [ES7], this also prevents exporting the default from a referenced module as a name within than module, for the same reasons:

```js
// valid:
export foo from './foo.js'

// message: Using exported name 'bar' as identifier for default export.
export bar from './foo.js';
```

### `export`

Reports funny business with exports, such as
Expand Down
44 changes: 44 additions & 0 deletions docs/rules/no-named-as-default.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# `no-named-as-default`

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...

- *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)

## Rule Details

Given:
```js
// foo.js
export default 'foo';
export const bar = 'baz';
```

...this would be valid:
```js
import foo from './foo.js';
```

...and this would be reported:
```js
// message: Using exported name 'bar' as identifier for default export.
import bar from './foo.js';
```

For [ES7], this also prevents exporting the default from a referenced module as a name within than module, for the same reasons:

```js
// valid:
export foo from './foo.js'

// message: Using exported name 'bar' as identifier for default export.
export bar from './foo.js';
```

## Further Reading

- Lee Byron's [ES7] export proposal

[ES7]: https://github.com/leebyron/ecmascript-more-export-from

0 comments on commit 645743a

Please sign in to comment.