diff --git a/README.md b/README.md index 107e898..db3b6f7 100644 --- a/README.md +++ b/README.md @@ -59,8 +59,8 @@ depending on your preferred shell. ## Usage -The most common use case is to `cd` into a folder containing an `elvis.config` file -and executing `elvis rock`. +The most common use case is to `cd` into a folder (containing an `elvis.config` file, or not - +in which case some sane defaults apply) and execute `elvis rock`. If you just execute `elvis` with no arguments or options you'll get to the usage instructions outlined in this README. @@ -97,7 +97,7 @@ in the configuration (i.e. either `elvis.config` or the path set by option `--co ### `--config ` (`-c `) -Allows providing the path to the config. file (by default `elvis.config` is assumed). +Allows providing the path to the configuration file (by default `elvis.config` is assumed). ### `--help` (`-h`) diff --git a/config/elvis-test.config b/config/elvis-test.config index 74465bb..a711af3 100644 --- a/config/elvis-test.config +++ b/config/elvis-test.config @@ -7,17 +7,9 @@ filter => "*.erl", ruleset => erl_files }, - #{dirs => ["../.."], - filter => "Makefile", - ruleset => makefiles - }, #{dirs => ["../.."], filter => "rebar.config", ruleset => rebar_config - }, - #{dirs => ["../.."], - filter => "elvis.config", - ruleset => elvis_config } ] } diff --git a/config/elvis.config b/config/elvis.config index 74c730c..04f7b2f 100644 --- a/config/elvis.config +++ b/config/elvis.config @@ -7,17 +7,9 @@ filter => "*.erl", ruleset => erl_files }, - #{dirs => ["."], - filter => "Makefile", - ruleset => makefiles - }, #{dirs => ["."], filter => "rebar.config", ruleset => rebar_config - }, - #{dirs => ["."], - filter => "elvis.config", - ruleset => elvis_config } ] } diff --git a/config/test.config b/config/test.config index d55bf42..d298ab6 100644 --- a/config/test.config +++ b/config/test.config @@ -7,17 +7,9 @@ filter => "**.erl", ruleset => erl_files }, - #{dirs => ["."], - filter => "Makefile", - ruleset => makefiles - }, - #{dirs => ["."], + #{dirs => ["../.."], filter => "rebar.config", ruleset => rebar_config - }, - #{dirs => ["."], - filter => "elvis.config", - ruleset => elvis_config } ] }, diff --git a/elvis.config b/elvis.config index 971053a..320e854 100644 --- a/elvis.config +++ b/elvis.config @@ -5,7 +5,4 @@ ruleset => erl_files}, #{dirs => ["."], filter => "rebar.config", - ruleset => rebar_config}, - #{dirs => ["."], - filter => "elvis.config", - ruleset => elvis_config}]}]}]. + ruleset => rebar_config}]}]}]. diff --git a/rebar.config b/rebar.config index 41a226f..5ccdf8d 100644 --- a/rebar.config +++ b/rebar.config @@ -24,7 +24,11 @@ %% == Dependencies and plugins == -{deps, [{elvis_core, "4.1.1"}, {getopt, "1.0.3"}, {egithub, "0.7.0"}]}. +{deps, + [{elvis_core, + {git, "https://github.com/inaka/elvis_core.git", {branch, "fix/config-parse-validate"}}}, + {getopt, "1.0.3"}, + {egithub, "0.7.0"}]}. {project_plugins, [{rebar3_hank, "~> 1.4.1"}, @@ -36,7 +40,7 @@ {ex_doc, [{source_url, <<"https://github.com/inaka/elvis">>}, - {extras, [<<"README.md">>, <<"LICENSE">>]}, + {extras, [<<"README.md">>, <<"LICENSE">>, <<"CONTRIBUTING.md">>]}, {main, <<"README.md">>}, {prefix_ref_vsn_with_v, false}, {api_reference, false}]}. diff --git a/rebar.lock b/rebar.lock index 990854c..9b7943e 100644 --- a/rebar.lock +++ b/rebar.lock @@ -1,7 +1,10 @@ {"1.2.0", [{<<"certifi">>,{pkg,<<"certifi">>,<<"2.15.0">>},2}, {<<"egithub">>,{pkg,<<"egithub">>,<<"0.7.0">>},0}, - {<<"elvis_core">>,{pkg,<<"elvis_core">>,<<"4.1.1">>},0}, + {<<"elvis_core">>, + {git,"https://github.com/inaka/elvis_core.git", + {ref,"5ae29ef4f9361fd8232a77a037a977ad8b7dc736"}}, + 0}, {<<"getopt">>,{pkg,<<"getopt">>,<<"1.0.3">>},0}, {<<"goldrush">>,{pkg,<<"goldrush">>,<<"0.1.9">>},1}, {<<"hackney">>,{pkg,<<"hackney">>,<<"1.17.1">>},1}, @@ -19,7 +22,6 @@ {pkg_hash,[ {<<"certifi">>, <<"0E6E882FCDAAA0A5A9F2B3DB55B1394DBA07E8D6D9BCAD08318FB604C6839712">>}, {<<"egithub">>, <<"CFF720B2ADE8A0528B8861D2309339FD3C1C289B9BCB9E498FF77C619CE28AF2">>}, - {<<"elvis_core">>, <<"0F69E9F1512C1EA68C65ABC805079DC3A5B22E0E16E0DE8DDDBB780A43D007A9">>}, {<<"getopt">>, <<"4F3320C1F6F26B2BEC0F6C6446B943EB927A1E6428EA279A1C6C534906EE79F1">>}, {<<"goldrush">>, <<"F06E5D5F1277DA5C413E84D5A2924174182FB108DABB39D5EC548B27424CD106">>}, {<<"hackney">>, <<"08463F93D2CC1A03817BF28D8DAE6021543F773BD436C9377047224856C4422C">>}, @@ -36,7 +38,6 @@ {pkg_hash_ext,[ {<<"certifi">>, <<"B147ED22CE71D72EAFDAD94F055165C1C182F61A2FF49DF28BCC71D1D5B94A60">>}, {<<"egithub">>, <<"E009CE11EFD8008D0F9ED59D9C488E3E9ABE302A0F2CD6D663E4CC26756FCC4C">>}, - {<<"elvis_core">>, <<"80A562574B8D974A2E7544E9A9455716D04C9E095DBC8C8915E2468031DD1385">>}, {<<"getopt">>, <<"7E01DE90AC540F21494FF72792B1E3162D399966EBBFC674B4CE52CB8F49324F">>}, {<<"goldrush">>, <<"99CB4128CFFCB3227581E5D4D803D5413FA643F4EB96523F77D9E6937D994CEB">>}, {<<"hackney">>, <<"D2CBA9E3C8103AD0320623E9F1C33E8D378A15EAABE2EE8AE441898F3D35A18C">>}, diff --git a/src/elvis.app.src b/src/elvis.app.src index dcf341e..55a0a9e 100644 --- a/src/elvis.app.src +++ b/src/elvis.app.src @@ -5,17 +5,6 @@ {vsn, git}, {applications, [kernel, stdlib, ssl, elvis_core, egithub, katana_code, getopt]}, {modules, [elvis, elvis_git, elvis_webhook]}, - {env, - [{config, - [#{dirs => ["apps/**", "lib/**", "src/**", "test/**"], - filter => "*.erl", - ruleset => erl_files}, - #{dirs => ["."], - filter => "Makefile", - ruleset => makefiles}, - #{dirs => [".", "apps/**", "lib/**", "src/**"], - filter => "rebar.config", - ruleset => rebar_config}]}]}, {registered, []}, {licenses, ["Apache 2.0"]}, {links, diff --git a/src/elvis.erl b/src/elvis.erl index 6d4e153..e0c8d3c 100644 --- a/src/elvis.erl +++ b/src/elvis.erl @@ -8,10 +8,6 @@ -export([start/0]). --define(APP_NAME, "elvis"). --define(DEFAULT_CONFIG_PATH, "./elvis.config"). --define(DEFAULT_REBAR_CONFIG_PATH, "./rebar.config"). - -type option() :: commands | help | @@ -61,7 +57,7 @@ main(Args) -> {ok, {Options, Commands}} -> process_options(Options, Commands); {error, {Reason, Data}} -> - elvis_utils:error_prn("~s ~p~n", [Reason, Data]), + elvis_utils:error("~s ~p~n", [Reason, Data]), help(), elvis_utils:erlang_halt(1) end. @@ -110,12 +106,12 @@ process_options(Options, Commands) -> process_options(Options, AtomCommands, Config) catch _:Exception -> - elvis_utils:error_prn("~p.", [Exception]), + elvis_utils:error("~p.", [Exception]), elvis_utils:erlang_halt(1) end. %% @private --spec process_options([option()], [string()], elvis_config:configs()) -> ok. +-spec process_options([option()], [string()], [elvis_config:t()]) -> ok. process_options([help | Opts], Cmds, Config) -> help(), process_options(Opts, Cmds, Config); @@ -126,16 +122,16 @@ 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_core, output_format, list_to_atom(Format)), + ok = elvis_config:set_output_format(list_to_atom(Format)), process_options(Opts, Cmds, Config); process_options([keep_rocking | Opts], Cmds, Config) -> - ok = application:set_env(elvis_core, keep_rocking, true), + ok = application:set_env(elvis, keep_rocking, true), process_options(Opts, Cmds, Config); process_options([quiet | Opts], Cmds, Config) -> - ok = application:set_env(elvis_core, no_output, true), + ok = elvis_config:set_no_output(true), process_options(Opts, Cmds, Config); process_options([verbose | Opts], Cmds, Config) -> - ok = application:set_env(elvis_core, verbose, true), + ok = elvis_config:set_verbose(true), process_options(Opts, Cmds, Config); process_options([version | Opts], Cmds, Config) -> version(), @@ -150,7 +146,7 @@ process_options([{parallel, Num} | Opts], Cmds, Config) -> _ -> erlang:list_to_integer(Num) end, - ok = application:set_env(elvis_core, parallel, N), + ok = elvis_config:set_parallel(N), process_options(Opts, Cmds, Config); process_options([], Cmds, Config) -> process_commands(Cmds, Config). @@ -162,7 +158,7 @@ process_options([], Cmds, Config) -> 'git-hook' | 'git-branch' | string()], - elvis_config:configs()) -> + [elvis_config:t()]) -> ok. process_commands([rock | Files], Config) -> case Files of @@ -199,10 +195,10 @@ process_commands([_Cmd | _Cmds], _Config) -> -spec help() -> ok. help() -> OptSpecList = option_spec_list(), - getopt:usage(OptSpecList, ?APP_NAME, standard_io). + getopt:usage(OptSpecList, "elvis", standard_io). %% @private --spec help(elvis_config:configs()) -> elvis_config:configs(). +-spec help([elvis_config:t()]) -> [elvis_config:t()]. help(Config) -> help(), Config. @@ -250,7 +246,7 @@ rock_one_song(FileName, Config) -> F = atom_to_list(FileName), case elvis_core:rock_this(F, Config) of {fail, _} -> - case application:get_env(elvis_core, keep_rocking, false) of + case application:get_env(elvis, keep_rocking, false) of false -> elvis_utils:erlang_halt(1); true -> @@ -260,27 +256,15 @@ rock_one_song(FileName, Config) -> ok end. -%% @private --spec default_config() -> elvis_config:configs(). +-spec default_config() -> [elvis_config:t()]. default_config() -> - default_config([fun() -> elvis_config:from_file(?DEFAULT_CONFIG_PATH) end, - fun() -> elvis_config:from_rebar(?DEFAULT_REBAR_CONFIG_PATH) end]). - --spec default_config([Fun]) -> elvis_config:configs() - when Fun :: fun(() -> elvis_config:config()). -default_config([Fun | Funs]) -> - Config = - try - Fun() - catch - _:_ -> - [] - end, - case Config of - [] -> - default_config(Funs); + case elvis_config:config() of + {fail, [{throw, {invalid_config, _}}]} -> + % When we implement warnings_as_errors, where the default is false, + % replace the next line with elvis_config:default() alone + % Maybe think about making this the default for `elvis_config:config()` + % with an output notice + application:get_env(elvis, config, elvis_config:default()); Config -> Config - end; -default_config([]) -> - application:get_env(elvis, config, []). + end. diff --git a/src/elvis_git.erl b/src/elvis_git.erl index b947d31..218e35e 100644 --- a/src/elvis_git.erl +++ b/src/elvis_git.erl @@ -12,7 +12,7 @@ %%% Public %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --spec run_hook(elvis_config:configs()) -> ok. +-spec run_hook([elvis_config:t()]) -> ok. run_hook(Config) -> Files = elvis_git:staged_files(), NewConfig = elvis_config:resolve_files(Config, Files), @@ -23,7 +23,7 @@ run_hook(Config) -> ok end. --spec run_branch(string(), elvis_config:configs()) -> ok. +-spec run_branch(string(), [elvis_config:t()]) -> ok. run_branch(Commit, Config) -> Files = elvis_git:branch_files(Commit), NewConfig = elvis_config:resolve_files(Config, Files), @@ -34,11 +34,11 @@ run_branch(Commit, Config) -> ok end. --spec branch_files(string()) -> [elvis_file:file()]. +-spec branch_files(string()) -> [elvis_file:t()]. branch_files(Commit) -> process_files(?LIST_BRANCH_CHANGES(Commit)). --spec staged_files() -> [elvis_file:file()]. +-spec staged_files() -> [elvis_file:t()]. staged_files() -> process_files(?LIST_STAGED). @@ -49,7 +49,7 @@ process_files(Cmd) -> Paths = [binary_to_list(Path) || Path <- Lines, byte_size(Path) > 0], lists:map(fun elvis_file/1, Paths). --spec elvis_file(string()) -> elvis_file:file(). +-spec elvis_file(string()) -> elvis_file:t(). elvis_file(Path) -> #{path => Path}. @@ -79,11 +79,10 @@ install_hook() -> check_git_dir(), ok = filelib:ensure_dir(?PRE_COMMIT_FILE), _ = add_pre_commit_hook(), - elvis_utils:info("Elvis pre-commit hook installed. " - "Wop-bop-a-loom-a-blop-bam-boom!") + elvis_utils:info("Elvis pre-commit hook installed. Wop-bop-a-loom-a-blop-bam-boom!", []) catch _:Reason -> - elvis_utils:error_prn(Reason) + elvis_utils:error(Reason, []) end. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% diff --git a/test/elvis_meta_SUITE.erl b/test/elvis_meta_SUITE.erl deleted file mode 100644 index ec26cc9..0000000 --- a/test/elvis_meta_SUITE.erl +++ /dev/null @@ -1,30 +0,0 @@ --module(elvis_meta_SUITE). - --export([all/0]). --export([elvis/1]). - --type config() :: proplists:proplist(). - --export_type([config/0]). - --hank([unnecessary_function_arguments]). - --spec all() -> [elvis, ...]. -all() -> - [elvis]. - --spec elvis(config()) -> {comment, []}. -elvis(_Config) -> - BaseDir = code:lib_dir(elvis), - ConfigFile = filename:join(BaseDir, "../../../../elvis.config"), - ElvisConfig = [fix_dirs(Group) || 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), Dir) - || Dir <- Dirs], - Group#{dirs := NewDirs}. diff --git a/test/examples/user_defined_rules.erl b/test/examples/user_defined_rules.erl index c203bd1..cee9e6d 100644 --- a/test/examples/user_defined_rules.erl +++ b/test/examples/user_defined_rules.erl @@ -1,9 +1,9 @@ -module(user_defined_rules). --export([rule/3]). +-export([rule/2]). -hank([unnecessary_function_arguments]). --spec rule(any(), any(), any()) -> [elvis_result:item(), ...]. -rule(_Config, _Target, _) -> +-spec rule(any(), any()) -> [elvis_result:item(), ...]. +rule(_Config, _Target) -> [elvis_result:new(item, "This will always FAIL.", [], 1)].