Skip to content
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

newline-after-import deosn't take care of comments #2151

Closed
manuth opened this issue Jul 11, 2021 · 6 comments · Fixed by #2399
Closed

newline-after-import deosn't take care of comments #2151

manuth opened this issue Jul 11, 2021 · 6 comments · Fixed by #2399

Comments

@manuth
Copy link
Contributor

manuth commented Jul 11, 2021

The newline-after-import rule doesn't hit if the import-statements are immediately followed by comments:

This piece of code is expected to produce an error, but it doesn't:

import { join } from "path";
/**
 *
 */
console.log();
@ljharb
Copy link
Member

ljharb commented Jul 13, 2021

From where do you form this expectation? The docs don't have any examples with comments, nor do the tests.

The goal of the rule is to ensure that there's some spacing between imports and non-imports - arguably a comment suffices.

@alvis
Copy link

alvis commented Aug 1, 2021

I come to this issue for the exact same problem. In the OP's case, I'd expect

import { join } from "path";

/**
 *
 */
console.log();

The examples and tests may not include comment into consideration but I find it more intuitive and more clear if there's an empty line after all the import statements. After all, I believe it's the intention of the rule. For example, the following annoying example doesn't make sense to me but it's a pass today:

import something from 'somewhere';
// it's a very looooooooooooooooooooooooooooooooooooog comment
console.log('is it a good quality code?')

@ljharb
Copy link
Member

ljharb commented Aug 1, 2021

A PR to add an option to make comments not be counted as an empty line would be appreciated.

@SrBrahma

This comment has been minimized.

@pri1311
Copy link
Contributor

pri1311 commented Mar 3, 2022

Hey! I would like to work on this.

@ljharb
Copy link
Member

ljharb commented Mar 3, 2022

Go for it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

5 participants