Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is flutter analyze different from dart analyze?

I am learning Flutter and I've created a simple Android app. I want to follow the best practices, so I've also created a analysis_options.yaml:

include: package:pedantic/analysis_options.yaml

linter:
  rules:
    public_member_api_docs: true

Android Studio correctly updates it's code analysis settings according to the analysis_options.yaml and reports violations.

The issue is that when I run flutter analyze it doesn't report any of public_member_api_docs:

flutter analyze
Running "flutter pub get" in flutter-course...         514ms
Analyzing flutter-course...                                 

   info • Unused import: 'package:places/ui/screen/sight_list_screen.dart' • lib/main.dart:2:8 • unused_import
   info • Omit type annotations for local variables • lib/ui/screen/visiting_screen.dart:166:5 • omit_local_variable_types

But when I run dart analyze it reports ton's of warnings:

dart analyze
Analyzing flutter-course... 2.1s

   info • Document all public members at lib/constants.dart:5:16 • (public_member_api_docs)
   info • Document all public members at lib/constants.dart:6:16 • (public_member_api_docs)
   …
   info • Unused import: 'package:places/ui/screen/sight_list_screen.dart' • lib/main.dart:2:8 • unused_import
   info • Omit type annotations for local variables • lib/ui/screen/visiting_screen.dart:166:5 • omit_local_variable_types

Why doesn't flutter analyze respect the settings from my analysis_options.yaml?

like image 652
madhead - StandWithUkraine Avatar asked Dec 15 '20 15:12

madhead - StandWithUkraine


People also ask

What is DART analyze?

DART® stands for Direct Analysis in Real Time. It is a new ionization for rapid, non-contact surface sampling of compounds. Operating at ambient pressure with the sample at ground potential, the source enables near instantaneous determination of sample composition by using mass spectrometry.

What flutter clean does?

Flutter clean will delete the /build folder. Manually delete the/build folder, which is essentially the same as flutter clean. Restart your IDE, as it might be caching some older error logs and locking everything up.


1 Answers

I would assume they use different presets (if you have not configured analysis_options.yaml).

The dart analyze may default to something that is more appropriate for a published package (public_member_api_docs) while flutter analyze is more for an app that doesn't have an API that is being consumed.

You can try to add an analysis_options.yaml file with some preset configuration like lint or pedantic.

With that you may see more hints and warnings but you have a good baseline and I think both commands should give you the same output.

Alternatively you can start with an empty analysis_options.yaml and enable/disable the checks that you want to use one by one.

Edit

Why doesn't flutter analyze respect the settings from my analysis_options.yaml?

I missed this. There have traditionally been differences in the output and also in the formatting of both commands as they have been using different dependency versions. With Dart 2.12 and Flutter 2.0 they are both supposed to be using the same things under the hood.

That being said, there currently seems to be https://github.com/flutter/flutter/projects/106 in progress to fix the last remaining disparities.

like image 192
kuhnroyal Avatar answered Oct 16 '22 18:10

kuhnroyal