Skip to content
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

Require Dart 2.19, use new team lints #138

Merged
merged 1 commit into from
Mar 7, 2023
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/test-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
sdk: [2.14.0, dev]
sdk: [2.19.0, dev]
steps:
- uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c
- uses: dart-lang/setup-dart@a57a6c04cf7d4840e88432aad6281d1e125f0d46
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 1.0.3-dev

- Require Dart SDK >= 2.19

# 1.0.2

- Require Dart SDK >= 2.14
Expand Down
16 changes: 3 additions & 13 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,20 +1,10 @@
include: package:lints/recommended.yaml
include: package:dart_flutter_team_lints/analysis_options.yaml

analyzer:
language:
strict-casts: true
errors:
todo: ignore
unused_import: error
unused_element: error
unused_local_variable: error
dead_code: error

linter:
rules:
# comment_references # https://github.com/dart-lang/sdk/issues/39467
- depend_on_referenced_packages
- prefer_generic_function_type_aliases
- prefer_typing_uninitialized_variables
- unnecessary_const
- unnecessary_new
- comment_references # https://github.com/dart-lang/sdk/issues/39467

7 changes: 3 additions & 4 deletions benchmark/path_set.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import 'dart:math' as math;

import 'package:benchmark_harness/benchmark_harness.dart';
import 'package:path/path.dart' as p;

import 'package:watcher/src/path_set.dart';

final String root = Platform.isWindows ? r'C:\root' : '/root';
Expand All @@ -31,7 +30,7 @@ abstract class PathSetBenchmark extends BenchmarkBase {
/// Each virtual directory contains ten entries: either subdirectories or
/// files.
void walkTree(int depth, void Function(String) callback) {
void recurse(String path, remainingDepth) {
void recurse(String path, int remainingDepth) {
for (var i = 0; i < 10; i++) {
var padded = i.toString().padLeft(2, '0');
if (remainingDepth == 0) {
Expand Down Expand Up @@ -100,7 +99,7 @@ class ContainsBenchmark extends PathSetBenchmark {
if (pathSet.contains(path)) contained++;
}

if (contained != 10000) throw 'Wrong result: $contained';
if (contained != 10000) throw StateError('Wrong result: $contained');
}
}

Expand All @@ -119,7 +118,7 @@ class PathsBenchmark extends PathSetBenchmark {
count++;
}

if (count != 10000) throw 'Wrong result: $count';
if (count != 10000) throw StateError('Wrong result: $count');
}
}

Expand Down
4 changes: 1 addition & 3 deletions example/watch.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,5 @@ void main(List<String> arguments) {
}

var watcher = DirectoryWatcher(p.absolute(arguments[0]));
watcher.events.listen((event) {
print(event);
});
watcher.events.listen(print);
}
6 changes: 2 additions & 4 deletions lib/src/directory_watcher/mac_os.dart
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,7 @@ class _MacOSDirectoryWatcher
subscription.onDone(() {
_listSubscriptions.remove(subscription);
});
subscription.onError((Object e, StackTrace stackTrace) {
_emitError(e, stackTrace);
});
subscription.onError(_emitError);
_listSubscriptions.add(subscription);
} else if (event is FileSystemModifyEvent) {
assert(!event.isDirectory);
Expand Down Expand Up @@ -294,7 +292,7 @@ class _MacOSDirectoryWatcher
return ConstructableFileSystemModifyEvent(
batch.first.path, isDir, false);
default:
throw 'unreachable';
throw StateError('unreachable');
}
}

Expand Down
6 changes: 3 additions & 3 deletions lib/src/directory_watcher/windows.dart
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,7 @@ class _WindowsDirectoryWatcher

