This repository has been archived by the owner on Jul 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 258
/
unnecessary_nullable_console_reporter.dart
62 lines (49 loc) · 1.94 KB
/
unnecessary_nullable_console_reporter.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import 'dart:io';
import '../../../../../reporters/models/console_reporter.dart';
import '../../../models/unnecessary_nullable_file_report.dart';
import '../../unnecessary_nullable_report_params.dart';
/// Unnecessary nullable console reporter.
///
/// Use it to create reports in console format.
class UnnecessaryNullableConsoleReporter extends ConsoleReporter<
UnnecessaryNullableFileReport, void, UnnecessaryNullableReportParams> {
UnnecessaryNullableConsoleReporter(IOSink output) : super(output);
@override
Future<void> report(
Iterable<UnnecessaryNullableFileReport> records, {
Iterable<void> summary = const [],
UnnecessaryNullableReportParams? additionalParams,
}) async {
if (records.isEmpty) {
if (additionalParams?.congratulate ?? true) {
output
.writeln('${okPen('✔')} no unnecessary nullable parameters found!');
}
return;
}
final sortedRecords = records.toList()
..sort((a, b) => a.relativePath.compareTo(b.relativePath));
var warnings = 0;
for (final analysisRecord in sortedRecords) {
output.writeln('${analysisRecord.relativePath}:');
for (final issue in analysisRecord.issues) {
final line = issue.location.line;
final column = issue.location.column;
final path = analysisRecord.path;
final offset = ''.padRight(3);
final pathOffset = offset.padRight(5);
output
..writeln(
'$offset ${warningPen('⚠')} ${issue.declarationType} ${issue.declarationName} has unnecessary nullable parameters',
)
..writeln('$pathOffset ${issue.parameters}')
..writeln('$pathOffset at $path:$line:$column');
}
warnings += analysisRecord.issues.length;
output.writeln('');
}
output.writeln(
'${alarmPen('✖')} total declarations (functions, methods and constructors) with unnecessary nullable parameters - ${alarmPen(warnings)}',
);
}
}