Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

linter: import sorting and grouping #2713

Closed
LIMPIX31 opened this issue Mar 13, 2024 · 10 comments
Closed

linter: import sorting and grouping #2713

LIMPIX31 opened this issue Mar 13, 2024 · 10 comments

Comments

@LIMPIX31
Copy link
Contributor

LIMPIX31 commented Mar 13, 2024

Need rule for lexicographical sorting and grouping of imports

Details

@Boshen
Copy link
Member

Boshen commented Mar 14, 2024

I'd say that reporting whether the imports are sorted or not is kind of useless, I wonder if this should be a codemod, or a linter rule with --fix.

@LIMPIX31
Copy link
Contributor Author

I'd say that reporting whether the imports are sorted or not is kind of useless, I wonder if this should be a codemod, or a linter rule with --fix.

Yes, there should be a --fix option for that rule.

@Boshen
Copy link
Member

Boshen commented Mar 14, 2024

Is there an existing eslint plugin for this? I'll make a decision if I have more contexts.

@LIMPIX31
Copy link
Contributor Author

Is there an existing eslint plugin for this? I'll make a decision if I have more contexts.

https://github.com/lydell/eslint-plugin-simple-import-sort

@Dunqing
Copy link
Member

Dunqing commented Mar 18, 2024

The import plugin has order rule do the same thing https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/order.md

@XantreDev
Copy link
Contributor

The import plugin has order rule do the same thing import-js/eslint-plugin-import@main/docs/rules/order.md

I think eslint-plugin-simple-import-sort just has good defaults. Oxc can have both configurable rule and with good default

@XantreDev
Copy link
Contributor

XantreDev commented Mar 21, 2024

import/order is doable but too complex. Has too much of configuration, require support.
import/order ~ 800 LOC
simple-import-sort ~ 200 LOC (it's not actually true, there are a lot of shared code)

I will continue research about porting of simple-import-sort

Also import/order spams with errors, this is one of the reasons why it's harder to implement

simple-import-sort uses tokens to sort ImportSpecifiers

@LIMPIX31
Copy link
Contributor Author

import/order is doable but too complex. Has too much of configuration, require support. import/order ~ 800 LOC simple-import-sort ~ 200 LOC (it's not actually true, there are a lot of shared code)

I will continue research about porting of simple-import-sort

Also import/order spams with errors, this is one of the reasons why it's hard to implement

I'm wondering if we can do import grouping relying on workspace (reading package.json and glob matching) or tsconfig.json paths rather than just the import source.

This should configure well, because I'd like to see the react and next imports separate and at the very top, not mixed in with other modules.

@XantreDev
Copy link
Contributor

XantreDev commented Mar 21, 2024

I'm wondering if we can do import grouping relying on workspace (reading package.json and glob matching) or tsconfig.json paths rather than just the import source.

What is the problem with import source?

@LIMPIX31
Copy link
Contributor Author

What is the problem with import source?

import { useEffect } from 'react'    // "react": "18.2.0"
import { cn } from '@repo/lib'       // "@repo/lib": "workspace:*"
import { Button } from 'components'  // "baseUrl": "src"

By looking at the string after from (import source) you can tell that it looks like an npm package. Whereas they can actually be categorized into: package, monorepo package and path mapping (from tsconfig paths).

The question is whether linter is allowed to read any files in the workspace.

@oxc-project oxc-project locked and limited conversation to collaborators Mar 29, 2024
@Boshen Boshen converted this issue into discussion #2858 Mar 29, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants