Skip to content

feat(order rule): add forceFix option for potentially unsafe import sorting #230

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

Open
privatenumber opened this issue Feb 10, 2025 · 5 comments

Comments

@privatenumber
Copy link
Contributor

The order rule enforces a specific import order but refuses to auto-sort in case of potential side effects. However, there are many cases when imports have no side effects, making reordering safe.

It would be useful to have a forceFix option to allow automatic sorting when side effects are not a concern.

For precedent, TypeScript ESLint's no-explicit-any rule has a similar option: fixToUnknown

@JounQin
Copy link
Member

JounQin commented Mar 16, 2025

Maybe we can provide suggestions instead of fix in this case?

@privatenumber
Copy link
Contributor Author

In my project, we enforce a no side-effects rule, and auto-fixes are expected when saving in VSCode.

I'd be fine with making this a suggestion, as long as it can be auto-applied on save.

However, if suggestions can be auto-fixed, I worry that making it a suggestion might be too risky for some projects or users.

@JounQin
Copy link
Member

JounQin commented Mar 16, 2025

suggestions will not be applied automatically AFAIK?

These fixes are unsafe, so a manual action is better IMO.

@privatenumber
Copy link
Contributor Author

You can use --fix-type suggestion: https://eslint.org/docs/latest/use/command-line-interface#--fix-type
There's also a PR to add fixType support to the VSCode extension: microsoft/vscode-eslint#1945

These fixes are unsafe, so a manual action is better IMO.

I agree that it should be manual by default. For reference, Perfectionist's version of this rule has a sortSideEffects option to opt into sorting side-effect imports. Another example is TypeScript's no-explicit-any rule with the fixToUnknown option.

It would be useful to be able to opt into automating unsafe changes with the acknowledgement that there's a risk.

@JounQin
Copy link
Member

JounQin commented Mar 19, 2025

@privatenumber Would you like to raise a PR for it?

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

No branches or pull requests

2 participants