From 4e9eed614123333f00c3e4e2c31565b4e046d9b8 Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Thu, 20 Dec 2018 11:47:52 -0800 Subject: [PATCH] [License] Enable empty_catches lint --- engine/src/flutter/tools/licenses/analysis_options.yaml | 1 + engine/src/flutter/tools/licenses/lib/filesystem.dart | 2 ++ engine/src/flutter/tools/licenses/lib/licenses.dart | 6 +++--- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/engine/src/flutter/tools/licenses/analysis_options.yaml b/engine/src/flutter/tools/licenses/analysis_options.yaml index 2368599d9a..281e646ce2 100644 --- a/engine/src/flutter/tools/licenses/analysis_options.yaml +++ b/engine/src/flutter/tools/licenses/analysis_options.yaml @@ -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 diff --git a/engine/src/flutter/tools/licenses/lib/filesystem.dart b/engine/src/flutter/tools/licenses/lib/filesystem.dart index 60f9d5df60..d11d0d0608 100644 --- a/engine/src/flutter/tools/licenses/lib/filesystem.dart +++ b/engine/src/flutter/tools/licenses/lib/filesystem.dart @@ -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'; diff --git a/engine/src/flutter/tools/licenses/lib/licenses.dart b/engine/src/flutter/tools/licenses/lib/licenses.dart index 616a498f45..05ce3a3172 100644 --- a/engine/src/flutter/tools/licenses/lib/licenses.dart +++ b/engine/src/flutter/tools/licenses/lib/licenses.dart @@ -327,19 +327,19 @@ abstract class License implements Comparable { 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'; }