12

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

mirkancal
  • 4,762
  • 7
  • 37
  • 75

5 Answers5

31

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

James
  • 543
  • 5
  • 14
12

You can fix all the Analysis issues identified by dart analyze on save of file.

Add this in settings.json file

{
    // ...
    "editor.codeActionsOnSave": {
        "source.fixAll": true
    },
}
Abhishek Patil
  • 180
  • 1
  • 9
1

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.

0

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.

SugaR256
  • 963
  • 10
  • 9
  • Thank you for your time. Unfortunately it didn't solve the problem. I've run this command but trivial fixes like "convert to single quoted string" was not applied. – mirkancal Jun 02 '20 at 17:10
0

Honestly I tried all fixes listed on here, and the one that helped me the most was manually using the search and replace feature in VSCode. For example, if you have 500+ Invalid const value errors, just search for something like "const Text(" and replace it with "Text(" and all the errors with this error assorsiated with text will be gone... I just repeated this with other errors and then at the end, run:

dart fix --dry-run && dart fix --apply

and this got rid of my 500+ errors and most of the problems listed. Hope this works. Just get creative with your search and replaceAll phase...

Manbus
  • 706
  • 4
  • 9