Skip to content

Commit fbbb18a

Browse files
committed
[Fix] import-js#2882 exactCount with considerComments false positive, when there is a leading comment
1 parent ef3d0e7 commit fbbb18a

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/rules/newline-after-import.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ module.exports = {
169169
let nextComment;
170170

171171
if (typeof parent.comments !== 'undefined' && options.considerComments) {
172-
nextComment = parent.comments.find((o) => o.loc.start.line <= endLine + options.count + 1);
172+
nextComment = parent.comments.find((o) => o.loc.start.line >= endLine && o.loc.start.line <= endLine + options.count + 1);
173173
}
174174

175175
// skip "export import"s

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

+5
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,11 @@ ruleTester.run('newline-after-import', require('rules/newline-after-import'), {
152152
parserOptions: { ecmaVersion: 2015, sourceType: 'module' },
153153
options: [{ count: 1, exactCount: true, considerComments: true }],
154154
},
155+
{
156+
code: `/**\n * A leading comment\n */\nimport foo from 'foo';\n\n// Some random comment\nexport {foo};`,
157+
parserOptions: { ecmaVersion: 2015, sourceType: 'module' },
158+
options: [{ count: 2, exactCount: true }],
159+
},
155160
{
156161
code: `import foo from 'foo';\n\n\nvar bar = 'bar';`,
157162
parserOptions: { ecmaVersion: 2015, sourceType: 'module' },

0 commit comments

Comments
 (0)