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 26, 2016
1 parent bd35156 commit d4268e7
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
with some `parserOptions` in the mix. ([#402])
- `react` shared config: added `jsx: true` to `parserOptions.ecmaFeatures`.
- Added [`no-webpack-loader-syntax`] rule: forbid custom Webpack loader syntax in imports. ([#586], thanks [@fson]!)
- Add option `newlines-between: "ignore"` to [`order`] ([#519])

### Breaking
- [`import/extensions` setting] defaults to `['.js']`. ([#306])
Expand Down Expand Up @@ -392,6 +393,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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 d4268e7

Please sign in to comment.