From 4d893f123c462e175e717d80dd356d42c570b82f Mon Sep 17 00:00:00 2001 From: Justin Wood Date: Mon, 18 Mar 2019 23:51:20 -0400 Subject: Add basic linting for .app file This currently just checks for the existence of the description and applications keys and that the applications list has kernel and stdlib in it. --- src/rebar_app_utils.erl | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/rebar_app_utils.erl b/src/rebar_app_utils.erl index 5fe5ba6..037bf9d 100644 --- a/src/rebar_app_utils.erl +++ b/src/rebar_app_utils.erl @@ -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}); @@ -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]) + 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(), -- cgit v1.1 From 39895a78f3508367c85daaf7ae6f749aae368e8d Mon Sep 17 00:00:00 2001 From: Justin Wood Date: Thu, 4 Apr 2019 15:31:20 -0400 Subject: test for app file linting --- test/rebar_compile_SUITE.erl | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/test/rebar_compile_SUITE.erl b/test/rebar_compile_SUITE.erl index 0bc3ad0..dfbbc80 100644 --- a/test/rebar_compile_SUITE.erl +++ b/test/rebar_compile_SUITE.erl @@ -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]}, @@ -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)), @@ -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 -- cgit v1.1 From 1fa0503fc93b3411f42ebb58d197f4a060f40631 Mon Sep 17 00:00:00 2001 From: Justin Wood Date: Tue, 16 Apr 2019 12:43:05 -0400 Subject: Change wording in application linting to be more clear --- src/rebar_app_utils.erl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rebar_app_utils.erl b/src/rebar_app_utils.erl index 037bf9d..951bc1d 100644 --- a/src/rebar_app_utils.erl +++ b/src/rebar_app_utils.erl @@ -136,7 +136,7 @@ lint_applications(AppDetail, AppFile) -> ?WARN("~p is missing stdlib from applications list", [AppFile]); true -> ok end; - _ -> ?WARN("~p requires a list for applications key", [AppFile]) + _ -> ?WARN("~p requires a list for applications value", [AppFile]) end. %% @doc parses all dependencies from the root of the project -- cgit v1.1 From 60d6e0bb6b422cd1f40ba4ab406b47fb47abacfc Mon Sep 17 00:00:00 2001 From: Justin Wood Date: Tue, 16 Apr 2019 12:57:45 -0400 Subject: Remove debugging --- test/rebar_compile_SUITE.erl | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/rebar_compile_SUITE.erl b/test/rebar_compile_SUITE.erl index dfbbc80..44f20d7 100644 --- a/test/rebar_compile_SUITE.erl +++ b/test/rebar_compile_SUITE.erl @@ -2324,8 +2324,6 @@ app_file_linting(Config) -> 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)). -- cgit v1.1 From cb881390dce42dab63f18dba59eddd1e4990b969 Mon Sep 17 00:00:00 2001 From: Justin Wood Date: Tue, 16 Apr 2019 12:58:14 -0400 Subject: An empty list on applications key should not be treated as missing --- src/rebar_app_utils.erl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rebar_app_utils.erl b/src/rebar_app_utils.erl index 951bc1d..bb706fd 100644 --- a/src/rebar_app_utils.erl +++ b/src/rebar_app_utils.erl @@ -123,8 +123,8 @@ lint_description(AppDetail, AppFile) -> -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]); + case proplists:get_value(applications, AppDetail) of + undefined -> ?WARN("~p is missing applications entry", [AppFile]); AppList when is_list(AppList) -> case lists:member(kernel, AppList) of false -> -- cgit v1.1