Skip to content

Fix orders newline-between for multiline imports #329

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
### Fixed
- Ignore namespace / ES7 re-exports in [`no-mutable-exports`]. ([#317], fixed by [#322]. thanks [@borisyankov] + [@jfmengels])
- Make [`no-extraneous-dependencies`] handle scoped packages ([#316], thanks [@jfmengels])
- Make [`order`]'s `newline-between` option handle multiline import statements ([#313], thanks [@singles])

## [1.7.0] - 2016-05-06
### Added
Expand Down
2 changes: 1 addition & 1 deletion src/rules/order.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ function convertGroupsToRanks(groups) {

function makeNewlinesBetweenReport (context, imported, newlinesBetweenImports) {
const getLineDifference = (currentImport, previousImport) => {
return currentImport.node.loc.start.line - previousImport.node.loc.start.line
return currentImport.node.loc.start.line - previousImport.node.loc.end.line
}
let previousImport = imported[0]

Expand Down
38 changes: 38 additions & 0 deletions tests/src/rules/order.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,44 @@ ruleTester.run('order', rule, {
},
],
}),
// Option newlines-between: 'never' with multiline imports #1
test({
code: `
import path from 'path';

import {
I,
Want,
Couple,
Imports,
Here
} from 'bar';
import external from 'external'
`,
options: [{ 'newlines-between': 'always' }]
}),
// Option newlines-between: 'always' with multiline imports #2
test({
code: `
import path from 'path';
import net
from 'net';

import external from 'external'
`,
options: [{ 'newlines-between': 'always' }]
}),
// Option newlines-between: 'always' with multiline imports #3
test({
code: `
import foo
from '../../../../this/will/be/very/long/path/and/therefore/this/import/has/to/be/in/two/lines';

import bar
from './sibling';
`,
options: [{ 'newlines-between': 'always' }]
}),
],
invalid: [
// builtin before external module (require)
Expand Down