Skip to content

Commit bd243b2

Browse files
authored
Merge branch 'master' into master
2 parents 1fe3b4a + 98e7048 commit bd243b2

File tree

5 files changed

+152
-58
lines changed

5 files changed

+152
-58
lines changed

CHANGELOG.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
66
## [Unreleased]
77
### Added
88
- [`no-anonymous-default-export`] rule: report anonymous default exports ([#712], thanks [@duncanbeevers]).
9-
- Add new value to `order`'s `newlines-between` option to allow newlines inside import groups ([#627], [#628], thanks [@giodamelio])
9+
- Add new value to [`order`]'s `newlines-between` option to allow newlines inside import groups ([#627], [#628], thanks [@giodamelio])
10+
- Add `count` option to the [`newline-after-import`] rule to allow configuration of number of newlines expected ([#742], thanks [@ntdb])
1011

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

1415
### Fixed
1516
- attempt to fix crash in [`no-mutable-exports`]. ([#660])
17+
- "default is a reserved keyword" in no-maned-default tests by locking down babylon to 6.15.0 (#756, thanks @gmathieu)
1618
- support scoped modules containing non word characters
1719

1820

@@ -383,6 +385,7 @@ for info on changes for earlier releases.
383385
[`unambiguous`]: ./docs/rules/unambiguous.md
384386
[`no-anonymous-default-export`]: ./docs/rules/no-anonymous-default-export.md
385387

388+
[#742]: https://github.com/benmosher/eslint-plugin-import/pull/742
386389
[#712]: https://github.com/benmosher/eslint-plugin-import/pull/712
387390
[#680]: https://github.com/benmosher/eslint-plugin-import/pull/680
388391
[#654]: https://github.com/benmosher/eslint-plugin-import/pull/654
@@ -572,3 +575,4 @@ for info on changes for earlier releases.
572575
[@wtgtybhertgeghgtwtg]: https://github.com/wtgtybhertgeghgtwtg
573576
[@duncanbeevers]: https://github.com/duncanbeevers
574577
[@giodamelio]: https://github.com/giodamelio
578+
[@ntdb]: https://github.com/ntdb

docs/rules/newline-after-import.md

+38-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
# newline-after-import
22

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

55
## Rule Details
66

7+
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`.
8+
79
Valid:
810

911
```js
@@ -26,7 +28,7 @@ const BAR = require('./bar')
2628
const BAZ = 1
2729
```
2830

29-
...whereas here imports will be reported:
31+
Invalid:
3032

3133
```js
3234
import * as foo from 'foo'
@@ -46,6 +48,40 @@ const BAZ = 1
4648
const BAR = require('./bar')
4749
```
4850

51+
With `count` set to `2` this will be considered valid:
52+
53+
```js
54+
import defaultExport from './foo'
55+
56+
57+
const FOO = 'BAR'
58+
```
59+
60+
With `count` set to `2` these will be considered invalid:
61+
62+
```js
63+
import defaultExport from './foo'
64+
const FOO = 'BAR'
65+
```
66+
67+
```js
68+
import defaultExport from './foo'
69+
70+
const FOO = 'BAR'
71+
```
72+
73+
74+
## Example options usage
75+
```
76+
{
77+
...
78+
"rules": {
79+
"import/newline-after-import": [{ "count": 2 }]
80+
}
81+
}
82+
```
83+
84+
4985
## When Not To Use It
5086

5187
If you like to visually group module imports with its usage, you don't want to use this rule.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
"babel-plugin-istanbul": "^2.0.1",
5353
"babel-preset-es2015-argon": "latest",
5454
"babel-register": "6.16.3",
55+
"babylon": "6.15.0",
5556
"chai": "^3.4.0",
5657
"coveralls": "^2.11.4",
5758
"cross-env": "^3.1.0",

src/rules/newline-after-import.js

+14-1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,18 @@ function isClassWithDecorator(node) {
4545
module.exports = {
4646
meta: {
4747
docs: {},
48+
schema: [
49+
{
50+
'type': 'object',
51+
'properties': {
52+
'count': {
53+
'type': 'integer',
54+
'minimum': 1,
55+
},
56+
},
57+
'additionalProperties': false,
58+
},
59+
],
4860
},
4961
create: function (context) {
5062
let level = 0
@@ -55,7 +67,8 @@ module.exports = {
5567
nextNode = nextNode.decorators[0]
5668
}
5769

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

6174
if (node.loc.start.line !== node.loc.end.line) {

0 commit comments

Comments
 (0)