Skip to content

Commit

Permalink
Move to latest lints (dart-archive/coverage#471)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevmoo authored Nov 9, 2023
1 parent 0d63a09 commit d574b9b
Show file tree
Hide file tree
Showing 26 changed files with 118 additions and 105 deletions.
2 changes: 2 additions & 0 deletions pkgs/coverage/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
## 1.7.2-wip

## 1.7.1

- Update `package:vm_service` constraints to '>=12.0.0 <14.0.0'.
Expand Down
2 changes: 1 addition & 1 deletion pkgs/coverage/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
include: package:lints/recommended.yaml
include: package:dart_flutter_team_lints/analysis_options.yaml

analyzer:
language:
Expand Down
4 changes: 2 additions & 2 deletions pkgs/coverage/benchmark/many_isolates.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ Future<void> main(List<String> args, dynamic message) async {
// If there is no message, it means this instance was created by
// run_benchmarks.dart. In that case, this is the parent instance that
// spawns all the others.
int sum = 0;
for (int i = 0; i < 10; ++i) {
var sum = 0;
for (var i = 0; i < 10; ++i) {
final port = ReceivePort();
final isolate =
Isolate.spawnUri(Uri.file('many_isolates.dart'), [], port.sendPort);
Expand Down
8 changes: 4 additions & 4 deletions pkgs/coverage/benchmark/run_benchmarks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ import '../bin/format_coverage.dart' as format_coverage;
class CoverageBenchmark extends AsyncBenchmarkBase {
CoverageBenchmark(
ScoreEmitter emitter,
String name,
super.name,
this.script, {
this.gatherCoverage = false,
this.functionCoverage = false,
this.branchCoverage = false,
}) : super(name, emitter: emitter);
}) : super(emitter: emitter);

final String script;
final bool gatherCoverage;
Expand Down Expand Up @@ -102,9 +102,9 @@ class JsonEmitter implements ScoreEmitter {
}

Future<void> runBenchmark(CoverageBenchmark benchmark) async {
for (int i = 0; i < 3; ++i) {
for (var i = 0; i < 3; ++i) {
try {
await benchmark.report().timeout(Duration(minutes: 2));
await benchmark.report().timeout(const Duration(minutes: 2));
return;
} on TimeoutException {
print('Timed out');
Expand Down
4 changes: 3 additions & 1 deletion pkgs/coverage/lib/src/chrome.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
// 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.

import 'package:coverage/src/hitmap.dart';
import 'package:source_maps/parser.dart';

import 'hitmap.dart';

/// Returns a Dart based hit-map containing coverage report for the provided
/// Chrome [preciseCoverage].
///
Expand Down Expand Up @@ -37,6 +38,7 @@ Future<Map<String, dynamic>> parseChromeCoverage(
mapping = parse(mapResponse) as SingleMapping;
} on FormatException {
continue;
// ignore: avoid_catching_errors
} on ArgumentError {
continue;
}
Expand Down
12 changes: 5 additions & 7 deletions pkgs/coverage/lib/src/collect.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,8 @@ Future<Map<String, dynamic>> collect(Uri serviceUri, bool resume,
controller.close();
service.dispose();
});
service = VmService(
controller.stream, (String message) => socket.add(message),
log: StdoutLog(), disposeHandler: () => socket.close());
service = VmService(controller.stream, socket.add,
log: StdoutLog(), disposeHandler: socket.close);
await service.getVM().timeout(_retryInterval);
} on TimeoutException {
// The signature changed in vm_service version 6.0.0.
Expand Down Expand Up @@ -269,11 +268,11 @@ Future _waitIsolatesPaused(VmService service, {Duration? timeout}) async {

Future allPaused() async {
final vm = await service.getVM();
if (vm.isolates!.isEmpty) throw 'No isolates.';
if (vm.isolates!.isEmpty) throw StateError('No isolates.');
for (var isolateRef in vm.isolates!) {
final isolate = await service.getIsolate(isolateRef.id!);
if (!pauseEvents.contains(isolate.pauseEvent!.kind)) {
throw 'Unpaused isolates remaining.';
throw StateError('Unpaused isolates remaining.');
}
}
}
Expand Down Expand Up @@ -330,8 +329,7 @@ Future<List<Map<String, dynamic>>> _processSourceReport(
return scripts[scriptRef];
}

HitMap getHitMap(Uri scriptUri) =>
hitMaps.putIfAbsent(scriptUri, () => HitMap());
HitMap getHitMap(Uri scriptUri) => hitMaps.putIfAbsent(scriptUri, HitMap.new);

Future<void> processFunction(FuncRef funcRef) async {
final func = await service.getObject(isolateRef.id!, funcRef.id!) as Func;
Expand Down
15 changes: 9 additions & 6 deletions pkgs/coverage/lib/src/formatter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

import 'package:path/path.dart' as p;

import 'resolver.dart';
import 'hitmap.dart';
import 'resolver.dart';

@Deprecated('Migrate to FileHitMapsFormatter')
abstract class Formatter {
Expand Down Expand Up @@ -144,14 +144,17 @@ extension FileHitMapsFormatter on Map<String, HitMap> {
for (final entry in entries) {
final v = entry.value;
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 StateError(
'Function coverage formatting was requested, but the hit map is '
'missing function coverage information. Did you run '
'collect_coverage with the --function-coverage flag?',
);
}
if (reportBranches && v.branchHits == null) {
throw 'Branch coverage formatting was requested, but the hit map is '
throw StateError(
'Branch coverage formatting was requested, but the hit map is '
'missing branch coverage information. Did you run '
'collect_coverage with the --branch-coverage flag?';
'collect_coverage with the --branch-coverage flag?');
}
final hits = reportFuncs
? v.funcHits!
Expand Down
12 changes: 6 additions & 6 deletions pkgs/coverage/lib/src/hitmap.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import 'dart:convert' show json;
import 'dart:io';

import 'package:coverage/src/resolver.dart';
import 'package:coverage/src/util.dart';
import 'resolver.dart';
import 'util.dart';

/// Contains line and function hit information for a single script.
class HitMap {
Expand Down Expand Up @@ -66,7 +66,7 @@ class HitMap {

if (checkIgnoredLines) {
if (ignoredLinesInFilesCache.containsKey(source)) {
final List<List<int>>? cacheHit = ignoredLinesInFilesCache[source];
final cacheHit = ignoredLinesInFilesCache[source];
if (cacheHit == null) {
// Null-entry indicates that the whole file was ignored.
continue;
Expand Down Expand Up @@ -157,7 +157,7 @@ class HitMap {
}
}

final sourceHitMap = globalHitMap.putIfAbsent(source, () => HitMap());
final sourceHitMap = globalHitMap.putIfAbsent(source, HitMap.new);
fillHitMap(e['hits'] as List, sourceHitMap.lineHits);
if (e.containsKey('funcHits')) {
sourceHitMap.funcHits ??= <int, int>{};
Expand Down Expand Up @@ -188,7 +188,7 @@ class HitMap {
@Deprecated('Use packagePath') String? packagesPath,
String? packagePath,
}) async {
final Resolver resolver = await Resolver.create(
final resolver = await Resolver.create(
packagesPath: packagesPath, packagePath: packagePath);
return parseJsonSync(jsonResult,
checkIgnoredLines: checkIgnoredLines,
Expand Down Expand Up @@ -375,7 +375,7 @@ List _sortHits(List hits) {
final lineOrLineRange = hits[i];
final firstLineInRange = lineOrLineRange is int
? lineOrLineRange
: int.parse(lineOrLineRange.split('-')[0] as String);
: int.parse((lineOrLineRange as String).split('-')[0]);
structuredHits.add(_HitInfo(firstLineInRange, hits[i], hits[i + 1] as int));
}
structuredHits.sort((a, b) => a.firstLine.compareTo(b.firstLine));
Expand Down
3 changes: 2 additions & 1 deletion pkgs/coverage/lib/src/resolver.dart
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,8 @@ class Loader {
/// Returns `null` if the resource could not be loaded.
List<String>? loadSync(String path) {
try {
// Ensure `readAsLinesSync` runs within the try block so errors are caught.
// Ensure `readAsLinesSync` runs within the try block so errors are
// caught.
return File(path).readAsLinesSync();
} catch (_) {
failed.add(path);
Expand Down
2 changes: 1 addition & 1 deletion pkgs/coverage/lib/src/run_and_collect.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Future<Map<String, dynamic>> runAndCollect(String scriptPath,
timeout: timeout,
);
} finally {
await process.stderr.drain();
await process.stderr.drain<void>();
}
final exitStatus = await process.exitCode;
if (exitStatus != 0) {
Expand Down
5 changes: 3 additions & 2 deletions pkgs/coverage/lib/src/util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ final singleLineIgnore = RegExp(r'//\s*coverage:ignore-line[\w\d\s]*$');
final ignoreFile = RegExp(r'//\s*coverage:ignore-file[\w\d\s]*$');

/// Return list containing inclusive range of lines to be ignored by coverage.
/// If there is a error in balancing the statements it will throw a FormatException,
/// If there is a error in balancing the statements it will throw a
/// [FormatException],
/// unless `coverage:ignore-file` is found.
/// Return [0, lines.length] if the whole file is ignored.
///
Expand Down Expand Up @@ -162,7 +163,7 @@ List<List<int>> getIgnoredLines(String filePath, List<String>? lines) {

extension StandardOutExtension on Stream<List<int>> {
Stream<String> lines() =>
transform(SystemEncoding().decoder).transform(const LineSplitter());
transform(const SystemEncoding().decoder).transform(const LineSplitter());
}

Future<Uri> serviceUriFromProcess(Stream<String> procStdout) {
Expand Down
6 changes: 3 additions & 3 deletions pkgs/coverage/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name: coverage
version: 1.7.1
version: 1.7.2-wip
description: Coverage data manipulation and formatting
repository: https://github.com/dart-lang/coverage

environment:
sdk: '^3.0.0'
sdk: ^3.0.0

dependencies:
args: ^2.0.0
Expand All @@ -18,7 +18,7 @@ dependencies:
dev_dependencies:
benchmark_harness: ^2.2.0
build_runner: ^2.1.10
lints: ^2.0.0
dart_flutter_team_lints: ^2.0.0
mockito: ^5.3.2
test: ^1.16.0
test_descriptor: ^2.0.0
Expand Down
9 changes: 6 additions & 3 deletions pkgs/coverage/test/chrome_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

// TODO(#388): Fix and re-enable this test.
@TestOn('!windows')
library;

import 'dart:convert';
import 'dart:io';
Expand Down Expand Up @@ -42,9 +43,11 @@ void main() {
sourceUriProvider,
);

final sourceReport = report['coverage'].firstWhere(
(Map<String, dynamic> report) =>
report['source'].toString().contains('main_test.dart'));
final sourceReport =
(report['coverage'] as List<Map<String, dynamic>>).firstWhere(
(Map<String, dynamic> report) =>
report['source'].toString().contains('main_test.dart'),
);

final expectedHits = {
7: 1,
Expand Down
2 changes: 1 addition & 1 deletion pkgs/coverage/test/collect_coverage_api_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ void main() {
everyElement(containsPair('branchHits', isNotEmpty)));
expect(sources[_isolateLibFileUri],
everyElement(containsPair('branchHits', isNotEmpty)));
}, skip: !platformVersionCheck(2, 17));
});

test('collect_coverage_api with coverableLineCache', () async {
final coverableLineCache = <String, Set<int>>{};
Expand Down
Loading

0 comments on commit d574b9b

Please sign in to comment.