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

Rule proposal: no-empty-line-separating-import #172

Open
gajus opened this issue Feb 10, 2016 · 14 comments
Open

Rule proposal: no-empty-line-separating-import #172

gajus opened this issue Feb 10, 2016 · 14 comments

Comments

@gajus
Copy link
Contributor

gajus commented Feb 10, 2016

This is stylistic rule. I often see import statements separated one from another using arbitrary rules, e.g.

import yargs from 'yargs';
import getStdin from 'get-stdin';


import {
    lintFiles,
    lintText
} from './../../utilities';

import {
    failHandler,
    getTargetPaths,
    outputReport
} from './../../utilities/bin';

This rule would enforce no spacing between import statements, i.e.

import yargs from 'yargs';
import getStdin from 'get-stdin';
import {
    lintFiles,
    lintText
} from './../../utilities';
import {
    failHandler,
    getTargetPaths,
    outputReport
} from './../../utilities/bin';
@benmosher
Copy link
Member

Just a heads up: if you want to implement + PR this and the others you've proposed, I'm more than willing to accept them.

I just don't have a lot of time ATM and the style-guide rules are lower priority than getting ready for ESLint 2, infrastructure, etc. so I don't expect to work on them any time soon.

@alexander-akait
Copy link

@benmosher maybe rename max-empty-line-separating-import with option number?

@jfmengels
Copy link
Collaborator

jfmengels commented Sep 29, 2016

You can configure the order rule to do the wanted behavior. It's a but of a hack if you only want to enforce this trait, but that would be the way to go IMO. What do you think @benmosher?

@benmosher
Copy link
Member

I'm cool either way. Seems reasonable to assume that intent to use a rule like this implies desire to use order.

@ljharb
Copy link
Member

ljharb commented Nov 14, 2016

That assumption is incorrect - I do not want ordering but do want imports grouped with no newlines.

@caub
Copy link
Contributor

caub commented Feb 3, 2018

I agree with ↑, https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/order.md#newlines-between-ignorealwaysalways-and-inside-groupsnever lets ignore the newlines-between option, but not the group one

oh.. right, after reading more:

'import/order': ['error', {
      'groups': [['index', 'sibling', 'parent', 'internal', 'external', 'builtin']],
      'newlines-between': 'never'
    }],

works to allow mangling of all groups

@Devansu-Yadav
Copy link

@benmosher @ljharb Is this issue still open to take up? I don't see any PR created for this rule, so I was hoping to take a shot at implementing this if it's something useful to have 😅

For starters, I'm thinking of going through the code for newlines-between option (especially the never value that can be passed) of the order rule to understand how to avoid empty lines between imports. I'm also looking to play around with the AST Explorer to get an idea about the implementation.

Though, I'll need some input from your end to get some clarity on the implementation as well as what options we could configure for this rule 😅

@ljharb
Copy link
Member

ljharb commented Dec 22, 2022

@Devansu-Yadav yup! no PR yet. altho let's make sure we're on the same page about implementation first.

@Devansu-Yadav
Copy link

@Devansu-Yadav yup! no PR yet. altho let's make sure we're on the same page about implementation first.

Sure, absolutely!

@Devansu-Yadav
Copy link

@Devansu-Yadav yup! no PR yet. altho let's make sure we're on the same page about implementation first.

@ljharb Any updates on how I should be proceeding with the implementation?

@ljharb
Copy link
Member

ljharb commented Jan 11, 2023

What schema did you have in mind?

@Devansu-Yadav
Copy link

What schema did you have in mind?

As this rule mostly deals with having no newlines between import statements, having a count option to count the no of newlines wouldn't make sense here. Do we want an option like groups defined in the order rule to enforce no newlines inside specified groups of import statements but ignore newlines between different import groups? This would work exactly like always value for the newlines-between option defined in the order rule. The only difference in having the groups option here for this rule would be that it would have a default value of [], meaning that we wouldn't have any import groups specified by default.

I'm not sure if it would be useful to only enforce no newlines inside import groups using the groups option 😅. What do you think?

I'm also thinking about whether we should have an option like considerComments to group together comments along with imports without any newline or it would deviate the purpose of this rule.
I'm open to any suggestions for the schema we should have for this rule.

@Devansu-Yadav
Copy link

What schema did you have in mind?

As this rule mostly deals with having no newlines between import statements, having a count option to count the no of newlines wouldn't make sense here. Do we want an option like groups defined in the order rule to enforce no newlines inside specified groups of import statements but ignore newlines between different import groups? This would work exactly like always value for the newlines-between option defined in the order rule. The only difference in having the groups option here for this rule would be that it would have a default value of [], meaning that we wouldn't have any import groups specified by default.

I'm not sure if it would be useful to only enforce no newlines inside import groups using the groups option 😅. What do you think?

I'm also thinking about whether we should have an option like considerComments to group together comments along with imports without any newline or it would deviate the purpose of this rule. I'm open to any suggestions for the schema we should have for this rule.

Any thoughts on this? @ljharb

@ghmcadams
Copy link

I thought I would weigh in on this one - I would love if this were part of the order rule.

I see a couple of potential options:

  1. The newlines-between option could be modified to allow a numeric value
  2. Another property could be added (spacing-between: number?), which would only be used when newlines-between has a value of always' or 'always-and-inside-groups

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

No branches or pull requests

8 participants