willhoney7 / eslint-plugin-import-helpers

ESLint plugin to help enforce a configurable order for import statements
288 stars 17 forks source link

Line count dependent `newlinesBetween` #16

Closed buschtoens closed 5 years ago

buschtoens commented 5 years ago

Thanks for this great plugin! 🍻

I am using newlinesBetween: "always" in these two configurations:

This type of grouping, looks like this:

import { join, dirname } from 'path';

import BroccoliDebug from 'broccoli-debug';
import BroccoliMergeTrees from 'broccoli-merge-trees';
import BroccoliPlugin, { BroccoliNode } from 'broccoli-plugin';
import { WatchedDir } from 'broccoli-source';
import EmberApp from 'ember-cli/lib/broccoli/ember-app';
import Addon from 'ember-cli/lib/models/addon';
import Project from 'ember-cli/lib/models/project';
import fromPairs from 'lodash.frompairs';

import commands from './commands';
import {
  computeOptions,
  MakeupOptions,
  FinalMakeupOptions
} from './lib/options';
import { addon } from './lib/utils/ember-cli-entities';
import { CSSConfigCreator } from './plugins/broccoli/config-creator';
import EmberCSSModulesPlugin from './plugins/ember-css-modules';
import { Usage } from './plugins/postcss';
import { register } from './plugins/preprocessor-registry';
import { ThemeProviderRegistry, ThemeProvider } from './themes';

It works great for files, that have a lot of imports, like above, but it's total overkill for files with only a few imports of different groups, e.g.:

import Application from '@ember/application';

import loadInitializers from 'ember-load-initializers';

import config from './config/environment';

This would look cleaner IMO:

import Application from '@ember/application';
import loadInitializers from 'ember-load-initializers';
import config from './config/environment';

What do you think about an additional config that allows to specify the minimum number of imports per group for newlines to be inserted.

willhoney7 commented 5 years ago

Hi! I'm glad you've found the plugin useful. Thanks for your feedback!

While it does look cleaner to have the three imports grouped together, I think consistency is more valuable. The imports are ordered the same way in every file. There's value in defining the groups and separating them, even if the groups are small. In your first example, I can tell very quickly that the config file is a relative import. In the second, I have to look more carefully to realize it is a relative import.

I'm going to close this issue for now–we can revisit in the future if there's widespread interest.