Skip to content

Commit

Permalink
Merge pull request #116 from inaka/425-rename-application
Browse files Browse the repository at this point in the history
[inaka/elvis#425] Rename application to elvis_core
  • Loading branch information
elbrujohalcon authored Dec 18, 2019
2 parents 069bba7 + 2a9e594 commit 59043b5
Show file tree
Hide file tree
Showing 14 changed files with 124 additions and 166 deletions.
2 changes: 1 addition & 1 deletion config/elvis.config
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
elvis,
[
{config,
[#{dirs => ["src"],
[#{dirs => ["../../_build/test/lib/elvis_core/test/examples"],
filter => "*.erl",
ruleset => erl_files
},
Expand Down
2 changes: 1 addition & 1 deletion config/rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
{elvis,
[
{config,
[#{dirs => ["../../_build/test/lib/elvis/test/examples"],
[#{dirs => ["../../_build/test/lib/elvis_core/test/examples"],
filter => "**.erl",
rules => [{elvis_style, line_length, #{limit => 135}}]
}
Expand Down
4 changes: 2 additions & 2 deletions config/test.config
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[
{
elvis,
elvis_core,
[
{config,
[#{dirs => ["../../_build/test/lib/elvis/test/examples"],
[#{dirs => ["../../_build/test/lib/elvis_core/test/examples"],
filter => "**.erl",
rules => [{elvis_style, line_length, #{limit => 80,
skip_comments => false}},
Expand Down
3 changes: 1 addition & 2 deletions config/test.pass.config
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
elvis,
[
{config,
[#{dirs => ["../../_build/test/lib/elvis/test/examples"],
[#{dirs => ["../../_build/test/lib/elvis_core/test/examples"],
filter => "**.erl",
rules => [{elvis_style, line_length, #{limit => 800}}]
}]
Expand All @@ -12,4 +12,3 @@
]
}
].

79 changes: 26 additions & 53 deletions src/elvis_config.erl
Original file line number Diff line number Diff line change
@@ -1,70 +1,52 @@
-module(elvis_config).

-export([
default/0,
load_file/1,
load/1,
validate/1,
normalize/1,
%% Geters
dirs/1,
include_dirs/1,
ignore/1,
filter/1,
files/1,
rules/1,
%% Files
resolve_files/1,
resolve_files/2,
apply_to_files/2
-export([ from_rebar/1
, from_file/1
, validate/1
, normalize/1
%% Geters
, dirs/1
, ignore/1
, filter/1
, files/1
, rules/1
%% Files
, resolve_files/1
, resolve_files/2
, apply_to_files/2
]).

-export_type([
config/0
]).
-export_type([config/0]).

-type config() :: [map()].

-define(DEFAULT_CONFIG_PATH, "./elvis.config").
-define(DEFAULT_REBAR_CONFIG_PATH, "./rebar.config").
-define(DEFAULT_FILTER, "*.erl").
-define(DEFAULT_INCLUDE_DIRS, ["include"]).

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Public
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

-spec default() -> config().
default() ->
case file:consult(?DEFAULT_CONFIG_PATH) of
{ok, [Config]} ->
load(Config);
{error, enoent} ->
case file:consult(?DEFAULT_REBAR_CONFIG_PATH) of
{ok, Config} ->
load(Config);
{error, enoent} ->
Config = application:get_env(elvis, config, []),
ensure_config_list(Config);
{error, Reason} ->
throw(Reason)
end;
-spec from_rebar(string()) -> config().
from_rebar(Path) ->
case file:consult(Path) of
{ok, Config} ->
load(elvis, Config);
{error, Reason} ->
throw(Reason)
end.

-spec load_file(string()) -> config().
load_file(Path) ->
-spec from_file(string()) -> config().
from_file(Path) ->
case file:consult(Path) of
{ok, [Config]} ->
load(Config);
load(elvis, Config);
{error, Reason} ->
throw(Reason)
end.

-spec load(term()) -> config().
load(AppConfig) ->
ElvisConfig = proplists:get_value(elvis, AppConfig, []),
-spec load(atom(), term()) -> config().
load(Key, AppConfig) ->
ElvisConfig = proplists:get_value(Key, AppConfig, []),
Config = proplists:get_value(config, ElvisConfig, []),
ensure_config_list(Config).

Expand Down Expand Up @@ -118,15 +100,6 @@ dirs(_RuleGroup = #{dirs := Dirs}) ->
dirs(#{}) ->
[].

% Only get `include_dirs' value for erl files RuleGroup, discard other ones.
-spec include_dirs(Config::config() | map()) -> [string()].
include_dirs(Config) when is_list(Config) ->
lists:flatmap(fun include_dirs/1, Config);
include_dirs(_RuleGroup = #{include_dirs := IDirs})->
IDirs;
include_dirs(_) ->
?DEFAULT_INCLUDE_DIRS.

-spec ignore(config() | map()) -> [string()].
ignore(Config) when is_list(Config) ->
lists:flatmap(fun ignore/1, Config);
Expand Down
2 changes: 1 addition & 1 deletion src/elvis.app.src → src/elvis_core.app.src
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
application, elvis,
application, elvis_core,
[
{pkg_name, elvis_core},
{description, "Core library for the Erlang style reviewer"},
Expand Down
24 changes: 4 additions & 20 deletions src/elvis_core.erl
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,15 @@

%% Public API

-export([
rock/0,
rock/1,
rock_this/1,
rock_this/2
-export([ rock/1
, rock_this/2
]).

-export([start/0]).

%% for internal use only
-export([do_rock/2]).

-define(APP_NAME, "elvis").

-type source_filename() :: nonempty_string().
-type target() :: source_filename() | module().

Expand All @@ -26,29 +21,18 @@
%% @doc Used when starting the application on the shell.
-spec start() -> ok.
start() ->
{ok, _} = application:ensure_all_started(elvis),
{ok, _} = application:ensure_all_started(elvis_core),
ok.

%%% Rock Command

-spec rock() -> ok | {fail, [elvis_result:file()]}.
rock() ->
Config = elvis_config:default(),
rock(Config).

-spec rock(elvis_config:config()) -> ok | {fail, [elvis_result:file()]}.
rock(Config) ->
ok = elvis_config:validate(Config),
NewConfig = elvis_config:normalize(Config),
Results = lists:map(fun do_parallel_rock/1, NewConfig),
lists:foldl(fun combine_results/2, ok, Results).

-spec rock_this(target()) ->
ok | {fail, [elvis_result:file() | elvis_result:rule()]}.
rock_this(Target) ->
Config = elvis_config:default(),
rock_this(Target, Config).

-spec rock_this(target(), elvis_config:config()) ->
ok | {fail, [elvis_result:file() | elvis_result:rule()]}.
rock_this(Module, Config) when is_atom(Module) ->
Expand Down Expand Up @@ -85,7 +69,7 @@ rock_this(Path, Config) ->
%% @private
-spec do_parallel_rock(map()) -> ok | {fail, [elvis_result:file() | elvis_result:rule()]}.
do_parallel_rock(Config0) ->
Parallel = application:get_env(elvis, parallel, 1),
Parallel = application:get_env(elvis_core, parallel, 1),
Config = elvis_config:resolve_files(Config0),
Files = elvis_config:files(Config),

Expand Down
2 changes: 1 addition & 1 deletion src/elvis_result.erl
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ get_line_num(#{line_num := LineNum}) -> LineNum.

-spec print_results(file()) -> ok.
print_results(Results) ->
Format = application:get_env(elvis, output_format, colors),
Format = application:get_env(elvis_core, output_format, colors),
print(Format, Results).

-spec print(plain | colors | parsable, [file()] | file()) -> ok.
Expand Down
6 changes: 3 additions & 3 deletions src/elvis_utils.erl
Original file line number Diff line number Diff line change
Expand Up @@ -164,14 +164,14 @@ error_prn(Message, Args) ->

-spec print_info(string(), [term()]) -> ok.
print_info(Message, Args) ->
case application:get_env(elvis, verbose) of
case application:get_env(elvis_core, verbose) of
{ok, true} -> print(Message, Args);
_ -> ok
end.

-spec print(string(), [term()]) -> ok.
print(Message, Args) ->
case application:get_env(elvis, no_output) of
case application:get_env(elvis_core, no_output) of
{ok, true} -> ok;
_ ->
Output = io_lib:format(Message, Args),
Expand All @@ -190,7 +190,7 @@ parse_colors(Message) ->
"white-bold" => "\e[1;37m",
"reset" => "\e[0m"},
Opts = [global, {return, list}],
case application:get_env(elvis, output_format, colors) of
case application:get_env(elvis_core, output_format, colors) of
P when P =:= plain orelse
P =:= parsable ->
re:replace(Message, "{{.*?}}", "", Opts);
Expand Down
Loading

0 comments on commit 59043b5

Please sign in to comment.