Skip to content

Commit

Permalink
Fix iterations
Browse files Browse the repository at this point in the history
  • Loading branch information
chriscerie committed Oct 15, 2023
1 parent ff5d606 commit c7d371b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
7 changes: 5 additions & 2 deletions selene-lib/src/lints/test_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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::<Vec<_>>();
let mut fixed_diagnostics = diagnostics
.iter()
.filter(|diagnostic| diagnostic.fixed_code.is_some())
.collect::<Vec<_>>();
let mut lint_results;

// To handle potential conflicts with different lint suggestions, we apply conflicting fixes one at a time.
Expand Down
11 changes: 11 additions & 0 deletions selene/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,8 @@ fn apply_diagnostics_fixes(code: &str, diagnostics: &Vec<&Diagnostic>) -> String
}
});

println!("{}", chosen_diagnostics.iter().count());

new_code
}

Expand Down Expand Up @@ -355,9 +357,18 @@ fn read<R: 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",
Expand Down

0 comments on commit c7d371b

Please sign in to comment.