biomejs / biome

A toolchain for web projects, aimed to provide functionalities to maintain them. Biome offers formatter and linter, usable via CLI and LSP.
https://biomejs.dev
Apache License 2.0
15.59k stars 485 forks source link

β˜‚οΈ Import sorter revamping - custom order #3177

Open Conaclos opened 5 months ago

Conaclos commented 5 months ago

Description

We recently published an RFC to improve the Biome import sorter.

This issue tracks the implementation of the RFC. The main goal of this implementation is to:

We will provide a legacy configuration to enable the old way of sorting imports. By disabling this configuration, the new system will be used.

Upvote & Fund

Fund with Polar

louisgv commented 2 months ago

Would love to have this improved such that we can replace the following prettier config:

import { fileURLToPath } from 'url';

/** @typedef {import("prettier").Config} PrettierConfig */
/** @typedef {import("prettier-plugin-tailwindcss").PluginOptions} TailwindConfig */
/** @typedef {import("@ianvs/prettier-plugin-sort-imports").PluginConfig} SortImportsConfig */

/** @satisfies { PrettierConfig | SortImportsConfig | TailwindConfig } */
const config = {
  arrowParens: 'always',
  singleQuote: true,
  tabWidth: 2,
  trailingComma: 'all',
  singleAttributePerLine: true,
  jsxSingleQuote: true,
  plugins: [
    '@ianvs/prettier-plugin-sort-imports',
    'prettier-plugin-tailwindcss',
  ],
  tailwindConfig: fileURLToPath(
    new URL('../../packages/theme/tailwind.web.ts', import.meta.url),
  ),
  tailwindFunctions: ['cn', 'cva', 'tw'],
  importOrder: [
    '<TYPES>',
    '<TYPES>^@org-monorepo',
    '<TYPES>^[@/]',
    '<TYPES>^[./|../]',
    '',

    '^(react/(.*)$)|^(react$)|^(react-native(.*)$)',
    '^(next/(.*)$)|^(next$)',
    '^(expo(.*)$)|^(expo$)',
    '<BUILTIN_MODULES>', // Node.js built-in modules
    '<THIRD_PARTY_MODULES>', // Imports not matched by other special words or groups.
    '',

    '^@org-monorepo/enums/(.*)$',
    '',
    '^@org-monorepo/(.*)-utils/(.*)$',
    '',
    '^@org-monorepo/components/(.*)$',
    '',
    '^@org-monorepo/(.*)$',
    '',
    '^@/types(.*)$',
    '',
    '^@/utils/(.*)$',
    '',
    '^@/components/(.*)$',
    '',
    '^@/(.*)$',
    '',

    '^[../]',
    '^[./]',
  ],
  importOrderParserPlugins: ['typescript', 'jsx', 'decorators-legacy'],
};

export default config;
stunaz commented 2 months ago

yeah.... give us a way to do the grouping automatically

Conaclos commented 2 months ago

The issue has been funded! I will start work in a week.

ematipico commented 1 month ago

@MatheusRoichman based on @Conaclos 'last message, he started to work on the feature today.

Please refrain from asking "whens" or for ETAs. The feature will be ready when it's ready. You may not realise this, but these kinds of messages put pressure on the person, which is something I want to avoid here.

Thank you for understanding ☺️

nhuesmann commented 1 month ago

I pledged support for this feature several months ago so I come back to check it periodically. I am SO excited to see we've met the funding goal! Best of luck @Conaclos, you've got this! πŸ™Œ

artola commented 1 month ago

I use a plugin forked from original Trivago and we setup a simple grouping for: company, team, root folder, that goes below the node/external packages.

  plugins: [require.resolve('@ianvs/prettier-plugin-sort-imports')],
  importOrder: [
    '',
    '^@company/(.*)$',
    '',
    '^@team/(.*)$',
    '',
    '^@/(.*)$',
    '',
    '^[./]',
  ],

I am glad to hear that development of this feature has started. Thanks.

nhuesmann commented 2 weeks ago

Hi @Conaclos! Just wanted to confirm, has this been released? I see that the related task was completed a few weeks ago, but this issue is still open. Just wanted to know the status to see if I can start migrating my setup to Biome. Thanks!

dyc3 commented 2 weeks ago

@nhuesmann Nope, not yet. We'll post about it here when we have updates.

nhuesmann commented 1 week ago

@dyc3 Awesome, thank you!