Ben Konyi 1709c884aa
[ Tool ] Enable omit_obvious_*_types and specify_nonobvious_*_types lints (#172018)
Sources under `packages/flutter_tools/` aren't accessible to the average
Flutter user by navigating through sources from their projects, so it
doesn't need to be as explicitly verbose with types for readability
purposes. The `always_specify_types` lint results in extremely verbose
code within the tool which adds little value.

This change disables `always_specify_types` in favor of a new set of
lints that aim to reduce verbosity by removing obvious types while also
maintaining readability in cases where variable types otherwise wouldn't
be obvious:

  - `omit_obvious_local_variable_types`
  - `omit_obvious_property_types`
  - `specify_nonobvious_local_variable_types`
  - `specify_nonobvious_property_types`
2025-07-11 19:32:57 +00:00

61 lines
1.9 KiB
Dart

// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:io';
/// Produces a per-library coverage summary when fed an lcov file, sorted by
/// increasing code coverage percentage.
///
/// Usage: `dart tool/unit_coverage lcov.info`
void main(List<String> args) {
if (args.isEmpty || args.length > 1) {
print('Usage: dart tool/unit_coverage lcov.info');
return;
}
final List<String> lines = File(args.single).readAsLinesSync();
final coverages = <Coverage>[];
Coverage? currentCoverage;
for (final line in lines) {
if (line.startsWith('SF:')) {
final String library = line.split('SF:')[1];
currentCoverage = Coverage()..library = library;
coverages.add(currentCoverage);
}
if (line.startsWith('DA')) {
currentCoverage?.totalLines += 1;
if (!line.endsWith(',0')) {
currentCoverage?.testedLines += 1;
}
}
if (line == 'end_of_record') {
currentCoverage = null;
}
}
coverages.sort((Coverage left, Coverage right) {
final double leftPercent = left.testedLines / left.totalLines;
final double rightPercent = right.testedLines / right.totalLines;
return leftPercent.compareTo(rightPercent);
});
double overallNumerator = 0;
double overallDenominator = 0;
print('% | tested | total');
for (final coverage in coverages) {
overallNumerator += coverage.testedLines;
overallDenominator += coverage.totalLines;
final String coveragePercent = (coverage.testedLines / coverage.totalLines * 100)
.toStringAsFixed(2);
print(
'${coverage.library}: $coveragePercent% | ${coverage.testedLines} | ${coverage.totalLines}',
);
}
print('OVERALL: ${overallNumerator / overallDenominator}');
}
class Coverage {
String? library;
var totalLines = 0;
var testedLines = 0;
}