Skip to content

Commit

Permalink
[Fix] #2882 exactCount with considerComments false positive, when the…
Browse files Browse the repository at this point in the history
…re is a leading comment
  • Loading branch information
kinland committed Sep 26, 2023
1 parent ef3d0e7 commit fbbb18a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/rules/newline-after-import.js
Expand Up @@ -169,7 +169,7 @@ module.exports = {
let nextComment;

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

// skip "export import"s
Expand Down
5 changes: 5 additions & 0 deletions tests/src/rules/newline-after-import.js
Expand Up @@ -152,6 +152,11 @@ ruleTester.run('newline-after-import', require('rules/newline-after-import'), {
parserOptions: { ecmaVersion: 2015, sourceType: 'module' },
options: [{ count: 1, exactCount: true, considerComments: true }],
},
{
code: `/**\n * A leading comment\n */\nimport foo from 'foo';\n\n// Some random comment\nexport {foo};`,
parserOptions: { ecmaVersion: 2015, sourceType: 'module' },
options: [{ count: 2, exactCount: true }],
},
{
code: `import foo from 'foo';\n\n\nvar bar = 'bar';`,
parserOptions: { ecmaVersion: 2015, sourceType: 'module' },
Expand Down

0 comments on commit fbbb18a

Please sign in to comment.