diff --git a/crates/elp/src/bin/args.rs b/crates/elp/src/bin/args.rs index 1b7588a83..5757164d8 100644 --- a/crates/elp/src/bin/args.rs +++ b/crates/elp/src/bin/args.rs @@ -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, diff --git a/crates/elp/src/bin/lint_cli.rs b/crates/elp/src/bin/lint_cli.rs index 8a199d8b7..3b8e47415 100644 --- a/crates/elp/src/bin/lint_cli.rs +++ b/crates/elp/src/bin/lint_cli.rs @@ -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) @@ -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, @@ -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())); diff --git a/crates/elp/src/resources/test/lint_help.stdout b/crates/elp/src/resources/test/lint_help.stdout index 336e6bf5e..d8ef2cffa 100644 --- a/crates/elp/src/resources/test/lint_help.stdout +++ b/crates/elp/src/resources/test/lint_help.stdout @@ -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] ... +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] ... Available positional items: Rest of args are space separated list of apps to ignore @@ -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 Optional prefix to prepend to each fact. Only used when --format=json is set