Cleanup (#20)
* dartfmt
* use new Travis CI Dart tasks
* A couple of lint fixes
* use recommended name for analysis_options
diff --git a/.travis.yml b/.travis.yml
index e110e4e..93b8adb 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,6 +1,14 @@
language: dart
sudo: false
dart:
- - stable
- dev
-script: ./tool/travis.sh
+ - stable
+ - 1.23.0
+ - 1.22.1
+cache:
+ directories:
+ - $HOME/.pub-cache
+dart_task:
+ - test: --platform vm
+ - dartfmt
+ - dartanalyzer
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a86aabd..e725bda 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -68,7 +68,7 @@
* The preferred top-level method is now `createStaticHandler`. `getHandler` is deprecated.
* Set `content-type` header if the mime type of the requested file can be determined from the file extension.
* Respond with `304-Not modified` against `IF-MODIFIED-SINCE` request header.
-* Better error when provided a non-existant `fileSystemPath`.
+* Better error when provided a non-existent `fileSystemPath`.
* Added `example/example_server.dart`.
## 0.1.1+1
diff --git a/README.md b/README.md
index ffe0e26..b0bf77d 100644
--- a/README.md
+++ b/README.md
@@ -1,7 +1,6 @@
`shelf_static` is a `Handler` for the Dart `shelf` package.
[![Build Status](https://travis-ci.org/dart-lang/shelf_static.svg?branch=master)](https://travis-ci.org/dart-lang/shelf_static?branch=master)
-[![Coverage Status](https://coveralls.io/repos/dart-lang/shelf_static/badge.svg?branch=master&service=github)](https://coveralls.io/github/dart-lang/shelf_static?branch=master)
### Example
```dart
diff --git a/.analysis_options b/analysis_options.yaml
similarity index 100%
rename from .analysis_options
rename to analysis_options.yaml
diff --git a/example/example_server.dart b/example/example_server.dart
index 1233eef..087b421 100644
--- a/example/example_server.dart
+++ b/example/example_server.dart
@@ -60,6 +60,7 @@
abbr: 'f',
defaultsTo: false,
negatable: false,
- help: 'List the files in the source directory instead of servering the default document - "$_defaultDoc".');
+ help: 'List the files in the source directory instead of serving the '
+ 'default document - "$_defaultDoc".');
const _defaultDoc = 'index.html';
diff --git a/lib/src/directory_listing.dart b/lib/src/directory_listing.dart
index 8339fb9..a391a52 100644
--- a/lib/src/directory_listing.dart
+++ b/lib/src/directory_listing.dart
@@ -77,9 +77,12 @@
controller.add(encoding.encode(string));
}
- String heading = path.relative(dirPath, from: fileSystemPath);
- if (heading == '.') heading = '/';
- else heading = '/$heading/';
+ var heading = path.relative(dirPath, from: fileSystemPath);
+ if (heading == '.') {
+ heading = '/';
+ } else {
+ heading = '/$heading/';
+ }
add(_getHeader(sanitizer.convert(heading)));
new Directory(dirPath).list().listen((FileSystemEntity entity) {
diff --git a/lib/src/static_handler.dart b/lib/src/static_handler.dart
index a2e3e71..9f67de9 100644
--- a/lib/src/static_handler.dart
+++ b/lib/src/static_handler.dart
@@ -64,7 +64,7 @@
var entityType = FileSystemEntity.typeSync(fsPath, followLinks: true);
- File file = null;
+ File file;
if (entityType == FileSystemEntityType.FILE) {
file = new File(fsPath);
@@ -115,14 +115,15 @@
String contentType;
if (useHeaderBytesForContentType) {
- var length =
- math.min(contentTypeResolver.magicNumbersMaxLength, file.lengthSync());
+ var length = math.min(
+ contentTypeResolver.magicNumbersMaxLength, file.lengthSync());
var byteSink = new ByteAccumulatorSink();
await file.openRead(0, length).listen(byteSink.add).asFuture();
- contentType = contentTypeResolver.lookup(file.path, headerBytes: byteSink.bytes);
+ contentType =
+ contentTypeResolver.lookup(file.path, headerBytes: byteSink.bytes);
} else {
contentType = contentTypeResolver.lookup(file.path);
}
diff --git a/test/alternative_root_test.dart b/test/alternative_root_test.dart
index 28ae4e8..4b7852d 100644
--- a/test/alternative_root_test.dart
+++ b/test/alternative_root_test.dart
@@ -20,12 +20,10 @@
});
d.file('root.txt', 'root txt').create();
- d
- .dir('files', [
+ d.dir('files', [
d.file('test.txt', 'test txt content'),
d.file('with space.txt', 'with space content')
- ])
- .create();
+ ]).create();
currentSchedule.onComplete.schedule(() {
d.defaultRoot = null;
diff --git a/test/basic_file_test.dart b/test/basic_file_test.dart
index 97b5929..4511243 100644
--- a/test/basic_file_test.dart
+++ b/test/basic_file_test.dart
@@ -2,8 +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 'dart:io';
import 'dart:convert';
+import 'dart:io';
+
import 'package:http_parser/http_parser.dart';
import 'package:mime/mime.dart' as mime;
import 'package:path/path.dart' as p;
@@ -35,7 +36,8 @@
r"OJE7pB/VXmF3CdseucmjxaAruR41Pl9p/Gbyoq5B9FeL2OR7zJ+3aC/X8QdQCyIArPs"
r"HkQAAAABJRU5ErkJggg==";
- var webpBytesContent = r"UklGRiQAAABXRUJQVlA4IBgAAAAwAQCdASoBAAEAAQAcJaQAA3AA/v3AgAA=";
+ var webpBytesContent =
+ r"UklGRiQAAABXRUJQVlA4IBgAAAAwAQCdASoBAAEAAQAcJaQAA3AA/v3AgAA=";
d.dir('files', [
d.file('test.txt', 'test txt content'),
@@ -226,8 +228,16 @@
test('header_bytes_test_webp should be image/webp', () {
schedule(() {
final mime.MimeTypeResolver resolver = new mime.MimeTypeResolver();
- resolver.addMagicNumber(<int>[0x52,0x49,0x46,0x46,0x00,0x00,0x00,0x00,0x57,0x45,0x42,0x50], "image/webp",
- mask: <int>[0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF]);
+ resolver.addMagicNumber(
+ <int>[
+ 0x52, 0x49, 0x46, 0x46, 0x00, 0x00, //
+ 0x00, 0x00, 0x57, 0x45, 0x42, 0x50
+ ],
+ "image/webp",
+ mask: <int>[
+ 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, //
+ 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF
+ ]);
final dynamic handler = createStaticHandler(d.defaultRoot,
useHeaderBytesForContentType: true, contentTypeResolver: resolver);
@@ -237,6 +247,5 @@
});
});
});
-
});
}
diff --git a/test/default_document_test.dart b/test/default_document_test.dart
index 0ec133f..39943a4 100644
--- a/test/default_document_test.dart
+++ b/test/default_document_test.dart
@@ -23,12 +23,10 @@
d.file('index.html', '<html></html>').create();
d.file('root.txt', 'root txt').create();
- d
- .dir('files', [
+ d.dir('files', [
d.file('index.html', '<html><body>files</body></html>'),
d.file('with space.txt', 'with space content')
- ])
- .create();
+ ]).create();
currentSchedule.onComplete.schedule(() {
d.defaultRoot = null;
diff --git a/test/directory_listing_test.dart b/test/directory_listing_test.dart
index 93ce260..192691e 100644
--- a/test/directory_listing_test.dart
+++ b/test/directory_listing_test.dart
@@ -22,13 +22,11 @@
d.file('index.html', '<html></html>').create();
d.file('root.txt', 'root txt').create();
- d
- .dir('files', [
+ d.dir('files', [
d.file('index.html', '<html><body>files</body></html>'),
d.file('with space.txt', 'with space content'),
d.dir('empty subfolder', []),
- ])
- .create();
+ ]).create();
currentSchedule.onComplete.schedule(() {
d.defaultRoot = null;
@@ -77,8 +75,10 @@
return makeRequest(handler, '/files/empty subfolder').then((response) {
expect(response.statusCode, HttpStatus.MOVED_PERMANENTLY);
- expect(response.headers, containsPair(HttpHeaders.LOCATION,
- 'http://localhost/files/empty%20subfolder/'));
+ expect(
+ response.headers,
+ containsPair(HttpHeaders.LOCATION,
+ 'http://localhost/files/empty%20subfolder/'));
});
});
});
diff --git a/test/get_handler_test.dart b/test/get_handler_test.dart
index c957001..bdb150b 100644
--- a/test/get_handler_test.dart
+++ b/test/get_handler_test.dart
@@ -20,12 +20,10 @@
});
d.file('root.txt', 'root txt').create();
- d
- .dir('files', [
+ d.dir('files', [
d.file('test.txt', 'test txt content'),
d.file('with space.txt', 'with space content')
- ])
- .create();
+ ]).create();
currentSchedule.onComplete.schedule(() {
d.defaultRoot = null;
diff --git a/test/symbolic_link_test.dart b/test/symbolic_link_test.dart
index 4a655d6..ad2b747 100644
--- a/test/symbolic_link_test.dart
+++ b/test/symbolic_link_test.dart
@@ -20,7 +20,9 @@
});
});
- d.dir('originals', [d.file('index.html', '<html></html>'),]).create();
+ d.dir('originals', [
+ d.file('index.html', '<html></html>'),
+ ]).create();
d.dir('alt_root').create();
diff --git a/test/test_util.dart b/test/test_util.dart
index 51652e5..ce54dce 100644
--- a/test/test_util.dart
+++ b/test/test_util.dart
@@ -53,9 +53,9 @@
return datesEqualToSecond(_target, item);
}
- Description describe(Description descirption) => descirption.add(
- 'Must be at the same moment as $_target with resolution '
- 'to the second.');
+ Description describe(Description description) =>
+ description.add('Must be at the same moment as $_target with resolution '
+ 'to the second.');
}
bool datesEqualToSecond(DateTime d1, DateTime d2) {
diff --git a/tool/travis.sh b/tool/travis.sh
deleted file mode 100755
index 0f7c725..0000000
--- a/tool/travis.sh
+++ /dev/null
@@ -1,15 +0,0 @@
-#!/bin/bash
-
-# Fast fail the script on failures.
-set -e
-
-pub run test
-
-# Install dart_coveralls; gather and send coverage data.
-if [ "$COVERALLS_TOKEN" ] && [ "$TRAVIS_DART_VERSION" = "stable" ]; then
- pub global activate dart_coveralls
- pub global run dart_coveralls report \
- --exclude-test-files \
- --log-level warning \
- test/test_all.dart
-fi