From 6bc5fa59e15382985409061fa00ba854d5c95f80 Mon Sep 17 00:00:00 2001 From: Dmitry Zhifarsky Date: Sun, 14 Aug 2022 12:09:32 +0400 Subject: [PATCH 1/3] feat: replace relative path in reporters output with absolute to support IDE clicks --- CHANGELOG.md | 1 + .../reporters_list/console/lint_console_reporter.dart | 6 +++--- .../console/lint_console_reporter_helper.dart | 6 +++--- .../console/unnecessary_nullable_console_reporter.dart | 2 +- .../console/unused_code_console_reporter.dart | 2 +- .../console/unused_files_console_reporter.dart | 2 +- .../console/unused_l10n_console_reporter.dart | 2 +- 7 files changed, 11 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e076850a5e..87a33ba1c6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/lib/src/analyzers/lint_analyzer/reporters/reporters_list/console/lint_console_reporter.dart b/lib/src/analyzers/lint_analyzer/reporters/reporters_list/console/lint_console_reporter.dart index 7be78b626a..0a6c273cdc 100644 --- a/lib/src/analyzers/lint_analyzer/reporters/reporters_list/console/lint_console_reporter.dart +++ b/lib/src/analyzers/lint_analyzer/reporters/reporters_list/console/lint_console_reporter.dart @@ -36,7 +36,7 @@ class LintConsoleReporter extends ConsoleReporter _reportIssues(Iterable issues, String relativePath) => + Iterable _reportIssues(Iterable 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 _reportEntityMetrics(Map reports) => diff --git a/lib/src/analyzers/lint_analyzer/reporters/reporters_list/console/lint_console_reporter_helper.dart b/lib/src/analyzers/lint_analyzer/reporters/reporters_list/console/lint_console_reporter_helper.dart index 2f5971f2b1..c4662b0623 100644 --- a/lib/src/analyzers/lint_analyzer/reporters/reporters_list/console/lint_console_reporter_helper.dart +++ b/lib/src/analyzers/lint_analyzer/reporters/reporters_list/console/lint_console_reporter_helper.dart @@ -30,17 +30,17 @@ class LintConsoleReporterHelper { }; /// Converts an [issue] to the issue message string. - Iterable getIssueMessage(Issue issue, String relativePath) { + Iterable 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}', '', ]; diff --git a/lib/src/analyzers/unnecessary_nullable_analyzer/reporters/reporters_list/console/unnecessary_nullable_console_reporter.dart b/lib/src/analyzers/unnecessary_nullable_analyzer/reporters/reporters_list/console/unnecessary_nullable_console_reporter.dart index a9b2db7ef4..84e3a77538 100644 --- a/lib/src/analyzers/unnecessary_nullable_analyzer/reporters/reporters_list/console/unnecessary_nullable_console_reporter.dart +++ b/lib/src/analyzers/unnecessary_nullable_analyzer/reporters/reporters_list/console/unnecessary_nullable_console_reporter.dart @@ -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); diff --git a/lib/src/analyzers/unused_code_analyzer/reporters/reporters_list/console/unused_code_console_reporter.dart b/lib/src/analyzers/unused_code_analyzer/reporters/reporters_list/console/unused_code_console_reporter.dart index 8c2ac5d8b1..544a035bed 100644 --- a/lib/src/analyzers/unused_code_analyzer/reporters/reporters_list/console/unused_code_console_reporter.dart +++ b/lib/src/analyzers/unused_code_analyzer/reporters/reporters_list/console/unused_code_console_reporter.dart @@ -36,7 +36,7 @@ class UnusedCodeConsoleReporter extends ConsoleReporter Date: Tue, 30 Aug 2022 14:28:10 +0400 Subject: [PATCH 2/3] test: update test --- .../console/lint_console_reporter_test.dart | 8 ++++---- .../console/unused_code_console_reporter_test.dart | 2 +- .../console/unused_files_console_reporter_test.dart | 4 ++-- .../console/unused_l10n_console_reporter_test.dart | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/test/src/analyzers/lint_analyzer/reporters/reporters_list/console/lint_console_reporter_test.dart b/test/src/analyzers/lint_analyzer/reporters/reporters_list/console/lint_console_reporter_test.dart index 9d0907cf85..4542cd685b 100644 --- a/test/src/analyzers/lint_analyzer/reporters/reporters_list/console/lint_console_reporter_test.dart +++ b/test/src/analyzers/lint_analyzer/reporters/reporters_list/console/lint_console_reporter_test.dart @@ -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', @@ -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', diff --git a/test/src/analyzers/unused_code_analyzer/reporters/reporters_list/console/unused_code_console_reporter_test.dart b/test/src/analyzers/unused_code_analyzer/reporters/reporters_list/console/unused_code_console_reporter_test.dart index 75bf877023..0f5c03e3aa 100644 --- a/test/src/analyzers/unused_code_analyzer/reporters/reporters_list/console/unused_code_console_reporter_test.dart +++ b/test/src/analyzers/unused_code_analyzer/reporters/reporters_list/console/unused_code_console_reporter_test.dart @@ -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', ]), diff --git a/test/src/analyzers/unused_files_analyzer/reporters/reporters_list/console/unused_files_console_reporter_test.dart b/test/src/analyzers/unused_files_analyzer/reporters/reporters_list/console/unused_files_console_reporter_test.dart index f886daa080..8b261b53d0 100644 --- a/test/src/analyzers/unused_files_analyzer/reporters/reporters_list/console/unused_files_console_reporter_test.dart +++ b/test/src/analyzers/unused_files_analyzer/reporters/reporters_list/console/unused_files_console_reporter_test.dart @@ -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', ]), @@ -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', ]), diff --git a/test/src/analyzers/unused_l10n_analyzer/reporters/reporters_list/console/unused_l10n_console_reporter_test.dart b/test/src/analyzers/unused_l10n_analyzer/reporters/reporters_list/console/unused_l10n_console_reporter_test.dart index ff36330a94..3a7cd3f898 100644 --- a/test/src/analyzers/unused_l10n_analyzer/reporters/reporters_list/console/unused_l10n_console_reporter_test.dart +++ b/test/src/analyzers/unused_l10n_analyzer/reporters/reporters_list/console/unused_l10n_console_reporter_test.dart @@ -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', ]), From 48734cd6bfb7fc2108fa76fd2ff16be6547fabfd Mon Sep 17 00:00:00 2001 From: Dmitry Zhifarsky Date: Tue, 30 Aug 2022 15:21:50 +0400 Subject: [PATCH 3/3] test: update test --- .../console/lint_console_reporter_helper_test.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/src/analyzers/lint_analyzer/reporters/reporters_list/console/lint_console_reporter_helper_test.dart b/test/src/analyzers/lint_analyzer/reporters/reporters_list/console/lint_console_reporter_helper_test.dart index db2d8cd30f..0cceb02c0f 100644 --- a/test/src/analyzers/lint_analyzer/reporters/reporters_list/console/lint_console_reporter_helper_test.dart +++ b/test/src/analyzers/lint_analyzer/reporters/reporters_list/console/lint_console_reporter_helper_test.dart @@ -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', '', ]), @@ -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', '', ]),