Skip to content

Commit

Permalink
Format Erlang Service
Browse files Browse the repository at this point in the history
Summary: Add the `format` pragma, format files. No functional changes.

Reviewed By: ir-regular

Differential Revision: D51062328

fbshipit-source-id: fd651fac4a10a07b986285d96e6993bc3fcb20a1
  • Loading branch information
robertoaloi authored and facebook-github-bot committed Nov 7, 2023
1 parent 205b48f commit 654ae55
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 41 deletions.
2 changes: 1 addition & 1 deletion erlang_service/src/erlang_service.app.src
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
%%% LICENSE-MIT file in the root directory of this source tree and the Apache
%%% License, Version 2.0 found in the LICENSE-APACHE file in the root directory
%%% of this source tree.

%%% % @format
{application, erlang_service, [
{description, "Erlang Service"},
{vsn, "0.1.0"},
Expand Down
1 change: 1 addition & 0 deletions erlang_service/src/erlang_service.erl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
%%% LICENSE-MIT file in the root directory of this source tree and the Apache
%%% License, Version 2.0 found in the LICENSE-APACHE file in the root directory
%%% of this source tree.
%%% % @format
-module(erlang_service).

-export([main/1]).
Expand Down
1 change: 1 addition & 0 deletions erlang_service/src/erlang_service_app.erl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
%%% LICENSE-MIT file in the root directory of this source tree and the Apache
%%% License, Version 2.0 found in the LICENSE-APACHE file in the root directory
%%% of this source tree.
%%% % @format
%%==============================================================================
%% Application Callback Module
%%==============================================================================
Expand Down
16 changes: 9 additions & 7 deletions erlang_service/src/erlang_service_ct.erl
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,22 @@
%%% LICENSE-MIT file in the root directory of this source tree and the Apache
%%% License, Version 2.0 found in the LICENSE-APACHE file in the root directory
%%% of this source tree.
%%% % @format
-module(erlang_service_ct).

-export([run/1]).

run([Module, Filename, CompileOptions, ShouldRequestGroups]) ->
{ok, Module, Binary} = compile:file(Filename, [binary|normalize_compile_options(CompileOptions)]),
{ok, Module, Binary} = compile:file(Filename, [binary | normalize_compile_options(CompileOptions)]),
code:load_binary(Module, Filename, Binary),
All = eval(lists:flatten(io_lib:format("~p:all().", [Module]))),
Groups = case ShouldRequestGroups of
true ->
eval(lists:flatten(io_lib:format("~p:groups().", [Module])));
false ->
[]
end,
Groups =
case ShouldRequestGroups of
true ->
eval(lists:flatten(io_lib:format("~p:groups().", [Module])));
false ->
[]
end,
code:delete(Module),
code:purge(Module),
{ok, [{"CT_INFO_ALL", term_to_binary(All)}, {"CT_INFO_GROUPS", term_to_binary(Groups)}]}.
Expand Down
8 changes: 4 additions & 4 deletions erlang_service/src/erlang_service_edoc.erl
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
%%% LICENSE-MIT file in the root directory of this source tree and the Apache
%%% License, Version 2.0 found in the LICENSE-APACHE file in the root directory
%%% of this source tree.
%%% % @format
-module(erlang_service_edoc).

-export([ run/1 ]).
-export([run/1]).

-define(DICT_KEY, edoc_diagnostics).

Expand Down Expand Up @@ -52,7 +53,7 @@ serialize_edoc_diagnostic({Line, Code, Message, Severity}) ->
io_lib:format("~ts ~ts ~tp ~ts", [Code, Severity, Line, Message])
).

-spec get_docs_for_src_file(_FileName, edoc | eep48) -> docs().
-spec get_docs_for_src_file(_FileName, edoc | eep48) -> docs().
get_docs_for_src_file(FileName, Origin) ->
put(?DICT_KEY, []),
case filename:extension(FileName) of
Expand Down Expand Up @@ -115,8 +116,7 @@ fetch_diagnostics_from_dict() ->
% Format used by OTP docs
render_docs_v1(
ModuleName,
{docs_v1, _Anno, _BeamLang, <<"application/erlang+html">> = _Format, _ModuleDoc, _Metadata,
FunctionDocs} =
{docs_v1, _Anno, _BeamLang, <<"application/erlang+html">> = _Format, _ModuleDoc, _Metadata, FunctionDocs} =
DocsV1,
Diagnostics = []
) ->
Expand Down
13 changes: 9 additions & 4 deletions erlang_service/src/erlang_service_error_codes.erl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
%%% LICENSE-MIT file in the root directory of this source tree and the Apache
%%% License, Version 2.0 found in the LICENSE-APACHE file in the root directory
%%% of this source tree.
%%% % @format
-module(erlang_service_error_codes).

-export([make_code/2]).
Expand Down Expand Up @@ -484,25 +485,29 @@ make_code(edoc, "reference to untyped record ~w") ->
"O0030";
make_code(edoc, "'~s' is not allowed - skipping tag, extracting content") ->
"O0031";
make_code(edoc,
make_code(
edoc,
"cannot handle spec with constraints - arity mismatch.\n"
"This is a bug in EDoc spec formatter - please report it at "
"https://bugs.erlang.org/\n"
"Identified arguments: ~p\n"
"Original spec: ~s\n"
) ->
"O0032";
make_code(edoc,
make_code(
edoc,
"cannot annotate spec: "
"function and spec clause numbers do not match\n"
) ->
"O0033";
make_code(edoc,
make_code(
edoc,
"EDoc @spec tags are deprecated. "
"Please use -spec attributes instead."
) ->
"O0034";
make_code(edoc,
make_code(
edoc,
"EDoc @type tags are deprecated. "
"Please use -type attributes instead."
) ->
Expand Down
31 changes: 16 additions & 15 deletions erlang_service/src/erlang_service_lint.erl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
%%% LICENSE-MIT file in the root directory of this source tree and the Apache
%%% License, Version 2.0 found in the LICENSE-APACHE file in the root directory
%%% of this source tree.
%%% % @format
-module(erlang_service_lint).

-export([run/1]).
Expand Down Expand Up @@ -61,10 +62,11 @@ run([FileName, Options0, PostProcess, Deterministic]) ->
ResultAST = PostProcess(AST, FileName),
FormattedErrors = format_errors(Forms3, FileName, Errors),
FormattedWarnings = format_errors(Forms3, FileName, Warnings),
{ok, [{"AST", ResultAST},
{"STUB", ResultStub},
{"ERRORS", FormattedErrors},
{"WARNINGS", FormattedWarnings}
{ok, [
{"AST", ResultAST},
{"STUB", ResultStub},
{"ERRORS", FormattedErrors},
{"WARNINGS", FormattedWarnings}
]}
end;
{error, Reason} ->
Expand All @@ -75,12 +77,13 @@ run([FileName, Options0, PostProcess, Deterministic]) ->
end.

lint_file(Forms, FileName, Options0) ->
Options = case filename:extension(FileName) of
".hrl" ->
[nowarn_unused_function, nowarn_unused_record, nowarn_unused_type|Options0];
_ ->
Options0
end,
Options =
case filename:extension(FileName) of
".hrl" ->
[nowarn_unused_function, nowarn_unused_record, nowarn_unused_type | Options0];
_ ->
Options0
end,
elp_lint:module(Forms, FileName, Options).

epp_module(Options) ->
Expand Down Expand Up @@ -138,8 +141,7 @@ transform(Other, Forms, _Options) ->
Other:parse_transform(Forms, []).

cth_readable_transform({call, Line, {remote, _, {atom, _, ct}, {atom, _, pal}}, Args}) ->
{call, Line, {remote, Line, {atom, Line, cthr}, {atom, Line, pal}},
cth_readable_transform(Args)};
{call, Line, {remote, Line, {atom, Line, cthr}, {atom, Line, pal}}, cth_readable_transform(Args)};
cth_readable_transform(Tuple) when is_tuple(Tuple) ->
list_to_tuple(cth_readable_transform(tuple_to_list(Tuple)));
cth_readable_transform(List) when is_list(List) ->
Expand All @@ -148,8 +150,7 @@ cth_readable_transform(Atomic) ->
Atomic.

vararg_transform({call, Line, {atom, Line2, 'MAKE_FUN'}, Args}) ->
{call, Line, {remote, Line2, {atom, Line2, vararg}, {atom, Line2, 'MAKE_FUN'}},
vararg_transform(Args)};
{call, Line, {remote, Line2, {atom, Line2, vararg}, {atom, Line2, 'MAKE_FUN'}}, vararg_transform(Args)};
vararg_transform(Tuple) when is_tuple(Tuple) ->
list_to_tuple(vararg_transform(tuple_to_list(Tuple)));
vararg_transform(List) when is_list(List) ->
Expand All @@ -165,7 +166,7 @@ format_errors(Forms, OriginalPath, Warnings) ->
Formatted =
lists:flatten([
format_error(Forms, OriginalPath, Path, Warning)
|| {Path, FileWarnings} <- Warnings, Warning <- FileWarnings
|| {Path, FileWarnings} <- Warnings, Warning <- FileWarnings
]),
term_to_binary(Formatted).

Expand Down
22 changes: 12 additions & 10 deletions erlang_service/src/erlang_service_server.erl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
%%% LICENSE-MIT file in the root directory of this source tree and the Apache
%%% License, Version 2.0 found in the LICENSE-APACHE file in the root directory
%%% of this source tree.
%%%
%%% % @format
%%==============================================================================
%% The server responsible for co-ordinating work
%%==============================================================================
Expand All @@ -30,7 +30,7 @@
]).

%% API
-export([ get_docs/3, ct_info/2, elp_lint/4 ]).
-export([get_docs/3, ct_info/2, elp_lint/4]).

%%==============================================================================
%% Includes
Expand Down Expand Up @@ -79,13 +79,14 @@ handle_call(_Request, _From, State) ->
-spec handle_cast(any(), state()) -> {noreply, state()}.
handle_cast({request, Request, Id, Data, AdditionalParams}, #{requests := Requests} = State) ->
Pid = process_request_async(callback_module(Request), Id, Data, AdditionalParams),
Timer = case timeout(Request) of
infinity ->
infinity;
Timeout ->
erlang:send_after(Timeout, ?SERVER, {timeout, Pid})
end,
{noreply, State#{requests => [{Pid, Id, Timer}|Requests]}};
Timer =
case timeout(Request) of
infinity ->
infinity;
Timeout ->
erlang:send_after(Timeout, ?SERVER, {timeout, Pid})
end,
{noreply, State#{requests => [{Pid, Id, Timer} | Requests]}};
handle_cast({result, Id, Result}, #{io := IO, requests := Requests} = State) ->
case lists:keytake(Id, 2, Requests) of
{value, {Pid, Id, infinity}, NewRequests} ->
Expand Down Expand Up @@ -159,7 +160,8 @@ process_request_async(Module, Id, Data, AdditionalParams) ->
ExceptionData = unicode:characters_to_binary(Formatted),
gen_server:cast(?SERVER, {exception, Id, ExceptionData})
end
end).
end
).

callback_module(get_docs) -> erlang_service_edoc;
callback_module(ct_info) -> erlang_service_ct;
Expand Down
1 change: 1 addition & 0 deletions erlang_service/src/erlang_service_sup.erl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
%%% LICENSE-MIT file in the root directory of this source tree and the Apache
%%% License, Version 2.0 found in the LICENSE-APACHE file in the root directory
%%% of this source tree.
%%% % @format
%%==============================================================================
%% Top Level Supervisor
%%==============================================================================
Expand Down

0 comments on commit 654ae55

Please sign in to comment.