Skip to content

Commit

Permalink
Migrate to dart_flutter_team_lints v2.1 (#153)
Browse files Browse the repository at this point in the history
- Fix new lints.
- Deduplicate lints in local config.
- Add some missing generic types on futures and stream controllers.
- Fix a typo in a test.
- Remove unnecessary library names.
  • Loading branch information
parlough authored Oct 19, 2023
1 parent 3998cdd commit 6ad58dc
Show file tree
Hide file tree
Showing 21 changed files with 41 additions and 47 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
## 1.1.1-wip

## 1.1.0

- Require Dart SDK >= 3.0.0
Expand Down
9 changes: 0 additions & 9 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1 @@
include: package:dart_flutter_team_lints/analysis_options.yaml

analyzer:
language:
strict-casts: true

linter:
rules:
- comment_references # https:/dart-lang/sdk/issues/39467

2 changes: 1 addition & 1 deletion benchmark/path_set.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// BSD-style license that can be found in the LICENSE file.

/// Benchmarks for the PathSet class.
library watcher.benchmark.path_set;
library;

import 'dart:io';
import 'dart:math' as math;
Expand Down
2 changes: 1 addition & 1 deletion example/watch.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// BSD-style license that can be found in the LICENSE file.

/// Watches the given directory and prints each modification to it.
library watch;
library;

import 'package:path/path.dart' as p;
import 'package:watcher/watcher.dart';
Expand Down
6 changes: 3 additions & 3 deletions lib/src/directory_watcher/linux.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ class _LinuxDirectoryWatcher
bool get isReady => _readyCompleter.isCompleted;

@override
Future get ready => _readyCompleter.future;
final _readyCompleter = Completer();
Future<void> get ready => _readyCompleter.future;
final _readyCompleter = Completer<void>();

/// A stream group for the [Directory.watch] events of [path] and all its
/// subdirectories.
Expand Down Expand Up @@ -284,7 +284,7 @@ class _LinuxDirectoryWatcher
{Function? onError,
void Function()? onDone,
bool cancelOnError = false}) {
late StreamSubscription subscription;
late StreamSubscription<T> subscription;
subscription = stream.listen(onData, onError: onError, onDone: () {
_subscriptions.remove(subscription);
onDone?.call();
Expand Down
15 changes: 8 additions & 7 deletions lib/src/directory_watcher/mac_os.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ class _MacOSDirectoryWatcher
bool get isReady => _readyCompleter.isCompleted;

@override
Future get ready => _readyCompleter.future;
final _readyCompleter = Completer();
Future<void> get ready => _readyCompleter.future;
final _readyCompleter = Completer<void>();

/// The set of files that are known to exist recursively within the watched
/// directory.
Expand Down Expand Up @@ -367,12 +367,12 @@ class _MacOSDirectoryWatcher

/// Starts or restarts listing the watched directory to get an initial picture
/// of its state.
Future _listDir() {
Future<void> _listDir() {
assert(!isReady);
_initialListSubscription?.cancel();

_files.clear();
var completer = Completer();
var completer = Completer<void>();
var stream = Directory(path).list(recursive: true);
_initialListSubscription = stream.listen((entity) {
if (entity is! Directory) _files.add(entity.path);
Expand All @@ -385,9 +385,10 @@ class _MacOSDirectoryWatcher
/// 200ms is short in terms of human interaction, but longer than any Mac OS
/// watcher tests take on the bots, so it should be safe to assume that any
/// bogus events will be signaled in that time frame.
Future _waitForBogusEvents() {
var completer = Completer();
_bogusEventTimer = Timer(Duration(milliseconds: 200), completer.complete);
Future<void> _waitForBogusEvents() {
var completer = Completer<void>();
_bogusEventTimer =
Timer(const Duration(milliseconds: 200), completer.complete);
return completer.future;
}

Expand Down
4 changes: 2 additions & 2 deletions lib/src/directory_watcher/polling.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class PollingDirectoryWatcher extends ResubscribableWatcher
PollingDirectoryWatcher(String directory, {Duration? pollingDelay})
: super(directory, () {
return _PollingDirectoryWatcher(
directory, pollingDelay ?? Duration(seconds: 1));
directory, pollingDelay ?? const Duration(seconds: 1));
});
}

Expand Down Expand Up @@ -184,7 +184,7 @@ class _PollingDirectoryWatcher
if (!isReady) _readyCompleter.complete();

// Wait and then poll again.
await Future.delayed(_pollingDelay);
await Future<void>.delayed(_pollingDelay);
if (_events.isClosed) return;
_poll();
}
Expand Down
4 changes: 2 additions & 2 deletions lib/src/directory_watcher/windows.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class _WindowsDirectoryWatcher

@override
Future<void> get ready => _readyCompleter.future;
final _readyCompleter = Completer();
final _readyCompleter = Completer<void>();

final Map<String, _EventBatcher> _eventBatchers =
HashMap<String, _EventBatcher>();
Expand Down Expand Up @@ -407,7 +407,7 @@ class _WindowsDirectoryWatcher
_initialListSubscription?.cancel();

_files.clear();
var completer = Completer();
var completer = Completer<void>();
var stream = Directory(path).list(recursive: true);
void handleEntity(FileSystemEntity entity) {
if (entity is! Directory) _files.add(entity.path);
Expand Down
6 changes: 3 additions & 3 deletions lib/src/file_watcher/native.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ class _NativeFileWatcher implements FileWatcher, ManuallyClosedWatcher {
bool get isReady => _readyCompleter.isCompleted;

@override
Future get ready => _readyCompleter.future;
final _readyCompleter = Completer();
Future<void> get ready => _readyCompleter.future;
final _readyCompleter = Completer<void>();

StreamSubscription? _subscription;
StreamSubscription<List<FileSystemEvent>>? _subscription;

_NativeFileWatcher(this.path) {
_listen();
Expand Down
8 changes: 4 additions & 4 deletions lib/src/file_watcher/polling.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class PollingFileWatcher extends ResubscribableWatcher implements FileWatcher {
PollingFileWatcher(String path, {Duration? pollingDelay})
: super(path, () {
return _PollingFileWatcher(
path, pollingDelay ?? Duration(seconds: 1));
path, pollingDelay ?? const Duration(seconds: 1));
});
}

Expand All @@ -31,8 +31,8 @@ class _PollingFileWatcher implements FileWatcher, ManuallyClosedWatcher {
bool get isReady => _readyCompleter.isCompleted;

@override
Future get ready => _readyCompleter.future;
final _readyCompleter = Completer();
Future<void> get ready => _readyCompleter.future;
final _readyCompleter = Completer<void>();

/// The timer that controls polling.
late final Timer _timer;
Expand All @@ -49,7 +49,7 @@ class _PollingFileWatcher implements FileWatcher, ManuallyClosedWatcher {
}

/// Checks the mtime of the file and whether it's been removed.
Future _poll() async {
Future<void> _poll() async {
// We don't mark the file as removed if this is the first poll (indicated by
// [_lastModified] being null). Instead, below we forward the dart:io error
// that comes from trying to read the mtime below.
Expand Down
2 changes: 1 addition & 1 deletion lib/src/resubscribable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ abstract class ResubscribableWatcher implements Watcher {
/// emitted by [_factory].
ResubscribableWatcher(this.path, this._factory) {
late ManuallyClosedWatcher watcher;
late StreamSubscription subscription;
late StreamSubscription<WatchEvent> subscription;

_eventsController = StreamController<WatchEvent>.broadcast(
onListen: () async {
Expand Down
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: watcher
version: 1.1.0
version: 1.1.1-wip
description: >-
A file system watcher. It monitors changes to contents of directories and
sends notifications when files have been added, removed, or modified.
Expand All @@ -14,7 +14,7 @@ dependencies:

dev_dependencies:
benchmark_harness: ^2.0.0
dart_flutter_team_lints: ^1.0.0
dart_flutter_team_lints: ^2.1.0
test: ^1.16.0
test_descriptor: ^2.0.0

2 changes: 1 addition & 1 deletion test/directory_watcher/linux_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ void main() {
sharedTests();

test('DirectoryWatcher creates a LinuxDirectoryWatcher on Linux', () {
expect(DirectoryWatcher('.'), TypeMatcher<LinuxDirectoryWatcher>());
expect(DirectoryWatcher('.'), const TypeMatcher<LinuxDirectoryWatcher>());
});

test('emits events for many nested files moved out then immediately back in',
Expand Down
2 changes: 1 addition & 1 deletion test/directory_watcher/mac_os_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ void main() {
sharedTests();

test('DirectoryWatcher creates a MacOSDirectoryWatcher on Mac OS', () {
expect(DirectoryWatcher('.'), TypeMatcher<MacOSDirectoryWatcher>());
expect(DirectoryWatcher('.'), const TypeMatcher<MacOSDirectoryWatcher>());
});

test(
Expand Down
4 changes: 2 additions & 2 deletions test/directory_watcher/polling_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import 'shared.dart';

void main() {
// Use a short delay to make the tests run quickly.
watcherFactory = (dir) =>
PollingDirectoryWatcher(dir, pollingDelay: Duration(milliseconds: 100));
watcherFactory = (dir) => PollingDirectoryWatcher(dir,
pollingDelay: const Duration(milliseconds: 100));

sharedTests();

Expand Down
4 changes: 2 additions & 2 deletions test/directory_watcher/shared.dart
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ void sharedTests() {
renameFile('from.txt', 'to.txt');
await inAnyOrder([isRemoveEvent('from.txt'), isModifyEvent('to.txt')]);
}, onPlatform: {
'windows': Skip('https:/dart-lang/watcher/issues/125')
'windows': const Skip('https:/dart-lang/watcher/issues/125')
});
});

Expand Down Expand Up @@ -278,7 +278,7 @@ void sharedTests() {
isAddEvent('new')
]);
}, onPlatform: {
'windows': Skip('https:/dart-lang/watcher/issues/21')
'windows': const Skip('https:/dart-lang/watcher/issues/21')
});

test('emits events for many nested files added at once', () async {
Expand Down
2 changes: 1 addition & 1 deletion test/directory_watcher/windows_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ void main() {
group('Shared Tests:', sharedTests);

test('DirectoryWatcher creates a WindowsDirectoryWatcher on Windows', () {
expect(DirectoryWatcher('.'), TypeMatcher<WindowsDirectoryWatcher>());
expect(DirectoryWatcher('.'), const TypeMatcher<WindowsDirectoryWatcher>());
});
}
2 changes: 1 addition & 1 deletion test/file_watcher/polling_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import 'shared.dart';

void main() {
watcherFactory = (file) =>
PollingFileWatcher(file, pollingDelay: Duration(milliseconds: 100));
PollingFileWatcher(file, pollingDelay: const Duration(milliseconds: 100));

setUp(() {
writeFile('file.txt');
Expand Down
2 changes: 1 addition & 1 deletion test/file_watcher/shared.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void sharedTests() {
var sub = watcher.events.listen(null);

deleteFile('file.txt');
await Future.delayed(Duration(milliseconds: 10));
await Future<void>.delayed(const Duration(milliseconds: 10));
await sub.cancel();
});
}
4 changes: 2 additions & 2 deletions test/ready/shared.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ void sharedTests() {
// Ensure ready completes immediately
expect(
watcher.ready.timeout(
Duration(milliseconds: 0),
onTimeout: () => throw StateError('Does not complete immedately'),
const Duration(milliseconds: 0),
onTimeout: () => throw StateError('Does not complete immediately'),
),
completes,
);
Expand Down
2 changes: 1 addition & 1 deletion test/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ StreamMatcher _collectStreamMatcher(void Function() block) {
/// it with [_collectStreamMatcher].
///
/// [streamMatcher] can be a [StreamMatcher], a [Matcher], or a value.
Future _expectOrCollect(streamMatcher) {
Future _expectOrCollect(Matcher streamMatcher) {
var collectedStreamMatchers = _collectedStreamMatchers;
if (collectedStreamMatchers != null) {
collectedStreamMatchers.add(emits(streamMatcher));
Expand Down

0 comments on commit 6ad58dc

Please sign in to comment.