Enable and fix a number of lints (#64)
diff --git a/analysis_options.yaml b/analysis_options.yaml
index 4a486d1..47ffcd4 100644
--- a/analysis_options.yaml
+++ b/analysis_options.yaml
@@ -6,7 +6,14 @@
linter:
rules:
+ - avoid_catching_errors
+ - avoid_function_literals_in_foreach_calls
+ - avoid_private_typedef_functions
+ - avoid_redundant_argument_values
+ - avoid_renaming_method_parameters
+ - avoid_returning_null_for_void
- avoid_unused_constructor_parameters
+ - avoid_void_async
- await_only_futures
- camel_case_types
- cancel_subscriptions
@@ -14,15 +21,45 @@
- control_flow_in_finally
- directives_ordering
- empty_statements
+ - file_names
- hash_and_equals
- implementation_imports
- iterable_contains_unrelated_type
+ - join_return_with_assignment
+ - lines_longer_than_80_chars
- list_remove_unrelated_type
+ - missing_whitespace_between_adjacent_strings
+ - no_runtimeType_toString
- non_constant_identifier_names
+ - only_throw_errors
- overridden_fields
- package_api_docs
- package_names
- package_prefixed_library_names
+ - prefer_asserts_in_initializer_lists
+ - prefer_const_constructors
+ - prefer_const_declarations
+ - prefer_expression_function_bodies
+ - prefer_final_locals
+ - prefer_function_declarations_over_variables
+ - prefer_initializing_formals
+ - prefer_inlined_adds
+ - prefer_interpolation_to_compose_strings
+ - prefer_is_not_operator
+ - prefer_null_aware_operators
+ - prefer_relative_imports
+ - prefer_typing_uninitialized_variables
+ - prefer_void_to_null
+ - provide_deprecation_message
+ - sort_pub_dependencies
- test_types_in_equals
- throw_in_finally
- unnecessary_brace_in_string_interps
+ - unnecessary_lambdas
+ - unnecessary_null_aware_assignments
+ - unnecessary_overrides
+ - unnecessary_parenthesis
+ - unnecessary_statements
+ - unnecessary_string_interpolations
+ - use_string_buffers
+ - void_checks
diff --git a/benchmark/benchmark.dart b/benchmark/benchmark.dart
index 60550a4..a7fbb7a 100644
--- a/benchmark/benchmark.dart
+++ b/benchmark/benchmark.dart
@@ -38,8 +38,8 @@
arguments = args;
for (var style in [p.Style.posix, p.Style.url, p.Style.windows]) {
- var context = p.Context(style: style);
- var files = genericPaths.toList()..addAll(platformPaths[style]);
+ final context = p.Context(style: style);
+ final files = genericPaths.toList()..addAll(platformPaths[style]);
void benchmark(String name, Function function) {
runBenchmark('${style.name}-$name', 100000, () {
@@ -95,12 +95,12 @@
function();
}
- var stopwatch = Stopwatch()..start();
+ final stopwatch = Stopwatch()..start();
for (var i = 0; i < count; i++) {
function();
}
- var rate =
+ final rate =
(count / stopwatch.elapsedMicroseconds).toStringAsFixed(5).padLeft(9);
print('${name.padLeft(32)}: $rate iter/us (${stopwatch.elapsed})');
}
diff --git a/lib/path.dart b/lib/path.dart
index 29e87ec..a501e0c 100644
--- a/lib/path.dart
+++ b/lib/path.dart
@@ -100,16 +100,15 @@
if (Style.platform == Style.url) {
_current = uri.resolve('.').toString();
- return _current;
} else {
- var path = uri.toFilePath();
+ final path = uri.toFilePath();
// Remove trailing '/' or '\' unless it is the only thing left
// (for instance the root on Linux).
- var lastIndex = path.length - 1;
+ final lastIndex = path.length - 1;
assert(path[lastIndex] == '/' || path[lastIndex] == '\\');
_current = lastIndex == 0 ? path : path.substring(0, lastIndex);
- return _current;
}
+ return _current;
}
/// The last value returned by [Uri.base].
diff --git a/lib/src/context.dart b/lib/src/context.dart
index df1eba2..9e58e4a 100644
--- a/lib/src/context.dart
+++ b/lib/src/context.dart
@@ -122,7 +122,7 @@
///
/// context.dirname('path/to/'); // -> 'path'
String dirname(String path) {
- var parsed = _parse(path);
+ final parsed = _parse(path);
parsed.removeTrailingSeparators();
if (parsed.parts.isEmpty) return parsed.root ?? '.';
if (parsed.parts.length == 1) return parsed.root ?? '.';
@@ -216,7 +216,7 @@
String part6,
String part7,
String part8]) {
- var parts = <String>[
+ final parts = <String>[
part1,
part2,
part3,
@@ -245,7 +245,7 @@
///
/// For a fixed number of parts, [join] is usually terser.
String joinAll(Iterable<String> parts) {
- var buffer = StringBuffer();
+ final buffer = StringBuffer();
var needsSeparator = false;
var isAbsoluteAndNotRootRelative = false;
@@ -253,8 +253,8 @@
if (isRootRelative(part) && isAbsoluteAndNotRootRelative) {
// If the new part is root-relative, it preserves the previous root but
// replaces the path after it.
- var parsed = _parse(part);
- var path = buffer.toString();
+ final parsed = _parse(part);
+ final path = buffer.toString();
parsed.root =
path.substring(0, style.rootLength(path, withDrive: true));
if (style.needsSeparator(parsed.root)) {
@@ -304,7 +304,7 @@
/// // Windows
/// context.split(r'C:\path\to\foo'); // -> [r'C:\', 'path', 'to', 'foo']
List<String> split(String path) {
- var parsed = _parse(path);
+ final parsed = _parse(path);
// Filter out empty parts that exist due to multiple separators in a row.
parsed.parts = parsed.parts.where((part) => part.isNotEmpty).toList();
if (parsed.root != null) parsed.parts.insert(0, parsed.root);
@@ -327,7 +327,7 @@
path = absolute(path);
if (style != Style.windows && !_needsNormalization(path)) return path;
- var parsed = _parse(path);
+ final parsed = _parse(path);
parsed.normalize(canonicalize: true);
return parsed.toString();
}
@@ -343,7 +343,7 @@
String normalize(String path) {
if (!_needsNormalization(path)) return path;
- var parsed = _parse(path);
+ final parsed = _parse(path);
parsed.normalize();
return parsed.toString();
}
@@ -351,14 +351,14 @@
/// Returns whether [path] needs to be normalized.
bool _needsNormalization(String path) {
var start = 0;
- var codeUnits = path.codeUnits;
+ final codeUnits = path.codeUnits;
int previousPrevious;
int previous;
// Skip past the root before we start looking for snippets that need
// normalization. We want to normalize "//", but not when it's part of
// "http://".
- var root = style.rootLength(path);
+ final root = style.rootLength(path);
if (root != 0) {
start = root;
previous = chars.slash;
@@ -373,7 +373,7 @@
}
for (var i = start; i < codeUnits.length; i++) {
- var codeUnit = codeUnits[i];
+ final codeUnit = codeUnits[i];
if (style.isSeparator(codeUnit)) {
// Forward slashes in Windows paths are normalized to backslashes.
if (style == Style.windows && codeUnit == chars.slash) return true;
@@ -469,8 +469,8 @@
throw PathException('Unable to find a path to "$path" from "$from".');
}
- var fromParsed = _parse(from)..normalize();
- var pathParsed = _parse(path)..normalize();
+ final fromParsed = _parse(from)..normalize();
+ final pathParsed = _parse(path)..normalize();
if (fromParsed.parts.isNotEmpty && fromParsed.parts[0] == '.') {
return pathParsed.toString();
@@ -552,8 +552,8 @@
// Make both paths the same level of relative. We're only able to do the
// quick comparison if both paths are in the same format, and making a path
// absolute is faster than making it relative.
- var parentIsAbsolute = isAbsolute(parent);
- var childIsAbsolute = isAbsolute(child);
+ final parentIsAbsolute = isAbsolute(parent);
+ final childIsAbsolute = isAbsolute(child);
if (parentIsAbsolute && !childIsAbsolute) {
child = absolute(child);
if (style.isRootRelative(parent)) parent = absolute(parent);
@@ -561,8 +561,8 @@
parent = absolute(parent);
if (style.isRootRelative(child)) child = absolute(child);
} else if (childIsAbsolute && parentIsAbsolute) {
- var childIsRootRelative = style.isRootRelative(child);
- var parentIsRootRelative = style.isRootRelative(parent);
+ final childIsRootRelative = style.isRootRelative(child);
+ final parentIsRootRelative = style.isRootRelative(parent);
if (childIsRootRelative && !parentIsRootRelative) {
child = absolute(child);
@@ -571,7 +571,7 @@
}
}
- var result = _isWithinOrEqualsFast(parent, child);
+ final result = _isWithinOrEqualsFast(parent, child);
if (result != _PathRelation.inconclusive) return result;
String relative;
@@ -600,8 +600,8 @@
// a single dot easily enough.
if (parent == '.') parent = '';
- var parentRootLength = style.rootLength(parent);
- var childRootLength = style.rootLength(child);
+ final parentRootLength = style.rootLength(parent);
+ final childRootLength = style.rootLength(child);
// If the roots aren't the same length, we know both paths are absolute or
// both are root-relative, and thus that the roots are meaningfully
@@ -616,8 +616,8 @@
// isWithin("C:/bar", "D:/bar/baz") //=> false
// isWithin("http://example.com/", "http://example.org/bar") //=> false
for (var i = 0; i < parentRootLength; i++) {
- var parentCodeUnit = parent.codeUnitAt(i);
- var childCodeUnit = child.codeUnitAt(i);
+ final parentCodeUnit = parent.codeUnitAt(i);
+ final childCodeUnit = child.codeUnitAt(i);
if (!style.codeUnitsEqual(parentCodeUnit, childCodeUnit)) {
return _PathRelation.different;
}
@@ -720,12 +720,12 @@
// As long as the remainders of the two paths don't have any unresolved
// ".." components, we can be confident that [child] is not within
// [parent].
- var childDirection = _pathDirection(child, childIndex);
+ final childDirection = _pathDirection(child, childIndex);
if (childDirection != _PathDirection.belowRoot) {
return _PathRelation.inconclusive;
}
- var parentDirection = _pathDirection(parent, parentIndex);
+ final parentDirection = _pathDirection(parent, parentIndex);
if (parentDirection != _PathDirection.belowRoot) {
return _PathRelation.inconclusive;
}
@@ -747,7 +747,7 @@
lastParentSeparator ??= math.max(0, parentRootLength - 1);
}
- var direction =
+ final direction =
_pathDirection(parent, lastParentSeparator ?? parentRootLength - 1);
if (direction == _PathDirection.atRoot) return _PathRelation.equal;
return direction == _PathDirection.aboveRoot
@@ -758,7 +758,7 @@
// We've reached the end of the parent path, which means it's time to make a
// decision. Before we do, though, we'll check the rest of the child to see
// what that tells us.
- var direction = _pathDirection(child, childIndex);
+ final direction = _pathDirection(child, childIndex);
// If there are no more components in the child, then it's the same as
// the parent.
@@ -818,7 +818,7 @@
if (i == path.length) break;
// Move through the path component to the next separator.
- var start = i;
+ final start = i;
while (i < path.length && !style.isSeparator(path.codeUnitAt(i))) {
i++;
}
@@ -865,10 +865,10 @@
// paths have the same hash code.
path = absolute(path);
- var result = _hashFast(path);
+ final result = _hashFast(path);
if (result != null) return result;
- var parsed = _parse(path);
+ final parsed = _parse(path);
parsed.normalize();
return _hashFast(parsed.toString());
}
@@ -882,7 +882,7 @@
var beginning = true;
var wasSeparator = true;
for (var i = 0; i < path.length; i++) {
- var codeUnit = style.canonicalizeCodeUnit(path.codeUnitAt(i));
+ final codeUnit = style.canonicalizeCodeUnit(path.codeUnitAt(i));
// Take advantage of the fact that collisions are allowed to ignore
// separators entirely. This lets us avoid worrying about cases like
@@ -902,7 +902,7 @@
// We've hit "/." at the end of the path, which we can ignore.
if (i + 1 == path.length) break;
- var next = path.codeUnitAt(i + 1);
+ final next = path.codeUnitAt(i + 1);
// We can just ignore "/./", since they don't affect the semantics of
// the path.
@@ -934,7 +934,7 @@
///
/// context.withoutExtension('path/to/foo.dart'); // -> 'path/to/foo'
String withoutExtension(String path) {
- var parsed = _parse(path);
+ final parsed = _parse(path);
for (var i = parsed.parts.length - 1; i >= 0; i--) {
if (parsed.parts[i].isNotEmpty) {
@@ -1032,7 +1032,7 @@
/// // -> r'a/b.dart'
/// context.prettyUri('file:///root/path'); // -> 'file:///root/path'
String prettyUri(uri) {
- var typedUri = _parseUri(uri);
+ final typedUri = _parseUri(uri);
if (typedUri.scheme == 'file' && style == Style.url) {
return typedUri.toString();
} else if (typedUri.scheme != 'file' &&
@@ -1041,8 +1041,8 @@
return typedUri.toString();
}
- var path = normalize(fromUri(typedUri));
- var rel = relative(path);
+ final path = normalize(fromUri(typedUri));
+ final rel = relative(path);
// Only return a relative path if it's actually shorter than the absolute
// path. This avoids ugly things like long "../" chains to get to the root
@@ -1075,7 +1075,7 @@
}
// Show the arguments.
- var message = StringBuffer();
+ final message = StringBuffer();
message.write('$method(');
message.write(args
.take(numArgs)
diff --git a/lib/src/internal_style.dart b/lib/src/internal_style.dart
index 53b4ade..b7f6e93 100644
--- a/lib/src/internal_style.dart
+++ b/lib/src/internal_style.dart
@@ -44,7 +44,7 @@
/// returns `null`.
@override
String getRoot(String path) {
- var length = rootLength(path);
+ final length = rootLength(path);
if (length > 0) return path.substring(0, length);
return isRootRelative(path) ? path[0] : null;
}
@@ -61,7 +61,7 @@
/// Returns the URI that represents the relative path made of [parts].
@override
Uri relativePathToUri(String path) {
- var segments = context.split(path);
+ final segments = context.split(path);
// Ensure that a trailing slash in the path produces a trailing slash in the
// URL.
diff --git a/lib/src/parsed_path.dart b/lib/src/parsed_path.dart
index 42c9f2f..9efd529 100644
--- a/lib/src/parsed_path.dart
+++ b/lib/src/parsed_path.dart
@@ -40,13 +40,13 @@
factory ParsedPath.parse(String path, InternalStyle style) {
// Remove the root prefix, if any.
- var root = style.getRoot(path);
- var isRootRelative = style.isRootRelative(path);
+ final root = style.getRoot(path);
+ final isRootRelative = style.isRootRelative(path);
if (root != null) path = path.substring(root.length);
// Split the parts on path separators.
- var parts = <String>[];
- var separators = <String>[];
+ final parts = <String>[];
+ final separators = <String>[];
var start = 0;
@@ -78,7 +78,7 @@
this.style, this.root, this.isRootRelative, this.parts, this.separators);
String get basename {
- var copy = clone();
+ final copy = clone();
copy.removeTrailingSeparators();
if (copy.parts.isEmpty) return root ?? '';
return copy.parts.last;
@@ -100,7 +100,7 @@
void normalize({bool canonicalize = false}) {
// Handle '.', '..', and empty parts.
var leadingDoubles = 0;
- var newParts = <String>[];
+ final newParts = <String>[];
for (var part in parts) {
if (part == '.' || part == '') {
// Do nothing. Ignore it.
@@ -128,7 +128,7 @@
}
// Canonicalize separators.
- var newSeparators = List<String>.generate(
+ final newSeparators = List<String>.generate(
newParts.length, (_) => style.separator,
growable: true);
newSeparators.insert(
@@ -150,7 +150,7 @@
@override
String toString() {
- var builder = StringBuffer();
+ final builder = StringBuffer();
if (root != null) builder.write(root);
for (var i = 0; i < parts.length; i++) {
builder.write(separators[i]);
@@ -167,12 +167,12 @@
/// Returns a two-element list. The first is the name of the file without any
/// extension. The second is the extension or "" if it has none.
List<String> _splitExtension() {
- var file = parts.lastWhere((p) => p != '', orElse: () => null);
+ final file = parts.lastWhere((p) => p != '', orElse: () => null);
if (file == null) return ['', ''];
if (file == '..') return ['..', ''];
- var lastDot = file.lastIndexOf('.');
+ final lastDot = file.lastIndexOf('.');
// If there is no dot, or it's the first character, like '.bashrc', it
// doesn't count.
diff --git a/lib/src/path_set.dart b/lib/src/path_set.dart
index 03a7eeb..01397c8 100644
--- a/lib/src/path_set.dart
+++ b/lib/src/path_set.dart
@@ -62,7 +62,7 @@
void clear() => _inner.clear();
@override
- bool contains(Object other) => _inner.contains(other);
+ bool contains(Object element) => _inner.contains(element);
@override
bool containsAll(Iterable<Object> other) => _inner.containsAll(other);
diff --git a/lib/src/style/posix.dart b/lib/src/style/posix.dart
index 0b9803b..f8b7e78 100644
--- a/lib/src/style/posix.dart
+++ b/lib/src/style/posix.dart
@@ -59,7 +59,7 @@
@override
Uri absolutePathToUri(String path) {
- var parsed = ParsedPath.parse(path, this);
+ final parsed = ParsedPath.parse(path, this);
if (parsed.parts.isEmpty) {
// If the path is a bare root (e.g. "/"), [components] will
// currently be empty. We add two empty components so the URL constructor
diff --git a/lib/src/style/url.dart b/lib/src/style/url.dart
index b9d6dff..1f99bd5 100644
--- a/lib/src/style/url.dart
+++ b/lib/src/style/url.dart
@@ -51,7 +51,7 @@
if (isSeparator(path.codeUnitAt(0))) return 1;
for (var i = 0; i < path.length; i++) {
- var codeUnit = path.codeUnitAt(i);
+ final codeUnit = path.codeUnitAt(i);
if (isSeparator(codeUnit)) return 0;
if (codeUnit == chars.colon) {
if (i == 0) return 0;
@@ -59,7 +59,7 @@
// The root part is up until the next '/', or the full path. Skip ':'
// (and '//' if it exists) and search for '/' after that.
if (path.startsWith('//', i + 1)) i += 3;
- var index = path.indexOf('/', i);
+ final index = path.indexOf('/', i);
if (index <= 0) return path.length;
// file: URLs sometimes consider Windows drive letters part of the root.
diff --git a/lib/src/style/windows.dart b/lib/src/style/windows.dart
index 287733a..64d5a3f 100644
--- a/lib/src/style/windows.dart
+++ b/lib/src/style/windows.dart
@@ -77,7 +77,7 @@
@override
String getRelativeRoot(String path) {
- var length = rootLength(path);
+ final length = rootLength(path);
if (length == 1) return path[0];
return null;
}
@@ -105,13 +105,13 @@
@override
Uri absolutePathToUri(String path) {
- var parsed = ParsedPath.parse(path, this);
+ final parsed = ParsedPath.parse(path, this);
if (parsed.root.startsWith(r'\\')) {
// Network paths become "file://server/share/path/to/file".
// The root is of the form "\\server\share". We want "server" to be the
// URI host, and "share" to be the first element of the path.
- var rootParts = parsed.root.split('\\').where((part) => part != '');
+ final rootParts = parsed.root.split('\\').where((part) => part != '');
parsed.parts.insert(0, rootParts.last);
if (parsed.hasTrailingSeparator) {
@@ -155,7 +155,7 @@
if (codeUnit1 ^ codeUnit2 != _asciiCaseBit) return false;
// Now we just need to verify that one of the code units is an ASCII letter.
- var upperCase1 = codeUnit1 | _asciiCaseBit;
+ final upperCase1 = codeUnit1 | _asciiCaseBit;
return upperCase1 >= chars.lowerA && upperCase1 <= chars.lowerZ;
}
diff --git a/test/browser_test.dart b/test/browser_test.dart
index 1a6f623..ac25dbe 100644
--- a/test/browser_test.dart
+++ b/test/browser_test.dart
@@ -12,18 +12,18 @@
void main() {
group('new Context()', () {
test('uses the window location if root and style are omitted', () {
- var context = path.Context();
+ final context = path.Context();
expect(context.current,
Uri.parse(window.location.href).resolve('.').toString());
});
test('uses "." if root is omitted', () {
- var context = path.Context(style: path.Style.platform);
+ final context = path.Context(style: path.Style.platform);
expect(context.current, '.');
});
test('uses the host platform if style is omitted', () {
- var context = path.Context();
+ final context = path.Context();
expect(context.style, path.Style.platform);
});
});
diff --git a/test/io_test.dart b/test/io_test.dart
index da57a77..293d762 100644
--- a/test/io_test.dart
+++ b/test/io_test.dart
@@ -12,17 +12,17 @@
void main() {
group('new Context()', () {
test('uses the current directory if root and style are omitted', () {
- var context = path.Context();
+ final context = path.Context();
expect(context.current, io.Directory.current.path);
});
test('uses "." if root is omitted', () {
- var context = path.Context(style: path.Style.platform);
+ final context = path.Context(style: path.Style.platform);
expect(context.current, '.');
});
test('uses the host platform if style is omitted', () {
- var context = path.Context();
+ final context = path.Context();
expect(context.style, path.Style.platform);
});
});
@@ -41,10 +41,10 @@
});
test('uses the previous working directory if deleted', () {
- var dir = io.Directory.current.path;
+ final dir = io.Directory.current.path;
try {
- var temp = io.Directory.systemTemp.createTempSync('path_test');
- var tempPath = temp.path;
+ final temp = io.Directory.systemTemp.createTempSync('path_test');
+ final tempPath = temp.path;
io.Directory.current = temp;
// Call "current" once so that it can be cached.
@@ -61,7 +61,7 @@
});
test('registers changes to the working directory', () {
- var dir = io.Directory.current.path;
+ final dir = io.Directory.current.path;
try {
expect(path.absolute('foo/bar'), equals(path.join(dir, 'foo/bar')));
expect(
@@ -81,7 +81,7 @@
// rather than just a custom context because we do some processing in
// [path.current] that has clobbered the root in the past.
test('absolute works on root working directory', () {
- var dir = path.current;
+ final dir = path.current;
try {
io.Directory.current = path.rootPrefix(path.current);
diff --git a/test/path_map_test.dart b/test/path_map_test.dart
index c9170e1..127d7c6 100644
--- a/test/path_map_test.dart
+++ b/test/path_map_test.dart
@@ -9,7 +9,7 @@
void main() {
group('considers equal', () {
test('two identical paths', () {
- var map = PathMap<int>();
+ final map = PathMap<int>();
map[join('foo', 'bar')] = 1;
map[join('foo', 'bar')] = 2;
expect(map, hasLength(1));
@@ -17,7 +17,7 @@
});
test('two logically equivalent paths', () {
- var map = PathMap<int>();
+ final map = PathMap<int>();
map['foo'] = 1;
map[absolute('foo')] = 2;
expect(map, hasLength(1));
@@ -26,7 +26,7 @@
});
test('two nulls', () {
- var map = PathMap<int>();
+ final map = PathMap<int>();
map[null] = 1;
map[null] = 2;
expect(map, hasLength(1));
@@ -36,7 +36,7 @@
group('considers unequal', () {
test('two distinct paths', () {
- var map = PathMap<int>();
+ final map = PathMap<int>();
map['foo'] = 1;
map['bar'] = 2;
expect(map, hasLength(2));
@@ -45,7 +45,7 @@
});
test('a path and null', () {
- var map = PathMap<int>();
+ final map = PathMap<int>();
map['foo'] = 1;
map[null] = 2;
expect(map, hasLength(2));
@@ -55,7 +55,7 @@
});
test('uses the custom context', () {
- var map = PathMap<int>(context: windows);
+ final map = PathMap<int>(context: windows);
map['FOO'] = 1;
map['foo'] = 2;
expect(map, hasLength(1));
@@ -64,14 +64,14 @@
group('.of()', () {
test("copies the existing map's keys", () {
- var map = PathMap.of({'foo': 1, 'bar': 2});
+ final map = PathMap.of({'foo': 1, 'bar': 2});
expect(map, hasLength(2));
expect(map, containsPair('foo', 1));
expect(map, containsPair('bar', 2));
});
test('uses the second value in the case of duplicates', () {
- var map = PathMap.of({'foo': 1, absolute('foo'): 2});
+ final map = PathMap.of({'foo': 1, absolute('foo'): 2});
expect(map, hasLength(1));
expect(map, containsPair('foo', 2));
expect(map, containsPair(absolute('foo'), 2));
diff --git a/test/path_set_test.dart b/test/path_set_test.dart
index cfbab9e..3214e19 100644
--- a/test/path_set_test.dart
+++ b/test/path_set_test.dart
@@ -9,7 +9,7 @@
void main() {
group('considers equal', () {
test('two identical paths', () {
- var set = PathSet();
+ final set = PathSet();
expect(set.add(join('foo', 'bar')), isTrue);
expect(set.add(join('foo', 'bar')), isFalse);
expect(set, hasLength(1));
@@ -17,7 +17,7 @@
});
test('two logically equivalent paths', () {
- var set = PathSet();
+ final set = PathSet();
expect(set.add('foo'), isTrue);
expect(set.add(absolute('foo')), isFalse);
expect(set, hasLength(1));
@@ -26,7 +26,7 @@
});
test('two nulls', () {
- var set = PathSet();
+ final set = PathSet();
expect(set.add(null), isTrue);
expect(set.add(null), isFalse);
expect(set, hasLength(1));
@@ -36,7 +36,7 @@
group('considers unequal', () {
test('two distinct paths', () {
- var set = PathSet();
+ final set = PathSet();
expect(set.add('foo'), isTrue);
expect(set.add('bar'), isTrue);
expect(set, hasLength(2));
@@ -45,7 +45,7 @@
});
test('a path and null', () {
- var set = PathSet();
+ final set = PathSet();
expect(set.add('foo'), isTrue);
expect(set.add(null), isTrue);
expect(set, hasLength(2));
@@ -55,7 +55,7 @@
});
test('uses the custom context', () {
- var set = PathSet(context: windows);
+ final set = PathSet(context: windows);
expect(set.add('FOO'), isTrue);
expect(set.add('foo'), isFalse);
expect(set, hasLength(1));
@@ -64,14 +64,14 @@
group('.of()', () {
test("copies the existing set's keys", () {
- var set = PathSet.of(['foo', 'bar']);
+ final set = PathSet.of(['foo', 'bar']);
expect(set, hasLength(2));
expect(set, contains('foo'));
expect(set, contains('bar'));
});
test('uses the first value in the case of duplicates', () {
- var set = PathSet.of(['foo', absolute('foo')]);
+ final set = PathSet.of(['foo', absolute('foo')]);
expect(set, hasLength(1));
expect(set, contains('foo'));
expect(set, contains(absolute('foo')));
diff --git a/test/path_test.dart b/test/path_test.dart
index ce7efdb..6625ac4 100644
--- a/test/path_test.dart
+++ b/test/path_test.dart
@@ -27,12 +27,12 @@
group('new Context()', () {
test('uses the given current directory', () {
- var context = path.Context(current: '/a/b/c');
+ final context = path.Context(current: '/a/b/c');
expect(context.current, '/a/b/c');
});
test('uses the given style', () {
- var context = path.Context(style: path.Style.windows);
+ final context = path.Context(style: path.Style.windows);
expect(context.style, path.Style.windows);
});
});
diff --git a/test/posix_test.dart b/test/posix_test.dart
index b08d584..bd6c3e0 100644
--- a/test/posix_test.dart
+++ b/test/posix_test.dart
@@ -8,7 +8,7 @@
import 'utils.dart';
void main() {
- var context = path.Context(style: path.Style.posix, current: '/root/path');
+ final context = path.Context(style: path.Style.posix, current: '/root/path');
test('separator', () {
expect(context.separator, '/');
@@ -366,7 +366,7 @@
});
group('from relative root', () {
- var r = path.Context(style: path.Style.posix, current: 'foo/bar');
+ final r = path.Context(style: path.Style.posix, current: 'foo/bar');
test('given absolute path', () {
expect(r.relative('/'), equals('/'));
@@ -387,7 +387,7 @@
});
test('from a root with extension', () {
- var r = path.Context(style: path.Style.posix, current: '/dir.ext');
+ final r = path.Context(style: path.Style.posix, current: '/dir.ext');
expect(r.relative('/dir.ext/file'), 'file');
});
@@ -400,7 +400,7 @@
});
test('with a root parameter and a relative root', () {
- var r = path.Context(style: path.Style.posix, current: 'relative/root');
+ final r = path.Context(style: path.Style.posix, current: 'relative/root');
expect(r.relative('/foo/bar/baz', from: '/foo/bar'), equals('baz'));
expect(() => r.relative('..', from: '/foo/bar'), throwsPathException);
expect(
@@ -409,7 +409,7 @@
});
test('from a . root', () {
- var r = path.Context(style: path.Style.posix, current: '.');
+ final r = path.Context(style: path.Style.posix, current: '.');
expect(r.relative('/foo/bar/baz'), equals('/foo/bar/baz'));
expect(r.relative('foo/bar/baz'), equals('foo/bar/baz'));
});
@@ -440,7 +440,7 @@
});
test('from a relative root', () {
- var r = path.Context(style: path.Style.posix, current: 'foo/bar');
+ final r = path.Context(style: path.Style.posix, current: 'foo/bar');
expect(r.isWithin('.', 'a/b/c'), isTrue);
expect(r.isWithin('.', '../a/b/c'), isFalse);
expect(r.isWithin('.', '../../a/foo/b/c'), isFalse);
@@ -477,7 +477,7 @@
});
test('from a relative root', () {
- var r = path.Context(style: path.Style.posix, current: 'foo/bar');
+ final r = path.Context(style: path.Style.posix, current: 'foo/bar');
expectEquals(r, 'a/b', 'a/b');
expectNotEquals(r, '.', 'foo/bar');
expectNotEquals(r, '.', '../a/b');
diff --git a/test/relative_test.dart b/test/relative_test.dart
index 140b9e2..657611b 100644
--- a/test/relative_test.dart
+++ b/test/relative_test.dart
@@ -26,7 +26,7 @@
}
void relativeTest(path.Context context, String prefix) {
- var isRelative = (context.current == '.');
+ final isRelative = context.current == '.';
// Cases where the arguments are absolute paths.
void expectRelative(String result, String pathArg, String fromArg) {
expect(context.relative(pathArg, from: fromArg), context.normalize(result));
diff --git a/test/url_test.dart b/test/url_test.dart
index 6af34e6..ebb4532 100644
--- a/test/url_test.dart
+++ b/test/url_test.dart
@@ -8,7 +8,7 @@
import 'utils.dart';
void main() {
- var context = path.Context(
+ final context = path.Context(
style: path.Style.url, current: 'http://dartlang.org/root/path');
test('separator', () {
@@ -549,7 +549,7 @@
});
group('from relative root', () {
- var r = path.Context(style: path.Style.url, current: 'foo/bar');
+ final r = path.Context(style: path.Style.url, current: 'foo/bar');
test('given absolute path', () {
expect(r.relative('http://google.com/'), equals('http://google.com'));
@@ -574,7 +574,7 @@
});
group('from root-relative root', () {
- var r = path.Context(style: path.Style.url, current: '/foo/bar');
+ final r = path.Context(style: path.Style.url, current: '/foo/bar');
test('given absolute path', () {
expect(r.relative('http://google.com/'), equals('http://google.com'));
@@ -599,7 +599,7 @@
});
test('from a root with extension', () {
- var r = path.Context(style: path.Style.url, current: '/dir.ext');
+ final r = path.Context(style: path.Style.url, current: '/dir.ext');
expect(r.relative('/dir.ext/file'), 'file');
});
@@ -643,7 +643,7 @@
});
test('with a root parameter and a relative root', () {
- var r = path.Context(style: path.Style.url, current: 'relative/root');
+ final r = path.Context(style: path.Style.url, current: 'relative/root');
expect(r.relative('/foo/bar/baz', from: '/foo/bar'), equals('baz'));
expect(r.relative('/foo/bar/baz', from: 'http://dartlang.org/foo/bar'),
equals('/foo/bar/baz'));
@@ -669,7 +669,7 @@
});
test('from a . root', () {
- var r = path.Context(style: path.Style.url, current: '.');
+ final r = path.Context(style: path.Style.url, current: '.');
expect(r.relative('http://dartlang.org/foo/bar/baz'),
equals('http://dartlang.org/foo/bar/baz'));
expect(r.relative('file:///foo/bar/baz'), equals('file:///foo/bar/baz'));
@@ -727,7 +727,7 @@
});
test('from a relative root', () {
- var r = path.Context(style: path.Style.url, current: 'foo/bar');
+ final r = path.Context(style: path.Style.url, current: 'foo/bar');
expect(r.isWithin('.', 'a/b/c'), isTrue);
expect(r.isWithin('.', '../a/b/c'), isFalse);
expect(r.isWithin('.', '../../a/foo/b/c'), isFalse);
@@ -773,7 +773,7 @@
});
test('from a relative root', () {
- var r = path.Context(style: path.Style.posix, current: 'foo/bar');
+ final r = path.Context(style: path.Style.posix, current: 'foo/bar');
expectEquals(r, 'a/b', 'a/b');
expectNotEquals(r, '.', 'foo/bar');
expectNotEquals(r, '.', '../a/b');
diff --git a/test/utils.dart b/test/utils.dart
index 68e3c85..dfd62a8 100644
--- a/test/utils.dart
+++ b/test/utils.dart
@@ -6,7 +6,7 @@
import 'package:path/path.dart' as p;
/// A matcher for a closure that throws a [path.PathException].
-final throwsPathException = throwsA(TypeMatcher<p.PathException>());
+final throwsPathException = throwsA(const TypeMatcher<p.PathException>());
void expectEquals(p.Context context, String path1, String path2) {
expect(context.equals(path1, path2), isTrue,
diff --git a/test/windows_test.dart b/test/windows_test.dart
index 096fa6f..2d6b90f 100644
--- a/test/windows_test.dart
+++ b/test/windows_test.dart
@@ -8,7 +8,7 @@
import 'utils.dart';
void main() {
- var context =
+ final context =
path.Context(style: path.Style.windows, current: r'C:\root\path');
test('separator', () {
@@ -449,7 +449,7 @@
});
group('from relative root', () {
- var r = path.Context(style: path.Style.windows, current: r'foo\bar');
+ final r = path.Context(style: path.Style.windows, current: r'foo\bar');
test('given absolute path', () {
expect(r.relative(r'C:\'), equals(r'C:\'));
@@ -472,7 +472,7 @@
});
group('from root-relative root', () {
- var r = path.Context(style: path.Style.windows, current: r'\foo\bar');
+ final r = path.Context(style: path.Style.windows, current: r'\foo\bar');
test('given absolute path', () {
expect(r.relative(r'C:\'), equals(r'C:\'));
@@ -497,7 +497,7 @@
});
test('from a root with extension', () {
- var r = path.Context(style: path.Style.windows, current: r'C:\dir.ext');
+ final r = path.Context(style: path.Style.windows, current: r'C:\dir.ext');
expect(r.relative(r'C:\dir.ext\file'), 'file');
});
@@ -513,7 +513,7 @@
});
test('with a root parameter and a relative root', () {
- var r =
+ final r =
path.Context(style: path.Style.windows, current: r'relative\root');
expect(r.relative(r'C:\foo\bar\baz', from: r'C:\foo\bar'), equals('baz'));
expect(() => r.relative('..', from: r'C:\foo\bar'), throwsPathException);
@@ -528,7 +528,7 @@
});
test('from a . root', () {
- var r = path.Context(style: path.Style.windows, current: '.');
+ final r = path.Context(style: path.Style.windows, current: '.');
expect(r.relative(r'C:\foo\bar\baz'), equals(r'C:\foo\bar\baz'));
expect(r.relative(r'foo\bar\baz'), equals(r'foo\bar\baz'));
expect(r.relative(r'\foo\bar\baz'), equals(r'\foo\bar\baz'));
@@ -575,7 +575,7 @@
});
test('from a relative root', () {
- var r = path.Context(style: path.Style.windows, current: r'foo\bar');
+ final r = path.Context(style: path.Style.windows, current: r'foo\bar');
expect(r.isWithin('.', r'a\b\c'), isTrue);
expect(r.isWithin('.', r'..\a\b\c'), isFalse);
expect(r.isWithin('.', r'..\..\a\foo\b\c'), isFalse);
@@ -627,7 +627,7 @@
});
test('from a relative root', () {
- var r = path.Context(style: path.Style.windows, current: r'foo\bar');
+ final r = path.Context(style: path.Style.windows, current: r'foo\bar');
expectEquals(r, r'a\b', r'a\b');
expectNotEquals(r, '.', r'foo\bar');
expectNotEquals(r, '.', r'..\a\b');