|
| 1 | +# Live Test Ruby File for Tier 2 Native Fixer Validation |
| 2 | +# |
| 3 | +# This file contains INTENTIONAL issues that should be fixed by various tiers: |
| 4 | +# |
| 5 | +# Tier 1/2 (rubocop --auto-correct): |
| 6 | +# - Style/StringLiterals: Double quotes instead of single quotes |
| 7 | +# - Style/TrailingCommaInArrayLiteral: Missing trailing commas |
| 8 | +# - Style/TrailingCommaInHashLiteral: Missing trailing commas |
| 9 | +# - Style/FrozenStringLiteralComment: Missing magic comment |
| 10 | +# - Layout/SpaceAroundOperators: Missing spaces |
| 11 | +# - Layout/SpaceInsideHashLiteralBraces: Inconsistent spacing |
| 12 | +# - Layout/SpaceInsideArrayLiteralBrackets: Inconsistent spacing |
| 13 | +# - Layout/IndentationWidth: Inconsistent indentation |
| 14 | +# - Layout/EmptyLines: Extra blank lines |
| 15 | +# - Layout/TrailingWhitespace: Trailing whitespace |
| 16 | +# - Layout/EndOfLine: Line endings |
| 17 | +# |
| 18 | +# Tier 3 (AI Required - Metrics, Complexity): |
| 19 | +# - Metrics/MethodLength: Method too long |
| 20 | +# - Metrics/CyclomaticComplexity: Too complex |
| 21 | +# - Metrics/AbcSize: Assignment/Branch/Condition too high |
| 22 | +# - Style/Documentation: Missing class documentation |
| 23 | +# |
| 24 | +# DO NOT manually fix these issues - they are test fixtures. |
| 25 | + |
| 26 | +# Tier 1 (Style/FrozenStringLiteralComment): Missing magic comment at top |
| 27 | + |
| 28 | +# Tier 1 (Style/StringLiterals): Using double quotes instead of single |
| 29 | +class BadlyFormattedClass |
| 30 | + # Tier 1 (Style/StringLiterals): Double quotes where single would suffice |
| 31 | + def greeting_message |
| 32 | + "Hello, World!" |
| 33 | + end |
| 34 | + |
| 35 | + # Tier 1 (Style/StringLiterals): More double quotes |
| 36 | + def farewell_message |
| 37 | + "Goodbye, World!" |
| 38 | + end |
| 39 | + |
| 40 | + # Tier 1 (Layout/SpaceAroundOperators): Missing spaces around operators |
| 41 | + def calculate_sum(a,b,c) |
| 42 | + result=a+b*c-1 |
| 43 | + result |
| 44 | + end |
| 45 | + |
| 46 | + # Tier 1 (Layout/SpaceInsideHashLiteralBraces): Bad hash spacing |
| 47 | + def create_config |
| 48 | + {:name=>"test",:value=>42,:enabled=>true} |
| 49 | + end |
| 50 | + |
| 51 | + # Tier 1 (Layout/SpaceInsideArrayLiteralBrackets): Bad array spacing |
| 52 | + def create_list |
| 53 | + [ "apple","banana","cherry" ] |
| 54 | + end |
| 55 | + |
| 56 | + # Tier 1 (Style/TrailingCommaInArrayLiteral): Missing trailing commas |
| 57 | + def multi_line_array |
| 58 | + [ |
| 59 | + "first_item", |
| 60 | + "second_item", |
| 61 | + "third_item" |
| 62 | + ] |
| 63 | + end |
| 64 | + |
| 65 | + # Tier 1 (Style/TrailingCommaInHashLiteral): Missing trailing commas |
| 66 | + def multi_line_hash |
| 67 | + { |
| 68 | + name: "test", |
| 69 | + value: 123, |
| 70 | + active: true |
| 71 | + } |
| 72 | + end |
| 73 | + |
| 74 | + # Tier 1 (Layout/IndentationWidth): Bad indentation (3 spaces instead of 2) |
| 75 | + def bad_indentation |
| 76 | + result = 1 |
| 77 | + nested = 2 |
| 78 | + result + nested |
| 79 | + end |
| 80 | + |
| 81 | + # Tier 1 (Style/SymbolProc): Block can be replaced with symbol |
| 82 | + def process_names(names) |
| 83 | + names.map { |name| name.upcase } |
| 84 | + end |
| 85 | + |
| 86 | + # Tier 1 (Style/SymbolProc): Another block replacement opportunity |
| 87 | + def process_numbers(numbers) |
| 88 | + numbers.select { |n| n.even? } |
| 89 | + end |
| 90 | + |
| 91 | + # Tier 1 (Layout/EmptyLines): Extra blank lines |
| 92 | + |
| 93 | + |
| 94 | + def extra_blank_lines_above |
| 95 | + "method with blank lines above" |
| 96 | + end |
| 97 | + |
| 98 | + |
| 99 | + # Tier 1 (Style/RedundantReturn): Explicit return not needed |
| 100 | + def redundant_return_example(x) |
| 101 | + return x * 2 |
| 102 | + end |
| 103 | + |
| 104 | + # Tier 1 (Style/RedundantSelf): Unnecessary self |
| 105 | + def self_reference_example |
| 106 | + self.class.name |
| 107 | + end |
| 108 | + |
| 109 | + # Tier 1 (Style/NegatedIf): Negated condition |
| 110 | + def negated_condition(value) |
| 111 | + if !value.nil? |
| 112 | + "has value" |
| 113 | + else |
| 114 | + "no value" |
| 115 | + end |
| 116 | + end |
| 117 | + |
| 118 | + # Tier 1 (Style/GuardClause): Could use guard clause |
| 119 | + def no_guard_clause(value) |
| 120 | + if value |
| 121 | + process(value) |
| 122 | + validate(value) |
| 123 | + save(value) |
| 124 | + end |
| 125 | + end |
| 126 | + |
| 127 | + # Tier 1 (Style/ConditionalAssignment): Can be simplified |
| 128 | + def conditional_assignment(condition) |
| 129 | + if condition |
| 130 | + result = "yes" |
| 131 | + else |
| 132 | + result = "no" |
| 133 | + end |
| 134 | + result |
| 135 | + end |
| 136 | + |
| 137 | + # Tier 1 (Style/IfUnlessModifier): Should use modifier form |
| 138 | + def modifier_form_candidate(x) |
| 139 | + if x > 10 |
| 140 | + puts x |
| 141 | + end |
| 142 | + end |
| 143 | + |
| 144 | + # Tier 1 (Style/HashSyntax): Old hash rocket syntax |
| 145 | + def old_hash_syntax |
| 146 | + {:key => "value", :another => "data"} |
| 147 | + end |
| 148 | + |
| 149 | + # Tier 1 (Style/WordArray): Should use %w() |
| 150 | + def string_array_literal |
| 151 | + ["foo", "bar", "baz", "qux"] |
| 152 | + end |
| 153 | + |
| 154 | + # Tier 1 (Style/SymbolArray): Should use %i() |
| 155 | + def symbol_array_literal |
| 156 | + [:one, :two, :three, :four] |
| 157 | + end |
| 158 | + |
| 159 | + # Tier 3 (Metrics/MethodLength): Method too long - requires AI to refactor |
| 160 | + def overly_long_method(data) |
| 161 | + # This method intentionally has too many lines |
| 162 | + result = {} |
| 163 | + result[:step1] = data[:input1] || "default1" |
| 164 | + result[:step2] = data[:input2] || "default2" |
| 165 | + result[:step3] = data[:input3] || "default3" |
| 166 | + result[:step4] = data[:input4] || "default4" |
| 167 | + result[:step5] = data[:input5] || "default5" |
| 168 | + result[:step6] = data[:input6] || "default6" |
| 169 | + result[:step7] = data[:input7] || "default7" |
| 170 | + result[:step8] = data[:input8] || "default8" |
| 171 | + result[:step9] = data[:input9] || "default9" |
| 172 | + result[:step10] = data[:input10] || "default10" |
| 173 | + result[:step11] = data[:input11] || "default11" |
| 174 | + result[:step12] = data[:input12] || "default12" |
| 175 | + result[:step13] = data[:input13] || "default13" |
| 176 | + result[:step14] = data[:input14] || "default14" |
| 177 | + result[:step15] = data[:input15] || "default15" |
| 178 | + result[:processed] = true |
| 179 | + result[:timestamp] = Time.now |
| 180 | + result |
| 181 | + end |
| 182 | + |
| 183 | + # Tier 3 (Metrics/CyclomaticComplexity): Too many branches - requires AI |
| 184 | + def complex_decision_logic(a, b, c, d, e) |
| 185 | + if a > 0 |
| 186 | + if b > 0 |
| 187 | + if c > 0 |
| 188 | + "all positive" |
| 189 | + elsif c < 0 |
| 190 | + "c negative" |
| 191 | + else |
| 192 | + "c zero" |
| 193 | + end |
| 194 | + elsif b < 0 |
| 195 | + if d > 0 |
| 196 | + "d positive" |
| 197 | + else |
| 198 | + "d not positive" |
| 199 | + end |
| 200 | + else |
| 201 | + if e > 0 |
| 202 | + "e positive" |
| 203 | + elsif e < 0 |
| 204 | + "e negative" |
| 205 | + else |
| 206 | + "e zero" |
| 207 | + end |
| 208 | + end |
| 209 | + else |
| 210 | + "a not positive" |
| 211 | + end |
| 212 | + end |
| 213 | + |
| 214 | + # Tier 3 (Metrics/AbcSize): High ABC score - requires AI to refactor |
| 215 | + def high_abc_method(user) |
| 216 | + name = user.name |
| 217 | + email = user.email |
| 218 | + age = user.age |
| 219 | + address = user.address |
| 220 | + phone = user.phone |
| 221 | + company = user.company |
| 222 | + validated = validate_user(name, email) |
| 223 | + processed = process_user(age, address) |
| 224 | + notified = notify_user(phone, company) |
| 225 | + result = combine_results(validated, processed, notified) |
| 226 | + log_action(result) |
| 227 | + send_confirmation(email, result) |
| 228 | + update_database(user, result) |
| 229 | + result |
| 230 | + end |
| 231 | + |
| 232 | + private |
| 233 | + |
| 234 | + # Helper methods for the complex methods above |
| 235 | + def process(value) |
| 236 | + value |
| 237 | + end |
| 238 | + |
| 239 | + def validate(value) |
| 240 | + value |
| 241 | + end |
| 242 | + |
| 243 | + def save(value) |
| 244 | + value |
| 245 | + end |
| 246 | + |
| 247 | + def validate_user(name, email) |
| 248 | + true |
| 249 | + end |
| 250 | + |
| 251 | + def process_user(age, address) |
| 252 | + true |
| 253 | + end |
| 254 | + |
| 255 | + def notify_user(phone, company) |
| 256 | + true |
| 257 | + end |
| 258 | + |
| 259 | + def combine_results(a, b, c) |
| 260 | + { a: a, b: b, c: c } |
| 261 | + end |
| 262 | + |
| 263 | + def log_action(result) |
| 264 | + result |
| 265 | + end |
| 266 | + |
| 267 | + def send_confirmation(email, result) |
| 268 | + result |
| 269 | + end |
| 270 | + |
| 271 | + def update_database(user, result) |
| 272 | + result |
| 273 | + end |
| 274 | +end |
| 275 | + |
| 276 | +# Tier 1 (Style/Documentation): Missing class documentation |
| 277 | +class UndocumentedClass |
| 278 | + def undocumented_method |
| 279 | + "no docs" |
| 280 | + end |
| 281 | +end |
| 282 | + |
| 283 | +# Tier 1 (Layout/TrailingWhitespace): Trailing whitespace below |
| 284 | +# (There is intentional trailing whitespace on the line above) |
| 285 | + |
| 286 | +# Usage example (avoids "unused class" warnings) |
| 287 | +if __FILE__ == $PROGRAM_NAME |
| 288 | + obj = BadlyFormattedClass.new |
| 289 | + puts obj.greeting_message |
| 290 | + puts obj.farewell_message |
| 291 | + puts obj.calculate_sum(1, 2, 3) |
| 292 | + puts obj.create_config |
| 293 | + puts obj.create_list.inspect |
| 294 | + puts obj.multi_line_array.inspect |
| 295 | + puts obj.multi_line_hash |
| 296 | + puts obj.bad_indentation |
| 297 | + puts obj.process_names(["alice", "bob"]) |
| 298 | + puts obj.process_numbers([1, 2, 3, 4, 5, 6]) |
| 299 | + puts obj.extra_blank_lines_above |
| 300 | + puts obj.redundant_return_example(5) |
| 301 | + puts obj.self_reference_example |
| 302 | + puts obj.negated_condition("test") |
| 303 | + puts obj.conditional_assignment(true) |
| 304 | + puts obj.modifier_form_candidate(20) |
| 305 | + puts obj.old_hash_syntax |
| 306 | + puts obj.string_array_literal.inspect |
| 307 | + puts obj.symbol_array_literal.inspect |
| 308 | + puts obj.overly_long_method({}) |
| 309 | + puts obj.complex_decision_logic(1, 1, 1, 1, 1) |
| 310 | + |
| 311 | + undoc = UndocumentedClass.new |
| 312 | + puts undoc.undocumented_method |
| 313 | +end |
0 commit comments