### Run Example in Repository Source: https://github.com/trivago/prettier-plugin-sort-imports/blob/main/docs/DEBUG.md Execute an example file within the repository using yarn. Ensure you have the necessary dependencies installed. ```shell yarn run example examples/example.ts --config .prettierrc ``` -------------------------------- ### Installation Source: https://github.com/trivago/prettier-plugin-sort-imports/blob/main/README.md Instructions for installing the prettier-plugin-sort-imports using various package managers. ```APIDOC ## Installation ### Using npm ```shell script npm install --save-dev @trivago/prettier-plugin-sort-imports ``` ### Using yarn ```shell script yarn add --dev @trivago/prettier-plugin-sort-imports ``` ### Using pnpm ```shell script pnpm add -D @trivago/prettier-plugin-sort-imports ``` **Note:** If formatting `.vue` sfc files please install `@vue/compiler-sfc` if not in your dependency tree - this normally is within Vue projects. ``` -------------------------------- ### Vue Single-File Component Example Source: https://context7.com/trivago/prettier-plugin-sort-imports/llms.txt A Vue single-file component demonstrating import usage within a script setup block. ```vue ``` -------------------------------- ### Install Prettier Plugin Sort Imports Source: https://context7.com/trivago/prettier-plugin-sort-imports/llms.txt Install the plugin as a dev dependency using npm, yarn, or pnpm. ```bash # Using npm npm install --save-dev @trivago/prettier-plugin-sort-imports ``` ```bash # Using yarn yarn add --dev @trivago/prettier-plugin-sort-imports ``` ```bash # Using pnpm pnpm add -D @trivago/prettier-plugin-sort-imports ``` -------------------------------- ### Example Output Imports Source: https://github.com/trivago/prettier-plugin-sort-imports/blob/main/README.md Illustrates the sorted order of import declarations after applying the plugin. ```javascript import { debounce, reduce } from 'lodash-es'; import React, { ChangeEvent, FC, KeyboardEvent, useEffect, useRef, } from 'react'; import { createConnection } from '@server/database'; import { createServer } from '@server/node'; import { initializeApp } from '@core/app'; import { logger } from '@core/logger'; import { Alert } from '@ui/Alert'; import { Popup } from '@ui/Popup'; import { Message } from '../Message'; import { add, filter, repeat } from '../utils'; ``` -------------------------------- ### Install Prettier Plugin with pnpm Source: https://github.com/trivago/prettier-plugin-sort-imports/blob/main/README.md Use this command to install the prettier-plugin-sort-imports as a development dependency using pnpm. ```shell pnpm add -D @trivago/prettier-plugin-sort-imports ``` -------------------------------- ### Install Prettier Plugin with npm Source: https://github.com/trivago/prettier-plugin-sort-imports/blob/main/README.md Use this command to install the prettier-plugin-sort-imports as a development dependency using npm. ```shell npm install --save-dev @trivago/prettier-plugin-sort-imports ``` -------------------------------- ### Example Input Imports Source: https://github.com/trivago/prettier-plugin-sort-imports/blob/main/README.md Shows the original order of import declarations before sorting. ```javascript import React, { FC, useEffect, useRef, ChangeEvent, KeyboardEvent, } from 'react'; import { logger } from '@core/logger'; import { reduce, debounce } from 'lodash-es'; import { Message } from '../Message'; import { createServer } from '@server/node'; import { Alert } from '@ui/Alert'; import { repeat, filter, add } from '../utils'; import { initializeApp } from '@core/app'; import { Popup } from '@ui/Popup'; import { createConnection } from '@server/database'; ``` -------------------------------- ### Import Order Regex Example Source: https://github.com/trivago/prettier-plugin-sort-imports/blob/main/README.md Example of defining a custom import order using regular expressions. The plugin sorts third-party modules not matching the regex to the top by default. ```json "importOrder": ["^@core/(.*)$", "^@server/(.*)$", "^@ui/(.*)$", "^[./]"] ``` -------------------------------- ### Import Sorting Example (JavaScript) Source: https://context7.com/trivago/prettier-plugin-sort-imports/llms.txt Demonstrates the input and output of import sorting for a JavaScript file using the plugin. ```javascript // Input import { createServer } from '@server/node'; import React, { useState, useEffect, FC } from 'react'; import { logger } from '@core/logger'; import * as utils from './utils'; import fs from 'node:fs'; import { debounce, throttle } from 'lodash-es'; import { Button } from '@ui/Button'; import { Message } from '../Message'; import path from 'path'; import ReactDOM from 'react-dom'; import { config } from '@company/config'; // Output import fs from 'node:fs'; import path from 'path'; import React, { FC, useEffect, useState } from 'react'; import ReactDOM from 'react-dom'; import { debounce, throttle } from 'lodash-es'; import { config } from '@company/config'; import { logger } from '@core/logger'; import { createServer } from '@server/node'; import { Button } from '@ui/Button'; import { Message } from '../Message'; import * as utils from './utils'; ``` -------------------------------- ### Install Prettier Plugin with Yarn Source: https://github.com/trivago/prettier-plugin-sort-imports/blob/main/README.md Use this command to install the prettier-plugin-sort-imports as a development dependency using Yarn. ```shell yarn add --dev @trivago/prettier-plugin-sort-imports ``` -------------------------------- ### Run Prettier in Any Codebase Source: https://github.com/trivago/prettier-plugin-sort-imports/blob/main/docs/DEBUG.md After installing the plugin, use this command to format TypeScript and JavaScript files across your project. Ensure Prettier is installed in your project. ```shell ./node_modules/.bin/prettier --write '**/*.{ts,tsx,js}' ``` -------------------------------- ### Svelte Component Example Source: https://context7.com/trivago/prettier-plugin-sort-imports/llms.txt A Svelte component demonstrating import usage within a script block. ```svelte ``` -------------------------------- ### Sort Imports with importOrder Configuration Source: https://context7.com/trivago/prettier-plugin-sort-imports/llms.txt Example demonstrating how the `importOrder` configuration sorts imports. Third-party modules not matching any regex are placed at the top by default. ```javascript // Input import React from 'react'; import { logger } from '@core/logger'; import { debounce } from 'lodash-es'; import { Message } from '../Message'; import { createServer } from '@server/node'; import { Alert } from '@ui/Alert'; import { initializeApp } from '@core/app'; ``` ```javascript // Output import { debounce } from 'lodash-es'; import React from 'react'; import { initializeApp } from '@core/app'; import { logger } from '@core/logger'; import { createServer } from '@server/node'; import { Alert } from '@ui/Alert'; import { Message } from '../Message'; ``` -------------------------------- ### Svelte Support Configuration Source: https://context7.com/trivago/prettier-plugin-sort-imports/llms.txt Configuration for enabling Svelte support. Requires installing 'prettier-plugin-svelte' and 'svelte' peer dependencies. ```json // Svelte support - install prettier-plugin-svelte and svelte { "plugins": ["prettier-plugin-svelte", "@trivago/prettier-plugin-sort-imports"] } ``` -------------------------------- ### Sort Imports with BUILTIN_MODULES Placeholder Source: https://context7.com/trivago/prettier-plugin-sort-imports/llms.txt Example demonstrating the use of the `` placeholder to group Node.js built-in modules at the beginning of the import order. ```javascript // Input import { join } from 'path'; import React from 'react'; import fs from 'node:fs'; import { logger } from '@core/logger'; import { helper } from './helper'; ``` ```javascript // Output import fs from 'node:fs'; import { join } from 'path'; import React from 'react'; import { logger } from '@core/logger'; import { helper } from './helper'; ``` -------------------------------- ### Vue Support Configuration Source: https://context7.com/trivago/prettier-plugin-sort-imports/llms.txt Configuration for enabling Vue single-file component support. Requires installing the '@vue/compiler-sfc' peer dependency. ```json // Vue support - install @vue/compiler-sfc { "plugins": ["@trivago/prettier-plugin-sort-imports"] } ``` -------------------------------- ### Sort Imports with THIRD_PARTY_MODULES Placeholder Source: https://context7.com/trivago/prettier-plugin-sort-imports/llms.txt Example showing how the `` placeholder affects the import order, placing specified third-party modules in a designated section. ```javascript // Input import thirdPartyTwo from 'third-party-2'; import otherthing from '@core/otherthing'; import thirdPartyOne from 'third-party-1'; import component from '@ui/hello'; import sameLevelRelativePath from './sameLevelRelativePath'; ``` ```javascript // Output import otherthing from '@core/otherthing'; import thirdPartyOne from 'third-party-1'; import thirdPartyTwo from 'third-party-2'; import component from '@ui/hello'; import sameLevelRelativePath from './sameLevelRelativePath'; ``` -------------------------------- ### Import Group Separation Example Source: https://context7.com/trivago/prettier-plugin-sort-imports/llms.txt Illustrates the effect of `importOrderSeparation: true` by showing the output with blank lines between import groups, compared to the default behavior. ```javascript // Input import { logger } from '@core/logger'; import React from 'react'; import { createServer } from '@server/node'; import { Message } from './Message'; ``` ```javascript // Output (with importOrderSeparation: true) import React from 'react'; import { logger } from '@core/logger'; import { createServer } from '@server/node'; import { Message } from './Message'; ``` ```javascript // Output (with importOrderSeparation: false) import React from 'react'; import { logger } from '@core/logger'; import { createServer } from '@server/node'; import { Message } from './Message'; ``` -------------------------------- ### Case-Insensitive Sorting Example Source: https://github.com/trivago/prettier-plugin-sort-imports/blob/main/README.md Demonstrates the effect of 'importOrderCaseInsensitive: true' on import sorting. Without it, 'ExampleView' would precede 'ExamplesList'. With it, 'ExamplesList' comes first. ```ecmascript 6 import ExampleView from './ExampleView'; import ExamplesList from './ExamplesList'; ``` ```ecmascript 6 import ExamplesList from './ExamplesList'; import ExampleView from './ExampleView'; ``` -------------------------------- ### Sort Specifiers within Imports Example Source: https://context7.com/trivago/prettier-plugin-sort-imports/llms.txt Demonstrates the effect of `importOrderSortSpecifiers: true` by showing the output with alphabetically sorted named imports within each declaration. ```javascript // Input import React, { FC, useEffect, useRef, ChangeEvent, KeyboardEvent, } from 'react'; import { reduce, debounce } from 'lodash-es'; import { repeat, filter, add } from './utils'; ``` ```javascript // Output import React, { ChangeEvent, FC, KeyboardEvent, useEffect, useRef, } from 'react'; import { debounce, reduce } from 'lodash-es'; import { add, filter, repeat } from './utils'; ``` -------------------------------- ### Place Third Party Modules in Imports Source: https://github.com/trivago/prettier-plugin-sort-imports/blob/main/docs/MIGRATION.md Use the `` special word within the `importOrder` configuration to specify the desired location for third-party imports. This example demonstrates placing them after core imports and before UI imports. ```javascript module.exports = { "importOrder": ["^@core/(.*)$", "", "^@ui/(.*)$", "^[./]"] } ``` ```typescript import threeLevelRelativePath from '../../../threeLevelRelativePath'; import sameLevelRelativePath from './sameLevelRelativePath'; import thirdPartyTwo from 'third-party-2'; import otherthing from '@core/otherthing'; import thirdPartyOne from 'third-party-1'; import twoLevelRelativePath from '../../twoLevelRelativePath'; import component from '@ui/hello'; import thirdPartyThree from 'third-party-3'; ``` ```typescript import otherthing from '@core/otherthing'; import thirdPartyOne from 'third-party-1'; import thirdPartyTwo from 'third-party-2'; import thirdPartyThree from 'third-party-3'; import component from '@ui/hello'; import threeLevelRelativePath from '../../../threeLevelRelativePath'; import twoLevelRelativePath from '../../twoLevelRelativePath'; import sameLevelRelativePath from './sameLevelRelativePath'; ``` -------------------------------- ### Define RegEx for Custom Import Order Source: https://github.com/trivago/prettier-plugin-sort-imports/blob/main/docs/TROUBLESHOOTING.md Use regular expressions within `importOrder` to group and sort imports based on patterns. This example shows how to sort UI, server, and local imports. ```ecmascript 6 import React from 'react'; import classnames from 'classnames'; import z from '@server/z'; import a from '@server/a'; import s from './'; import p from '@ui/p'; import q from '@ui/q'; ``` ```ecmascript 6 import classnames from 'classnames'; import React from 'react'; import p from '@ui/p'; import q from '@ui/q'; import a from '@server/a'; import z from '@server/z'; import s from './'; ``` -------------------------------- ### Configure Parser Plugins for Experimental Syntax Source: https://github.com/trivago/prettier-plugin-sort-imports/blob/main/docs/TROUBLESHOOTING.md When encountering errors related to experimental syntax, specify necessary parser plugins in the `.prettierrc` configuration file using the `importOrderParserPlugins` option. ```shell script SyntaxError: This experimental syntax requires enabling one of the following parser plugin(s): ... ``` -------------------------------- ### Configuration Source: https://github.com/trivago/prettier-plugin-sort-imports/blob/main/README.md Configuration options for the prettier-plugin-sort-imports in your Prettier config file. ```APIDOC ## Configuration Add an order in prettier config file. ```ecmascript 6 module.exports = { "printWidth": 80, "tabWidth": 4, "trailingComma": "all", "singleQuote": true, "semi": true, "importOrder": ["^@core/(.*)$", "^@server/(.*)$", "^@ui/(.*)$", "^[./]"], "importOrderSeparation": true, "importOrderSortSpecifiers": true } ``` **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. ```js module.exports = { ... "plugins": ["@trivago/prettier-plugin-sort-imports"] } ``` ``` -------------------------------- ### Configure Import Attributes Keyword Source: https://context7.com/trivago/prettier-plugin-sort-imports/llms.txt Specifies the syntax for import attributes/assertions. Options are 'with', 'assert', or 'with-legacy'. Default behavior matches input style. ```json { "importOrderImportAttributesKeyword": "with" } ``` ```javascript // With "with" keyword import config from './config.json' with { type: 'json' }; // With "assert" keyword import config from './config.json' assert { type: 'json' }; // With "with-legacy" keyword import config from './config.json' with type: 'json'; ``` -------------------------------- ### API Options Source: https://github.com/trivago/prettier-plugin-sort-imports/blob/main/README.md Detailed explanation of the configuration options available for the plugin. ```APIDOC ## API Options ### `importOrder` **type**: `Array` A collection of Regular expressions in string format. ``` "importOrder": ["^@core/(.*)$", "^@server/(.*)$", "^@ui/(.*)$", "^[./]"], ``` _Default behavior:_ 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 `` to assign third party imports to the appropriate position: ``` "importOrder": ["^@core/(.*)$", "", "^@server/(.*)$", "^@ui/(.*)$", "^[./]"], ``` You can also use `` to control the position of Node.js builtin modules (like `fs`, `path`, `http`, and their `node:` prefixed variants): ``` "importOrder": ["", "", "^@core/(.*)$", "^@server/(.*)$", "^@ui/(.*)$", "^[./]"], ``` When `` is included in your `importOrder`, Node.js builtin modules will be sorted to that position. If not included, builtin modules are treated as regular third-party imports. ### `importOrderSeparation` **type**: `boolean` **default value**: `false` A boolean value to enable or disable the new line separation between sorted import declarations group. The separation takes place according to the `importOrder`. ``` "importOrderSeparation": true, ``` If this option is enabled and `` is used in the `importOrder` array, the plugin will ONLY add newlines at those locations and at the end of the imports. ### `importOrderSortSpecifiers` **type**: `boolean` **default value:** `false` A boolean value to enable or disable sorting of the specifiers in an import declarations. ### `importOrderGroupNamespaceSpecifiers` **type**: `boolean` **default value:** `false` A boolean value to enable or disable sorting the namespace specifiers to the top of the import group. ### `importOrderCaseInsensitive` **type**: `boolean` **default value**: `false` A boolean value to enable case-insensitivity in the sorting algorithm used to order imports within each match group. For example, when false (or not specified): ```ecmascript 6 import ExampleView from './ExampleView'; import ExamplesList from './ExamplesList'; ``` compared with `"importOrderCaseInsensitive": true`: ```ecmascript 6 import ExamplesList from './ExamplesList'; import ExampleView from './ExampleView'; ``` ``` -------------------------------- ### Use `` for Flexible Import Ordering Source: https://github.com/trivago/prettier-plugin-sort-imports/blob/main/docs/TROUBLESHOOTING.md Employ the `` placeholder in `importOrder` to dynamically place third-party modules like React and classnames without hardcoding their exact positions relative to other groups. ```ecmascript 6 import p from '@ui/p'; import q from '@ui/q'; import a from '@server/a'; import z from '@server/z'; import classnames from 'classnames'; import React from 'react'; import s from './'; ``` -------------------------------- ### Complete .prettierrc Configuration Source: https://context7.com/trivago/prettier-plugin-sort-imports/llms.txt A comprehensive .prettierrc configuration for React/TypeScript projects, demonstrating all available options for import sorting. ```json { "printWidth": 80, "tabWidth": 4, "trailingComma": "all", "singleQuote": true, "semi": true, "importOrder": [ "", "^react$", "^react-dom$", "", "^@company/(.*)$", "^@core/(.*)$", "^@server/(.*)$", "^@ui/(.*)$", "^[./]" ], "importOrderSeparation": true, "importOrderSortSpecifiers": true, "importOrderCaseInsensitive": true, "importOrderGroupNamespaceSpecifiers": true, "plugins": ["@trivago/prettier-plugin-sort-imports"] } ``` -------------------------------- ### Manually Load Plugin with pnpm Source: https://github.com/trivago/prettier-plugin-sort-imports/blob/main/docs/TROUBLESHOOTING.md If the plugin is not automatically loaded with pnpm, explicitly configure it in your Prettier settings. ```js module.exports = { plugins: ['@trivago/prettier-plugin-sort-imports'], } ``` -------------------------------- ### Configure Babel Parser Plugins with Options Source: https://github.com/trivago/prettier-plugin-sort-imports/blob/main/README.md Pass plugins with options to the Babel parser by providing a JSON string of the plugin array. This allows for detailed configuration of parser plugins. ```json "importOrderParserPlugins" : ["classProperties", "[\"decorators\", { \"decoratorsBeforeExport\": true }]"] ``` -------------------------------- ### Configure Import Order Parser Plugins Source: https://github.com/trivago/prettier-plugin-sort-imports/blob/main/docs/MIGRATION.md Pass options to Babel parser plugins using the `importOrderParserPlugins` option in your Prettier configuration. This replaces the older `experimentalBabelParserPluginsList`. ```javascript module.exports = { "importOrderParserPlugins": ["@babel/plugin-syntax-typescript", "@babel/plugin-syntax-jsx"] } ``` -------------------------------- ### Configure Babel Parser Plugins Source: https://github.com/trivago/prettier-plugin-sort-imports/blob/main/README.md Specify plugins for the Babel parser to understand specific syntaxes. This list is passed directly to the Babel parser. ```json "importOrderParserPlugins" : ["classProperties", "decorators-legacy"] ``` -------------------------------- ### Control Third-Party Module Placement with THIRD_PARTY_MODULES Source: https://context7.com/trivago/prettier-plugin-sort-imports/llms.txt Use the `` placeholder in `importOrder` to control where third-party packages are placed in the import order. ```json { "importOrder": ["^@core/(.*)$", "", "^@server/(.*)$", "^@ui/(.*)$", "^[./]"] } ``` -------------------------------- ### Add Plugin to Prettier Configuration Source: https://github.com/trivago/prettier-plugin-sort-imports/blob/main/README.md Include the plugin in your Prettier configuration to enable its functionality. This is particularly useful when facing issues with certain package managers or Prettier versions. ```js module.exports = { ... "plugins": ["@trivago/prettier-plugin-sort-imports"] } ``` -------------------------------- ### Debug Plugin with Node Debugger Source: https://github.com/trivago/prettier-plugin-sort-imports/blob/main/docs/DEBUG.md Compile the plugin and then run Prettier with the Node.js inspector enabled. Set breakpoints in the plugin code to step through execution. ```shell yarn run compile && node --inspect-brk ./node_modules/.bin/prettier --config .prettierrc --plugin lib/src/index.js examples/example.ts ``` -------------------------------- ### Prettier Configuration with Import Order Source: https://github.com/trivago/prettier-plugin-sort-imports/blob/main/README.md Configure Prettier to sort imports using the 'importOrder' and 'importOrderSeparation' options. Ensure 'importOrderSortSpecifiers' is also set to true for specifier sorting. ```ecmascript 6 module.exports = { "printWidth": 80, "tabWidth": 4, "trailingComma": "all", "singleQuote": true, "semi": true, "importOrder": ["^@core/(.*)$", "^@server/(.*)$", "^@ui/(.*)$", "^[./]"], "importOrderSeparation": true, "importOrderSortSpecifiers": true } ``` -------------------------------- ### Sort Imports by Length Source: https://github.com/trivago/prettier-plugin-sort-imports/blob/main/README.md Enable sorting of imports within their groups based on string length. Set to 'asc' for ascending or 'desc' for descending order. Null or blank ignores length. ```json "importOrderSortByLength": "asc" ``` -------------------------------- ### Control Built-in Module Placement with BUILTIN_MODULES Source: https://context7.com/trivago/prettier-plugin-sort-imports/llms.txt Use the `` placeholder to control the position of Node.js builtin modules in the import order. ```json { "importOrder": ["", "", "^@core/(.*)$", "^[./]"] } ``` -------------------------------- ### Import Order with Built-in Modules Placeholder Source: https://github.com/trivago/prettier-plugin-sort-imports/blob/main/README.md Use the '' placeholder to explicitly control the sorting position of Node.js built-in modules. If omitted, they are treated as regular third-party imports. ```json "importOrder": ["", "", "^@core/(.*)$", "^@server/(.*)$", "^@ui/(.*)$", "^[./]"] ``` -------------------------------- ### Sort Imports by String Length Source: https://context7.com/trivago/prettier-plugin-sort-imports/llms.txt Sorts imports within their groups by string length. Options are 'asc' (shortest to longest), 'desc' (longest to shortest), or null (disabled). Default is null. ```json { "importOrderSortByLength": "asc" } ``` ```javascript // Input import { createConnection } from '@server/database'; import { createServer } from '@server/node'; import { api } from '@server/api'; // Output (importOrderSortByLength: "asc") import { api } from '@server/api'; import { createServer } from '@server/node'; import { createConnection } from '@server/database'; // Output (importOrderSortByLength: "desc") import { createConnection } from '@server/database'; import { createServer } from '@server/node'; import { api } from '@server/api'; ``` -------------------------------- ### Configure importOrder Source: https://context7.com/trivago/prettier-plugin-sort-imports/llms.txt Define the order of import groups using an array of Regular Expression patterns. Imports matching earlier patterns appear before those matching later patterns. Third-party imports not matching any pattern are placed at the top by default. ```json { "importOrder": ["^@core/(.*)$", "^@server/(.*)$", "^@ui/(.*)$", "^[./]"] } ``` -------------------------------- ### Enable Case-Insensitive Import Sorting Source: https://context7.com/trivago/prettier-plugin-sort-imports/llms.txt When true, performs case-insensitive sorting of imports. Default is false. ```json { "importOrderCaseInsensitive": true } ``` ```javascript // Input (case-sensitive, default) import ExampleView from './ExampleView'; import ExamplesList from './ExamplesList'; // Output (importOrderCaseInsensitive: false - default) import ExampleView from './ExampleView'; import ExamplesList from './ExamplesList'; // Output (importOrderCaseInsensitive: true) import ExamplesList from './ExamplesList'; import ExampleView from './ExampleView'; ``` -------------------------------- ### Specify Babel Parser Plugins Source: https://context7.com/trivago/prettier-plugin-sort-imports/llms.txt Specifies Babel parser plugins to enable parsing of experimental or specialized syntax. Default is ["typescript", "jsx"]. ```json { "importOrderParserPlugins": ["typescript", "jsx", "decorators-legacy", "classProperties"] } ``` ```javascript // With decorators support import { Component } from '@angular/core'; import { Injectable } from '@angular/core'; @Component({ selector: 'app-root', template: '