void _onEvent(FileSystemEvent event) {
assert(isReady);
final batcher =
_eventBatchers.putIfAbsent(event.path, () => _EventBatcher());
final batcher = _eventBatchers.putIfAbsent(event.path, _EventBatcher.new);
batcher.addEvent(event, () {
_eventBatchers.remove(event.path);
_onBatch(batcher.events);
Expand Down Expand Up @@ -316,7 +315,7 @@ class _WindowsDirectoryWatcher
case FileSystemEvent.move:
return null;
default:
throw 'unreachable';
throw StateError('unreachable');
}
}

Expand Down Expand Up @@ -397,6 +396,7 @@ class _WindowsDirectoryWatcher
_eventsController.addError(error, stackTrace);
_startWatch();
} else {
// ignore: only_throw_errors
throw error;
}
});
Expand Down
2 changes: 1 addition & 1 deletion lib/src/path_set.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class PathSet {
var parts = p.split(path);
var entry = _entries;
for (var part in parts) {
entry = entry.contents.putIfAbsent(part, () => _Entry());
entry = entry.contents.putIfAbsent(part, _Entry.new);
}

entry.isExplicit = true;
Expand Down
6 changes: 3 additions & 3 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
name: watcher
version: 1.0.2
version: 1.0.3-dev
description: >-
A file system watcher. It monitors changes to contents of directories and
sends notifications when files have been added, removed, or modified.
repository: https://github.com/dart-lang/watcher

environment:
sdk: '>=2.14.0 <3.0.0'
sdk: '>=2.19.0 <3.0.0'

dependencies:
async: ^2.5.0
path: ^1.8.0

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

9 changes: 6 additions & 3 deletions test/custom_watcher_factory_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,12 @@ void main() {

test('registering twice throws', () async {
expect(
() => registerCustomWatcher(memFsFactoryId,
(_, {pollingDelay}) => throw 0, (_, {pollingDelay}) => throw 0),
throwsA(isA<ArgumentError>()));
() => registerCustomWatcher(
memFsFactoryId,
(_, {pollingDelay}) => throw UnimplementedError(),
(_, {pollingDelay}) => throw UnimplementedError()),
throwsA(isA<ArgumentError>()),
);
});

test('finding two applicable factories throws', () async {
Expand Down
5 changes: 3 additions & 2 deletions test/directory_watcher/linux_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@
// BSD-style license that can be found in the LICENSE file.

@TestOn('linux')
library;

import 'package:test/test.dart';
import 'package:watcher/src/directory_watcher/linux.dart';
import 'package:watcher/watcher.dart';

import 'shared.dart';
import '../utils.dart';
import 'shared.dart';

void main() {
watcherFactory = (dir) => LinuxDirectoryWatcher(dir);
watcherFactory = LinuxDirectoryWatcher.new;

sharedTests();

Expand Down
5 changes: 3 additions & 2 deletions test/directory_watcher/mac_os_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@
// BSD-style license that can be found in the LICENSE file.

@TestOn('mac-os')
library;

import 'package:test/test.dart';
import 'package:watcher/src/directory_watcher/mac_os.dart';
import 'package:watcher/watcher.dart';

import 'shared.dart';
import '../utils.dart';
import 'shared.dart';

void main() {
watcherFactory = (dir) => MacOSDirectoryWatcher(dir);
watcherFactory = MacOSDirectoryWatcher.new;

sharedTests();

Expand Down
2 changes: 1 addition & 1 deletion test/directory_watcher/polling_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import 'package:test/test.dart';
import 'package:watcher/watcher.dart';

import 'shared.dart';
import '../utils.dart';
import 'shared.dart';

void main() {
// Use a short delay to make the tests run quickly.
Expand Down
1 change: 0 additions & 1 deletion test/directory_watcher/shared.dart
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,6 @@ void sharedTests() {
isAddEvent('new')
]);
}, onPlatform: {
'mac-os': Skip('https://github.com/dart-lang/watcher/issues/21'),
'windows': Skip('https://github.com/dart-lang/watcher/issues/21')
});

Expand Down
9 changes: 4 additions & 5 deletions test/directory_watcher/windows_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,19 @@
// BSD-style license that can be found in the LICENSE file.

@TestOn('windows')
library;

import 'package:test/test.dart';
import 'package:watcher/src/directory_watcher/windows.dart';
import 'package:watcher/watcher.dart';

import 'shared.dart';
import '../utils.dart';
import 'shared.dart';

void main() {
watcherFactory = (dir) => WindowsDirectoryWatcher(dir);
watcherFactory = WindowsDirectoryWatcher.new;

group('Shared Tests:', () {
sharedTests();
});
group('Shared Tests:', sharedTests);

test('DirectoryWatcher creates a WindowsDirectoryWatcher on Windows', () {
expect(DirectoryWatcher('.'), TypeMatcher<WindowsDirectoryWatcher>());
Expand Down
5 changes: 3 additions & 2 deletions test/file_watcher/native_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
// BSD-style license that can be found in the LICENSE file.

@TestOn('linux || mac-os')
library;

import 'package:test/test.dart';
import 'package:watcher/src/file_watcher/native.dart';

import 'shared.dart';
import '../utils.dart';
import 'shared.dart';

void main() {
watcherFactory = (file) => NativeFileWatcher(file);
watcherFactory = NativeFileWatcher.new;

setUp(() {
writeFile('file.txt');
Expand Down
3 changes: 2 additions & 1 deletion test/file_watcher/polling_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
// BSD-style license that can be found in the LICENSE file.

@TestOn('linux || mac-os')
library;

import 'package:test/test.dart';
import 'package:watcher/watcher.dart';

import 'shared.dart';
import '../utils.dart';
import 'shared.dart';

void main() {
watcherFactory = (file) =>
Expand Down
5 changes: 3 additions & 2 deletions test/no_subscription/linux_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
// BSD-style license that can be found in the LICENSE file.

@TestOn('linux')
library;

import 'package:test/test.dart';
import 'package:watcher/src/directory_watcher/linux.dart';

import 'shared.dart';
import '../utils.dart';
import 'shared.dart';

void main() {
watcherFactory = (dir) => LinuxDirectoryWatcher(dir);
watcherFactory = LinuxDirectoryWatcher.new;

sharedTests();
}
6 changes: 3 additions & 3 deletions test/no_subscription/mac_os_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
// BSD-style license that can be found in the LICENSE file.

@TestOn('mac-os')
@Skip('Flaky due to sdk#23877')
library;

import 'package:test/test.dart';
import 'package:watcher/src/directory_watcher/mac_os.dart';

import 'shared.dart';
import '../utils.dart';
import 'shared.dart';

void main() {
watcherFactory = (dir) => MacOSDirectoryWatcher(dir);
watcherFactory = MacOSDirectoryWatcher.new;

sharedTests();
}
4 changes: 2 additions & 2 deletions test/no_subscription/polling_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

import 'package:watcher/watcher.dart';

import 'shared.dart';
import '../utils.dart';
import 'shared.dart';

void main() {
watcherFactory = (dir) => PollingDirectoryWatcher(dir);
watcherFactory = PollingDirectoryWatcher.new;

sharedTests();
}
5 changes: 3 additions & 2 deletions test/no_subscription/windows_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
// BSD-style license that can be found in the LICENSE file.

@TestOn('windows')
library;

import 'package:test/test.dart';
import 'package:watcher/src/directory_watcher/windows.dart';

import 'shared.dart';
import '../utils.dart';
import 'shared.dart';

void main() {
watcherFactory = (dir) => WindowsDirectoryWatcher(dir);
watcherFactory = WindowsDirectoryWatcher.new;

sharedTests();
}
5 changes: 3 additions & 2 deletions test/ready/linux_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
// BSD-style license that can be found in the LICENSE file.

@TestOn('linux')
library;

import 'package:test/test.dart';
import 'package:watcher/src/directory_watcher/linux.dart';

import 'shared.dart';
import '../utils.dart';
import 'shared.dart';

void main() {
watcherFactory = (dir) => LinuxDirectoryWatcher(dir);
watcherFactory = LinuxDirectoryWatcher.new;

sharedTests();
}
Loading