Enable use_if_null_to_convert_nulls_to_bools lint (#98753)

This commit is contained in:
Tomasz Gucio
2022-02-22 23:39:20 +01:00
committed by GitHub
parent a7790d8e3a
commit e4351ff053
71 changed files with 179 additions and 166 deletions

View File

@@ -290,7 +290,7 @@ abstract class FlutterCommand extends Command<void> {
}
String get targetFile {
if (argResults?.wasParsed('target') == true) {
if (argResults?.wasParsed('target') ?? false) {
return stringArg('target')!;
}
final List<String>? rest = argResults?.rest;
@@ -422,8 +422,8 @@ abstract class FlutterCommand extends Command<void> {
late final bool enableDds = () {
bool ddsEnabled = false;
if (argResults?.wasParsed('disable-dds') == true) {
if (argResults?.wasParsed('dds') == true) {
if (argResults?.wasParsed('disable-dds') ?? false) {
if (argResults?.wasParsed('dds') ?? false) {
throwToolExit(
'The "--[no-]dds" and "--[no-]disable-dds" arguments are mutually exclusive. Only specify "--[no-]dds".');
}
@@ -444,8 +444,8 @@ abstract class FlutterCommand extends Command<void> {
return ddsEnabled;
}();
bool get _hostVmServicePortProvided => argResults?.wasParsed('observatory-port') == true ||
argResults?.wasParsed('host-vmservice-port') == true;
bool get _hostVmServicePortProvided => (argResults?.wasParsed('observatory-port') ?? false)
|| (argResults?.wasParsed('host-vmservice-port') ?? false);
int _tryParseHostVmservicePort() {
final String? observatoryPort = stringArg('observatory-port');
@@ -464,7 +464,7 @@ abstract class FlutterCommand extends Command<void> {
if (argResults?.wasParsed('dds-port') != true && _hostVmServicePortProvided) {
// If an explicit DDS port is _not_ provided, use the host-vmservice-port for DDS.
return _tryParseHostVmservicePort();
} else if (argResults?.wasParsed('dds-port') == true) {
} else if (argResults?.wasParsed('dds-port') ?? false) {
// If an explicit DDS port is provided, use dds-port for DDS.
return int.tryParse(stringArg('dds-port')!) ?? 0;
}
@@ -473,7 +473,7 @@ abstract class FlutterCommand extends Command<void> {
}
Uri? get devToolsServerAddress {
if (argResults?.wasParsed(kDevToolsServerAddress) == true) {
if (argResults?.wasParsed(kDevToolsServerAddress) ?? false) {
final Uri? uri = Uri.tryParse(stringArg(kDevToolsServerAddress)!);
if (uri != null && uri.host.isNotEmpty && uri.port != 0) {
return uri;
@@ -493,8 +493,8 @@ abstract class FlutterCommand extends Command<void> {
if (!_usesPortOption || !_hostVmServicePortProvided) {
return null;
}
if (argResults?.wasParsed('observatory-port') == true &&
argResults?.wasParsed('host-vmservice-port') == true) {
if ((argResults?.wasParsed('observatory-port') ?? false)
&& (argResults?.wasParsed('host-vmservice-port') ?? false)) {
throwToolExit('Only one of "--observatory-port" and '
'"--host-vmservice-port" may be specified.');
}
@@ -612,8 +612,8 @@ abstract class FlutterCommand extends Command<void> {
bool get reportNullSafety => false;
late final Duration? deviceDiscoveryTimeout = () {
if (argResults?.options.contains(FlutterOptions.kDeviceTimeout) == true
&& argResults?.wasParsed(FlutterOptions.kDeviceTimeout) == true) {
if ((argResults?.options.contains(FlutterOptions.kDeviceTimeout) ?? false)
&& (argResults?.wasParsed(FlutterOptions.kDeviceTimeout) ?? false)) {
final int? timeoutSeconds = int.tryParse(stringArg(FlutterOptions.kDeviceTimeout)!);
if (timeoutSeconds == null) {
throwToolExit( 'Could not parse "--${FlutterOptions.kDeviceTimeout}" argument. It must be an integer.');
@@ -1000,7 +1000,7 @@ abstract class FlutterCommand extends Command<void> {
// Explicitly check for `true` and `false` so that `null` results in not
// passing a flag. Examine the entrypoint file to determine if it
// is opted in or out.
final bool wasNullSafetyFlagParsed = argResults?.wasParsed(FlutterOptions.kNullSafety) == true;
final bool wasNullSafetyFlagParsed = argResults?.wasParsed(FlutterOptions.kNullSafety) ?? false;
if (!wasNullSafetyFlagParsed && (argParser.options.containsKey('target') || forcedTargetFile != null)) {
final File entrypointFile = forcedTargetFile ?? globals.fs.file(targetFile);
final LanguageVersion languageVersion = determineLanguageVersion(

View File

@@ -205,12 +205,12 @@ class FlutterCommandRunner extends CommandRunner<void> {
wrapColumn: wrapColumn,
);
if ((topLevelResults['show-test-device'] as bool?) == true ||
topLevelResults['device-id'] == FlutterTesterDevices.kTesterDeviceId) {
if (((topLevelResults['show-test-device'] as bool?) ?? false)
|| topLevelResults['device-id'] == FlutterTesterDevices.kTesterDeviceId) {
FlutterTesterDevices.showFlutterTesterDevice = true;
}
if ((topLevelResults['show-web-server-device'] as bool?) == true ||
topLevelResults['device-id'] == WebServerDevice.kWebServerDeviceId) {
if (((topLevelResults['show-web-server-device'] as bool?) ?? false)
|| topLevelResults['device-id'] == WebServerDevice.kWebServerDeviceId) {
WebServerDevice.showWebServerDevice = true;
}
@@ -231,13 +231,13 @@ class FlutterCommandRunner extends CommandRunner<void> {
return MapEntry<Type, Generator>(type, () => value);
}),
body: () async {
globals.logger.quiet = (topLevelResults['quiet'] as bool?) == true;
globals.logger.quiet = (topLevelResults['quiet'] as bool?) ?? false;
if (globals.platform.environment['FLUTTER_ALREADY_LOCKED'] != 'true') {
await globals.cache.lock();
}
if ((topLevelResults['suppress-analytics'] as bool?) == true) {
if ((topLevelResults['suppress-analytics'] as bool?) ?? false) {
globals.flutterUsage.suppressAnalytics = true;
}
@@ -258,7 +258,7 @@ class FlutterCommandRunner extends CommandRunner<void> {
// See if the user specified a specific device.
globals.deviceManager?.specifiedDeviceId = topLevelResults['device-id'] as String?;
if ((topLevelResults['version'] as bool?) == true) {
if ((topLevelResults['version'] as bool?) ?? false) {
globals.flutterUsage.sendCommand('version');
globals.flutterVersion.fetchTagsAndUpdate();
String status;