prettier-plugin-sort-imports
prettier-plugin-sort-imports copied to clipboard
Enable custom order in the same group
Is your feature request related to a problem?
I would like to manually sort some imports in a group without placing them in separated group.
For instance I'd like to have import React from "react"
as first and then all the others in alphabetical orders as default.
Describe the solution you'd like I thought we could set an array for a single group to define an order. Example:
{
"importOrder": [
["^react", "<THIRD_PARTY_MODULES>"],
"^[./]"
],
}
Describe alternatives you've considered None
This feature exists in a fork, if you want to use that until/unless this project merges https://github.com/trivago/prettier-plugin-sort-imports/pull/42.
https://github.com/ianvs/prettier-plugin-sort-imports#importorderseparation
Could this help?
.prettierrc.js
of mine
const packages = require('./package.json').dependencies;
const sortedPackages = Object.keys(packages).sort();
module.exports = {
printWidth: 120,
tabWidth: 2,
useTabs: false,
semi: true,
singleQuote: true,
trailingComma: 'all',
arrowParens: 'avoid',
endOfLine: 'lf',
importOrder: sortedPackages.concat(['<THIRD_PARTY_MODULES>', '^\\.\\./', '^\\./']),
importOrderSeparation: true,
importOrderSortSpecifiers: true,
importOrderCaseInsensitive: true,
};
Actually <THIRD_PARTY_MODULES>
act as your custom imports
@tearf001 I don't think it would.
Anyway I'm using this fork at the moment that can do it: https://github.com/ianvs/prettier-plugin-sort-imports
@tearf001
Thanks for the great workaround. It helped me with custom aliases.
I transformed to Regex because otherwise a package abc
would catch a local path like ./app-abc.ts
const sortedPackages = Object.keys(packages).sort().map(package => `^${package}($|\/.+)`;
I really would like this feature!
I would LOVE this feature! Has any progress been made?
I would LOVE this feature. I like React imports up top also.