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 importOrderSortSpecifiers option #65

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
22 changes: 0 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ Since then more critical features & fixes have been added, and the options have
- [How does import sort work?](#how-does-import-sort-work)
- [Options](#options)
- [`importOrder`](#importorder)
- [`importOrderSortSpecifiers`](#importordersortspecifiers)
- [`importOrderMergeDuplicateImports`](#importordermergeduplicateimports)
- [`importOrderCombineTypeAndValueImports`](#importordercombinetypeandvalueimports)
- [`importOrderParserPlugins`](#importorderparserplugins)
Expand Down Expand Up @@ -133,7 +132,6 @@ module.exports = {
importOrderParserPlugins: ['typescript', 'jsx', 'decorators-legacy'],
importOrderMergeDuplicateImports: true,
importOrderCombineTypeAndValueImports: true,
importOrderSortSpecifiers: true,
};
```

Expand Down Expand Up @@ -221,26 +219,6 @@ _Note:_ If you want to separate some groups from others, you can add an empty st
],
```

#### `importOrderSortSpecifiers`

**type**: `boolean`

**default value:** `false`

A boolean value to enable or disable sorting of the specifiers in an import declarations. If enabled, type imports will be sorted after value imports.

Before:

```ts
import Default, {type Bravo, delta as echo, charlie, type Alpha} from 'source';
```

After:

```ts
import Default, {charlie, delta as echo, type Alpha, type Bravo} from 'source';
```

#### `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 @@ -8,6 +8,7 @@
- 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.
- The `importOrderGroupNamespaceSpecifiers` option has been removed.
- The `importOrderSortSpecifiers` option has been removed, and specifiers are now always sorted (previous `true` setting)

#### `importOrderSeparation` removed

Expand Down
1 change: 0 additions & 1 deletion prettier.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ module.exports = {
semi: true,
plugins: [require('./lib/src/index.js')],
importOrder: ['', '<THIRD_PARTY_MODULES>', '', '^[./]'],
importOrderSortSpecifiers: true,
};
6 changes: 0 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,6 @@ export const options: Record<
default: [{ value: ['typescript', 'jsx'] }],
description: 'Provide a list of plugins for special syntax',
},
importOrderSortSpecifiers: {
type: 'boolean',
category: 'Global',
default: false,
description: 'Should specifiers be sorted?',
},
importOrderMergeDuplicateImports: {
type: 'boolean',
category: 'Global',
Expand Down
2 changes: 0 additions & 2 deletions src/preprocessors/preprocessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export function preprocessor(code: string, options: PrettierOptions): string {
importOrderParserPlugins,
importOrder,
importOrderMergeDuplicateImports,
importOrderSortSpecifiers,
} = options;

let { importOrderCombineTypeAndValueImports } = options;
Expand Down Expand Up @@ -68,7 +67,6 @@ export function preprocessor(code: string, options: PrettierOptions): string {
importOrder,
importOrderMergeDuplicateImports,
importOrderCombineTypeAndValueImports,
importOrderSortSpecifiers,
});

return getCodeFromAst({
Expand Down
1 change: 0 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ export type GetSortedNodes = (
| 'importOrder'
| 'importOrderMergeDuplicateImports'
| 'importOrderCombineTypeAndValueImports'
| 'importOrderSortSpecifiers'
>,
) => ImportOrLine[];

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 @@ -13,7 +13,6 @@ const getSortedImportNodes = (code: string, options?: ParserOptions) => {
importOrder: [],
importOrderMergeDuplicateImports: false,
importOrderCombineTypeAndValueImports: false,
importOrderSortSpecifiers: 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 @@ -20,7 +20,6 @@ import a from 'a';
importOrder: [],
importOrderMergeDuplicateImports: false,
importOrderCombineTypeAndValueImports: false,
importOrderSortSpecifiers: false,
});
const formatted = getCodeFromAst({
nodesToOutput: sortedNodes,
Expand Down Expand Up @@ -58,7 +57,6 @@ import type {See} from 'c';
importOrder: [],
importOrderMergeDuplicateImports: true,
importOrderCombineTypeAndValueImports: false,
importOrderSortSpecifiers: false,
});
const formatted = getCodeFromAst({
nodesToOutput: sortedNodes,
Expand Down
210 changes: 16 additions & 194 deletions src/utils/__tests__/get-sorted-nodes-by-import-order.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ test('it returns all sorted nodes', () => {
importOrder: ['^[./]'],
importOrderMergeDuplicateImports: false,
importOrderCombineTypeAndValueImports: false,
importOrderSortSpecifiers: false,
}) as ImportDeclaration[];

expect(getSortedNodesNamesAndNewlines(sorted)).toEqual([
Expand Down Expand Up @@ -66,59 +65,8 @@ test('it returns all sorted nodes', () => {
['BY'],
['c', 'cD'],
['g'],
['k', 'kE', 'kB'],
['tC', 'tA', 'tB'],
['x'],
['Xa'],
['XY'],
['z'],
['local'],
]);
});

test('it returns all sorted nodes case-insensitive', () => {
const result = getImportNodes(code);
const sorted = getSortedNodesByImportOrder(result, {
importOrder: ['^[./]'],
importOrderMergeDuplicateImports: false,
importOrderCombineTypeAndValueImports: false,
importOrderSortSpecifiers: false,
}) as ImportDeclaration[];

expect(getSortedNodesNamesAndNewlines(sorted)).toEqual([
'node:fs/promises',
'node:url',
'path',
'a',
'Ba',
'BY',
'c',
'g',
'k',
't',
'x',
'Xa',
'XY',
'z',
'./local',
]);
expect(
sorted
.filter((node) => node.type === 'ImportDeclaration')
.map((importDeclaration) =>
getSortedNodesModulesNames(importDeclaration.specifiers),
),
).toEqual([
['fs'],
['url'], // `node:url` comes before `path`
['path'],
['a'],
['Ba'],
['BY'],
['c', 'cD'],
['g'],
['k', 'kE', 'kB'],
['tC', 'tA', 'tB'],
['k', 'kB', 'kE'],
['tA', 'tB', 'tC'],
['x'],
['Xa'],
['XY'],
Expand All @@ -133,107 +81,6 @@ test('it returns all sorted nodes with sort order', () => {
importOrder: ['^a$', '^t$', '^k$', '^B', '^[./]'],
importOrderMergeDuplicateImports: false,
importOrderCombineTypeAndValueImports: false,
importOrderSortSpecifiers: false,
}) as ImportDeclaration[];
expect(getSortedNodesNamesAndNewlines(sorted)).toEqual([
'node:fs/promises',
'node:url',
'path',
'c',
'g',
'x',
'Xa',
'XY',
'z',
'a',
't',
'k',
'Ba',
'BY',
'./local',
]);
expect(
sorted
.filter((node) => node.type === 'ImportDeclaration')
.map((importDeclaration) =>
getSortedNodesModulesNames(importDeclaration.specifiers),
),
).toEqual([
['fs'],
['url'], // `node:url` comes before `path`
['path'],
['c', 'cD'],
['g'],
['x'],
['Xa'],
['XY'],
['z'],
['a'],
['tC', 'tA', 'tB'],
['k', 'kE', 'kB'],
['Ba'],
['BY'],
['local'],
]);
});

test('it returns all sorted nodes with sort order case-insensitive', () => {
const result = getImportNodes(code);
const sorted = getSortedNodesByImportOrder(result, {
importOrder: ['^a$', '^t$', '^k$', '^B', '^[./]'],
importOrderMergeDuplicateImports: false,
importOrderCombineTypeAndValueImports: false,
importOrderSortSpecifiers: false,
}) as ImportDeclaration[];
expect(getSortedNodesNamesAndNewlines(sorted)).toEqual([
'node:fs/promises',
'node:url',
'path',
'c',
'g',
'x',
'Xa',
'XY',
'z',
'a',
't',
'k',
'Ba',
'BY',
'./local',
]);
expect(
sorted
.filter((node) => node.type === 'ImportDeclaration')
.map((importDeclaration) =>
getSortedNodesModulesNames(importDeclaration.specifiers),
),
).toEqual([
['fs'],
['url'], // `node:url` comes before `path`
['path'],
['c', 'cD'],
['g'],
['x'],
['Xa'],
['XY'],
['z'],
['a'],
['tC', 'tA', 'tB'],
['k', 'kE', 'kB'],
['Ba'],
['BY'],
['local'],
]);
});

test('it returns all sorted import nodes with sorted import specifiers', () => {
const result = getImportNodes(code);
const sorted = getSortedNodesByImportOrder(result, {
importOrder: ['^a$', '^t$', '^k$', '^B', '^[./]'],
importOrderMergeDuplicateImports: false,
importOrderCombineTypeAndValueImports: false,
importOrderSortSpecifiers: true,
}) as ImportDeclaration[];
expect(getSortedNodesNamesAndNewlines(sorted)).toEqual([
'node:fs/promises',
Expand Down Expand Up @@ -277,53 +124,32 @@ test('it returns all sorted import nodes with sorted import specifiers', () => {
]);
});

test('it returns all sorted import nodes with sorted import specifiers with case-insensitive ', () => {
const result = getImportNodes(code);
test('it returns all sorted import nodes with sorted import specifiers', () => {
const code = `
import { tC, tA, tB } from 't';
import k, { kE, kB } from 'k';
import {type B, A} from 'z';
`;

const result = getImportNodes(code, {
plugins: ['typescript'],
});
const sorted = getSortedNodesByImportOrder(result, {
importOrder: ['^a$', '^t$', '^k$', '^B', '^[./]'],
importOrder: ['^[./]'],
importOrderMergeDuplicateImports: false,
importOrderCombineTypeAndValueImports: false,
importOrderSortSpecifiers: true,
}) as ImportDeclaration[];
expect(getSortedNodesNamesAndNewlines(sorted)).toEqual([
'node:fs/promises',
'node:url',
'path',
'c',
'g',
'x',
'Xa',
'XY',
'z',
'a',
't',
'k',
'Ba',
'BY',
'./local',
]);
expect(getSortedNodesNamesAndNewlines(sorted)).toEqual(['k', 't', 'z']);
expect(
sorted
.filter((node) => node.type === 'ImportDeclaration')
.map((importDeclaration) =>
getSortedNodesModulesNames(importDeclaration.specifiers),
),
).toEqual([
['fs'],
['url'], // `node:url` comes before `path`
['path'],
['c', 'cD'],
['g'],
['x'],
['Xa'],
['XY'],
['z'],
['a'],
['tA', 'tB', 'tC'],
['k', 'kB', 'kE'],
['Ba'],
['BY'],
['local'],
['tA', 'tB', 'tC'],
['A', 'B'],
]);
});

Expand All @@ -333,7 +159,6 @@ test('it returns all sorted nodes with builtin specifiers at the top', () => {
importOrder: ['^[./]'],
importOrderMergeDuplicateImports: false,
importOrderCombineTypeAndValueImports: false,
importOrderSortSpecifiers: false,
}) as ImportDeclaration[];

expect(getSortedNodesNamesAndNewlines(sorted)).toEqual([
Expand Down Expand Up @@ -361,7 +186,6 @@ test('it returns all sorted nodes with custom third party modules and builtins a
importOrder: ['^a$', '<THIRD_PARTY_MODULES>', '^t$', '^k$', '^[./]'],
importOrderMergeDuplicateImports: false,
importOrderCombineTypeAndValueImports: false,
importOrderSortSpecifiers: false,
}) as ImportDeclaration[];
expect(getSortedNodesNamesAndNewlines(sorted)).toEqual([
'node:fs/promises',
Expand Down Expand Up @@ -395,7 +219,6 @@ test('it returns all sorted nodes with custom separation', () => {
],
importOrderMergeDuplicateImports: false,
importOrderCombineTypeAndValueImports: false,
importOrderSortSpecifiers: false,
}) as ImportDeclaration[];
expect(getSortedNodesNamesAndNewlines(sorted)).toEqual([
'node:fs/promises',
Expand Down Expand Up @@ -432,7 +255,6 @@ test('it does not add multiple custom import separators', () => {
],
importOrderMergeDuplicateImports: false,
importOrderCombineTypeAndValueImports: false,
importOrderSortSpecifiers: false,
}) as ImportDeclaration[];
expect(getSortedNodesNamesAndNewlines(sorted)).toEqual([
'node:fs/promises',
Expand Down
Loading