[License] Enable empty_catches lint

This commit is contained in:
Chris Bracken
2018-12-20 11:47:52 -08:00
parent f1d81a6960
commit 4e9eed6141
3 changed files with 6 additions and 3 deletions

View File

@@ -16,6 +16,7 @@ linter:
- close_sinks
- control_flow_in_finally
- empty_statements
- empty_catches
- hash_and_equals
# - invariant_booleans # Produces false positives, see https://github.com/flutter/flutter/issues/5790
- iterable_contains_unrelated_type

View File

@@ -332,6 +332,8 @@ mixin Latin1TextFile implements TextFile {
cache(UTF8Of(this), () => utf8.decode(readBytes()));
isUTF8 = true;
} on FormatException {
// Exceptions are fine/expected for non-UTF8 text, which we test for
// immediately below.
}
if (isUTF8)
throw '$fullName contains valid UTF-8 and is probably not actually encoded as Win1252';

View File

@@ -327,19 +327,19 @@ abstract class License implements Comparable<License> {
try {
latin1Encoded = latin1.encode(body);
isUTF8 = false;
} on ArgumentError { }
} on ArgumentError { /* Fall through to next encoding check. */ }
if (!isUTF8) {
bool isAscii = false;
try {
ascii.decode(latin1Encoded);
isAscii = true;
} on FormatException { }
} on FormatException { /* Fall through to next encoding check */ }
if (isAscii)
return;
try {
utf8.decode(latin1Encoded);
isUTF8 = true;
} on FormatException { }
} on FormatException { /* We check isUTF8 below and throw if necessary */ }
if (isUTF8)
throw 'tried to create a License object with text that appears to have been misdecoded as Latin1 instead of as UTF-8:\n$body';
}