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

Duplicate imports do not have a consistent ordering #620

Open
jakebailey opened this issue Apr 3, 2024 · 1 comment
Open

Duplicate imports do not have a consistent ordering #620

jakebailey opened this issue Apr 3, 2024 · 1 comment

Comments

@jakebailey
Copy link
Contributor

Describe the bug

I'm looking into removing the ESLint plugin we use on TS to sort/group imports, as using dprint to do this would be a lot faster and less noisy. But, for "reasons" we have files that need to import from the same module specifier more than once. While messing with imports to try and make sure that sorting was working, I noticed that reordering those duplicates didn't net a single output.

I'm not 100% sure how to sort between these, but eslint-plugin-simple-import-order seems to do it. At least in the examples below, I think the ordering is at least sort of clear; stick the namespace import before the declaration with named imports.

dprint-plugin-typescript version: 0.90.0

Input Code

import * as ts from "../../_namespaces/ts";
import { ScriptTarget } from "../../_namespaces/ts";
import * as evaluator from "../../_namespaces/evaluator";

import { ScriptTarget } from "../../_namespaces/ts";
import * as ts from "../../_namespaces/ts";
import * as evaluator from "../../_namespaces/evaluator";

Expected Output

import * as evaluator from "../../_namespaces/evaluator";
import * as ts from "../../_namespaces/ts";
import { ScriptTarget } from "../../_namespaces/ts";


import * as evaluator from "../../_namespaces/evaluator";
import * as ts from "../../_namespaces/ts";
import { ScriptTarget } from "../../_namespaces/ts";

Actual Output

import * as evaluator from "../../_namespaces/evaluator";
import * as ts from "../../_namespaces/ts";
import { ScriptTarget } from "../../_namespaces/ts";


import * as evaluator from "../../_namespaces/evaluator";
import { ScriptTarget } from "../../_namespaces/ts";
import * as ts from "../../_namespaces/ts";
@jakebailey
Copy link
Contributor Author

I think it may be sufficient to just put the namespace import before a named/default import, actually. If you're importing with names but twice, that's weird and probably pointless as those two could be merged.

e.g., the canonical sort order would be:

import * as ts from "typescript";
import ts2 from "typescript";
import { SyntaxKind } from "typescript"

or something...

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

No branches or pull requests

1 participant