Hello

' }) export class AppComponent {} ``` ```json // Passing options to babel plugins { "importOrderParserPlugins": [ "typescript", "jsx", "[\"decorators\", { \"decoratorsBeforeExport\": true }]" ] } ``` -------------------------------- ### Enable Import Group Separation with importOrderSeparation Source: https://context7.com/trivago/prettier-plugin-sort-imports/llms.txt When set to `true`, adds a blank line between each import group defined by `importOrder`. Default is `false`. ```json { "importOrder": ["^@core/(.*)$", "^@server/(.*)$", "^[./]"], "importOrderSeparation": true } ``` -------------------------------- ### Enable Case-Insensitive Import Sorting Source: https://github.com/trivago/prettier-plugin-sort-imports/blob/main/README.md Set 'importOrderCaseInsensitive' to true to perform case-insensitive sorting of imports within each matched group. This ensures consistent ordering regardless of capitalization. ```json "importOrderCaseInsensitive": true ``` -------------------------------- ### Ignore Import Ordering Source: https://github.com/trivago/prettier-plugin-sort-imports/blob/main/README.md Use the `// sort-imports-ignore` comment to exclude a file from import ordering. This is useful for files that require specific import arrangements, like polyfills. ```javascript // sort-imports-ignore import './polyfills'; import foo from 'foo' ``` -------------------------------- ### Enable Sorting of Namespace Specifiers Source: https://github.com/trivago/prettier-plugin-sort-imports/blob/main/README.md Set 'importOrderGroupNamespaceSpecifiers' to true to sort namespace specifiers (e.g., `import * as React from 'react'`) to the top of their respective import groups. ```json "importOrderGroupNamespaceSpecifiers": true ``` -------------------------------- ### Ignore Files from Import Sorting Source: https://context7.com/trivago/prettier-plugin-sort-imports/llms.txt Add the `// sort-imports-ignore` comment at the top of a file to prevent the plugin from sorting imports. Useful for files requiring specific import order for side effects. ```javascript // sort-imports-ignore import './polyfills'; // Must run first import './environment-setup'; import b from 'b'; import a from 'a'; // Will NOT be sorted function init() { // Application code } ``` -------------------------------- ### Enable Newline Separation for Import Groups Source: https://github.com/trivago/prettier-plugin-sort-imports/blob/main/README.md Set 'importOrderSeparation' to true to enable newline separation between groups of imports defined by the 'importOrder' configuration. This enhances readability. ```json "importOrderSeparation": true ``` -------------------------------- ### Ignore Specific Imports with a Comment Source: https://github.com/trivago/prettier-plugin-sort-imports/blob/main/docs/TROUBLESHOOTING.md Add the `// sort-imports-ignore` comment at the top of a file to prevent the plugin from reordering any import statements within that file. ```plaintext // sort-imports-ignore ``` -------------------------------- ### Preserve First Comment and Remove Extra Newlines Source: https://github.com/trivago/prettier-plugin-sort-imports/blob/main/docs/TROUBLESHOOTING.md The plugin retains the initial file comment and removes extraneous blank lines between it and the first import statement. ```js // comment import a from 'a'; ``` ```js // comment import a from 'a'; ``` -------------------------------- ### Handle Side Effect Imports Source: https://github.com/trivago/prettier-plugin-sort-imports/blob/main/README.md Control the sorting of side effect imports. By default, they are sorted with other imports. Setting to `false` keeps them in place while sorting others. ```javascript import z from 'z' import a from 'a' import 'side-effect-lib' c from 'c' b from 'b' ``` -------------------------------- ### Group Namespace Specifiers in Imports Source: https://context7.com/trivago/prettier-plugin-sort-imports/llms.txt When true, groups namespace specifiers (`* as name`) at the top of their import group. Default is false. ```json { "importOrderGroupNamespaceSpecifiers": true } ``` -------------------------------- ### Disable Default Babel Parser Plugins Source: https://github.com/trivago/prettier-plugin-sort-imports/blob/main/README.md To disable all default plugins for the Babel parser, pass an empty array to `importOrderParserPlugins`. ```json importOrderParserPlugins: [] ``` -------------------------------- ### Enable Specifier Sorting with importOrderSortSpecifiers Source: https://context7.com/trivago/prettier-plugin-sort-imports/llms.txt When set to `true`, sorts the named imports (specifiers) within each import declaration alphabetically. Default is `false`. ```json { "importOrderSortSpecifiers": true } ``` -------------------------------- ### Debug Unit Tests with Node Debugger Source: https://github.com/trivago/prettier-plugin-sort-imports/blob/main/docs/DEBUG.md Run Jest unit tests with the Node.js inspector enabled to debug test failures or logic. This allows setting breakpoints within your test files. ```shell node --inspect-brk ./node_modules/.bin/jest -i ``` ```shell node --inspect-brk ./node_modules/.bin/jest -i ``` -------------------------------- ### Control Side-Effect Import Sorting Source: https://context7.com/trivago/prettier-plugin-sort-imports/llms.txt When false, side-effect imports (imports without specifiers) maintain their original position while other imports are sorted around them. Default is true. ```json { "importOrderSideEffects": false } ``` ```javascript // Input import z from 'z'; import a from 'a'; import 'side-effect-lib'; import c from 'c'; import b from 'b'; // Output (importOrderSideEffects: false) import a from 'a'; import z from 'z'; import 'side-effect-lib'; import b from 'b'; import c from 'c'; // Output (importOrderSideEffects: true - default) import 'side-effect-lib'; import a from 'a'; import b from 'b'; import c from 'c'; import z from 'z'; ``` -------------------------------- ### Sort Import Specifiers Source: https://github.com/trivago/prettier-plugin-sort-imports/blob/main/docs/MIGRATION.md Enable sorting of import specifiers within an import declaration by setting the `importOrderSortSpecifiers` flag to true. This sorts the identifiers alphabetically. ```typescript import { a, d, c, b } from 'some-package' ``` ```typescript import { a, b, c, d } from 'some-package' ``` -------------------------------- ### Remove Inline Comments from Import Declarations Source: https://github.com/trivago/prettier-plugin-sort-imports/blob/main/docs/TROUBLESHOOTING.md Inline comments on import statements are removed due to Babel's comment handling mechanisms. ```js import a from 'a'; // comment ``` ```js import a from 'a'; ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.