Skip to content
This repository has been archived by the owner on Jul 16, 2023. It is now read-only.

feat: replace relative path in reporters output with absolute to support IDE clicks #966

Merged
merged 3 commits into from Aug 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -4,6 +4,7 @@

* chore: restrict `analyzer` version to `>=4.1.0 <4.5.0`.
* chore: restrict `analyzer_plugin` version to `>=0.11.0 <0.12.0`.
* feat: replace relative path in reporters output with absolute to support IDE clicks.

## 4.17.0

Expand Down
Expand Up @@ -36,7 +36,7 @@ class LintConsoleReporter extends ConsoleReporter<LintFileReport,
..._reportMetrics('', file.file),
..._reportIssues(
[...file.issues, ...file.antiPatternCases],
file.relativePath,
file.path,
),
..._reportEntityMetrics({...file.classes, ...file.functions}),
];
Expand All @@ -57,11 +57,11 @@ class LintConsoleReporter extends ConsoleReporter<LintFileReport,
}
}

Iterable<String> _reportIssues(Iterable<Issue> issues, String relativePath) =>
Iterable<String> _reportIssues(Iterable<Issue> issues, String absolutePath) =>
(issues.toList()
..sort((a, b) =>
a.location.start.offset.compareTo(b.location.start.offset)))
.map((issue) => _helper.getIssueMessage(issue, relativePath))
.map((issue) => _helper.getIssueMessage(issue, absolutePath))
.expand((lines) => lines);

Iterable<String> _reportEntityMetrics(Map<String, Report> reports) =>
Expand Down
Expand Up @@ -30,17 +30,17 @@ class LintConsoleReporterHelper {
};

