Project Name | Stars | Downloads | Repos Using This | Packages Using This | Most Recent Commit | Total Releases | Latest Release | Open Issues | License | Language |
---|---|---|---|---|---|---|---|---|---|---|
Prettier Plugin Sort Imports | 1,857 | 9 | 3 days ago | 26 | February 03, 2022 | 51 | apache-2.0 | TypeScript | ||
A prettier plugin to sort imports in typescript and javascript files by the provided RegEx order. | ||||||||||
Kirby Selector | 140 | 6 years ago | 13 | gpl-3.0 | PHP | |||||
file selector panel field for Kirby CMS | ||||||||||
Csv Utils | 55 | a month ago | May 30, 2021 | mit | Go | |||||
Split (rows and columns), sort, and search | ||||||||||
Td | 47 | 14 | 6 years ago | 5 | July 19, 2014 | 1 | gpl-3.0 | Python | ||
a non-offensive, per project ToDo manager. | ||||||||||
Rnm | 42 | 3 years ago | 4 | gpl-3.0 | C++ | |||||
Unix tool: Bulk Rename Utility | ||||||||||
Sortboard | 29 | 2 years ago | 10 | August 22, 2018 | 7 | mit | TypeScript | |||
A small ES6 library for easy sorting and filtering of elements. | ||||||||||
Filesharper | 10 | 9 months ago | 1 | mit | C# | |||||
An extensible, GUI-based file search and processing tool for Windows written in C# and WPF, with out-of-the-box functionality similar to grepWin and dnGrep | ||||||||||
Chrome Bookmark Sort Out | 7 | 5 years ago | gpl-3.0 | |||||||
Sort out your Bookmarks by the keywords/regular expression for Chrome/Chromium | ||||||||||
Msort | 5 | 11 years ago | 11 | mit | Python | |||||
MSort is a command line media folder sorting tool. It can sort folders into sub-folders of similarly names directory prefixes. Matching is done via Regex rules which are defined in a configuration file, with grouping based of the captured regex values. | ||||||||||
Algorithms In Java | 5 | 6 years ago | Java | |||||||
Implementation of Algorithms in Java |
A prettier plugin to sort import declarations by provided Regular Expression order.
Note: If you are migrating from v2.x.x to v3.x.x, Please Read Migration Guidelines
import React, {
FC,
useEffect,
useRef,
ChangeEvent,
KeyboardEvent,
} from 'react';
import { logger } from '@core/logger';
import { reduce, debounce } from 'lodash';
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 { debounce, reduce } from 'lodash';
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';
npm
npm install --save-dev @trivago/prettier-plugin-sort-imports
or, using yarn
yarn add --dev @trivago/prettier-plugin-sort-imports
Note: If you are migrating from v2.x.x to v3.x.x, Please Read Migration Guidelines
Note: If formatting .vue
sfc files please install @vue/compiler-sfc
if not in your dependency tree - this normally is within Vue projects.
Add an order in prettier config file.
module.exports = {
"printWidth": 80,
"tabWidth": 4,
"trailingComma": "all",
"singleQuote": true,
"semi": true,
"importOrder": ["^@core/(.*)$", "^@server/(.*)$", "^@ui/(.*)$", "^[./]"],
"importOrderSeparation": true,
"importOrderSortSpecifiers": true
}
importOrder
type: Array<string>
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 <THIRD_PARTY_MODULES>
to assign third party imports to the appropriate position:
"importOrder": ["^@core/(.*)$", "<THIRD_PARTY_MODULES>", "^@server/(.*)$", "^@ui/(.*)$", "^[./]"],
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,
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):
import ExampleView from './ExampleView';
import ExamplesList from './ExamplesList';
compared with "importOrderCaseInsensitive": true
:
import ExamplesList from './ExamplesList';
import ExampleView from './ExampleView';
importOrderParserPlugins
type: Array<string>
default value: ["typescript", "jsx"]
Previously known as experimentalBabelParserPluginsList
.
A collection of plugins for babel parser. The plugin passes this list to babel parser, so it can understand the syntaxes used in the file being formatted. The plugin uses prettier itself to figure out the parser it needs to use but if that fails, you can use this field to enforce the usage of the plugins' babel parser needs.
To pass the plugins to babel parser:
"importOrderParserPlugins" : ["classProperties", "decorators-legacy"]
To pass the options to the babel parser plugins: Since prettier options are limited to string, you can pass plugins
with options as a JSON string of the plugin array:
"[\"plugin-name\", { \"pluginOption\": true }]"
.
"importOrderParserPlugins" : ["classProperties", "[\"decorators\", { \"decoratorsBeforeExport\": true }]"]
To disable default plugins for babel parser, pass an empty array:
importOrderParserPlugins: []
The plugin extracts the imports which are defined in importOrder
. These imports are considered as local imports.
The imports which are not part of the importOrder
is considered as third party imports.
After, the plugin sorts the local imports and third party imports using natural sort algorithm.
In the end, the plugin returns final imports with third party imports on top and local imports at the end.
The third party imports position (it's top by default) can be overridden using the <THIRD_PARTY_MODULES>
special word in the importOrder
.
Having some trouble or an issue ? You can check FAQ / Troubleshooting section.
Framework | Supported | Note |
---|---|---|
JS with ES Modules | Everything | - |
NodeJS with ES Modules | Everything | - |
React | Everything | - |
Angular | Everything | Supported through importOrderParserPlugins API |
Vue | Everything |
@vue/compiler-sfc is required |
Svelte | Soon to be supported. | Any contribution is welcome. |
Want to highlight your project or company ? Adding your project / company name will help plugin to gain attraction and contribution. Feel free to make a Pull Request to add your project / company name.
For more information regarding contribution, please check the Contributing Guidelines. If you are trying to debug some code in the plugin, check Debugging Guidelines
Ayush Sharma | Behrang Yarahmadi |
---|---|
@ayusharma_ | @behrang_y |
This plugin modifies the AST which is against the rules of prettier.