{"_id":"@caipira/prettier-plugin-sort-imports","_rev":"2-bb8447971b0fac661b99b9b6ce057dda","name":"@caipira/prettier-plugin-sort-imports","dist-tags":{"latest":"0.0.1"},"versions":{"0.0.0":{"name":"@caipira/prettier-plugin-sort-imports","version":"0.0.0","keywords":["prettier","plugin","sort","import","typescript","javascript"],"author":{"name":"Theone Lucas","email":"theone@caipira.io"},"license":"MIT","_id":"@caipira/prettier-plugin-sort-imports@0.0.0","maintainers":[{"name":"theonelucas","email":"theone@caipira.io"}],"homepage":"https://github.com/caipira-io/prettier-plugin-sort-imports#readme","bugs":{"url":"https://github.com/caipira-io/prettier-plugin-sort-imports/issues"},"ava":{"extensions":["ts"],"nodeArguments":["-r","ts-node/register"]},"dist":{"shasum":"71158635fdaca6879dd655c46df5f14e3b386c1e","tarball":"https://registry.npmjs.org/@caipira/prettier-plugin-sort-imports/-/prettier-plugin-sort-imports-0.0.0.tgz","fileCount":3,"integrity":"sha512-S/o68aiPxUeKhn9tCTCfPZGo0hReTx7whY+6rVuLARu8P2TkytqNVbbKLzosuC413TkUbBW6jKX+WRXfJsQhyg==","signatures":[{"sig":"MEUCIQDtJWG3Cd9Gr7L9z23ox3dm+PZfRmdI9rY54yZNO9tSkAIgGlspA+IQ1QnU2swepxdSURW4r7tFrYB94VUXKUZtt8A=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":28909},"main":"dist/index.js","gitHead":"dc139ff42e5b17b068fd9282c67808d066a29f95","private":false,"scripts":{"test":"bun bundle:dev && ava test/test.ts -- -- --sort-imports-reinit","bundle":"esbuild --bundle --platform=node --external:typescript --external:prettier --outfile=dist/index.js app/index.ts --minify","format":"prettier --write app test","prepack":"bun format && tsc && bun bundle","test:dev":"ava test/test.ts -- -- --dev --sort-imports-reinit","bundle:dev":"esbuild --bundle --platform=node --external:typescript --external:prettier --outfile=dist/index.js app/index.ts","prepublish":"bun prepack","codeGenerationTest":"ts-node -T test/codeGenerationTest.ts --test"},"_npmUser":{"name":"theonelucas","email":"theone@caipira.io"},"repository":{"url":"git+https://github.com/caipira-io/prettier-plugin-sort-imports.git","type":"git"},"_npmVersion":"11.6.2","description":"A prettier plugin for sorting imports in a configurable way.","directories":{},"_nodeVersion":"24.11.1","dependencies":{"prettier":"^3.1.1"},"_hasShrinkwrap":false,"devDependencies":{"ava":"^6.0.1","esbuild":"^0.19.10","ts-node":"^10.9.2","typescript":"^5.3.3","@types/node":"^14.11.2"},"peerDependencies":{"typescript":">4.0.0"},"_npmOperationalInternal":{"tmp":"tmp/prettier-plugin-sort-imports_0.0.0_1780585779106_0.03613697512305536","host":"s3://npm-registry-packages-npm-production"}},"0.0.1":{"name":"@caipira/prettier-plugin-sort-imports","version":"0.0.1","private":false,"description":"A prettier plugin for sorting imports in a configurable way.","main":"dist/index.js","author":{"name":"Theone Lucas","email":"theone@caipira.io"},"repository":{"type":"git","url":"git+https://github.com/caipira-io/prettier-plugin-sort-imports.git"},"license":"MIT","devDependencies":{"@types/node":"^14.11.2","ava":"^6.0.1","esbuild":"^0.19.10","ts-node":"^10.9.2","typescript":"^5.3.3"},"dependencies":{"prettier":"^3.1.1"},"peerDependencies":{"typescript":">4.0.0"},"keywords":["prettier","plugin","sort","import","typescript","javascript"],"scripts":{"prepublishOnly":"npm run prepack","bundle":"esbuild --bundle --platform=node --external:typescript --external:prettier --outfile=dist/index.js app/index.ts --minify","bundle:dev":"esbuild --bundle --platform=node --external:typescript --external:prettier --outfile=dist/index.js app/index.ts","test":"npm run bundle:dev && ava test/test.ts -- -- --sort-imports-reinit","test:dev":"ava test/test.ts -- -- --dev --sort-imports-reinit","prepack":"npm run format && tsc && npm run bundle","format":"prettier --write app test","codeGenerationTest":"ts-node -T test/codeGenerationTest.ts --test"},"ava":{"extensions":["ts"],"nodeArguments":["-r","ts-node/register"]},"gitHead":"fd94eab9092d8106d476a8addef7975c712f2cdc","_id":"@caipira/prettier-plugin-sort-imports@0.0.1","bugs":{"url":"https://github.com/caipira-io/prettier-plugin-sort-imports/issues"},"homepage":"https://github.com/caipira-io/prettier-plugin-sort-imports#readme","_nodeVersion":"24.16.0","_npmVersion":"11.16.0","dist":{"integrity":"sha512-3RIhLDPJ9MeD8s2VnMeEqBYHWufNlVjxCPQbdvDSoSb1JrfUE5TXP71QhYBux48EKo/WvOm2G01tFtFehzQNQg==","shasum":"b3b784adbf16bbb412461532f6416423fab84738","tarball":"https://registry.npmjs.org/@caipira/prettier-plugin-sort-imports/-/prettier-plugin-sort-imports-0.0.1.tgz","fileCount":3,"unpackedSize":28874,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIELQfuKcjmXrBrZGBb/7fHpK7n5oH7Y3Pl67d7aK1hW2AiEAgE2QpGmho9Qx8698HJnItGGny+Fgf4IKdbGyYlhvPk0="}]},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:e51f4ef0-e274-4262-bca6-880d5c4043b5"}},"directories":{},"maintainers":[{"name":"theonelucas","email":"theone@caipira.io"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/prettier-plugin-sort-imports_0.0.1_1780587121169_0.3739329241209033"},"_hasShrinkwrap":false}},"time":{"created":"2026-06-04T15:09:38.974Z","modified":"2026-06-04T15:32:01.448Z","0.0.0":"2026-06-04T15:09:39.262Z","0.0.1":"2026-06-04T15:32:01.331Z"},"bugs":{"url":"https://github.com/caipira-io/prettier-plugin-sort-imports/issues"},"author":{"name":"Theone Lucas","email":"theone@caipira.io"},"license":"MIT","homepage":"https://github.com/caipira-io/prettier-plugin-sort-imports#readme","keywords":["prettier","plugin","sort","import","typescript","javascript"],"repository":{"type":"git","url":"git+https://github.com/caipira-io/prettier-plugin-sort-imports.git"},"description":"A prettier plugin for sorting imports in a configurable way.","maintainers":[{"name":"theonelucas","email":"theone@caipira.io"}],"readme":"# @caipira/prettier-plugin-sort-imports\n\n![NPM Downloads](https://img.shields.io/npm/dt/@caipira/prettier-plugin-sort-imports)\n\nForked from [prettier-plugin-sort-imports](https://github.com/SanderRonde/prettier-plugin-sort-imports).\n\nA [Prettier v3+](https://prettier.io/) plugin for sorting imports in a configurable way:\n\n- Import length or line length sorting\n- Alphabetical sorting\n- Splitting imports into separate statements by kind\n\nExample:\n\n![](./images/transform.png)\n\n## Installation\n\n```sh\n# npm\nnpm install --save-dev @caipira/prettier-plugin-sort-imports\n\n# pnpm\npnpm add -D @caipira/prettier-plugin-sort-imports\n\n# yarn\nyarn add -D @caipira/prettier-plugin-sort-imports\n```\n\n## Quick Start\n\nAdd the plugin to your Prettier config:\n\n```js\n// prettier.config.js\nmodule.exports = {\n\tsortingMethod: 'importLength',\n\tplugins: ['@caipira/prettier-plugin-sort-imports'],\n};\n```\n\n## Option Reference\n\nAll options are Prettier options, so place them in your Prettier config.\n\n| Option                   | Type                                               | Default              | Description                                                                                                      |\n| ------------------------ | -------------------------------------------------- | -------------------- | ---------------------------------------------------------------------------------------------------------------- |\n| `sortingMethod`          | `'lineLength' \\| 'importLength' \\| 'alphabetical'` | `'lineLength'`       | Primary sort metric inside each import group.                                                                    |\n| `sortingOrder`           | `'ascending' \\| 'descending'`                      | `'descending'`       | Reverses sorted output produced by the selected method.                                                          |\n| `stripNewlines`          | `boolean`                                          | `false`              | Merges adjacent import blocks when only whitespace/comments separate them.                                       |\n| `importTypeOrder`        | `IMPORT_TYPE[]`                                    | `['all']`            | Defines group buckets and their group order.                                                                     |\n| `packageJSONFiles`       | `string[]`                                         | `['./package.json']` | Package manifests used to detect npm/dependency imports.                                                         |\n| `newlineBetweenTypes`    | `boolean`                                          | `false`              | Inserts a blank line between non-empty import type groups.                                                       |\n| `splitByImportTypeOrder` | `boolean`                                          | `false`              | Forces grouping by `importTypeOrder`, extracts inline `type` specifiers, and splits groups into separate blocks. |\n\n## Import Type Values\n\n`importTypeOrder` accepts these values:\n\n- `all`: single bucket for all imports (disables type grouping)\n- `NPMPackages`: npm/dependency imports (plus Node built-ins and `bun`)\n- `NPMPackagesType`: type-only npm imports\n- `importsType`: all type-only imports (npm + local)\n- `localImportsValue`: local non-type imports\n- `localImportsType`: local type-only imports\n- `localImports`: all local imports (type + value)\n- `components`: imports ending in `.vue` or `.tsx`\n\n## How Sorting Works\n\nThe plugin runs in this order:\n\n1. Skip file if ignore directive is present.\n2. If enabled, split mixed imports into value import + `import type` import.\n3. Sort specifiers inside multi-line named imports.\n4. Detect import blocks.\n5. Group imports by `importTypeOrder`.\n6. Sort each group by `sortingMethod`/`sortingOrder`.\n7. Rebuild blocks and optional inter-group blank lines.\n\n### 1) `sortingMethod`\n\n#### `lineLength`\n\nSorts by full import statement text length (`import ... from 'x'`).\n\n#### `importLength`\n\nSorts by import clause length (specifier area), not full line length.\n\nExamples:\n\n- `import { a, bb } from 'x'` compares by `{ a, bb }`\n- `import Default from 'x'` compares by `Default`\n- `import type { Foo } from 'x'` compares by `{ Foo }`\n- `import 'x'` has specifier length `0`\n\n#### `alphabetical`\n\nSorts by `moduleSpecifier` string (`'react'`, `'./file'`, etc.).\n\n### 2) `sortingOrder`\n\n`sortingOrder` reverses the result produced by the method sorter.\n\n- For length-based methods, `descending` means longer first, `ascending` means shorter first.\n- For alphabetical, current behavior is legacy: `descending` results in A to Z, and `ascending` results in Z to A.\n\n### 3) `stripNewlines`\n\nWhen `false`, import blocks are split on blank lines.\n\nWhen `true`, blocks separated only by whitespace/comments are merged and sorted together.\n\nCode between imports still keeps blocks separate.\n\n### 4) `importTypeOrder`\n\nDefines grouping buckets and group order. Within each group, normal sorting still applies.\n\n#### Classification precedence\n\nWhen multiple categories could match, classification priority is:\n\n1. `components`\n2. `importsType`\n3. `NPMPackagesType`\n4. `localImportsType`\n5. `NPMPackages`\n6. `localImportsValue`\n7. `localImports`\n\n### 5) `packageJSONFiles`\n\nUsed to detect npm package imports for npm-related buckets.\n\n- reads both `dependencies` and `devDependencies`\n- supports multiple package files\n- absolute paths are respected\n- relative paths are resolved from the nearest Prettier config location (fallback: process cwd)\n- Node built-ins are treated as npm bucket imports\n- `bun` is always treated as a built-in bucket import\n\n### 6) `newlineBetweenTypes`\n\nIf `true`, inserts one blank line between non-empty import groups.\n\n### 7) `splitByImportTypeOrder`\n\nWhen enabled:\n\n- import blocks are effectively merged for grouping (acts like strip-then-regroup)\n- group boundaries follow `importTypeOrder`\n- blank lines are inserted between resulting groups\n- mixed imports are split:\n\n```ts\nimport { Kind, type FieldNode } from './types';\n```\n\nbecomes:\n\n```ts\nimport { Kind } from './types';\nimport type { FieldNode } from './types';\n```\n\n- generated multi-line imports are also passed through specifier sorting\n\n## Multi-Line Specifier Sorting\n\nAll multi-line named imports are sorted internally.\n\n- single-line named imports are not rewritten\n- with `alphabetical`, specifiers sort lexicographically\n- with `lineLength` or `importLength`, specifiers sort by specifier text length (with alphabetical tie-break)\n- `type` prefix is ignored for comparison keys (`type Foo` compares as `Foo`)\n\n## Interaction Rules and Validation\n\nThe plugin validates combinations and throws for invalid setups.\n\n### Rules\n\n1. `['all']` must be alone.\n2. `localImports` cannot be combined with `localImportsValue` or `localImportsType`.\n3. If you use legacy local split (`localImportsValue`/`localImportsType`) without `importsType` or `NPMPackagesType`, both value and type options must be present together.\n4. `importsType` cannot be combined with `localImportsType` or `NPMPackagesType`.\n5. If you use one of `localImports`, `localImportsValue`, or `localImportsType`, you must also include at least one npm bucket (`NPMPackages` or `NPMPackagesType`).\n\n### Valid examples\n\n```json\n{\n\t\"importTypeOrder\": [\"all\"]\n}\n```\n\n```json\n{\n\t\"importTypeOrder\": [\"NPMPackages\", \"localImports\"]\n}\n```\n\n```json\n{\n\t\"importTypeOrder\": [\n\t\t\"NPMPackagesType\",\n\t\t\"localImportsType\",\n\t\t\"NPMPackages\",\n\t\t\"localImportsValue\"\n\t]\n}\n```\n\n```json\n{\n\t\"importTypeOrder\": [\n\t\t\"importsType\",\n\t\t\"NPMPackages\",\n\t\t\"localImports\",\n\t\t\"components\"\n\t]\n}\n```\n\n### Invalid examples\n\n```json\n{\n\t\"importTypeOrder\": [\"all\", \"NPMPackages\"]\n}\n```\n\n```json\n{\n\t\"importTypeOrder\": [\"importsType\", \"localImportsType\", \"NPMPackages\"]\n}\n```\n\n```json\n{\n\t\"importTypeOrder\": [\"localImportsType\", \"NPMPackages\"]\n}\n```\n\n## Recommended Configurations\n\n### A) Minimal, stable behavior\n\n```json\n{\n\t\"sortingMethod\": \"lineLength\",\n\t\"sortingOrder\": \"descending\",\n\t\"importTypeOrder\": [\"all\"]\n}\n```\n\n### B) NPM first, local second\n\n```json\n{\n\t\"sortingMethod\": \"alphabetical\",\n\t\"sortingOrder\": \"descending\",\n\t\"importTypeOrder\": [\"NPMPackages\", \"localImports\"],\n\t\"newlineBetweenTypes\": true\n}\n```\n\n### C) Strict type/value grouping with splitting\n\n```json\n{\n\t\"sortingMethod\": \"importLength\",\n\t\"sortingOrder\": \"ascending\",\n\t\"importTypeOrder\": [\n\t\t\"importsType\",\n\t\t\"NPMPackages\",\n\t\t\"localImportsValue\",\n\t\t\"components\"\n\t],\n\t\"splitByImportTypeOrder\": true,\n\t\"newlineBetweenTypes\": true\n}\n```\n\n### D) Monorepo package detection\n\n```json\n{\n\t\"importTypeOrder\": [\"NPMPackages\", \"localImports\"],\n\t\"packageJSONFiles\": [\n\t\t\"./package.json\",\n\t\t\"./packages/app/package.json\",\n\t\t\"./packages/ui/package.json\"\n\t]\n}\n```\n\n## Ignore Controls\n\nSkip an entire file:\n\n```ts\n// sort-imports-ignore\n```\n\nSkip a range:\n\n```ts\n// sort-imports-begin-ignore\n// ...imports or code here...\n// sort-imports-end-ignore\n```\n\nNotes:\n\n- begin/end ignore markers must be balanced\n- unmatched markers skip sorting for the file and print a warning\n\n## Compatibility issues with other plugins\n\nWhen combined with other plugins that make use of private Prettier APIs (for example `prettier-plugin-tailwindcss`), you will need combine them into a single plugin:\n\n```ts\n// prettier.config.js:\nconst pluginTailwindcss = require('prettier-plugin-tailwindcss');\nconst pluginSortImports = require('@caipira/prettier-plugin-sort-imports');\n\nasync function parseWithTailwindTypescript(...args) {\n\tconst tsParser = pluginTailwindcss.parsers.typescript;\n\n\tif (tsParser && typeof tsParser.parse === 'function') {\n\t\treturn tsParser.parse(...args);\n\t}\n\n\tif (typeof tsParser === 'function') {\n\t\ttry {\n\t\t\tconst maybeParser = await tsParser();\n\t\t\tif (maybeParser && typeof maybeParser.parse === 'function') {\n\t\t\t\treturn maybeParser.parse(...args);\n\t\t\t}\n\t\t} catch (_err) {}\n\n\t\treturn tsParser(...args);\n\t}\n}\n\n/** @type {import(\"prettier\").Plugin}  */\nconst plugin = {\n\toptions: pluginSortImports.options,\n\tparsers: {\n\t\ttypescript: {\n\t\t\t...pluginSortImports.parsers.typescript,\n\t\t\tparse: parseWithTailwindTypescript,\n\t\t},\n\t},\n};\n\nmodule.exports = {\n\tplugins: [plugin],\n\n\t// Your prettier options\n\tarrowParens: 'always',\n\tbracketSpacing: true,\n\tprintWidth: 90,\n\tsemi: true,\n\ttabWidth: 4,\n\tsingleQuote: true,\n\tuseTabs: false,\n\ttrailingComma: 'es5',\n\tvueIndentScriptAndStyle: false,\n\tsingleAttributePerLine: true,\n\n\t// Options for @caipira/prettier-plugin-sort-imports\n\tsortingMethod: 'importLength',\n\tsortingOrder: 'ascending',\n\timportTypeOrder: [\n\t\t'importsType',\n\t\t'NPMPackages',\n\t\t'localImportsValue',\n\t\t'components',\n\t],\n\tsplitByImportTypeOrder: true,\n\tnewlineBetweenTypes: true,\n};\n```\n","readmeFilename":"README.md"}