diff --git a/src/elvis_style.erl b/src/elvis_style.erl index f5ddb924..056929da 100644 --- a/src/elvis_style.erl +++ b/src/elvis_style.erl @@ -106,7 +106,15 @@ default(macro_names) -> #{regex => "^([A-Z][A-Z_0-9]+)$"}; default(operator_spaces) -> - #{rules => [{right, ","}, {right, "++"}, {left, "++"}]}; + #{rules => + [{right, "++"}, {left, "++"}, {right, "="}, {left, "="}, {right, "+"}, {left, "+"}, + {right, "-"}, {left, "-"}, {right, "*"}, {left, "*"}, {right, "/"}, {left, "/"}, + {right, "=<"}, {left, "=<"}, {right, "<"}, {left, "<"}, {right, ">"}, {left, ">"}, + {right, ">="}, {left, ">="}, {right, "=="}, {left, "=="}, {right, "=:="}, {left, "=:="}, + {right, "/="}, {left, "/="}, {right, "=/="}, {left, "=/="}, {right, "--"}, {left, "--"}, + {right, "=>"}, {left, "=>"}, {right, ":="}, {left, ":="}, {right, "<-"}, {left, "<-"}, + {right, "<="}, {left, "<="}, {right, "||"}, {left, "||"}, {right, "|"}, {left, "|"}, + {right, "::"}, {left, "::"}, {right, "->"}, {left, "->"}, {right, ","}]}; default(no_space) -> #{rules => [{right, "("}, {left, ")"}, {left, ","}]}; default(nesting_level) -> diff --git a/test/examples/fail_operator_spaces.erl b/test/examples/fail_operator_spaces.erl index df89a854..8a459b53 100644 --- a/test/examples/fail_operator_spaces.erl +++ b/test/examples/fail_operator_spaces.erl @@ -18,6 +18,8 @@ , windows_newlines/0 , this/0 , this/1 + , pass_more_operators/0 + , fail_more_operators/0 ]). %% No space before and after coma,on a comment. @@ -102,3 +104,49 @@ this() this(shouldnt_either) -> A = 1 - 2, A. + + +-spec pass_more_operators() -> R when R :: tuple(). +pass_more_operators() -> + D = "Elvis should not complain this function " + "since operators are properly spaced out: " + "=,+,-,*,/,=<,<,>,>=,==,=:=,/=,=/=,--,=>,:=,<-,<=,||,|,::,->", + X = 1 + 2 - 3 * 4 / 5, + M = #{d => D, x => X}, + { + X =< 1, + X < 2, + X > 3, + X >= 4, + X == 5, + X =:= 6, + X /= 7, + X =/= 8, + D -- "", + M#{d => D, x := X}, + [A || A <- D], + << <> || <> <= list_to_binary(D) >>, + [X | D] + }. + +-spec fail_more_operators()->R when R::tuple(). +fail_more_operators()-> + D="Elvis should complain this function " + "since operators have no space around them.", + X=1+2-3*4/5, + M=#{d=>D, x=>X}, + { + X=<1, + X<2, + X>3, + X>=4, + X==5, + X=:=6, + X/=7, + X=/=8, + D--"", + M#{d=>D, x:=X}, + [A||A<- D], + <<<<$>>>||<<$>>><=<<$>>>>>, + [X|D] + }. diff --git a/test/examples/pass_line_length_elvis_attr.erl b/test/examples/pass_line_length_elvis_attr.erl index 2c9460b0..2509b0f4 100644 --- a/test/examples/pass_line_length_elvis_attr.erl +++ b/test/examples/pass_line_length_elvis_attr.erl @@ -35,7 +35,7 @@ function_5() -> io:format("This line is 90 characters long and should be detected ~p!!!!!!!!!!!!!!!!!!!!!!!!!!", [yeah]), io:format("This line is 90 characters long and should be detected ~p and these two escaped ~p!!!!!!!!!!!!!!!!!!", [yeah, no]). -function_6(Config, AntPositions)-> +function_6(Config, AntPositions) -> gb_trees:from_orddict([{Pos, #{pos => Pos, state => model:random_ant_state(Config)}} || Pos <- lists:sort(AntPositions)]). % {Pozycja, CaƂyAgent} - ew. do zmiany, jest zbalansowany [DG] function_7() -> diff --git a/test/style_SUITE.erl b/test/style_SUITE.erl index 3f3b5fb8..304a4240 100644 --- a/test/style_SUITE.erl +++ b/test/style_SUITE.erl @@ -412,35 +412,42 @@ verify_operator_spaces(Config) -> [_] = elvis_core_apply_rule(Config, elvis_style, operator_spaces, AppendOptions, Path), SumOperation = #{rules => [{right, "+"}, {left, "+"}]}, - [_, _] = elvis_core_apply_rule(Config, elvis_style, operator_spaces, SumOperation, Path), + [_, _, _, _] = + elvis_core_apply_rule(Config, elvis_style, operator_spaces, SumOperation, Path), MinusOperation = #{rules => [{right, "-"}, {left, "-"}]}, - [] = elvis_core_apply_rule(Config, elvis_style, operator_spaces, MinusOperation, Path), + [_, _] = + elvis_core_apply_rule(Config, elvis_style, operator_spaces, MinusOperation, Path), Arrow = #{rules => [{left, "->"}]}, - [] = elvis_core_apply_rule(Config, elvis_style, operator_spaces, Arrow, Path), + [_, _] = elvis_core_apply_rule(Config, elvis_style, operator_spaces, Arrow, Path), BarOptions = #{rules => [{right, "|"}, {left, "|"}]}, - [_, _] = elvis_core_apply_rule(Config, elvis_style, operator_spaces, BarOptions, Path), + [_, _, _, _] = + elvis_core_apply_rule(Config, elvis_style, operator_spaces, BarOptions, Path), ComprehensionOperation = #{rules => [{right, "||"}, {left, "||"}]}, - [_, _] = + [_, _, _, _, _, _] = elvis_core_apply_rule(Config, elvis_style, operator_spaces, ComprehensionOperation, Path), - AllOptions = - #{rules => - [{right, ","}, - {right, "++"}, - {left, "++"}, - {right, "+"}, - {left, "+"}, - {left, "->"}, - {right, "|"}, - {left, "|"}, - {right, "||"}, - {left, "||"}]}, - [_, _, _, _, _, _, _, _, _, _] = - elvis_core_apply_rule(Config, elvis_style, operator_spaces, AllOptions, Path). + DefaultOptions = #{}, + [#{info := [right, "," | _]}, #{info := [right, "," | _]}, #{info := [left, "++" | _]}, + #{info := [right, "," | _]}, #{info := [left, "+" | _]}, #{info := [right, "+" | _]}, + #{info := [right, "|" | _]}, #{info := [left, "|" | _]}, #{info := [right, "||" | _]}, + #{info := [left, "||" | _]}, #{info := [right, "::" | _]}, #{info := [left, "::" | _]}, + #{info := [right, "->" | _]}, #{info := [left, "->" | _]}, #{info := [left, "->" | _]}, + #{info := [right, "+" | _]}, #{info := [left, "+" | _]}, #{info := [right, "-" | _]}, + #{info := [left, "-" | _]}, #{info := [right, "*" | _]}, #{info := [left, "*" | _]}, + #{info := [right, "/" | _]}, #{info := [left, "/" | _]}, #{info := [right, "=<" | _]}, + #{info := [left, "=<" | _]}, #{info := [right, "<" | _]}, #{info := [left, "<" | _]}, + #{info := [right, ">" | _]}, #{info := [left, ">" | _]}, #{info := [right, ">=" | _]}, + #{info := [left, ">=" | _]}, #{info := [right, "==" | _]}, #{info := [left, "==" | _]}, + #{info := [right, "=:=" | _]}, #{info := [left, "=:=" | _]}, #{info := [right, "/=" | _]}, + #{info := [left, "/=" | _]}, #{info := [right, "=/=" | _]}, #{info := [left, "=/=" | _]}, + #{info := [right, "--" | _]}, #{info := [left, "--" | _]}, #{info := [right, "||" | _]}, + #{info := [left, "||" | _]}, #{info := [right, "||" | _]}, #{info := [left, "||" | _]}, + #{info := [right, "|" | _]}, #{info := [left, "|" | _]}] = + elvis_core_apply_rule(Config, elvis_style, operator_spaces, DefaultOptions, Path). -spec verify_no_space(config()) -> any(). verify_no_space(Config) -> @@ -1414,6 +1421,7 @@ verify_elvis_attr(Config, FilenameNoExt) -> Ext = proplists:get_value(test_file_ext, Config, "erl"), {ok, File} = elvis_test_utils:find_file(SrcDirs, FilenameNoExt ++ "." ++ Ext), + ct:pal("File: ~p", [File]), {ok, #{rules := RuleResults}} = elvis_core:do_rock(File, ElvisConfig), [[] = Items || #{items := Items} <- RuleResults],