Enable and fix some more lints
diff --git a/analysis_options.yaml b/analysis_options.yaml index c2977b5..69009d3 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml
@@ -7,8 +7,11 @@ linter: rules: - avoid_bool_literals_in_conditional_expressions + - avoid_catching_errors - avoid_classes_with_only_static_members - avoid_function_literals_in_foreach_calls + - avoid_private_typedef_functions + - avoid_redundant_argument_values - avoid_renaming_method_parameters - avoid_returning_null - avoid_returning_null_for_future @@ -16,6 +19,7 @@ - avoid_returning_this - avoid_single_cascade_in_expression_statements - avoid_unused_constructor_parameters + - avoid_void_async - await_only_futures - camel_case_types - cancel_subscriptions @@ -30,21 +34,34 @@ - invariant_booleans - iterable_contains_unrelated_type - join_return_with_assignment + - lines_longer_than_80_chars - list_remove_unrelated_type - literal_only_boolean_expressions + - missing_whitespace_between_adjacent_strings - no_adjacent_strings_in_list + - 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_await_in_return @@ -52,6 +69,9 @@ - unnecessary_getters_setters - unnecessary_lambdas - unnecessary_null_aware_assignments + - unnecessary_overrides - unnecessary_parenthesis - unnecessary_statements + - unnecessary_string_interpolations + - use_string_buffers - void_checks
diff --git a/lib/src/authentication_challenge.dart b/lib/src/authentication_challenge.dart index e4b6619..9b554e8 100644 --- a/lib/src/authentication_challenge.dart +++ b/lib/src/authentication_challenge.dart
@@ -33,79 +33,77 @@ /// challenges. /// /// Throws a [FormatException] if the header is invalid. - static List<AuthenticationChallenge> parseHeader(String header) { - return wrapFormatException('authentication header', header, () { - final scanner = StringScanner(header); - scanner.scan(whitespace); - final challenges = parseList(scanner, () { - final scheme = _scanScheme(scanner, whitespaceName: '" " or "="'); + static List<AuthenticationChallenge> parseHeader(String header) => + wrapFormatException('authentication header', header, () { + final scanner = StringScanner(header); + scanner.scan(whitespace); + final challenges = parseList(scanner, () { + final scheme = _scanScheme(scanner, whitespaceName: '" " or "="'); - // Manually parse the inner list. We need to do some lookahead to - // disambiguate between an auth param and another challenge. - final params = <String, String>{}; + // Manually parse the inner list. We need to do some lookahead to + // disambiguate between an auth param and another challenge. + final params = <String, String>{}; - // Consume initial empty values. - while (scanner.scan(',')) { - scanner.scan(whitespace); - } - - _scanAuthParam(scanner, params); - - var beforeComma = scanner.position; - while (scanner.scan(',')) { - scanner.scan(whitespace); - - // Empty elements are allowed, but excluded from the results. - if (scanner.matches(',') || scanner.isDone) continue; - - scanner.expect(token, name: 'a token'); - final name = scanner.lastMatch[0]; - scanner.scan(whitespace); - - // If there's no "=", then this is another challenge rather than a - // parameter for the current challenge. - if (!scanner.scan('=')) { - scanner.position = beforeComma; - break; + // Consume initial empty values. + while (scanner.scan(',')) { + scanner.scan(whitespace); } - scanner.scan(whitespace); + _scanAuthParam(scanner, params); - if (scanner.scan(token)) { - params[name] = scanner.lastMatch[0]; - } else { - params[name] = - expectQuotedString(scanner, name: 'a token or a quoted string'); + var beforeComma = scanner.position; + while (scanner.scan(',')) { + scanner.scan(whitespace); + + // Empty elements are allowed, but excluded from the results. + if (scanner.matches(',') || scanner.isDone) continue; + + scanner.expect(token, name: 'a token'); + final name = scanner.lastMatch[0]; + scanner.scan(whitespace); + + // If there's no "=", then this is another challenge rather than a + // parameter for the current challenge. + if (!scanner.scan('=')) { + scanner.position = beforeComma; + break; + } + + scanner.scan(whitespace); + + if (scanner.scan(token)) { + params[name] = scanner.lastMatch[0]; + } else { + params[name] = expectQuotedString(scanner, + name: 'a token or a quoted string'); + } + + scanner.scan(whitespace); + beforeComma = scanner.position; } - scanner.scan(whitespace); - beforeComma = scanner.position; - } + return AuthenticationChallenge(scheme, params); + }); - return AuthenticationChallenge(scheme, params); + scanner.expectDone(); + return challenges; }); - scanner.expectDone(); - return challenges; - }); - } - /// Parses a single WWW-Authenticate challenge value. /// /// Throws a [FormatException] if the challenge is invalid. - factory AuthenticationChallenge.parse(String challenge) { - return wrapFormatException('authentication challenge', challenge, () { - final scanner = StringScanner(challenge); - scanner.scan(whitespace); - final scheme = _scanScheme(scanner); + factory AuthenticationChallenge.parse(String challenge) => + wrapFormatException('authentication challenge', challenge, () { + final scanner = StringScanner(challenge); + scanner.scan(whitespace); + final scheme = _scanScheme(scanner); - final params = <String, String>{}; - parseList(scanner, () => _scanAuthParam(scanner, params)); + final params = <String, String>{}; + parseList(scanner, () => _scanAuthParam(scanner, params)); - scanner.expectDone(); - return AuthenticationChallenge(scheme, params); - }); - } + scanner.expectDone(); + return AuthenticationChallenge(scheme, params); + }); /// Scans a single scheme name and asserts that it's followed by a space. ///
diff --git a/lib/src/chunked_coding/decoder.dart b/lib/src/chunked_coding/decoder.dart index cd06f39..dcc0188 100644 --- a/lib/src/chunked_coding/decoder.dart +++ b/lib/src/chunked_coding/decoder.dart
@@ -163,8 +163,8 @@ } else { // If the byte is an uppercase letter, convert it to lowercase. This works // because uppercase letters in ASCII are exactly `0b100000 = 0x20` less - // than lowercase letters, so if we ensure that that bit is 1 we ensure that - // the letter is lowercase. + // than lowercase letters, so if we ensure that that bit is 1 we ensure + // that the letter is lowercase. final letter = 0x20 | byte; if ($a <= letter && letter <= $f) return letter - $a + 10; }
diff --git a/lib/src/http_date.dart b/lib/src/http_date.dart index 88ada63..71f6bab 100644 --- a/lib/src/http_date.dart +++ b/lib/src/http_date.dart
@@ -57,58 +57,57 @@ /// /// This follows [RFC 2616](http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.3). /// It will throw a [FormatException] if [date] is invalid. -DateTime parseHttpDate(String date) { - return wrapFormatException('HTTP date', date, () { - final scanner = StringScanner(date); +DateTime parseHttpDate(String date) => + wrapFormatException('HTTP date', date, () { + final scanner = StringScanner(date); - if (scanner.scan(_longWeekdayRegExp)) { - // RFC 850 starts with a long weekday. - scanner.expect(', '); - final day = _parseInt(scanner, 2); - scanner.expect('-'); + if (scanner.scan(_longWeekdayRegExp)) { + // RFC 850 starts with a long weekday. + scanner.expect(', '); + final day = _parseInt(scanner, 2); + scanner.expect('-'); + final month = _parseMonth(scanner); + scanner.expect('-'); + final year = 1900 + _parseInt(scanner, 2); + scanner.expect(' '); + final time = _parseTime(scanner); + scanner.expect(' GMT'); + scanner.expectDone(); + + return _makeDateTime(year, month, day, time); + } + + // RFC 1123 and asctime both start with a short weekday. + scanner.expect(_shortWeekdayRegExp); + if (scanner.scan(', ')) { + // RFC 1123 follows the weekday with a comma. + final day = _parseInt(scanner, 2); + scanner.expect(' '); + final month = _parseMonth(scanner); + scanner.expect(' '); + final year = _parseInt(scanner, 4); + scanner.expect(' '); + final time = _parseTime(scanner); + scanner.expect(' GMT'); + scanner.expectDone(); + + return _makeDateTime(year, month, day, time); + } + + // asctime follows the weekday with a space. + scanner.expect(' '); final month = _parseMonth(scanner); - scanner.expect('-'); - final year = 1900 + _parseInt(scanner, 2); + scanner.expect(' '); + final day = + scanner.scan(' ') ? _parseInt(scanner, 1) : _parseInt(scanner, 2); scanner.expect(' '); final time = _parseTime(scanner); - scanner.expect(' GMT'); - scanner.expectDone(); - - return _makeDateTime(year, month, day, time); - } - - // RFC 1123 and asctime both start with a short weekday. - scanner.expect(_shortWeekdayRegExp); - if (scanner.scan(', ')) { - // RFC 1123 follows the weekday with a comma. - final day = _parseInt(scanner, 2); - scanner.expect(' '); - final month = _parseMonth(scanner); scanner.expect(' '); final year = _parseInt(scanner, 4); - scanner.expect(' '); - final time = _parseTime(scanner); - scanner.expect(' GMT'); scanner.expectDone(); return _makeDateTime(year, month, day, time); - } - - // asctime follows the weekday with a space. - scanner.expect(' '); - final month = _parseMonth(scanner); - scanner.expect(' '); - final day = - scanner.scan(' ') ? _parseInt(scanner, 1) : _parseInt(scanner, 2); - scanner.expect(' '); - final time = _parseTime(scanner); - scanner.expect(' '); - final year = _parseInt(scanner, 4); - scanner.expectDone(); - - return _makeDateTime(year, month, day, time); - }); -} + }); /// Parses a short-form month name to a form accepted by [DateTime]. int _parseMonth(StringScanner scanner) {
diff --git a/lib/src/media_type.dart b/lib/src/media_type.dart index 8d0b082..71b16b2 100644 --- a/lib/src/media_type.dart +++ b/lib/src/media_type.dart
@@ -40,41 +40,40 @@ /// Parses a media type. /// /// This will throw a FormatError if the media type is invalid. - factory MediaType.parse(String mediaType) { - // This parsing is based on sections 3.6 and 3.7 of the HTTP spec: - // http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html. - return wrapFormatException('media type', mediaType, () { - final scanner = StringScanner(mediaType); - scanner.scan(whitespace); - scanner.expect(token); - final type = scanner.lastMatch[0]; - scanner.expect('/'); - scanner.expect(token); - final subtype = scanner.lastMatch[0]; - scanner.scan(whitespace); - - final parameters = <String, String>{}; - while (scanner.scan(';')) { + factory MediaType.parse(String mediaType) => + // This parsing is based on sections 3.6 and 3.7 of the HTTP spec: + // http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html. + wrapFormatException('media type', mediaType, () { + final scanner = StringScanner(mediaType); scanner.scan(whitespace); scanner.expect(token); - final attribute = scanner.lastMatch[0]; - scanner.expect('='); + final type = scanner.lastMatch[0]; + scanner.expect('/'); + scanner.expect(token); + final subtype = scanner.lastMatch[0]; + scanner.scan(whitespace); - String value; - if (scanner.scan(token)) { - value = scanner.lastMatch[0]; - } else { - value = expectQuotedString(scanner); + final parameters = <String, String>{}; + while (scanner.scan(';')) { + scanner.scan(whitespace); + scanner.expect(token); + final attribute = scanner.lastMatch[0]; + scanner.expect('='); + + String value; + if (scanner.scan(token)) { + value = scanner.lastMatch[0]; + } else { + value = expectQuotedString(scanner); + } + + scanner.scan(whitespace); + parameters[attribute] = value; } - scanner.scan(whitespace); - parameters[attribute] = value; - } - - scanner.expectDone(); - return MediaType(type, subtype, parameters); - }); - } + scanner.expectDone(); + return MediaType(type, subtype, parameters); + }); MediaType(String type, String subtype, [Map<String, String> parameters]) : type = type.toLowerCase(),