Skip to content

Commit fbcbb83

Browse files
bwilkersoncommit-bot@chromium.org
authored andcommitted
Add documentation for more diagnostics
Change-Id: I57b69e5e16c7b6effb369e49556fc744976b04e8 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/110201 Commit-Queue: Brian Wilkerson <[email protected]> Reviewed-by: Kathy Walrath <[email protected]> Reviewed-by: Konstantin Shcheglov <[email protected]>
1 parent d9287f4 commit fbcbb83

File tree

4 files changed

+1593
-158
lines changed

4 files changed

+1593
-158
lines changed

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

Lines changed: 131 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -85,16 +85,29 @@ class HintCode extends ErrorCode {
8585
"Try replacing the use of the deprecated member with the replacement.");
8686

8787
/**
88-
* Deprecated members should not be invoked or used from within the package
89-
* where they are declared.
90-
*
91-
* Intentionally separate from DEPRECATED_MEMBER_USE, so that package owners
92-
* can ignore same-package deprecate member use Hints if they like, and
93-
* continue to see cross-package deprecated member use Hints.
94-
*
9588
* Parameters:
9689
* 0: the name of the member
9790
*/
91+
// #### Description
92+
//
93+
// The analyzer produces this diagnostic when a deprecated library member or
94+
// class member is used in the same package in which it's declared.
95+
//
96+
// #### Example
97+
//
98+
// The following code produces this diagnostic:
99+
//
100+
// ```dart
101+
// @deprecated
102+
// var x = 0;
103+
// var y = [!x!];
104+
// ```
105+
//
106+
// #### Common fixes
107+
//
108+
// The fix depends on what's been deprecated and what the replacement is. The
109+
// documentation for deprecated declarations should indicate what code to use
110+
// in place of the deprecated code.
98111
static const HintCode DEPRECATED_MEMBER_USE_FROM_SAME_PACKAGE = const HintCode(
99112
'DEPRECATED_MEMBER_USE_FROM_SAME_PACKAGE',
100113
"'{0}' is deprecated and shouldn't be used.",
@@ -431,14 +444,31 @@ class HintCode extends ErrorCode {
431444
"The parameter '{0}' is required. {1}.");
432445

433446
/**
434-
* Generate a hint for methods or functions that have a return type, but do
435-
* not have a non-void return statement on all branches. At the end of methods
436-
* or functions with no return, Dart implicitly returns `null`, avoiding these
437-
* implicit returns is considered a best practice.
438-
*
439447
* Parameters:
440448
* 0: the name of the declared return type
441449
*/
450+
// #### Description
451+
//
452+
// Any function or method that doesn’t end with either an explicit return or a
453+
// throw implicitly returns `null`. This is rarely the desired behavior. The
454+
// analyzer produces this diagnostic when it finds an implicit return.
455+
//
456+
// #### Example
457+
//
458+
// The following code produces this diagnostic:
459+
//
460+
// ```dart
461+
// [!int!] f(int x) {
462+
// if (x < 0) {
463+
// return 0;
464+
// }
465+
// }
466+
// ```
467+
//
468+
// #### Common fixes
469+
//
470+
// Add a return statement that makes the return value explicit, even if `null`
471+
// is the appropriate value.
442472
static const HintCode MISSING_RETURN = const HintCode(
443473
'MISSING_RETURN',
444474
"This function has a return type of '{0}', but doesn't end with a "
@@ -839,25 +869,87 @@ class HintCode extends ErrorCode {
839869

840870
/**
841871
* Parameters:
842-
* 0: The name that is declared but not referenced.
872+
* 0: the name that is declared but not referenced
843873
*/
874+
// #### Description
875+
//
876+
// The analyzer produces this diagnostic when a private class, enum, mixin,
877+
// typedef, top level variable, top level function, or method is declared but
878+
// never referenced.
879+
//
880+
// #### Example
881+
//
882+
// Assuming that no code in the library references `_C`, the following code
883+
// produces this diagnostic:
884+
//
885+
// ```dart
886+
// class [!_C!] {}
887+
// ```
888+
//
889+
// #### Common fixes
890+
//
891+
// If the declaration isn't needed, then remove it.
892+
//
893+
// If the declaration was intended to be used, then add the missing code.
844894
static const HintCode UNUSED_ELEMENT = const HintCode(
845895
'UNUSED_ELEMENT', "The declaration '{0}' isn't referenced.",
846896
correction: "Try removing the declaration of '{0}'.");
847897

848898
/**
849-
* Unused fields are fields which are never read.
899+
* Parameters:
900+
* 0: the name of the unused field
850901
*/
902+
// #### Description
903+
//
904+
// The analyzer produces this diagnostic when a private field is declared but
905+
// never read, even if it's written in one or more places.
906+
//
907+
// #### Example
908+
//
909+
// The following code produces this diagnostic:
910+
//
911+
// ```dart
912+
// class Point {
913+
// int [!_x!];
914+
// }
915+
// ```
916+
//
917+
// #### Common fixes
918+
//
919+
// If the field isn't needed, then remove it.
920+
//
921+
// If the field was intended to be used, then add the missing code.
851922
static const HintCode UNUSED_FIELD = const HintCode(
852923
'UNUSED_FIELD', "The value of the field '{0}' isn't used.",
853924
correction: "Try removing the field, or using it.");
854925

855926
/**
856-
* Unused imports are imports which are never used.
857-
*
858927
* Parameters:
859-
* 0: The content of the unused import's uri
928+
* 0: the content of the unused import's uri
860929
*/
930+
// #### Description
931+
//
932+
// The analyzer produces this diagnostic when an import isn't needed because
933+
// none of the names that are imported are referenced within the importing
934+
// library.
935+
//
936+
// #### Example
937+
//
938+
// The following code produces this diagnostic:
939+
//
940+
// ```dart
941+
// import [!'dart:async'!];
942+
//
943+
// void main() {
944+
// }
945+
// ```
946+
//
947+
// #### Common fixes
948+
//
949+
// If the import isn't needed, then remove it.
950+
//
951+
// If some of the imported names are intended to be used, then add the missing
952+
// code.
861953
static const HintCode UNUSED_IMPORT = const HintCode(
862954
'UNUSED_IMPORT', "Unused import: '{0}'.",
863955
correction: "Try removing the import directive.");
@@ -872,8 +964,29 @@ class HintCode extends ErrorCode {
872964
"using it in either a 'break' or 'continue' statement.");
873965

874966
/**
875-
* Unused local variables are local variables that are never read.
967+
* Parameters:
968+
* 0: the name of the unused variable
876969
*/
970+
// #### Description
971+
//
972+
// The analyzer produces this diagnostic when a local variable is declared but
973+
// never read, even if it's written in one or more places.
974+
//
975+
// #### Example
976+
//
977+
// The following code produces this diagnostic:
978+
//
979+
// ```dart
980+
// void main() {
981+
// int [!count!] = 0;
982+
// }
983+
// ```
984+
//
985+
// #### Common fixes
986+
//
987+
// If the variable isn't needed, then remove it.
988+
//
989+
// If the variable was intended to be used, then add the missing code.
877990
static const HintCode UNUSED_LOCAL_VARIABLE = const HintCode(
878991
'UNUSED_LOCAL_VARIABLE',
879992
"The value of the local variable '{0}' isn't used.",

0 commit comments

Comments
 (0)