Skip to content

Commit c23e763

Browse files
committed
Fix #441 + added a bunch of debug logging for next time 😅
1 parent b2184f0 commit c23e763

File tree

3 files changed

+50
-3
lines changed

3 files changed

+50
-3
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
"dependencies": {
7171
"builtin-modules": "^1.1.1",
7272
"contains-path": "^0.1.0",
73+
"debug": "^2.2.0",
7374
"doctrine": "1.2.x",
7475
"es6-map": "^0.1.3",
7576
"es6-set": "^0.1.4",

src/rules/newline-after-import.js

+15-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
import isStaticRequire from '../core/staticRequire'
77
import findIndex from 'lodash.findindex'
88

9+
import debug from 'debug'
10+
11+
const log = debug('eslint-plugin-import:rules:newline-after-import')
12+
913
//------------------------------------------------------------------------------
1014
// Rule Definition
1115
//------------------------------------------------------------------------------
@@ -16,7 +20,8 @@ function containsNodeOrEqual(outerNode, innerNode) {
1620

1721
function getScopeBody(scope) {
1822
if (scope.block.type === 'SwitchStatement') {
19-
return []
23+
log('SwitchStatement scopes not supported')
24+
return null
2025
}
2126

2227
const { body } = scope.block
@@ -85,14 +90,22 @@ module.exports = function (context) {
8590
}
8691
},
8792
'Program:exit': function () {
93+
log('exit processing for', context.getFilename())
8894
scopes.forEach(function ({ scope, requireCalls }) {
8995
const scopeBody = getScopeBody(scope)
9096

9197
// skip non-array scopes (i.e. arrow function expressions)
92-
if (!(scopeBody instanceof Array)) return
98+
if (!scopeBody || !(scopeBody instanceof Array)) {
99+
log('invalid scope:', scopeBody)
100+
return
101+
}
102+
103+
log('got scope:', scopeBody)
93104

94105
requireCalls.forEach(function (node, index) {
95106
const nodePosition = findNodeIndexInScopeBody(scopeBody, node)
107+
log('node position in scope:', nodePosition)
108+
96109
const statementWithRequireCall = scopeBody[nodePosition]
97110
const nextStatement = scopeBody[nodePosition + 1]
98111
const nextRequireCall = requireCalls[index + 1]

tests/src/rules/newline-after-import.js

+34-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,39 @@ ruleTester.run('newline-after-import', require('rules/newline-after-import'), {
3232
return renderData.mainModalContent.clone()
3333
}
3434
}`,
35+
{ code: `//issue 441
36+
function bar() {
37+
switch (foo) {
38+
case '1':
39+
return require('../path/to/file1.jst.hbs')(renderData, options);
40+
case '2':
41+
return require('../path/to/file2.jst.hbs')(renderData, options);
42+
case '3':
43+
return require('../path/to/file3.jst.hbs')(renderData, options);
44+
case '4':
45+
return require('../path/to/file4.jst.hbs')(renderData, options);
46+
case '5':
47+
return require('../path/to/file5.jst.hbs')(renderData, options);
48+
case '6':
49+
return require('../path/to/file6.jst.hbs')(renderData, options);
50+
case '7':
51+
return require('../path/to/file7.jst.hbs')(renderData, options);
52+
case '8':
53+
return require('../path/to/file8.jst.hbs')(renderData, options);
54+
case '9':
55+
return require('../path/to/file9.jst.hbs')(renderData, options);
56+
case '10':
57+
return require('../path/to/file10.jst.hbs')(renderData, options);
58+
case '11':
59+
return require('../path/to/file11.jst.hbs')(renderData, options);
60+
case '12':
61+
return something();
62+
default:
63+
return somethingElse();
64+
}
65+
}`,
66+
parserOptions: { sourceType: 'module' },
67+
},
3568
{
3669
code: "import path from 'path';\nimport foo from 'foo';\n",
3770
parserOptions: { sourceType: 'module' },
@@ -196,5 +229,5 @@ ruleTester.run('newline-after-import', require('rules/newline-after-import'), {
196229
} ],
197230
parserOptions: { sourceType: 'module' },
198231
},
199-
]
232+
],
200233
})

0 commit comments

Comments
 (0)