Skip to content

Commit e0aca53

Browse files
authored
Turn on stricter analyzer options (flutter#17)
(and fix the associated warnings & errors)
1 parent 3ba4cf2 commit e0aca53

36 files changed

+813
-323
lines changed

.analysis_options

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ linter:
1515

1616
# === error rules ===
1717
- avoid_empty_else
18-
# TODO - comment_references
18+
- comment_references
1919
- cancel_subscriptions
20-
# TODO - close_sinks
20+
- close_sinks
2121
- control_flow_in_finally
2222
- empty_statements
2323
- hash_and_equals
@@ -32,14 +32,14 @@ linter:
3232

3333
# === style rules ===
3434
- always_declare_return_types
35-
# TODO - always_specify_types
36-
# TODO - annotate_overrides
35+
- always_specify_types
36+
- annotate_overrides
3737
# TODO - avoid_as
3838
- avoid_init_to_null
3939
- avoid_return_types_on_setters
4040
- await_only_futures
41-
# TODO - camel_case_types
42-
# TODO - constant_identifier_names
41+
- camel_case_types
42+
- constant_identifier_names
4343
- control_flow_in_finally
4444
- empty_catches
4545
- empty_constructor_bodies
@@ -53,14 +53,14 @@ linter:
5353
- package_api_docs
5454
- package_prefixed_library_names
5555
- prefer_is_not_empty
56-
# TODO - public_member_api_docs
56+
- public_member_api_docs
5757
- slash_for_doc_comments
5858
- sort_constructors_first
59-
# TODO - sort_unnamed_constructors_first
59+
- sort_unnamed_constructors_first
6060
- super_goes_last
61-
# TODO - type_annotate_public_apis
61+
- type_annotate_public_apis
6262
- type_init_formals
63-
# TODO - unawaited_futures
63+
- unawaited_futures
6464
- unnecessary_brace_in_string_interp
6565
- unnecessary_getters_setters
6666

lib/memory.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5+
import 'src/backends/memory.dart';
6+
import 'src/interface.dart';
7+
58
/// An implementation of [FileSystem] that exists entirely in memory with an
69
/// internal representation loosely based on the Filesystem Hierarchy Standard.
710
/// [MemoryFileSystem] is suitable for mocking and tests, as well as for

lib/src/backends/chroot/chroot_directory.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ part of file.src.backends.chroot;
66

77
class _ChrootDirectory extends _ChrootFileSystemEntity<Directory, io.Directory>
88
with ForwardingDirectory {
9+
_ChrootDirectory(ChrootFileSystem fs, String path) : super(fs, path);
10+
911
factory _ChrootDirectory.wrapped(
1012
ChrootFileSystem fs,
1113
Directory delegate, {
@@ -15,8 +17,6 @@ class _ChrootDirectory extends _ChrootFileSystemEntity<Directory, io.Directory>
1517
return new _ChrootDirectory(fs, localPath);
1618
}
1719

18-
_ChrootDirectory(ChrootFileSystem fs, String path) : super(fs, path);
19-
2020
@override
2121
FileSystemEntityType get expectedType => FileSystemEntityType.DIRECTORY;
2222

lib/src/backends/chroot/chroot_file.dart

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@
44

55
part of file.src.backends.chroot;
66

7+
typedef dynamic _SetupCallback();
8+
79
class _ChrootFile extends _ChrootFileSystemEntity<File, io.File>
810
with ForwardingFile {
11+
_ChrootFile(ChrootFileSystem fs, String path) : super(fs, path);
12+
913
factory _ChrootFile.wrapped(
1014
ChrootFileSystem fs,
1115
io.File delegate, {
@@ -15,8 +19,6 @@ class _ChrootFile extends _ChrootFileSystemEntity<File, io.File>
1519
return new _ChrootFile(fs, localPath);
1620
}
1721

18-
_ChrootFile(ChrootFileSystem fs, String path) : super(fs, path);
19-
2022
@override
2123
FileSystemEntityType get expectedType => FileSystemEntityType.FILE;
2224

@@ -25,7 +27,7 @@ class _ChrootFile extends _ChrootFileSystemEntity<File, io.File>
2527

2628
@override
2729
Future<File> rename(String newPath) async {
28-
var setUp = () {};
30+
_SetupCallback setUp = () {};
2931

3032
if (await fileSystem.type(newPath, followLinks: false) ==
3133
FileSystemEntityType.LINK) {
@@ -72,7 +74,7 @@ class _ChrootFile extends _ChrootFileSystemEntity<File, io.File>
7274

7375
@override
7476
File renameSync(String newPath) {
75-
var setUp = () {};
77+
_SetupCallback setUp = () {};
7678

7779
if (fileSystem.typeSync(newPath, followLinks: false) ==
7880
FileSystemEntityType.LINK) {
@@ -125,7 +127,7 @@ class _ChrootFile extends _ChrootFileSystemEntity<File, io.File>
125127
String path = fileSystem._resolve(
126128
this.path,
127129
followLinks: false,
128-
notFound: recursive ? _NotFoundBehavior.MKDIR : _NotFoundBehavior.ALLOW,
130+
notFound: recursive ? _NotFoundBehavior.mkdir : _NotFoundBehavior.allow,
129131
);
130132

131133
String real() => fileSystem._real(path, resolve: false);
@@ -134,7 +136,7 @@ class _ChrootFile extends _ChrootFileSystemEntity<File, io.File>
134136

135137
if (await type() == FileSystemEntityType.LINK) {
136138
path = fileSystem._resolve(p.basename(path),
137-
from: p.dirname(path), notFound: _NotFoundBehavior.ALLOW_AT_TAIL);
139+
from: p.dirname(path), notFound: _NotFoundBehavior.allowAtTail);
138140
switch (await type()) {
139141
case FileSystemEntityType.NOT_FOUND:
140142
await _rawDelegate(real()).create();
@@ -157,7 +159,7 @@ class _ChrootFile extends _ChrootFileSystemEntity<File, io.File>
157159
String path = fileSystem._resolve(
158160
this.path,
159161
followLinks: false,
160-
notFound: recursive ? _NotFoundBehavior.MKDIR : _NotFoundBehavior.ALLOW,
162+
notFound: recursive ? _NotFoundBehavior.mkdir : _NotFoundBehavior.allow,
161163
);
162164

163165
String real() => fileSystem._real(path, resolve: false);
@@ -166,7 +168,7 @@ class _ChrootFile extends _ChrootFileSystemEntity<File, io.File>
166168

167169
if (type() == FileSystemEntityType.LINK) {
168170
path = fileSystem._resolve(p.basename(path),
169-
from: p.dirname(path), notFound: _NotFoundBehavior.ALLOW_AT_TAIL);
171+
from: p.dirname(path), notFound: _NotFoundBehavior.allowAtTail);
170172
switch (type()) {
171173
case FileSystemEntityType.NOT_FOUND:
172174
_rawDelegate(real()).createSync();

lib/src/backends/chroot/chroot_file_system.dart

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,14 @@ class ChrootFileSystem extends FileSystem {
6060
String get _localRoot => p.rootPrefix(root);
6161

6262
@override
63-
Directory directory(path) => new _ChrootDirectory(this, common.getPath(path));
63+
Directory directory(dynamic path) =>
64+
new _ChrootDirectory(this, common.getPath(path));
6465

6566
@override
66-
File file(path) => new _ChrootFile(this, common.getPath(path));
67+
File file(dynamic path) => new _ChrootFile(this, common.getPath(path));
6768

6869
@override
69-
Link link(path) => new _ChrootLink(this, common.getPath(path));
70+
Link link(dynamic path) => new _ChrootLink(this, common.getPath(path));
7071

7172
@override
7273
p.Context get path =>
@@ -99,7 +100,7 @@ class ChrootFileSystem extends FileSystem {
99100
/// Gets the path context for this file system given the current working dir.
100101
101102
@override
102-
set currentDirectory(path) {
103+
set currentDirectory(dynamic path) {
103104
String value;
104105
if (path is io.Directory) {
105106
value = path.path;
@@ -109,7 +110,7 @@ class ChrootFileSystem extends FileSystem {
109110
throw new ArgumentError('Invalid type for "path": ${path?.runtimeType}');
110111
}
111112

112-
value = _resolve(value, notFound: _NotFoundBehavior.THROW);
113+
value = _resolve(value, notFound: _NotFoundBehavior.throwError);
113114
String realPath = _real(value, resolve: false);
114115
switch (delegate.typeSync(realPath, followLinks: false)) {
115116
case FileSystemEntityType.DIRECTORY:
@@ -128,7 +129,7 @@ class ChrootFileSystem extends FileSystem {
128129
try {
129130
path = _resolve(path);
130131
} on FileSystemException {
131-
return new Future.value(const _NotFoundFileStat());
132+
return new Future<FileStat>.value(const _NotFoundFileStat());
132133
}
133134
return delegate.stat(_real(path, resolve: false));
134135
}
@@ -164,7 +165,8 @@ class ChrootFileSystem extends FileSystem {
164165
try {
165166
realPath = _real(path, followLinks: followLinks);
166167
} on FileSystemException {
167-
return new Future.value(FileSystemEntityType.NOT_FOUND);
168+
return new Future<FileSystemEntityType>.value(
169+
FileSystemEntityType.NOT_FOUND);
168170
}
169171
return delegate.type(realPath, followLinks: false);
170172
}
@@ -244,14 +246,20 @@ class ChrootFileSystem extends FileSystem {
244246
/// only if [followLinks] is `true`. Symbolic links found in the middle of
245247
/// the path will always be resolved.
246248
///
247-
/// If [throwIfNotFound] is `true`, and the path cannot be resolved, a file
248-
/// system exception is thrown - otherwise the resolution will halt and the
249-
/// partially resolved path will be returned.
249+
/// If the path cannot be resolved, and [notFound] is:
250+
/// - [_NotFoundBehavior.throwError]: a [FileSystemException] is thrown.
251+
/// - [_NotFoundBehavior.mkdir]: the path will be created as needed.
252+
/// - [_NotFoundBehavior.allowAtTail]: a [FileSystemException] is thrown,
253+
/// unless only the *tail* path element cannot be resolved, in which case
254+
/// the resolution will halt at the tail element, and the partially
255+
/// resolved path will be returned.
256+
/// - [_NotFoundBehavior.allow] (the default), the resolution will halt and
257+
/// the partially resolved path will be returned.
250258
String _resolve(
251259
String path, {
252260
String from,
253261
bool followLinks: true,
254-
_NotFoundBehavior notFound: _NotFoundBehavior.ALLOW,
262+
_NotFoundBehavior notFound: _NotFoundBehavior.allow,
255263
}) {
256264
p.Context ctx = _context;
257265
String root = _localRoot;
@@ -304,19 +312,19 @@ class ChrootFileSystem extends FileSystem {
304312
}
305313

306314
switch (notFound) {
307-
case _NotFoundBehavior.MKDIR:
315+
case _NotFoundBehavior.mkdir:
308316
if (parts.isNotEmpty) {
309317
delegate.directory(realPath).createSync();
310318
}
311319
break;
312-
case _NotFoundBehavior.ALLOW:
320+
case _NotFoundBehavior.allow:
313321
return returnEarly();
314-
case _NotFoundBehavior.ALLOW_AT_TAIL:
322+
case _NotFoundBehavior.allowAtTail:
315323
if (parts.isEmpty) {
316324
return returnEarly();
317325
}
318326
throw notFoundException();
319-
case _NotFoundBehavior.THROW:
327+
case _NotFoundBehavior.throwError:
320328
throw notFoundException();
321329
}
322330
break;
@@ -351,10 +359,10 @@ class _ChrootJailException implements IOException {}
351359

352360
/// What to do when `NOT_FOUND` paths are encountered while resolving.
353361
enum _NotFoundBehavior {
354-
ALLOW,
355-
ALLOW_AT_TAIL,
356-
THROW,
357-
MKDIR,
362+
allow,
363+
allowAtTail,
364+
throwError,
365+
mkdir,
358366
}
359367

360368
/// A [FileStat] representing a `NOT_FOUND` entity.

lib/src/backends/chroot/chroot_file_system_entity.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ abstract class _ChrootFileSystemEntity<T extends FileSystemEntity,
7676

7777
@override
7878
String resolveSymbolicLinksSync() =>
79-
fileSystem._resolve(path, notFound: _NotFoundBehavior.THROW);
79+
fileSystem._resolve(path, notFound: _NotFoundBehavior.throwError);
8080

8181
@override
8282
Future<FileStat> stat() {
@@ -103,7 +103,7 @@ abstract class _ChrootFileSystemEntity<T extends FileSystemEntity,
103103
@override
104104
Future<T> delete({bool recursive: false}) async {
105105
String path = fileSystem._resolve(this.path,
106-
followLinks: false, notFound: _NotFoundBehavior.THROW);
106+
followLinks: false, notFound: _NotFoundBehavior.throwError);
107107

108108
String real(String path) => fileSystem._real(path, resolve: false);
109109
Future<FileSystemEntityType> type(String path) =>
@@ -114,7 +114,7 @@ abstract class _ChrootFileSystemEntity<T extends FileSystemEntity,
114114
await fileSystem.delegate.link(real(path)).delete();
115115
} else {
116116
String resolvedPath = fileSystem._resolve(p.basename(path),
117-
from: p.dirname(path), notFound: _NotFoundBehavior.ALLOW_AT_TAIL);
117+
from: p.dirname(path), notFound: _NotFoundBehavior.allowAtTail);
118118
if (!recursive && await type(resolvedPath) != expectedType) {
119119
String msg = expectedType == FileSystemEntityType.FILE
120120
? 'Is a directory'
@@ -133,7 +133,7 @@ abstract class _ChrootFileSystemEntity<T extends FileSystemEntity,
133133
@override
134134
void deleteSync({bool recursive: false}) {
135135
String path = fileSystem._resolve(this.path,
136-
followLinks: false, notFound: _NotFoundBehavior.THROW);
136+
followLinks: false, notFound: _NotFoundBehavior.throwError);
137137

138138
String real(String path) => fileSystem._real(path, resolve: false);
139139
FileSystemEntityType type(String path) =>
@@ -144,7 +144,7 @@ abstract class _ChrootFileSystemEntity<T extends FileSystemEntity,
144144
fileSystem.delegate.link(real(path)).deleteSync();
145145
} else {
146146
String resolvedPath = fileSystem._resolve(p.basename(path),
147-
from: p.dirname(path), notFound: _NotFoundBehavior.ALLOW_AT_TAIL);
147+
from: p.dirname(path), notFound: _NotFoundBehavior.allowAtTail);
148148
if (!recursive && type(resolvedPath) != expectedType) {
149149
String msg = expectedType == FileSystemEntityType.FILE
150150
? 'Is a directory'

lib/src/backends/chroot/chroot_link.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ part of file.src.backends.chroot;
66

77
class _ChrootLink extends _ChrootFileSystemEntity<Link, io.Link>
88
with ForwardingLink {
9+
_ChrootLink(ChrootFileSystem fs, String path) : super(fs, path);
10+
911
factory _ChrootLink.wrapped(
1012
ChrootFileSystem fs,
1113
io.Link delegate, {
@@ -15,8 +17,6 @@ class _ChrootLink extends _ChrootFileSystemEntity<Link, io.Link>
1517
return new _ChrootLink(fs, localPath);
1618
}
1719

18-
_ChrootLink(ChrootFileSystem fs, String path) : super(fs, path);
19-
2020
@override
2121
Future<bool> exists() => delegate.exists();
2222

lib/src/backends/local/local_file_system.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,18 @@ part of file.src.backends.local;
99
/// Since this implementation of the [FileSystem] interface delegates to
1010
/// `dart:io`, is is not suitable for use in the browser.
1111
class LocalFileSystem extends FileSystem {
12+
/// Creates a new `LocalFileSystem`.
1213
const LocalFileSystem();
1314

1415
@override
15-
Directory directory(path) =>
16+
Directory directory(dynamic path) =>
1617
new _LocalDirectory(this, shim.newDirectory(path));
1718

1819
@override
19-
File file(path) => new _LocalFile(this, shim.newFile(path));
20+
File file(dynamic path) => new _LocalFile(this, shim.newFile(path));
2021

2122
@override
22-
Link link(path) => new _LocalLink(this, shim.newLink(path));
23+
Link link(dynamic path) => new _LocalLink(this, shim.newLink(path));
2324

2425
@override
2526
p.Context get path => new p.Context();

lib/src/backends/memory/memory_directory.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class _MemoryDirectory extends _MemoryFileSystemEntity implements Directory {
5555
_DirectoryNode node = fileSystem._findNode(dirname);
5656
_checkExists(node, () => dirname);
5757
_checkIsDir(node, () => dirname);
58-
var name = () => '$basename$_tempCounter';
58+
String name() => '$basename$_tempCounter';
5959
while (node.children.containsKey(name())) {
6060
_tempCounter++;
6161
}
@@ -90,7 +90,7 @@ class _MemoryDirectory extends _MemoryFileSystemEntity implements Directory {
9090
bool recursive: false,
9191
bool followLinks: true,
9292
}) =>
93-
new Stream.fromIterable(listSync(
93+
new Stream<FileSystemEntity>.fromIterable(listSync(
9494
recursive: recursive,
9595
followLinks: followLinks,
9696
));

0 commit comments

Comments
 (0)