{"_rev":"3-6105c34e4ad71f1482d13159c284d9ff","time":{"created":"2025-06-13T19:42:20.288Z","modified":"2025-06-13T19:42:20.935Z","5.2.2":"2025-06-13T19:26:12.180Z","5.2.3":"2025-06-13T19:42:20.634Z"},"_id":"@ckwalsh/prettier-plugin-sort-imports","name":"@ckwalsh/prettier-plugin-sort-imports","dist-tags":{"latest":"5.2.3"},"versions":{"5.2.3":{"name":"@ckwalsh/prettier-plugin-sort-imports","version":"5.2.3","description":"Fork of trivago/prettier-plugin-sort-imports, with PR #359","main":"lib/src/index.js","types":"types/index.d.ts","repository":{"url":"git+https://github.com/ckwalsh/prettier-plugin-sort-imports.git","type":"git"},"homepage":"https://github.com/ckwalsh/prettier-plugin-sort-imports#readme","scripts":{"prepare":"yarn run compile","compile":"tsc","preexample":"yarn run compile","example":"prettier --config ./examples/.prettierrc --plugin lib/src/index.js","test":"yarn node --experimental-vm-modules $(yarn bin jest)","type-check":"tsc --noEmit","prepublishOnly":"npm run compile && npm run test"},"keywords":["prettier","plugin","sort","import","typescript","javascript"],"author":{"name":"Cullen Walsh","url":"https://github.com/ckwalsh"},"license":"Apache-2.0","dependencies":{"@babel/generator":"^7.26.5","@babel/parser":"^7.26.7","@babel/traverse":"^7.26.7","@babel/types":"^7.26.7","javascript-natural-sort":"^0.7.1","lodash":"^4.17.21"},"devDependencies":{"@babel/core":"^7.26.7","@types/chai":"^5.0.1","@types/jest":"^29.5.14","@types/lodash":"^4.17.14","@types/node":"^22.10.10","@vue/compiler-sfc":"^3.5.13","jest":"^29.7.0","prettier":"^3.4.2","prettier-plugin-svelte":"^3.3.3","svelte":"^4.2.19","ts-jest":"^29.2.5","typescript":"^5.7.3"},"peerDependencies":{"@vue/compiler-sfc":"3.x","prettier":"2.x - 3.x","prettier-plugin-svelte":"3.x","svelte":"4.x || 5.x"},"engines":{"node":">18.12"},"peerDependenciesMeta":{"@vue/compiler-sfc":{"optional":true},"prettier-plugin-svelte":{"optional":true},"svelte":{"optional":true}},"resolutions":{"@types/babel__generator":"7.6.8","@babel/types":"7.26.7"},"packageManager":"yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e","_id":"@ckwalsh/prettier-plugin-sort-imports@5.2.3","gitHead":"05bd0f397cd87f7704140130fc72d51e408b2782","bugs":{"url":"https://github.com/ckwalsh/prettier-plugin-sort-imports/issues"},"_nodeVersion":"22.16.0","_npmVersion":"10.9.2","dist":{"integrity":"sha512-VXrTAapCZ8r83+NeUjTRFRAg/C0DlPLbK4vOAs30qxXGr2Y+zFA9Kbr4+hYttg+bom93Gs2ZhbNclcA1xA58Ug==","shasum":"5e450fc46b26b220d18c4ec11a690b6b959e80fe","tarball":"https://registry.npmjs.org/@ckwalsh/prettier-plugin-sort-imports/-/prettier-plugin-sort-imports-5.2.3.tgz","fileCount":43,"unpackedSize":150791,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCICw4B8eP24Vb97uJSQsk8ltFbqa7kW+kR7zgPGi/FoxDAiEAj00JKPSEhPmwd5hzBp+DeqvLhEHhWpOZeV7xKNEaTiw="}]},"_npmUser":{"name":"ckwalsh","email":"ckwalsh@cullenwalsh.com"},"directories":{},"maintainers":[{"name":"ckwalsh","email":"ckwalsh@cullenwalsh.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/prettier-plugin-sort-imports_5.2.3_1749843740403_0.17089892543911422"},"_hasShrinkwrap":false}},"maintainers":[{"name":"ckwalsh","email":"ckwalsh@cullenwalsh.com"}],"description":"Fork of trivago/prettier-plugin-sort-imports, with PR #359","homepage":"https://github.com/ckwalsh/prettier-plugin-sort-imports#readme","keywords":["prettier","plugin","sort","import","typescript","javascript"],"repository":{"url":"git+https://github.com/ckwalsh/prettier-plugin-sort-imports.git","type":"git"},"author":{"name":"Cullen Walsh","url":"https://github.com/ckwalsh"},"bugs":{"url":"https://github.com/ckwalsh/prettier-plugin-sort-imports/issues"},"license":"Apache-2.0","readme":"# Prettier plugin sort imports\n\nA prettier plugin to sort import declarations by provided Regular Expression order.\n\n**Note: If you are migrating from v2.x.x to v3.x.x, [Please Read Migration Guidelines](./docs/MIGRATION.md)**\n\n### Input\n\n```javascript\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 { initializeApp } from '@core/app';\nimport { Popup } from '@ui/Popup';\nimport { createConnection } from '@server/database';\n```\n\n### Output\n\n```javascript\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\nnpm\n\n```shell script\nnpm install --save-dev @trivago/prettier-plugin-sort-imports\n```\n\nor, using yarn\n\n```shell script\nyarn add --dev @trivago/prettier-plugin-sort-imports\n```\n\n**Note: If you are migrating from v2.x.x to v3.x.x, [Please Read Migration Guidelines](./docs/MIGRATION.md)**\n\n**Note: If formatting `.vue` sfc files please install `@vue/compiler-sfc` if not in your dependency tree - this normally is within Vue projects.**\n\n### Usage\n\nAdd an order in prettier config file.\n\n```ecmascript 6\nmodule.exports = {\n  \"printWidth\": 80,\n  \"tabWidth\": 4,\n  \"trailingComma\": \"all\",\n  \"singleQuote\": true,\n  \"semi\": true,\n  \"importOrder\": [\"^@core/(.*)$\", \"^@server/(.*)$\", \"^@ui/(.*)$\", \"^[./]\"],\n  \"importOrderSeparation\": true,\n  \"importOrderSortSpecifiers\": true\n}\n```\n\n\\*\\*Note: There may be an issue with some package managers, such as `pnpm` or when using `prettier` v3.x. You can solve it by providing additional configuration option in prettier config file.\n\n```js\nmodule.exports = {\n    ...\n    \"plugins\": [\"@trivago/prettier-plugin-sort-imports\"]\n}\n```\n\n### APIs\n\n#### **`importOrder`**\n\n**type**: `Array<string>`\n\nA collection of Regular expressions in string format.\n\n```\n\"importOrder\": [\"^@core/(.*)$\", \"^@server/(.*)$\", \"^@ui/(.*)$\", \"^[./]\"],\n```\n\n_Default behavior:_ The 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 `<THIRD_PARTY_MODULES>` to assign third party imports to the appropriate position:\n\n```\n\"importOrder\": [\"^@core/(.*)$\", \"<THIRD_PARTY_MODULES>\", \"^@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```\n\"importOrderSeparation\": true,\n```\n\n#### `importOrderSortSpecifiers`\n\n**type**: `boolean`\n\n**default value:** `false`\n\nA boolean value to enable or disable sorting of the specifiers in an import declarations.\n\n#### `importOrderGroupNamespaceSpecifiers`\n\n**type**: `boolean`\n\n**default value:** `false`\n\nA boolean value to enable or disable sorting the namespace specifiers to the top of the import group.\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```ecmascript 6\nimport ExampleView from './ExampleView';\nimport ExamplesList from './ExamplesList';\n```\n\ncompared with `\"importOrderCaseInsensitive\": true`:\n\n```ecmascript 6\nimport ExamplesList from './ExamplesList';\nimport ExampleView from './ExampleView';\n```\n\n#### `importOrderParserPlugins`\n\n**type**: `Array<string>`\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```\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```\n  \"importOrderParserPlugins\" : [\"classProperties\", \"[\\\"decorators\\\", { \\\"decoratorsBeforeExport\\\": true }]\"]\n```\n\n**To disable default plugins for babel parser, pass an empty array**:\n\n```\nimportOrderParserPlugins: []\n```\n\n#### `importOrderSideEffects`\n\n**type**: `boolean`\n\n**default value**: `true`\n\nBy default, the plugin sorts [side effect imports](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#import_a_module_for_its_side_effects_only) like any other imports in the file. If you need to keep side effect imports in the same place but sort all other imports around them, set this option to false.\n\nExample:\n\nInitial file:\n\n```js\nimport z from 'z'\nimport a from 'a'\n\nimport 'side-effect-lib'\n\nimport c from 'c'\nimport b from 'b'\n```\n\nWhen sorted:\n\n```js\nimport a from 'a'\nimport z from 'z'\n\nimport 'side-effect-lib'\n\nimport b from 'b'\nimport c from 'c'\n```\n\n#### `importOrderImportAttributesKeyword`\n\n**type**: `'assert' | 'with' | 'with-legacy'`\n\nThe import attributes/assertions syntax:\n\n- `with`: `import \"...\" with { type: \"json\" }`\n- `assert`: `import \"...\" assert { type: \"json\" }`\n- `with-legacy`: `import \"...\" with type: \"json\"`.\n\n```json\n  \"importOrderImportAttributesKeyword\": 'with'\n```\n\n_Default behavior:_ When not specified, @babel/generator will try to match the style in the input code based on the AST shape.\n\n#### `importOrderIgnoreHeaderComments`\n\n**type**: `number`\n\n**default value**: `-1`\n\nHow many comments at the start of the code to ignore while attaching comments to imports for sorting.\n\nThis option is useful for projects that use a license header or similar comments at the start of the code, to\nensure that whitespace around header comments is maintained, and header comments are not accidentally associated\nwith the first import and sorted away from the start of the code.\n\nNegative values, including the default value of -1, preserve how this plugin has historically handled comments\nimmediately before the first import statement. When negative, all comments immediately before the first import\nwill be placed at the top of the import list. However, this has limitations:\n\n- Whitespace IS NOT maintained between these comments. If one of the comments is maintained by a linter /\n  formatter, and that tool expects whitespace to be preserved, it may result in conflicts where the code fails\n  to converge.\n- If the first import is sorted further down the list, comments intended to be attached to the first import\n  will not be sorted along with the import.\n\n```\n\"importOrderIgnoreHeaderComments\": 1,\n```\n\n#### `importOrderIgnoreHeaderCommentTypess`\n\n**type**: `'All' | 'CommentBlock' | 'CommentLine'`\n\n**default value**: `'All'`\n\nThe type of comments ignored when using importOrderIgnoreHeaderComments option.\n\nIf an unspecified comment type is encountered while evaluating importOrderIgnoreHeaderComments, it and all\nfollowing comments will be sorted with the first import.\n\n```\n\"importOrderIgnoreHeaderCommentTypes\": \"CommentBlock\",\n```\n\n### Ignoring import ordering\n\nIn some cases it's desired to ignore import ordering, specifically if you require to instantiate a common service or polyfill in your application logic before all the other imports. The plugin supports the `// sort-imports-ignore` comment, which will exclude the file from ordering the imports.\n\n```javascript\n// sort-imports-ignore\nimport './polyfills';\n\nimport foo from 'foo'\n```\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\nAfter, 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 `<THIRD_PARTY_MODULES>` 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| Solid                  | ✅ Everything            | -                                                |\n| Angular                | ✅ Everything            | Supported through `importOrderParserPlugins` API |\n| Vue                    | ✅ Everything            | `@vue/compiler-sfc` is required                  |\n| Svelte                 | ✅ Everything            | `prettier-plugin-svelte` is required             |\n\n### Used by\n\nWant to highlight your project or company ? Adding your project / company name will help plugin to gain attraction and contribution.\nFeel free to make a Pull Request to add your project / company name.\n\n- [trivago](https://company.trivago.com)\n- [AuresKonnect](https://aures.com)\n- [FactorialHR](https://factorialhr.com)\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### Maintainers\n\n| [Ayush Sharma](https://github.com/ayusharma)                             | [Behrang Yarahmadi](https://github.com/byara)                         |\n| ------------------------------------------------------------------------ | --------------------------------------------------------------------- |\n| ![ayusharma](https://avatars2.githubusercontent.com/u/6918450?s=120&v=4) | ![@byara](https://avatars2.githubusercontent.com/u/6979966?s=120&v=4) |\n| [@ayusharma\\_](https://twitter.com/ayusharma_)                           | [@behrang_y](https://twitter.com/behrang_y)                           |\n\n### Disclaimer\n\nThis plugin modifies the AST which is against the rules of prettier.\n","readmeFilename":"README.md"}