Skip to content

Commit 0be0fff

Browse files
committed
Sort uppercase before lowercase
1 parent da275c6 commit 0be0fff

File tree

5 files changed

+53
-3
lines changed

5 files changed

+53
-3
lines changed

.changeset/famous-insects-matter.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'eslint-plugin-import-sorting': minor
3+
---
4+
5+
Explicitly set case sensitivity & sort uppercase before lowercase

src/rules/order.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export default createRule<unknown[], MessageId>({
5151
create(context) {
5252
let { settings, sourceCode } = context
5353
let options: Options = {
54-
ignoreCase: true,
54+
ignoreCase: false,
5555
newlinesBetween: 'always',
5656
order: 'asc',
5757
type: 'natural',

src/rules/specifier-order.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export default createRule<unknown[], MessageId>({
4747
let { sourceCode } = context
4848
let options: Options = {
4949
ignoreAlias: true,
50-
ignoreCase: true,
50+
ignoreCase: false,
5151
groupKind: 'mixed',
5252
order: 'asc',
5353
type: 'natural',

src/utils/compare.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,11 @@ function stripProtocol(name: string) {
5757
function compareString(first: string, second: string) {
5858
if (first.startsWith('.') && !second.startsWith('.')) return 1
5959
if (!first.startsWith('.') && second.startsWith('.')) return -1
60-
return first.localeCompare(second, 'en', { numeric: true })
60+
return first.localeCompare(second, 'en', {
61+
caseFirst: 'upper',
62+
numeric: true,
63+
sensitivity: 'case',
64+
})
6165
}
6266

6367
function compareDotSegments(first: string, second: string) {

tests/rules/order.test.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,47 @@ describe('order', () => {
5858
],
5959
})
6060

61+
ruleTester.run('checks character case', orderRule, {
62+
valid: [
63+
{
64+
name: 'without errors',
65+
code: dedent`
66+
import { a } from 'Arrow'
67+
import { b } from 'arrow'
68+
import { c } from 'Arrows'
69+
import { d } from 'ArrowTurn'
70+
`,
71+
},
72+
],
73+
invalid: [
74+
{
75+
name: 'fixes import order',
76+
code: dedent`
77+
import { a } from 'Arrow'
78+
import { d } from 'ArrowTurn'
79+
import { c } from 'Arrows'
80+
import { b } from 'arrow'
81+
`,
82+
output: dedent`
83+
import { a } from 'Arrow'
84+
import { b } from 'arrow'
85+
import { c } from 'Arrows'
86+
import { d } from 'ArrowTurn'
87+
`,
88+
errors: [
89+
{
90+
messageId: 'out-of-order',
91+
data: { left: 'ArrowTurn', right: 'Arrows' },
92+
},
93+
{
94+
messageId: 'out-of-order',
95+
data: { left: 'Arrows', right: 'arrow' },
96+
},
97+
],
98+
},
99+
],
100+
})
101+
61102
ruleTester.run('sorts imports into groups', orderRule, {
62103
valid: [
63104
{

0 commit comments

Comments
 (0)