Skip to content

Commit

Permalink
Report an error if given L1500 for elp lint command
Browse files Browse the repository at this point in the history
Summary:
We changed the error code for `unused include` from `L1500` to `W0020`, because the `L` range belongs to diagnostics from the OTP compiler, and it is an ELP-native diagnostic.
Report a useful error if `L1500` is passed as the diagnostic filter for `elp lint`

Reviewed By: VLanvin

Differential Revision: D55186509

fbshipit-source-id: 53a445d51830cbee224277cc1c6a27b086a0adf1
  • Loading branch information
alanz authored and facebook-github-bot committed Mar 21, 2024
1 parent 961cf29 commit f119709
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
5 changes: 5 additions & 0 deletions crates/elp/src/bin/lint_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,11 @@ pub fn do_codemod(cli: &mut dyn Cli, loaded: &mut LoadResult, args: &Lint) -> Re
}

if let Some(diagnostic_filter) = diagnostic_filter {
// We have replaced L1500 with W0020. Generate an error if we get L1500.
if diagnostic_filter == "L1500" {
bail!("Code L1500 has been superseded by W0020");
}

let diagnostic_filter = DiagnosticCode::from(diagnostic_filter.as_str());
// Make sure we do not mask the one we explicitly asked for
disabled_diagnostics.remove(&diagnostic_filter);
Expand Down
15 changes: 15 additions & 0 deletions crates/elp/src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1225,6 +1225,21 @@ mod tests {
.expect("Bad test");
}

#[test_case(false ; "rebar")]
#[test_case(true ; "buck")]
fn lint_errors_on_deprecated_l1500(buck: bool) {
let tmp_dir = TempDir::new().expect("Could not create temporary directory");
let tmp_path = tmp_dir.path();
fs::create_dir_all(tmp_path).expect("Could not create temporary directory path");
simple_snapshot_expect_stderror(
args_vec!["lint", "--module", "app_a", "--diagnostic-filter", "L1500",],
"diagnostics",
expect_file!("../resources/test/diagnostics/parse_elp_l1500_deprecated.stdout"),
buck,
None,
)
}

#[test_case(false ; "rebar")]
#[test_case(true ; "buck")]
fn lint_edoc(buck: bool) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Code L1500 has been superseded by W0020

0 comments on commit f119709

Please sign in to comment.