How to fix auto-fixable problems on VSCode with Flutter?

Viewed 7056

I've updated pedantic package and ended up 1K+ problems. Many of them are prefer_single_quotes or unnecessary this etc. They are one click away to fix. I think eslint or some other tools can do that within the VSCode.

Is there a way to do it with Flutter projects? I find dartfix package but says “No recommended changes” after running it. What I want to do is fix all the auto-fixable problems on the problems tab.

dartfix on pub.dev

3 Answers

Not sure if you have tried the built in fixes using dart fix.

Use dart fix --dry-run to see suggested changes and dart fix --apply to apply them.

https://dart.dev/tools/dart-fix

I was having the same issue and tried dartfix. It worked for me when I specified the correct path:

$ dartfix --pedantic lib/src/ --overwrite

Went from ~450 problems to 59

Even though all of my files that I wanted to fix are in the src folder, I had to run the command again with $ dartfix --pedantic lib/ --overwrite to get my main file. That might be the issue that you're having, too.

I'm not sure how many of these problems dartfmt can cover, but it's definitely worth trying! To run dartfmt with idiomatic fixing, overwriting and link-following, please run dartfmt --fix --overwrite --follow-links . in your project folder.

Related