Unverified Commit a5137399 authored by Jenn Magder's avatar Jenn Magder Committed by GitHub

Migrate analyze commands to null safety (#95442)

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