Skip to content

Commit

Permalink
Turn on stricter analyzer options (flutter#17)
Browse files Browse the repository at this point in the history
(and fix the associated warnings & errors)
  • Loading branch information
tvolkert authored Feb 1, 2017
1 parent 3ba4cf2 commit e0aca53
Show file tree
Hide file tree
Showing 36 changed files with 813 additions and 323 deletions.
20 changes: 10 additions & 10 deletions .analysis_options
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ linter:

# === error rules ===
- avoid_empty_else
# TODO - comment_references
- comment_references
- cancel_subscriptions
# TODO - close_sinks
- close_sinks
- control_flow_in_finally
- empty_statements
- hash_and_equals
Expand All @@ -32,14 +32,14 @@ linter:

# === style rules ===
- always_declare_return_types
# TODO - always_specify_types
# TODO - annotate_overrides
- always_specify_types
- annotate_overrides
# TODO - avoid_as
- avoid_init_to_null
- avoid_return_types_on_setters
- await_only_futures
# TODO - camel_case_types
# TODO - constant_identifier_names
- camel_case_types
- constant_identifier_names
- control_flow_in_finally
- empty_catches
- empty_constructor_bodies
Expand All @@ -53,14 +53,14 @@ linter:
- package_api_docs
- package_prefixed_library_names
- prefer_is_not_empty
# TODO - public_member_api_docs
- public_member_api_docs
- slash_for_doc_comments
- sort_constructors_first
# TODO - sort_unnamed_constructors_first
- sort_unnamed_constructors_first
- super_goes_last
# TODO - type_annotate_public_apis
- type_annotate_public_apis
- type_init_formals
# TODO - unawaited_futures
- unawaited_futures
- unnecessary_brace_in_string_interp
- unnecessary_getters_setters

Expand Down
3 changes: 3 additions & 0 deletions lib/memory.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
// 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 'src/backends/memory.dart';
import 'src/interface.dart';

/// An implementation of [FileSystem] that exists entirely in memory with an
/// internal representation loosely based on the Filesystem Hierarchy Standard.
/// [MemoryFileSystem] is suitable for mocking and tests, as well as for
Expand Down
4 changes: 2 additions & 2 deletions lib/src/backends/chroot/chroot_directory.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ part of file.src.backends.chroot;

class _ChrootDirectory extends _ChrootFileSystemEntity<Directory, io.Directory>
with ForwardingDirectory {
_ChrootDirectory(ChrootFileSystem fs, String path) : super(fs, path);

factory _ChrootDirectory.wrapped(
ChrootFileSystem fs,
Directory delegate, {
Expand All @@ -15,8 +17,6 @@ class _ChrootDirectory extends _ChrootFileSystemEntity<Directory, io.Directory>
return new _ChrootDirectory(fs, localPath);
}

_ChrootDirectory(ChrootFileSystem fs, String path) : super(fs, path);

@override
FileSystemEntityType get expectedType => FileSystemEntityType.DIRECTORY;

Expand Down
18 changes: 10 additions & 8 deletions lib/src/backends/chroot/chroot_file.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@

part of file.src.backends.chroot;

typedef dynamic _SetupCallback();

class _ChrootFile extends _ChrootFileSystemEntity<File, io.File>
with ForwardingFile {
_ChrootFile(ChrootFileSystem fs, String path) : super(fs, path);

factory _ChrootFile.wrapped(
ChrootFileSystem fs,
io.File delegate, {
Expand All @@ -15,8 +19,6 @@ class _ChrootFile extends _ChrootFileSystemEntity<File, io.File>
return new _ChrootFile(fs, localPath);
}

_ChrootFile(ChrootFileSystem fs, String path) : super(fs, path);

@override
FileSystemEntityType get expectedType => FileSystemEntityType.FILE;

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

@override
Future<File> rename(String newPath) async {
var setUp = () {};
_SetupCallback setUp = () {};

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

@override
File renameSync(String newPath) {
var setUp = () {};
_SetupCallback setUp = () {};

if (fileSystem.typeSync(newPath, followLinks: false) ==
FileSystemEntityType.LINK) {
Expand Down Expand Up @@ -125,7 +127,7 @@ class _ChrootFile extends _ChrootFileSystemEntity<File, io.File>
String path = fileSystem._resolve(
this.path,
followLinks: false,
notFound: recursive ? _NotFoundBehavior.MKDIR : _NotFoundBehavior.ALLOW,
notFound: recursive ? _NotFoundBehavior.mkdir : _NotFoundBehavior.allow,
);

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

if (await type() == FileSystemEntityType.LINK) {
path = fileSystem._resolve(p.basename(path),
from: p.dirname(path), notFound: _NotFoundBehavior.ALLOW_AT_TAIL);
from: p.dirname(path), notFound: _NotFoundBehavior.allowAtTail);
switch (await type()) {
case FileSystemEntityType.NOT_FOUND:
await _rawDelegate(real()).create();
Expand All @@ -157,7 +159,7 @@ class _ChrootFile extends _ChrootFileSystemEntity<File, io.File>
String path = fileSystem._resolve(
this.path,
followLinks: false,
notFound: recursive ? _NotFoundBehavior.MKDIR : _NotFoundBehavior.ALLOW,
notFound: recursive ? _NotFoundBehavior.mkdir : _NotFoundBehavior.allow,
);

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

if (type() == FileSystemEntityType.LINK) {
path = fileSystem._resolve(p.basename(path),
from: p.dirname(path), notFound: _NotFoundBehavior.ALLOW_AT_TAIL);
from: p.dirname(path), notFound: _NotFoundBehavior.allowAtTail);
switch (type()) {
case FileSystemEntityType.NOT_FOUND:
_rawDelegate(real()).createSync();
Expand Down
46 changes: 27 additions & 19 deletions lib/src/backends/chroot/chroot_file_system.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,14 @@ class ChrootFileSystem extends FileSystem {
String get _localRoot => p.rootPrefix(root);

@override
Directory directory(path) => new _ChrootDirectory(this, common.getPath(path));
Directory directory(dynamic path) =>
new _ChrootDirectory(this, common.getPath(path));

@override
File file(path) => new _ChrootFile(this, common.getPath(path));
File file(dynamic path) => new _ChrootFile(this, common.getPath(path));

@override
Link link(path) => new _ChrootLink(this, common.getPath(path));
Link link(dynamic path) => new _ChrootLink(this, common.getPath(path));

@override
p.Context get path =>
Expand Down Expand Up @@ -99,7 +100,7 @@ class ChrootFileSystem extends FileSystem {
/// Gets the path context for this file system given the current working dir.
@override
set currentDirectory(path) {
set currentDirectory(dynamic path) {
String value;
if (path is io.Directory) {
value = path.path;
Expand All @@ -109,7 +110,7 @@ class ChrootFileSystem extends FileSystem {
throw new ArgumentError('Invalid type for "path": ${path?.runtimeType}');
}

value = _resolve(value, notFound: _NotFoundBehavior.THROW);
value = _resolve(value, notFound: _NotFoundBehavior.throwError);
String realPath = _real(value, resolve: false);
switch (delegate.typeSync(realPath, followLinks: false)) {
case FileSystemEntityType.DIRECTORY:
Expand All @@ -128,7 +129,7 @@ class ChrootFileSystem extends FileSystem {
try {
path = _resolve(path);
} on FileSystemException {
return new Future.value(const _NotFoundFileStat());
return new Future<FileStat>.value(const _NotFoundFileStat());
}
return delegate.stat(_real(path, resolve: false));
}
Expand Down Expand Up @@ -164,7 +165,8 @@ class ChrootFileSystem extends FileSystem {
try {
realPath = _real(path, followLinks: followLinks);
} on FileSystemException {
return new Future.value(FileSystemEntityType.NOT_FOUND);
return new Future<FileSystemEntityType>.value(
FileSystemEntityType.NOT_FOUND);
}
return delegate.type(realPath, followLinks: false);
}
Expand Down Expand Up @@ -244,14 +246,20 @@ class ChrootFileSystem extends FileSystem {
/// only if [followLinks] is `true`. Symbolic links found in the middle of
/// the path will always be resolved.
///
/// If [throwIfNotFound] is `true`, and the path cannot be resolved, a file
/// system exception is thrown - otherwise the resolution will halt and the
/// partially resolved path will be returned.
/// If the path cannot be resolved, and [notFound] is:
/// - [_NotFoundBehavior.throwError]: a [FileSystemException] is thrown.
/// - [_NotFoundBehavior.mkdir]: the path will be created as needed.
/// - [_NotFoundBehavior.allowAtTail]: a [FileSystemException] is thrown,
/// unless only the *tail* path element cannot be resolved, in which case
/// the resolution will halt at the tail element, and the partially
/// resolved path will be returned.
/// - [_NotFoundBehavior.allow] (the default), the resolution will halt and
/// the partially resolved path will be returned.
String _resolve(
String path, {
String from,
bool followLinks: true,
_NotFoundBehavior notFound: _NotFoundBehavior.ALLOW,
_NotFoundBehavior notFound: _NotFoundBehavior.allow,
}) {
p.Context ctx = _context;
String root = _localRoot;
Expand Down Expand Up @@ -304,19 +312,19 @@ class ChrootFileSystem extends FileSystem {
}

switch (notFound) {
case _NotFoundBehavior.MKDIR:
case _NotFoundBehavior.mkdir:
if (parts.isNotEmpty) {
delegate.directory(realPath).createSync();
}
break;
case _NotFoundBehavior.ALLOW:
case _NotFoundBehavior.allow:
return returnEarly();
case _NotFoundBehavior.ALLOW_AT_TAIL:
case _NotFoundBehavior.allowAtTail:
if (parts.isEmpty) {
return returnEarly();
}
throw notFoundException();
case _NotFoundBehavior.THROW:
case _NotFoundBehavior.throwError:
throw notFoundException();
}
break;
Expand Down Expand Up @@ -351,10 +359,10 @@ class _ChrootJailException implements IOException {}

/// What to do when `NOT_FOUND` paths are encountered while resolving.
enum _NotFoundBehavior {
ALLOW,
ALLOW_AT_TAIL,
THROW,
MKDIR,
allow,
allowAtTail,
throwError,
mkdir,
}

/// A [FileStat] representing a `NOT_FOUND` entity.
Expand Down
10 changes: 5 additions & 5 deletions lib/src/backends/chroot/chroot_file_system_entity.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ abstract class _ChrootFileSystemEntity<T extends FileSystemEntity,

@override
String resolveSymbolicLinksSync() =>
fileSystem._resolve(path, notFound: _NotFoundBehavior.THROW);
fileSystem._resolve(path, notFound: _NotFoundBehavior.throwError);

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

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

String real(String path) => fileSystem._real(path, resolve: false);
FileSystemEntityType type(String path) =>
Expand All @@ -144,7 +144,7 @@ abstract class _ChrootFileSystemEntity<T extends FileSystemEntity,
fileSystem.delegate.link(real(path)).deleteSync();
} else {
String resolvedPath = fileSystem._resolve(p.basename(path),
from: p.dirname(path), notFound: _NotFoundBehavior.ALLOW_AT_TAIL);
from: p.dirname(path), notFound: _NotFoundBehavior.allowAtTail);
if (!recursive && type(resolvedPath) != expectedType) {
String msg = expectedType == FileSystemEntityType.FILE
? 'Is a directory'
Expand Down
4 changes: 2 additions & 2 deletions lib/src/backends/chroot/chroot_link.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ part of file.src.backends.chroot;

class _ChrootLink extends _ChrootFileSystemEntity<Link, io.Link>
with ForwardingLink {
_ChrootLink(ChrootFileSystem fs, String path) : super(fs, path);

factory _ChrootLink.wrapped(
ChrootFileSystem fs,
io.Link delegate, {
Expand All @@ -15,8 +17,6 @@ class _ChrootLink extends _ChrootFileSystemEntity<Link, io.Link>
return new _ChrootLink(fs, localPath);
}

_ChrootLink(ChrootFileSystem fs, String path) : super(fs, path);

@override
Future<bool> exists() => delegate.exists();

Expand Down
7 changes: 4 additions & 3 deletions lib/src/backends/local/local_file_system.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,18 @@ part of file.src.backends.local;
/// Since this implementation of the [FileSystem] interface delegates to
/// `dart:io`, is is not suitable for use in the browser.
class LocalFileSystem extends FileSystem {
/// Creates a new `LocalFileSystem`.
const LocalFileSystem();

@override
Directory directory(path) =>
Directory directory(dynamic path) =>
new _LocalDirectory(this, shim.newDirectory(path));

@override
File file(path) => new _LocalFile(this, shim.newFile(path));
File file(dynamic path) => new _LocalFile(this, shim.newFile(path));

@override
Link link(path) => new _LocalLink(this, shim.newLink(path));
Link link(dynamic path) => new _LocalLink(this, shim.newLink(path));

@override
p.Context get path => new p.Context();
Expand Down
4 changes: 2 additions & 2 deletions lib/src/backends/memory/memory_directory.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class _MemoryDirectory extends _MemoryFileSystemEntity implements Directory {
_DirectoryNode node = fileSystem._findNode(dirname);
_checkExists(node, () => dirname);
_checkIsDir(node, () => dirname);
var name = () => '$basename$_tempCounter';
String name() => '$basename$_tempCounter';
while (node.children.containsKey(name())) {
_tempCounter++;
}
Expand Down Expand Up @@ -90,7 +90,7 @@ class _MemoryDirectory extends _MemoryFileSystemEntity implements Directory {
bool recursive: false,
bool followLinks: true,
}) =>
new Stream.fromIterable(listSync(
new Stream<FileSystemEntity>.fromIterable(listSync(
recursive: recursive,
followLinks: followLinks,
));
Expand Down
Loading

0 comments on commit e0aca53

Please sign in to comment.