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

Question: Is there a way to disable auto-fixing for a subset of rules #657

Closed
pharmpy-dev-123 opened this issue Mar 29, 2022 · 6 comments
Closed

Comments

@pharmpy-dev-123
Copy link

I like that @typescript-eslint/ban-types raises errors when running xo.
I do not like that @typescript-eslint/ban-types auto-fixes apply when running xo --fix.
This is because, in my experience, auto-fixing for this rule almost always produces broken source.

Is it possible to configure xo so that auto-fixing for @typescript-eslint/ban-types is disabled but rule-violating lines still raise an error?

@sindresorhus
Copy link
Member

There's no way to do that. You will have to propose such a change over at https://github.com/eslint/eslint which is what XO uses underneath.

@sindresorhus
Copy link
Member

Is it possible to configure xo so that auto-fixing for @typescript-eslint/ban-types is disabled but rule-violating lines still raise an error?

The ban-types config has the ability to disable the fixers though. Look at the config. You can do so in your own code by overriding it.

Would you disable fixers for all the banned types or just some? If some, which ones? Out of curiosity.

auto-fixing for this rule almost always produces broken source.

Almost any change can break TS types though. At least it fails loudly.

@pharmpy-dev-123
Copy link
Author

There's no way to do that. You will have to propose such a change over at https://github.com/eslint/eslint which is what XO uses underneath.

OK

The ban-types config has the ability to disable the fixers though. Look at the config. You can do so in your own code by overriding it.

I will look into it, that looks like a solution to my problem.

Would you disable fixers for all the banned types or just some? If some, which ones? Out of curiosity.

A priori, all of them. I have problems with null being partially fixed to undefined producing broken source that is later caught by TypeScript.

@pharmpy-dev-123
Copy link
Author

NB: Naively configuring @typescript-eslint/ban-types does not work. I get the following errors when trying to lint non-TypeScript file.

/home/runner/work/amdui/amdui/gatsby-config.js: line 1, col 1, Error - Definition for rule '@typescript-eslint/ban-types' was not found. (@typescript-eslint/ban-types)
/home/runner/work/amdui/amdui/lint-staged.config.js: line 1, col 1, Error - Definition for rule '@typescript-eslint/ban-types' was not found. (@typescript-eslint/ban-types)

I think I need to be more specific about the files this rule covers.

@aladdin-add
Copy link
Contributor

@pharmpy-dev-123 just try this: eslint-plugin-no-autofix

@fregante
Copy link
Member

fregante commented Aug 6, 2022

eslint’s solution for this is to set the rule as a warning instead: eslint/eslint#8935

I don’t think XO can effectively do this outside ESLint unfortunately.

@fregante fregante closed this as not planned Won't fix, can't repro, duplicate, stale Aug 6, 2022
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

4 participants