Skip to content

Commit

Permalink
Fix new lint rules
Browse files Browse the repository at this point in the history
  • Loading branch information
plux committed May 19, 2024
1 parent cb48c94 commit 86fd262
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 31 deletions.
26 changes: 12 additions & 14 deletions apps/els_core/src/els_escript.erl
Original file line number Diff line number Diff line change
Expand Up @@ -225,20 +225,18 @@ epp_open24(File, Fd, StartLine, IncludePath, PreDefMacros) ->

-spec check_source(state()) -> state().
check_source(S) ->
case S of
#state{
exports_main = ExpMain,
forms_or_bin = [FileForm2, ModForm2 | Forms]
} ->
%% Optionally add export of main/1
Forms2 =
case ExpMain of
false -> [{attribute, erl_anno:new(0), export, [{main, 1}]} | Forms];
true -> Forms
end,
Forms3 = [FileForm2, ModForm2 | Forms2],
S#state{forms_or_bin = Forms3}
end.
#state{
exports_main = ExpMain,
forms_or_bin = [FileForm2, ModForm2 | Forms]
} = S,
%% Optionally add export of main/1
Forms2 =
case ExpMain of
false -> [{attribute, erl_anno:new(0), export, [{main, 1}]} | Forms];
true -> Forms
end,
Forms3 = [FileForm2, ModForm2 | Forms2],
S#state{forms_or_bin = Forms3}.

-spec pre_def_macros(_) -> {any(), any()}.
pre_def_macros(File) ->
Expand Down
4 changes: 2 additions & 2 deletions apps/els_core/src/els_io_string.erl
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ request({get_chars, _Encoding, _Prompt, N}, Str) ->
get_chars(N, Str);
request({get_line, _Encoding, _Prompt}, Str) ->
get_line(Str);
request({get_until, _Encoding, _Prompt, Module, Function, Xargs}, Str) ->
get_until(Module, Function, Xargs, Str);
request({get_until, _Encoding, _Prompt, Module, Function, XArgs}, Str) ->
get_until(Module, Function, XArgs, Str);
request(_Other, State) ->
{{error, request}, State}.

Expand Down
6 changes: 3 additions & 3 deletions apps/els_lsp/src/els_compiler_diagnostics.erl
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ make_code(compile, {crash, _Pass, _Reason, _Stk}) ->
<<"C1010">>;
make_code(compile, {bad_return, _Pass, _Reason}) ->
<<"C1011">>;
make_code(compile, {module_name, _Mod, _Filename}) ->
make_code(compile, {module_name, _Mod, _FileName}) ->
<<"C1012">>;
make_code(compile, _Other) ->
<<"C1099">>;
Expand Down Expand Up @@ -765,8 +765,8 @@ compile_file(Path, Dependencies) ->
Res = compile:file(Path, diagnostics_options()),
%% Restore things after compilation
[
code:load_binary(Dependency, Filename, Binary)
|| {{Dependency, Binary, Filename}, _} <- Olds
code:load_binary(Dependency, FileName, Binary)
|| {{Dependency, Binary, FileName}, _} <- Olds
],
Diagnostics = lists:flatten([Diags || {_, Diags} <- Olds]),
{Res, Diagnostics ++ module_name_check(Path)}.
Expand Down
4 changes: 2 additions & 2 deletions apps/els_lsp/src/els_docs.erl
Original file line number Diff line number Diff line change
Expand Up @@ -372,10 +372,10 @@ edoc_run(Uri) ->
?LOG_DEBUG("Done generating doc chunks for ~s.", [Module]),
Parent ! {Ref, Res}
catch
_:Err:St ->
_:Err:ST ->
?LOG_INFO(
"Generating do chunks for ~s failed: ~p\n~p",
[Module, Err, St]
[Module, Err, ST]
),
%% Respond to parent with error
Parent ! {Ref, error}
Expand Down
12 changes: 6 additions & 6 deletions apps/els_lsp/src/els_references_provider.erl
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ find_references(Uri, POI = #{kind := Kind}) when
Kind =:= define
->
find_scoped_references_for_def(Uri, POI);
find_references(Uri, Poi = #{kind := Kind, id := Id}) when
find_references(Uri, POI = #{kind := Kind, id := Id}) when
Kind =:= type_definition
->
Key =
Expand All @@ -113,15 +113,15 @@ find_references(Uri, Poi = #{kind := Kind, id := Id}) when
end,
lists:usort(
find_references_for_id(Kind, Key) ++
find_scoped_references_for_def(Uri, Poi)
find_scoped_references_for_def(Uri, POI)
);
find_references(Uri, Poi = #{kind := Kind, id := Id}) when
find_references(Uri, POI = #{kind := Kind, id := Id}) when
Kind =:= record_expr;
Kind =:= record_field;
Kind =:= macro;
Kind =:= type_application
->
case els_code_navigation:goto_definition(Uri, Poi) of
case els_code_navigation:goto_definition(Uri, POI) of
{ok, [{DefUri, DefPoi}]} ->
find_references(DefUri, DefPoi);
_ ->
Expand Down Expand Up @@ -175,8 +175,8 @@ find_scoped_references_naive(Uri, #{id := Id, kind := Kind}) ->
Refs = els_scope:local_and_includer_pois(Uri, [RefKind]),
MatchingRefs = [
location(U, R)
|| {U, Pois} <- Refs,
#{id := N, range := R} <- Pois,
|| {U, POIs} <- Refs,
#{id := N, range := R} <- POIs,
N =:= Id
],
?LOG_DEBUG(
Expand Down
6 changes: 3 additions & 3 deletions apps/els_lsp/src/els_rename_provider.erl
Original file line number Diff line number Diff line change
Expand Up @@ -299,13 +299,13 @@ changes(Uri, #{kind := function, id := {F, A}}, NewName) ->
]
),
Changes;
changes(Uri, #{kind := DefKind} = DefPoi, NewName) when
changes(Uri, #{kind := DefKind} = DefPOI, NewName) when
DefKind =:= define;
DefKind =:= record;
DefKind =:= record_def_field
->
Self = #{range => editable_range(DefPoi), newText => NewName},
Refs = els_references_provider:find_scoped_references_for_def(Uri, DefPoi),
Self = #{range => editable_range(DefPOI), newText => NewName},
Refs = els_references_provider:find_scoped_references_for_def(Uri, DefPOI),
lists:foldl(
fun(#{uri := U, range := R}, Acc) ->
Change = #{
Expand Down
7 changes: 6 additions & 1 deletion elvis.config
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,12 @@
}},
{elvis_style, no_debug_call, #{ignore => [erlang_ls]}},
{elvis_style, atom_naming_convention, disable},
{elvis_style, state_record_and_type, disable}
{elvis_style, state_record_and_type, disable},
{elvis_style, export_used_types, disable},
{elvis_style, no_throw, disable},
{elvis_style, no_catch_expressions, disable},
{elvis_style, no_block_expressions, disable},
{elvis_style, param_pattern_matching, disable}
],
ignore => [els_dodger, els_typer, els_erlfmt_ast, els_eep48_docs]
},
Expand Down

0 comments on commit 86fd262

Please sign in to comment.