Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add basic linting for .app file #2035

Merged
merged 5 commits into from
Apr 17, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions src/rebar_app_utils.erl
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ validate_application_info(AppInfo, AppDetail) ->
undefined ->
false;
AppFile ->
lint_detail(AppDetail, AppFile),
case proplists:get_value(modules, AppDetail) of
undefined ->
?PRV_ERROR({module_list, AppFile});
Expand All @@ -108,6 +109,36 @@ validate_application_info(AppInfo, AppDetail) ->
end
end.

-spec lint_detail(list(), file:filename_all()) -> ok.
lint_detail(AppDetail, AppFile) ->
lint_description(AppDetail, AppFile),
lint_applications(AppDetail, AppFile).

-spec lint_description(list(), file:filename_all()) -> ok.
lint_description(AppDetail, AppFile) ->
case proplists:get_value(description, AppDetail, "") of
"" -> ?WARN("~p is missing description entry", [AppFile]);
_ -> ok
end.

-spec lint_applications(list(), file:filename_all()) -> ok.
lint_applications(AppDetail, AppFile) ->
case proplists:get_value(applications, AppDetail, []) of
[] -> ?WARN("~p is missing applications entry", [AppFile]);
AppList when is_list(AppList) ->
case lists:member(kernel, AppList) of
false ->
?WARN("~p is missing kernel from applications list", [AppFile]);
true -> ok
end,
case lists:member(stdlib, AppList) of
false ->
?WARN("~p is missing stdlib from applications list", [AppFile]);
true -> ok
end;
_ -> ?WARN("~p requires a list for applications key", [AppFile])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"for applications value" maybe would be clearer

end.

%% @doc parses all dependencies from the root of the project
-spec parse_deps(Dir, Deps, State, Locks, Level) -> [rebar_app_info:t()] when
Dir :: file:filename(),
Expand Down
22 changes: 20 additions & 2 deletions test/rebar_compile_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ all() ->
always_recompile_when_erl_compiler_options_set,
dont_recompile_when_erl_compiler_options_env_does_not_change,
recompile_when_erl_compiler_options_env_changes,
rebar_config_os_var].
rebar_config_os_var,

app_file_linting].

groups() ->
[{basic_app, [], [build_basic_app, paths_basic_app, clean_basic_app]},
Expand Down Expand Up @@ -431,7 +433,6 @@ paths_release_apps(Config) ->
[Vsn1, Vsn2] = ?config(vsns, Config),

{ok, State} = rebar_test_utils:run_and_check(Config, [], ["compile"], return),

code:add_paths(rebar_state:code_paths(State, all_deps)),
ok = application:load(list_to_atom(Name1)),
ok = application:load(list_to_atom(Name2)),
Expand Down Expand Up @@ -2312,6 +2313,23 @@ regex_filter_regression(Config) ->
{ok, [{file, Expected}]}),
ok.

app_file_linting(Config) ->
meck:new(rebar_log, [no_link, passthrough]),
AppDir = ?config(apps, Config),
Name = rebar_test_utils:create_random_name("app_file_linting"),
Vsn = rebar_test_utils:create_random_vsn(),
rebar_test_utils:create_app(AppDir, Name, Vsn, [foo]),

_ = rebar_test_utils:run_and_check(Config, [], ["compile"], return),
History = meck:history(rebar_log),
Warnings = [{Str, Args} || {_, {rebar_log, log, [warn, Str, Args]}, _} <- History],

ct:pal("Warnings Length: ~p", [length(Warnings)]),
ct:pal("Warnings: ~p", [Warnings]),
?assert(none /= proplists:lookup("~p is missing description entry", Warnings)),
?assert(none /= proplists:lookup("~p is missing kernel from applications list", Warnings)),
?assert(none /= proplists:lookup("~p is missing stdlib from applications list", Warnings)).

%%

%% a copy of lib/parsetools/include/yeccpre.hrl so we can test yrl includefile
Expand Down