From 135b6e55d710df32c3a23c7fe266a04e1eb0c2c1 Mon Sep 17 00:00:00 2001 From: ADTC Date: Mon, 25 Mar 2024 20:27:27 +0800 Subject: [PATCH] Update README to show more options for disabling and overrides (#165) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The new feature of disabling with empty array can do more than just disabling globally and enabling for certain folders or files. It can do the opposite: enabling globally and disabling for certain folders or files. It can also do sort order overrides, where a different order applies to certain folders and files instead of the global order. Feel free to suggest a rewrite of the text if needed. 🙂 I have used the reverse configuration in an actual project and it works well: ```jsonc // .prettierrc { "plugins": ["@ianvs/prettier-plugin-sort-imports"], "overrides": [ { "files": "please/doNot/sortThis.ts", "options": { "importOrder": [] // disabled } } ], "importOrder": [ /* global order here */ ] //... } ``` Tip: The `overrides` order can come before or after the global `importOrder`. It doesn't matter as Prettier will always apply the override regardless of where it is in `.prettierrc`. --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d352520..462574a 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ This project is based on [@trivago/prettier-plugin-sort-imports](https://github. - [4. Group type imports separately from values](#4-group-type-imports-separately-from-values) - [5. Group aliases with local imports](#5-group-aliases-with-local-imports) - [6. Enforce a blank line after top of file comments](#6-enforce-a-blank-line-after-top-of-file-comments) - - [7. Enforce sort order only in certain folders or files](#7-enforce-sort-order-only-in-certain-folders-or-files) + - [7. Enable/disable plugin or use different order in certain folders or files](#7-enabledisable-plugin-or-use-different-order-in-certain-folders-or-files) - [`importOrderTypeScriptVersion`](#importordertypescriptversion) - [`importOrderParserPlugins`](#importorderparserplugins) - [Prevent imports from being sorted](#prevent-imports-from-being-sorted) @@ -333,7 +333,7 @@ import icon from '@assets/icon'; import App from './App'; ``` -##### 7. Enforce sort order only in certain folders or files +##### 7. Enable/disable plugin or use different order in certain folders or files If you'd like to sort the imports only in a specific set of files or directories, you can disable the plugin by setting `importOrder` to an empty array, and then use Prettier's [Configuration Overrides](https://prettier.io/docs/en/configuration#configuration-overrides) to set the order for files matching a glob pattern. @@ -351,6 +351,8 @@ This can also be beneficial for large projects wishing to gradually adopt a sort ] ``` +You can also do this in reverse, where the plugin is enabled globally, but disabled for a set of files or directories in the overrides configuration. It is also useful for setting a different sort order to use in certain files or directories instead of the global sort order. + #### `importOrderTypeScriptVersion` **type**: `string`