-
Notifications
You must be signed in to change notification settings - Fork 82
Migrate configuration.dart
and shared.dart
to null-safety
#1757
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
560160c
Start migration of WebDev to null-safety
elliette 93d8e9c
Migrate configuration.dart and shared.dart to null-safety
elliette 86b2a27
Make ints non-nullable
elliette 955a316
Resolve merge conflicts
elliette 7b7119f
Respond to PR comments
elliette File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,8 +2,6 @@ | |
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
// @dart = 2.9 | ||
|
||
import 'package:args/args.dart'; | ||
import 'package:dwds/dwds.dart'; | ||
import 'package:logging/logging.dart'; | ||
|
@@ -40,13 +38,13 @@ const disableDdsFlag = 'disable-dds'; | |
|
||
ReloadConfiguration _parseReloadConfiguration(ArgResults argResults) { | ||
var auto = argResults.options.contains(autoOption) | ||
? argResults[autoOption] as String | ||
? argResults[autoOption] as String? | ||
: null; | ||
|
||
void _handleDeprecatedFlag(String flag, String autoFallback) { | ||
if (argResults.options.contains(flag) && | ||
argResults.wasParsed(flag) && | ||
argResults[flag] as bool == true) { | ||
argResults[flag].toUpperCase() == 'TRUE') { | ||
logWriter( | ||
Level.WARNING, | ||
'--$flag is deprecated please use --auto=$autoFallback instead ' | ||
|
@@ -83,52 +81,52 @@ ReloadConfiguration _parseReloadConfiguration(ArgResults argResults) { | |
} | ||
|
||
class Configuration { | ||
final bool _autoRun; | ||
final int _chromeDebugPort; | ||
final bool _debugExtension; | ||
final bool _debug; | ||
final bool _enableInjectedClient; | ||
final String _hostname; | ||
final String _tlsCertChain; | ||
final String _tlsCertKey; | ||
final List<String> _launchApps; | ||
final bool _launchInChrome; | ||
final String _userDataDir; | ||
final bool _logRequests; | ||
final String _output; | ||
final String outputInput; | ||
final String outputPath; | ||
final bool _release; | ||
final ReloadConfiguration _reload; | ||
final bool _requireBuildWebCompilers; | ||
final bool _enableExpressionEvaluation; | ||
final bool _verbose; | ||
final bool _disableDds; | ||
final String _nullSafety; | ||
final bool? _autoRun; | ||
elliette marked this conversation as resolved.
Show resolved
Hide resolved
|
||
final int? _chromeDebugPort; | ||
final bool? _debugExtension; | ||
final bool? _debug; | ||
final bool? _enableInjectedClient; | ||
final String? _hostname; | ||
final String? _tlsCertChain; | ||
final String? _tlsCertKey; | ||
final List<String>? _launchApps; | ||
final bool? _launchInChrome; | ||
final String? _userDataDir; | ||
final bool? _logRequests; | ||
final String? _output; | ||
final String? outputInput; | ||
final String? outputPath; | ||
final bool? _release; | ||
final ReloadConfiguration? _reload; | ||
final bool? _requireBuildWebCompilers; | ||
final bool? _enableExpressionEvaluation; | ||
final bool? _verbose; | ||
final bool? _disableDds; | ||
final String? _nullSafety; | ||
|
||
Configuration({ | ||
bool autoRun, | ||
int chromeDebugPort, | ||
bool debugExtension, | ||
bool debug, | ||
bool enableInjectedClient, | ||
String hostname, | ||
String tlsCertChain, | ||
String tlsCertKey, | ||
List<String> launchApps, | ||
bool launchInChrome, | ||
String userDataDir, | ||
bool logRequests, | ||
String output, | ||
bool? autoRun, | ||
int? chromeDebugPort, | ||
bool? debugExtension, | ||
bool? debug, | ||
bool? enableInjectedClient, | ||
String? hostname, | ||
String? tlsCertChain, | ||
String? tlsCertKey, | ||
List<String>? launchApps, | ||
bool? launchInChrome, | ||
String? userDataDir, | ||
bool? logRequests, | ||
String? output, | ||
this.outputInput, | ||
this.outputPath, | ||
ReloadConfiguration reload, | ||
bool release, | ||
bool requireBuildWebCompilers, | ||
bool enableExpressionEvaluation, | ||
bool verbose, | ||
bool disableDds, | ||
String nullSafety, | ||
ReloadConfiguration? reload, | ||
bool? release, | ||
bool? requireBuildWebCompilers, | ||
bool? enableExpressionEvaluation, | ||
bool? verbose, | ||
bool? disableDds, | ||
String? nullSafety, | ||
}) : _autoRun = autoRun, | ||
_chromeDebugPort = chromeDebugPort, | ||
_debugExtension = debugExtension, | ||
|
@@ -155,7 +153,7 @@ class Configuration { | |
void _validateConfiguration() { | ||
// Both null and an empty string are valid values for outputInput. For any | ||
// other value, we need to ensure it's a top-level dir. | ||
if (outputInput?.isNotEmpty ?? false) ensureIsTopLevelDir(outputInput); | ||
if (outputInput?.isNotEmpty ?? false) ensureIsTopLevelDir(outputInput!); | ||
|
||
if ((tlsCertKey != null && tlsCertChain == null) || | ||
(tlsCertKey == null && tlsCertChain != null)) { | ||
|
@@ -241,15 +239,15 @@ class Configuration { | |
|
||
String get hostname => _hostname ?? 'localhost'; | ||
|
||
String get tlsCertChain => _tlsCertChain; | ||
String? get tlsCertChain => _tlsCertChain; | ||
elliette marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
String get tlsCertKey => _tlsCertKey; | ||
String? get tlsCertKey => _tlsCertKey; | ||
annagrin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
List<String> get launchApps => _launchApps ?? []; | ||
|
||
bool get launchInChrome => _launchInChrome ?? false; | ||
|
||
String get userDataDir => _userDataDir; | ||
String? get userDataDir => _userDataDir; | ||
annagrin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
bool get logRequests => _logRequests ?? false; | ||
|
||
|
@@ -270,17 +268,17 @@ class Configuration { | |
/// 'sound', 'unsound', or 'auto'. | ||
/// 'auto' indicates that the default `package:build_web_compilers` | ||
/// behavior should be used. | ||
String get nullSafety => _nullSafety; | ||
String? get nullSafety => _nullSafety; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this feels non-nullable - can we return There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, done! |
||
|
||
/// Returns a new configuration with values updated from the parsed args. | ||
static Configuration fromArgs(ArgResults argResults, | ||
{Configuration defaultConfiguration}) { | ||
static Configuration fromArgs(ArgResults? argResults, | ||
{Configuration? defaultConfiguration}) { | ||
defaultConfiguration ??= Configuration(); | ||
if (argResults == null) return defaultConfiguration; | ||
|
||
var enableInjectedClient = | ||
argResults.options.contains(enableInjectedClientFlag) | ||
? argResults[enableInjectedClientFlag] as bool | ||
? (argResults[enableInjectedClientFlag] as bool) | ||
: defaultConfiguration.enableInjectedClient; | ||
|
||
// Change the defaults when we have no injected client to disable all | ||
|
@@ -297,56 +295,56 @@ class Configuration { | |
: defaultConfiguration.chromeDebugPort; | ||
|
||
var debugExtension = argResults.options.contains(debugExtensionFlag) | ||
? argResults[debugExtensionFlag] as bool | ||
? argResults[debugExtensionFlag] as bool? | ||
: defaultConfiguration.debugExtension; | ||
|
||
var debug = argResults.options.contains(debugFlag) | ||
? argResults[debugFlag] as bool | ||
? argResults[debugFlag] as bool? | ||
: defaultConfiguration.debug; | ||
|
||
var hostname = argResults.options.contains(hostnameFlag) | ||
? argResults[hostnameFlag] as String | ||
? argResults[hostnameFlag] as String? | ||
: defaultConfiguration.hostname; | ||
|
||
var tlsCertChain = argResults.options.contains(tlsCertChainFlag) | ||
? argResults[tlsCertChainFlag] as String | ||
? argResults[tlsCertChainFlag] as String? | ||
: defaultConfiguration.tlsCertChain; | ||
|
||
var tlsCertKey = argResults.options.contains(tlsCertKeyFlag) | ||
? argResults[tlsCertKeyFlag] as String | ||
? argResults[tlsCertKeyFlag] as String? | ||
annagrin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
: defaultConfiguration.tlsCertKey; | ||
|
||
var launchApps = argResults.options.contains(launchAppOption) && | ||
argResults.wasParsed(launchAppOption) | ||
? argResults[launchAppOption] as List<String> | ||
? argResults[launchAppOption] as List<String>? | ||
: defaultConfiguration.launchApps; | ||
|
||
var launchInChrome = argResults.options.contains(launchInChromeFlag) && | ||
argResults.wasParsed(launchInChromeFlag) | ||
? argResults[launchInChromeFlag] as bool | ||
? argResults[launchInChromeFlag] as bool? | ||
// We want to default to launch chrome if the user provides just --debug | ||
// and not --chrome-debug-port. | ||
: debug && | ||
: debug! && | ||
!(argResults.options.contains(launchInChromeFlag) && | ||
argResults.wasParsed(chromeDebugPortFlag)) | ||
? true | ||
: defaultConfiguration.launchInChrome; | ||
|
||
var userDataDir = argResults.options.contains(userDataDirFlag) | ||
? argResults[userDataDirFlag] as String | ||
? argResults[userDataDirFlag] as String? | ||
: defaultConfiguration.userDataDir; | ||
|
||
var logRequests = argResults.options.contains(logRequestsFlag) | ||
? argResults[logRequestsFlag] as bool | ||
? argResults[logRequestsFlag] as bool? | ||
: defaultConfiguration.logRequests; | ||
|
||
var output = argResults.options.contains(outputFlag) | ||
? argResults[outputFlag] as String | ||
? argResults[outputFlag] as String? | ||
: defaultConfiguration.output; | ||
|
||
String outputPath; | ||
String? outputPath; | ||
String outputInput; | ||
if (output == 'NONE') { | ||
if (output == 'NONE' || output == null) { | ||
// The empty string means build everything. | ||
outputInput = ''; | ||
} else { | ||
|
@@ -362,29 +360,29 @@ class Configuration { | |
} | ||
|
||
var release = argResults.options.contains(releaseFlag) | ||
? argResults[releaseFlag] as bool | ||
? argResults[releaseFlag] as bool? | ||
: defaultConfiguration.release; | ||
|
||
var requireBuildWebCompilers = | ||
argResults.options.contains(requireBuildWebCompilersFlag) | ||
? argResults[requireBuildWebCompilersFlag] as bool | ||
? argResults[requireBuildWebCompilersFlag] as bool? | ||
: defaultConfiguration.requireBuildWebCompilers; | ||
|
||
var enableExpressionEvaluation = | ||
argResults.options.contains(enableExpressionEvaluationFlag) | ||
? argResults[enableExpressionEvaluationFlag] as bool | ||
? argResults[enableExpressionEvaluationFlag] as bool? | ||
: defaultConfiguration.enableExpressionEvaluation; | ||
|
||
var verbose = argResults.options.contains(verboseFlag) | ||
? argResults[verboseFlag] as bool | ||
? argResults[verboseFlag] as bool? | ||
: defaultConfiguration.verbose; | ||
|
||
var nullSafety = argResults.options.contains(nullSafetyFlag) | ||
? argResults[nullSafetyFlag] as String | ||
? argResults[nullSafetyFlag] as String? | ||
: defaultConfiguration.nullSafety; | ||
|
||
var disableDds = argResults.options.contains(disableDdsFlag) | ||
? argResults[disableDdsFlag] as bool | ||
? argResults[disableDdsFlag] as bool? | ||
: defaultConfiguration.disableDds; | ||
|
||
return Configuration( | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.