Skip to content

Commit 07a9ac7

Browse files
stereotype441Commit Queue
authored andcommitted
[analyzer] trim trailing whitespace from diagnostic messages.
This is something the CFE already does as part of its diagnostic message code generation; the analyzer should do it too. Making this change to the analyzer now paves the way for unifying the analyzer and CFE code for reading and interpreting `messages.yaml` files. Change-Id: I6a6a6964b04ef0a67f8077becb3726bafc40a5cb Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/448228 Reviewed-by: Konstantin Shcheglov <[email protected]> Commit-Queue: Paul Berry <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]>
1 parent cd36725 commit 07a9ac7

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

pkg/analyzer/lib/src/manifest/manifest_warning_code.g.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class ManifestWarningCode extends DiagnosticCodeWithExpectedTypes {
5757
noTouchscreenFeature = ManifestWarningWithoutArguments(
5858
'NO_TOUCHSCREEN_FEATURE',
5959
"The default \"android.hardware.touchscreen\" needs to be optional for "
60-
"Chrome OS. ",
60+
"Chrome OS.",
6161
correctionMessage:
6262
"Consider adding <uses-feature "
6363
"android:name=\"android.hardware.touchscreen\" android:required=\"false\" "
@@ -76,7 +76,7 @@ class ManifestWarningCode extends DiagnosticCodeWithExpectedTypes {
7676
permissionImpliesUnsupportedHardware = ManifestWarningTemplate(
7777
'PERMISSION_IMPLIES_UNSUPPORTED_HARDWARE',
7878
"Permission makes app incompatible for Chrome OS, consider adding optional "
79-
"{0} feature tag, ",
79+
"{0} feature tag,",
8080
correctionMessage:
8181
" Try adding `<uses-feature android:name=\"{0}\" "
8282
"android:required=\"false\">`.",

pkg/analyzer/tool/messages/error_code_info.dart

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -656,13 +656,13 @@ abstract class ErrorCodeInfo {
656656
ErrorCodeInfo.fromYaml(Map<Object?, Object?> yaml)
657657
: this(
658658
comment: yaml['comment'] as String?,
659-
correctionMessage: yaml['correctionMessage'] as String?,
659+
correctionMessage: _decodeMessage(yaml['correctionMessage']),
660660
deprecatedMessage: yaml['deprecatedMessage'] as String?,
661661
documentation: yaml['documentation'] as String?,
662662
hasPublishedDocs: yaml['hasPublishedDocs'] as bool?,
663663
isUnresolvedIdentifier:
664664
yaml['isUnresolvedIdentifier'] as bool? ?? false,
665-
problemMessage: yaml['problemMessage'] as String? ?? '',
665+
problemMessage: _decodeMessage(yaml['problemMessage']) ?? '',
666666
sharedName: yaml['sharedName'] as String?,
667667
removedIn: yaml['removedIn'] as String?,
668668
previousName: yaml['previousName'] as String?,
@@ -887,6 +887,20 @@ static LocatableDiagnostic $withArgumentsName({$withArgumentsParams}) {
887887
}
888888
}
889889

890+
static String? _decodeMessage(Object? rawMessage) {
891+
switch (rawMessage) {
892+
case null:
893+
return null;
894+
case String():
895+
// Remove trailing whitespace. This is necessary for templates defined
896+
// with `|` (verbatim) as they always contain a trailing newline that we
897+
// don't want.
898+
return rawMessage.trimRight();
899+
default:
900+
throw 'Bad message type: ${rawMessage.runtimeType}';
901+
}
902+
}
903+
890904
static List<ErrorCodeParameter>? _decodeParameters(Object? yaml) {
891905
if (yaml == null) return null;
892906
if (yaml == 'none') return const [];

0 commit comments

Comments
 (0)