Skip to content

Commit ba3a5c0

Browse files
committed
Fix broken tests, add docs
1 parent 3e5acab commit ba3a5c0

File tree

2 files changed

+41
-5
lines changed

2 files changed

+41
-5
lines changed

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 line after the last top-level import statement or require call.
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`.
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 `newlines` 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 `newlines` 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": [{ "newlines": 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.

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ 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: [{ 'newlines': 2 }],
8787
},
8888
{
8989
code: `var foo = require('foo-module');\n\nvar foo = 'bar';`,
@@ -92,7 +92,7 @@ ruleTester.run('newline-after-import', require('rules/newline-after-import'), {
9292
{
9393
code: `var foo = require('foo-module');\n\n\nvar foo = 'bar';`,
9494
parserOptions: { sourceType: 'module' },
95-
options: { newlines: 2 },
95+
options: [{ 'newlines': 2 }],
9696
},
9797
{
9898
code: `require('foo-module');\n\nvar foo = 'bar';`,
@@ -165,7 +165,7 @@ ruleTester.run('newline-after-import', require('rules/newline-after-import'), {
165165
},
166166
{
167167
code: `import foo from 'foo';\n\nexport default function() {};`,
168-
options: { newlines: 2 },
168+
options: [{ 'newlines': 2 }],
169169
errors: [ {
170170
line: 1,
171171
column: 1,

0 commit comments

Comments
 (0)