Skip to content
This repository has been archived by the owner on Feb 10, 2025. It is now read-only.

Commit

Permalink
Enable and fix lints, test on oldest supported Dart SDK, verify lints…
Browse files Browse the repository at this point in the history
… on Travis (#68)
  • Loading branch information
kevmoo authored May 16, 2019
1 parent 7168052 commit 562b9e5
Show file tree
Hide file tree
Showing 11 changed files with 43 additions and 24 deletions.
20 changes: 14 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
language: dart
dart: dev

dart:
- dev
- 2.0.0

dart_task:
- test
- dartfmt
- dartanalyzer
- test
- dartanalyzer: --fatal-warnings --fatal-infos .

matrix:
include:
# Only validate formatting using the dev release
- dart: dev
dart_task: dartfmt

# Only building master means that we don't run two builds for each pull request.
branches:
only: [master]

cache:
directories:
- $HOME/.pub-cache
directories:
- $HOME/.pub-cache
3 changes: 3 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,7 @@ analyzer:
linter:
rules:
- comment_references
- prefer_generic_function_type_aliases
- prefer_typing_uninitialized_variables
- unnecessary_const
- unnecessary_new
10 changes: 7 additions & 3 deletions benchmark/path_set.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ abstract class PathSetBenchmark extends BenchmarkBase {

final PathSet pathSet = PathSet(root);

/// Use a fixed [Random] with a constant seed to ensure the tests are
/// Use a fixed [math.Random] with a constant seed to ensure the tests are
/// deterministic.
final math.Random random = math.Random(1234);

Expand Down Expand Up @@ -59,7 +59,9 @@ class AddBenchmark extends PathSetBenchmark {
}

void run() {
for (var path in paths) pathSet.add(path);
for (var path in paths) {
pathSet.add(path);
}
}
}

Expand Down Expand Up @@ -135,7 +137,9 @@ class RemoveBenchmark extends PathSetBenchmark {
}

void run() {
for (var path in paths) pathSet.remove(path);
for (var path in paths) {
pathSet.remove(path);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/src/async_queue.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import 'dart:async';
import 'dart:collection';

typedef Future ItemProcessor<T>(T item);
typedef ItemProcessor<T> = Future Function(T item);

/// A queue of items that are sequentially, asynchronously processed.
///
Expand Down
4 changes: 3 additions & 1 deletion lib/src/file_watcher/polling.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import 'dart:async';
import 'dart:io';

import 'package:pedantic/pedantic.dart';

import '../file_watcher.dart';
import '../resubscribable.dart';
import '../stat.dart';
Expand Down Expand Up @@ -54,7 +56,7 @@ class _PollingFileWatcher implements FileWatcher, ManuallyClosedWatcher {

if (_lastModified != null && !pathExists) {
_eventsController.add(WatchEvent(ChangeType.REMOVE, path));
close();
unawaited(close());
return;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/src/stat.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import 'dart:io';

/// A function that takes a file path and returns the last modified time for
/// the file at that path.
typedef DateTime MockTimeCallback(String path);
typedef MockTimeCallback = DateTime Function(String path);

MockTimeCallback _mockTimeCallback;

Expand Down
6 changes: 3 additions & 3 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: watcher
version: 0.9.7+12
version: 0.9.8-dev

description: >
description: >-
A file system watcher. It monitors changes to contents of directories and
sends notifications when files have been added, removed, or modified.
author: Dart Team <misc@dartlang.org>
Expand All @@ -13,9 +13,9 @@ environment:
dependencies:
async: '>=1.10.0 <3.0.0'
path: '>=0.9.0 <2.0.0'
pedantic: ^1.1.0

dev_dependencies:
benchmark_harness: ^1.0.4
pedantic: ^1.1.0
test: '>=0.12.42 <2.0.0'
test_descriptor: ^1.0.0
6 changes: 3 additions & 3 deletions test/directory_watcher/shared.dart
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ void sharedTests() {
await startWatcher(path: "dir");

renameFile("old.txt", "dir/new.txt");
expectAddEvent("dir/new.txt");
await expectAddEvent("dir/new.txt");
});

test('notifies when a file is moved outside the watched directory',
Expand All @@ -124,7 +124,7 @@ void sharedTests() {
await startWatcher(path: "dir");

renameFile("dir/old.txt", "new.txt");
expectRemoveEvent("dir/old.txt");
await expectRemoveEvent("dir/old.txt");
});

test('notifies when a file is moved onto an existing one', () async {
Expand Down Expand Up @@ -231,7 +231,7 @@ void sharedTests() {
test('watches files in subdirectories', () async {
await startWatcher();
writeFile("a/b/c/d/file.txt");
expectAddEvent("a/b/c/d/file.txt");
await expectAddEvent("a/b/c/d/file.txt");
});

test(
Expand Down
3 changes: 2 additions & 1 deletion test/no_subscription/shared.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// BSD-style license that can be found in the LICENSE file.

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

Expand All @@ -15,7 +16,7 @@ void sharedTests() {
// stream is and is not subscribed.
var watcher = createWatcher();
var queue = StreamQueue(watcher.events);
queue.hasNext;
unawaited(queue.hasNext);

var future =
expectLater(queue, emits(isWatchEvent(ChangeType.ADD, "file.txt")));
Expand Down
5 changes: 3 additions & 2 deletions test/ready/shared.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

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

import '../utils.dart';
Expand All @@ -11,9 +12,9 @@ void sharedTests() {
var watcher = createWatcher();

var ready = false;
watcher.ready.then((_) {
unawaited(watcher.ready.then((_) {
ready = true;
});
}));
await pumpEventQueue();

expect(ready, isFalse);
Expand Down
6 changes: 3 additions & 3 deletions test/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import 'dart:io';

import 'package:async/async.dart';
import 'package:path/path.dart' as p;
import 'package:pedantic/pedantic.dart';
import 'package:test/test.dart';
import 'package:test_descriptor/test_descriptor.dart' as d;

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

typedef Watcher WatcherFactory(String directory);
typedef WatcherFactory = Watcher Function(String directory);

/// Sets the function used to create the watcher.
set watcherFactory(WatcherFactory factory) {
Expand Down Expand Up @@ -69,7 +69,7 @@ Future<Null> startWatcher({String path}) async {
var watcher = createWatcher(path: path);
_watcherEvents = StreamQueue(watcher.events);
// Forces a subscription to the underlying stream.
_watcherEvents.hasNext;
unawaited(_watcherEvents.hasNext);
await watcher.ready;
}

Expand Down

0 comments on commit 562b9e5

Please sign in to comment.