Skip to content

Commit 2c7f799

Browse files
authored
Set package:watcher language version to 3.8, reformat (#2301)
1 parent 52cc9b5 commit 2c7f799

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+910
-737
lines changed

.github/workflows/watcher.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ jobs:
5454
fail-fast: false
5555
matrix:
5656
os: [ubuntu-latest, macos-latest, windows-latest]
57-
sdk: [3.4, dev]
57+
sdk: [3.8, dev]
5858
steps:
5959
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8
6060
- uses: dart-lang/setup-dart@e51d8e571e22473a2ddebf0ef8a2123f0ab2c02c

pkgs/watcher/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 1.2.2-wip
2+
3+
- Require Dart SDK `^3.8.0`.
4+
15
## 1.2.1
26

37
- Bug fix: versions before 1.2.0 would allow and ignore a trailing path

pkgs/watcher/lib/src/async_queue.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,10 @@ class AsyncQueue<T> {
3333
/// Used to avoid top-leveling asynchronous errors.
3434
final void Function(Object, StackTrace) _errorHandler;
3535

36-
AsyncQueue(this._processor,
37-
{required void Function(Object, StackTrace) onError})
38-
: _errorHandler = onError;
36+
AsyncQueue(
37+
this._processor, {
38+
required void Function(Object, StackTrace) onError,
39+
}) : _errorHandler = onError;
3940

4041
/// Enqueues [item] to be processed and starts asynchronously processing it
4142
/// if a process isn't already running.

pkgs/watcher/lib/src/custom_watcher_factory.dart

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,15 @@ import '../watcher.dart';
88
class _CustomWatcherFactory {
99
final String id;
1010
final DirectoryWatcher? Function(String path, {Duration? pollingDelay})
11-
createDirectoryWatcher;
11+
createDirectoryWatcher;
1212
final FileWatcher? Function(String path, {Duration? pollingDelay})
13-
createFileWatcher;
13+
createFileWatcher;
1414

1515
_CustomWatcherFactory(
16-
this.id, this.createDirectoryWatcher, this.createFileWatcher);
16+
this.id,
17+
this.createDirectoryWatcher,
18+
this.createFileWatcher,
19+
);
1720
}
1821

1922
/// Registers a custom watcher.
@@ -32,35 +35,44 @@ class _CustomWatcherFactory {
3235
void registerCustomWatcher(
3336
String id,
3437
DirectoryWatcher? Function(String path, {Duration? pollingDelay})?
35-
createDirectoryWatcher,
38+
createDirectoryWatcher,
3639
FileWatcher? Function(String path, {Duration? pollingDelay})?
37-
createFileWatcher,
40+
createFileWatcher,
3841
) {
3942
if (_customWatcherFactories.containsKey(id)) {
40-
throw ArgumentError('A custom watcher with id `$id` '
41-
'has already been registered');
43+
throw ArgumentError(
44+
'A custom watcher with id `$id` '
45+
'has already been registered',
46+
);
4247
}
4348
_customWatcherFactories[id] = _CustomWatcherFactory(
44-
id,
45-
createDirectoryWatcher ?? (_, {pollingDelay}) => null,
46-
createFileWatcher ?? (_, {pollingDelay}) => null);
49+
id,
50+
createDirectoryWatcher ?? (_, {pollingDelay}) => null,
51+
createFileWatcher ?? (_, {pollingDelay}) => null,
52+
);
4753
}
4854

4955
/// Tries to create a custom [DirectoryWatcher] and returns it.
5056
///
5157
/// Returns `null` if no custom watcher was applicable and throws a [StateError]
5258
/// if more than one was.
53-
DirectoryWatcher? createCustomDirectoryWatcher(String path,
54-
{Duration? pollingDelay}) {
59+
DirectoryWatcher? createCustomDirectoryWatcher(
60+
String path, {
61+
Duration? pollingDelay,
62+
}) {
5563
DirectoryWatcher? customWatcher;
5664
String? customFactoryId;
5765
for (var watcherFactory in _customWatcherFactories.values) {
5866
if (customWatcher != null) {
59-
throw StateError('Two `CustomWatcherFactory`s applicable: '
60-
'`$customFactoryId` and `${watcherFactory.id}` for `$path`');
67+
throw StateError(
68+
'Two `CustomWatcherFactory`s applicable: '
69+
'`$customFactoryId` and `${watcherFactory.id}` for `$path`',
70+
);
6171
}
62-
customWatcher =
63-
watcherFactory.createDirectoryWatcher(path, pollingDelay: pollingDelay);
72+
customWatcher = watcherFactory.createDirectoryWatcher(
73+
path,
74+
pollingDelay: pollingDelay,
75+
);
6476
customFactoryId = watcherFactory.id;
6577
}
6678
return customWatcher;
@@ -75,11 +87,15 @@ FileWatcher? createCustomFileWatcher(String path, {Duration? pollingDelay}) {
7587
String? customFactoryId;
7688
for (var watcherFactory in _customWatcherFactories.values) {
7789
if (customWatcher != null) {
78-
throw StateError('Two `CustomWatcherFactory`s applicable: '
79-
'`$customFactoryId` and `${watcherFactory.id}` for `$path`');
90+
throw StateError(
91+
'Two `CustomWatcherFactory`s applicable: '
92+
'`$customFactoryId` and `${watcherFactory.id}` for `$path`',
93+
);
8094
}
81-
customWatcher =
82-
watcherFactory.createFileWatcher(path, pollingDelay: pollingDelay);
95+
customWatcher = watcherFactory.createFileWatcher(
96+
path,
97+
pollingDelay: pollingDelay,
98+
);
8399
customFactoryId = watcherFactory.id;
84100
}
85101
return customWatcher;

pkgs/watcher/lib/src/directory_watcher.dart

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,11 @@ abstract class DirectoryWatcher implements Watcher {
4242
///
4343
/// On Windows, pass [runInIsolateOnWindows] `false` to not run the watcher
4444
/// in a separate isolate to reduce buffer exhaustion failures.
45-
factory DirectoryWatcher(String directory,
46-
{Duration? pollingDelay, bool runInIsolateOnWindows = true}) {
45+
factory DirectoryWatcher(
46+
String directory, {
47+
Duration? pollingDelay,
48+
bool runInIsolateOnWindows = true,
49+
}) {
4750
if (FileSystemEntity.isWatchSupported) {
4851
var customWatcher = createCustomDirectoryWatcher(
4952
directory,
@@ -55,8 +58,10 @@ abstract class DirectoryWatcher implements Watcher {
5558
return RecursiveDirectoryWatcher(directory, runInIsolate: false);
5659
}
5760
if (Platform.isWindows) {
58-
return RecursiveDirectoryWatcher(directory,
59-
runInIsolate: runInIsolateOnWindows);
61+
return RecursiveDirectoryWatcher(
62+
directory,
63+
runInIsolate: runInIsolateOnWindows,
64+
);
6065
}
6166
}
6267
return PollingDirectoryWatcher(directory, pollingDelay: pollingDelay);

pkgs/watcher/lib/src/directory_watcher/linux/linux_directory_watcher.dart

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class LinuxDirectoryWatcher extends ResubscribableWatcher
1717
String get directory => path;
1818

1919
LinuxDirectoryWatcher(String directory)
20-
: super(directory, _LinuxDirectoryWatcher.new);
20+
: super(directory, _LinuxDirectoryWatcher.new);
2121
}
2222

2323
/// Linux directory watcher that watches using [WatchTreeRoot].
@@ -43,9 +43,10 @@ class _LinuxDirectoryWatcher
4343

4444
_LinuxDirectoryWatcher(this.path) {
4545
_watchTree = WatchTreeRoot(
46-
watchedDirectory: path,
47-
eventsController: _eventsController,
48-
readyCompleter: _readyCompleter);
46+
watchedDirectory: path,
47+
eventsController: _eventsController,
48+
readyCompleter: _readyCompleter,
49+
);
4950
}
5051

5152
@override

pkgs/watcher/lib/src/directory_watcher/linux/native_watch.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,10 @@ class NativeWatch {
8282
required void Function() watchedDirectoryWasDeleted,
8383
required void Function(List<Event>) onEvents,
8484
required void Function(Object, StackTrace) onError,
85-
}) : _onError = onError,
86-
_onEvents = onEvents,
87-
_watchedDirectoryWasDeleted = watchedDirectoryWasDeleted,
88-
_restartWatching = restartWatching {
85+
}) : _onError = onError,
86+
_onEvents = onEvents,
87+
_watchedDirectoryWasDeleted = watchedDirectoryWasDeleted,
88+
_restartWatching = restartWatching {
8989
logForTesting?.call('NativeWatch(),$watchedDirectory');
9090
_subscription = watchedDirectory
9191
.watch()

pkgs/watcher/lib/src/directory_watcher/linux/watch_tree.dart

Lines changed: 42 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ class WatchTree {
4747
required void Function(WatchEvent) emitEvent,
4848
required void Function(Object, StackTrace) onError,
4949
required void Function() watchedDirectoryWasDeleted,
50-
}) : _emitEvent = emitEvent,
51-
_onError = onError,
52-
_watchedDirectoryWasDeleted = watchedDirectoryWasDeleted {
50+
}) : _emitEvent = emitEvent,
51+
_onError = onError,
52+
_watchedDirectoryWasDeleted = watchedDirectoryWasDeleted {
5353
logForTesting?.call('WatchTree(),$watchedDirectory');
5454
_watch(starting: starting, recovering: false);
5555
}
@@ -74,20 +74,22 @@ class WatchTree {
7474
/// for files that have disappeared, and "modify" for files that are still
7575
/// present.
7676
void _watch({required bool starting, required bool recovering}) {
77-
logForTesting
78-
?.call('WatchTree,$watchedDirectory,_watch,$starting,$recovering');
77+
logForTesting?.call(
78+
'WatchTree,$watchedDirectory,_watch,$starting,$recovering',
79+
);
7980
_nativeWatch?.close();
8081
_nativeWatch = NativeWatch(
81-
watchedDirectory: watchedDirectory,
82-
restartWatching: () {
83-
_watch(starting: false, recovering: true);
84-
},
85-
watchedDirectoryWasDeleted: () {
86-
_emitDeleteTree();
87-
_watchedDirectoryWasDeleted();
88-
},
89-
onError: _onError,
90-
onEvents: _onEvents);
82+
watchedDirectory: watchedDirectory,
83+
restartWatching: () {
84+
_watch(starting: false, recovering: true);
85+
},
86+
watchedDirectoryWasDeleted: () {
87+
_emitDeleteTree();
88+
_watchedDirectoryWasDeleted();
89+
},
90+
onError: _onError,
91+
onEvents: _onEvents,
92+
);
9193

9294
final listedFiles = <RelativePath>{};
9395
final listedDirectories = <RelativePath>{};
@@ -103,8 +105,10 @@ class WatchTree {
103105
// Nothing found, use empty sets so everything is handled as deleted.
104106
}
105107

106-
logForTesting?.call('Watch,$watchedDirectory,list,'
107-
'files=$listedFiles,directories=$listedDirectories');
108+
logForTesting?.call(
109+
'Watch,$watchedDirectory,list,'
110+
'files=$listedFiles,directories=$listedDirectories',
111+
);
108112
if (recovering) {
109113
// Emit deletes for missing files.
110114
for (final file in _files.toList()) {
@@ -210,12 +214,14 @@ class WatchTree {
210214
final eventTypesSet = eventTypes.toSet();
211215

212216
// Path needs polling if it had both a delete and a create.
213-
final needsPolling = eventTypesSet.contains(EventType.delete) &&
217+
final needsPolling =
218+
eventTypesSet.contains(EventType.delete) &&
214219
(eventTypesSet.contains(EventType.createFile) ||
215220
eventTypesSet.contains(EventType.createDirectory));
216221
if (needsPolling) {
217-
logForTesting
218-
?.call('Watch,$watchedDirectory,onEvents,$eventPath,ambiguous');
222+
logForTesting?.call(
223+
'Watch,$watchedDirectory,onEvents,$eventPath,ambiguous',
224+
);
219225
pathsToPoll.add(eventPath);
220226
continue;
221227
}
@@ -291,21 +297,22 @@ class WatchTree {
291297
logForTesting?.call('Watch,$watchedDirectory,createDirectory,$directory');
292298
_directories.remove(directory)?._emitDeleteTree();
293299
_directories[directory] = WatchTree(
294-
emitEvent: _emitEvent,
295-
onError: (Object e, StackTrace s) {
296-
// Ignore exceptions from subdirectories except "out of watchers"
297-
// which is an unrecoverable error.
298-
if (e is FileSystemException &&
299-
e.message.contains('Failed to watch path') &&
300-
e.osError?.errorCode == 28) {
301-
_onError(e, s);
302-
}
303-
},
304-
watchedDirectoryWasDeleted: () {
305-
_emitDeleteDirectory(directory);
306-
},
307-
watchedDirectory: watchedDirectory.append(directory),
308-
starting: starting);
300+
emitEvent: _emitEvent,
301+
onError: (Object e, StackTrace s) {
302+
// Ignore exceptions from subdirectories except "out of watchers"
303+
// which is an unrecoverable error.
304+
if (e is FileSystemException &&
305+
e.message.contains('Failed to watch path') &&
306+
e.osError?.errorCode == 28) {
307+
_onError(e, s);
308+
}
309+
},
310+
watchedDirectoryWasDeleted: () {
311+
_emitDeleteDirectory(directory);
312+
},
313+
watchedDirectory: watchedDirectory.append(directory),
314+
starting: starting,
315+
);
309316
}
310317

311318
/// Adds [file] to known [_files].

pkgs/watcher/lib/src/directory_watcher/linux/watch_tree_root.dart

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,21 @@ class WatchTreeRoot {
1717

1818
late final WatchTree watch;
1919

20-
WatchTreeRoot(
21-
{required String watchedDirectory,
22-
required Completer<void> readyCompleter,
23-
required StreamController<WatchEvent> eventsController})
24-
: _readyCompleter = readyCompleter,
25-
_eventsController = eventsController,
26-
watchedDirectory = AbsolutePath(watchedDirectory) {
20+
WatchTreeRoot({
21+
required String watchedDirectory,
22+
required Completer<void> readyCompleter,
23+
required StreamController<WatchEvent> eventsController,
24+
}) : _readyCompleter = readyCompleter,
25+
_eventsController = eventsController,
26+
watchedDirectory = AbsolutePath(watchedDirectory) {
2727
logForTesting?.call('WatchTree(),$watchedDirectory');
2828
watch = WatchTree(
29-
watchedDirectory: this.watchedDirectory,
30-
starting: true,
31-
emitEvent: _emit,
32-
onError: _emitError,
33-
watchedDirectoryWasDeleted: _watchedDirectoryWasDeleted);
29+
watchedDirectory: this.watchedDirectory,
30+
starting: true,
31+
emitEvent: _emit,
32+
onError: _emitError,
33+
watchedDirectoryWasDeleted: _watchedDirectoryWasDeleted,
34+
);
3435
_ready();
3536
}
3637

@@ -44,8 +45,9 @@ class WatchTreeRoot {
4445

4546
/// Handler for when [watchedDirectory] is deleted.
4647
void _watchedDirectoryWasDeleted() {
47-
logForTesting
48-
?.call('WatchTree,$watchedDirectory,_watchedDirectoryWasDeleted');
48+
logForTesting?.call(
49+
'WatchTree,$watchedDirectory,_watchedDirectoryWasDeleted',
50+
);
4951
_ready();
5052
_eventsController.close();
5153
}

0 commit comments

Comments
 (0)