Skip to content

Commit

Permalink
Update to Dart 3.7 and reformat with tall style (#228)
Browse files Browse the repository at this point in the history
* Update to Dart 3.7 and reformat with tall style

* Remove require_trailing_commas lint
  • Loading branch information
parlough authored Feb 13, 2025
1 parent e8242b8 commit 9f4e82e
Show file tree
Hide file tree
Showing 46 changed files with 348 additions and 341 deletions.
11 changes: 7 additions & 4 deletions command_line/bin/github_activity.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,16 @@ void main(List<String> args) {
}

var fetcher = ActivityService(
options.user!, options.verbose!, options.interval,
formatter: _getFormatter(options));
options.user!,
options.verbose!,
options.interval,
formatter: _getFormatter(options),
);

// Stream the github activity to the console
fetcher.getActivityStrings().listen((s) {
print(s);
})
print(s);
})
..onDone(() => exit(0))
..onError((e) => print('Unable to fetch stats:\n$e'));
}
Expand Down
8 changes: 6 additions & 2 deletions command_line/lib/github_activity.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,12 @@ class ActivityService {
final EventFormatter formatter;
static const _supportedEventTypes = ['PullRequestEvent', 'IssuesEvent'];

ActivityService(this.username, this.verbose, this.interval,
{this.formatter = const DefaultEventFormatter()});
ActivityService(
this.username,
this.verbose,
this.interval, {
this.formatter = const DefaultEventFormatter(),
});

/// Returns a stream of formatted lines for printing to the console.
Stream<String> getActivityStrings() async* {
Expand Down
18 changes: 10 additions & 8 deletions command_line/lib/src/options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ class Options {
final bool? verbose;

@CliOption(
abbr: 'f',
help: 'The format to display. Defaults to '
'"Friday, October 18 at 13:55 PM: <User> opened <URL>"',
allowed: ['default', 'markdown'])
abbr: 'f',
help:
'The format to display. Defaults to '
'"Friday, October 18 at 13:55 PM: <User> opened <URL>"',
allowed: ['default', 'markdown'],
)
final String? format;

@CliOption(abbr: 'h', negatable: false, help: 'Prints usage information.')
Expand All @@ -47,8 +49,8 @@ enum Interval {
month;

Duration get duration => switch (this) {
Interval.day => const Duration(days: 1),
Interval.week => const Duration(days: 7),
Interval.month => const Duration(days: 30),
};
Interval.day => const Duration(days: 1),
Interval.week => const Duration(days: 7),
Interval.month => const Duration(days: 30),
};
}
88 changes: 42 additions & 46 deletions command_line/lib/src/options.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 12 additions & 12 deletions command_line/lib/src/util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,22 @@ import 'options.dart';
String? extractAction(Event event) => event.payload!['action'];

String? extractUrl(Event event) => switch (event.type) {
'PullRequestEvent' => event.payload!['pull_request']['html_url'],
'IssuesEvent' => event.payload!['issue']['html_url'],
_ => null,
};
'PullRequestEvent' => event.payload!['pull_request']['html_url'],
'IssuesEvent' => event.payload!['issue']['html_url'],
_ => null,
};

String? extractTitle(Event event) => switch (event.type) {
'PullRequestEvent' => event.payload!['pull_request']['title'],
'IssuesEvent' => event.payload!['issue']['title'],
_ => null,
};
'PullRequestEvent' => event.payload!['pull_request']['title'],
'IssuesEvent' => event.payload!['issue']['title'],
_ => null,
};

int? extractIssueNumber(Event event) => switch (event.type) {
'PullRequestEvent' => event.payload!['pull_request']['number'],
'IssuesEvent' => event.payload!['issue']['number'],
_ => null,
};
'PullRequestEvent' => event.payload!['pull_request']['number'],
'IssuesEvent' => event.payload!['issue']['number'],
_ => null,
};

bool isTooOld(DateTime? date, Interval interval) =>
date?.isBefore(DateTime.now().subtract(interval.duration)) ?? true;
2 changes: 1 addition & 1 deletion command_line/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ description: >-
publish_to: none

environment:
sdk: ^3.5.0
sdk: ^3.7.0

