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

[order] Separate handling of regular imports and type imports #2016

Closed
vmk1vmk opened this issue Mar 26, 2021 · 4 comments
Closed

[order] Separate handling of regular imports and type imports #2016

vmk1vmk opened this issue Mar 26, 2021 · 4 comments

Comments

@vmk1vmk
Copy link

vmk1vmk commented Mar 26, 2021

I would like to split the imports into regular imports and type imports and apply the specified ordering on each of them individually.

Example:

/**
 *  Regular imports
 */
import fs from 'fs';
import _ from 'lodash';
// etc.

/**
 *  Type imports
 */
import type { File } from 'fs';
import type { LoDashStatic } from 'lodash';
// etc.

How could I achieve that behaviour with the order rule?

Thank you for helping in advance.

@ljharb
Copy link
Member

ljharb commented Mar 26, 2021

I think we'd need to add a "group" to the rule for type imports for this to be possible.

However, then how would people be able to not separate them? in other words, if they wanted to enforce that type imports were right before, or after, the value imports from the same module?

@vmk1vmk
Copy link
Author

vmk1vmk commented Mar 27, 2021

I would consider group and importTypeGroups to be different dimensions.

Maybe there should be two stages in the rule:

  1. Group and sort by import type
  2. Group and sort inside import type with the specified group ordering

The proposed Option could be called importTypeGroup and look like the following code.

type ImportTypeGroup = Default | TypeFirst | RegularFirst;

type Default = [
  ['regular', 'type'] // (default) treat them as the same
];

type TypeFirst = [
  'type',
  'regular'
];

type RegularFirst = [
 'regular',
  'type'
];

The Option behaves almost identical as group.
Also the default preserves the current behaviour and would therefore not bother pure JS users.

Options that are modifying the behaviour of group could be also considered here, like newlines-between.

This is currently my best guess on how to implement an easy and clear API that doesn't have to concern non TS users.

@bobaaaaa
Copy link

There is also the issue #645 with some comments in it.

@ljharb
Copy link
Member

ljharb commented Mar 31, 2021

In that case, let’s close this as a duplicate of #645 and consolidate discussion there.

@ljharb ljharb closed this as completed Mar 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants