Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable custom order in the same group #170

Open
mattiaz9 opened this issue Sep 2, 2022 · 6 comments
Open

Enable custom order in the same group #170

mattiaz9 opened this issue Sep 2, 2022 · 6 comments
Labels
feature request A new feature request

Comments

@mattiaz9
Copy link

mattiaz9 commented Sep 2, 2022

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

@mattiaz9 mattiaz9 added the feature request A new feature request label Sep 2, 2022
@IanVS
Copy link

IanVS commented Sep 27, 2022

This feature exists in a fork, if you want to use that until/unless this project merges #42.

https://github.com/ianvs/prettier-plugin-sort-imports#importorderseparation

@tearf001
Copy link

tearf001 commented Sep 30, 2022

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

@mattiaz9
Copy link
Author

@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

@tsvetkovv
Copy link

@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}($|\/.+)`;

@CagriUysal
Copy link

I really would like this feature!

@DaveKeehl
Copy link

I would LOVE this feature! Has any progress been made?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request A new feature request
Projects
None yet
Development

No branches or pull requests

6 participants