Skip to content

v1.11.1 #445

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

Merged
merged 3 commits into from
Jul 20, 2016
Merged
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
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel

## [Unreleased]

## [1.11.1] - 2016-07-20
### Fixed
- [`newline-after-import`] exception for `switch` branches with `require`s iff parsed as `sourceType:'module'`.
(still [#441], thanks again [@ljharb])

## [1.11.0] - 2016-07-17
### Added
- Added an `peerDependencies` option to [`no-extraneous-dependencies`] to allow/forbid peer dependencies ([#423], [#428], thanks [@jfmengels]!).
Expand Down Expand Up @@ -323,7 +328,8 @@ for info on changes for earlier releases.
[#119]: https://github.com/benmosher/eslint-plugin-import/issues/119
[#89]: https://github.com/benmosher/eslint-plugin-import/issues/89

[Unreleased]: https://github.com/benmosher/eslint-plugin-import/compare/v1.11.0...HEAD
[Unreleased]: https://github.com/benmosher/eslint-plugin-import/compare/v1.11.1...HEAD
[1.11.1]: https://github.com/benmosher/eslint-plugin-import/compare/v1.11.0...v1.11.1
[1.11.0]: https://github.com/benmosher/eslint-plugin-import/compare/v1.10.3...v1.11.0
[1.10.3]: https://github.com/benmosher/eslint-plugin-import/compare/v1.10.2...v1.10.3
[1.10.2]: https://github.com/benmosher/eslint-plugin-import/compare/v1.10.1...v1.10.2
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eslint-plugin-import",
"version": "1.11.0",
"version": "1.11.1",
"description": "Import with sanity.",
"main": "lib/index.js",
"directories": {
Expand Down Expand Up @@ -70,6 +70,7 @@
"dependencies": {
"builtin-modules": "^1.1.1",
"contains-path": "^0.1.0",
"debug": "^2.2.0",
"doctrine": "1.2.x",
"es6-map": "^0.1.3",
"es6-set": "^0.1.4",
Expand Down
17 changes: 15 additions & 2 deletions src/rules/newline-after-import.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
import isStaticRequire from '../core/staticRequire'
import findIndex from 'lodash.findindex'

import debug from 'debug'

const log = debug('eslint-plugin-import:rules:newline-after-import')

//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------
Expand All @@ -16,7 +20,8 @@ function containsNodeOrEqual(outerNode, innerNode) {

function getScopeBody(scope) {
if (scope.block.type === 'SwitchStatement') {
return []
log('SwitchStatement scopes not supported')
return null
}

const { body } = scope.block
Expand Down Expand Up @@ -85,14 +90,22 @@ module.exports = function (context) {
}
},
'Program:exit': function () {
log('exit processing for', context.getFilename())
scopes.forEach(function ({ scope, requireCalls }) {
const scopeBody = getScopeBody(scope)

// skip non-array scopes (i.e. arrow function expressions)
if (!(scopeBody instanceof Array)) return
if (!scopeBody || !(scopeBody instanceof Array)) {
log('invalid scope:', scopeBody)
return
}

log('got scope:', scopeBody)

requireCalls.forEach(function (node, index) {
const nodePosition = findNodeIndexInScopeBody(scopeBody, node)
log('node position in scope:', nodePosition)

const statementWithRequireCall = scopeBody[nodePosition]
const nextStatement = scopeBody[nodePosition + 1]
const nextRequireCall = requireCalls[index + 1]
Expand Down
35 changes: 34 additions & 1 deletion tests/src/rules/newline-after-import.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,39 @@ ruleTester.run('newline-after-import', require('rules/newline-after-import'), {
return renderData.mainModalContent.clone()
}
}`,
{ code: `//issue 441
function bar() {
switch (foo) {
case '1':
return require('../path/to/file1.jst.hbs')(renderData, options);
case '2':
return require('../path/to/file2.jst.hbs')(renderData, options);
case '3':
return require('../path/to/file3.jst.hbs')(renderData, options);
case '4':
return require('../path/to/file4.jst.hbs')(renderData, options);
case '5':
return require('../path/to/file5.jst.hbs')(renderData, options);
case '6':
return require('../path/to/file6.jst.hbs')(renderData, options);
case '7':
return require('../path/to/file7.jst.hbs')(renderData, options);
case '8':
return require('../path/to/file8.jst.hbs')(renderData, options);
case '9':
return require('../path/to/file9.jst.hbs')(renderData, options);
case '10':
return require('../path/to/file10.jst.hbs')(renderData, options);
case '11':
return require('../path/to/file11.jst.hbs')(renderData, options);
case '12':
return something();
default:
return somethingElse();
}
}`,
parserOptions: { sourceType: 'module' },
},
{
code: "import path from 'path';\nimport foo from 'foo';\n",
parserOptions: { sourceType: 'module' },
Expand Down Expand Up @@ -196,5 +229,5 @@ ruleTester.run('newline-after-import', require('rules/newline-after-import'), {
} ],
parserOptions: { sourceType: 'module' },
},
]
],
})