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
?
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
) whileflutter 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
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.