| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library analyzer.src.dart.error.hint_codes; | 5 library analyzer.src.dart.error.hint_codes; |
| 6 | 6 |
| 7 import 'package:analyzer/error/error.dart'; | 7 import 'package:analyzer/error/error.dart'; |
| 8 import 'package:analyzer/src/dart/element/element.dart'; | 8 import 'package:analyzer/src/dart/element/element.dart'; |
| 9 | 9 |
| 10 /** | 10 /** |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 * | 88 * |
| 89 * Parameters: | 89 * Parameters: |
| 90 * 0: the name of the member | 90 * 0: the name of the member |
| 91 */ | 91 */ |
| 92 static const HintCode DEPRECATED_MEMBER_USE = const HintCode( | 92 static const HintCode DEPRECATED_MEMBER_USE = const HintCode( |
| 93 'DEPRECATED_MEMBER_USE', | 93 'DEPRECATED_MEMBER_USE', |
| 94 "'{0}' is deprecated and shouldn't be used.", | 94 "'{0}' is deprecated and shouldn't be used.", |
| 95 "Try replacing the use of the deprecated member with the replacement."); | 95 "Try replacing the use of the deprecated member with the replacement."); |
| 96 | 96 |
| 97 /** | 97 /** |
| 98 * Duplicate imports. | |
| 99 */ | |
| 100 static const HintCode DUPLICATE_IMPORT = const HintCode('DUPLICATE_IMPORT', | |
| 101 "Duplicate import.", "Try removing all but one import of the library."); | |
| 102 | |
| 103 /** | |
| 104 * Hint to use the ~/ operator. | 98 * Hint to use the ~/ operator. |
| 105 */ | 99 */ |
| 106 static const HintCode DIVISION_OPTIMIZATION = const HintCode( | 100 static const HintCode DIVISION_OPTIMIZATION = const HintCode( |
| 107 'DIVISION_OPTIMIZATION', | 101 'DIVISION_OPTIMIZATION', |
| 108 "The operator x ~/ y is more efficient than (x / y).toInt().", | 102 "The operator x ~/ y is more efficient than (x / y).toInt().", |
| 109 "Try re-writing the expression to use the '~/' operator."); | 103 "Try re-writing the expression to use the '~/' operator."); |
| 110 | 104 |
| 111 /** | 105 /** |
| 112 * Hint for the `x is double` type checks. | 106 * Duplicate imports. |
| 113 */ | 107 */ |
| 114 static const HintCode IS_DOUBLE = const HintCode( | 108 static const HintCode DUPLICATE_IMPORT = const HintCode('DUPLICATE_IMPORT', |
| 115 'IS_DOUBLE', | 109 "Duplicate import.", "Try removing all but one import of the library."); |
| 116 "When compiled to JS, this test might return true when the left hand " | |
| 117 "side is an int.", | |
| 118 "Try testing for 'num' instead."); | |
| 119 | 110 |
| 120 /** | 111 /** |
| 121 * Hint for the `x is int` type checks. | 112 * It is a bad practice for a source file in a package "lib" directory |
| 113 * hierarchy to traverse outside that directory hierarchy. For example, a |
| 114 * source file in the "lib" directory should not contain a directive such as |
| 115 * `import '../web/some.dart'` which references a file outside the lib |
| 116 * directory. |
| 122 */ | 117 */ |
| 123 static const HintCode IS_INT = const HintCode( | 118 static const HintCode FILE_IMPORT_INSIDE_LIB_REFERENCES_FILE_OUTSIDE = |
| 124 'IS_INT', | 119 const HintCode( |
| 125 "When compiled to JS, this test might return true when the left hand " | 120 'FILE_IMPORT_INSIDE_LIB_REFERENCES_FILE_OUTSIDE', |
| 126 "side is a double.", | 121 "A file in the 'lib' directory shouldn't import a file outside the " |
| 127 "Try testing for 'num' instead."); | 122 "'lib' directory.", |
| 123 "Try removing the import, or " |
| 124 "moving the imported file inside the 'lib' directory."); |
| 128 | 125 |
| 129 /** | 126 /** |
| 130 * Hint for the `x is! double` type checks. | 127 * It is a bad practice for a source file ouside a package "lib" directory |
| 128 * hierarchy to traverse into that directory hierarchy. For example, a source |
| 129 * file in the "web" directory should not contain a directive such as |
| 130 * `import '../lib/some.dart'` which references a file inside the lib |
| 131 * directory. |
| 131 */ | 132 */ |
| 132 static const HintCode IS_NOT_DOUBLE = const HintCode( | 133 static const HintCode FILE_IMPORT_OUTSIDE_LIB_REFERENCES_FILE_INSIDE = |
| 133 'IS_NOT_DOUBLE', | 134 const HintCode( |
| 134 "When compiled to JS, this test might return false when the left hand " | 135 'FILE_IMPORT_OUTSIDE_LIB_REFERENCES_FILE_INSIDE', |
| 135 "side is an int.", | 136 "A file outside the 'lib' directory shouldn't reference a file " |
| 136 "Try testing for 'num' instead."); | 137 "inside the 'lib' directory using a relative path.", |
| 137 | 138 "Try using a package: URI instead."); |
| 138 /** | |
| 139 * Hint for the `x is! int` type checks. | |
| 140 */ | |
| 141 static const HintCode IS_NOT_INT = const HintCode( | |
| 142 'IS_NOT_INT', | |
| 143 "When compiled to JS, this test might return false when the left hand " | |
| 144 "side is a double.", | |
| 145 "Try testing for 'num' instead."); | |
| 146 | 139 |
| 147 /** | 140 /** |
| 148 * Deferred libraries shouldn't define a top level function 'loadLibrary'. | 141 * Deferred libraries shouldn't define a top level function 'loadLibrary'. |
| 149 */ | 142 */ |
| 150 static const HintCode IMPORT_DEFERRED_LIBRARY_WITH_LOAD_FUNCTION = | 143 static const HintCode IMPORT_DEFERRED_LIBRARY_WITH_LOAD_FUNCTION = |
| 151 const HintCode( | 144 const HintCode( |
| 152 'IMPORT_DEFERRED_LIBRARY_WITH_LOAD_FUNCTION', | 145 'IMPORT_DEFERRED_LIBRARY_WITH_LOAD_FUNCTION', |
| 153 "The library '{0}' defines a top-level function named 'loadLibrary' " | 146 "The library '{0}' defines a top-level function named 'loadLibrary' " |
| 154 "which is hidden by deferring this library.", | 147 "which is hidden by deferring this library.", |
| 155 "Try changing the import to not be deferred, or " | 148 "Try changing the import to not be deferred, or " |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 * object. | 185 * object. |
| 193 * | 186 * |
| 194 * Parameters: | 187 * Parameters: |
| 195 * 0: the name of the method | 188 * 0: the name of the method |
| 196 */ | 189 */ |
| 197 static const HintCode INVALID_FACTORY_METHOD_IMPL = const HintCode( | 190 static const HintCode INVALID_FACTORY_METHOD_IMPL = const HintCode( |
| 198 'INVALID_FACTORY_METHOD_IMPL', | 191 'INVALID_FACTORY_METHOD_IMPL', |
| 199 "Factory method '{0}' doesn't return a newly allocated object."); | 192 "Factory method '{0}' doesn't return a newly allocated object."); |
| 200 | 193 |
| 201 /** | 194 /** |
| 195 * Generic Method DEP: number of type parameters must match. |
| 196 * <https://github.com/leafpetersen/dep-generic-methods/blob/master/proposal.m
d#function-subtyping> |
| 197 * |
| 198 * Parameters: |
| 199 * 0: the number of type parameters in the method |
| 200 * 1: the number of type parameters in the overridden method |
| 201 * 2: the name of the class where the overridden method is declared |
| 202 */ |
| 203 static const HintCode INVALID_METHOD_OVERRIDE_TYPE_PARAMETERS = |
| 204 const HintCode( |
| 205 'INVALID_METHOD_OVERRIDE_TYPE_PARAMETERS', |
| 206 "The method has {0} type parameters, but it is overriding a method " |
| 207 "with {1} type parameters from '{2}'.", |
| 208 "Try changing the number of type parameters so that they are the same."); |
| 209 |
| 210 /** |
| 211 * Generic Method DEP: bounds of type parameters must be compatible. |
| 212 * <https://github.com/leafpetersen/dep-generic-methods/blob/master/proposal.m
d#function-subtyping> |
| 213 * |
| 214 * Parameters: |
| 215 * 0: the type parameter name |
| 216 * 1: the type parameter bound |
| 217 * 2: the overridden type parameter name |
| 218 * 3: the overridden type parameter bound |
| 219 * 4: the name of the class where the overridden method is declared |
| 220 */ |
| 221 static const HintCode INVALID_METHOD_OVERRIDE_TYPE_PARAMETER_BOUND = |
| 222 const HintCode( |
| 223 'INVALID_METHOD_OVERRIDE_TYPE_PARAMETER_BOUND', |
| 224 "The type parameter '{0}' extends '{1}', but that is stricter than " |
| 225 "'{2}' extends '{3}' in the overridden method from '{4}'.", |
| 226 "Try changing the bounds on the type parameters so that they are compatibl
e."); |
| 227 |
| 228 /** |
| 202 * This hint is generated anywhere where a member annotated with `@protected` | 229 * This hint is generated anywhere where a member annotated with `@protected` |
| 203 * is used outside an instance member of a subclass. | 230 * is used outside an instance member of a subclass. |
| 204 * | 231 * |
| 205 * Parameters: | 232 * Parameters: |
| 206 * 0: the name of the member | 233 * 0: the name of the member |
| 207 * 1: the name of the defining class | 234 * 1: the name of the defining class |
| 208 */ | 235 */ |
| 209 static const HintCode INVALID_USE_OF_PROTECTED_MEMBER = const HintCode( | 236 static const HintCode INVALID_USE_OF_PROTECTED_MEMBER = const HintCode( |
| 210 'INVALID_USE_OF_PROTECTED_MEMBER', | 237 'INVALID_USE_OF_PROTECTED_MEMBER', |
| 211 "The member '{0}' can only be used within instance members of subclasses " | 238 "The member '{0}' can only be used within instance members of subclasses " |
| 212 "of '{1}'."); | 239 "of '{1}'."); |
| 213 | 240 |
| 214 /** | 241 /** |
| 242 * Hint for the `x is double` type checks. |
| 243 */ |
| 244 static const HintCode IS_DOUBLE = const HintCode( |
| 245 'IS_DOUBLE', |
| 246 "When compiled to JS, this test might return true when the left hand " |
| 247 "side is an int.", |
| 248 "Try testing for 'num' instead."); |
| 249 |
| 250 /** |
| 251 * Hint for the `x is int` type checks. |
| 252 */ |
| 253 static const HintCode IS_INT = const HintCode( |
| 254 'IS_INT', |
| 255 "When compiled to JS, this test might return true when the left hand " |
| 256 "side is a double.", |
| 257 "Try testing for 'num' instead."); |
| 258 |
| 259 /** |
| 260 * Hint for the `x is! double` type checks. |
| 261 */ |
| 262 static const HintCode IS_NOT_DOUBLE = const HintCode( |
| 263 'IS_NOT_DOUBLE', |
| 264 "When compiled to JS, this test might return false when the left hand " |
| 265 "side is an int.", |
| 266 "Try testing for 'num' instead."); |
| 267 |
| 268 /** |
| 269 * Hint for the `x is! int` type checks. |
| 270 */ |
| 271 static const HintCode IS_NOT_INT = const HintCode( |
| 272 'IS_NOT_INT', |
| 273 "When compiled to JS, this test might return false when the left hand " |
| 274 "side is a double.", |
| 275 "Try testing for 'num' instead."); |
| 276 |
| 277 /** |
| 278 * Generate a hint for an element that is annotated with `@JS(...)` whose |
| 279 * library declaration is not similarly annotated. |
| 280 */ |
| 281 static const HintCode MISSING_JS_LIB_ANNOTATION = const HintCode( |
| 282 'MISSING_JS_LIB_ANNOTATION', |
| 283 "The @JS() annotation can only be used if it is also declared on the " |
| 284 "library directive.", |
| 285 "Try adding the annotation to the library directive."); |
| 286 |
| 287 /** |
| 215 * Generate a hint for a constructor, function or method invocation where a | 288 * Generate a hint for a constructor, function or method invocation where a |
| 216 * required parameter is missing. | 289 * required parameter is missing. |
| 217 * | 290 * |
| 218 * Parameters: | 291 * Parameters: |
| 219 * 0: the name of the parameter | 292 * 0: the name of the parameter |
| 220 */ | 293 */ |
| 221 static const HintCode MISSING_REQUIRED_PARAM = const HintCode( | 294 static const HintCode MISSING_REQUIRED_PARAM = const HintCode( |
| 222 'MISSING_REQUIRED_PARAM', "The parameter '{0}' is required."); | 295 'MISSING_REQUIRED_PARAM', "The parameter '{0}' is required."); |
| 223 | 296 |
| 224 /** | 297 /** |
| 225 * Generate a hint for a constructor, function or method invocation where a | 298 * Generate a hint for a constructor, function or method invocation where a |
| 226 * required parameter is missing. | 299 * required parameter is missing. |
| 227 * | 300 * |
| 228 * Parameters: | 301 * Parameters: |
| 229 * 0: the name of the parameter | 302 * 0: the name of the parameter |
| 230 * 1: message details | 303 * 1: message details |
| 231 */ | 304 */ |
| 232 static const HintCode MISSING_REQUIRED_PARAM_WITH_DETAILS = const HintCode( | 305 static const HintCode MISSING_REQUIRED_PARAM_WITH_DETAILS = const HintCode( |
| 233 'MISSING_REQUIRED_PARAM_WITH_DETAILS', | 306 'MISSING_REQUIRED_PARAM_WITH_DETAILS', |
| 234 "The parameter '{0}' is required. {1}."); | 307 "The parameter '{0}' is required. {1}."); |
| 235 | 308 |
| 236 /** | 309 /** |
| 237 * Generate a hint for an element that is annotated with `@JS(...)` whose | |
| 238 * library declaration is not similarly annotated. | |
| 239 */ | |
| 240 static const HintCode MISSING_JS_LIB_ANNOTATION = const HintCode( | |
| 241 'MISSING_JS_LIB_ANNOTATION', | |
| 242 "The @JS() annotation can only be used if it is also declared on the " | |
| 243 "library directive.", | |
| 244 "Try adding the annotation to the library directive."); | |
| 245 | |
| 246 /** | |
| 247 * Generate a hint for methods or functions that have a return type, but do | 310 * Generate a hint for methods or functions that have a return type, but do |
| 248 * not have a non-void return statement on all branches. At the end of methods | 311 * not have a non-void return statement on all branches. At the end of methods |
| 249 * or functions with no return, Dart implicitly returns `null`, avoiding these | 312 * or functions with no return, Dart implicitly returns `null`, avoiding these |
| 250 * implicit returns is considered a best practice. | 313 * implicit returns is considered a best practice. |
| 251 * | 314 * |
| 252 * Parameters: | 315 * Parameters: |
| 253 * 0: the name of the declared return type | 316 * 0: the name of the declared return type |
| 254 */ | 317 */ |
| 255 static const HintCode MISSING_RETURN = const HintCode( | 318 static const HintCode MISSING_RETURN = const HintCode( |
| 256 'MISSING_RETURN', | 319 'MISSING_RETURN', |
| (...skipping 18 matching lines...) Expand all Loading... |
| 275 * uses the null-aware '?.' operator. | 338 * uses the null-aware '?.' operator. |
| 276 */ | 339 */ |
| 277 static const HintCode NULL_AWARE_IN_CONDITION = const HintCode( | 340 static const HintCode NULL_AWARE_IN_CONDITION = const HintCode( |
| 278 'NULL_AWARE_IN_CONDITION', | 341 'NULL_AWARE_IN_CONDITION', |
| 279 "The value of the '?.' operator can be 'null', which isn't appropriate " | 342 "The value of the '?.' operator can be 'null', which isn't appropriate " |
| 280 "in a condition.", | 343 "in a condition.", |
| 281 "Try replacing the '?.' with a '.', testing the left-hand side for null if
" | 344 "Try replacing the '?.' with a '.', testing the left-hand side for null if
" |
| 282 "necessary."); | 345 "necessary."); |
| 283 | 346 |
| 284 /** | 347 /** |
| 348 * Hint for classes that override equals, but not hashCode. |
| 349 * |
| 350 * Parameters: |
| 351 * 0: the name of the current class |
| 352 */ |
| 353 static const HintCode OVERRIDE_EQUALS_BUT_NOT_HASH_CODE = const HintCode( |
| 354 'OVERRIDE_EQUALS_BUT_NOT_HASH_CODE', |
| 355 "The class '{0}' overrides 'operator==', but not 'get hashCode'.", |
| 356 "Try implementing 'hashCode'."); |
| 357 |
| 358 /** |
| 285 * A getter with the override annotation does not override an existing getter. | 359 * A getter with the override annotation does not override an existing getter. |
| 286 */ | 360 */ |
| 287 static const HintCode OVERRIDE_ON_NON_OVERRIDING_GETTER = const HintCode( | 361 static const HintCode OVERRIDE_ON_NON_OVERRIDING_GETTER = const HintCode( |
| 288 'OVERRIDE_ON_NON_OVERRIDING_GETTER', | 362 'OVERRIDE_ON_NON_OVERRIDING_GETTER', |
| 289 "Getter doesn't override an inherited getter.", | 363 "Getter doesn't override an inherited getter.", |
| 290 "Try updating this class to match the superclass, or " | 364 "Try updating this class to match the superclass, or " |
| 291 "removing the override annotation."); | 365 "removing the override annotation."); |
| 292 | 366 |
| 293 /** | 367 /** |
| 294 * A field with the override annotation does not override a getter or setter. | 368 * A field with the override annotation does not override a getter or setter. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 311 /** | 385 /** |
| 312 * A setter with the override annotation does not override an existing setter. | 386 * A setter with the override annotation does not override an existing setter. |
| 313 */ | 387 */ |
| 314 static const HintCode OVERRIDE_ON_NON_OVERRIDING_SETTER = const HintCode( | 388 static const HintCode OVERRIDE_ON_NON_OVERRIDING_SETTER = const HintCode( |
| 315 'OVERRIDE_ON_NON_OVERRIDING_SETTER', | 389 'OVERRIDE_ON_NON_OVERRIDING_SETTER', |
| 316 "Setter doesn't override an inherited setter.", | 390 "Setter doesn't override an inherited setter.", |
| 317 "Try updating this class to match the superclass, or " | 391 "Try updating this class to match the superclass, or " |
| 318 "removing the override annotation."); | 392 "removing the override annotation."); |
| 319 | 393 |
| 320 /** | 394 /** |
| 321 * Hint for classes that override equals, but not hashCode. | 395 * It is a bad practice for a package import to reference anything outside the |
| 322 * | 396 * given package, or more generally, it is bad practice for a package import |
| 323 * Parameters: | 397 * to contain a "..". For example, a source file should not contain a |
| 324 * 0: the name of the current class | 398 * directive such as `import 'package:foo/../some.dart'`. |
| 325 */ | 399 */ |
| 326 static const HintCode OVERRIDE_EQUALS_BUT_NOT_HASH_CODE = const HintCode( | 400 static const HintCode PACKAGE_IMPORT_CONTAINS_DOT_DOT = const HintCode( |
| 327 'OVERRIDE_EQUALS_BUT_NOT_HASH_CODE', | 401 'PACKAGE_IMPORT_CONTAINS_DOT_DOT', |
| 328 "The class '{0}' overrides 'operator==', but not 'get hashCode'.", | 402 "A package import shouldn't contain '..'."); |
| 329 "Try implementing 'hashCode'."); | |
| 330 | 403 |
| 331 /** | 404 /** |
| 332 * Type checks of the type `x is! Null` should be done with `x != null`. | 405 * Type checks of the type `x is! Null` should be done with `x != null`. |
| 333 */ | 406 */ |
| 334 static const HintCode TYPE_CHECK_IS_NOT_NULL = const HintCode( | 407 static const HintCode TYPE_CHECK_IS_NOT_NULL = const HintCode( |
| 335 'TYPE_CHECK_IS_NOT_NULL', | 408 'TYPE_CHECK_IS_NOT_NULL', |
| 336 "Tests for non-null should be done with '!= null'.", | 409 "Tests for non-null should be done with '!= null'.", |
| 337 "Try replacing the 'is! Null' check with '!= null'."); | 410 "Try replacing the 'is! Null' check with '!= null'."); |
| 338 | 411 |
| 339 /** | 412 /** |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 443 | 516 |
| 444 /** | 517 /** |
| 445 * Unnecessary type checks, the result is always true. | 518 * Unnecessary type checks, the result is always true. |
| 446 */ | 519 */ |
| 447 static const HintCode UNNECESSARY_TYPE_CHECK_TRUE = const HintCode( | 520 static const HintCode UNNECESSARY_TYPE_CHECK_TRUE = const HintCode( |
| 448 'UNNECESSARY_TYPE_CHECK_TRUE', | 521 'UNNECESSARY_TYPE_CHECK_TRUE', |
| 449 "Unnecessary type check, the result is always true.", | 522 "Unnecessary type check, the result is always true.", |
| 450 "Try correcting the type check, or removing the type check."); | 523 "Try correcting the type check, or removing the type check."); |
| 451 | 524 |
| 452 /** | 525 /** |
| 526 * Unused catch exception variables. |
| 527 */ |
| 528 static const HintCode UNUSED_CATCH_CLAUSE = const HintCode( |
| 529 'UNUSED_CATCH_CLAUSE', |
| 530 "The exception variable '{0}' isn't used, so the 'catch' clause can be rem
oved.", |
| 531 // TODO(brianwilkerson) Split this error code so that we can differentiate |
| 532 // between removing the catch clause and replacing the catch clause with |
| 533 // an on clause. |
| 534 "Try removing the catch clause."); |
| 535 |
| 536 /** |
| 537 * Unused catch stack trace variables. |
| 538 */ |
| 539 static const HintCode UNUSED_CATCH_STACK = const HintCode( |
| 540 'UNUSED_CATCH_STACK', |
| 541 "The stack trace variable '{0}' isn't used and can be removed.", |
| 542 "Try removing the stack trace variable, or using it."); |
| 543 |
| 544 /** |
| 453 * See [Modifier.IS_USED_IN_LIBRARY]. | 545 * See [Modifier.IS_USED_IN_LIBRARY]. |
| 454 */ | 546 */ |
| 455 static const HintCode UNUSED_ELEMENT = const HintCode('UNUSED_ELEMENT', | 547 static const HintCode UNUSED_ELEMENT = const HintCode('UNUSED_ELEMENT', |
| 456 "The {0} '{1}' isn't used.", "Try removing the declaration of '{1}'."); | 548 "The {0} '{1}' isn't used.", "Try removing the declaration of '{1}'."); |
| 457 | 549 |
| 458 /** | 550 /** |
| 459 * Unused fields are fields which are never read. | 551 * Unused fields are fields which are never read. |
| 460 */ | 552 */ |
| 461 static const HintCode UNUSED_FIELD = const HintCode( | 553 static const HintCode UNUSED_FIELD = const HintCode( |
| 462 'UNUSED_FIELD', | 554 'UNUSED_FIELD', |
| 463 "The value of the field '{0}' isn't used.", | 555 "The value of the field '{0}' isn't used.", |
| 464 "Try removing the field, or using it."); | 556 "Try removing the field, or using it."); |
| 465 | 557 |
| 466 /** | 558 /** |
| 467 * Unused imports are imports which are never used. | 559 * Unused imports are imports which are never used. |
| 468 */ | 560 */ |
| 469 static const HintCode UNUSED_IMPORT = const HintCode( | 561 static const HintCode UNUSED_IMPORT = const HintCode( |
| 470 'UNUSED_IMPORT', "Unused import.", "Try removing the import directive."); | 562 'UNUSED_IMPORT', "Unused import.", "Try removing the import directive."); |
| 471 | 563 |
| 472 /** | 564 /** |
| 473 * Unused catch exception variables. | |
| 474 */ | |
| 475 static const HintCode UNUSED_CATCH_CLAUSE = const HintCode( | |
| 476 'UNUSED_CATCH_CLAUSE', | |
| 477 "The exception variable '{0}' isn't used, so the 'catch' clause can be rem
oved.", | |
| 478 // TODO(brianwilkerson) Split this error code so that we can differentiate | |
| 479 // between removing the catch clause and replacing the catch clause with | |
| 480 // an on clause. | |
| 481 "Try removing the catch clause."); | |
| 482 | |
| 483 /** | |
| 484 * Unused catch stack trace variables. | |
| 485 */ | |
| 486 static const HintCode UNUSED_CATCH_STACK = const HintCode( | |
| 487 'UNUSED_CATCH_STACK', | |
| 488 "The stack trace variable '{0}' isn't used and can be removed.", | |
| 489 "Try removing the stack trace variable, or using it."); | |
| 490 | |
| 491 /** | |
| 492 * Unused local variables are local variables which are never read. | 565 * Unused local variables are local variables which are never read. |
| 493 */ | 566 */ |
| 494 static const HintCode UNUSED_LOCAL_VARIABLE = const HintCode( | 567 static const HintCode UNUSED_LOCAL_VARIABLE = const HintCode( |
| 495 'UNUSED_LOCAL_VARIABLE', | 568 'UNUSED_LOCAL_VARIABLE', |
| 496 "The value of the local variable '{0}' isn't used.", | 569 "The value of the local variable '{0}' isn't used.", |
| 497 "Try removing the variable, or using it."); | 570 "Try removing the variable, or using it."); |
| 498 | 571 |
| 499 /** | 572 /** |
| 500 * Unused shown names are names shown on imports which are never used. | 573 * Unused shown names are names shown on imports which are never used. |
| 501 */ | 574 */ |
| 502 static const HintCode UNUSED_SHOWN_NAME = const HintCode( | 575 static const HintCode UNUSED_SHOWN_NAME = const HintCode( |
| 503 'UNUSED_SHOWN_NAME', | 576 'UNUSED_SHOWN_NAME', |
| 504 "The name {0} is shown, but not used.", | 577 "The name {0} is shown, but not used.", |
| 505 "Try removing the name from the list of shown members."); | 578 "Try removing the name from the list of shown members."); |
| 506 | 579 |
| 507 /** | 580 /** |
| 508 * Hint for cases where the source expects a method or function to return a | 581 * Hint for cases where the source expects a method or function to return a |
| 509 * non-void result, but the method or function signature returns void. | 582 * non-void result, but the method or function signature returns void. |
| 510 * | 583 * |
| 511 * Parameters: | 584 * Parameters: |
| 512 * 0: the name of the method or function that returns void | 585 * 0: the name of the method or function that returns void |
| 513 */ | 586 */ |
| 514 static const HintCode USE_OF_VOID_RESULT = const HintCode( | 587 static const HintCode USE_OF_VOID_RESULT = const HintCode( |
| 515 'USE_OF_VOID_RESULT', | 588 'USE_OF_VOID_RESULT', |
| 516 "The result of '{0}' is being used, even though it is declared to be 'void
'."); | 589 "The result of '{0}' is being used, even though it is declared to be 'void
'."); |
| 517 | 590 |
| 518 /** | 591 /** |
| 519 * It is a bad practice for a source file in a package "lib" directory | 592 * It will be a static type warning if <i>m</i> is not a generic method with |
| 520 * hierarchy to traverse outside that directory hierarchy. For example, a | 593 * exactly <i>n</i> type parameters. |
| 521 * source file in the "lib" directory should not contain a directive such as | 594 * |
| 522 * `import '../web/some.dart'` which references a file outside the lib | 595 * Parameters: |
| 523 * directory. | 596 * 0: the name of the method being referenced (<i>G</i>) |
| 597 * 1: the number of type parameters that were declared |
| 598 * 2: the number of type arguments provided |
| 524 */ | 599 */ |
| 525 static const HintCode FILE_IMPORT_INSIDE_LIB_REFERENCES_FILE_OUTSIDE = | 600 static const HintCode WRONG_NUMBER_OF_TYPE_ARGUMENTS_METHOD = |
| 526 const HintCode( | 601 const HintCode( |
| 527 'FILE_IMPORT_INSIDE_LIB_REFERENCES_FILE_OUTSIDE', | 602 'WRONG_NUMBER_OF_TYPE_ARGUMENTS_METHOD', |
| 528 "A file in the 'lib' directory shouldn't import a file outside the " | 603 "The method '{0}' is declared with {1} type parameters, " |
| 529 "'lib' directory.", | 604 "but {2} type arguments were given.", |
| 530 "Try removing the import, or " | 605 "Try adjusting the number of type arguments."); |
| 531 "moving the imported file inside the 'lib' directory."); | |
| 532 | |
| 533 /** | |
| 534 * It is a bad practice for a source file ouside a package "lib" directory | |
| 535 * hierarchy to traverse into that directory hierarchy. For example, a source | |
| 536 * file in the "web" directory should not contain a directive such as | |
| 537 * `import '../lib/some.dart'` which references a file inside the lib | |
| 538 * directory. | |
| 539 */ | |
| 540 static const HintCode FILE_IMPORT_OUTSIDE_LIB_REFERENCES_FILE_INSIDE = | |
| 541 const HintCode( | |
| 542 'FILE_IMPORT_OUTSIDE_LIB_REFERENCES_FILE_INSIDE', | |
| 543 "A file outside the 'lib' directory shouldn't reference a file " | |
| 544 "inside the 'lib' directory using a relative path.", | |
| 545 "Try using a package: URI instead."); | |
| 546 | |
| 547 /** | |
| 548 * It is a bad practice for a package import to reference anything outside the | |
| 549 * given package, or more generally, it is bad practice for a package import | |
| 550 * to contain a "..". For example, a source file should not contain a | |
| 551 * directive such as `import 'package:foo/../some.dart'`. | |
| 552 */ | |
| 553 static const HintCode PACKAGE_IMPORT_CONTAINS_DOT_DOT = const HintCode( | |
| 554 'PACKAGE_IMPORT_CONTAINS_DOT_DOT', | |
| 555 "A package import shouldn't contain '..'."); | |
| 556 | 606 |
| 557 /** | 607 /** |
| 558 * Initialize a newly created error code to have the given [name]. The message | 608 * Initialize a newly created error code to have the given [name]. The message |
| 559 * associated with the error will be created from the given [message] | 609 * associated with the error will be created from the given [message] |
| 560 * template. The correction associated with the error will be created from the | 610 * template. The correction associated with the error will be created from the |
| 561 * given [correction] template. | 611 * given [correction] template. |
| 562 */ | 612 */ |
| 563 const HintCode(String name, String message, [String correction]) | 613 const HintCode(String name, String message, [String correction]) |
| 564 : super(name, message, correction); | 614 : super(name, message, correction); |
| 565 | 615 |
| 566 @override | 616 @override |
| 567 ErrorSeverity get errorSeverity => ErrorType.HINT.severity; | 617 ErrorSeverity get errorSeverity => ErrorType.HINT.severity; |
| 568 | 618 |
| 569 @override | 619 @override |
| 570 ErrorType get type => ErrorType.HINT; | 620 ErrorType get type => ErrorType.HINT; |
| 571 } | 621 } |
| OLD | NEW |