Skip to content

Commit

Permalink
Update our Default Sort Order builtins, (thirdparty &absolute paths),…
Browse files Browse the repository at this point in the history
… relative paths
  • Loading branch information
fbartho committed May 15, 2023
1 parent 1ab1031 commit f978466
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,17 @@ A collection of Regular expressions in string format.
"importOrder": ["^@core/(.*)$", "^@server/(.*)$", "^@ui/(.*)$", "^[./]"],
```

_Default:_ `[]`
_Default:_

By default, this plugin will not move any imports. To separate third party from relative imports, use `["^[./]"]`. This will become the default in the next major version.
```js
[
// built-ins are implicitly first
'<THIRD_PARTY_MODULES>',
'^[.]', // relative imports
],
```

By default, this plugin sorts as documented on the line above.

The plugin moves the third party imports to the top which are not part of the `importOrder` list.
To move the third party imports at desired place, you can use `<THIRD_PARTY_MODULES>` to assign third party imports to the appropriate position:
Expand Down
14 changes: 12 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { parsers as flowParsers } from 'prettier/parser-flow';
import { parsers as htmlParsers } from 'prettier/parser-html';
import { parsers as typescriptParsers } from 'prettier/parser-typescript';

import { THIRD_PARTY_MODULES_SPECIAL_WORD } from './constants';
import { defaultPreprocessor } from './preprocessors/default';
import { vuePreprocessor } from './preprocessors/vue';
import type { PrettierOptions } from './types';
Expand All @@ -25,8 +26,17 @@ export const options: Record<
type: 'path',
category: 'Global',
array: true,
default: [{ value: [] }],
description: 'Provide an order to sort imports.',
default: [
{
value: [
// built-ins are implicitly first
THIRD_PARTY_MODULES_SPECIAL_WORD,
'^[.]', // relative imports
],
},
],
description:
'Provide an order to sort imports. [built-ins are always implicitly first]',
},
importOrderParserPlugins: {
type: 'path',
Expand Down

0 comments on commit f978466

Please sign in to comment.