Skip to content

Commit

Permalink
Merge pull request #511 from inaka/491-otp-naming-conventions
Browse files Browse the repository at this point in the history
[#491] Update elvis_core with correct OTP naming
  • Loading branch information
elbrujohalcon authored Mar 30, 2020
2 parents 866210b + a513b14 commit c55c59b
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 70 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
dist: trusty
sudo: false
language: erlang
otp_release:
Expand Down
7 changes: 2 additions & 5 deletions rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,9 @@

%% == Dependencies ==

{deps, [ {elvis, "0.4.2", {pkg, elvis_core}}
{deps, [ {elvis_core, "0.6.0"}
, {getopt, "1.0.1"}
, {egithub, "0.5.7"}
, {katana_code, "0.1.2"}
, {egithub, "0.6.0"}
]}.

%% == Dialyzer ==
Expand All @@ -80,5 +79,3 @@

{escript_main_app, elvis}.
{escript_name, "elvis"}.
% Needed because the script refers to elvis folder instead elvis_shell
{escript_incl_apps, [elvis_shell]}.
32 changes: 15 additions & 17 deletions rebar.lock
Original file line number Diff line number Diff line change
@@ -1,38 +1,36 @@
{"1.1.0",
[{<<"aleppo">>,{pkg,<<"inaka_aleppo">>,<<"1.1.1">>},1},
{<<"certifi">>,{pkg,<<"certifi">>,<<"2.5.1">>},2},
{<<"egithub">>,{pkg,<<"egithub">>,<<"0.5.7">>},0},
{<<"elvis">>,{pkg,<<"elvis_core">>,<<"0.4.2">>},0},
[{<<"certifi">>,{pkg,<<"certifi">>,<<"2.5.1">>},2},
{<<"egithub">>,{pkg,<<"egithub">>,<<"0.6.0">>},0},
{<<"elvis_core">>,{pkg,<<"elvis_core">>,<<"0.6.0">>},0},
{<<"getopt">>,{pkg,<<"getopt">>,<<"1.0.1">>},0},
{<<"goldrush">>,{pkg,<<"goldrush">>,<<"0.1.9">>},1},
{<<"hackney">>,{pkg,<<"hackney">>,<<"1.15.1">>},1},
{<<"hackney">>,{pkg,<<"hackney">>,<<"1.15.2">>},1},
{<<"idna">>,{pkg,<<"idna">>,<<"6.0.0">>},2},
{<<"jiffy">>,{pkg,<<"jiffy">>,<<"1.0.1">>},1},
{<<"katana_code">>,{pkg,<<"katana_code">>,<<"0.1.2">>},0},
{<<"lager">>,{pkg,<<"lager">>,<<"3.7.0">>},1},
{<<"jsx">>,{pkg,<<"jsx">>,<<"2.10.0">>},1},
{<<"katana_code">>,{pkg,<<"katana_code">>,<<"0.2.1">>},1},
{<<"lager">>,{pkg,<<"lager">>,<<"3.8.0">>},1},
{<<"metrics">>,{pkg,<<"metrics">>,<<"1.0.1">>},2},
{<<"mimerl">>,{pkg,<<"mimerl">>,<<"1.2.0">>},2},
{<<"parse_trans">>,{pkg,<<"parse_trans">>,<<"3.3.0">>},3},
{<<"ssl_verify_fun">>,{pkg,<<"ssl_verify_fun">>,<<"1.1.4">>},2},
{<<"ssl_verify_fun">>,{pkg,<<"ssl_verify_fun">>,<<"1.1.5">>},2},
{<<"unicode_util_compat">>,{pkg,<<"unicode_util_compat">>,<<"0.4.1">>},3},
{<<"zipper">>,{pkg,<<"zipper">>,<<"1.0.1">>},1}]}.
[
{pkg_hash,[
{<<"aleppo">>, <<"B0F7D05A118C5EBC3A735D68E92A7BD5837FE53455495EDE37CF0AA8BA4912E3">>},
{<<"certifi">>, <<"867CE347F7C7D78563450A18A6A28A8090331E77FA02380B4A21962A65D36EE5">>},
{<<"egithub">>, <<"55863E5778F985E89CA341F048F77AC6C6F6B1D9A40F11F49D4DEDBEEA3B454F">>},
{<<"elvis">>, <<"ED5D861A38493B7750427DAECFE0D844001E017C9DBC1F7F8DE302DB6226BC24">>},
{<<"egithub">>, <<"5E323E8693652B17558D7C1F82ED8CE3472AC07A06C65D567813AFA4FBAADE13">>},
{<<"elvis_core">>, <<"178B7EE3486936911B95165613651251A35144FF1CBEC41967AB22FFC7872AF9">>},
{<<"getopt">>, <<"C73A9FA687B217F2FF79F68A3B637711BB1936E712B521D8CE466B29CBF7808A">>},
{<<"goldrush">>, <<"F06E5D5F1277DA5C413E84D5A2924174182FB108DABB39D5EC548B27424CD106">>},
{<<"hackney">>, <<"9F8F471C844B8CE395F7B6D8398139E26DDCA9EBC171A8B91342EE15A19963F4">>},
{<<"hackney">>, <<"07E33C794F8F8964EE86CEBEC1A8ED88DB5070E52E904B8F12209773C1036085">>},
{<<"idna">>, <<"689C46CBCDF3524C44D5F3DDE8001F364CD7608A99556D8FBD8239A5798D4C10">>},
{<<"jiffy">>, <<"4F25639772CA41202F41BA9C8F6CA0933554283DD4742C90651E03471C55E341">>},
{<<"katana_code">>, <<"347D42D5E89AC6C4BF8D02B64633AC1BFE14B7724B5910260D39EFEAFE737F01">>},
{<<"lager">>, <<"563AB17CD32134A3DD17EC3B3622E6D8F827506AA4F8C489158879BED87D980B">>},
{<<"jsx">>, <<"77760560D6AC2B8C51FD4C980E9E19B784016AA70BE354CE746472C33BEB0B1C">>},
{<<"katana_code">>, <<"B2195859DF57D8BEBF619A9FD3327CD7D01563A98417156D0F4C5FAB435F2630">>},
{<<"lager">>, <<"3402B9A7E473680CA179FC2F1D827CAB88DD37DD1E6113090C6F45EF05228A1C">>},
{<<"metrics">>, <<"25F094DEA2CDA98213CECC3AEFF09E940299D950904393B2A29D191C346A8486">>},
{<<"mimerl">>, <<"67E2D3F571088D5CFD3E550C383094B47159F3EEE8FFA08E64106CDF5E981BE3">>},
{<<"parse_trans">>, <<"09765507A3C7590A784615CFD421D101AEC25098D50B89D7AA1D66646BC571C1">>},
{<<"ssl_verify_fun">>, <<"F0EAFFF810D2041E93F915EF59899C923F4568F4585904D010387ED74988E77B">>},
{<<"ssl_verify_fun">>, <<"6EAF7AD16CB568BB01753DBBD7A95FF8B91C7979482B95F38443FE2C8852A79B">>},
{<<"unicode_util_compat">>, <<"D869E4C68901DD9531385BB0C8C40444EBF624E60B6962D95952775CAC5E90CD">>},
{<<"zipper">>, <<"3CCB4F14B97C06B2749B93D8B6C204A1ECB6FAFC6050CACC3B93B9870C05952A">>}]}
].
24 changes: 24 additions & 0 deletions src/elvis.app.src
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{ application, elvis
, [ {pkg_name, elvis}
, {description, "CLI for the Elvis Erlang Style Reviewer"}
, {vsn, "0.4.2"}
, { applications
, [kernel, stdlib, ssl, elvis_core, egithub, katana_code, getopt]
}
, { modules
, [ elvis
, elvis_git
, elvis_webhook
]
}
, {registered, []}
, {maintainers, ["Inaka"]}
, {licenses, ["Apache 2.0"]}
, { links
, [ {"Github", "https://github.com/inaka/elvis"}
, {"Blog", "http://inaka.net/blog/2014/09/05/erlang-standards-and-elvis-rock/"}
]
}
, {build_tools, ["rebar3"]}
]
}.
51 changes: 34 additions & 17 deletions src/elvis.erl
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@

%% Public API

-export([main/1]).
-export([ main/1
, default_config/0
]).

-export([start/0]).

-define(APP_NAME, "elvis").
-define(DEFAULT_CONFIG_PATH, "./elvis.config").
-define(DEFAULT_REBAR_CONFIG_PATH, "./rebar.config").

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Public API
Expand All @@ -15,22 +19,22 @@
%% @doc Used when starting the application on the shell.
-spec start() -> ok.
start() ->
{ok, _} = application:ensure_all_started(elvis_shell),
{ok, _} = application:ensure_all_started(elvis),
ok.

-spec main(string()) -> ok.
main(Args) ->
%% Load the application to be able to access its information
%% (e.g. --version option)
ok =
case application:load(elvis_shell) of
case application:load(elvis) of
ok -> ok;
{error, {already_loaded, elvis_shell}} -> ok
{error, {already_loaded, elvis}} -> ok
end,
ok =
case application:load(elvis) of
case application:load(elvis_core) of
ok -> ok;
{error, {already_loaded, elvis}} -> ok
{error, {already_loaded, elvis_core}} -> ok
end,
OptSpecList = option_spec_list(),
case getopt:parse(OptSpecList, Args) of
Expand Down Expand Up @@ -88,7 +92,7 @@ option_spec_list() ->
-spec process_options([atom()], [string()]) -> ok.
process_options(Options, Commands) ->
try
Config = elvis_config:default(),
Config = default_config(),
AtomCommands = lists:map(fun list_to_atom/1, Commands),
process_options(Options, AtomCommands, Config)
catch
Expand All @@ -103,22 +107,22 @@ process_options([help | Opts], Cmds, Config) ->
help(),
process_options(Opts, Cmds, Config);
process_options([{config, Path} | Opts], Cmds, _) ->
Config = elvis_config:load_file(Path),
Config = elvis_config:from_file(Path),
process_options(Opts, Cmds, Config);
process_options([commands | Opts], Cmds, Config) ->
commands(),
process_options(Opts, Cmds, Config);
process_options([{output_format, Format} | Opts], Cmds, Config) ->
ok = application:set_env(elvis, output_format, list_to_atom(Format)),
ok = application:set_env(elvis_core, output_format, list_to_atom(Format)),
process_options(Opts, Cmds, Config);
process_options([keep_rocking | Opts], Cmds, Config) ->
ok = application:set_env(elvis, keep_rocking, true),
ok = application:set_env(elvis_core, keep_rocking, true),
process_options(Opts, Cmds, Config);
process_options([quiet | Opts], Cmds, Config) ->
ok = application:set_env(elvis, no_output, true),
ok = application:set_env(elvis_core, no_output, true),
process_options(Opts, Cmds, Config);
process_options([verbose | Opts], Cmds, Config) ->
ok = application:set_env(elvis, verbose, true),
ok = application:set_env(elvis_core, verbose, true),
process_options(Opts, Cmds, Config);
process_options([version | Opts], Cmds, Config) ->
version(),
Expand All @@ -131,7 +135,7 @@ process_options([{parallel, Num} | Opts], Cmds, Config) ->
"auto" -> erlang:system_info(schedulers);
_ -> erlang:list_to_integer(Num)
end,
ok = application:set_env(elvis, parallel, N),
ok = application:set_env(elvis_core, parallel, N),
process_options(Opts, Cmds, Config);
process_options([], Cmds, Config) ->
process_commands(Cmds, Config).
Expand Down Expand Up @@ -199,8 +203,8 @@ install git-hook

-spec version() -> ok.
version() ->
{ok, ElvisCoreAppConfig} = application:get_all_key(elvis),
{ok, ElvisShellAppConfig} = application:get_all_key(elvis_shell),
{ok, ElvisCoreAppConfig} = application:get_all_key(elvis_core),
{ok, ElvisShellAppConfig} = application:get_all_key(elvis),
ElvisCoreVsn = proplists:get_value(vsn, ElvisCoreAppConfig),
ElvisShellVsn = proplists:get_value(vsn, ElvisShellAppConfig),
Version = " ______ _ \n"
Expand All @@ -211,14 +215,27 @@ version() ->
"Elvis Core Version: ~s\n",
io:format(Version, [ElvisShellVsn, ElvisCoreVsn]).


rock_one_song(FileName, Config) ->
F = atom_to_list(FileName),
case elvis_core:rock_this(F, Config) of
{fail, _} ->
case application:get_env(elvis, keep_rocking, false) of
case application:get_env(elvis_core, keep_rocking, false) of
false -> elvis_utils:erlang_halt(1);
true -> ok
end;
ok -> ok
end.

-spec default_config() -> elvis_config:config().
default_config() ->
try elvis_config:from_file(?DEFAULT_CONFIG_PATH) of
Config -> Config
catch _:_ -> do_default_config()
end.

-spec do_default_config() -> elvis_config:config().
do_default_config() ->
try elvis_config:from_rebar(?DEFAULT_REBAR_CONFIG_PATH) of
Config -> Config
catch _:_ -> application:get_env(elvis, config, [])
end.
22 changes: 0 additions & 22 deletions src/elvis_shell.app.src

This file was deleted.

5 changes: 3 additions & 2 deletions src/elvis_webhook.erl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ handle_pull_request(Cred, Data, GithubFiles) ->
maps_get([<<"pull_request">>, <<"head">>, <<"ref">>], Data, <<"master">>),
Repo = binary_to_list(maps:get(<<"full_name">>, Repository)),
Branch = binary_to_list(BranchName),
Config = repo_config(Cred, Repo, Branch, elvis_config:default()),
Config = repo_config(Cred, Repo, Branch, elvis:default_config()),

GithubFiles1 = [F#{path => Path}
|| F = #{<<"filename">> := Path} <- GithubFiles],
Expand Down Expand Up @@ -97,7 +97,8 @@ repo_config(Cred, Repo, Branch, LocalConfig) ->
case egithub:file_content(Cred, Repo, Branch, "elvis.config") of
{ok, ConfigContent} ->
ConfigEval = ktn_code:eval(ConfigContent),
elvis_config:load(ConfigEval);
ElvisConfig = proplists:get_value(elvis, ConfigEval),
proplists:get_value(config, ElvisConfig);
{error, _} ->
LocalConfig
end.
Expand Down
4 changes: 2 additions & 2 deletions test/elvis_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ all() ->

-spec init_per_suite(config()) -> config().
init_per_suite(Config) ->
_ = application:start(elvis_shell),
_ = application:start(elvis),
Config.

-spec end_per_suite(config()) -> config().
end_per_suite(Config) ->
ok = application:stop(elvis_shell),
ok = application:stop(elvis),
Config.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Expand Down
10 changes: 5 additions & 5 deletions test/elvis_meta_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ all() -> [dialyzer, xref, elvis].

-spec dialyzer(config()) -> {comment, []}.
dialyzer(_Config) ->
BaseDir = code:lib_dir(elvis_shell),
BaseDir = code:lib_dir(elvis),
DefaultRebar3PltLoc = filename:join(BaseDir, "../../../default"),
Plts = filelib:wildcard(filename:join(DefaultRebar3PltLoc, "*_plt")),
Dirs = [filename:join(BaseDir, Dir) || Dir <- ["ebin", "test"]],
Expand All @@ -29,7 +29,7 @@ dialyzer(_Config) ->

-spec xref(config()) -> {comment, []}.
xref(_Config) ->
BaseDir = code:lib_dir(elvis_shell),
BaseDir = code:lib_dir(elvis),
Dirs = [filename:join(BaseDir, Dir) || Dir <- ["ebin", "test"]],
XrefConfig = #{ dirs => Dirs
, xref_defaults =>
Expand All @@ -50,14 +50,14 @@ xref(_Config) ->

-spec elvis(config()) -> {comment, []}.
elvis(_Config) ->
BaseDir = code:lib_dir(elvis_shell),
BaseDir = code:lib_dir(elvis),
ConfigFile = filename:join(BaseDir, "../../../../elvis.config"),
ElvisConfig = [ fix_dirs(Group)
|| Group <- elvis_config:load_file(ConfigFile)],
|| Group <- elvis_config:from_file(ConfigFile)],
ct:comment("Elvis rocks!"),
ok = elvis_core:rock(ElvisConfig),
{comment, ""}.

fix_dirs(#{dirs := Dirs} = Group) ->
NewDirs = [filename:join(code:lib_dir(elvis_shell), Dir) || Dir <- Dirs],
NewDirs = [filename:join(code:lib_dir(elvis), Dir) || Dir <- Dirs],
Group#{dirs := NewDirs}.

0 comments on commit c55c59b

Please sign in to comment.