Linter: lint to remove unused imports

Created on 7 Aug 2015  路  7Comments  路  Source: dart-lang/linter

Most helpful comment

I solved this by customizing analysis rules using the analysis_options.yaml file:

analyzer:
  errors:
    unused_import: error

鎴睆2020-05-24 涓嬪崍12 53 03

All 7 comments

Interesting. This check is provided by the analyzer in the form of a "hint".

It sounds like you'd like to be able to elevate that to a lint (to use, for example, in a presubmit step)?

I suspect that there's a misconception here that the linter will "auto-fix" some number of problems. I don't think that's the current intent for the linter.

I also believe that auto-fix utilities tend to be dangerous. Unless you can verify that there are no false positives and that there is only one reasonable way to fix a problem, you risk breaking the code.

Yeah, unused_import is a solved analyzer hint.

Is there some functionality in the IDEA plugin that automatically removes unused imports? For as long as I can remember, unused imports in Flutter are removed whenever I press Command+Alt+L to format the document. It used to leave my non-Flutter Dart projects alone, but out of nowhere, now calling the formatter removes imports, which is a frustration when formatting a document I'm not finished writing yet.

Just trying to figure out what the potential causes could be.

Hey @thosakwe. Take a look at your Flutter preferences.

image

Maybe you have "Organize imports on save" checked?

I probably do; thanks for the tip, @pq!

I solved this by customizing analysis rules using the analysis_options.yaml file:

analyzer:
  errors:
    unused_import: error

鎴睆2020-05-24 涓嬪崍12 53 03

Was this page helpful?
0 / 5 - 0 ratings