Skip to content

Commit

Permalink
Provide test example of using lints from config
Browse files Browse the repository at this point in the history
Summary:
We are able to specify a limited set of lints from a config file.
Provide an end-to-end test example of how to use this.

Reviewed By: robertoaloi

Differential Revision: D58779864

fbshipit-source-id: 6f3e185ee021a0752bb5b9108de236919aed25ec
  • Loading branch information
alanz authored and facebook-github-bot committed Jun 19, 2024
1 parent c2206f4 commit f7a3a14
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 0 deletions.
31 changes: 31 additions & 0 deletions crates/elp/src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1121,6 +1121,37 @@ mod tests {
.expect("bad test");
}

#[test_case(false ; "rebar")]
#[test_case(true ; "buck")]
fn lint_custom_ad_hoc_lints(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");
check_lint_fix(
args_vec![
"lint",
"--experimental",
"--config-file",
"../../test_projects/linter/elp_lint_adhoc.toml",
"--module",
"app_b",
"--apply-fix",
"--to",
tmp_path,
],
"linter",
expect_file!("../resources/test/linter/parse_elp_lint_adhoc_output.stdout"),
0,
buck,
None,
tmp_path,
Path::new("../resources/test/lint/from_config"),
&[("app_b/src/app_b.erl", "app_b.erl")],
false,
)
.expect("bad test");
}

#[test_case(false ; "rebar")]
#[test_case(true ; "buck")]
fn lint_diagnostic_ignore(buck: bool) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-module(app_b).
-export([application_env_error/0]).

application_env_error() ->
ok.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module specified: app_b
Diagnostics reported in 1 modules:
app_b: 1
4:4-4:34::[WeakWarning] [ad-hoc: application:get_env/2] 'application:get_env/2' called
---------------------------------------------

Applying fix in module 'app_b' for
4:4-4:34::[WeakWarning] [ad-hoc: application:get_env/2] 'application:get_env/2' called
@@ -1,5 +1,5 @@
-module(app_b).
-export([application_env_error/0]).

application_env_error() ->
- application:get_env(misc, key).
+ ok.

15 changes: 15 additions & 0 deletions test_projects/linter/elp_lint_adhoc.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
enabled_lints = ["ad-hoc: application:get_env/2"]
# disabled_lints = []

[[ad_hoc_lints.lints]]
type = "ReplaceCall"

[ad_hoc_lints.lints.matcher]
type = "MFA"
module = "application"
name = "get_env"
arity = 2

[ad_hoc_lints.lints.action]
action = "Replace"
type = "UseOk"

0 comments on commit f7a3a14

Please sign in to comment.