Eslint-plugin-import: Proposal: `new-line-between-groups` option for `order`

Created on 27 Apr 2016  路  10Comments  路  Source: benmosher/eslint-plugin-import

This follow up on discussions we had here and #246.

Options for that would be either always or never.

Then for always and groups like: groups: [ [ "builtin", "external" ], [ "index", "sibling", "parent" ] ] }

So the following would be considered as a problem:

import url from 'url';
import express from 'express'; // <-- missing new line after this statement
import foo from './foo';

This would not be considered as a problem:

import url from 'url';
import express from 'express';

import foo from './foo';

new-line-between-groups would allow you to configure new lines inside groups like you want - should be pretty flexible.

I don't think there should be another rule for achieving that, option for order IMHO would be fine.

NOTE: Option name could of course be changed to something different, separate-groups(-with-newline) maybe.

Most helpful comment

@jfmengels Depends how to look at that - you can interpret it like: if you will have more than two groups then you will have newlineS between groups - even if it will be one line between group, total amount of empty lines in imports section will be bigger than 1, thus newlinesshould be fine.

I'm ok with plural form :)

All 10 comments

I will mostly defer to @jfmengels and company on this one, but a few gut reactions:

I think if you don't set the option at all, it shouldn't enforce any spacing.

Also, if you _do_ set it, to either setting, would it enforce that there are no newlines _within_ a group?

i.e.

import url from 'url';
// assuming this were a blank line, would it be reported? "extra newline inside group" or some such
import express from 'express';

Also I think it would be optimal if the option were one or two words, something like newlines. Clarity over brevity, but brevity would be ideal.

I think if you don't set the option at all, it shouldn't enforce any spacing.

:+1:

if you do set it, to either setting, would it enforce that there are no newlines within a group?

I think so yes.

Maybe we could specify the number of blank lines between groups?
If I want no blank lines, I can set 0, if I want an empty line, I can set 1, and if I like bigger spacing, I can set 2. If I don't specify it or set it to false (?), nothing will be enforced.

if the option were one or two words, something like newlines

I think group-groups contains the wanted functionality, but it's a bit... repetitive ^^'

I think if you don't set the option at all, it shouldn't enforce any spacing.

Yep, then it's do whatever you want mode :)

if you do set it, to either setting, would it enforce that there are no newlines within a group?

Yes, this is what I had in mind.

Maybe we could specify the number of blank lines between groups?

Personally I don't think it's necessary, especially at the beginning. We might add it later :)

Maybe we could specify the number of blank lines between groups?

Personally I don't think it's necessary, especially at the beginning. We might add it later :)

One of the things it brings is make the option setting clearer IMO (well, depending on the name of the option...).

I like starting with true for 1 line, false for 0, and then later if it's int-valued that could be the number of lines, if someone wants that.

New name idea: newlines-between.

I think I like newlines-between. Just one thing, If you only allow at most 1 line and it's a boolean type field, then it should be newline-between, which doesn't upgrade well to an eventual int-type later. Man, naming is hard :p

@jfmengels Depends how to look at that - you can interpret it like: if you will have more than two groups then you will have newlineS between groups - even if it will be one line between group, total amount of empty lines in imports section will be bigger than 1, thus newlinesshould be fine.

I'm ok with plural form :)

So, can I assume it's something which would be ok with you guys and I can try to prepare a PR?

I'd wait for an explicit 馃憤 from @jfmengels but I'm good with where we ended up, discussion-wise.

Same here :+1:

Was this page helpful?
0 / 5 - 0 ratings

Related issues

thewilkybarkid picture thewilkybarkid  路  36Comments

jtsom picture jtsom  路  21Comments

Robinfr picture Robinfr  路  27Comments

msuntharesan picture msuntharesan  路  29Comments

steve-taylor picture steve-taylor  路  24Comments