Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(260)

Side by Side Diff: pkg/analyzer/lib/src/dart/error/hint_codes.dart

Issue 2442463002: Split out error codes into separate files (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 library analyzer.src.dart.error.hint_codes;
6
7 import 'package:analyzer/error/error.dart';
8 import 'package:analyzer/src/dart/element/element.dart';
9
10 /**
11 * The hints and coding recommendations for best practices which are not
12 * mentioned in the Dart Language Specification.
13 */
14 class HintCode extends ErrorCode {
15 /**
16 * When an abstract supertype member is referenced with `super` as its target,
17 * it cannot be overridden, so it is always a runtime error.
18 *
19 * Parameters:
20 * 0: the display name for the kind of the referenced element
21 * 1: the name of the referenced element
22 */
23 static const HintCode ABSTRACT_SUPER_MEMBER_REFERENCE = const HintCode(
24 'ABSTRACT_SUPER_MEMBER_REFERENCE',
25 "The {0} '{1}' is always abstract in the supertype.");
26
27 /**
28 * This hint is generated anywhere where the
29 * [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE] would have been generated,
30 * if we used propagated information for the warnings.
31 *
32 * Parameters:
33 * 0: the name of the actual argument type
34 * 1: the name of the expected type
35 */
36 static const HintCode ARGUMENT_TYPE_NOT_ASSIGNABLE = const HintCode(
37 'ARGUMENT_TYPE_NOT_ASSIGNABLE',
38 "The argument type '{0}' can't be assigned to the parameter type '{1}'.");
39
40 /**
41 * When the target expression uses '?.' operator, it can be `null`, so all the
42 * subsequent invocations should also use '?.' operator.
43 */
44 static const HintCode CAN_BE_NULL_AFTER_NULL_AWARE = const HintCode(
45 'CAN_BE_NULL_AFTER_NULL_AWARE',
46 "The target expression uses '?.', so its value can be null.",
47 "Replace the '.' with a '?.' in the invocation.");
48
49 /**
50 * Dead code is code that is never reached, this can happen for instance if a
51 * statement follows a return statement.
52 */
53 static const HintCode DEAD_CODE = const HintCode(
54 'DEAD_CODE',
55 "Dead code.",
56 "Try removing the code, or "
57 "fixing the code before it so that it can be reached.");
58
59 /**
60 * Dead code is code that is never reached. This case covers cases where the
61 * user has catch clauses after `catch (e)` or `on Object catch (e)`.
62 */
63 static const HintCode DEAD_CODE_CATCH_FOLLOWING_CATCH = const HintCode(
64 'DEAD_CODE_CATCH_FOLLOWING_CATCH',
65 "Dead code: catch clauses after a 'catch (e)' or "
66 "an 'on Object catch (e)' are never reached.",
67 "Try reordering the catch clauses so that they can be reached, or "
68 "removing the unreachable catch clauses.");
69
70 /**
71 * Dead code is code that is never reached. This case covers cases where the
72 * user has an on-catch clause such as `on A catch (e)`, where a supertype of
73 * `A` was already caught.
74 *
75 * Parameters:
76 * 0: name of the subtype
77 * 1: name of the supertype
78 */
79 static const HintCode DEAD_CODE_ON_CATCH_SUBTYPE = const HintCode(
80 'DEAD_CODE_ON_CATCH_SUBTYPE',
81 "Dead code: this on-catch block will never be executed because '{0}' is "
82 "a subtype of '{1}' and hence will have been caught above.",
83 "Try reordering the catch clauses so that this block can be reached, or "
84 "removing the unreachable catch clause.");
85
86 /**
87 * Deprecated members should not be invoked or used.
88 *
89 * Parameters:
90 * 0: the name of the member
91 */
92 static const HintCode DEPRECATED_MEMBER_USE = const HintCode(
93 'DEPRECATED_MEMBER_USE',
94 "'{0}' is deprecated and shouldn't be used.",
95 "Try replacing the use of the deprecated member with the replacement.");
96
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.
105 */
106 static const HintCode DIVISION_OPTIMIZATION = const HintCode(
107 'DIVISION_OPTIMIZATION',
108 "The operator x ~/ y is more efficient than (x / y).toInt().",
109 "Try re-writing the expression to use the '~/' operator.");
110
111 /**
112 * Hint for the `x is double` type checks.
113 */
114 static const HintCode IS_DOUBLE = const HintCode(
115 'IS_DOUBLE',
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
120 /**
121 * Hint for the `x is int` type checks.
122 */
123 static const HintCode IS_INT = const HintCode(
124 'IS_INT',
125 "When compiled to JS, this test might return true when the left hand "
126 "side is a double.",
127 "Try testing for 'num' instead.");
128
129 /**
130 * Hint for the `x is! double` type checks.
131 */
132 static const HintCode IS_NOT_DOUBLE = const HintCode(
133 'IS_NOT_DOUBLE',
134 "When compiled to JS, this test might return false when the left hand "
135 "side is an int.",
136 "Try testing for 'num' instead.");
137
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
147 /**
148 * Deferred libraries shouldn't define a top level function 'loadLibrary'.
149 */
150 static const HintCode IMPORT_DEFERRED_LIBRARY_WITH_LOAD_FUNCTION =
151 const HintCode(
152 'IMPORT_DEFERRED_LIBRARY_WITH_LOAD_FUNCTION',
153 "The library '{0}' defines a top-level function named 'loadLibrary' "
154 "which is hidden by deferring this library.",
155 "Try changing the import to not be deferred, or "
156 "rename the function in the imported library.");
157
158 /**
159 * This hint is generated anywhere where the
160 * [StaticTypeWarningCode.INVALID_ASSIGNMENT] would have been generated, if we
161 * used propagated information for the warnings.
162 *
163 * Parameters:
164 * 0: the name of the right hand side type
165 * 1: the name of the left hand side type
166 */
167 static const HintCode INVALID_ASSIGNMENT = const HintCode(
168 'INVALID_ASSIGNMENT',
169 "A value of type '{0}' can't be assigned to a variable of type '{1}'.",
170 "Try changing the type of the variable, or "
171 "casting the right-hand type to '{1}'.");
172
173 /**
174 * This hint is generated anywhere a @factory annotation is associated with
175 * anything other than a method.
176 */
177 static const HintCode INVALID_FACTORY_ANNOTATION = const HintCode(
178 'INVALID_FACTORY_ANNOTATION',
179 "Only methods can be annotated as factories.");
180
181 /**
182 * This hint is generated anywhere a @factory annotation is associated with
183 * a method that does not declare a return type.
184 */
185 static const HintCode INVALID_FACTORY_METHOD_DECL = const HintCode(
186 'INVALID_FACTORY_METHOD_DECL',
187 "Factory method '{0}' must have a return type.");
188
189 /**
190 * This hint is generated anywhere a @factory annotation is associated with
191 * a non-abstract method that can return anything other than a newly allocated
192 * object.
193 *
194 * Parameters:
195 * 0: the name of the method
196 */
197 static const HintCode INVALID_FACTORY_METHOD_IMPL = const HintCode(
198 'INVALID_FACTORY_METHOD_IMPL',
199 "Factory method '{0}' doesn't return a newly allocated object.");
200
201 /**
202 * This hint is generated anywhere where a member annotated with `@protected`
203 * is used outside an instance member of a subclass.
204 *
205 * Parameters:
206 * 0: the name of the member
207 * 1: the name of the defining class
208 */
209 static const HintCode INVALID_USE_OF_PROTECTED_MEMBER = const HintCode(
210 'INVALID_USE_OF_PROTECTED_MEMBER',
211 "The member '{0}' can only be used within instance members of subclasses "
212 "of '{1}'.");
213
214 /**
215 * Generate a hint for a constructor, function or method invocation where a
216 * required parameter is missing.
217 *
218 * Parameters:
219 * 0: the name of the parameter
220 */
221 static const HintCode MISSING_REQUIRED_PARAM = const HintCode(
222 'MISSING_REQUIRED_PARAM', "The parameter '{0}' is required.");
223
224 /**
225 * Generate a hint for a constructor, function or method invocation where a
226 * required parameter is missing.
227 *
228 * Parameters:
229 * 0: the name of the parameter
230 * 1: message details
231 */
232 static const HintCode MISSING_REQUIRED_PARAM_WITH_DETAILS = const HintCode(
233 'MISSING_REQUIRED_PARAM_WITH_DETAILS',
234 "The parameter '{0}' is required. {1}.");
235
236 /**
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
248 * 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
250 * implicit returns is considered a best practice.
251 *
252 * Parameters:
253 * 0: the name of the declared return type
254 */
255 static const HintCode MISSING_RETURN = const HintCode(
256 'MISSING_RETURN',
257 "This function declares a return type of '{0}', but doesn't end with a "
258 "return statement.",
259 "Try adding a return statement, or changing the return type to 'void'.");
260
261 /**
262 * Generate a hint for methods that override methods annotated `@mustCallSuper `
263 * that do not invoke the overridden super method.
264 *
265 * Parameters:
266 * 0: the name of the class declaring the overriden method
267 */
268 static const HintCode MUST_CALL_SUPER = const HintCode(
269 'MUST_CALL_SUPER',
270 "This method overrides a method annotated as @mustCall super in '{0}', "
271 "but does invoke the overriden method.");
272
273 /**
274 * A condition in a control flow statement could evaluate to `null` because it
275 * uses the null-aware '?.' operator.
276 */
277 static const HintCode NULL_AWARE_IN_CONDITION = const HintCode(
278 'NULL_AWARE_IN_CONDITION',
279 "The value of the '?.' operator can be 'null', which isn't appropriate "
280 "in a condition.",
281 "Try replacing the '?.' with a '.', testing the left-hand side for null if "
282 "necessary.");
283
284 /**
285 * A getter with the override annotation does not override an existing getter.
286 */
287 static const HintCode OVERRIDE_ON_NON_OVERRIDING_GETTER = const HintCode(
288 'OVERRIDE_ON_NON_OVERRIDING_GETTER',
289 "Getter doesn't override an inherited getter.",
290 "Try updating this class to match the superclass, or "
291 "removing the override annotation.");
292
293 /**
294 * A field with the override annotation does not override a getter or setter.
295 */
296 static const HintCode OVERRIDE_ON_NON_OVERRIDING_FIELD = const HintCode(
297 'OVERRIDE_ON_NON_OVERRIDING_FIELD',
298 "Field doesn't override an inherited getter or setter.",
299 "Try updating this class to match the superclass, or "
300 "removing the override annotation.");
301
302 /**
303 * A method with the override annotation does not override an existing method.
304 */
305 static const HintCode OVERRIDE_ON_NON_OVERRIDING_METHOD = const HintCode(
306 'OVERRIDE_ON_NON_OVERRIDING_METHOD',
307 "Method doesn't override an inherited method.",
308 "Try updating this class to match the superclass, or "
309 "removing the override annotation.");
310
311 /**
312 * A setter with the override annotation does not override an existing setter.
313 */
314 static const HintCode OVERRIDE_ON_NON_OVERRIDING_SETTER = const HintCode(
315 'OVERRIDE_ON_NON_OVERRIDING_SETTER',
316 "Setter doesn't override an inherited setter.",
317 "Try updating this class to match the superclass, or "
318 "removing the override annotation.");
319
320 /**
321 * Hint for classes that override equals, but not hashCode.
322 *
323 * Parameters:
324 * 0: the name of the current class
325 */
326 static const HintCode OVERRIDE_EQUALS_BUT_NOT_HASH_CODE = const HintCode(
327 'OVERRIDE_EQUALS_BUT_NOT_HASH_CODE',
328 "The class '{0}' overrides 'operator==', but not 'get hashCode'.",
329 "Try implementing 'hashCode'.");
330
331 /**
332 * Type checks of the type `x is! Null` should be done with `x != null`.
333 */
334 static const HintCode TYPE_CHECK_IS_NOT_NULL = const HintCode(
335 'TYPE_CHECK_IS_NOT_NULL',
336 "Tests for non-null should be done with '!= null'.",
337 "Try replacing the 'is! Null' check with '!= null'.");
338
339 /**
340 * Type checks of the type `x is Null` should be done with `x == null`.
341 */
342 static const HintCode TYPE_CHECK_IS_NULL = const HintCode(
343 'TYPE_CHECK_IS_NULL',
344 "Tests for null should be done with '== null'.",
345 "Try replacing the 'is Null' check with '== null'.");
346
347 /**
348 * This hint is generated anywhere where the
349 * [StaticTypeWarningCode.UNDEFINED_GETTER] or
350 * [StaticWarningCode.UNDEFINED_GETTER] would have been generated, if we used
351 * propagated information for the warnings.
352 *
353 * Parameters:
354 * 0: the name of the getter
355 * 1: the name of the enclosing type where the getter is being looked for
356 */
357 static const HintCode UNDEFINED_GETTER = const HintCode(
358 'UNDEFINED_GETTER',
359 "The getter '{0}' isn't defined for the class '{1}'.",
360 "Try defining a getter or field named '{0}', or invoke a different getter. ");
361
362 /**
363 * An undefined name hidden in an import or export directive.
364 */
365 static const HintCode UNDEFINED_HIDDEN_NAME = const HintCode(
366 'UNDEFINED_HIDDEN_NAME',
367 "The library '{0}' doesn't export a member with the hidden name '{1}'.",
368 "Try removing the name from the list of hidden members.");
369
370 /**
371 * This hint is generated anywhere where the
372 * [StaticTypeWarningCode.UNDEFINED_METHOD] would have been generated, if we
373 * used propagated information for the warnings.
374 *
375 * Parameters:
376 * 0: the name of the method that is undefined
377 * 1: the resolved type name that the method lookup is happening on
378 */
379 static const HintCode UNDEFINED_METHOD = const HintCode(
380 'UNDEFINED_METHOD',
381 "The method '{0}' isn't defined for the class '{1}'.",
382 "Try correcting the name to the name of an existing method, or"
383 "defining a method named '{0}'.");
384
385 /**
386 * This hint is generated anywhere where the
387 * [StaticTypeWarningCode.UNDEFINED_OPERATOR] would have been generated, if we
388 * used propagated information for the warnings.
389 *
390 * Parameters:
391 * 0: the name of the operator
392 * 1: the name of the enclosing type where the operator is being looked for
393 */
394 static const HintCode UNDEFINED_OPERATOR = const HintCode(
395 'UNDEFINED_OPERATOR',
396 "The operator '{0}' isn't defined for the class '{1}'.",
397 "Try defining the operator '{0}'.");
398
399 /**
400 * This hint is generated anywhere where the
401 * [StaticTypeWarningCode.UNDEFINED_SETTER] or
402 * [StaticWarningCode.UNDEFINED_SETTER] would have been generated, if we used
403 * propagated information for the warnings.
404 *
405 * Parameters:
406 * 0: the name of the setter
407 * 1: the name of the enclosing type where the setter is being looked for
408 */
409 static const HintCode UNDEFINED_SETTER = const HintCode(
410 'UNDEFINED_SETTER',
411 "The setter '{0}' isn't defined for the class '{1}'.",
412 "Try defining a setter or field named '{0}', or invoke a different setter. ");
413
414 /**
415 * An undefined name shown in an import or export directive.
416 */
417 static const HintCode UNDEFINED_SHOWN_NAME = const HintCode(
418 'UNDEFINED_SHOWN_NAME',
419 "The library '{0}' doesn't export a member with the shown name '{1}'.",
420 "Try removing the name from the list of shown members.");
421
422 /**
423 * Unnecessary cast.
424 */
425 static const HintCode UNNECESSARY_CAST = const HintCode(
426 'UNNECESSARY_CAST', "Unnecessary cast.", "Try removing the cast.");
427
428 /**
429 * Unnecessary `noSuchMethod` declaration.
430 */
431 static const HintCode UNNECESSARY_NO_SUCH_METHOD = const HintCode(
432 'UNNECESSARY_NO_SUCH_METHOD',
433 "Unnecessary 'noSuchMethod' declaration.",
434 "Try removing the declaration of 'noSuchMethod'.");
435
436 /**
437 * Unnecessary type checks, the result is always false.
438 */
439 static const HintCode UNNECESSARY_TYPE_CHECK_FALSE = const HintCode(
440 'UNNECESSARY_TYPE_CHECK_FALSE',
441 "Unnecessary type check, the result is always false.",
442 "Try correcting the type check, or removing the type check.");
443
444 /**
445 * Unnecessary type checks, the result is always true.
446 */
447 static const HintCode UNNECESSARY_TYPE_CHECK_TRUE = const HintCode(
448 'UNNECESSARY_TYPE_CHECK_TRUE',
449 "Unnecessary type check, the result is always true.",
450 "Try correcting the type check, or removing the type check.");
451
452 /**
453 * See [Modifier.IS_USED_IN_LIBRARY].
454 */
455 static const HintCode UNUSED_ELEMENT = const HintCode('UNUSED_ELEMENT',
456 "The {0} '{1}' isn't used.", "Try removing the declaration of '{1}'.");
457
458 /**
459 * Unused fields are fields which are never read.
460 */
461 static const HintCode UNUSED_FIELD = const HintCode(
462 'UNUSED_FIELD',
463 "The value of the field '{0}' isn't used.",
464 "Try removing the field, or using it.");
465
466 /**
467 * Unused imports are imports which are never used.
468 */
469 static const HintCode UNUSED_IMPORT = const HintCode(
470 'UNUSED_IMPORT', "Unused import.", "Try removing the import directive.");
471
472 /**
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.
493 */
494 static const HintCode UNUSED_LOCAL_VARIABLE = const HintCode(
495 'UNUSED_LOCAL_VARIABLE',
496 "The value of the local variable '{0}' isn't used.",
497 "Try removing the variable, or using it.");
498
499 /**
500 * Unused shown names are names shown on imports which are never used.
501 */
502 static const HintCode UNUSED_SHOWN_NAME = const HintCode(
503 'UNUSED_SHOWN_NAME',
504 "The name {0} is shown, but not used.",
505 "Try removing the name from the list of shown members.");
506
507 /**
508 * 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.
510 *
511 * Parameters:
512 * 0: the name of the method or function that returns void
513 */
514 static const HintCode USE_OF_VOID_RESULT = const HintCode(
515 'USE_OF_VOID_RESULT',
516 "The result of '{0}' is being used, even though it is declared to be 'void '.");
517
518 /**
519 * It is a bad practice for a source file in a package "lib" directory
520 * hierarchy to traverse outside that directory hierarchy. For example, a
521 * source file in the "lib" directory should not contain a directive such as
522 * `import '../web/some.dart'` which references a file outside the lib
523 * directory.
524 */
525 static const HintCode FILE_IMPORT_INSIDE_LIB_REFERENCES_FILE_OUTSIDE =
526 const HintCode(
527 'FILE_IMPORT_INSIDE_LIB_REFERENCES_FILE_OUTSIDE',
528 "A file in the 'lib' directory shouldn't import a file outside the "
529 "'lib' directory.",
530 "Try removing the import, or "
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
557 /**
558 * 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]
560 * template. The correction associated with the error will be created from the
561 * given [correction] template.
562 */
563 const HintCode(String name, String message, [String correction])
564 : super(name, message, correction);
565
566 @override
567 ErrorSeverity get errorSeverity => ErrorType.HINT.severity;
568
569 @override
570 ErrorType get type => ErrorType.HINT;
571 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/analysis_options/error/option_codes.dart ('k') | pkg/analyzer/lib/src/dart/error/lint_codes.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698