| 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.error.codes; | 5 library analyzer.src.error.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'; | |
| 9 | 8 |
| 10 /** | 9 export 'package:analyzer/src/analysis_options/error/option_codes.dart'; |
| 11 * The error codes used for errors in analysis options files. The convention for | 10 export 'package:analyzer/src/dart/error/hint_codes.dart'; |
| 12 * this class is for the name of the error code to indicate the problem that | 11 export 'package:analyzer/src/dart/error/lint_codes.dart'; |
| 13 * caused the error to be generated and for the error message to explain what is | 12 export 'package:analyzer/src/dart/error/todo_codes.dart'; |
| 14 * wrong and, when appropriate, how the problem can be corrected. | 13 export 'package:analyzer/src/html/error/html_codes.dart'; |
| 15 */ | |
| 16 class AnalysisOptionsErrorCode extends ErrorCode { | |
| 17 /** | |
| 18 * An error code indicating that there is a syntactic error in the file. | |
| 19 * | |
| 20 * Parameters: | |
| 21 * 0: the error message from the parse error | |
| 22 */ | |
| 23 static const AnalysisOptionsErrorCode PARSE_ERROR = | |
| 24 const AnalysisOptionsErrorCode('PARSE_ERROR', '{0}'); | |
| 25 | |
| 26 /** | |
| 27 * Initialize a newly created error code to have the given [name]. | |
| 28 */ | |
| 29 const AnalysisOptionsErrorCode(String name, String message, | |
| 30 [String correction]) | |
| 31 : super(name, message, correction); | |
| 32 | |
| 33 @override | |
| 34 ErrorSeverity get errorSeverity => ErrorSeverity.ERROR; | |
| 35 | |
| 36 @override | |
| 37 ErrorType get type => ErrorType.COMPILE_TIME_ERROR; | |
| 38 } | |
| 39 | |
| 40 /** | |
| 41 * The error codes used for warnings in analysis options files. The convention | |
| 42 * for this class is for the name of the error code to indicate the problem that | |
| 43 * caused the error to be generated and for the error message to explain what is | |
| 44 * wrong and, when appropriate, how the problem can be corrected. | |
| 45 */ | |
| 46 class AnalysisOptionsWarningCode extends ErrorCode { | |
| 47 /** | |
| 48 * An error code indicating that a plugin is being configured with an | |
| 49 * unsupported option and legal options are provided. | |
| 50 * | |
| 51 * Parameters: | |
| 52 * 0: the plugin name | |
| 53 * 1: the unsupported option key | |
| 54 * 2: legal values | |
| 55 */ | |
| 56 static const AnalysisOptionsWarningCode UNSUPPORTED_OPTION_WITH_LEGAL_VALUES = | |
| 57 const AnalysisOptionsWarningCode( | |
| 58 'UNSUPPORTED_OPTION_WITH_LEGAL_VALUES', | |
| 59 "The option '{1}' isn't supported by '{0}'.", | |
| 60 "Try using one of the supported options: {2}."); | |
| 61 | |
| 62 /** | |
| 63 * An error code indicating that a plugin is being configured with an | |
| 64 * unsupported option where there is just one legal value. | |
| 65 * | |
| 66 * Parameters: | |
| 67 * 0: the plugin name | |
| 68 * 1: the unsupported option key | |
| 69 * 2: the legal value | |
| 70 */ | |
| 71 static const AnalysisOptionsWarningCode UNSUPPORTED_OPTION_WITH_LEGAL_VALUE = | |
| 72 const AnalysisOptionsWarningCode( | |
| 73 'UNSUPPORTED_OPTION_WITH_LEGAL_VALUE', | |
| 74 "The option '{1}' isn't supported by '{0}'." | |
| 75 "Try using the only supported option: '{2}'."); | |
| 76 | |
| 77 /** | |
| 78 * An error code indicating that an option entry is being configured with an | |
| 79 * unsupported value. | |
| 80 * | |
| 81 * Parameters: | |
| 82 * 0: the option name | |
| 83 * 1: the unsupported value | |
| 84 * 2: legal values | |
| 85 */ | |
| 86 static const AnalysisOptionsWarningCode UNSUPPORTED_VALUE = | |
| 87 const AnalysisOptionsWarningCode( | |
| 88 'UNSUPPORTED_VALUE', | |
| 89 "The value '{1}' isn't supported by '{0}'.", | |
| 90 "Try using one of the supported options: {2}."); | |
| 91 | |
| 92 /** | |
| 93 * An error code indicating that an unrecognized error code is being used to | |
| 94 * specify an error filter. | |
| 95 * | |
| 96 * Parameters: | |
| 97 * 0: the unrecognized error code | |
| 98 */ | |
| 99 static const AnalysisOptionsWarningCode UNRECOGNIZED_ERROR_CODE = | |
| 100 const AnalysisOptionsWarningCode( | |
| 101 'UNRECOGNIZED_ERROR_CODE', "'{0}' isn't a recognized error code."); | |
| 102 | |
| 103 /** | |
| 104 * Initialize a newly created warning code to have the given [name]. | |
| 105 */ | |
| 106 const AnalysisOptionsWarningCode(String name, String message, | |
| 107 [String correction]) | |
| 108 : super(name, message, correction); | |
| 109 | |
| 110 @override | |
| 111 ErrorSeverity get errorSeverity => ErrorSeverity.WARNING; | |
| 112 | |
| 113 @override | |
| 114 ErrorType get type => ErrorType.STATIC_WARNING; | |
| 115 } | |
| 116 | 14 |
| 117 /** | 15 /** |
| 118 * The error codes used for compile time errors caused by constant evaluation | 16 * The error codes used for compile time errors caused by constant evaluation |
| 119 * that would throw an exception when run in checked mode. The client of the | 17 * that would throw an exception when run in checked mode. The client of the |
| 120 * analysis engine is responsible for determining how these errors should be | 18 * analysis engine is responsible for determining how these errors should be |
| 121 * presented to the user (for example, a command-line compiler might elect to | 19 * presented to the user (for example, a command-line compiler might elect to |
| 122 * treat these errors differently depending whether it is compiling it "checked" | 20 * treat these errors differently depending whether it is compiling it "checked" |
| 123 * mode). | 21 * mode). |
| 124 */ | 22 */ |
| 125 class CheckedModeCompileTimeErrorCode extends ErrorCode { | 23 class CheckedModeCompileTimeErrorCode extends ErrorCode { |
| (...skipping 2483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2609 : super(name, message, correction); | 2507 : super(name, message, correction); |
| 2610 | 2508 |
| 2611 @override | 2509 @override |
| 2612 ErrorSeverity get errorSeverity => ErrorType.COMPILE_TIME_ERROR.severity; | 2510 ErrorSeverity get errorSeverity => ErrorType.COMPILE_TIME_ERROR.severity; |
| 2613 | 2511 |
| 2614 @override | 2512 @override |
| 2615 ErrorType get type => ErrorType.COMPILE_TIME_ERROR; | 2513 ErrorType get type => ErrorType.COMPILE_TIME_ERROR; |
| 2616 } | 2514 } |
| 2617 | 2515 |
| 2618 /** | 2516 /** |
| 2619 * The hints and coding recommendations for best practices which are not | |
| 2620 * mentioned in the Dart Language Specification. | |
| 2621 */ | |
| 2622 class HintCode extends ErrorCode { | |
| 2623 /** | |
| 2624 * When an abstract supertype member is referenced with `super` as its target, | |
| 2625 * it cannot be overridden, so it is always a runtime error. | |
| 2626 * | |
| 2627 * Parameters: | |
| 2628 * 0: the display name for the kind of the referenced element | |
| 2629 * 1: the name of the referenced element | |
| 2630 */ | |
| 2631 static const HintCode ABSTRACT_SUPER_MEMBER_REFERENCE = const HintCode( | |
| 2632 'ABSTRACT_SUPER_MEMBER_REFERENCE', | |
| 2633 "The {0} '{1}' is always abstract in the supertype."); | |
| 2634 | |
| 2635 /** | |
| 2636 * This hint is generated anywhere where the | |
| 2637 * [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE] would have been generated, | |
| 2638 * if we used propagated information for the warnings. | |
| 2639 * | |
| 2640 * Parameters: | |
| 2641 * 0: the name of the actual argument type | |
| 2642 * 1: the name of the expected type | |
| 2643 */ | |
| 2644 static const HintCode ARGUMENT_TYPE_NOT_ASSIGNABLE = const HintCode( | |
| 2645 'ARGUMENT_TYPE_NOT_ASSIGNABLE', | |
| 2646 "The argument type '{0}' can't be assigned to the parameter type '{1}'."); | |
| 2647 | |
| 2648 /** | |
| 2649 * When the target expression uses '?.' operator, it can be `null`, so all the | |
| 2650 * subsequent invocations should also use '?.' operator. | |
| 2651 */ | |
| 2652 static const HintCode CAN_BE_NULL_AFTER_NULL_AWARE = const HintCode( | |
| 2653 'CAN_BE_NULL_AFTER_NULL_AWARE', | |
| 2654 "The target expression uses '?.', so its value can be null.", | |
| 2655 "Replace the '.' with a '?.' in the invocation."); | |
| 2656 | |
| 2657 /** | |
| 2658 * Dead code is code that is never reached, this can happen for instance if a | |
| 2659 * statement follows a return statement. | |
| 2660 */ | |
| 2661 static const HintCode DEAD_CODE = const HintCode( | |
| 2662 'DEAD_CODE', | |
| 2663 "Dead code.", | |
| 2664 "Try removing the code, or " | |
| 2665 "fixing the code before it so that it can be reached."); | |
| 2666 | |
| 2667 /** | |
| 2668 * Dead code is code that is never reached. This case covers cases where the | |
| 2669 * user has catch clauses after `catch (e)` or `on Object catch (e)`. | |
| 2670 */ | |
| 2671 static const HintCode DEAD_CODE_CATCH_FOLLOWING_CATCH = const HintCode( | |
| 2672 'DEAD_CODE_CATCH_FOLLOWING_CATCH', | |
| 2673 "Dead code: catch clauses after a 'catch (e)' or " | |
| 2674 "an 'on Object catch (e)' are never reached.", | |
| 2675 "Try reordering the catch clauses so that they can be reached, or " | |
| 2676 "removing the unreachable catch clauses."); | |
| 2677 | |
| 2678 /** | |
| 2679 * Dead code is code that is never reached. This case covers cases where the | |
| 2680 * user has an on-catch clause such as `on A catch (e)`, where a supertype of | |
| 2681 * `A` was already caught. | |
| 2682 * | |
| 2683 * Parameters: | |
| 2684 * 0: name of the subtype | |
| 2685 * 1: name of the supertype | |
| 2686 */ | |
| 2687 static const HintCode DEAD_CODE_ON_CATCH_SUBTYPE = const HintCode( | |
| 2688 'DEAD_CODE_ON_CATCH_SUBTYPE', | |
| 2689 "Dead code: this on-catch block will never be executed because '{0}' is " | |
| 2690 "a subtype of '{1}' and hence will have been caught above.", | |
| 2691 "Try reordering the catch clauses so that this block can be reached, or " | |
| 2692 "removing the unreachable catch clause."); | |
| 2693 | |
| 2694 /** | |
| 2695 * Deprecated members should not be invoked or used. | |
| 2696 * | |
| 2697 * Parameters: | |
| 2698 * 0: the name of the member | |
| 2699 */ | |
| 2700 static const HintCode DEPRECATED_MEMBER_USE = const HintCode( | |
| 2701 'DEPRECATED_MEMBER_USE', | |
| 2702 "'{0}' is deprecated and shouldn't be used.", | |
| 2703 "Try replacing the use of the deprecated member with the replacement."); | |
| 2704 | |
| 2705 /** | |
| 2706 * Duplicate imports. | |
| 2707 */ | |
| 2708 static const HintCode DUPLICATE_IMPORT = const HintCode('DUPLICATE_IMPORT', | |
| 2709 "Duplicate import.", "Try removing all but one import of the library."); | |
| 2710 | |
| 2711 /** | |
| 2712 * Hint to use the ~/ operator. | |
| 2713 */ | |
| 2714 static const HintCode DIVISION_OPTIMIZATION = const HintCode( | |
| 2715 'DIVISION_OPTIMIZATION', | |
| 2716 "The operator x ~/ y is more efficient than (x / y).toInt().", | |
| 2717 "Try re-writing the expression to use the '~/' operator."); | |
| 2718 | |
| 2719 /** | |
| 2720 * Hint for the `x is double` type checks. | |
| 2721 */ | |
| 2722 static const HintCode IS_DOUBLE = const HintCode( | |
| 2723 'IS_DOUBLE', | |
| 2724 "When compiled to JS, this test might return true when the left hand " | |
| 2725 "side is an int.", | |
| 2726 "Try testing for 'num' instead."); | |
| 2727 | |
| 2728 /** | |
| 2729 * Hint for the `x is int` type checks. | |
| 2730 */ | |
| 2731 static const HintCode IS_INT = const HintCode( | |
| 2732 'IS_INT', | |
| 2733 "When compiled to JS, this test might return true when the left hand " | |
| 2734 "side is a double.", | |
| 2735 "Try testing for 'num' instead."); | |
| 2736 | |
| 2737 /** | |
| 2738 * Hint for the `x is! double` type checks. | |
| 2739 */ | |
| 2740 static const HintCode IS_NOT_DOUBLE = const HintCode( | |
| 2741 'IS_NOT_DOUBLE', | |
| 2742 "When compiled to JS, this test might return false when the left hand " | |
| 2743 "side is an int.", | |
| 2744 "Try testing for 'num' instead."); | |
| 2745 | |
| 2746 /** | |
| 2747 * Hint for the `x is! int` type checks. | |
| 2748 */ | |
| 2749 static const HintCode IS_NOT_INT = const HintCode( | |
| 2750 'IS_NOT_INT', | |
| 2751 "When compiled to JS, this test might return false when the left hand " | |
| 2752 "side is a double.", | |
| 2753 "Try testing for 'num' instead."); | |
| 2754 | |
| 2755 /** | |
| 2756 * Deferred libraries shouldn't define a top level function 'loadLibrary'. | |
| 2757 */ | |
| 2758 static const HintCode IMPORT_DEFERRED_LIBRARY_WITH_LOAD_FUNCTION = | |
| 2759 const HintCode( | |
| 2760 'IMPORT_DEFERRED_LIBRARY_WITH_LOAD_FUNCTION', | |
| 2761 "The library '{0}' defines a top-level function named 'loadLibrary' " | |
| 2762 "which is hidden by deferring this library.", | |
| 2763 "Try changing the import to not be deferred, or " | |
| 2764 "rename the function in the imported library."); | |
| 2765 | |
| 2766 /** | |
| 2767 * This hint is generated anywhere where the | |
| 2768 * [StaticTypeWarningCode.INVALID_ASSIGNMENT] would have been generated, if we | |
| 2769 * used propagated information for the warnings. | |
| 2770 * | |
| 2771 * Parameters: | |
| 2772 * 0: the name of the right hand side type | |
| 2773 * 1: the name of the left hand side type | |
| 2774 */ | |
| 2775 static const HintCode INVALID_ASSIGNMENT = const HintCode( | |
| 2776 'INVALID_ASSIGNMENT', | |
| 2777 "A value of type '{0}' can't be assigned to a variable of type '{1}'.", | |
| 2778 "Try changing the type of the variable, or " | |
| 2779 "casting the right-hand type to '{1}'."); | |
| 2780 | |
| 2781 /** | |
| 2782 * This hint is generated anywhere a @factory annotation is associated with | |
| 2783 * anything other than a method. | |
| 2784 */ | |
| 2785 static const HintCode INVALID_FACTORY_ANNOTATION = const HintCode( | |
| 2786 'INVALID_FACTORY_ANNOTATION', | |
| 2787 "Only methods can be annotated as factories."); | |
| 2788 | |
| 2789 /** | |
| 2790 * This hint is generated anywhere a @factory annotation is associated with | |
| 2791 * a method that does not declare a return type. | |
| 2792 */ | |
| 2793 static const HintCode INVALID_FACTORY_METHOD_DECL = const HintCode( | |
| 2794 'INVALID_FACTORY_METHOD_DECL', | |
| 2795 "Factory method '{0}' must have a return type."); | |
| 2796 | |
| 2797 /** | |
| 2798 * This hint is generated anywhere a @factory annotation is associated with | |
| 2799 * a non-abstract method that can return anything other than a newly allocated | |
| 2800 * object. | |
| 2801 * | |
| 2802 * Parameters: | |
| 2803 * 0: the name of the method | |
| 2804 */ | |
| 2805 static const HintCode INVALID_FACTORY_METHOD_IMPL = const HintCode( | |
| 2806 'INVALID_FACTORY_METHOD_IMPL', | |
| 2807 "Factory method '{0}' doesn't return a newly allocated object."); | |
| 2808 | |
| 2809 /** | |
| 2810 * This hint is generated anywhere where a member annotated with `@protected` | |
| 2811 * is used outside an instance member of a subclass. | |
| 2812 * | |
| 2813 * Parameters: | |
| 2814 * 0: the name of the member | |
| 2815 * 1: the name of the defining class | |
| 2816 */ | |
| 2817 static const HintCode INVALID_USE_OF_PROTECTED_MEMBER = const HintCode( | |
| 2818 'INVALID_USE_OF_PROTECTED_MEMBER', | |
| 2819 "The member '{0}' can only be used within instance members of subclasses " | |
| 2820 "of '{1}'."); | |
| 2821 | |
| 2822 /** | |
| 2823 * Generate a hint for a constructor, function or method invocation where a | |
| 2824 * required parameter is missing. | |
| 2825 * | |
| 2826 * Parameters: | |
| 2827 * 0: the name of the parameter | |
| 2828 */ | |
| 2829 static const HintCode MISSING_REQUIRED_PARAM = const HintCode( | |
| 2830 'MISSING_REQUIRED_PARAM', "The parameter '{0}' is required."); | |
| 2831 | |
| 2832 /** | |
| 2833 * Generate a hint for a constructor, function or method invocation where a | |
| 2834 * required parameter is missing. | |
| 2835 * | |
| 2836 * Parameters: | |
| 2837 * 0: the name of the parameter | |
| 2838 * 1: message details | |
| 2839 */ | |
| 2840 static const HintCode MISSING_REQUIRED_PARAM_WITH_DETAILS = const HintCode( | |
| 2841 'MISSING_REQUIRED_PARAM_WITH_DETAILS', | |
| 2842 "The parameter '{0}' is required. {1}."); | |
| 2843 | |
| 2844 /** | |
| 2845 * Generate a hint for an element that is annotated with `@JS(...)` whose | |
| 2846 * library declaration is not similarly annotated. | |
| 2847 */ | |
| 2848 static const HintCode MISSING_JS_LIB_ANNOTATION = const HintCode( | |
| 2849 'MISSING_JS_LIB_ANNOTATION', | |
| 2850 "The @JS() annotation can only be used if it is also declared on the " | |
| 2851 "library directive.", | |
| 2852 "Try adding the annotation to the library directive."); | |
| 2853 | |
| 2854 /** | |
| 2855 * Generate a hint for methods or functions that have a return type, but do | |
| 2856 * not have a non-void return statement on all branches. At the end of methods | |
| 2857 * or functions with no return, Dart implicitly returns `null`, avoiding these | |
| 2858 * implicit returns is considered a best practice. | |
| 2859 * | |
| 2860 * Parameters: | |
| 2861 * 0: the name of the declared return type | |
| 2862 */ | |
| 2863 static const HintCode MISSING_RETURN = const HintCode( | |
| 2864 'MISSING_RETURN', | |
| 2865 "This function declares a return type of '{0}', but doesn't end with a " | |
| 2866 "return statement.", | |
| 2867 "Try adding a return statement, or changing the return type to 'void'."); | |
| 2868 | |
| 2869 /** | |
| 2870 * Generate a hint for methods that override methods annotated `@mustCallSuper
` | |
| 2871 * that do not invoke the overridden super method. | |
| 2872 * | |
| 2873 * Parameters: | |
| 2874 * 0: the name of the class declaring the overriden method | |
| 2875 */ | |
| 2876 static const HintCode MUST_CALL_SUPER = const HintCode( | |
| 2877 'MUST_CALL_SUPER', | |
| 2878 "This method overrides a method annotated as @mustCall super in '{0}', " | |
| 2879 "but does invoke the overriden method."); | |
| 2880 | |
| 2881 /** | |
| 2882 * A condition in a control flow statement could evaluate to `null` because it | |
| 2883 * uses the null-aware '?.' operator. | |
| 2884 */ | |
| 2885 static const HintCode NULL_AWARE_IN_CONDITION = const HintCode( | |
| 2886 'NULL_AWARE_IN_CONDITION', | |
| 2887 "The value of the '?.' operator can be 'null', which isn't appropriate " | |
| 2888 "in a condition.", | |
| 2889 "Try replacing the '?.' with a '.', testing the left-hand side for null if
" | |
| 2890 "necessary."); | |
| 2891 | |
| 2892 /** | |
| 2893 * A getter with the override annotation does not override an existing getter. | |
| 2894 */ | |
| 2895 static const HintCode OVERRIDE_ON_NON_OVERRIDING_GETTER = const HintCode( | |
| 2896 'OVERRIDE_ON_NON_OVERRIDING_GETTER', | |
| 2897 "Getter doesn't override an inherited getter.", | |
| 2898 "Try updating this class to match the superclass, or " | |
| 2899 "removing the override annotation."); | |
| 2900 | |
| 2901 /** | |
| 2902 * A field with the override annotation does not override a getter or setter. | |
| 2903 */ | |
| 2904 static const HintCode OVERRIDE_ON_NON_OVERRIDING_FIELD = const HintCode( | |
| 2905 'OVERRIDE_ON_NON_OVERRIDING_FIELD', | |
| 2906 "Field doesn't override an inherited getter or setter.", | |
| 2907 "Try updating this class to match the superclass, or " | |
| 2908 "removing the override annotation."); | |
| 2909 | |
| 2910 /** | |
| 2911 * A method with the override annotation does not override an existing method. | |
| 2912 */ | |
| 2913 static const HintCode OVERRIDE_ON_NON_OVERRIDING_METHOD = const HintCode( | |
| 2914 'OVERRIDE_ON_NON_OVERRIDING_METHOD', | |
| 2915 "Method doesn't override an inherited method.", | |
| 2916 "Try updating this class to match the superclass, or " | |
| 2917 "removing the override annotation."); | |
| 2918 | |
| 2919 /** | |
| 2920 * A setter with the override annotation does not override an existing setter. | |
| 2921 */ | |
| 2922 static const HintCode OVERRIDE_ON_NON_OVERRIDING_SETTER = const HintCode( | |
| 2923 'OVERRIDE_ON_NON_OVERRIDING_SETTER', | |
| 2924 "Setter doesn't override an inherited setter.", | |
| 2925 "Try updating this class to match the superclass, or " | |
| 2926 "removing the override annotation."); | |
| 2927 | |
| 2928 /** | |
| 2929 * Hint for classes that override equals, but not hashCode. | |
| 2930 * | |
| 2931 * Parameters: | |
| 2932 * 0: the name of the current class | |
| 2933 */ | |
| 2934 static const HintCode OVERRIDE_EQUALS_BUT_NOT_HASH_CODE = const HintCode( | |
| 2935 'OVERRIDE_EQUALS_BUT_NOT_HASH_CODE', | |
| 2936 "The class '{0}' overrides 'operator==', but not 'get hashCode'.", | |
| 2937 "Try implementing 'hashCode'."); | |
| 2938 | |
| 2939 /** | |
| 2940 * Type checks of the type `x is! Null` should be done with `x != null`. | |
| 2941 */ | |
| 2942 static const HintCode TYPE_CHECK_IS_NOT_NULL = const HintCode( | |
| 2943 'TYPE_CHECK_IS_NOT_NULL', | |
| 2944 "Tests for non-null should be done with '!= null'.", | |
| 2945 "Try replacing the 'is! Null' check with '!= null'."); | |
| 2946 | |
| 2947 /** | |
| 2948 * Type checks of the type `x is Null` should be done with `x == null`. | |
| 2949 */ | |
| 2950 static const HintCode TYPE_CHECK_IS_NULL = const HintCode( | |
| 2951 'TYPE_CHECK_IS_NULL', | |
| 2952 "Tests for null should be done with '== null'.", | |
| 2953 "Try replacing the 'is Null' check with '== null'."); | |
| 2954 | |
| 2955 /** | |
| 2956 * This hint is generated anywhere where the | |
| 2957 * [StaticTypeWarningCode.UNDEFINED_GETTER] or | |
| 2958 * [StaticWarningCode.UNDEFINED_GETTER] would have been generated, if we used | |
| 2959 * propagated information for the warnings. | |
| 2960 * | |
| 2961 * Parameters: | |
| 2962 * 0: the name of the getter | |
| 2963 * 1: the name of the enclosing type where the getter is being looked for | |
| 2964 */ | |
| 2965 static const HintCode UNDEFINED_GETTER = const HintCode( | |
| 2966 'UNDEFINED_GETTER', | |
| 2967 "The getter '{0}' isn't defined for the class '{1}'.", | |
| 2968 "Try defining a getter or field named '{0}', or invoke a different getter.
"); | |
| 2969 | |
| 2970 /** | |
| 2971 * An undefined name hidden in an import or export directive. | |
| 2972 */ | |
| 2973 static const HintCode UNDEFINED_HIDDEN_NAME = const HintCode( | |
| 2974 'UNDEFINED_HIDDEN_NAME', | |
| 2975 "The library '{0}' doesn't export a member with the hidden name '{1}'.", | |
| 2976 "Try removing the name from the list of hidden members."); | |
| 2977 | |
| 2978 /** | |
| 2979 * This hint is generated anywhere where the | |
| 2980 * [StaticTypeWarningCode.UNDEFINED_METHOD] would have been generated, if we | |
| 2981 * used propagated information for the warnings. | |
| 2982 * | |
| 2983 * Parameters: | |
| 2984 * 0: the name of the method that is undefined | |
| 2985 * 1: the resolved type name that the method lookup is happening on | |
| 2986 */ | |
| 2987 static const HintCode UNDEFINED_METHOD = const HintCode( | |
| 2988 'UNDEFINED_METHOD', | |
| 2989 "The method '{0}' isn't defined for the class '{1}'.", | |
| 2990 "Try correcting the name to the name of an existing method, or" | |
| 2991 "defining a method named '{0}'."); | |
| 2992 | |
| 2993 /** | |
| 2994 * This hint is generated anywhere where the | |
| 2995 * [StaticTypeWarningCode.UNDEFINED_OPERATOR] would have been generated, if we | |
| 2996 * used propagated information for the warnings. | |
| 2997 * | |
| 2998 * Parameters: | |
| 2999 * 0: the name of the operator | |
| 3000 * 1: the name of the enclosing type where the operator is being looked for | |
| 3001 */ | |
| 3002 static const HintCode UNDEFINED_OPERATOR = const HintCode( | |
| 3003 'UNDEFINED_OPERATOR', | |
| 3004 "The operator '{0}' isn't defined for the class '{1}'.", | |
| 3005 "Try defining the operator '{0}'."); | |
| 3006 | |
| 3007 /** | |
| 3008 * This hint is generated anywhere where the | |
| 3009 * [StaticTypeWarningCode.UNDEFINED_SETTER] or | |
| 3010 * [StaticWarningCode.UNDEFINED_SETTER] would have been generated, if we used | |
| 3011 * propagated information for the warnings. | |
| 3012 * | |
| 3013 * Parameters: | |
| 3014 * 0: the name of the setter | |
| 3015 * 1: the name of the enclosing type where the setter is being looked for | |
| 3016 */ | |
| 3017 static const HintCode UNDEFINED_SETTER = const HintCode( | |
| 3018 'UNDEFINED_SETTER', | |
| 3019 "The setter '{0}' isn't defined for the class '{1}'.", | |
| 3020 "Try defining a setter or field named '{0}', or invoke a different setter.
"); | |
| 3021 | |
| 3022 /** | |
| 3023 * An undefined name shown in an import or export directive. | |
| 3024 */ | |
| 3025 static const HintCode UNDEFINED_SHOWN_NAME = const HintCode( | |
| 3026 'UNDEFINED_SHOWN_NAME', | |
| 3027 "The library '{0}' doesn't export a member with the shown name '{1}'.", | |
| 3028 "Try removing the name from the list of shown members."); | |
| 3029 | |
| 3030 /** | |
| 3031 * Unnecessary cast. | |
| 3032 */ | |
| 3033 static const HintCode UNNECESSARY_CAST = const HintCode( | |
| 3034 'UNNECESSARY_CAST', "Unnecessary cast.", "Try removing the cast."); | |
| 3035 | |
| 3036 /** | |
| 3037 * Unnecessary `noSuchMethod` declaration. | |
| 3038 */ | |
| 3039 static const HintCode UNNECESSARY_NO_SUCH_METHOD = const HintCode( | |
| 3040 'UNNECESSARY_NO_SUCH_METHOD', | |
| 3041 "Unnecessary 'noSuchMethod' declaration.", | |
| 3042 "Try removing the declaration of 'noSuchMethod'."); | |
| 3043 | |
| 3044 /** | |
| 3045 * Unnecessary type checks, the result is always false. | |
| 3046 */ | |
| 3047 static const HintCode UNNECESSARY_TYPE_CHECK_FALSE = const HintCode( | |
| 3048 'UNNECESSARY_TYPE_CHECK_FALSE', | |
| 3049 "Unnecessary type check, the result is always false.", | |
| 3050 "Try correcting the type check, or removing the type check."); | |
| 3051 | |
| 3052 /** | |
| 3053 * Unnecessary type checks, the result is always true. | |
| 3054 */ | |
| 3055 static const HintCode UNNECESSARY_TYPE_CHECK_TRUE = const HintCode( | |
| 3056 'UNNECESSARY_TYPE_CHECK_TRUE', | |
| 3057 "Unnecessary type check, the result is always true.", | |
| 3058 "Try correcting the type check, or removing the type check."); | |
| 3059 | |
| 3060 /** | |
| 3061 * See [Modifier.IS_USED_IN_LIBRARY]. | |
| 3062 */ | |
| 3063 static const HintCode UNUSED_ELEMENT = const HintCode('UNUSED_ELEMENT', | |
| 3064 "The {0} '{1}' isn't used.", "Try removing the declaration of '{1}'."); | |
| 3065 | |
| 3066 /** | |
| 3067 * Unused fields are fields which are never read. | |
| 3068 */ | |
| 3069 static const HintCode UNUSED_FIELD = const HintCode( | |
| 3070 'UNUSED_FIELD', | |
| 3071 "The value of the field '{0}' isn't used.", | |
| 3072 "Try removing the field, or using it."); | |
| 3073 | |
| 3074 /** | |
| 3075 * Unused imports are imports which are never used. | |
| 3076 */ | |
| 3077 static const HintCode UNUSED_IMPORT = const HintCode( | |
| 3078 'UNUSED_IMPORT', "Unused import.", "Try removing the import directive."); | |
| 3079 | |
| 3080 /** | |
| 3081 * Unused catch exception variables. | |
| 3082 */ | |
| 3083 static const HintCode UNUSED_CATCH_CLAUSE = const HintCode( | |
| 3084 'UNUSED_CATCH_CLAUSE', | |
| 3085 "The exception variable '{0}' isn't used, so the 'catch' clause can be rem
oved.", | |
| 3086 // TODO(brianwilkerson) Split this error code so that we can differentiate | |
| 3087 // between removing the catch clause and replacing the catch clause with | |
| 3088 // an on clause. | |
| 3089 "Try removing the catch clause."); | |
| 3090 | |
| 3091 /** | |
| 3092 * Unused catch stack trace variables. | |
| 3093 */ | |
| 3094 static const HintCode UNUSED_CATCH_STACK = const HintCode( | |
| 3095 'UNUSED_CATCH_STACK', | |
| 3096 "The stack trace variable '{0}' isn't used and can be removed.", | |
| 3097 "Try removing the stack trace variable, or using it."); | |
| 3098 | |
| 3099 /** | |
| 3100 * Unused local variables are local variables which are never read. | |
| 3101 */ | |
| 3102 static const HintCode UNUSED_LOCAL_VARIABLE = const HintCode( | |
| 3103 'UNUSED_LOCAL_VARIABLE', | |
| 3104 "The value of the local variable '{0}' isn't used.", | |
| 3105 "Try removing the variable, or using it."); | |
| 3106 | |
| 3107 /** | |
| 3108 * Unused shown names are names shown on imports which are never used. | |
| 3109 */ | |
| 3110 static const HintCode UNUSED_SHOWN_NAME = const HintCode( | |
| 3111 'UNUSED_SHOWN_NAME', | |
| 3112 "The name {0} is shown, but not used.", | |
| 3113 "Try removing the name from the list of shown members."); | |
| 3114 | |
| 3115 /** | |
| 3116 * Hint for cases where the source expects a method or function to return a | |
| 3117 * non-void result, but the method or function signature returns void. | |
| 3118 * | |
| 3119 * Parameters: | |
| 3120 * 0: the name of the method or function that returns void | |
| 3121 */ | |
| 3122 static const HintCode USE_OF_VOID_RESULT = const HintCode( | |
| 3123 'USE_OF_VOID_RESULT', | |
| 3124 "The result of '{0}' is being used, even though it is declared to be 'void
'."); | |
| 3125 | |
| 3126 /** | |
| 3127 * It is a bad practice for a source file in a package "lib" directory | |
| 3128 * hierarchy to traverse outside that directory hierarchy. For example, a | |
| 3129 * source file in the "lib" directory should not contain a directive such as | |
| 3130 * `import '../web/some.dart'` which references a file outside the lib | |
| 3131 * directory. | |
| 3132 */ | |
| 3133 static const HintCode FILE_IMPORT_INSIDE_LIB_REFERENCES_FILE_OUTSIDE = | |
| 3134 const HintCode( | |
| 3135 'FILE_IMPORT_INSIDE_LIB_REFERENCES_FILE_OUTSIDE', | |
| 3136 "A file in the 'lib' directory shouldn't import a file outside the " | |
| 3137 "'lib' directory.", | |
| 3138 "Try removing the import, or " | |
| 3139 "moving the imported file inside the 'lib' directory."); | |
| 3140 | |
| 3141 /** | |
| 3142 * It is a bad practice for a source file ouside a package "lib" directory | |
| 3143 * hierarchy to traverse into that directory hierarchy. For example, a source | |
| 3144 * file in the "web" directory should not contain a directive such as | |
| 3145 * `import '../lib/some.dart'` which references a file inside the lib | |
| 3146 * directory. | |
| 3147 */ | |
| 3148 static const HintCode FILE_IMPORT_OUTSIDE_LIB_REFERENCES_FILE_INSIDE = | |
| 3149 const HintCode( | |
| 3150 'FILE_IMPORT_OUTSIDE_LIB_REFERENCES_FILE_INSIDE', | |
| 3151 "A file outside the 'lib' directory shouldn't reference a file " | |
| 3152 "inside the 'lib' directory using a relative path.", | |
| 3153 "Try using a package: URI instead."); | |
| 3154 | |
| 3155 /** | |
| 3156 * It is a bad practice for a package import to reference anything outside the | |
| 3157 * given package, or more generally, it is bad practice for a package import | |
| 3158 * to contain a "..". For example, a source file should not contain a | |
| 3159 * directive such as `import 'package:foo/../some.dart'`. | |
| 3160 */ | |
| 3161 static const HintCode PACKAGE_IMPORT_CONTAINS_DOT_DOT = const HintCode( | |
| 3162 'PACKAGE_IMPORT_CONTAINS_DOT_DOT', | |
| 3163 "A package import shouldn't contain '..'."); | |
| 3164 | |
| 3165 /** | |
| 3166 * Initialize a newly created error code to have the given [name]. The message | |
| 3167 * associated with the error will be created from the given [message] | |
| 3168 * template. The correction associated with the error will be created from the | |
| 3169 * given [correction] template. | |
| 3170 */ | |
| 3171 const HintCode(String name, String message, [String correction]) | |
| 3172 : super(name, message, correction); | |
| 3173 | |
| 3174 @override | |
| 3175 ErrorSeverity get errorSeverity => ErrorType.HINT.severity; | |
| 3176 | |
| 3177 @override | |
| 3178 ErrorType get type => ErrorType.HINT; | |
| 3179 } | |
| 3180 | |
| 3181 /** | |
| 3182 * The error codes used for errors in HTML files. The convention for this | |
| 3183 * class is for the name of the error code to indicate the problem that caused | |
| 3184 * the error to be generated and for the error message to explain what is wrong | |
| 3185 * and, when appropriate, how the problem can be corrected. | |
| 3186 */ | |
| 3187 class HtmlErrorCode extends ErrorCode { | |
| 3188 /** | |
| 3189 * An error code indicating that there is a syntactic error in the file. | |
| 3190 * | |
| 3191 * Parameters: | |
| 3192 * 0: the error message from the parse error | |
| 3193 */ | |
| 3194 static const HtmlErrorCode PARSE_ERROR = | |
| 3195 const HtmlErrorCode('PARSE_ERROR', '{0}'); | |
| 3196 | |
| 3197 /** | |
| 3198 * Initialize a newly created error code to have the given [name]. The message | |
| 3199 * associated with the error will be created from the given [message] | |
| 3200 * template. The correction associated with the error will be created from the | |
| 3201 * given [correction] template. | |
| 3202 */ | |
| 3203 const HtmlErrorCode(String name, String message, [String correction]) | |
| 3204 : super(name, message, correction); | |
| 3205 | |
| 3206 @override | |
| 3207 ErrorSeverity get errorSeverity => ErrorSeverity.ERROR; | |
| 3208 | |
| 3209 @override | |
| 3210 ErrorType get type => ErrorType.COMPILE_TIME_ERROR; | |
| 3211 } | |
| 3212 | |
| 3213 /** | |
| 3214 * The error codes used for warnings in HTML files. The convention for this | |
| 3215 * class is for the name of the error code to indicate the problem that caused | |
| 3216 * the error to be generated and for the error message to explain what is wrong | |
| 3217 * and, when appropriate, how the problem can be corrected. | |
| 3218 */ | |
| 3219 class HtmlWarningCode extends ErrorCode { | |
| 3220 /** | |
| 3221 * An error code indicating that the value of the 'src' attribute of a Dart | |
| 3222 * script tag is not a valid URI. | |
| 3223 * | |
| 3224 * Parameters: | |
| 3225 * 0: the URI that is invalid | |
| 3226 */ | |
| 3227 static const HtmlWarningCode INVALID_URI = | |
| 3228 const HtmlWarningCode('INVALID_URI', "Invalid URI syntax: '{0}'."); | |
| 3229 | |
| 3230 /** | |
| 3231 * An error code indicating that the value of the 'src' attribute of a Dart | |
| 3232 * script tag references a file that does not exist. | |
| 3233 * | |
| 3234 * Parameters: | |
| 3235 * 0: the URI pointing to a non-existent file | |
| 3236 */ | |
| 3237 static const HtmlWarningCode URI_DOES_NOT_EXIST = const HtmlWarningCode( | |
| 3238 'URI_DOES_NOT_EXIST', "Target of URI doesn't exist: '{0}'."); | |
| 3239 | |
| 3240 /** | |
| 3241 * Initialize a newly created error code to have the given [name]. The message | |
| 3242 * associated with the error will be created from the given [message] | |
| 3243 * template. The correction associated with the error will be created from the | |
| 3244 * given [correction] template. | |
| 3245 */ | |
| 3246 const HtmlWarningCode(String name, String message, [String correction]) | |
| 3247 : super(name, message, correction); | |
| 3248 | |
| 3249 @override | |
| 3250 ErrorSeverity get errorSeverity => ErrorSeverity.WARNING; | |
| 3251 | |
| 3252 @override | |
| 3253 ErrorType get type => ErrorType.STATIC_WARNING; | |
| 3254 } | |
| 3255 | |
| 3256 /** | |
| 3257 * Defines style and best practice recommendations. | |
| 3258 * | |
| 3259 * Unlike [HintCode]s, which are akin to traditional static warnings from a | |
| 3260 * compiler, lint recommendations focus on matters of style and practices that | |
| 3261 * might aggregated to define a project's style guide. | |
| 3262 */ | |
| 3263 class LintCode extends ErrorCode { | |
| 3264 const LintCode(String name, String message, [String correction]) | |
| 3265 : super(name, message, correction); | |
| 3266 | |
| 3267 @override | |
| 3268 ErrorSeverity get errorSeverity => ErrorSeverity.INFO; | |
| 3269 | |
| 3270 @override | |
| 3271 ErrorType get type => ErrorType.LINT; | |
| 3272 } | |
| 3273 | |
| 3274 /** | |
| 3275 * The error codes used for static type warnings. The convention for this class | 2517 * The error codes used for static type warnings. The convention for this class |
| 3276 * is for the name of the error code to indicate the problem that caused the | 2518 * is for the name of the error code to indicate the problem that caused the |
| 3277 * error to be generated and for the error message to explain what is wrong and, | 2519 * error to be generated and for the error message to explain what is wrong and, |
| 3278 * when appropriate, how the problem can be corrected. | 2520 * when appropriate, how the problem can be corrected. |
| 3279 */ | 2521 */ |
| 3280 class StaticTypeWarningCode extends ErrorCode { | 2522 class StaticTypeWarningCode extends ErrorCode { |
| 3281 /** | 2523 /** |
| 3282 * 12.7 Lists: A fresh instance (7.6.1) <i>a</i>, of size <i>n</i>, whose | 2524 * 12.7 Lists: A fresh instance (7.6.1) <i>a</i>, of size <i>n</i>, whose |
| 3283 * class implements the built-in class <i>List<E></i> is allocated. | 2525 * class implements the built-in class <i>List<E></i> is allocated. |
| 3284 * | 2526 * |
| (...skipping 2318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5603 * created from the optional [correction] template. | 4845 * created from the optional [correction] template. |
| 5604 */ | 4846 */ |
| 5605 const StrongModeCode(ErrorType type, String name, String message, | 4847 const StrongModeCode(ErrorType type, String name, String message, |
| 5606 [String correction]) | 4848 [String correction]) |
| 5607 : type = type, | 4849 : type = type, |
| 5608 super('STRONG_MODE_$name', message, correction); | 4850 super('STRONG_MODE_$name', message, correction); |
| 5609 | 4851 |
| 5610 @override | 4852 @override |
| 5611 ErrorSeverity get errorSeverity => type.severity; | 4853 ErrorSeverity get errorSeverity => type.severity; |
| 5612 } | 4854 } |
| 5613 | |
| 5614 /** | |
| 5615 * The error code indicating a marker in code for work that needs to be finished | |
| 5616 * or revisited. | |
| 5617 */ | |
| 5618 class TodoCode extends ErrorCode { | |
| 5619 /** | |
| 5620 * The single enum of TodoCode. | |
| 5621 */ | |
| 5622 static const TodoCode TODO = const TodoCode('TODO'); | |
| 5623 | |
| 5624 /** | |
| 5625 * This matches the two common Dart task styles | |
| 5626 * | |
| 5627 * * TODO: | |
| 5628 * * TODO(username): | |
| 5629 * | |
| 5630 * As well as | |
| 5631 * * TODO | |
| 5632 * | |
| 5633 * But not | |
| 5634 * * todo | |
| 5635 * * TODOS | |
| 5636 */ | |
| 5637 static RegExp TODO_REGEX = | |
| 5638 new RegExp("([\\s/\\*])((TODO[^\\w\\d][^\\r\\n]*)|(TODO:?\$))"); | |
| 5639 | |
| 5640 /** | |
| 5641 * Initialize a newly created error code to have the given [name]. | |
| 5642 */ | |
| 5643 const TodoCode(String name) : super(name, "{0}"); | |
| 5644 | |
| 5645 @override | |
| 5646 ErrorSeverity get errorSeverity => ErrorSeverity.INFO; | |
| 5647 | |
| 5648 @override | |
| 5649 ErrorType get type => ErrorType.TODO; | |
| 5650 } | |
| OLD | NEW |