Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin940726 authored Apr 10, 2017
2 parents b060805 + 98e7048 commit 33ab6be
Show file tree
Hide file tree
Showing 6 changed files with 154 additions and 59 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
## [Unreleased]
### Added
- [`no-anonymous-default-export`] rule: report anonymous default exports ([#712], thanks [@duncanbeevers]).
- Add new value to `order`'s `newlines-between` option to allow newlines inside import groups ([#627], [#628], thanks [@giodamelio])
- Add new value to [`order`]'s `newlines-between` option to allow newlines inside import groups ([#627], [#628], thanks [@giodamelio])
- Add `count` option to the [`newline-after-import`] rule to allow configuration of number of newlines expected ([#742], thanks [@ntdb])
- Add `allow` option to [`no-unassigned-import`] to allow for files that match the globs ([#671], [#737], thanks [@kevin940726]).

### Changed
- [`no-extraneous-dependencies`]: use `read-pkg-up` to simplify finding + loading `package.json` ([#680], thanks [@wtgtybhertgeghgtwtg])

### Fixed
- attempt to fix crash in [`no-mutable-exports`]. ([#660])
- "default is a reserved keyword" in no-maned-default tests by locking down babylon to 6.15.0 (#756, thanks @gmathieu)


## [2.2.0] - 2016-11-07
Expand Down Expand Up @@ -383,7 +385,9 @@ for info on changes for earlier releases.
[`unambiguous`]: ./docs/rules/unambiguous.md
[`no-anonymous-default-export`]: ./docs/rules/no-anonymous-default-export.md


[#737]: https://github.com/benmosher/eslint-plugin-import/pull/737
[#742]: https://github.com/benmosher/eslint-plugin-import/pull/742
[#712]: https://github.com/benmosher/eslint-plugin-import/pull/712
[#680]: https://github.com/benmosher/eslint-plugin-import/pull/680
[#654]: https://github.com/benmosher/eslint-plugin-import/pull/654
Expand Down Expand Up @@ -575,3 +579,4 @@ for info on changes for earlier releases.
[@duncanbeevers]: https://github.com/duncanbeevers
[@giodamelio]: https://github.com/giodamelio
[@kevin940726]: https://github.com/kevin940726
[@ntdb]: https://github.com/ntdb
40 changes: 38 additions & 2 deletions docs/rules/newline-after-import.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# newline-after-import

Enforces having an empty line after the last top-level import statement or require call.
Enforces having one or more empty lines after the last top-level import statement or require call.

## Rule Details

This rule has one option, `count` which sets the number of newlines that are enforced after the last top-level import statement or require call. This option defaults to `1`.

Valid:

```js
Expand All @@ -26,7 +28,7 @@ const BAR = require('./bar')
const BAZ = 1
```

...whereas here imports will be reported:
Invalid:

```js
import * as foo from 'foo'
Expand All @@ -46,6 +48,40 @@ const BAZ = 1
const BAR = require('./bar')
```

With `count` set to `2` this will be considered valid:

```js
import defaultExport from './foo'


const FOO = 'BAR'
```

With `count` set to `2` these will be considered invalid:

```js
import defaultExport from './foo'
const FOO = 'BAR'
```

```js
import defaultExport from './foo'

const FOO = 'BAR'
```


## Example options usage
```
{
...
"rules": {
"import/newline-after-import": [{ "count": 2 }]
}
}
```


## When Not To Use It

If you like to visually group module imports with its usage, you don't want to use this rule.
2 changes: 1 addition & 1 deletion docs/rules/no-named-as-default.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import foo from './foo.js';
import bar from './foo.js';
```

For post-ES2015 `export` extensions, this also prevents exporting the default from a referenced module as a name within than module, for the same reasons:
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:
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"babel-plugin-istanbul": "^2.0.1",
"babel-preset-es2015-argon": "latest",
"babel-register": "6.16.3",
"babylon": "6.15.0",
"chai": "^3.4.0",
"coveralls": "^2.11.4",
"cross-env": "^3.1.0",
Expand Down
15 changes: 14 additions & 1 deletion src/rules/newline-after-import.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,18 @@ function isClassWithDecorator(node) {
module.exports = {
meta: {
docs: {},
schema: [
{
'type': 'object',
'properties': {
'count': {
'type': 'integer',
'minimum': 1,
},
},
'additionalProperties': false,
},
],
},
create: function (context) {
let level = 0
Expand All @@ -55,7 +67,8 @@ module.exports = {
nextNode = nextNode.decorators[0]
}

if (getLineDifference(node, nextNode) < 2) {
const options = context.options[0] || { count: 1 }
if (getLineDifference(node, nextNode) < options.count + 1) {
let column = node.loc.start.column

if (node.loc.start.line !== node.loc.end.line) {
Expand Down
Loading

0 comments on commit 33ab6be

Please sign in to comment.