From bc361f7dd2a921655806189e114823a8f5cb7063 Mon Sep 17 00:00:00 2001 From: Juan Facorro Date: Fri, 29 Nov 2019 16:18:23 +0100 Subject: [PATCH] Bump katana_code to 0.2.1 which removes the usage of aleppo --- rebar.config | 2 +- rebar.lock | 6 +-- src/elvis_file.erl | 10 ++-- src/elvis_style.erl | 9 ++-- test/elvis_SUITE.erl | 54 -------------------- test/examples/fail_used_ignored_variable.erl | 13 +++-- 6 files changed, 22 insertions(+), 72 deletions(-) diff --git a/rebar.config b/rebar.config index 6dde27d..00959ad 100644 --- a/rebar.config +++ b/rebar.config @@ -62,7 +62,7 @@ %% == Dependencies == {deps, [ {zipper, "1.0.1"} - , {katana_code, "0.1.2"} + , {katana_code, "0.2.1"} ]}. %% == Dialyzer == diff --git a/rebar.lock b/rebar.lock index b56d495..279d21e 100644 --- a/rebar.lock +++ b/rebar.lock @@ -1,10 +1,8 @@ {"1.1.0", -[{<<"aleppo">>,{pkg,<<"inaka_aleppo">>,<<"1.1.1">>},1}, - {<<"katana_code">>,{pkg,<<"katana_code">>,<<"0.1.2">>},0}, +[{<<"katana_code">>,{pkg,<<"katana_code">>,<<"0.2.1">>},0}, {<<"zipper">>,{pkg,<<"zipper">>,<<"1.0.1">>},0}]}. [ {pkg_hash,[ - {<<"aleppo">>, <<"B0F7D05A118C5EBC3A735D68E92A7BD5837FE53455495EDE37CF0AA8BA4912E3">>}, - {<<"katana_code">>, <<"347D42D5E89AC6C4BF8D02B64633AC1BFE14B7724B5910260D39EFEAFE737F01">>}, + {<<"katana_code">>, <<"B2195859DF57D8BEBF619A9FD3327CD7D01563A98417156D0F4C5FAB435F2630">>}, {<<"zipper">>, <<"3CCB4F14B97C06B2749B93D8B6C204A1ECB6FAFC6050CACC3B93B9870C05952A">>}]} ]. diff --git a/src/elvis_file.erl b/src/elvis_file.erl index d6f6696..0fe6c8e 100644 --- a/src/elvis_file.erl +++ b/src/elvis_file.erl @@ -51,7 +51,7 @@ parse_tree(_Config, File = #{parse_tree := ParseTree}) -> parse_tree(Config, File = #{path := Path, content := Content}) -> Ext = filename:extension(Path), ExtStr = elvis_utils:to_str(Ext), - ParseTree = resolve_parse_tree(Config, ExtStr, Content), + ParseTree = resolve_parse_tree(ExtStr, Content), parse_tree(Config, File#{parse_tree => ParseTree}); parse_tree(Config, File0 = #{path := _Path}) -> {_, File} = src(File0), @@ -109,11 +109,11 @@ filter_files(Files, Dirs, Filter, IgnoreList) -> %% Private %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --spec resolve_parse_tree(map(), string(), binary()) -> +-spec resolve_parse_tree(string(), binary()) -> undefined | ktn_code:tree_node(). -resolve_parse_tree(Config, ".erl", Content) -> - ktn_code:parse_tree(elvis_config:include_dirs(Config), Content); -resolve_parse_tree(_, _, _) -> +resolve_parse_tree(".erl", Content) -> + ktn_code:parse_tree(Content); +resolve_parse_tree( _, _) -> undefined. -spec glob_to_regex(iodata()) -> iodata(). diff --git a/src/elvis_style.erl b/src/elvis_style.erl index 435c5ea..49c11fb 100644 --- a/src/elvis_style.erl +++ b/src/elvis_style.erl @@ -882,7 +882,7 @@ check_macro_names(Line, Num, _Args) -> end end. -%% Macro in Function Call as Module or Functon Name +%% Macro in Function Call as Module or Function Name -spec check_macro_module_names(binary(), integer(), [term()]) -> no_result | {ok, elvis_result:item()}. @@ -939,7 +939,8 @@ is_remote_call({Num, Col}, Root) -> (Node0 == zipper:node(Zipper)) andalso has_remote_call_parent(Zipper) end, - [] =/= elvis_code:find(Pred, Root, #{mode => zipper}) + Opts = #{mode => zipper, traverse => all}, + [] =/= elvis_code:find(Pred, Root, Opts) end. has_remote_call_parent(undefined) -> @@ -1048,7 +1049,7 @@ is_dynamic_call(Node) -> end. %% Plain Variable --spec is_var(ktn_code:tree_node()) -> boolean(). +-spec is_var(zipper:zipper(_)) -> boolean(). is_var(Zipper) -> case ktn_code:type(zipper:node(Zipper)) of var -> @@ -1066,7 +1067,7 @@ is_var(Zipper) -> %% Ignored Variable --spec is_ignored_var(ktn_code:tree_node()) -> +-spec is_ignored_var(zipper:zipper(_)) -> boolean(). is_ignored_var(Zipper) -> Node = zipper:node(Zipper), diff --git a/test/elvis_SUITE.erl b/test/elvis_SUITE.erl index 3cd5b00..6929ea1 100644 --- a/test/elvis_SUITE.erl +++ b/test/elvis_SUITE.erl @@ -26,7 +26,6 @@ rock_with_rule_groups/1, rock_this_skipping_files/1, rock_this_not_skipping_files/1, - rock_with_include_dirs/1, %% Util & Config throw_configuration/1, find_file_and_check_src/1, @@ -320,59 +319,6 @@ rock_this_not_skipping_files(_Config) -> meck:unload(elvis_file), ok. --spec rock_with_include_dirs(Config::config()) -> ok. -rock_with_include_dirs(_Config) -> - meck:new(ktn_code, [unstick]), - Dirs = ["../../test/examples"], - Filter = "small.erl", - _ = application:set_env(elvis, verbose, true), - - % Default `include_dirs' value is used when not provided - meck:expect(ktn_code, - parse_tree, - fun(IDirs = ["include"], Content) -> - meck:passthrough([IDirs, Content]); - (_, _) -> - % Received include dirs are different than expected - throw({error, badmatch}) - end), - DefaultConf = [#{dirs => Dirs, filter => Filter, ruleset => erl_files}], - % We don't care about checks results - _ = elvis_core:rock(DefaultConf), - true = meck:validate(ktn_code), - - % Given `include_dirs' are used when provided - CustomIDirs = ["path/to/include1", "path/to/include2"], - meck:expect(ktn_code, - parse_tree, - fun(IDirs, Content) -> - case IDirs of - CustomIDirs -> - meck:passthrough([IDirs, Content]); - _ -> - % Received include dirs are different than expected - throw({error, badmatch}) - end - end), - CustomConf = #{dirs => Dirs, - include_dirs => CustomIDirs, - filter => Filter, - ruleset => erl_files}, - % We don't care about checks results - _ = elvis_core:rock([CustomConf]), - true = meck:validate(ktn_code), - - % It must fail when the received include_dirs value is different - % than expected. - _ = elvis_core:rock([CustomConf#{include_dirs => ["unknown/path"]}]), - false = meck:validate(ktn_code), - - % Clean up environment - _ = application:set_env(elvis, verbose, false), - _ = meck:unload(ktn_code), - ok. - - %%%%%%%%%%%%%%% %%% Utils diff --git a/test/examples/fail_used_ignored_variable.erl b/test/examples/fail_used_ignored_variable.erl index eec488c..23e713c 100644 --- a/test/examples/fail_used_ignored_variable.erl +++ b/test/examples/fail_used_ignored_variable.erl @@ -1,9 +1,9 @@ -module(fail_used_ignored_variable). --export([ - use_ignored_var/2, - use_ignored_var_in_fun/2, - no_used_ignored_vars_here/2, handle_call/3 +-export([ use_ignored_var/2 + , use_ignored_var_in_fun/2 + , no_used_ignored_vars_here/2, handle_call/3 + , macro_with_underscore/0 ]). use_ignored_var(_One, Two) -> @@ -24,3 +24,8 @@ no_used_ignored_vars_here(One, _Two) -> {stop, {unknown_request, Msg}, {unknown_request, Msg}, term()}. handle_call(Msg, _From, State) -> {stop, {unknown_request, Msg}, {unknown_request, Msg}, State}. + +-define(__(X), X). + +macro_with_underscore() -> + ?__("This string will be translated").