diff options
author | Fred Hebert <mononcqc@ferd.ca> | 2019-04-16 20:10:52 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-04-16 20:10:52 -0400 |
commit | 45aaba22b405b222fd28e46c625748a99a53cff3 (patch) | |
tree | ba1ef877ddf38a6f5844146e47f4e2f789ab911b | |
parent | 14928247cda69d953e673ed6b5feb6ff679a2dfc (diff) | |
parent | cb881390dce42dab63f18dba59eddd1e4990b969 (diff) |
Merge pull request #2035 from ankhers/lint_app_file
Add basic linting for .app file
-rw-r--r-- | src/rebar_app_utils.erl | 31 | ||||
-rw-r--r-- | test/rebar_compile_SUITE.erl | 20 |
2 files changed, 49 insertions, 2 deletions
diff --git a/src/rebar_app_utils.erl b/src/rebar_app_utils.erl index 0ea6ad8..91c095c 100644 --- a/src/rebar_app_utils.erl +++ b/src/rebar_app_utils.erl @@ -101,6 +101,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}); @@ -109,6 +110,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 + undefined -> ?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 value", [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(), diff --git a/test/rebar_compile_SUITE.erl b/test/rebar_compile_SUITE.erl index 0bc3ad0..44f20d7 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,21 @@ 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], + + ?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 |