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

[Breaking] Remove importOrderCaseInsensitive option #63

Merged
merged 1 commit into from
Apr 24, 2023
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
25 changes: 0 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ Since then more critical features & fixes have been added. As a result, this rep
- [`importOrder`](#importorder)
- [`importOrderSortSpecifiers`](#importordersortspecifiers)
- [`importOrderGroupNamespaceSpecifiers`](#importordergroupnamespacespecifiers)
- [`importOrderCaseInsensitive`](#importordercaseinsensitive)
- [`importOrderMergeDuplicateImports`](#importordermergeduplicateimports)
- [`importOrderCombineTypeAndValueImports`](#importordercombinetypeandvalueimports)
- [`importOrderParserPlugins`](#importorderparserplugins)
Expand Down Expand Up @@ -129,7 +128,6 @@ module.exports = {
singleQuote: true,
semi: true,
importOrder: ['^@core/(.*)$', '', '^@server/(.*)$', '', '^@ui/(.*)$', '', '^[./]'],
importOrderCaseInsensitive: true,
importOrderParserPlugins: ['typescript', 'jsx', 'decorators-legacy'],
importOrderMergeDuplicateImports: true,
importOrderCombineTypeAndValueImports: true,
Expand Down Expand Up @@ -249,29 +247,6 @@ import Default, {charlie, delta as echo, type Alpha, type Bravo} from 'source';

A boolean value to enable or disable sorting the namespace specifiers to the top of the import group.

#### `importOrderCaseInsensitive`

**type**: `boolean`

**default value**: `false`

A boolean value to enable case-insensitivity in the sorting algorithm
used to order imports within each match group.

For example, when false (or not specified):

```javascript
import ExampleView from './ExampleView';
import ExamplesList from './ExamplesList';
```

compared with `"importOrderCaseInsensitive": true`:

```javascript
import ExamplesList from './ExamplesList';
import ExampleView from './ExampleView';
```

#### `importOrderMergeDuplicateImports`

**type**: `boolean`
Expand Down
1 change: 1 addition & 0 deletions docs/MIGRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

- The `importOrderBuiltinModulesToTop` option has been removed, and node.js built in modules are always sorted to the top.
- The `importOrderSeparation` option has been removed. Use empty quotes in your `importOrder` to control the placement of blank lines.
- The `importOrderCaseInsensitive` option has been removed, and imports will always be sorted case-insensitive.

#### `importOrderSeparation` removed

Expand Down
6 changes: 0 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,6 @@ export const options: Record<
default: [{ value: [] }],
description: 'Provide an order to sort imports.',
},
importOrderCaseInsensitive: {
type: 'boolean',
category: 'Global',
default: false,
description: 'Provide a case sensitivity boolean flag',
},
importOrderParserPlugins: {
type: 'path',
category: 'Global',
Expand Down
4 changes: 1 addition & 3 deletions src/preprocessors/preprocessor.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ParserOptions, parse as babelParser } from '@babel/parser';
import { parse as babelParser, ParserOptions } from '@babel/parser';
import traverse, { NodePath } from '@babel/traverse';
import { ImportDeclaration, isTSModuleDeclaration } from '@babel/types';

Expand All @@ -12,7 +12,6 @@ export function preprocessor(code: string, options: PrettierOptions): string {
const {
importOrderParserPlugins,
importOrder,
importOrderCaseInsensitive,
importOrderGroupNamespaceSpecifiers,
importOrderMergeDuplicateImports,
importOrderSortSpecifiers,
Expand Down Expand Up @@ -68,7 +67,6 @@ export function preprocessor(code: string, options: PrettierOptions): string {

const nodesToOutput = getSortedNodes(allOriginalImportNodes, {
importOrder,
importOrderCaseInsensitive,
importOrderGroupNamespaceSpecifiers,
importOrderMergeDuplicateImports,
importOrderCombineTypeAndValueImports,
Expand Down
1 change: 0 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export type GetSortedNodes = (
options: Pick<
PrettierOptions,
| 'importOrder'
| 'importOrderCaseInsensitive'
| 'importOrderGroupNamespaceSpecifiers'
| 'importOrderMergeDuplicateImports'
| 'importOrderCombineTypeAndValueImports'
Expand Down
1 change: 0 additions & 1 deletion src/utils/__tests__/get-all-comments-from-nodes.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ const getSortedImportNodes = (code: string, options?: ParserOptions) => {

return getSortedNodes(importNodes, {
importOrder: [],
importOrderCaseInsensitive: false,
importOrderGroupNamespaceSpecifiers: false,
importOrderMergeDuplicateImports: false,
importOrderCombineTypeAndValueImports: false,
Expand Down
2 changes: 0 additions & 2 deletions src/utils/__tests__/get-code-from-ast.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import a from 'a';
const importNodes = getImportNodes(code);
const sortedNodes = getSortedNodes(importNodes, {
importOrder: [],
importOrderCaseInsensitive: false,
importOrderGroupNamespaceSpecifiers: false,
importOrderMergeDuplicateImports: false,
importOrderCombineTypeAndValueImports: false,
Expand Down Expand Up @@ -58,7 +57,6 @@ import type {See} from 'c';
const importNodes = getImportNodes(code, { plugins: ['typescript'] });
const sortedNodes = getSortedNodes(importNodes, {
importOrder: [],
importOrderCaseInsensitive: false,
importOrderGroupNamespaceSpecifiers: false,
importOrderMergeDuplicateImports: true,
importOrderCombineTypeAndValueImports: false,
Expand Down
68 changes: 28 additions & 40 deletions src/utils/__tests__/get-sorted-nodes-by-import-order.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ test('it returns all sorted nodes', () => {
const result = getImportNodes(code);
const sorted = getSortedNodesByImportOrder(result, {
importOrder: ['^[./]'],
importOrderCaseInsensitive: false,
importOrderGroupNamespaceSpecifiers: false,
importOrderMergeDuplicateImports: false,
importOrderCombineTypeAndValueImports: false,
Expand All @@ -40,16 +39,16 @@ test('it returns all sorted nodes', () => {
'node:fs/promises',
'node:url',
'path',
'BY',
'Ba',
'XY',
'Xa',
'a',
'Ba',
'BY',
'c',
'g',
'k',
't',
'x',
'Xa',
'XY',
'z',
'./local',
]);
Expand All @@ -63,16 +62,16 @@ test('it returns all sorted nodes', () => {
['fs'],
['url'], // `node:url` comes before `path`
['path'],
['BY'],
['Ba'],
['XY'],
['Xa'],
['a'],
['Ba'],
['BY'],
['c', 'cD'],
['g'],
['k', 'kE', 'kB'],
['tC', 'tA', 'tB'],
['x'],
['Xa'],
['XY'],
['z'],
['local'],
]);
Expand All @@ -82,7 +81,6 @@ test('it returns all sorted nodes case-insensitive', () => {
const result = getImportNodes(code);
const sorted = getSortedNodesByImportOrder(result, {
importOrder: ['^[./]'],
importOrderCaseInsensitive: true,
importOrderGroupNamespaceSpecifiers: false,
importOrderMergeDuplicateImports: false,
importOrderCombineTypeAndValueImports: false,
Expand Down Expand Up @@ -135,28 +133,26 @@ test('it returns all sorted nodes with sort order', () => {
const result = getImportNodes(code);
const sorted = getSortedNodesByImportOrder(result, {
importOrder: ['^a$', '^t$', '^k$', '^B', '^[./]'],
importOrderCaseInsensitive: false,
importOrderGroupNamespaceSpecifiers: false,
importOrderMergeDuplicateImports: false,
importOrderCombineTypeAndValueImports: false,
importOrderSortSpecifiers: false,
}) as ImportDeclaration[];

expect(getSortedNodesNamesAndNewlines(sorted)).toEqual([
'node:fs/promises',
'node:url',
'path',
'XY',
'Xa',
'c',
'g',
'x',
'Xa',
'XY',
'z',
'a',
't',
'k',
'BY',
'Ba',
'BY',
'./local',
]);
expect(
Expand All @@ -169,17 +165,17 @@ test('it returns all sorted nodes with sort order', () => {
['fs'],
['url'], // `node:url` comes before `path`
['path'],
['XY'],
['Xa'],
['c', 'cD'],
['g'],
['x'],
['Xa'],
['XY'],
['z'],
['a'],
['tC', 'tA', 'tB'],
['k', 'kE', 'kB'],
['BY'],
['Ba'],
['BY'],
['local'],
]);
});
Expand All @@ -188,7 +184,6 @@ test('it returns all sorted nodes with sort order case-insensitive', () => {
const result = getImportNodes(code);
const sorted = getSortedNodesByImportOrder(result, {
importOrder: ['^a$', '^t$', '^k$', '^B', '^[./]'],
importOrderCaseInsensitive: true,
importOrderGroupNamespaceSpecifiers: false,
importOrderMergeDuplicateImports: false,
importOrderCombineTypeAndValueImports: false,
Expand Down Expand Up @@ -240,7 +235,6 @@ test('it returns all sorted import nodes with sorted import specifiers', () => {
const result = getImportNodes(code);
const sorted = getSortedNodesByImportOrder(result, {
importOrder: ['^a$', '^t$', '^k$', '^B', '^[./]'],
importOrderCaseInsensitive: false,
importOrderGroupNamespaceSpecifiers: false,
importOrderMergeDuplicateImports: false,
importOrderCombineTypeAndValueImports: false,
Expand All @@ -250,17 +244,17 @@ test('it returns all sorted import nodes with sorted import specifiers', () => {
'node:fs/promises',
'node:url',
'path',
'XY',
'Xa',
'c',
'g',
'x',
'Xa',
'XY',
'z',
'a',
't',
'k',
'BY',
'Ba',
'BY',
'./local',
]);
expect(
Expand All @@ -273,17 +267,17 @@ test('it returns all sorted import nodes with sorted import specifiers', () => {
['fs'],
['url'], // `node:url` comes before `path`
['path'],
['XY'],
['Xa'],
['c', 'cD'],
['g'],
['x'],
['Xa'],
['XY'],
['z'],
['a'],
['tA', 'tB', 'tC'],
['k', 'kB', 'kE'],
['BY'],
['Ba'],
['BY'],
['local'],
]);
});
Expand All @@ -292,7 +286,6 @@ test('it returns all sorted import nodes with sorted import specifiers with case
const result = getImportNodes(code);
const sorted = getSortedNodesByImportOrder(result, {
importOrder: ['^a$', '^t$', '^k$', '^B', '^[./]'],
importOrderCaseInsensitive: true,
importOrderGroupNamespaceSpecifiers: false,
importOrderMergeDuplicateImports: false,
importOrderCombineTypeAndValueImports: false,
Expand Down Expand Up @@ -344,7 +337,6 @@ test('it returns all sorted nodes with namespace specifiers at the top (under bu
const result = getImportNodes(code);
const sorted = getSortedNodesByImportOrder(result, {
importOrder: ['^[./]'],
importOrderCaseInsensitive: false,
importOrderGroupNamespaceSpecifiers: true,
importOrderMergeDuplicateImports: false,
importOrderCombineTypeAndValueImports: false,
Expand All @@ -357,24 +349,23 @@ test('it returns all sorted nodes with namespace specifiers at the top (under bu
'path',
'a',
'x',
'BY',
'Ba',
'XY',
'Xa',
'BY',
'c',
'g',
'k',
't',
'Xa',
'XY',
'z',
'./local',
]);
});

test('it returns all sorted nodes with builtin specifiers at the top, ', () => {
test('it returns all sorted nodes with builtin specifiers at the top', () => {
const result = getImportNodes(code);
const sorted = getSortedNodesByImportOrder(result, {
importOrder: ['^[./]'],
importOrderCaseInsensitive: false,
importOrderGroupNamespaceSpecifiers: false,
importOrderMergeDuplicateImports: false,
importOrderCombineTypeAndValueImports: false,
Expand All @@ -385,16 +376,16 @@ test('it returns all sorted nodes with builtin specifiers at the top, ', () => {
'node:fs/promises',
'node:url',
'path',
'BY',
'Ba',
'XY',
'Xa',
'a',
'Ba',
'BY',
'c',
'g',
'k',
't',
'x',
'Xa',
'XY',
'z',
'./local',
]);
Expand All @@ -404,7 +395,6 @@ test('it returns all sorted nodes with custom third party modules and builtins a
const result = getImportNodes(code);
const sorted = getSortedNodesByImportOrder(result, {
importOrder: ['^a$', '<THIRD_PARTY_MODULES>', '^t$', '^k$', '^[./]'],
importOrderCaseInsensitive: true,
importOrderGroupNamespaceSpecifiers: false,
importOrderMergeDuplicateImports: false,
importOrderCombineTypeAndValueImports: false,
Expand Down Expand Up @@ -440,7 +430,6 @@ test('it returns all sorted nodes with custom separation', () => {
'^k$',
'^[./]',
],
importOrderCaseInsensitive: true,
importOrderGroupNamespaceSpecifiers: false,
importOrderMergeDuplicateImports: false,
importOrderCombineTypeAndValueImports: false,
Expand Down Expand Up @@ -479,7 +468,6 @@ test('it does not add multiple custom import separators', () => {
'^k$',
'^[./]',
],
importOrderCaseInsensitive: true,
importOrderGroupNamespaceSpecifiers: false,
importOrderMergeDuplicateImports: false,
importOrderCombineTypeAndValueImports: false,
Expand Down
Loading