Migrate analyze commands to null safety (#95442)
This commit is contained in:
@@ -2,9 +2,6 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// @dart = 2.8
|
||||
|
||||
import 'package:meta/meta.dart';
|
||||
import 'package:process/process.dart';
|
||||
|
||||
import '../artifacts.dart';
|
||||
@@ -20,12 +17,12 @@ class AnalyzeCommand extends FlutterCommand {
|
||||
AnalyzeCommand({
|
||||
bool verboseHelp = false,
|
||||
this.workingDirectory,
|
||||
@required FileSystem fileSystem,
|
||||
@required Platform platform,
|
||||
@required Terminal terminal,
|
||||
@required Logger logger,
|
||||
@required ProcessManager processManager,
|
||||
@required Artifacts artifacts,
|
||||
required FileSystem fileSystem,
|
||||
required Platform platform,
|
||||
required Terminal terminal,
|
||||
required Logger logger,
|
||||
required ProcessManager processManager,
|
||||
required Artifacts artifacts,
|
||||
}) : _artifacts = artifacts,
|
||||
_fileSystem = fileSystem,
|
||||
_processManager = processManager,
|
||||
@@ -35,7 +32,6 @@ class AnalyzeCommand extends FlutterCommand {
|
||||
argParser.addFlag('flutter-repo',
|
||||
negatable: false,
|
||||
help: 'Include all the examples and tests from the Flutter repository.',
|
||||
defaultsTo: false,
|
||||
hide: !verboseHelp);
|
||||
argParser.addFlag('current-package',
|
||||
help: 'Analyze the current project, if applicable.', defaultsTo: true);
|
||||
@@ -80,17 +76,15 @@ class AnalyzeCommand extends FlutterCommand {
|
||||
'files that will be analyzed.\n'
|
||||
'Ignored if "--watch" is specified.');
|
||||
argParser.addFlag('fatal-infos',
|
||||
negatable: true,
|
||||
help: 'Treat info level issues as fatal.',
|
||||
defaultsTo: true);
|
||||
argParser.addFlag('fatal-warnings',
|
||||
negatable: true,
|
||||
help: 'Treat warning level issues as fatal.',
|
||||
defaultsTo: true);
|
||||
}
|
||||
|
||||
/// The working directory for testing analysis using dartanalyzer.
|
||||
final Directory workingDirectory;
|
||||
final Directory? workingDirectory;
|
||||
|
||||
final Artifacts _artifacts;
|
||||
final FileSystem _fileSystem;
|
||||
@@ -127,9 +121,9 @@ class AnalyzeCommand extends FlutterCommand {
|
||||
Future<FlutterCommandResult> runCommand() async {
|
||||
if (boolArg('watch')) {
|
||||
await AnalyzeContinuously(
|
||||
argResults,
|
||||
runner.getRepoRoots(),
|
||||
runner.getRepoPackages(),
|
||||
argResults!,
|
||||
runner!.getRepoRoots(),
|
||||
runner!.getRepoPackages(),
|
||||
fileSystem: _fileSystem,
|
||||
logger: _logger,
|
||||
platform: _platform,
|
||||
@@ -139,9 +133,9 @@ class AnalyzeCommand extends FlutterCommand {
|
||||
).analyze();
|
||||
} else {
|
||||
await AnalyzeOnce(
|
||||
argResults,
|
||||
runner.getRepoRoots(),
|
||||
runner.getRepoPackages(),
|
||||
argResults!,
|
||||
runner!.getRepoRoots(),
|
||||
runner!.getRepoPackages(),
|
||||
workingDirectory: workingDirectory,
|
||||
fileSystem: _fileSystem,
|
||||
logger: _logger,
|
||||
|
||||
@@ -2,10 +2,7 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// @dart = 2.8
|
||||
|
||||
import 'package:args/args.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
import 'package:process/process.dart';
|
||||
|
||||
import '../artifacts.dart';
|
||||
@@ -23,12 +20,12 @@ class AnalyzeContinuously extends AnalyzeBase {
|
||||
ArgResults argResults,
|
||||
List<String> repoRoots,
|
||||
List<Directory> repoPackages, {
|
||||
@required FileSystem fileSystem,
|
||||
@required Logger logger,
|
||||
@required Terminal terminal,
|
||||
@required Platform platform,
|
||||
@required ProcessManager processManager,
|
||||
@required Artifacts artifacts,
|
||||
required FileSystem fileSystem,
|
||||
required Logger logger,
|
||||
required Terminal terminal,
|
||||
required Platform platform,
|
||||
required ProcessManager processManager,
|
||||
required Artifacts artifacts,
|
||||
}) : super(
|
||||
argResults,
|
||||
repoPackages: repoPackages,
|
||||
@@ -41,13 +38,13 @@ class AnalyzeContinuously extends AnalyzeBase {
|
||||
artifacts: artifacts,
|
||||
);
|
||||
|
||||
String analysisTarget;
|
||||
String? analysisTarget;
|
||||
bool firstAnalysis = true;
|
||||
Set<String> analyzedPaths = <String>{};
|
||||
Map<String, List<AnalysisError>> analysisErrors = <String, List<AnalysisError>>{};
|
||||
Stopwatch analysisTimer;
|
||||
final Stopwatch analysisTimer = Stopwatch();
|
||||
int lastErrorCount = 0;
|
||||
Status analysisStatus;
|
||||
Status? analysisStatus;
|
||||
|
||||
@override
|
||||
Future<void> analyze() async {
|
||||
@@ -83,7 +80,7 @@ class AnalyzeContinuously extends AnalyzeBase {
|
||||
server.onErrors.listen(_handleAnalysisErrors);
|
||||
|
||||
await server.start();
|
||||
final int exitCode = await server.onExit;
|
||||
final int? exitCode = await server.onExit;
|
||||
|
||||
final String message = 'Analysis server exited with code $exitCode.';
|
||||
if (exitCode != 0) {
|
||||
@@ -104,7 +101,7 @@ class AnalyzeContinuously extends AnalyzeBase {
|
||||
}
|
||||
analysisStatus = logger.startProgress('Analyzing $analysisTarget...');
|
||||
analyzedPaths.clear();
|
||||
analysisTimer = Stopwatch()..start();
|
||||
analysisTimer.start();
|
||||
} else {
|
||||
analysisStatus?.stop();
|
||||
analysisStatus = null;
|
||||
@@ -114,13 +111,13 @@ class AnalyzeContinuously extends AnalyzeBase {
|
||||
|
||||
// Remove errors for deleted files, sort, and print errors.
|
||||
final List<AnalysisError> errors = <AnalysisError>[];
|
||||
for (final String path in analysisErrors.keys.toList()) {
|
||||
analysisErrors.forEach((String path, List<AnalysisError> errors) {
|
||||
if (fileSystem.isFileSync(path)) {
|
||||
errors.addAll(analysisErrors[path]);
|
||||
errors.addAll(errors);
|
||||
} else {
|
||||
analysisErrors.remove(path);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
errors.sort();
|
||||
|
||||
|
||||
@@ -2,12 +2,9 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// @dart = 2.8
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:args/args.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
import 'package:process/process.dart';
|
||||
|
||||
import '../artifacts.dart';
|
||||
@@ -24,12 +21,12 @@ class AnalyzeOnce extends AnalyzeBase {
|
||||
ArgResults argResults,
|
||||
List<String> repoRoots,
|
||||
List<Directory> repoPackages, {
|
||||
@required FileSystem fileSystem,
|
||||
@required Logger logger,
|
||||
@required Platform platform,
|
||||
@required ProcessManager processManager,
|
||||
@required Terminal terminal,
|
||||
@required Artifacts artifacts,
|
||||
required FileSystem fileSystem,
|
||||
required Logger logger,
|
||||
required Platform platform,
|
||||
required ProcessManager processManager,
|
||||
required Terminal terminal,
|
||||
required Artifacts artifacts,
|
||||
this.workingDirectory,
|
||||
}) : super(
|
||||
argResults,
|
||||
@@ -44,7 +41,7 @@ class AnalyzeOnce extends AnalyzeBase {
|
||||
);
|
||||
|
||||
/// The working directory for testing analysis using dartanalyzer.
|
||||
final Directory workingDirectory;
|
||||
final Directory? workingDirectory;
|
||||
|
||||
@override
|
||||
Future<void> analyze() async {
|
||||
@@ -98,10 +95,10 @@ class AnalyzeOnce extends AnalyzeBase {
|
||||
protocolTrafficLog: protocolTrafficLog,
|
||||
);
|
||||
|
||||
Stopwatch timer;
|
||||
Status progress;
|
||||
Stopwatch? timer;
|
||||
Status? progress;
|
||||
try {
|
||||
StreamSubscription<bool> subscription;
|
||||
StreamSubscription<bool>? subscription;
|
||||
|
||||
void handleAnalysisStatus(bool isAnalyzing) {
|
||||
if (!isAnalyzing) {
|
||||
@@ -123,7 +120,7 @@ class AnalyzeOnce extends AnalyzeBase {
|
||||
|
||||
await server.start();
|
||||
// Completing the future in the callback can't fail.
|
||||
unawaited(server.onExit.then<void>((int exitCode) {
|
||||
unawaited(server.onExit.then<void>((int? exitCode) {
|
||||
if (!analysisCompleter.isCompleted) {
|
||||
analysisCompleter.completeError(
|
||||
// Include the last 20 lines of server output in exception message
|
||||
@@ -139,7 +136,7 @@ class AnalyzeOnce extends AnalyzeBase {
|
||||
final String message = directories.length > 1
|
||||
? '${directories.length} ${directories.length == 1 ? 'directory' : 'directories'}'
|
||||
: fileSystem.path.basename(directories.first);
|
||||
progress = argResults['preamble'] as bool
|
||||
progress = argResults['preamble'] == true
|
||||
? logger.startProgress(
|
||||
'Analyzing $message...',
|
||||
)
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// @dart = 2.8
|
||||
|
||||
import 'package:flutter_tools/src/commands/analyze_base.dart';
|
||||
|
||||
import '../../src/common.dart';
|
||||
|
||||
Reference in New Issue
Block a user