enable and fix a number of lints
diff --git a/analysis_options.yaml b/analysis_options.yaml
index 6ff678d..7f965d2 100644
--- a/analysis_options.yaml
+++ b/analysis_options.yaml
@@ -1,40 +1,43 @@
+include: package:pedantic/analysis_options.yaml
analyzer:
strong-mode:
implicit-casts: false
- errors:
- unused_element: error
- unused_import: error
- unused_local_variable: error
- dead_code: error
linter:
rules:
- # Errors
- avoid_empty_else
- #- comment_references
- - control_flow_in_finally
- - empty_statements
- - hash_and_equals
- - implementation_imports
- - test_types_in_equals
- - throw_in_finally
- - unrelated_type_equality_checks
- - valid_regexps
-
- # Style
- #- annotate_overrides
- avoid_init_to_null
- - avoid_return_types_on_setters
+ - avoid_null_checks_in_equality_operators
+ - avoid_unused_constructor_parameters
- await_only_futures
- camel_case_types
+ - cancel_subscriptions
+ #- constant_identifier_names
+ - control_flow_in_finally
- directives_ordering
- empty_catches
- empty_constructor_bodies
+ - empty_statements
+ - hash_and_equals
+ - implementation_imports
+ - iterable_contains_unrelated_type
- library_names
- library_prefixes
+ - list_remove_unrelated_type
- non_constant_identifier_names
- - only_throw_errors
+ - overridden_fields
+ - package_api_docs
+ - package_names
+ - package_prefixed_library_names
+ - prefer_equal_for_default_values
- prefer_final_fields
+ - prefer_generic_function_type_aliases
- prefer_is_not_empty
- #- prefer_single_quotes
- #- slash_for_doc_comments
+ - slash_for_doc_comments
+ - test_types_in_equals
+ - throw_in_finally
- type_init_formals
+ - unnecessary_brace_in_string_interps
+ - unnecessary_const
+ - unnecessary_new
+ - unrelated_type_equality_checks
+ - valid_regexps
diff --git a/lib/mime.dart b/lib/mime.dart
index 69a9cfa..90c8921 100644
--- a/lib/mime.dart
+++ b/lib/mime.dart
@@ -2,16 +2,14 @@
// 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.
-/**
- * Help for working with file format identifiers
- * such as `text/html` and `image/png`.
- *
- * More details, including a list of types, are in the Wikipedia article
- * [Internet media type](http://en.wikipedia.org/wiki/Internet_media_type).
- * For information on installing and importing this library, see the
- * [mime package on pub.dev]
- * (https://pub.dev/packages/mime).
- */
+/// Help for working with file format identifiers
+/// such as `text/html` and `image/png`.
+///
+/// More details, including a list of types, are in the Wikipedia article
+/// [Internet media type](http://en.wikipedia.org/wiki/Internet_media_type).
+/// For information on installing and importing this library, see the
+/// [mime package on pub.dev]
+/// (https://pub.dev/packages/mime).
library mime;
export 'src/mime_multipart_transformer.dart';
diff --git a/lib/src/bound_multipart_stream.dart b/lib/src/bound_multipart_stream.dart
index e843727..4b32ef9 100644
--- a/lib/src/bound_multipart_stream.dart
+++ b/lib/src/bound_multipart_stream.dart
@@ -10,7 +10,7 @@
import 'mime_shared.dart';
// Bytes for '()<>@,;:\\"/[]?={} \t'.
-const _SEPARATORS = const [
+const _SEPARATORS = [
40,
41,
60,
@@ -33,7 +33,7 @@
];
bool _isTokenChar(int byte) {
- return byte > 31 && byte < 128 && _SEPARATORS.indexOf(byte) == -1;
+ return byte > 31 && byte < 128 && !_SEPARATORS.contains(byte);
}
int _toLowerCase(int byte) {
@@ -45,13 +45,13 @@
void _expectByteValue(int val1, int val2) {
if (val1 != val2) {
- throw new MimeMultipartException("Failed to parse multipart mime 1");
+ throw MimeMultipartException("Failed to parse multipart mime 1");
}
}
void _expectWhitespace(int byte) {
if (byte != CharCode.SP && byte != CharCode.HT) {
- throw new MimeMultipartException("Failed to parse multipart mime 2");
+ throw MimeMultipartException("Failed to parse multipart mime 2");
}
}
@@ -118,7 +118,7 @@
List<int> _buffer;
BoundMultipartStream(this._boundary, Stream<List<int>> stream) {
- _controller = new StreamController(
+ _controller = StreamController(
sync: true,
onPause: _pauseStream,
onResume: _resumeStream,
@@ -137,7 +137,7 @@
}, onDone: () {
if (_state != _DONE) {
_controller
- .addError(new MimeMultipartException("Bad multipart ending"));
+ .addError(MimeMultipartException("Bad multipart ending"));
}
_controller.close();
}, onError: _controller.addError);
@@ -168,7 +168,7 @@
_subscription.cancel();
break;
default:
- throw new StateError("This code should never be reached.");
+ throw StateError("This code should never be reached.");
}
}
}
@@ -256,7 +256,7 @@
break;
case _HEADER_START:
- _headers = new Map<String, String>();
+ _headers = Map<String, String>();
if (byte == CharCode.CR) {
_state = _HEADER_ENDING;
} else {
@@ -271,7 +271,7 @@
_state = _HEADER_VALUE_START;
} else {
if (!_isTokenChar(byte)) {
- throw new MimeMultipartException("Invalid header field name");
+ throw MimeMultipartException("Invalid header field name");
}
_headerField.add(_toLowerCase(byte));
}
@@ -321,7 +321,7 @@
case _HEADER_ENDING:
_expectByteValue(byte, CharCode.LF);
- _multipartController = new StreamController(
+ _multipartController = StreamController(
sync: true,
onListen: () {
if (_subscription.isPaused) _subscription.resume();
@@ -329,7 +329,7 @@
onPause: _subscription.pause,
onResume: _subscription.resume);
_controller
- .add(new _MimeMultipart(_headers, _multipartController.stream));
+ .add(_MimeMultipart(_headers, _multipartController.stream));
_headers = null;
_state = _CONTENT;
contentStartIndex = _index + 1;
diff --git a/lib/src/magic_number.dart b/lib/src/magic_number.dart
index 7ea10fa..d490346 100644
--- a/lib/src/magic_number.dart
+++ b/lib/src/magic_number.dart
@@ -28,17 +28,16 @@
const int DEFAULT_MAGIC_NUMBERS_MAX_LENGTH = 12;
-const List<MagicNumber> DEFAULT_MAGIC_NUMBERS = const [
- const MagicNumber('application/pdf', const [0x25, 0x50, 0x44, 0x46]),
- const MagicNumber('application/postscript', const [0x25, 0x51]),
- const MagicNumber('image/gif', const [0x47, 0x49, 0x46, 0x38, 0x37, 0x61]),
- const MagicNumber('image/gif', const [0x47, 0x49, 0x46, 0x38, 0x39, 0x61]),
- const MagicNumber('image/jpeg', const [0xFF, 0xD8]),
- const MagicNumber(
- 'image/png', const [0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A]),
- const MagicNumber('image/tiff', const [0x49, 0x49, 0x2A, 0x00]),
- const MagicNumber('image/tiff', const [0x4D, 0x4D, 0x00, 0x2A]),
- const MagicNumber('video/mp4', const [
+const List<MagicNumber> DEFAULT_MAGIC_NUMBERS = [
+ MagicNumber('application/pdf', [0x25, 0x50, 0x44, 0x46]),
+ MagicNumber('application/postscript', [0x25, 0x51]),
+ MagicNumber('image/gif', [0x47, 0x49, 0x46, 0x38, 0x37, 0x61]),
+ MagicNumber('image/gif', [0x47, 0x49, 0x46, 0x38, 0x39, 0x61]),
+ MagicNumber('image/jpeg', [0xFF, 0xD8]),
+ MagicNumber('image/png', [0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A]),
+ MagicNumber('image/tiff', [0x49, 0x49, 0x2A, 0x00]),
+ MagicNumber('image/tiff', [0x4D, 0x4D, 0x00, 0x2A]),
+ MagicNumber('video/mp4', [
0x00,
0x00,
0x00,
@@ -51,7 +50,7 @@
0x67,
0x70,
0x35
- ], mask: const [
+ ], mask: [
0xFF,
0xFF,
0xFF,
@@ -65,5 +64,5 @@
0xFF,
0xFF
]),
- const MagicNumber('model/gltf-binary', const [0x46, 0x54, 0x6C, 0x67]),
+ MagicNumber('model/gltf-binary', [0x46, 0x54, 0x6C, 0x67]),
];
diff --git a/lib/src/mime_multipart_transformer.dart b/lib/src/mime_multipart_transformer.dart
index a71e6d9..5509339 100644
--- a/lib/src/mime_multipart_transformer.dart
+++ b/lib/src/mime_multipart_transformer.dart
@@ -13,7 +13,7 @@
Uint8List _getBoundary(String boundary) {
var charCodes = boundary.codeUnits;
- var boundaryList = new Uint8List(4 + charCodes.length);
+ var boundaryList = Uint8List(4 + charCodes.length);
// Set-up the matching boundary preceding it with CRLF and two
// dashes.
boundaryList[0] = CharCode.CR;
@@ -24,24 +24,20 @@
return boundaryList;
}
-/**
- * Parser for MIME multipart types of data as described in RFC 2046
- * section 5.1.1. The data is transformed into [MimeMultipart] objects, each
- * of them streaming the multipart data.
- */
+/// Parser for MIME multipart types of data as described in RFC 2046
+/// section 5.1.1. The data is transformed into [MimeMultipart] objects, each
+/// of them streaming the multipart data.
class MimeMultipartTransformer
extends StreamTransformerBase<List<int>, MimeMultipart> {
final List<int> _boundary;
- /**
- * Construct a new MIME multipart parser with the boundary
- * [boundary]. The boundary should be as specified in the content
- * type parameter, that is without the -- prefix.
- */
+ /// Construct a new MIME multipart parser with the boundary
+ /// [boundary]. The boundary should be as specified in the content
+ /// type parameter, that is without the -- prefix.
MimeMultipartTransformer(String boundary)
: _boundary = _getBoundary(boundary);
Stream<MimeMultipart> bind(Stream<List<int>> stream) {
- return new BoundMultipartStream(_boundary, stream).stream;
+ return BoundMultipartStream(_boundary, stream).stream;
}
}
diff --git a/lib/src/mime_shared.dart b/lib/src/mime_shared.dart
index 701fae5..5cc6a8f 100644
--- a/lib/src/mime_shared.dart
+++ b/lib/src/mime_shared.dart
@@ -13,10 +13,8 @@
String toString() => "MimeMultipartException: $message";
}
-/**
- * A Mime Multipart class representing each part parsed by
- * [MimeMultipartTransformer]. The data is streamed in as it become available.
- */
+/// A Mime Multipart class representing each part parsed by
+/// [MimeMultipartTransformer]. The data is streamed in as it become available.
abstract class MimeMultipart extends Stream<List<int>> {
Map<String, String> get headers;
}
diff --git a/lib/src/mime_type.dart b/lib/src/mime_type.dart
index b1fa8da..6fbe270 100644
--- a/lib/src/mime_type.dart
+++ b/lib/src/mime_type.dart
@@ -7,68 +7,54 @@
import 'default_extension_map.dart';
import 'magic_number.dart';
-final MimeTypeResolver _globalResolver = new MimeTypeResolver();
+final MimeTypeResolver _globalResolver = MimeTypeResolver();
-/**
- * The maximum number of bytes needed, to match all default magic-numbers.
- */
+/// The maximum number of bytes needed, to match all default magic-numbers.
int get defaultMagicNumbersMaxLength => _globalResolver.magicNumbersMaxLength;
-/**
- * Extract the extension from [path] and use that for MIME-type lookup, using
- * the default extension map.
- *
- * If no matching MIME-type was found, `null` is returned.
- *
- * If [headerBytes] is present, a match for known magic-numbers will be
- * performed first. This allows the correct mime-type to be found, even though
- * a file have been saved using the wrong file-name extension. If less than
- * [defaultMagicNumbersMaxLength] bytes was provided, some magic-numbers won't
- * be matched against.
- */
+/// Extract the extension from [path] and use that for MIME-type lookup, using
+/// the default extension map.
+///
+/// If no matching MIME-type was found, `null` is returned.
+///
+/// If [headerBytes] is present, a match for known magic-numbers will be
+/// performed first. This allows the correct mime-type to be found, even though
+/// a file have been saved using the wrong file-name extension. If less than
+/// [defaultMagicNumbersMaxLength] bytes was provided, some magic-numbers won't
+/// be matched against.
String lookupMimeType(String path, {List<int> headerBytes}) =>
_globalResolver.lookup(path, headerBytes: headerBytes);
-/**
- * MIME-type resolver class, used to customize the lookup of mime-types.
- */
+/// MIME-type resolver class, used to customize the lookup of mime-types.
class MimeTypeResolver {
final Map<String, String> _extensionMap = {};
final List<MagicNumber> _magicNumbers = [];
final bool _useDefault;
int _magicNumbersMaxLength;
- /**
- * Create a new empty [MimeTypeResolver].
- */
+ /// Create a new empty [MimeTypeResolver].
MimeTypeResolver.empty()
: _useDefault = false,
_magicNumbersMaxLength = 0;
- /**
- * Create a new [MimeTypeResolver] containing the default scope.
- */
+ /// Create a new [MimeTypeResolver] containing the default scope.
MimeTypeResolver()
: _useDefault = true,
_magicNumbersMaxLength = DEFAULT_MAGIC_NUMBERS_MAX_LENGTH;
- /**
- * Get the maximum number of bytes required to match all magic numbers, when
- * performing [lookup] with headerBytes present.
- */
+ /// Get the maximum number of bytes required to match all magic numbers, when
+ /// performing [lookup] with headerBytes present.
int get magicNumbersMaxLength => _magicNumbersMaxLength;
- /**
- * Extract the extension from [path] and use that for MIME-type lookup.
- *
- * If no matching MIME-type was found, `null` is returned.
- *
- * If [headerBytes] is present, a match for known magic-numbers will be
- * performed first. This allows the correct mime-type to be found, even though
- * a file have been saved using the wrong file-name extension. If less than
- * [magicNumbersMaxLength] bytes was provided, some magic-numbers won't
- * be matched against.
- */
+ /// Extract the extension from [path] and use that for MIME-type lookup.
+ ///
+ /// If no matching MIME-type was found, `null` is returned.
+ ///
+ /// If [headerBytes] is present, a match for known magic-numbers will be
+ /// performed first. This allows the correct mime-type to be found, even
+ /// though a file have been saved using the wrong file-name extension. If less
+ /// than [magicNumbersMaxLength] bytes was provided, some magic-numbers won't
+ /// be matched against.
String lookup(String path, {List<int> headerBytes}) {
String result;
if (headerBytes != null) {
@@ -89,28 +75,24 @@
return null;
}
- /**
- * Add a new MIME-type mapping to the [MimeTypeResolver]. If the [extension]
- * is already present in the [MimeTypeResolver], it'll be overwritten.
- */
+ /// Add a new MIME-type mapping to the [MimeTypeResolver]. If the [extension]
+ /// is already present in the [MimeTypeResolver], it'll be overwritten.
void addExtension(String extension, String mimeType) {
_extensionMap[extension] = mimeType;
}
- /**
- * Add a new magic-number mapping to the [MimeTypeResolver].
- *
- * If [mask] is present,the [mask] is used to only perform matching on
- * selective bits. The [mask] must have the same length as [bytes].
- */
+ /// Add a new magic-number mapping to the [MimeTypeResolver].
+ ///
+ /// If [mask] is present,the [mask] is used to only perform matching on
+ /// selective bits. The [mask] must have the same length as [bytes].
void addMagicNumber(List<int> bytes, String mimeType, {List<int> mask}) {
if (mask != null && bytes.length != mask.length) {
- throw new ArgumentError('Bytes and mask are of different lengths');
+ throw ArgumentError('Bytes and mask are of different lengths');
}
if (bytes.length > _magicNumbersMaxLength) {
_magicNumbersMaxLength = bytes.length;
}
- _magicNumbers.add(new MagicNumber(mimeType, bytes, mask: mask));
+ _magicNumbers.add(MagicNumber(mimeType, bytes, mask: mask));
}
static String _matchMagic(
diff --git a/pubspec.yaml b/pubspec.yaml
index eae8987..b1685bc 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -1,12 +1,13 @@
name: mime
-version: 0.9.6+3
+version: 0.9.7-dev
description: Helper-package for working with MIME.
author: Dart Team <misc@dartlang.org>
homepage: https://www.github.com/dart-lang/mime
environment:
- sdk: '>=2.0.0-dev.20.0 <3.0.0'
+ sdk: '>=2.0.0 <3.0.0'
dev_dependencies:
+ pedantic: ^1.0.0
test: ^1.2.0
diff --git a/test/mime_multipart_transformer_test.dart b/test/mime_multipart_transformer_test.dart
index 4a893fe..be8ca17 100644
--- a/test/mime_multipart_transformer_test.dart
+++ b/test/mime_multipart_transformer_test.dart
@@ -25,12 +25,12 @@
void _runParseTest(String message, String boundary, TestMode mode,
[List<Map> expectedHeaders, List expectedParts, bool expectError = false]) {
Future testWrite(List<int> data, [int chunkSize = -1]) {
- var controller = new StreamController<List<int>>(sync: true);
+ var controller = StreamController<List<int>>(sync: true);
var stream =
- controller.stream.transform(new MimeMultipartTransformer(boundary));
+ controller.stream.transform(MimeMultipartTransformer(boundary));
int i = 0;
- var completer = new Completer();
+ var completer = Completer();
var futures = <Future>[];
stream.listen((multipart) {
int part = i++;
@@ -48,7 +48,7 @@
break;
case TestMode.DELAY_LISTEN:
- futures.add(new Future(() {
+ futures.add(Future(() {
return multipart
.fold([], (buffer, data) => buffer..addAll(data)).then((data) {
if (expectedParts[part] != null) {
@@ -59,14 +59,14 @@
break;
case TestMode.PAUSE_RESUME:
- var completer = new Completer();
+ var completer = Completer();
futures.add(completer.future);
var buffer = [];
var subscription;
subscription = multipart.listen((data) {
buffer.addAll(data);
subscription.pause();
- new Future(() => subscription.resume());
+ Future(() => subscription.resume());
}, onDone: () {
if (expectedParts[part] != null) {
expect(buffer, equals(expectedParts[part].codeUnits));
@@ -90,11 +90,11 @@
}
Future testFirstPartOnly(List<int> data, [int chunkSize = -1]) {
- var completer = new Completer();
- var controller = new StreamController<List<int>>(sync: true);
+ var completer = Completer();
+ var controller = StreamController<List<int>>(sync: true);
var stream =
- controller.stream.transform(new MimeMultipartTransformer(boundary));
+ controller.stream.transform(MimeMultipartTransformer(boundary));
stream.first.then((multipart) {
if (expectedHeaders != null) {
@@ -116,10 +116,10 @@
Future testCompletePartAfterCancel(List<int> data, int parts,
[int chunkSize = -1]) {
- var completer = new Completer();
- var controller = new StreamController<List<int>>(sync: true);
+ var completer = Completer();
+ var controller = StreamController<List<int>>(sync: true);
var stream =
- controller.stream.transform(new MimeMultipartTransformer(boundary));
+ controller.stream.transform(MimeMultipartTransformer(boundary));
var subscription;
int i = 0;
var futures = <Future>[];
@@ -127,7 +127,7 @@
int partIndex = i;
if (partIndex >= parts) {
- throw new StateError('Expected no more parts, but got one.');
+ throw StateError('Expected no more parts, but got one.');
}
if (expectedHeaders != null) {
@@ -165,7 +165,7 @@
completes);
});
- if (expectedParts.length > 0) {
+ if (expectedParts.isNotEmpty) {
test('test-first-part-only', () {
expect(
Future.wait([
diff --git a/test/mime_type_test.dart b/test/mime_type_test.dart
index 84a7eca..9d02772 100644
--- a/test/mime_type_test.dart
+++ b/test/mime_type_test.dart
@@ -92,19 +92,19 @@
group('custom-resolver', () {
test('override-extension', () {
- var resolver = new MimeTypeResolver();
+ var resolver = MimeTypeResolver();
resolver.addExtension('jpg', 'my-mime-type');
_expectMimeType('file.jpg', 'my-mime-type', resolver: resolver);
});
test('fallthrough-extension', () {
- var resolver = new MimeTypeResolver();
+ var resolver = MimeTypeResolver();
resolver.addExtension('jpg2', 'my-mime-type');
_expectMimeType('file.jpg', 'image/jpeg', resolver: resolver);
});
test('with-mask', () {
- var resolver = new MimeTypeResolver.empty();
+ var resolver = MimeTypeResolver.empty();
resolver.addMagicNumber([0x01, 0x02, 0x03], 'my-mime-type',
mask: [0x01, 0xFF, 0xFE]);
_expectMimeType('file', 'my-mime-type',