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

Commit d994f23

Browse files
authored
Enable and fix a number of lints, test on the oldest supported SDK (#19)
1 parent 75af367 commit d994f23

16 files changed

+176
-113
lines changed

.travis.yml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,25 @@ language: dart
22

33
dart:
44
- dev
5+
- 2.0.0
56

67
dart_task:
78
- test
89

9-
# Only run one instance of the formatter and the analyzer, rather than running
10-
# them against each Dart version.
1110
matrix:
1211
include:
1312
- dart: dev
1413
dart_task: dartfmt
1514
- dart: dev
16-
dart_task: dartanalyzer
15+
dart_task:
16+
dartanalyzer: --fatal-infos --fatal-warnings .
17+
- dart: 2.0.0
18+
dart_task:
19+
dartanalyzer: --fatal-warnings .
1720

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

2224
cache:
23-
directories:
24-
- $HOME/.pub-cache
25+
directories:
26+
- $HOME/.pub-cache

analysis_options.yaml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
include: package:pedantic/analysis_options.yaml
2+
analyzer:
3+
strong-mode:
4+
implicit-casts: false
5+
errors:
6+
unused_element: error
7+
unused_import: error
8+
unused_local_variable: error
9+
dead_code: error
10+
linter:
11+
rules:
12+
#- annotate_overrides
13+
- avoid_function_literals_in_foreach_calls
14+
- avoid_init_to_null
15+
- avoid_null_checks_in_equality_operators
16+
- avoid_relative_lib_imports
17+
- avoid_returning_null
18+
- avoid_unused_constructor_parameters
19+
- await_only_futures
20+
- camel_case_types
21+
- cancel_subscriptions
22+
- comment_references
23+
- constant_identifier_names
24+
- control_flow_in_finally
25+
- directives_ordering
26+
- empty_catches
27+
- empty_constructor_bodies
28+
- empty_statements
29+
- hash_and_equals
30+
- implementation_imports
31+
- invariant_booleans
32+
- iterable_contains_unrelated_type
33+
- library_names
34+
- library_prefixes
35+
- list_remove_unrelated_type
36+
- no_adjacent_strings_in_list
37+
- non_constant_identifier_names
38+
- omit_local_variable_types
39+
- only_throw_errors
40+
- overridden_fields
41+
- package_api_docs
42+
- package_names
43+
- package_prefixed_library_names
44+
- prefer_adjacent_string_concatenation
45+
- prefer_collection_literals
46+
- prefer_conditional_assignment
47+
- prefer_const_constructors
48+
- prefer_final_fields
49+
- prefer_generic_function_type_aliases
50+
- prefer_initializing_formals
51+
- prefer_interpolation_to_compose_strings
52+
#- prefer_single_quotes
53+
- prefer_typing_uninitialized_variables
54+
- slash_for_doc_comments
55+
- test_types_in_equals
56+
- throw_in_finally
57+
- type_init_formals
58+
- unnecessary_brace_in_string_interps
59+
- unnecessary_const
60+
- unnecessary_getters_setters
61+
- unnecessary_lambdas
62+
- unnecessary_new
63+
- unnecessary_null_aware_assignments
64+
- unnecessary_statements
65+
- unnecessary_this

lib/src/descriptor.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
import 'dart:async';
66

7+
import 'sandbox.dart';
8+
79
/// A declarative description of a filesystem entry.
810
///
911
/// This may be extended outside this package.

lib/src/directory_descriptor.dart

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class DirectoryDescriptor extends Descriptor {
2929

3030
/// Returns a `dart:io` [Directory] object that refers to this file within
3131
/// [sandbox].
32-
Directory get io => new Directory(p.join(sandbox, name));
32+
Directory get io => Directory(p.join(sandbox, name));
3333

3434
DirectoryDescriptor(String name, Iterable<Descriptor> contents)
3535
: contents = contents.toList(),
@@ -38,17 +38,17 @@ class DirectoryDescriptor extends Descriptor {
3838
/// Creates a directory descriptor named [name] that describes the physical
3939
/// directory at [path].
4040
factory DirectoryDescriptor.fromFilesystem(String name, String path) {
41-
return new DirectoryDescriptor(
41+
return DirectoryDescriptor(
4242
name,
43-
new Directory(path).listSync().map((entity) {
43+
Directory(path).listSync().map((entity) {
4444
// Ignore hidden files.
4545
if (p.basename(entity.path).startsWith(".")) return null;
4646

4747
if (entity is Directory) {
48-
return new DirectoryDescriptor.fromFilesystem(
48+
return DirectoryDescriptor.fromFilesystem(
4949
p.basename(entity.path), entity.path);
5050
} else if (entity is File) {
51-
return new FileDescriptor(
51+
return FileDescriptor(
5252
p.basename(entity.path), entity.readAsBytesSync());
5353
}
5454
// Ignore broken symlinks.
@@ -57,13 +57,13 @@ class DirectoryDescriptor extends Descriptor {
5757

5858
Future create([String parent]) async {
5959
var fullPath = p.join(parent ?? sandbox, name);
60-
await new Directory(fullPath).create(recursive: true);
60+
await Directory(fullPath).create(recursive: true);
6161
await Future.wait(contents.map((entry) => entry.create(fullPath)));
6262
}
6363

6464
Future validate([String parent]) async {
6565
var fullPath = p.join(parent ?? sandbox, name);
66-
if (!(await new Directory(fullPath).exists())) {
66+
if (!(await Directory(fullPath).exists())) {
6767
fail('Directory not found: "${prettyPath(fullPath)}".');
6868
}
6969

@@ -75,7 +75,7 @@ class DirectoryDescriptor extends Descriptor {
7575
/// contents of the [FileDescriptor] at the given relative [url], which may be
7676
/// a [Uri] or a [String].
7777
///
78-
/// The [parent] parameter should only be passed by subclasses of
78+
/// The [parents] parameter should only be passed by subclasses of
7979
/// [DirectoryDescriptor] that are recursively calling [load]. It's the
8080
/// URL-format path of the directories that have been loaded so far.
8181
Stream<List<int>> load(url, [String parents]) {
@@ -85,15 +85,15 @@ class DirectoryDescriptor extends Descriptor {
8585
} else if (url is Uri) {
8686
path = url.toString();
8787
} else {
88-
throw new ArgumentError.value(url, "url", "must be a Uri or a String.");
88+
throw ArgumentError.value(url, "url", "must be a Uri or a String.");
8989
}
9090

9191
if (!p.url.isWithin('.', path)) {
92-
throw new ArgumentError.value(
92+
throw ArgumentError.value(
9393
url, "url", "must be relative and beneath the base URL.");
9494
}
9595

96-
return StreamCompleter.fromFuture(new Future.sync(() {
96+
return StreamCompleter.fromFuture(Future.sync(() {
9797
var split = p.url.split(p.url.normalize(path));
9898
var file = split.length == 1;
9999
var matchingEntries = contents.where((entry) {
@@ -124,7 +124,7 @@ class DirectoryDescriptor extends Descriptor {
124124
String describe() {
125125
if (contents.isEmpty) return name;
126126

127-
var buffer = new StringBuffer();
127+
var buffer = StringBuffer();
128128
buffer.writeln(name);
129129
for (var entry in contents.take(contents.length - 1)) {
130130
var entryString =

lib/src/file_descriptor.dart

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,33 +36,33 @@ abstract class FileDescriptor extends Descriptor {
3636
/// To match a [Matcher] against a file's binary contents, use [new
3737
/// FileDescriptor.binaryMatcher] instead.
3838
factory FileDescriptor(String name, contents) {
39-
if (contents is String) return new _StringFileDescriptor(name, contents);
39+
if (contents is String) return _StringFileDescriptor(name, contents);
4040
if (contents is List) {
41-
return new _BinaryFileDescriptor(name, contents.cast<int>());
41+
return _BinaryFileDescriptor(name, contents.cast<int>());
4242
}
43-
if (contents == null) return new _BinaryFileDescriptor(name, []);
44-
return new _MatcherFileDescriptor(name, contents);
43+
if (contents == null) return _BinaryFileDescriptor(name, []);
44+
return _MatcherFileDescriptor(name, contents as Matcher);
4545
}
4646

4747
/// Returns a `dart:io` [File] object that refers to this file within
4848
/// [sandbox].
49-
File get io => new File(p.join(sandbox, name));
49+
File get io => File(p.join(sandbox, name));
5050

5151
/// Creates a new binary [FileDescriptor] with [name] that matches its binary
5252
/// contents against [matcher].
5353
///
5454
/// The [create], [read], and [readAsBytes] methods are unsupported for this
5555
/// descriptor.
5656
factory FileDescriptor.binaryMatcher(String name, Matcher matcher) =>
57-
new _MatcherFileDescriptor(name, matcher, isBinary: true);
57+
_MatcherFileDescriptor(name, matcher, isBinary: true);
5858

5959
/// A protected constructor that's only intended for subclasses.
6060
FileDescriptor.protected(String name) : super(name);
6161

6262
Future create([String parent]) async {
6363
// Create the stream before we call [File.openWrite] because it may fail
6464
// fast (e.g. if this is a matcher file).
65-
var file = new File(p.join(parent ?? sandbox, name)).openWrite();
65+
var file = File(p.join(parent ?? sandbox, name)).openWrite();
6666
try {
6767
await readAsBytes().listen(file.add).asFuture();
6868
} finally {
@@ -73,11 +73,11 @@ abstract class FileDescriptor extends Descriptor {
7373
Future validate([String parent]) async {
7474
var fullPath = p.join(parent ?? sandbox, name);
7575
var pretty = prettyPath(fullPath);
76-
if (!(await new File(fullPath).exists())) {
76+
if (!(await File(fullPath).exists())) {
7777
fail('File not found: "$pretty".');
7878
}
7979

80-
await _validate(pretty, await new File(fullPath).readAsBytes());
80+
await _validate(pretty, await File(fullPath).readAsBytes());
8181
}
8282

8383
/// Validates that [binaryContents] matches the expected contents of
@@ -106,7 +106,7 @@ class _BinaryFileDescriptor extends FileDescriptor {
106106

107107
_BinaryFileDescriptor(String name, this._contents) : super.protected(name);
108108

109-
Stream<List<int>> readAsBytes() => new Stream.fromIterable([_contents]);
109+
Stream<List<int>> readAsBytes() => Stream.fromIterable([_contents]);
110110

111111
Future _validate(String prettPath, List<int> actualContents) async {
112112
if (const IterableEquality().equals(_contents, actualContents)) return null;
@@ -124,12 +124,12 @@ class _StringFileDescriptor extends FileDescriptor {
124124
Future<String> read() async => _contents;
125125

126126
Stream<List<int>> readAsBytes() =>
127-
new Stream.fromIterable([utf8.encode(_contents)]);
127+
Stream.fromIterable([utf8.encode(_contents)]);
128128

129129
Future _validate(String prettyPath, List<int> actualContents) {
130130
var actualContentsText = utf8.decode(actualContents);
131131
if (_contents == actualContentsText) return null;
132-
throw fail(_textMismatchMessage(prettyPath, _contents, actualContentsText));
132+
fail(_textMismatchMessage(prettyPath, _contents, actualContentsText));
133133
}
134134

135135
String _textMismatchMessage(
@@ -177,20 +177,19 @@ class _MatcherFileDescriptor extends FileDescriptor {
177177
/// contents.
178178
final bool _isBinary;
179179

180-
_MatcherFileDescriptor(String name, this._matcher, {bool isBinary: false})
180+
_MatcherFileDescriptor(String name, this._matcher, {bool isBinary = false})
181181
: _isBinary = isBinary,
182182
super.protected(name);
183183

184184
Stream<List<int>> readAsBytes() =>
185-
throw new UnsupportedError("Matcher files can't be created or read.");
185+
throw UnsupportedError("Matcher files can't be created or read.");
186186

187187
Future _validate(String prettyPath, List<int> actualContents) async {
188188
try {
189189
expect(
190190
_isBinary ? actualContents : utf8.decode(actualContents), _matcher);
191191
} on TestFailure catch (error) {
192-
throw new TestFailure(
193-
'Invalid contents for file "$prettyPath":\n' + error.message);
192+
fail('Invalid contents for file "$prettyPath":\n${error.message}');
194193
}
195194
}
196195
}

lib/src/nothing_descriptor.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ class NothingDescriptor extends Descriptor {
2323
Future validate([String parent]) async {
2424
var fullPath = p.join(parent ?? sandbox, name);
2525
var pretty = prettyPath(fullPath);
26-
if (new File(fullPath).existsSync()) {
26+
if (File(fullPath).existsSync()) {
2727
fail('Expected nothing to exist at "$pretty", but found a file.');
28-
} else if (new Directory(fullPath).existsSync()) {
28+
} else if (Directory(fullPath).existsSync()) {
2929
fail('Expected nothing to exist at "$pretty", but found a directory.');
30-
} else if (new Link(fullPath).existsSync()) {
30+
} else if (Link(fullPath).existsSync()) {
3131
fail('Expected nothing to exist at "$pretty", but found a link.');
3232
}
3333
}

lib/src/pattern_descriptor.dart

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import 'utils.dart';
1616
/// A function that takes a name for a [Descriptor] and returns a [Descriptor].
1717
/// This is used for [PatternDescriptor]s, where the name isn't known
1818
/// ahead-of-time.
19-
typedef Descriptor _EntryCreator(String name);
19+
typedef _EntryCreator = Descriptor Function(String name);
2020

2121
/// A descriptor that matches filesystem entity names by [Pattern] rather than
2222
/// by exact [String].
@@ -31,20 +31,19 @@ class PatternDescriptor extends Descriptor {
3131
/// matching [pattern].
3232
final _EntryCreator _fn;
3333

34-
PatternDescriptor(Pattern pattern, Descriptor child(String basename))
35-
: pattern = pattern,
36-
_fn = child,
34+
PatternDescriptor(this.pattern, Descriptor child(String basename))
35+
: _fn = child,
3736
super('$pattern');
3837

3938
/// Validates that there is some filesystem entity in [parent] that matches
4039
/// [pattern] and the child entry. This finds all entities in [parent]
41-
/// matching [pattern], then passes each of their names to the [EntityCreator]
42-
/// and validates the result. If exactly one succeeds, [this] is considered
43-
/// valid.
40+
/// matching [pattern], then passes each of their names to `child` provided
41+
/// in the constructor and validates the result. If exactly one succeeds,
42+
/// `this` is considered valid.
4443
Future validate([String parent]) async {
4544
var inSandbox = parent == null;
4645
parent ??= sandbox;
47-
var matchingEntries = await new Directory(parent)
46+
var matchingEntries = await Directory(parent)
4847
.list()
4948
.map((entry) =>
5049
entry is File ? entry.resolveSymbolicLinksSync() : entry.path)
@@ -54,13 +53,13 @@ class PatternDescriptor extends Descriptor {
5453

5554
var location = inSandbox ? "sandbox" : '"${prettyPath(parent)}"';
5655
if (matchingEntries.isEmpty) {
57-
fail('No entries found in $location matching ${_patternDescription}.');
56+
fail('No entries found in $location matching $_patternDescription.');
5857
}
5958

6059
var results = await Future.wait(matchingEntries.map((entry) {
6160
var basename = p.basename(entry);
6261
return runZoned(() {
63-
return Result.capture(new Future.sync(() async {
62+
return Result.capture(Future.sync(() async {
6463
await _fn(basename).validate(parent);
6564
return basename;
6665
}));
@@ -72,7 +71,7 @@ class PatternDescriptor extends Descriptor {
7271
}).toList());
7372

7473
var successes = results.where((result) => result.isValue).toList();
75-
if (successes.length == 0) {
74+
if (successes.isEmpty) {
7675
await waitAndReportErrors(results.map((result) => result.asFuture));
7776
} else if (successes.length > 1) {
7877
fail('Multiple valid entries found in $location matching '
@@ -88,13 +87,13 @@ class PatternDescriptor extends Descriptor {
8887
if (pattern is! RegExp) return '$pattern';
8988

9089
var regExp = pattern as RegExp;
91-
var flags = new StringBuffer();
90+
var flags = StringBuffer();
9291
if (!regExp.isCaseSensitive) flags.write('i');
9392
if (regExp.isMultiLine) flags.write('m');
9493
return '/${regExp.pattern}/$flags';
9594
}
9695

9796
Future create([String parent]) {
98-
throw new UnsupportedError("Pattern descriptors don't support create().");
97+
throw UnsupportedError("Pattern descriptors don't support create().");
9998
}
10099
}

lib/src/sandbox.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ String get sandbox {
2323
addTearDown(() async {
2424
var sandbox = _sandbox;
2525
_sandbox = null;
26-
await new Directory(sandbox).delete(recursive: true);
26+
await Directory(sandbox).delete(recursive: true);
2727
});
2828

2929
return _sandbox;

0 commit comments

Comments
 (0)