prettier-plugin-sort-imports-apolloio
v1.0.5
Published
A prettier plugins to sort imports in provided RegEx order (Fork of @trivago/prettier-plugin-sort-imports)
Maintainers
Readme
Prettier plugin sort imports
This is a fork of @trivago/prettier-plugin-sort-imports created by Ayush Sharma and the Trivago team. All credit for the original implementation goes to them.
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
Input
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';Output
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';Install
npm
npm install --save-dev prettier-plugin-sort-imports-apolloioor, using yarn
yarn add --dev prettier-plugin-sort-imports-apolloioNote: If formatting .vue sfc files please install @vue/compiler-sfc if not in your dependency tree - this normally is within Vue projects.
Usage
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
}**Note: There may be an issue with some package managers, such as pnpm. You can solve it by providing additional configuration option in prettier config file.
module.exports = {
...
"plugins": ["prettier-plugin-sort-imports-apolloio"]
}APIs
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.
