1 // Copyright Brian Schott (Hackerpilot) 2014. 2 // Distributed under the Boost Software License, Version 1.0. 3 // (See accompanying file LICENSE_1_0.txt or copy at 4 // http://www.boost.org/LICENSE_1_0.txt) 5 6 module analysis.config; 7 8 import inifiled; 9 10 StaticAnalysisConfig defaultStaticAnalysisConfig() 11 { 12 StaticAnalysisConfig config; 13 config.fillConfig!(Check.enabled); 14 return config; 15 } 16 17 enum Check: string 18 { 19 disabled = "disabled", 20 enabled = "enabled", 21 skipTests = "skip-unittest" 22 } 23 24 void fillConfig(string check)(ref StaticAnalysisConfig config) 25 { 26 foreach (mem; __traits(allMembers, StaticAnalysisConfig)) 27 { 28 static if (is(typeof(__traits(getMember, StaticAnalysisConfig, mem)))) 29 static if (is(typeof(__traits(getMember, config, mem)) == string)) 30 __traits(getMember, config, mem) = check; 31 } 32 } 33 34 unittest 35 { 36 StaticAnalysisConfig c; 37 c.fillConfig!(Check.enabled); 38 assert(c.enum_array_literal_check == Check.enabled); 39 fillConfig!(Check.skipTests)(c); 40 assert(c.alias_syntax_check == Check.skipTests); 41 } 42 43 @INI("Configure which static analysis checks are enabled") 44 struct StaticAnalysisConfig 45 { 46 @INI("Check variable, class, struct, interface, union, and function names against the Phobos style guide") 47 string style_check = Check.disabled; 48 49 @INI("Check for array literals that cause unnecessary allocation") 50 string enum_array_literal_check = Check.disabled; 51 52 @INI("Check for poor exception handling practices") 53 string exception_check = Check.disabled; 54 55 @INI("Check for use of the deprecated 'delete' keyword") 56 string delete_check = Check.disabled; 57 58 @INI("Check for use of the deprecated floating point operators") 59 string float_operator_check = Check.disabled; 60 61 @INI("Check number literals for readability") 62 string number_style_check = Check.disabled; 63 64 @INI("Checks that opEquals, opCmp, toHash, and toString are either const, immutable, or inout.") 65 string object_const_check = Check.disabled; 66 67 @INI("Checks for .. expressions where the left side is larger than the right.") 68 string backwards_range_check = Check.disabled; 69 70 @INI("Checks for if statements whose 'then' block is the same as the 'else' block") 71 string if_else_same_check = Check.disabled; 72 73 @INI("Checks for some problems with constructors") 74 string constructor_check = Check.disabled; 75 76 @INI("Checks for unused variables and function parameters") 77 string unused_variable_check = Check.disabled; 78 79 @INI("Checks for unused labels") 80 string unused_label_check = Check.disabled; 81 82 @INI("Checks for duplicate attributes") 83 string duplicate_attribute = Check.disabled; 84 85 @INI("Checks that opEquals and toHash are both defined or neither are defined") 86 string opequals_tohash_check = Check.disabled; 87 88 @INI("Checks for subtraction from .length properties") 89 string length_subtraction_check = Check.disabled; 90 91 @INI("Checks for methods or properties whose names conflict with built-in properties") 92 string builtin_property_names_check = Check.disabled; 93 94 @INI("Checks for confusing code in inline asm statements") 95 string asm_style_check = Check.disabled; 96 97 @INI("Checks for confusing logical operator precedence") 98 string logical_precedence_check = Check.disabled; 99 100 @INI("Checks for undocumented public declarations") 101 string undocumented_declaration_check = Check.disabled; 102 103 @INI("Checks for poor placement of function attributes") 104 string function_attribute_check = Check.disabled; 105 106 @INI("Checks for use of the comma operator") 107 string comma_expression_check = Check.disabled; 108 109 @INI("Checks for local imports that are too broad") 110 string local_import_check = Check.disabled; 111 112 @INI("Checks for variables that could be declared immutable") 113 string could_be_immutable_check = Check.disabled; // disabled by default for now 114 115 @INI("Checks for redundant expressions in if statements") 116 string redundant_if_check = Check.disabled; 117 118 @INI("Checks for redundant parenthesis") 119 string redundant_parens_check = Check.disabled; 120 121 @INI("Checks for mismatched argument and parameter names") 122 string mismatched_args_check = Check.disabled; 123 124 @INI("Checks for labels with the same name as variables") 125 string label_var_same_name_check = Check.disabled; 126 127 @INI("Checks for lines longer than 120 characters") 128 string long_line_check = Check.disabled; 129 130 @INI("Checks for assignment to auto-ref function parameters") 131 string auto_ref_assignment_check = Check.disabled; 132 133 @INI("Checks for incorrect infinite range definitions") 134 string incorrect_infinite_range_check = Check.disabled; 135 136 @INI("Checks for asserts that are always true") 137 string useless_assert_check = Check.disabled; 138 139 @INI("Check for uses of the old-style alias syntax") 140 string alias_syntax_check = Check.disabled; 141 142 @INI("Checks for else if that should be else static if") 143 string static_if_else_check = Check.disabled; 144 145 @INI("Check for unclear lambda syntax") 146 string lambda_return_check = Check.disabled; 147 148 @INI("Check for auto function without return statement") 149 string auto_function_check = Check.disabled; 150 151 @INI("Check for sortedness of imports") 152 string imports_sortedness = Check.disabled; 153 154 @INI("Check for explicitly annotated unittests") 155 string explicitly_annotated_unittests = Check.disabled; 156 157 @INI("Check for useless usage of the final attribute") 158 string final_attribute_check = Check.disabled; 159 }