Skip to content

Commit

Permalink
Fix #519: Add option newlines-between: "ignore" to order
Browse files Browse the repository at this point in the history
  • Loading branch information
jfmengels committed Sep 24, 2016
1 parent e3c41ca commit 2acc1c6
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -10,6 +10,7 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
- `recommended` shared config. Roughly `errors` and `warnings` mixed together,
with some `parserOptions` in the mix. ([#402])
- `react` shared config: added `jsx: true` to `parserOptions.ecmaFeatures`.
- Add option `newlines-between: "ignore"` to [`order`] ([#519])

### Breaking
- [`import/extensions` setting] defaults to `['.js']`. ([#306])
Expand Down Expand Up @@ -382,6 +383,7 @@ for info on changes for earlier releases.
[#566]: https://github.com/benmosher/eslint-plugin-import/issues/566
[#545]: https://github.com/benmosher/eslint-plugin-import/issues/545
[#530]: https://github.com/benmosher/eslint-plugin-import/issues/530
[#519]: https://github.com/benmosher/eslint-plugin-import/issues/519
[#507]: https://github.com/benmosher/eslint-plugin-import/issues/507
[#478]: https://github.com/benmosher/eslint-plugin-import/issues/478
[#456]: https://github.com/benmosher/eslint-plugin-import/issues/456
Expand Down
6 changes: 3 additions & 3 deletions docs/rules/order.md
Expand Up @@ -92,13 +92,13 @@ You can set the options like this:
"import/order": ["error", {"groups": ["index", "sibling", "parent", "internal", "external", "builtin"]}]
```

### `newlines-between: [always|never]`:
### `newlines-between: [always|ignore|never]`:


Enforces or forbids new lines between import groups:

- If omitted, assertion messages will be neither enforced nor forbidden.
- If set to `always`, at least one new line between each group will be enforced, and new lines inside a group will be forbidden. To prevent multiple lines between imports, core `no-multiple-empty-lines` rule can be used.
- If set to `always`, at least one new line between each group will be enforced, and new lines inside a group will be forbidden. To prevent multiple lines between imports, core `no-multiple-empty-lines` rule can be used (default).
- If set to `ignore`, no errors related to new lines between import groups will be reported.
- If set to `never`, no new lines are allowed in the entire import section.

With the default group setting, the following will be invalid:
Expand Down
4 changes: 2 additions & 2 deletions src/rules/order.js
Expand Up @@ -157,7 +157,7 @@ module.exports = {
type: 'array',
},
'newlines-between': {
enum: [ 'always', 'never' ],
enum: [ 'always', 'ignore', 'never' ],
},
},
additionalProperties: false,
Expand Down Expand Up @@ -206,7 +206,7 @@ module.exports = {
'Program:exit': function reportAndReset() {
makeOutOfOrderReport(context, imported)

if ('newlines-between' in options) {
if ('newlines-between' in options && options['newlines-between'] !== 'ignore') {
makeNewlinesBetweenReport(context, imported, options['newlines-between'])
}

Expand Down
28 changes: 27 additions & 1 deletion tests/src/rules/order.js
Expand Up @@ -209,6 +209,32 @@ ruleTester.run('order', rule, {
},
],
}),
// Option: newlines-between: 'ignore'
test({
code: `
var fs = require('fs');
var index = require('./');
var path = require('path');
var sibling = require('./foo');
var relParent1 = require('../foo');
var relParent3 = require('../');
var async = require('async');
`,
options: [
{
groups: [
['builtin', 'index'],
['sibling'],
['parent', 'external'],
],
'newlines-between': 'ignore',
},
],
}),
// Option newlines-between: 'always' with multiline imports #1
test({
code: `
Expand Down Expand Up @@ -299,7 +325,7 @@ ruleTester.run('order', rule, {
port: 4444,
runner: {
server_path: require('runner-binary').path,
cli_args: {
'webdriver.chrome.driver': require('browser-binary').path
}
Expand Down

0 comments on commit 2acc1c6

Please sign in to comment.