Skip to content
This repository has been archived by the owner on Oct 17, 2024. It is now read-only.

Commit

Permalink
Require Dart 2.18, update lints, update CI, add dependabot (#222)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevmoo authored Oct 20, 2022
1 parent 80d4abb commit aaf671c
Show file tree
Hide file tree
Showing 18 changed files with 125 additions and 107 deletions.
10 changes: 10 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Set update schedule for GitHub Actions
# See https://docs.github.com/en/github/administering-a-repository/keeping-your-actions-up-to-date-with-dependabot

version: 2
updates:

- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "monthly"
10 changes: 5 additions & 5 deletions .github/workflows/test-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ jobs:
matrix:
sdk: [dev]
steps:
- uses: actions/checkout@v2
- uses: dart-lang/setup-dart@v1.0
- uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8
- uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d
with:
sdk: ${{ matrix.sdk }}
- id: install
Expand All @@ -47,10 +47,10 @@ jobs:
# Add macos-latest and/or windows-latest if relevant for this package
os: [ubuntu-latest]
# Add stable if the package should also be tested on stable
sdk: [2.12.0, dev]
sdk: [2.18.0, dev]
steps:
- uses: actions/checkout@v2
- uses: dart-lang/setup-dart@v1.0
- uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8
- uses: dart-lang/setup-dart@6a218f2413a3e78e9087f638a238f6b40893203d
with:
sdk: ${{ matrix.sdk }}
- id: install
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.3.2-dev

* Require Dart 2.18

## 2.3.1

* Switch to using package:lints.
Expand Down
37 changes: 16 additions & 21 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,32 +1,27 @@
# https://dart.dev/guides/language/analysis-options
include: package:lints/recommended.yaml

linter:
rules:
- avoid_null_checks_in_equality_operators
- always_declare_return_types
- avoid_dynamic_calls
- avoid_unused_constructor_parameters
- await_only_futures
- camel_case_types
- cancel_subscriptions
- comment_references
- constant_identifier_names
- control_flow_in_finally
- directives_ordering
- empty_statements
- hash_and_equals
- implementation_imports
- iterable_contains_unrelated_type
- library_names
- library_prefixes
- list_remove_unrelated_type
- non_constant_identifier_names
- overridden_fields
- lines_longer_than_80_chars
- literal_only_boolean_expressions
- missing_whitespace_between_adjacent_strings
- no_adjacent_strings_in_list
- no_runtimeType_toString
- omit_local_variable_types
- package_api_docs
- package_names
- package_prefixed_library_names
- prefer_final_fields
- prefer_generic_function_type_aliases
- prefer_typing_uninitialized_variables
- prefer_relative_imports
- prefer_single_quotes
- test_types_in_equals
- throw_in_finally
- unnecessary_brace_in_string_interps
- unrelated_type_equality_checks
- type_annotate_public_apis
- unawaited_futures
- unnecessary_await_in_return
- unnecessary_lambdas
- use_super_parameters
1 change: 0 additions & 1 deletion example/arg_parser/example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ void main() {
allowedHelp: {
'vm': 'Run Dart code on the standalone dart vm.',
'd8': 'Run JavaScript from the command line using v8.',
// TODO(antonm): rename flag.
'drt': 'Run Dart or JavaScript in the headless version of Chrome,\n'
'content shell.',
'dartium': 'Run Dart or JavaScript in Dartium.',
Expand Down
12 changes: 6 additions & 6 deletions example/command_runner/draw.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class SquareCommand extends Command<String> {
@override
FutureOr<String>? run() {
final size = int.parse(argResults?['size'] ?? '20');
final char = globalResults?['char']?[0] ?? '#';
final char = (globalResults?['char'] as String?)?[0] ?? '#';
return draw(size, size, char, (x, y) => true);
}
}
Expand All @@ -56,7 +56,7 @@ class CircleCommand extends Command<String> {
@override
FutureOr<String>? run() {
final size = 2 * int.parse(argResults?['radius'] ?? '10');
final char = globalResults?['char']?[0] ?? '#';
final char = (globalResults?['char'] as String?)?[0] ?? '#';
return draw(size, size, char, (x, y) => x * x + y * y < 1);
}
}
Expand Down Expand Up @@ -94,7 +94,7 @@ class EquilateralTriangleCommand extends Command<String> {
@override
FutureOr<String>? run() {
final size = int.parse(argResults?['size'] ?? '20');
final char = globalResults?['char']?[0] ?? '#';
final char = (globalResults?['char'] as String?)?[0] ?? '#';
return drawTriangle(size, size * sqrt(3) ~/ 2, char);
}
}
Expand All @@ -118,17 +118,17 @@ class IsoscelesTriangleCommand extends Command<String> {
FutureOr<String>? run() {
final width = int.parse(argResults?['width'] ?? '50');
final height = int.parse(argResults?['height'] ?? '10');
final char = globalResults?['char']?[0] ?? '#';
final char = (globalResults?['char'] as String?)?[0] ?? '#';
return drawTriangle(width, height, char);
}
}

String draw(
int width, int height, String char, bool Function(double, double) pixel) {
final out = StringBuffer();
for (int y = 0; y <= height; ++y) {
for (var y = 0; y <= height; ++y) {
final ty = 2 * y / height - 1;
for (int x = 0; x <= width; ++x) {
for (var x = 0; x <= width; ++x) {
final tx = 2 * x / width - 1;
out.write(pixel(tx, ty) ? char : ' ');
}
Expand Down
9 changes: 6 additions & 3 deletions lib/command_runner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,16 @@ class CommandRunner<T> {
var usagePrefix = 'Usage:';
var buffer = StringBuffer();
buffer.writeln(
'$usagePrefix ${_wrap(invocation, hangingIndent: usagePrefix.length)}\n');
'$usagePrefix ${_wrap(invocation, hangingIndent: usagePrefix.length)}\n',
);
buffer.writeln(_wrap('Global options:'));
buffer.writeln('${argParser.usage}\n');
buffer.writeln(
'${_getCommandUsage(_commands, lineLength: argParser.usageLineLength)}\n');
'${_getCommandUsage(_commands, lineLength: argParser.usageLineLength)}\n',
);
buffer.write(_wrap(
'Run "$executableName help <command>" for more information about a command.'));
'Run "$executableName help <command>" for more information about a '
'command.'));
if (usageFooter != null) {
buffer.write('\n${_wrap(usageFooter!)}');
}
Expand Down
5 changes: 2 additions & 3 deletions lib/src/arg_parser_exception.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ class ArgParserException extends FormatException {
/// This will be empty if the error was on the root parser.
final List<String> commands;

ArgParserException(String message, [Iterable<String>? commands])
: commands = commands == null ? const [] : List.unmodifiable(commands),
super(message);
ArgParserException(super.message, [Iterable<String>? commands])
: commands = commands == null ? const [] : List.unmodifiable(commands);
}
6 changes: 2 additions & 4 deletions lib/src/help_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ class HelpCommand<T> extends Command<T> {
bool get hidden => true;

@override
// TODO: Remove when https://github.com/dart-lang/linter/issues/2792 is fixed.
// ignore: prefer_void_to_null
Null run() {
// Show the default help if no command was specified.
if (argResults!.rest.isEmpty) {
Expand All @@ -34,7 +32,7 @@ class HelpCommand<T> extends Command<T> {
// Walk the command tree to show help for the selected command or
// subcommand.
var commands = runner!.commands;
Command? command;
Command<T>? command;
var commandString = runner!.executableName;

for (var name in argResults!.rest) {
Expand All @@ -53,7 +51,7 @@ class HelpCommand<T> extends Command<T> {
}

command = commands[name];
commands = command!.subcommands as Map<String, Command<T>>;
commands = command!.subcommands;
commandString += ' $name';
}

Expand Down
6 changes: 3 additions & 3 deletions lib/src/option.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Option newOption(
String? valueHelp,
Iterable<String>? allowed,
Map<String, String>? allowedHelp,
defaultsTo,
Object? defaultsTo,
Function? callback,
OptionType type,
{bool? negatable,
Expand Down Expand Up @@ -146,14 +146,14 @@ class Option {
/// For single-valued options, it will be [defaultsTo] if set or `null`
/// otherwise. For multiple-valued options, it will be an empty list or a
/// list containing [defaultsTo] if set.
dynamic valueOrDefault(value) {
dynamic valueOrDefault(Object? value) {
if (value != null) return value;
if (isMultiple) return defaultsTo ?? <String>[];
return defaultsTo;
}

@Deprecated('Use valueOrDefault instead.')
dynamic getOrDefault(value) => valueOrDefault(value);
dynamic getOrDefault(Object? value) => valueOrDefault(value);

static final _invalidChars = RegExp(r'''[ \t\r\n"'\\/]''');
}
Expand Down
3 changes: 2 additions & 1 deletion lib/src/parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ class Parser {

var callback = option.callback;
if (callback == null) return;
// ignore: avoid_dynamic_calls
callback(option.valueOrDefault(parsedOption));
});

Expand Down Expand Up @@ -320,7 +321,7 @@ class Parser {
return;
}

var list = results.putIfAbsent(option.name, () => <String>[]);
var list = results.putIfAbsent(option.name, () => <String>[]) as List;

if (option.splitCommas) {
for (var element in value.split(',')) {
Expand Down
9 changes: 5 additions & 4 deletions lib/src/usage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ class _Usage {
_write(2, '(defaults to on)');
}
} else if (option.isMultiple) {
if (option.defaultsTo != null && option.defaultsTo.isNotEmpty) {
if (option.defaultsTo != null &&
(option.defaultsTo as Iterable).isNotEmpty) {
var defaults =
(option.defaultsTo as List).map((value) => '"$value"').join(', ');
_write(2, '(defaults to $defaults)');
Expand Down Expand Up @@ -137,9 +138,9 @@ class _Usage {

String _allowedTitle(Option option, String allowed) {
var isDefault = option.defaultsTo is List
? option.defaultsTo.contains(allowed)
? (option.defaultsTo as List).contains(allowed)
: option.defaultsTo == allowed;
return ' [$allowed]' + (isDefault ? ' (default)' : '');
return ' [$allowed]${isDefault ? ' (default)' : ''}';
}

List<int> _calculateColumnWidths() {
Expand Down Expand Up @@ -234,7 +235,7 @@ class _Usage {

String _buildAllowedList(Option option) {
var isDefault = option.defaultsTo is List
? option.defaultsTo.contains
? (option.defaultsTo as List).contains
: (value) => value == option.defaultsTo;

var allowedBuffer = StringBuffer();
Expand Down
4 changes: 3 additions & 1 deletion lib/src/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ String padRight(String source, int length) =>
///
/// ```dart
/// var prefix = "Usage: ";
/// print(prefix + wrapText(invocation, hangingIndent: prefix.length, length: 40));
/// print(
/// prefix + wrapText(invocation, hangingIndent: prefix.length, length: 40),
/// );
/// ```
///
/// yields:
Expand Down
6 changes: 3 additions & 3 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
name: args
version: 2.3.1
version: 2.3.2-dev
description: >-
Library for defining parsers for parsing raw command-line arguments into a set
of options and values using GNU and POSIX style options.
repository: https://github.com/dart-lang/args

environment:
sdk: '>=2.12.0 <3.0.0'
sdk: '>=2.18.0 <3.0.0'

dev_dependencies:
lints: ^1.0.0
lints: ^2.0.0
test: ^1.16.0
15 changes: 9 additions & 6 deletions test/parse_performance_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,15 @@ void _testParserPerformance(ArgParser parser, String string) {
print('Parsed $baseSize elements in ${baseTime}ms, '
'${baseSize * multiplier} elements in ${largeTime}ms.');

expect(largeTime, lessThan(baseTime * multiplier * 3),
reason:
'Comparing large data set time ${largeTime}ms to small data set time '
'${baseTime}ms. Data set increased ${multiplier}x, time is allowed to '
'increase up to ${multiplier * 3}x, but it increased '
'${largeTime ~/ baseTime}x.');
expect(
largeTime,
lessThan(baseTime * multiplier * 3),
reason:
'Comparing large data set time ${largeTime}ms to small data set time '
'${baseTime}ms. Data set increased ${multiplier}x, time is allowed to '
'increase up to ${multiplier * 3}x, but it increased '
'${largeTime ~/ baseTime}x.',
);
}

int _time(void Function() function) {
Expand Down
Loading

0 comments on commit aaf671c

Please sign in to comment.