diff --git a/selene-lib/src/lints/test_util.rs b/selene-lib/src/lints/test_util.rs index 36dd2f44..4cd6e8d7 100644 --- a/selene-lib/src/lints/test_util.rs +++ b/selene-lib/src/lints/test_util.rs @@ -40,7 +40,7 @@ fn replace_code_range(code: &str, start: usize, end: usize, replacement: &str) - return code.to_string(); } - return format!("{}{}{}", &code[..start], replacement, &code[end..]); + format!("{}{}{}", &code[..start], replacement, &code[end..]) } /// Assumes diagnostics is sorted by starting positions @@ -146,7 +146,10 @@ pub fn test_lint_config_with_output< diagnostics.sort_by_key(|diagnostic| diagnostic.primary_label.range); let mut fixed_code = lua_source.to_string(); - let mut fixed_diagnostics = diagnostics.iter().collect::>(); + let mut fixed_diagnostics = diagnostics + .iter() + .filter(|diagnostic| diagnostic.fixed_code.is_some()) + .collect::>(); let mut lint_results; // To handle potential conflicts with different lint suggestions, we apply conflicting fixes one at a time. diff --git a/selene/src/main.rs b/selene/src/main.rs index fd01cd0c..ba2995bb 100644 --- a/selene/src/main.rs +++ b/selene/src/main.rs @@ -238,6 +238,8 @@ fn apply_diagnostics_fixes(code: &str, diagnostics: &Vec<&Diagnostic>) -> String } }); + println!("{}", chosen_diagnostics.iter().count()); + new_code } @@ -355,9 +357,18 @@ fn read( &diagnostics .iter() .map(|diagnostic| &diagnostic.diagnostic) + .filter(|diagnostic| diagnostic.fixed_code.is_some()) .collect(), ); + println!( + "Fixer generated invalid code:\n\ + ----------------\n\ + {}\n\ + ----------------\n", + fixed_code + ); + let fixed_ast = full_moon::parse(&fixed_code).expect( "selene tried applying lint suggestions, but it generated invalid code that could not be parsed; \ this is likely a selene bug",