Revert "[doc_checker] Improve output on error"
This reverts commit f11d94135061b16643d6766a8c7c2e2e8ff32db4.
Reason for revert: When presubmit checked fxr/333071 patchset 12, docchecker threw an exception:
Unhandled exception:
NoSuchMethodError: The getter 'length' was called on null.
Receiver: null
Tried calling: length
#0 Object.noSuchMethod (dart:core-patch/object_patch.dart:53:5)
#1 _StringBase.compareTo (dart:core-patch/string_patch.dart:287:29)
#2 Error.compareTo (package:doc_checker/errors.dart:36:23)
#3 Comparable.compare (dart:core/comparable.dart:95:55)
#4 ListMixin._compareAny (dart:collection/list.dart:347:23)
#5 Sort._insertionSort (dart:_internal/sort.dart:71:36)
#6 Sort._doSort (dart:_internal/sort.dart:60:7)
#7 Sort.sort (dart:_internal/sort.dart:35:5)
#8 ListMixin.sort (dart:collection/list.dart:341:10)
#9 main (file:///b/s/w/ir/k/topaz/tools/doc_checker/bin/main.dart:256:7)
<asynchronous suspension>
#10 _startIsolate.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:299:32)
#11 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.
Original change's description:
> [doc_checker] Improve output on error
>
> To ease reading errors we
>
> * Order errors by location, grouping errors coming from the same file;
> * Print `location: error kind: error content`, which follows the typical
> fomat used by tools such as linters or compilers.
>
> New output
>
> //docs/development/internationalization/localizing_mods.md: Http link is broken: https://fuchsia.googlesource.com/experiences/+/refs/heads/master/examples/localized_flutter_app
> //docs/development/languages/dart/mod_integration_testing.md: Http link is broken: https://fuchsia.googlesource.com/topaz/+/HEAD/examples/test/driver_example_mod
> //docs/development/languages/dart/mod_integration_testing.md: Http link is broken: https://fuchsia.googlesource.com/topaz/+/HEAD/examples/test/driver_example_mod/BUILD.gn
> //docs/development/languages/dart/mod_integration_testing.md: Http link is broken: https://fuchsia.googlesource.com/topaz/+/HEAD/examples/test/driver_example_mod/lib/main.dart
> //docs/development/languages/dart/mod_integration_testing.md: Http link is broken: https://fuchsia.googlesource.com/topaz/+/HEAD/examples/test/driver_example_mod/test/driver_example_mod_test.dart
> //docs/development/languages/dart/mod_integration_testing.md: Http link is broken: https://fuchsia.googlesource.com/topaz/+/master/examples/test/driver_example_mod/test/driver_example_mod_test.dart
> //docs/development/languages/dart/mod_integration_testing.md: Http link is broken: https://fuchsia.googlesource.com/topaz/+/master/examples/test/driver_example_mod/meta/driver_example_mod_tests.cmx
> //docs/development/languages/fidl/CONTRIBUTING.md: Http link is broken: https://chromium.googlesource.com/chromium/src/+/master/build/fuchsia/fidlgen_js/
> //docs/development/languages/fidl/CONTRIBUTING.md: Http link is broken: https://chromium.googlesource.com/chromium/src/+/master/build/fuchsia/fidlgen_js/runtime/
> //docs/gen/build_arguments.md: Http link is broken: https://llvm.org/docs/UndefinedBehaviorSanitizer.html
> Found 10 error(s).
>
> Old output
>
> Http link is broken : https://chromium.googlesource.com/chromium/src/+/master/build/fuchsia/fidlgen_js/ (//docs/development/languages/fidl/CONTRIBUTING.md)
> Http link is broken : https://chromium.googlesource.com/chromium/src/+/master/build/fuchsia/fidlgen_js/runtime/ (//docs/development/languages/fidl/CONTRIBUTING.md)
> Http link is broken : https://fuchsia.googlesource.com/topaz/+/HEAD/examples/test/driver_example_mod (//docs/development/languages/dart/mod_integration_testing.md)
> Http link is broken : https://fuchsia.googlesource.com/topaz/+/HEAD/examples/test/driver_example_mod/BUILD.gn (//docs/development/languages/dart/mod_integration_testing.md)
> Http link is broken : https://fuchsia.googlesource.com/topaz/+/HEAD/examples/test/driver_example_mod/lib/main.dart (//docs/development/languages/dart/mod_integration_testing.md)
> Http link is broken : https://fuchsia.googlesource.com/topaz/+/HEAD/examples/test/driver_example_mod/test/driver_example_mod_test.dart (//docs/development/languages/dart/mod_integration_testing.md)
> Http link is broken : https://fuchsia.googlesource.com/topaz/+/master/examples/test/driver_example_mod/test/driver_example_mod_test.dart (//docs/development/languages/dart/mod_integration_testing.md)
> Http link is broken : https://fuchsia.googlesource.com/topaz/+/master/examples/test/driver_example_mod/meta/driver_example_mod_tests.cmx (//docs/development/languages/dart/mod_integration_testing.md)
> Http link is broken : https://llvm.org/docs/UndefinedBehaviorSanitizer.html (//docs/gen/build_arguments.md)
> Http link is broken : https://fuchsia.googlesource.com/experiences/+/refs/heads/master/examples/localized_flutter_app (//docs/development/internationalization/localizing_mods.md)
> Found 10 error(s).
>
> Change-Id: Ifbdbdf4e9592e2bdc909bbe1f2274b3e56198415
TBR=pascallouis@google.com,ccherubino@google.com,wilkinsonclay@google.com
# Not skipping CQ checks because original CL landed > 1 day ago.
Change-Id: I7422332d071d565ac7d4aa95e3e9d9946aef5d8a
diff --git a/tools/doc_checker/bin/main.dart b/tools/doc_checker/bin/main.dart
index e8fd730..dbfe933 100644
--- a/tools/doc_checker/bin/main.dart
+++ b/tools/doc_checker/bin/main.dart
@@ -64,8 +64,8 @@
}
}
- final String location = error.hasLocation ? error.location : 'unknown location';
- print('$location: ${errorToString(error.type)}: ${error.content}');
+ final String location = error.hasLocation ? ' (${error.location})' : '';
+ print('${errorToString(error.type).padRight(25)}: ${error.content}$location');
}
// Checks whether the URI points to the master branch of a Gerrit (i.e.,
@@ -253,7 +253,7 @@
}
errors
- ..sort()
+ ..sort((Error a, Error b) => a.type.index - b.type.index)
..forEach(reportError);
if (options[_optionDotFile].isNotEmpty) {
diff --git a/tools/doc_checker/lib/errors.dart b/tools/doc_checker/lib/errors.dart
index 10825f7..555bfdf 100644
--- a/tools/doc_checker/lib/errors.dart
+++ b/tools/doc_checker/lib/errors.dart
@@ -12,7 +12,7 @@
invalidUri,
}
-class Error implements Comparable<Error> {
+class Error {
final ErrorType type;
final String location;
final String content;
@@ -22,18 +22,4 @@
Error.forProject(this.type, this.content) : location = null;
bool get hasLocation => location != null;
-
- @override
- int compareTo(Error other) {
- if (location == other.location) {
- // same location (possibly null), break tie by type
- return type.index - other.type.index;
- } else if (location == null) {
- // no location, other is prioritized
- return 1;
- } else {
- // break tie by location
- return location.compareTo(other.location);
- }
- }
}