There are many lint warnings in different files of my project like:
Prefer const with constant constructors.
Use key in widget constructors.
...
Unnecessary string interpolation.
Is there a way to only fix a particular warning, something like
dart fix prefer_const_constructors
PS: I don’t want to fix all the warnings, for that I can run dart fix --apply
.
3
Answers
To ignore a single line, you can add a comment above the line:
To ignore for the whole file, you can add a comment at the top of the file:
To ignore for the whole project, you can set the rule to false in your analysis_options.yaml file:
Refer this for more
Yes, It is possible by changing lint rules. For time being, you have to add only rules which you want to fix and ignore all others.
Follow these steps
In the project, you have to create analysis_options.ymal file. The content of the file will look like this.
More details here
After that try to run
dart fix
, since only one lint rule is enabled it only gives you suggestions for that only.You can now use the flag
--code
for the newest dart versioncommand will be like:
dart fix --apply --code prefer_const_constructors