{"id":40448615,"url":"https://github.com/serverless-guru/prettier-import-order","last_synced_at":"2026-01-20T17:09:34.250Z","repository":{"id":61742291,"uuid":"553534312","full_name":"serverless-guru/prettier-import-order","owner":"serverless-guru","description":"A prettier plugin to sort TS/JS import declarations by provided Regular Expression order.","archived":false,"fork":false,"pushed_at":"2023-04-11T07:02:46.000Z","size":204,"stargazers_count":9,"open_issues_count":1,"forks_count":3,"subscribers_count":12,"default_branch":"main","last_synced_at":"2025-10-18T18:36:52.909Z","etag":null,"topics":["import-order","import-sort","imports","prettier"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/serverless-guru.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-10-18T11:11:54.000Z","updated_at":"2025-07-22T12:33:47.000Z","dependencies_parsed_at":"2024-06-19T05:29:39.409Z","dependency_job_id":"ccd2364d-eb01-4c50-bdaa-ba20a6f0e8b2","html_url":"https://github.com/serverless-guru/prettier-import-order","commit_stats":{"total_commits":14,"total_committers":1,"mean_commits":14.0,"dds":0.0,"last_synced_commit":"5664847d5b8f9d4246276bd139c4bcdb3b0c9d4f"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/serverless-guru/prettier-import-order","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serverless-guru%2Fprettier-import-order","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serverless-guru%2Fprettier-import-order/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serverless-guru%2Fprettier-import-order/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serverless-guru%2Fprettier-import-order/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/serverless-guru","download_url":"https://codeload.github.com/serverless-guru/prettier-import-order/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serverless-guru%2Fprettier-import-order/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28607624,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-20T16:10:39.856Z","status":"ssl_error","status_checked_at":"2026-01-20T16:10:39.493Z","response_time":117,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["import-order","import-sort","imports","prettier"],"created_at":"2026-01-20T17:09:34.109Z","updated_at":"2026-01-20T17:09:34.238Z","avatar_url":"https://github.com/serverless-guru.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @serverless-guru/prettier-plugin-import-order ![language](https://img.shields.io/badge/language-typescript-blue.svg) ![liscence](https://img.shields.io/npm/l/@serverless-guru/prettier-plugin-import-order) ![version](https://img.shields.io/npm/v/@serverless-guru/prettier-plugin-import-order) ![download](https://img.shields.io/npm/dt/@serverless-guru/prettier-plugin-import-order)\n\nA prettier plugin to sort import declarations by provided regular expression order.\n\n## Sample\n\n### Input\n\n```javascript\n// prettier-ignore\nimport { environment } from \"./misguided-module-with-side-effects.js\";\n\nimport 'core-js/another-side-effect-module';\nimport React, {\n    FC,\n    useEffect,\n    useRef,\n    ChangeEvent,\n    KeyboardEvent,\n} from 'react';\nimport { logger } from '@core/logger';\nimport { reduce, debounce } from 'lodash';\nimport { Message } from '../Message';\nimport { createServer } from '@server/node';\nimport { Alert } from '@ui/Alert';\nimport { repeat, filter, add } from '../utils';\nimport type { Params } from './func';\nimport { initializeApp } from '@core/app';\nimport { Popup } from '@ui/Popup';\nimport { createConnection } from '@server/database';\n\nimport type { Window } from 'document';\n```\n\n### Output\n\n```javascript\n// prettier-ignore\nimport { environment } from \"./misguided-module-with-side-effects.js\";\nimport 'core-js/another-side-effect-module';\n\nimport type { Window } from 'document';\nimport type { Params } from './func';\n\nimport { debounce, reduce } from 'lodash';\nimport React, {\n    ChangeEvent,\n    FC,\n    KeyboardEvent,\n    useEffect,\n    useRef,\n} from 'react';\n\nimport { createConnection } from '@server/database';\nimport { createServer } from '@server/node';\n\nimport { initializeApp } from '@core/app';\nimport { logger } from '@core/logger';\n\nimport { Alert } from '@ui/Alert';\nimport { Popup } from '@ui/Popup';\n\nimport { Message } from '../Message';\nimport { add, filter, repeat } from '../utils';\n```\n\n## Install\n\n```shell\nnpm install @serverless-guru/prettier-plugin-import-order --save-dev\n```\n\n```shell\nyarn add @serverless-guru/prettier-plugin-import-order -D\n```\n\n## Usage\n\nAdd your preferred settings in your prettier config file.\n\n```json\n// @ts-check\n\n/** @type {import(\"@serverless-guru/prettier-plugin-import-order\").PrettierConfig} */\n{\n    \"importOrder\": [\"^@core/(.*)$\", \"^@server/(.*)$\", \"^@ui/(.*)$\", \"^[./]\"],\n    \"importOrderTypeImportsToTop\": true,\n    \"importOrderTypeImportsToBottom\": false,\n    \"importOrderBuiltinModulesToTop\": true,\n    \"importOrderCaseInsensitive\": false,\n    \"importOrderParserPlugins\": [\"typescript\", \"jsx\", \"decorators-legacy\"],\n    \"importOrderMergeDuplicateImports\": true,\n    \"importOrderSeparation\": true,\n    \"importOrderSortIndividualImports\": true,\n}\n```\n\n_Note: all flags are off by default, so explore your options [below](#apis)_\n\nYou can use the following command from the root of your project to run prettier across all matching files.\n\n```shell\nnpx prettier --write '**/*.{ts,tsx,jsx,js,css,html}'\n```\n\n### APIs\n\n#### Prevent imports from being sorted\n\nThis plugin supports standard prettier ignore comments. By default, side-effect imports (like\n`import \"core-js/stable\";`) are not sorted, so in most cases things should just work. But if you ever need to, you can\nprevent an import from getting sorted like this:\n\n```javascript\n// prettier-ignore\nimport { goods } from \"zealand\";\n\nimport { cars } from 'austria';\n```\n\nThis will keep the `zealand` import at the top instead of moving it below the `austria` import. Note that since only\nentire import statements can be ignored, line comments (`// prettier-ignore`) are recommended over inline comments\n(`/* prettier-ignore */`).\n\n#### **`importOrder`**\n\n**type**: `Array\u003cstring\u003e`\n\nA collection of Regular expressions in string format.\n\n```json\n\"importOrder\": [\"^@core/(.*)$\", \"^@server/(.*)$\", \"^@ui/(.*)$\", \"^[./]\"],\n```\n\n_Default:_ `[]`\n\nBy 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.\n\nThe plugin moves the third party imports to the top which are not part of the `importOrder` list.\nTo move the third party imports at desired place, you can use `\u003cTHIRD_PARTY_MODULES\u003e` to assign third party imports to the appropriate position:\n\n```json\n\"importOrder\": [\"^@core/(.*)$\", \"\u003cTHIRD_PARTY_MODULES\u003e\", \"^@server/(.*)$\", \"^@ui/(.*)$\", \"^[./]\"],\n```\n\n#### `importOrderSeparation`\n\n**type**: `boolean`\n\n**default value**: `false`\n\nA boolean value to enable or disable the new line separation\nbetween sorted import declarations group. The separation takes place according to the `importOrder`.\n\n```json\n\"importOrderSeparation\": true,\n```\n\n_Note:_ If you want greater control over which groups are separated from others, you can add an empty string to your `importOrder` array to signify newlines. For example:\n\n```js\n\"importOrderSeparation\": false,\n\"importOrder\": [\n   \"^react\", // React will be placed at the top of third-party modules\n    \"\u003cTHIRD_PARTY_MODULES\u003e\",\n    \"\",  // use empty strings to separate groups with empty lines\n    \"^[./]\"\n],\n```\n\n#### `importOrderSortIndividualImports`\n\n**type**: `boolean`\n\n**default value:** `false`\n\nA boolean value to enable or disable sorting of the objects in an import declarations.\n\n```typescript\nimport c, a, b from 'd';\n\n// to\n\nimport a, b, c from 'd';\n```\n\n#### `importOrderNamespaceImportsToGroupTop`\n\n**type**: `boolean`\n\n**default value:** `false`\n\nA boolean value to enable or disable sorting the namespace imports to the top of the import group.\n\nNamespace imports look like `import * as mynamespace from 'module';`\n\n#### `importOrderCaseInsensitive`\n\n**type**: `boolean`\n\n**default value**: `false`\n\nA boolean value to enable case-insensitivity in the sorting algorithm\nused to order imports within each match group.\n\nFor example, when false (or not specified):\n\n```javascript\nimport ExampleView from './ExampleView';\nimport ExamplesList from './ExamplesList';\n```\n\ncompared with `\"importOrderCaseInsensitive\": true`:\n\n```javascript\nimport ExampleView from './ExampleView';\nimport ExamplesList from './ExamplesList';\n```\n\n#### `importOrderMergeDuplicateImports`\n\n**type**: `boolean`\n\n**default value:** `false`\n\nWhen `true`, multiple import statements from the same module will be combined into a single import.\n\n#### `importOrderParserPlugins`\n\n**type**: `Array\u003cstring\u003e`\n\n**default value**: `[\"typescript\", \"jsx\"]`\n\nPreviously known as `experimentalBabelParserPluginsList`.\n\nA collection of plugins for babel parser. The plugin passes this list to babel parser, so it can understand the syntaxes\nused in the file being formatted. The plugin uses prettier itself to figure out the parser it needs to use but if that fails,\nyou can use this field to enforce the usage of the plugins' babel parser needs.\n\n**To pass the plugins to babel parser**:\n\n```json\n  \"importOrderParserPlugins\" : [\"classProperties\", \"decorators-legacy\"]\n```\n\n**To pass the options to the babel parser plugins**: Since prettier options are limited to string, you can pass plugins\nwith options as a JSON string of the plugin array:\n`\"[\\\"plugin-name\\\", { \\\"pluginOption\\\": true }]\"`.\n\n```json\n  \"importOrderParserPlugins\" : [\"classProperties\", \"[\\\"decorators\\\", { \\\"decoratorsBeforeExport\\\": true }]\"]\n```\n\n**To disable default plugins for babel parser, pass an empty array**:\n\n```json\n\"importOrderParserPlugins\": []\n```\n\n#### `importOrderBuiltinModulesToTop`\n\n**type**: `boolean`\n\n**default value:** `false`\n\nA boolean value to enable sorting of [`node builtins`](https://nodejs.org/api/module.html#modulebuiltinmodules) to the top of all import groups.\n\n#### `importOrderTypeImportsToTop`\n\n**type**: `boolean`\n\n**default value:** `false`\n\nA boolean value to enable sorting of [`type imports`](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-8.html#type-only-imports-and-export) to the top of all import groups. Even higher than builtin modules if that setting is on.\n\n#### `importOrderTypeImportsToBottom`\n\n**type**: `boolean`\n\n**default value:** `false`\n\nA boolean value to enable sorting of [`type imports`](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-8.html#type-only-imports-and-export) to the bottom of all import groups.\n\n### How does import sort work?\n\nThe plugin extracts the imports which are defined in `importOrder`. These imports are considered as _local imports_.\nThe imports which are not part of the `importOrder` is considered as _third party imports_.\n\nFirst, the plugin checks for\n[side effect imports](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#import_a_module_for_its_side_effects_only),\nsuch as `import 'mock-fs'`. These imports often modify the global scope or apply some patches to the current\nenvironment, which may affect other imports. To preserve potential side effects, these kind of side effect imports are\nclassified as unsortable. They also behave as a barrier that other imports may not cross during the sort. So for\nexample, let's say you've got these imports:\n\n```javascript\nimport D from 'd';\nimport E from 'e';\nimport F from 'f';\n\nimport 'c';\n\nimport A from 'a';\nimport B from 'b';\n```\n\nThen the first three imports are sorted and the last two imports are sorted, but all imports above `c` stay above `c`\nand all imports below `c` stay below `c`, resulting in:\n\n```javascript\nimport D from 'd';\nimport E from 'e';\nimport F from 'f';\n\nimport 'c';\n\nimport A from 'a';\nimport B from 'b';\n```\n\nAdditionally, any import statements lines that are preceded by a `// prettier-ignore` comment are also classified as\nunsortable. This can be used for edge-cases, such as when you have a named import with side-effects.\n\nNext, the plugin sorts the _local imports_ and _third party imports_ using [natural sort algorithm](https://en.wikipedia.org/wiki/Natural_sort_order).\n\nIn the end, the plugin returns final imports with _third party imports_ on top and _local imports_ at the end.\n\nThe _third party imports_ position (it's top by default) can be overridden using the `\u003cTHIRD_PARTY_MODULES\u003e` special word in the `importOrder`.\n\n## FAQ / Troubleshooting\n\nHaving some trouble or an issue? You can check [FAQ / Troubleshooting section](./docs/TROUBLESHOOTING.md).\n\n## Compatibility\n\n| Framework              | Supported                | Note                                             |\n| ---------------------- | ------------------------ | ------------------------------------------------ |\n| JS with ES Modules     | ✅ Everything            | -                                                |\n| NodeJS with ES Modules | ✅ Everything            | -                                                |\n| React                  | ✅ Everything            | -                                                |\n| Angular                | ✅ Everything            | Supported through `importOrderParserPlugins` API |\n| Vue                    | ✅ Everything            | Peer dependency `@vue/compiler-sfc` is required  |\n\n## Contribution\n\nFor more information regarding contribution, please check the [Contributing Guidelines](./CONTRIBUTING.md). If you are trying to\ndebug some code in the plugin, check [Debugging Guidelines](./docs/DEBUG.md)\n\n## Disclaimer\n\nThis plugin modifies the AST which is against the rules of prettier.\n\n## Acknowledgements\n\nThis project is a fork of [@ianvs/prettier-plugin-sort-imports](https://github.com/ianvs/prettier-plugin-sort-imports) which is a fork of [@trivago/prettier-plugin-sort-imports](https://github.com/trivago/prettier-plugin-sort-imports).\n\nWe are grateful to the authors of these projects for creating this plugin.\n\n- [@ianvs](https://github.com/ianvs)\n- [@trivago](https://github.com/trivago)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fserverless-guru%2Fprettier-import-order","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fserverless-guru%2Fprettier-import-order","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fserverless-guru%2Fprettier-import-order/lists"}