dependencies:
args: ^2.5.0
Expand Down
10 changes: 6 additions & 4 deletions command_line/test/github_stats_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ void main() {
payload: {
'action': 'closed',
'pull_request': {
'html_url': 'https://github.com/peermaps/random-slicing/issues/2'
'html_url': 'https://github.com/peermaps/random-slicing/issues/2',
},
},
org: org,
Expand All @@ -32,8 +32,10 @@ void main() {
// Don't check exact date since it is formatted as local time.
expect(output, contains('Tuesday, October 1 at '));
expect(
output,
contains(
'substack closed https://github.com/peermaps/random-slicing/issues/2'));
output,
contains(
'substack closed https://github.com/peermaps/random-slicing/issues/2',
),
);
});
}
6 changes: 1 addition & 5 deletions enhanced_enums/lib/comparable_mixin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
// BSD-style license that can be found in the LICENSE file.

/// Enum that implements a Comparable using a mixin
enum Ordering with EnumIndexOrdering<Ordering> {
zero,
few,
many;
}
enum Ordering with EnumIndexOrdering<Ordering> { zero, few, many }

/// Mixin that uses the enum index to create a comparable
mixin EnumIndexOrdering<T extends Enum> on Enum implements Comparable<T> {
Expand Down
2 changes: 1 addition & 1 deletion enhanced_enums/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description: Samples that demonstrates the enhanced enums syntax
publish_to: none

environment:
sdk: ^3.5.0
sdk: ^3.7.0

dev_dependencies:
lints: ^5.0.0
Expand Down
4 changes: 2 additions & 2 deletions extension_methods/example/fluid_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ void main() {

extension on Group {
void removeYoungest() {
var sorted = people.toList()
..sort((a, b) => a.dayOfBirth.compareTo(b.dayOfBirth));
var sorted =
people.toList()..sort((a, b) => a.dayOfBirth.compareTo(b.dayOfBirth));
var youngest = sorted.last;
people.remove(youngest);
}
Expand Down
5 changes: 1 addition & 4 deletions extension_methods/example/json_helpers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@
///
/// This might create a false sense of (type) security, so use with caution.
void main() {
var json = {
'id': 100,
'name': 'Dash',
};
var json = {'id': 100, 'name': 'Dash'};

print("${json.name}'s ID is ${json.id}."); // Dash's ID is 100.
}
Expand Down
2 changes: 1 addition & 1 deletion extension_methods/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ description: >-
publish_to: none

environment:
sdk: ^3.5.0
sdk: ^3.7.0

dev_dependencies:
lints: ^5.0.0
Expand Down
27 changes: 19 additions & 8 deletions ffi/hello_world/hello.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,36 @@ typedef HelloWorld = void Function();

void main() {
// Open the dynamic library
var libraryPath =
path.join(Directory.current.path, 'hello_library', 'libhello.so');
var libraryPath = path.join(
Directory.current.path,
'hello_library',
'libhello.so',
);

if (Platform.isMacOS) {
libraryPath =
path.join(Directory.current.path, 'hello_library', 'libhello.dylib');
libraryPath = path.join(
Directory.current.path,
'hello_library',
'libhello.dylib',
);
}

if (Platform.isWindows) {
libraryPath = path.join(
Directory.current.path, 'hello_library', 'Debug', 'hello.dll');
Directory.current.path,
'hello_library',
'Debug',
'hello.dll',
);
}

final dylib = ffi.DynamicLibrary.open(libraryPath);

// Look up the C function 'hello_world'
final HelloWorld hello = dylib
.lookup<ffi.NativeFunction<HelloWorldFunc>>('hello_world')
.asFunction();
final HelloWorld hello =
dylib
.lookup<ffi.NativeFunction<HelloWorldFunc>>('hello_world')
.asFunction();
// Call the function
hello();
}
2 changes: 1 addition & 1 deletion ffi/hello_world/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ description: >-
publish_to: none

environment:
sdk: ^3.5.0
sdk: ^3.7.0

dependencies:
path: ^1.9.0
Expand Down
12 changes: 8 additions & 4 deletions ffi/hello_world/test/hello_world_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@ void main() async {
group('hello_world', () {
test('make dylib + execute', () async {
// run 'cmake .'
var cmake =
await Process.run('cmake', ['.'], workingDirectory: 'hello_library');
var cmake = await Process.run('cmake', [
'.',
], workingDirectory: 'hello_library');
expect(cmake.exitCode, 0);

// run 'make'
var make =
await Process.run('make', [], workingDirectory: 'hello_library');
var make = await Process.run(
'make',
[],
workingDirectory: 'hello_library',
);
expect(make.exitCode, 0);

var filePath = getLibraryFilePath('hello_library', 'hello');
Expand Down
Loading

0 comments on commit 9f4e82e

Please sign in to comment.