Skip to content

Commit

Permalink
Add --include-otp-diagnostics option to "elp lint"
Browse files Browse the repository at this point in the history
Summary:
The `elp lint` command does not currently request diagnostics generated by the Erlang service.

Now that we can attach assists to them, it is time to be able to request them too.

Reviewed By: robertoaloi

Differential Revision: D59574230

fbshipit-source-id: f146ca7b5adf3d17e183e81fa42f1c46d990debd
  • Loading branch information
alanz authored and facebook-github-bot committed Jul 10, 2024
1 parent 1495d56 commit c03acbd
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 28 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 @@ -232,6 +232,8 @@ pub struct Lint {
/// Run with rebar
pub rebar: bool,
pub include_generated: bool,
/// Include erlang service diagnostics
pub include_erlang_service_diagnostics: bool,
/// Include Common Test diagnostics
pub include_ct_diagnostics: bool,
/// Include EDoc diagnostics
Expand Down
9 changes: 8 additions & 1 deletion crates/elp/src/bin/lint_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use elp_ide::diagnostics;
use elp_ide::diagnostics::DiagnosticCode;
use elp_ide::diagnostics::DiagnosticsConfig;
use elp_ide::diagnostics::LintConfig;
use elp_ide::diagnostics::RemoveElpReported;
use elp_ide::diagnostics_collection::DiagnosticCollection;
use elp_ide::diff::diff_from_textedit;
use elp_ide::diff::DiffRange;
Expand Down Expand Up @@ -132,7 +133,13 @@ fn do_parse_one(
let mut diagnostics = DiagnosticCollection::default();
let native = db.native_diagnostics(config, file_id)?;
diagnostics.set_native(file_id, native);

if args.include_erlang_service_diagnostics {
let erlang_service =
db.erlang_service_diagnostics(file_id, config, RemoveElpReported::Yes)?;
for (file_id, diags) in erlang_service {
diagnostics.set_erlang_service(file_id, diags);
}
}
if args.include_ct_diagnostics {
diagnostics.set_ct(file_id, db.ct_diagnostics(file_id, config)?);
}
Expand Down
19 changes: 19 additions & 0 deletions crates/elp/src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1185,6 +1185,25 @@ mod tests {
);
}

#[test_case(false ; "rebar")]
#[test_case(true ; "buck")]
fn lint_reports_erlang_service_diagnostics(buck: bool) {
simple_snapshot(
args_vec![
"lint",
"--include-erlang-service-diagnostics",
"--diagnostic-filter",
"L1318",
"--module",
"expression_updates_literal"
],
"linter",
expect_file!("../resources/test/linter/parse_elp_lint_erlang_service.stdout"),
buck,
None,
);
}

#[test_case(false ; "rebar")]
#[test_case(true ; "buck")]
fn lint_config_file_parse_error(buck: bool) {
Expand Down
55 changes: 28 additions & 27 deletions crates/elp/src/resources/test/lint_help.stdout
Original file line number Diff line number Diff line change
@@ -1,33 +1,34 @@
Usage: [--project PROJECT] [--module MODULE] [--file FILE] [--to TO] [--no-diags] [--experimental] [--as PROFILE] [[--format FORMAT]] [--rebar] [--include-generated] [--include-ct-diagnostics] [--include-edoc-diagnostics] [--include-suppressed] [--include-tests] [--apply-fix] [--recursive] [--in-place] [--one-shot] [--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-erlang-service-diagnostics] [--include-ct-diagnostics] [--include-edoc-diagnostics] [--include-suppressed] [--include-tests] [--apply-fix] [--recursive] [--in-place] [--one-shot] [--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

Available options:
--project <PROJECT> Path to directory with project, or to a JSON file (defaults to `.`)
--module <MODULE> Parse a single module from the project, not the entire project.
--file <FILE> Parse a single file from the project, not the entire project. This can be an include file or escript, etc.
--to <TO> Path to a directory where to dump result files
--no-diags Do not print the full diagnostics for a file, just the count
--experimental Report experimental diagnostics too, if diagnostics are enabled
--as <PROFILE> Rebar3 profile to pickup (default is test)
--format <FORMAT> Show diagnostics in JSON format
--rebar Run with rebar
--project <PROJECT> Path to directory with project, or to a JSON file (defaults to `.`)
--module <MODULE> Parse a single module from the project, not the entire project.
--file <FILE> Parse a single file from the project, not the entire project. This can be an include file or escript, etc.
--to <TO> Path to a directory where to dump result files
--no-diags Do not print the full diagnostics for a file, just the count
--experimental Report experimental diagnostics too, if diagnostics are enabled
--as <PROFILE> Rebar3 profile to pickup (default is test)
--format <FORMAT> Show diagnostics in JSON format
--rebar Run with rebar
--include-generated
--include-ct-diagnostics Include Common Test diagnostics
--include-edoc-diagnostics Include EDoc diagnostics
--include-suppressed Include Suppressed diagnostics (e.g. elp:fixme)
--include-tests Also generate diagnostics for test files
--apply-fix If the diagnostic has an associated fix, apply it. The modified file will be in the --to directory, or original file if --in-place is set.
--recursive If applying fixes, apply any new ones that arise from the
prior fixes recursively. Limited in scope to the clause of the
prior change.
--in-place When applying a fix, modify the original file.
--one-shot Apply to all matching diagnostic occurrences at once, rather
than one at a time.
--diagnostic-ignore <CODE> Ignore the specified diagnostic, by code or label
--diagnostic-filter <CODE> Filter out all reported diagnostics except this one, by code or label
--ignore-fix-only Only apply elp:ignore fixes
--read-config Get some configuration from a .elp_lint.toml file instead in the project root
--config-file <CONFIG_FILE> Override normal configuration file. When set, acts as if READ_CONFIG is true.
-h, --help Prints help information
--include-erlang-service-diagnostics Include erlang service diagnostics
--include-ct-diagnostics Include Common Test diagnostics
--include-edoc-diagnostics Include EDoc diagnostics
--include-suppressed Include Suppressed diagnostics (e.g. elp:fixme)
--include-tests Also generate diagnostics for test files
--apply-fix If the diagnostic has an associated fix, apply it. The modified file will be in the --to directory, or original file if --in-place is set.
--recursive If applying fixes, apply any new ones that arise from the
prior fixes recursively. Limited in scope to the clause of the
prior change.
--in-place When applying a fix, modify the original file.
--one-shot Apply to all matching diagnostic occurrences at once, rather
than one at a time.
--diagnostic-ignore <CODE> Ignore the specified diagnostic, by code or label
--diagnostic-filter <CODE> Filter out all reported diagnostics except this one, by code or label
--ignore-fix-only Only apply elp:ignore fixes
--read-config Get some configuration from a .elp_lint.toml file instead in the project root
--config-file <CONFIG_FILE> Override normal configuration file. When set, acts as if READ_CONFIG is true.
-h, --help Prints help information
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module specified: expression_updates_literal
Diagnostics reported in 1 modules:
expression_updates_literal: 1
7:6-8:15::[Warning] [L1318] expression updates a literal
10 changes: 10 additions & 0 deletions test_projects/linter/app_a/src/expression_updates_literal.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
%% % @format
-module(expression_updates_literal).
-compile(warn_missing_spec_all).

-export([a_fun/0]).

a_fun() ->
[ #{a => 1}
#{a => 2}
].

0 comments on commit c03acbd

Please sign in to comment.