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

Ignore case when sorting imports #24048

Merged
merged 1 commit into from
May 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/harness/unittests/organizeImports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ namespace ts {
`import x from "./lib";`);
});

it("Sort - case-insensitive", () => {
assertSortsBefore(
`import y from "a";`,
`import x from "Z";`);
assertSortsBefore(
`import y from "A";`,
`import x from "z";`);
});

function assertSortsBefore(importString1: string, importString2: string) {
const [{moduleSpecifier: moduleSpecifier1}, {moduleSpecifier: moduleSpecifier2}] = parseImports(importString1, importString2);
assert.equal(OrganizeImports.compareModuleSpecifiers(moduleSpecifier1, moduleSpecifier2), Comparison.LessThan);
Expand All @@ -42,6 +51,13 @@ namespace ts {
assertListEqual(actualCoalescedImports, expectedCoalescedImports);
});

it("Sort specifiers - case-insensitive", () => {
const sortedImports = parseImports(`import { default as M, a as n, B, y, Z as O } from "lib";`);
const actualCoalescedImports = OrganizeImports.coalesceImports(sortedImports);
const expectedCoalescedImports = parseImports(`import { a as n, B, default as M, y, Z as O } from "lib";`);
assertListEqual(actualCoalescedImports, expectedCoalescedImports);
});

it("Combine side-effect-only imports", () => {
const sortedImports = parseImports(
`import "lib";`,
Expand Down
4 changes: 2 additions & 2 deletions src/services/organizeImports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ namespace ts.OrganizeImports {
}

function compareIdentifiers(s1: Identifier, s2: Identifier) {
return compareStringsCaseSensitive(s1.text, s2.text);
return compareStringsCaseInsensitive(s1.text, s2.text);
}
}

Expand All @@ -277,6 +277,6 @@ namespace ts.OrganizeImports {
const name2 = getExternalModuleName(m2);
return compareBooleans(name1 === undefined, name2 === undefined) ||
compareBooleans(isExternalModuleNameRelative(name1), isExternalModuleNameRelative(name2)) ||
compareStringsCaseSensitive(name1, name2);
compareStringsCaseInsensitive(name1, name2);
}
}