/// Converts an [issue] to the issue message string.
Iterable<String> getIssueMessage(Issue issue, String relativePath) {
Iterable<String> getIssueMessage(Issue issue, String absolutePath) {
final severity = _getSeverity(issue.severity);
final locationStart = issue.location.start;
final location = _linkPen(
'$relativePath:${locationStart.line}:${locationStart.column}',
'$absolutePath:${locationStart.line}:${locationStart.column}',
);
final tabulation = _normalize('');

return [
'$severity${issue.message}',
'$tabulation$location',
'${tabulation}at $location',
'$tabulation${issue.ruleId} : ${issue.documentation}',
'',
];
Expand Down
Expand Up @@ -37,7 +37,7 @@ class UnnecessaryNullableConsoleReporter extends ConsoleReporter<
for (final issue in analysisRecord.issues) {
final line = issue.location.line;
final column = issue.location.column;
final path = analysisRecord.relativePath;
final path = analysisRecord.path;

final offset = ''.padRight(3);
final pathOffset = offset.padRight(5);
Expand Down
Expand Up @@ -36,7 +36,7 @@ class UnusedCodeConsoleReporter extends ConsoleReporter<UnusedCodeFileReport,
for (final issue in analysisRecord.issues) {
final line = issue.location.line;
final column = issue.location.column;
final path = analysisRecord.relativePath;
final path = analysisRecord.path;

final offset = ''.padRight(3);
final pathOffset = offset.padRight(5);
Expand Down
Expand Up @@ -30,7 +30,7 @@ class UnusedFilesConsoleReporter extends ConsoleReporter<UnusedFilesFileReport,

for (final analysisRecord in sortedRecords) {
output.writeln(
'${warningPen('⚠')} unused file: ${analysisRecord.relativePath}',
'${warningPen('⚠')} unused file: ${analysisRecord.path}',
);
}

Expand Down
Expand Up @@ -36,7 +36,7 @@ class UnusedL10nConsoleReporter extends ConsoleReporter<UnusedL10nFileReport,
for (final issue in analysisRecord.issues) {
final line = issue.location.line;
final column = issue.location.column;
final path = analysisRecord.relativePath;
final path = analysisRecord.path;

final offset = ''.padRight(3);
final pathOffset = offset.padRight(5);
Expand Down
Expand Up @@ -39,7 +39,7 @@ void main() {
),
equals([
'\x1B[38;5;180mWARNING \x1B[0mIssue message',
' \x1B[38;5;39mlib/src/my_source.dart:1:2\x1B[0m',
' at \x1B[38;5;39mlib/src/my_source.dart:1:2\x1B[0m',
' rule : https://dartcodemetrics/rules/rule',
'',
]),
Expand All @@ -59,7 +59,7 @@ void main() {
),
equals([
'\x1B[38;5;7m \x1B[0mIssue message',
' \x1B[38;5;39mlib/src/my_source.dart:1:2\x1B[0m',
' at \x1B[38;5;39mlib/src/my_source.dart:1:2\x1B[0m',
' rule : https://dartcodemetrics/rules/rule',
'',
]),
Expand Down
Expand Up @@ -81,11 +81,11 @@ void main() {
'',
'test/resources/class_with_factory_constructors.dart:',
'\x1B[38;5;180mWARNING \x1B[0msimple message',
' \x1B[38;5;39mtest/resources/class_with_factory_constructors.dart:0:0\x1B[0m',
' at \x1B[38;5;39mtest/resources/class_with_factory_constructors.dart:0:0\x1B[0m',
' id : https://documentation.com',
'',
'\x1B[38;5;20mSTYLE \x1B[0msimple design message',
' \x1B[38;5;39mtest/resources/class_with_factory_constructors.dart:0:0\x1B[0m',
' at \x1B[38;5;39mtest/resources/class_with_factory_constructors.dart:0:0\x1B[0m',
' designId : https://documentation.com',
'',
'\x1B[38;5;180mWARNING \x1B[0mfunction',
Expand Down Expand Up @@ -118,11 +118,11 @@ void main() {
' metric2: \x1B[38;5;7m1\x1B[0m',
'',
'\x1B[38;5;180mWARNING \x1B[0msimple message',
' \x1B[38;5;39mtest/resources/class_with_factory_constructors.dart:0:0\x1B[0m',
' at \x1B[38;5;39mtest/resources/class_with_factory_constructors.dart:0:0\x1B[0m',
' id : https://documentation.com',
'',
'\x1B[38;5;20mSTYLE \x1B[0msimple design message',
' \x1B[38;5;39mtest/resources/class_with_factory_constructors.dart:0:0\x1B[0m',
' at \x1B[38;5;39mtest/resources/class_with_factory_constructors.dart:0:0\x1B[0m',
' designId : https://documentation.com',
'',
'\x1B[38;5;180mWARNING \x1B[0mfunction',
Expand Down
Expand Up @@ -72,7 +72,7 @@ void main() {
equals([
'example.dart:',
' \x1B[38;5;180m⚠\x1B[0m unused class SomeClass',
' at example.dart:5:3',
' at $fullPath:5:3',
'',
'\x1B[38;5;167m✖\x1B[0m total unused code (classes, functions, variables, extensions, enums, mixins and type aliases) - \x1B[38;5;167m1\x1B[0m',
]),
Expand Down
Expand Up @@ -67,7 +67,7 @@ void main() {
expect(
captured,
equals([
'\x1B[38;5;180m⚠\x1B[0m unused file: example.dart',
'\x1B[38;5;180m⚠\x1B[0m unused file: $fullPath',
'',
'\x1B[38;5;167m✖\x1B[0m total unused files - \x1B[38;5;167m1\x1B[0m',
]),
Expand All @@ -92,7 +92,7 @@ void main() {
expect(
captured,
equals([
'\x1B[38;5;180m⚠\x1B[0m unused file: example.dart',
'\x1B[38;5;180m⚠\x1B[0m unused file: $fullPath',
'',
'\x1B[38;5;20m✔\x1B[0m \x1B[38;5;167m1\x1B[0m files were successfully deleted',
]),
Expand Down
Expand Up @@ -75,7 +75,7 @@ void main() {
equals([
'class SomeClass',
' \x1B[38;5;180m⚠\x1B[0m unused someMethod()',
' at example.dart:5:3',
' at $fullPath:5:3',
'',
'\x1B[38;5;167m✖\x1B[0m total unused localization class fields, getters and methods - \x1B[38;5;167m1\x1B[0m',
]),
Expand Down