From c273a6b6158c7b37bd0fbfda7a0fb775069c11e7 Mon Sep 17 00:00:00 2001 From: z8674558 Date: Sun, 21 Mar 2021 19:06:32 +0900 Subject: [PATCH] allow checking spaces around | and || --- src/elvis_style.erl | 2 +- test/examples/fail_operator_spaces.erl | 8 ++++++++ test/style_SUITE.erl | 14 ++++++++++++-- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/elvis_style.erl b/src/elvis_style.erl index 6ca4640..563d06f 100644 --- a/src/elvis_style.erl +++ b/src/elvis_style.erl @@ -320,7 +320,7 @@ macro_module_names(Config, Target, RuleConfig) -> -type operator_spaces_config() :: #{ ignore => [ignorable()] , rules => [{right | left, string()}] }. --define(PUNCTUATION_SYMBOLS, [',', ';', 'dot', '->', ':', '::']). +-define(PUNCTUATION_SYMBOLS, [',', ';', 'dot', '->', ':', '::', '|', '||']). -spec operator_spaces(elvis_config:config(), elvis_file:file(), diff --git a/test/examples/fail_operator_spaces.erl b/test/examples/fail_operator_spaces.erl index 6039d8d..324a59e 100644 --- a/test/examples/fail_operator_spaces.erl +++ b/test/examples/fail_operator_spaces.erl @@ -11,6 +11,8 @@ , function5/0 , function6/0 , function7/0 + , function8/0 + , function9/0 , tag_filters/2 , unicode_characters/0 , this/0 @@ -53,6 +55,12 @@ function7() -> RegExp = "^.{1,20}$", re:run(Name, RegExp, [unicode]). +function8() -> + [should| [fail]] ++ [should |[fail]] ++ [shouldnot | [fail]]. + +function9() -> + [should|| fail <- []] ++ [should ||fail <- []] ++ [shouldnot || fail <- []]. + tag_filters(DocName, #{conn := Conn} = State) -> TableName = atom_to_list(DocName), Sql = ["SELECT " diff --git a/test/style_SUITE.erl b/test/style_SUITE.erl index e8a016b..e6e831e 100644 --- a/test/style_SUITE.erl +++ b/test/style_SUITE.erl @@ -327,13 +327,23 @@ verify_operator_spaces(Config) -> Arrow = #{rules => [{left, "->"}]}, [] = 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), + + ComprehensionOperation = #{rules => [{right, "||"}, {left, "||"}]}, + [_, _] = elvis_core_apply_rule(Config, elvis_style, operator_spaces, ComprehensionOperation, Path), + AllOptions = #{rules => [{right, ","}, {right, "++"}, {left, "++"}, {right, "+"}, {left, "+"}, - {left, "->"}]}, - [_, _, _, _, _, _] = + {left, "->"}, + {right, "|"}, + {left, "|"}, + {right, "||"}, + {left, "||"}]}, + [_, _, _, _, _, _, _, _, _, _] = elvis_core_apply_rule(Config, elvis_style, operator_spaces, AllOptions, Path). -spec verify_operator_spaces_latin1(config()) -> any().