Skip to content

Commit

Permalink
Change newlines option to count for newline-after-import rule
Browse files Browse the repository at this point in the history
  • Loading branch information
ntdb committed Feb 16, 2017
1 parent 1d757dc commit c0f733b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
### 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 `newlines` option to the `newline-after-import` rule to allow configuration of number of newlines expected ([#742])
- Add `count` option to the `newline-after-import` rule to allow configuration of number of newlines expected ([#742])

### Changed
- [`no-extraneous-dependencies`]: use `read-pkg-up` to simplify finding + loading `package.json` ([#680], thanks [@wtgtybhertgeghgtwtg])
Expand Down
8 changes: 4 additions & 4 deletions docs/rules/newline-after-import.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Enforces having one or more empty line after the last top-level import statement

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

Expand Down Expand Up @@ -48,7 +48,7 @@ const BAZ = 1
const BAR = require('./bar')
```

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

```js
import defaultExport from './foo'
Expand All @@ -57,7 +57,7 @@ import defaultExport from './foo'
const FOO = 'BAR'
```

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

```js
import defaultExport from './foo'
Expand All @@ -76,7 +76,7 @@ const FOO = 'BAR'
{
...
"rules": {
"import/newline-after-import": [{ "newlines": 2 }]
"import/newline-after-import": [{ "count": 2 }]
}
}
```
Expand Down
6 changes: 3 additions & 3 deletions src/rules/newline-after-import.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ module.exports = {
{
'type': 'object',
'properties': {
'newlines': {
'count': {
'type': 'integer',
'minimum': 1,
},
Expand All @@ -67,8 +67,8 @@ module.exports = {
nextNode = nextNode.decorators[0]
}

const options = context.options[0] || { newlines: 1 }
if (getLineDifference(node, nextNode) < options.newlines + 1) {
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
12 changes: 6 additions & 6 deletions tests/src/rules/newline-after-import.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,12 @@ 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: [{ 'count': 2 }],
},
{
code: `import foo from 'foo';\n\n\n\n\nvar foo = 'bar';`,
parserOptions: { sourceType: 'module' },
options: [{ 'newlines': 4 }],
options: [{ 'count': 4 }],
},
{
code: `var foo = require('foo-module');\n\nvar foo = 'bar';`,
Expand All @@ -97,12 +97,12 @@ 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: [{ 'count': 2 }],
},
{
code: `var foo = require('foo-module');\n\n\n\n\nvar foo = 'bar';`,
parserOptions: { sourceType: 'module' },
options: [{ 'newlines': 4 }],
options: [{ 'count': 4 }],
},
{
code: `require('foo-module');\n\nvar foo = 'bar';`,
Expand Down Expand Up @@ -175,7 +175,7 @@ ruleTester.run('newline-after-import', require('rules/newline-after-import'), {
},
{
code: `import foo from 'foo';\n\nexport default function() {};`,
options: [{ 'newlines': 2 }],
options: [{ 'count': 2 }],
errors: [ {
line: 1,
column: 1,
Expand All @@ -185,7 +185,7 @@ ruleTester.run('newline-after-import', require('rules/newline-after-import'), {
},
{
code: `import foo from 'foo';\nexport default function() {};`,
options: [{ 'newlines': 1 }],
options: [{ 'count': 1 }],
errors: [ {
line: 1,
column: 1,
Expand Down

0 comments on commit c0f733b

Please sign in to comment.