Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sort uppercase before lowercase
Browse files Browse the repository at this point in the history
stormwarning committed Jan 21, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent da275c6 commit 0be0fff
Showing 5 changed files with 53 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/famous-insects-matter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'eslint-plugin-import-sorting': minor
---

Explicitly set case sensitivity & sort uppercase before lowercase
2 changes: 1 addition & 1 deletion src/rules/order.ts
Original file line number Diff line number Diff line change
@@ -51,7 +51,7 @@ export default createRule<unknown[], MessageId>({
create(context) {
let { settings, sourceCode } = context
let options: Options = {
ignoreCase: true,
ignoreCase: false,
newlinesBetween: 'always',
order: 'asc',
type: 'natural',
2 changes: 1 addition & 1 deletion src/rules/specifier-order.ts
Original file line number Diff line number Diff line change
@@ -47,7 +47,7 @@ export default createRule<unknown[], MessageId>({
let { sourceCode } = context
let options: Options = {
ignoreAlias: true,
ignoreCase: true,
ignoreCase: false,
groupKind: 'mixed',
order: 'asc',
type: 'natural',
6 changes: 5 additions & 1 deletion src/utils/compare.ts
Original file line number Diff line number Diff line change
@@ -57,7 +57,11 @@ function stripProtocol(name: string) {
function compareString(first: string, second: string) {
if (first.startsWith('.') && !second.startsWith('.')) return 1
if (!first.startsWith('.') && second.startsWith('.')) return -1
return first.localeCompare(second, 'en', { numeric: true })
return first.localeCompare(second, 'en', {
caseFirst: 'upper',
numeric: true,
sensitivity: 'case',
})
}

function compareDotSegments(first: string, second: string) {
41 changes: 41 additions & 0 deletions tests/rules/order.test.ts
Original file line number Diff line number Diff line change
@@ -58,6 +58,47 @@ describe('order', () => {
],
})

ruleTester.run('checks character case', orderRule, {
valid: [
{
name: 'without errors',
code: dedent`
import { a } from 'Arrow'
import { b } from 'arrow'
import { c } from 'Arrows'
import { d } from 'ArrowTurn'
`,
},
],
invalid: [
{
name: 'fixes import order',
code: dedent`
import { a } from 'Arrow'
import { d } from 'ArrowTurn'
import { c } from 'Arrows'
import { b } from 'arrow'
`,
output: dedent`
import { a } from 'Arrow'
import { b } from 'arrow'
import { c } from 'Arrows'
import { d } from 'ArrowTurn'
`,
errors: [
{
messageId: 'out-of-order',
data: { left: 'ArrowTurn', right: 'Arrows' },
},
{
messageId: 'out-of-order',
data: { left: 'Arrows', right: 'arrow' },
},
],
},
],
})

ruleTester.run('sorts imports into groups', orderRule, {
valid: [
{

0 comments on commit 0be0fff

Please sign in to comment.