Skip to content

Commit c0f733b

Browse files
committed
Change newlines option to count for newline-after-import rule
1 parent 1d757dc commit c0f733b

File tree

4 files changed

+14
-14
lines changed

4 files changed

+14
-14
lines changed

CHANGELOG.md

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

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

docs/rules/newline-after-import.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Enforces having one or more empty line after the last top-level import statement
44

55
## Rule Details
66

7-
This rule has one option, `newlines` which sets the number of newlines that are enforced after the last top-level import statement or require call. This option defaults to `1`.
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`.
88

99
Valid:
1010

@@ -48,7 +48,7 @@ const BAZ = 1
4848
const BAR = require('./bar')
4949
```
5050

51-
With `newlines` set to `2` this will be considered valid:
51+
With `count` set to `2` this will be considered valid:
5252

5353
```js
5454
import defaultExport from './foo'
@@ -57,7 +57,7 @@ import defaultExport from './foo'
5757
const FOO = 'BAR'
5858
```
5959

60-
With `newlines` set to `2` these will be considered invalid:
60+
With `count` set to `2` these will be considered invalid:
6161

6262
```js
6363
import defaultExport from './foo'
@@ -76,7 +76,7 @@ const FOO = 'BAR'
7676
{
7777
...
7878
"rules": {
79-
"import/newline-after-import": [{ "newlines": 2 }]
79+
"import/newline-after-import": [{ "count": 2 }]
8080
}
8181
}
8282
```

src/rules/newline-after-import.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ module.exports = {
4949
{
5050
'type': 'object',
5151
'properties': {
52-
'newlines': {
52+
'count': {
5353
'type': 'integer',
5454
'minimum': 1,
5555
},
@@ -67,8 +67,8 @@ module.exports = {
6767
nextNode = nextNode.decorators[0]
6868
}
6969

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

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

tests/src/rules/newline-after-import.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,12 @@ ruleTester.run('newline-after-import', require('rules/newline-after-import'), {
8383
{
8484
code: `import foo from 'foo';\n\n\nvar foo = 'bar';`,
8585
parserOptions: { sourceType: 'module' },
86-
options: [{ 'newlines': 2 }],
86+
options: [{ 'count': 2 }],
8787
},
8888
{
8989
code: `import foo from 'foo';\n\n\n\n\nvar foo = 'bar';`,
9090
parserOptions: { sourceType: 'module' },
91-
options: [{ 'newlines': 4 }],
91+
options: [{ 'count': 4 }],
9292
},
9393
{
9494
code: `var foo = require('foo-module');\n\nvar foo = 'bar';`,
@@ -97,12 +97,12 @@ ruleTester.run('newline-after-import', require('rules/newline-after-import'), {
9797
{
9898
code: `var foo = require('foo-module');\n\n\nvar foo = 'bar';`,
9999
parserOptions: { sourceType: 'module' },
100-
options: [{ 'newlines': 2 }],
100+
options: [{ 'count': 2 }],
101101
},
102102
{
103103
code: `var foo = require('foo-module');\n\n\n\n\nvar foo = 'bar';`,
104104
parserOptions: { sourceType: 'module' },
105-
options: [{ 'newlines': 4 }],
105+
options: [{ 'count': 4 }],
106106
},
107107
{
108108
code: `require('foo-module');\n\nvar foo = 'bar';`,
@@ -175,7 +175,7 @@ ruleTester.run('newline-after-import', require('rules/newline-after-import'), {
175175
},
176176
{
177177
code: `import foo from 'foo';\n\nexport default function() {};`,
178-
options: [{ 'newlines': 2 }],
178+
options: [{ 'count': 2 }],
179179
errors: [ {
180180
line: 1,
181181
column: 1,
@@ -185,7 +185,7 @@ ruleTester.run('newline-after-import', require('rules/newline-after-import'), {
185185
},
186186
{
187187
code: `import foo from 'foo';\nexport default function() {};`,
188-
options: [{ 'newlines': 1 }],
188+
options: [{ 'count': 1 }],
189189
errors: [ {
190190
line: 1,
191191
column: 1,

0 commit comments

Comments
 (0)