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

Auto-fix by default? #374

Open
sindresorhus opened this issue Jan 21, 2019 · 13 comments
Open

Auto-fix by default? #374

sindresorhus opened this issue Jan 21, 2019 · 13 comments
Labels

Comments

@sindresorhus
Copy link
Member

sindresorhus commented Jan 21, 2019

Most user's workflow; run npm test, encounter linter errors, then manually run xo --fix.

Is there any good reason not to just make XO default to --fix? And instead have a xo --no-fix flag to opt-out. Are there any downsides in doing this?

This could be problematic for a few rules, like ava/no-skip-test, as its auto-fixer would remove the skip before running the test, but we could have a list of things to not auto-fix by default.

@novemberborn
Copy link

I see linters as being checkers. I wouldn't expect them to just go and change my code.

Would you detect CI and raise errors rather than fixing?

@sindresorhus
Copy link
Member Author

I see linters as being checkers. I wouldn't expect them to just go and change my code.

Can we change that perception? I see linters as helpers. Fixing my code is just helping me more.

Would you detect CI and raise errors rather than fixing?

Yes

@novemberborn
Copy link

Can we change that perception?

Prettier is more easily understood as a formatter.

I don't have hard feelings either way. Would be cool if I could disable the auto-fix behavior globally though.

@kevva
Copy link
Contributor

kevva commented Jan 21, 2019

There are also CI environments to take into account. Depending on what CI you run, you'd have to make sure to run xo with the --no-fix flag. We could probably check for this and skip setting the --fix flag if it's process.env.CI, but it might lead to some edge cases.

Then there are those cases where you are transitioning an existing code base to xo from another linter. In your first couple of runs you probably just want to run it and evaluate if you want to turn off some rules before settling for a config. This could cause some issues if it would fix a bunch of files automatically, since it's a pretty unexpected behaviour most linters don't employ.

Personally it boils down to mentality. I'm a bit wary of tools that make changes to my code without me explicitly telling them to.


Oh, didn't refresh the page before commenting. I see @novemberborn brought up the question about CI environments already :).

@vadimdemedes
Copy link

I can’t come up with any reason not to do this!

@fregante
Copy link
Member

fregante commented Jan 23, 2019

There are more cases where you only need to verify the code without fixing it:

  • CI, as mentioned before

  • pre-commit hooks: if xo changes the code and pass the hook, I don't think the changes will get committed.

  • Tools like np: lint passes, then np fails because suddenly the directory isn't clean.


Most editors can be set to auto-run tools like xo to fix the code on save, I don't think it's a big deal to set that up or to run xo --fix when that behavior is wanted.

@SamVerschueren
Copy link
Contributor

Not sure about this. On one side, I like the idea because like you say, it can only help you. On the other hand, I think there are quite a lot of edge cases, some already mentioned by others where it works against you instead of with you.

A way to test this would be to publish some kind of pre-release version with --fix on by default and start using it.

@fregante
Copy link
Member

fregante commented Mar 13, 2019

The idea has grown on me, is this worth a try in the wild?

If you can reliably detect CI, git and text editors plugins, the most common automated use cases won't be affected, so probably a try wouldn't ruin a lot of people's day 😅

  • Tools like np: lint passes, then np fails because suddenly the directory isn't clean.

To counter my own point, np would fail anyway in this step—but at its appropriate test step rather than at a random later check. So technically not completely broken, just slightly less understandable.

@sindresorhus
Copy link
Member Author

@bfred-it I'm not ready to experiment with this yet. I have too many things to deal with and I expect this to require a lot of follow up and tweaks.

@florianb
Copy link

I don't like the idea - i use xo to tackle my bad behaviors. If someone would want to autofix why not adding --fix to the test-call?

@coreyfarrell
Copy link
Contributor

If I make changes to index.js and run xo without running git add index.js then xo could end up modifying my unstaged file. If this were done I would add --no-fix to all my npm test targets.

@mIkramAnsari
Copy link

How can we formate the code only without changing the code?

@fregante
Copy link
Member

fregante commented Oct 1, 2023

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

No branches or pull requests

9 participants