Skip to content

Migrate away from specifying deprecated strong mode options #410

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ analyzer:
exclude:
- test/**/fixtures/**
language:
strict-casts: true
strict-inference: true
strict-raw-types: true
strong-mode:
implicit-casts: true
implicit-dynamic: true

linter:
rules:
Expand Down
2 changes: 1 addition & 1 deletion lib/src/dart_dev_runner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class DartDevRunner extends CommandRunner<int> {
@override
Future<int> run(Iterable<String> args) async {
final argResults = parse(args);
if (argResults['version'] ?? false) {
if (argResults['version'] as bool? ?? false) {
print(dartDevVersion);
return 0;
}
Expand Down
6 changes: 3 additions & 3 deletions lib/src/tools/compound_tool.dart
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ class CompoundArgParser implements ArgParser {
_compoundParser.addFlag(option.name,
abbr: option.abbr,
help: option.help,
defaultsTo: option.defaultsTo,
defaultsTo: option.defaultsTo as bool?,
negatable: option.negatable!,
callback: (bool value) => option.callback?.call(value),
hide: option.hide);
Expand All @@ -166,7 +166,7 @@ class CompoundArgParser implements ArgParser {
valueHelp: option.valueHelp,
allowed: option.allowed,
allowedHelp: option.allowedHelp,
defaultsTo: option.defaultsTo,
defaultsTo: option.defaultsTo as Iterable<String>?,
callback: (List<String> values) => option.callback?.call(values),
splitCommas: option.splitCommas,
hide: option.hide);
Expand All @@ -177,7 +177,7 @@ class CompoundArgParser implements ArgParser {
valueHelp: option.valueHelp,
allowed: option.allowed,
allowedHelp: option.allowedHelp,
defaultsTo: option.defaultsTo,
defaultsTo: option.defaultsTo as String?,
callback: (String? value) => option.callback?.call(value),
hide: option.hide);
}
Expand Down
6 changes: 3 additions & 3 deletions lib/src/tools/format_tool.dart
Original file line number Diff line number Diff line change
Expand Up @@ -627,9 +627,9 @@ void logCommand(
/// If none of the mode flags were enabled, this returns `null`.
FormatMode? validateAndParseMode(
ArgResults argResults, void Function(String message) usageException) {
final check = argResults['check'] ?? false;
final dryRun = argResults['dry-run'] ?? false;
final overwrite = argResults['overwrite'] ?? false;
final check = argResults['check'] as bool? ?? false;
final dryRun = argResults['dry-run'] as bool? ?? false;
final overwrite = argResults['overwrite'] as bool? ?? false;

if (check && dryRun && overwrite) {
usageException(
Expand Down
3 changes: 2 additions & 1 deletion lib/src/tools/webdev_serve_tool.dart
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ List<String> buildArgs(
// 1. Statically configured args from [WebdevServeTool.webdevArgs]
...?configuredWebdevArgs,
// 2. The -r|--release flag
if (argResults != null && argResults['release']) '--release',
if (argResults != null && (argResults['release'] as bool? ?? false))
'--release',
// 3. Args passed to --webdev-args
...?splitSingleOptionValue(argResults, 'webdev-args'),
];
Expand Down
24 changes: 15 additions & 9 deletions lib/src/utils/arg_results_utils.dart
Original file line number Diff line number Diff line change
@@ -1,33 +1,39 @@
import 'package:args/args.dart';

bool? flagValue(ArgResults? argResults, String name) {
if (argResults == null || argResults[name] == null) {
final result = argResults?[name];
if (result == null) {
return null;
}
if (argResults[name] is! bool) {

if (result is! bool) {
throw ArgumentError('Option "$name" is not a flag.');
}
return argResults[name];
return result;
}

Iterable<String>? multiOptionValue(ArgResults? argResults, String name) {
if (argResults == null || argResults[name] == null) {
final result = argResults?[name];
if (result == null) {
return null;
}
if (argResults[name] is! Iterable<String>) {

if (result is! Iterable<String>) {
throw ArgumentError('Option "$name" is not a multi-option.');
}
return List<String>.from(argResults[name]);
return List<String>.from(result);
}

String? singleOptionValue(ArgResults? argResults, String name) {
if (argResults == null || argResults[name] == null) {
final result = argResults?[name];
if (result == null) {
return null;
}
if (argResults[name] is! String) {

if (result is! String) {
throw ArgumentError('Option "$name" is not a single option.');
}
return argResults[name];
return result;
}

Iterable<String>? splitSingleOptionValue(ArgResults? argResults, String name) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ bool globalPackageIsActiveAndCompatible(
result.exitCode);
}

for (final line in result.stdout.split('\n')) {
final output = result.stdout as String;

for (final line in output.split('\n')) {
// Example line: "webdev 2.5.1" or "dart_dev 3.0.0 at path ..."
final parts = line.split(' ');
if (parts.length < 2 || parts[0] != packageName) {
Expand Down
2 changes: 1 addition & 1 deletion lib/src/utils/verbose_enabled.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:args/command_runner.dart';

bool verboseEnabled(Command<dynamic> command) =>
command.globalResults!['verbose'] ?? false;
command.globalResults!['verbose'] as bool? ?? false;