Skip to content

Commit 6ab608a

Browse files
asashourCommit Queue
authored and
Commit Queue
committed
[analyzer] DEPRECATED_MEMBER_USE message which ends with period.
Fixes #50518 Change-Id: I5c22eb73133b5591ca3b4ea4c63823fcab0935c3 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/271020 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Brian Wilkerson <[email protected]>
1 parent 699b42c commit 6ab608a

File tree

5 files changed

+92
-9
lines changed

5 files changed

+92
-9
lines changed

pkg/analyzer/lib/src/dart/error/hint_codes.g.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ class HintCode extends AnalyzerErrorCode {
188188
static const HintCode DEPRECATED_MEMBER_USE_FROM_SAME_PACKAGE_WITH_MESSAGE =
189189
HintCode(
190190
'DEPRECATED_MEMBER_USE_FROM_SAME_PACKAGE',
191-
"'{0}' is deprecated and shouldn't be used. {1}.",
191+
"'{0}' is deprecated and shouldn't be used. {1}",
192192
correctionMessage:
193193
"Try replacing the use of the deprecated member with the replacement.",
194194
hasPublishedDocs: true,
@@ -200,7 +200,7 @@ class HintCode extends AnalyzerErrorCode {
200200
/// 1: message details
201201
static const HintCode DEPRECATED_MEMBER_USE_WITH_MESSAGE = HintCode(
202202
'DEPRECATED_MEMBER_USE',
203-
"'{0}' is deprecated and shouldn't be used. {1}.",
203+
"'{0}' is deprecated and shouldn't be used. {1}",
204204
correctionMessage:
205205
"Try replacing the use of the deprecated member with the replacement.",
206206
hasPublishedDocs: true,

pkg/analyzer/lib/src/error/deprecated_member_use_verifier.dart

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,8 @@ class DeprecatedMemberUseVerifier extends BaseDeprecatedMemberUseVerifier {
307307
AstNode errorNode, Element element, String displayName, String? message) {
308308
var library = element is LibraryElement ? element : element.library;
309309

310-
if (message == null || message.isEmpty) {
310+
message = message?.trim();
311+
if (message == null || message.isEmpty || message == '.') {
311312
_errorReporter.reportErrorForNode(
312313
_isLibraryInWorkspacePackage(library)
313314
? HintCode.DEPRECATED_MEMBER_USE_FROM_SAME_PACKAGE
@@ -316,6 +317,11 @@ class DeprecatedMemberUseVerifier extends BaseDeprecatedMemberUseVerifier {
316317
[displayName],
317318
);
318319
} else {
320+
if (!message.endsWith('.') &&
321+
!message.endsWith('?') &&
322+
!message.endsWith('!')) {
323+
message = '$message.';
324+
}
319325
_errorReporter.reportErrorForNode(
320326
_isLibraryInWorkspacePackage(library)
321327
? HintCode.DEPRECATED_MEMBER_USE_FROM_SAME_PACKAGE_WITH_MESSAGE

pkg/analyzer/messages.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17901,7 +17901,7 @@ HintCode:
1790117901
should indicate what code to use in place of the deprecated code.
1790217902
DEPRECATED_MEMBER_USE_WITH_MESSAGE:
1790317903
sharedName: DEPRECATED_MEMBER_USE
17904-
problemMessage: "'{0}' is deprecated and shouldn't be used. {1}."
17904+
problemMessage: "'{0}' is deprecated and shouldn't be used. {1}"
1790517905
correctionMessage: Try replacing the use of the deprecated member with the replacement.
1790617906
hasPublishedDocs: true
1790717907
comment: |-
@@ -17938,7 +17938,7 @@ HintCode:
1793817938
in place of the deprecated code.
1793917939
DEPRECATED_MEMBER_USE_FROM_SAME_PACKAGE_WITH_MESSAGE:
1794017940
sharedName: DEPRECATED_MEMBER_USE_FROM_SAME_PACKAGE
17941-
problemMessage: "'{0}' is deprecated and shouldn't be used. {1}."
17941+
problemMessage: "'{0}' is deprecated and shouldn't be used. {1}"
1794217942
correctionMessage: Try replacing the use of the deprecated member with the replacement.
1794317943
hasPublishedDocs: true
1794417944
comment: |-

pkg/analyzer/test/src/diagnostics/deprecated_member_use_test.dart

Lines changed: 79 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,28 @@ void f(A a) {
265265
a.foo();
266266
}
267267
''', [
268-
error(HintCode.DEPRECATED_MEMBER_USE_WITH_MESSAGE, 48, 3),
268+
error(HintCode.DEPRECATED_MEMBER_USE_WITH_MESSAGE, 48, 3,
269+
text: "'foo' is deprecated and shouldn't be used. 0.9."),
270+
]);
271+
}
272+
273+
test_methodInvocation_withMessage_dot() async {
274+
newFile('$workspaceRootPath/aaa/lib/a.dart', r'''
275+
class A {
276+
@Deprecated('0.9.')
277+
void foo() {}
278+
}
279+
''');
280+
281+
await assertErrorsInCode(r'''
282+
import 'package:aaa/a.dart';
283+
284+
void f(A a) {
285+
a.foo();
286+
}
287+
''', [
288+
error(HintCode.DEPRECATED_MEMBER_USE_WITH_MESSAGE, 48, 3,
289+
text: "'foo' is deprecated and shouldn't be used. 0.9."),
269290
]);
270291
}
271292

@@ -932,7 +953,63 @@ class A {
932953
}
933954
''', [
934955
error(
935-
HintCode.DEPRECATED_MEMBER_USE_FROM_SAME_PACKAGE_WITH_MESSAGE, 47, 1),
956+
HintCode.DEPRECATED_MEMBER_USE_FROM_SAME_PACKAGE_WITH_MESSAGE, 47, 1,
957+
text: "'m' is deprecated and shouldn't be used. 0.9."),
958+
]);
959+
}
960+
961+
test_methodInvocation_constructor_dot() async {
962+
await assertErrorsInCode(r'''
963+
class A {
964+
@Deprecated('0.9.')
965+
m() {}
966+
n() {m();}
967+
}
968+
''', [
969+
error(
970+
HintCode.DEPRECATED_MEMBER_USE_FROM_SAME_PACKAGE_WITH_MESSAGE, 48, 1,
971+
text: "'m' is deprecated and shouldn't be used. 0.9."),
972+
]);
973+
}
974+
975+
test_methodInvocation_constructor_exclamationMark() async {
976+
await assertErrorsInCode(r'''
977+
class A {
978+
@Deprecated(' Really! ')
979+
m() {}
980+
n() {m();}
981+
}
982+
''', [
983+
error(
984+
HintCode.DEPRECATED_MEMBER_USE_FROM_SAME_PACKAGE_WITH_MESSAGE, 53, 1,
985+
text: "'m' is deprecated and shouldn't be used. Really!"),
986+
]);
987+
}
988+
989+
test_methodInvocation_constructor_onlyDot() async {
990+
await assertErrorsInCode(r'''
991+
class A {
992+
@Deprecated('.')
993+
m() {}
994+
n() {m();}
995+
}
996+
''', [
997+
error(HintCode.DEPRECATED_MEMBER_USE_FROM_SAME_PACKAGE, 45, 1,
998+
text: "'m' is deprecated and shouldn't be used."),
999+
]);
1000+
}
1001+
1002+
test_methodInvocation_constructor_questionMark() async {
1003+
await assertErrorsInCode(r'''
1004+
class A {
1005+
@Deprecated('Are you sure?')
1006+
m() {}
1007+
n() {m();}
1008+
}
1009+
''', [
1010+
error(
1011+
HintCode.DEPRECATED_MEMBER_USE_FROM_SAME_PACKAGE_WITH_MESSAGE, 57, 1,
1012+
text: "'m' is deprecated and shouldn't be used. Are you sure?"),
9361013
]);
9371014
}
9381015

pkg/analyzer/tool/diagnostics/diagnostics.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3885,7 +3885,7 @@ name: example
38853885

38863886
_'{0}' is deprecated and shouldn't be used._
38873887

3888-
_'{0}' is deprecated and shouldn't be used. {1}._
3888+
_'{0}' is deprecated and shouldn't be used. {1}_
38893889

38903890
#### Description
38913891

@@ -3912,7 +3912,7 @@ should indicate what code to use in place of the deprecated code.
39123912

39133913
_'{0}' is deprecated and shouldn't be used._
39143914

3915-
_'{0}' is deprecated and shouldn't be used. {1}._
3915+
_'{0}' is deprecated and shouldn't be used. {1}_
39163916

39173917
#### Description
39183918

0 commit comments

Comments
 (0)