Skip to content

Commit

Permalink
test + fix at least one case that causes #441
Browse files Browse the repository at this point in the history
  • Loading branch information
benmosher committed Jul 17, 2016
1 parent 2b4397b commit 3684a11
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/rules/newline-after-import.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,12 @@ module.exports = function (context) {
},
'Program:exit': function () {
scopes.forEach(function ({ scope, requireCalls }) {
const scopeBody = getScopeBody(scope)

// skip non-array scopes (i.e. arrow function expressions)
if (!(scopeBody instanceof Array)) return

requireCalls.forEach(function (node, index) {
const scopeBody = getScopeBody(scope)
const nodePosition = findNodeIndexInScopeBody(scopeBody, node)
const statementWithRequireCall = scopeBody[nodePosition]
const nextStatement = scopeBody[nodePosition + 1]
Expand Down
14 changes: 14 additions & 0 deletions tests/src/rules/newline-after-import.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@ const ruleTester = new RuleTester()
ruleTester.run('newline-after-import', require('rules/newline-after-import'), {
valid: [
"var path = require('path');\nvar foo = require('foo');\n",
"require('foo');",
"switch ('foo') { case 'bar': require('baz'); }",
{
code: `
const x = () => require('baz')
, y = () => require('bar')`,
parserOptions: { ecmaVersion: 6 } ,
},
{
code: `const x = () => require('baz') && require('bar')`,
parserOptions: { ecmaVersion: 6 } ,
},
"function x(){ require('baz'); }",

"a(require('b'), require('c'), require('d'));",
`function foo() {
switch (renderData.modalViewKey) {
Expand Down

0 comments on commit 3684a11

Please sign in to comment.