Fix analysis errors
diff --git a/lib/src/collect.dart b/lib/src/collect.dart
index 906dfed..7c481b0 100644
--- a/lib/src/collect.dart
+++ b/lib/src/collect.dart
@@ -247,12 +247,8 @@
// If the script's library isn't loaded, load it then look up all its funcs.
final libRef = script.library;
if (functionCoverage && libRef != null && !libraries.contains(libRef)) {
- if (hits.funcHits == null) {
- hits.funcHits = <int, int>{};
- }
- if (hits.funcNames == null) {
- hits.funcNames = <int, String>{};
- }
+ hits.funcHits ??= <int, int>{};
+ hits.funcNames ??= <int, String>{};
libraries.add(libRef);
final library =
await service.getObject(isolateRef.id!, libRef.id!) as Library;
diff --git a/lib/src/formatter.dart b/lib/src/formatter.dart
index 46962a4..50e0f67 100644
--- a/lib/src/formatter.dart
+++ b/lib/src/formatter.dart
@@ -101,9 +101,9 @@
for (var key in hitmap.keys) {
final v = hitmap[key]!;
if (reportFuncs && v.funcHits == null) {
- throw "Function coverage formatting was requested, but the hit map is" +
- " missing function coverage information. Did you run" +
- " collect_coverage with the --function-coverage flag?";
+ throw 'Function coverage formatting was requested, but the hit map is '
+ 'missing function coverage information. Did you run '
+ 'collect_coverage with the --function-coverage flag?';
}
final hits = reportFuncs ? v.funcHits! : v.lineHits;
final source = resolver.resolve(key);
diff --git a/lib/src/hitmap.dart b/lib/src/hitmap.dart
index 28e6e1e..7041e36 100644
--- a/lib/src/hitmap.dart
+++ b/lib/src/hitmap.dart
@@ -15,11 +15,11 @@
/// Map from the first line of each function, to the hit count for that
/// function. Null if function coverage info was not gathered.
- Map<int, int>? funcHits = null;
+ Map<int, int>? funcHits;
/// Map from the first line of each function, to the function name. Null if
/// function coverage info was not gathered.
- Map<int, String>? funcNames = null;
+ Map<int, String>? funcNames;
}
/// Class containing information about a coverage hit.
@@ -141,15 +141,11 @@
final sourceHitMap = globalHitMap.putIfAbsent(source, () => HitMap());
fillHitMap(e['hits'] as List, sourceHitMap.lineHits);
if (e.containsKey('funcHits')) {
- if (sourceHitMap.funcHits == null) {
- sourceHitMap.funcHits = <int, int>{};
- }
+ sourceHitMap.funcHits ??= <int, int>{};
fillHitMap(e['funcHits'] as List, sourceHitMap.funcHits!);
}
if (e.containsKey('funcNames')) {
- if (sourceHitMap.funcNames == null) {
- sourceHitMap.funcNames = <int, String>{};
- }
+ sourceHitMap.funcNames ??= <int, String>{};
final funcNames = e['funcNames'] as List;
for (var i = 0; i < funcNames.length; i += 2) {
sourceHitMap.funcNames![funcNames[i] as int] =
@@ -178,15 +174,11 @@
mergeHitCounts(v.lineHits, fileResult.lineHits);
if (v.funcHits != null) {
- if (fileResult.funcHits == null) {
- fileResult.funcHits = <int, int>{};
- }
+ fileResult.funcHits ??= <int, int>{};
mergeHitCounts(v.funcHits!, fileResult.funcHits!);
}
if (v.funcNames != null) {
- if (fileResult.funcNames == null) {
- fileResult.funcNames = <int, String>{};
- }
+ fileResult.funcNames ??= <int, String>{};
v.funcNames?.forEach((int line, String name) {
fileResult.funcNames![line] = name;
});