Skip to content

Commit

Permalink
Make ignore the default option for order newlines-between option
Browse files Browse the repository at this point in the history
  • Loading branch information
jfmengels authored and benmosher committed Sep 26, 2016
1 parent b8b2885 commit ee7c3cc
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
- [`import/extensions` setting] defaults to `['.js']`. ([#306])
- [`import/ignore` setting] defaults to nothing, and ambiguous modules are ignored natively. This means importing from CommonJS modules will no longer be reported by [`default`], [`named`], or [`namespace`], regardless of `import/ignore`. ([#270])
- [`newline-after-import`]: Removed need for an empty line after an inline `require` call ([#570])
- [`order`]: Default value for `newlines-between` option is now `ignore` ([#519])

### Changed
- `imports-first` is renamed to [`first`]. `imports-first` alias will continue to
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|ignore|never]`:
### `newlines-between: [ignore|always|never]`:


Enforces or forbids new lines between import groups:

- 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 `ignore`, no errors related to new lines between import groups will be reported (default).
- 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 `never`, no new lines are allowed in the entire import section.

With the default group setting, the following will be invalid:
Expand Down
7 changes: 4 additions & 3 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', 'ignore', 'never' ],
enum: [ 'ignore', 'always', 'never' ],
},
},
additionalProperties: false,
Expand All @@ -167,6 +167,7 @@ module.exports = {

create: function importOrderRule (context) {
const options = context.options[0] || {}
const newlinesBetweenImports = options['newlines-between'] || 'ignore'
let ranks

try {
Expand Down Expand Up @@ -206,8 +207,8 @@ module.exports = {
'Program:exit': function reportAndReset() {
makeOutOfOrderReport(context, imported)

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

imported = []
Expand Down
26 changes: 26 additions & 0 deletions tests/src/rules/order.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,32 @@ ruleTester.run('order', rule, {
},
],
}),
// 'ignore' should be the default value for `newlines-between`
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'],
],
},
],
}),
// Option newlines-between: 'always' with multiline imports #1
test({
code: `
Expand Down

0 comments on commit ee7c3cc

Please sign in to comment.