Skip to content

Commit

Permalink
Fix broken tests, add docs
Browse files Browse the repository at this point in the history
  • Loading branch information
ntdb committed Feb 12, 2017
1 parent 3e5acab commit ba3a5c0
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 5 deletions.
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 line after the last top-level import statement or require call.

## Rule Details

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

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 `newlines` set to `2` this will be considered valid:

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


const FOO = 'BAR'
```

With `newlines` 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": [{ "newlines": 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.
6 changes: 3 additions & 3 deletions tests/src/rules/newline-after-import.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ ruleTester.run('newline-after-import', require('rules/newline-after-import'), {
{
code: `import foo from 'foo';\n\n\nvar foo = 'bar';`,
parserOptions: { sourceType: 'module' },
options: { newlines: 2 },
options: [{ 'newlines': 2 }],
},
{
code: `var foo = require('foo-module');\n\nvar foo = 'bar';`,
Expand All @@ -92,7 +92,7 @@ ruleTester.run('newline-after-import', require('rules/newline-after-import'), {
{
code: `var foo = require('foo-module');\n\n\nvar foo = 'bar';`,
parserOptions: { sourceType: 'module' },
options: { newlines: 2 },
options: [{ 'newlines': 2 }],
},
{
code: `require('foo-module');\n\nvar foo = 'bar';`,
Expand Down Expand Up @@ -165,7 +165,7 @@ ruleTester.run('newline-after-import', require('rules/newline-after-import'), {
},
{
code: `import foo from 'foo';\n\nexport default function() {};`,
options: { newlines: 2 },
options: [{ 'newlines': 2 }],
errors: [ {
line: 1,
column: 1,
Expand Down

0 comments on commit ba3a5c0

Please sign in to comment.