mirror of
https://github.com/flutter/flutter
synced 2024-10-13 03:32:55 +00:00
flutter analyze repo analysis options (#5707)
This updates the flutter analyze command to use the .analysis_options_flutter_analyze in the repo root when either the --flutter-repo flag is supplied or the sources being analyzed reside in the flutter repo.
This commit is contained in:
parent
1f15e06e45
commit
3ed3390d0c
|
@ -1,9 +1,9 @@
|
|||
# Specify analysis options.
|
||||
|
||||
# This file is the .analysis_options file used by Flutter editors, such as
|
||||
# Atom. It is very similar to flutter_tools/flutter_analysis_options; the only
|
||||
# difference (currently) is the public_member_api_docs option, which triggers
|
||||
# too many messages to be used in editors.
|
||||
# This file contains the analysis options used by Flutter editors, such as Atom.
|
||||
# It is very similar to .analysis_options_flutter_analyze;
|
||||
# the only difference (currently) is the public_member_api_docs option,
|
||||
# which triggers too many messages to be used in editors.
|
||||
|
||||
analyzer:
|
||||
language:
|
||||
|
|
73
.analysis_options_flutter_analyze
Normal file
73
.analysis_options_flutter_analyze
Normal file
|
@ -0,0 +1,73 @@
|
|||
# Specify analysis options.
|
||||
|
||||
# This file contains the analysis options used by 'flutter analyze'.
|
||||
# It is very similar to .analysis_options;
|
||||
# the only difference (currently) is the public_member_api_docs option,
|
||||
# which is turned on and programmatically reduced to a single output line
|
||||
# indicating the # of violations for that rule.
|
||||
|
||||
analyzer:
|
||||
language:
|
||||
enableStrictCallChecks: true
|
||||
enableSuperMixins: true
|
||||
strong-mode: true
|
||||
errors:
|
||||
# we allow overriding fields (if they use super, ideally...)
|
||||
strong_mode_invalid_field_override: ignore
|
||||
# we allow type narrowing
|
||||
strong_mode_invalid_method_override: ignore
|
||||
strong_mode_static_type_error: ignore
|
||||
strong_mode_down_cast_composite: ignore
|
||||
# we allow having TODOs in the code
|
||||
todo: ignore
|
||||
exclude:
|
||||
- 'bin/**'
|
||||
|
||||
linter:
|
||||
rules:
|
||||
# these are in the same order as http://dart-lang.github.io/linter/lints/
|
||||
# to make maintenance easier
|
||||
|
||||
# error rules
|
||||
- avoid_empty_else
|
||||
# - comment_references
|
||||
- control_flow_in_finally
|
||||
- hash_and_equals
|
||||
# - iterable_contains_unrelated_type
|
||||
- test_types_in_equals
|
||||
- throw_in_finally
|
||||
- unrelated_type_equality_checks
|
||||
|
||||
# style rules
|
||||
- always_declare_return_types
|
||||
- always_specify_types
|
||||
- annotate_overrides
|
||||
- avoid_as
|
||||
- avoid_init_to_null
|
||||
- avoid_return_types_on_setters
|
||||
- await_only_futures
|
||||
- camel_case_types
|
||||
# - constant_identifier_names
|
||||
- control_flow_in_finally
|
||||
- empty_constructor_bodies
|
||||
- implementation_imports
|
||||
- library_names
|
||||
- library_prefixes
|
||||
- non_constant_identifier_names
|
||||
- one_member_abstracts
|
||||
# - overriden_field
|
||||
- package_api_docs
|
||||
- package_prefixed_library_names
|
||||
- prefer_is_not_empty
|
||||
- public_member_api_docs
|
||||
- slash_for_doc_comments
|
||||
- sort_constructors_first
|
||||
- sort_unnamed_constructors_first
|
||||
- super_goes_last
|
||||
# - type_annotate_public_apis # subset of always_specify_types
|
||||
- type_init_formals
|
||||
- unnecessary_brace_in_string_interp
|
||||
- unnecessary_getters_setters
|
||||
|
||||
# pub rules
|
||||
- package_names
|
|
@ -84,6 +84,21 @@ class AnalyzeCommand extends FlutterCommand {
|
|||
return true;
|
||||
}
|
||||
|
||||
/// Return `true` if [fileList] contains a path that resides inside the Flutter repository.
|
||||
/// If [fileList] is empty, then return `true` if the current directory resides inside the Flutter repository.
|
||||
bool inRepo(List<String> fileList) {
|
||||
if (fileList == null || fileList.isEmpty)
|
||||
fileList = <String>[path.current];
|
||||
String root = path.normalize(path.absolute(Cache.flutterRoot));
|
||||
String prefix = root + Platform.pathSeparator;
|
||||
for (String file in fileList) {
|
||||
file = path.normalize(path.absolute(file));
|
||||
if (file == root || file.startsWith(prefix))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool get _isBenchmarking => argResults['benchmark'];
|
||||
|
||||
Future<int> _analyzeOnce() async {
|
||||
|
@ -106,7 +121,7 @@ class AnalyzeCommand extends FlutterCommand {
|
|||
|
||||
bool currentDirectory = argResults['current-directory'] && (argResults.wasParsed('current-directory') || dartFiles.isEmpty);
|
||||
bool currentPackage = argResults['current-package'] && (argResults.wasParsed('current-package') || dartFiles.isEmpty);
|
||||
bool flutterRepo = argResults['flutter-repo'];
|
||||
bool flutterRepo = argResults['flutter-repo'] || inRepo(argResults.rest);
|
||||
|
||||
//TODO (pq): revisit package and directory defaults
|
||||
|
||||
|
@ -202,7 +217,9 @@ class AnalyzeCommand extends FlutterCommand {
|
|||
DriverOptions options = new DriverOptions();
|
||||
options.dartSdkPath = argResults['dart-sdk'];
|
||||
options.packageMap = packages;
|
||||
options.analysisOptionsFile = path.join(Cache.flutterRoot, 'packages', 'flutter_tools', 'flutter_analysis_options');
|
||||
options.analysisOptionsFile = flutterRepo
|
||||
? path.join(Cache.flutterRoot, '.analysis_options_flutter_analyze')
|
||||
: path.join(Cache.flutterRoot, 'packages', 'flutter_tools', 'flutter_analysis_options');
|
||||
AnalysisDriver analyzer = new AnalysisDriver(options);
|
||||
|
||||
// TODO(pq): consider error handling
|
||||
|
@ -241,14 +258,14 @@ class AnalyzeCommand extends FlutterCommand {
|
|||
_writeBenchmark(stopwatch, errorCount, membersMissingDocumentation);
|
||||
|
||||
if (errorCount > 0) {
|
||||
if (membersMissingDocumentation > 0 && argResults['flutter-repo'])
|
||||
if (membersMissingDocumentation > 0 && flutterRepo)
|
||||
printError('[lint] $membersMissingDocumentation public ${ membersMissingDocumentation == 1 ? "member lacks" : "members lack" } documentation (ran in ${elapsed}s)');
|
||||
else
|
||||
print('(Ran in ${elapsed}s)');
|
||||
return 1; // we consider any level of error to be an error exit (we don't report different levels)
|
||||
}
|
||||
if (argResults['congratulate']) {
|
||||
if (membersMissingDocumentation > 0 && argResults['flutter-repo']) {
|
||||
if (membersMissingDocumentation > 0 && flutterRepo) {
|
||||
printStatus('No analyzer warnings! (ran in ${elapsed}s; $membersMissingDocumentation public ${ membersMissingDocumentation == 1 ? "member lacks" : "members lack" } documentation)');
|
||||
} else {
|
||||
printStatus('No analyzer warnings! (ran in ${elapsed}s)');
|
||||
|
|
|
@ -6,6 +6,7 @@ import 'dart:async';
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:flutter_tools/src/base/os.dart';
|
||||
import 'package:flutter_tools/src/cache.dart';
|
||||
import 'package:flutter_tools/src/commands/analyze.dart';
|
||||
import 'package:flutter_tools/src/dart/pub.dart';
|
||||
import 'package:flutter_tools/src/dart/sdk.dart';
|
||||
|
@ -67,6 +68,30 @@ void main() {
|
|||
}, overrides: <Type, dynamic>{
|
||||
OperatingSystemUtils: os
|
||||
});
|
||||
|
||||
testUsingContext('inRepo', () {
|
||||
AnalyzeCommand cmd = new AnalyzeCommand();
|
||||
// Absolute paths
|
||||
expect(cmd.inRepo(<String>[tempDir.path]), isFalse);
|
||||
expect(cmd.inRepo(<String>[path.join(tempDir.path, 'foo')]), isFalse);
|
||||
expect(cmd.inRepo(<String>[Cache.flutterRoot]), isTrue);
|
||||
expect(cmd.inRepo(<String>[path.join(Cache.flutterRoot, 'foo')]), isTrue);
|
||||
// Relative paths
|
||||
String oldWorkingDirectory = path.current;
|
||||
try {
|
||||
Directory.current = Cache.flutterRoot;
|
||||
expect(cmd.inRepo(<String>['.']), isTrue);
|
||||
expect(cmd.inRepo(<String>['foo']), isTrue);
|
||||
Directory.current = tempDir.path;
|
||||
expect(cmd.inRepo(<String>['.']), isFalse);
|
||||
expect(cmd.inRepo(<String>['foo']), isFalse);
|
||||
} finally {
|
||||
Directory.current = oldWorkingDirectory;
|
||||
}
|
||||
// Ensure no exceptions
|
||||
cmd.inRepo(null);
|
||||
cmd.inRepo(<String>[]);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue