Skip to content

Commit

Permalink
lint: add option to check eqwalize-all after applying a fix
Browse files Browse the repository at this point in the history
Summary:
Applying a fix may have knock-on effects in other files.
Provide a flag to enable running `eqwalize-all` processing after applying a fix to verify how successful it might be, and roll back if any errors are detected.

This makes the assumption that we start with a clean codebase.

Reviewed By: robertoaloi

Differential Revision: D62636754

fbshipit-source-id: d480f3ffb899ea1e651e5da628b9ee46f7e5881b
  • Loading branch information
alanz authored and facebook-github-bot committed Sep 13, 2024
1 parent 90812cc commit 0d176af
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
2 changes: 2 additions & 0 deletions crates/elp/src/bin/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,8 @@ pub struct Lint {
pub in_place: bool,
/// After applying a fix step, check that the diagnostics are clear, else roll back
pub with_check: bool,
/// After applying a fix step, check that all eqwalizer project diagnostics are clear, else roll back
pub check_eqwalize_all: bool,
/// Apply to all matching diagnostic occurrences at once, rather
/// than one at a time.
pub one_shot: bool,
Expand Down
24 changes: 23 additions & 1 deletion crates/elp/src/bin/lint_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,25 @@ fn do_parse_one(
.collect_vec();
diagnostics.set_edoc(file_id, edoc_diagnostics);
}
if args.include_eqwalizer_diagnostics {
if args.check_eqwalize_all {
let project_id = db.project_id(file_id).unwrap().unwrap();
let max_tasks = elp_project_model::EqwalizerConfig::default().max_tasks;
if let Some(diags) = db
.eqwalizer_diagnostics_by_project(project_id, vec![file_id], max_tasks)
.unwrap()
{
diagnostics.set_eqwalizer_project(diags);
}
} else {
if let Some(diags) = db
.eqwalizer_diagnostics_for_file(file_id, args.include_generated)
.unwrap()
{
diagnostics.set_eqwalizer(file_id, diags);
}
}
}
if args.include_eqwalizer_diagnostics {
if let Some(diags) = db
.eqwalizer_diagnostics_for_file(file_id, args.include_generated)
Expand Down Expand Up @@ -525,6 +544,9 @@ impl<'a> Lints<'a> {
files_changed: vec![(file_id, Some(Arc::from(source)))],
app_structure: None,
});
if self.args.check_eqwalize_all {
writeln!(cli, "Running eqwalize-all to check for knock-on problems.")?;
}
let diags = do_parse_one(
&self.analysis_host.analysis(),
self.cfg,
Expand All @@ -538,7 +560,7 @@ impl<'a> Lints<'a> {
.into_iter()
.any(|diag| diagnostics::Severity::Error == diag.severity)
});
if self.args.with_check && err_in_diags {
if (self.args.with_check || self.args.check_eqwalize_all) && err_in_diags {
bail!("Applying change introduces an error diagnostic");
} else {
self.changed_files.insert((file_id, name.clone()));
Expand Down
3 changes: 2 additions & 1 deletion crates/elp/src/resources/test/lint_help.stdout
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Usage: [--project PROJECT] [--module MODULE] [--file FILE] [--to TO] [--no-diags] [--experimental] [--as PROFILE] [[--format FORMAT]] [--rebar] [--include-generated] [--include-erlc-diagnostics] [--include-ct-diagnostics] [--include-edoc-diagnostics] [--include-eqwalizer-diagnostics] [--include-suppressed] [--include-tests] [--apply-fix] [--recursive] [--in-place] [--with-check] [--one-shot] [--prefix ARG] [--diagnostic-ignore CODE] [--diagnostic-filter CODE] [--ignore-fix-only] [--read-config] [--config-file CONFIG_FILE] <IGNORED_APPS>...
Usage: [--project PROJECT] [--module MODULE] [--file FILE] [--to TO] [--no-diags] [--experimental] [--as PROFILE] [[--format FORMAT]] [--rebar] [--include-generated] [--include-erlc-diagnostics] [--include-ct-diagnostics] [--include-edoc-diagnostics] [--include-eqwalizer-diagnostics] [--include-suppressed] [--include-tests] [--apply-fix] [--recursive] [--in-place] [--with-check] [--check-eqwalize-all] [--one-shot] [--prefix ARG] [--diagnostic-ignore CODE] [--diagnostic-filter CODE] [--ignore-fix-only] [--read-config] [--config-file CONFIG_FILE] <IGNORED_APPS>...

Available positional items:
<IGNORED_APPS> Rest of args are space separated list of apps to ignore
Expand Down Expand Up @@ -26,6 +26,7 @@ Available options:
prior change.
--in-place When applying a fix, modify the original file.
--with-check After applying a fix step, check that the diagnostics are clear, else roll back
--check-eqwalize-all After applying a fix step, check that all eqwalizer project diagnostics are clear, else roll back
--one-shot Apply to all matching diagnostic occurrences at once, rather
than one at a time.
--prefix <ARG> Optional prefix to prepend to each fact. Only used when --format=json is set
Expand Down

0 comments on commit 0d176af

Please sign in to comment.