Skip to content

Commit

Permalink
FormatRBear.py: Disable parameter-options
Browse files Browse the repository at this point in the history
Default options of r_braces_on_next_line,
r_use_arrows are disabled.

Closes #514
  • Loading branch information
yogupta committed Mar 2, 2017
1 parent 4daad8d commit c8810e3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
11 changes: 7 additions & 4 deletions bears/r/FormatRBear.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ class FormatRBear:
def create_arguments(filename, file, config_file,
r_keep_comments: bool=True,
r_keep_blank_lines: bool=True,
r_braces_on_next_line: bool=False,
r_use_arrows: bool=False,
r_braces_on_next_line: bool=None,
r_use_arrows: bool=None,
indent_size:
int=SpacingHelper.DEFAULT_TAB_WIDTH,
r_max_expression_length: int=0):
Expand Down Expand Up @@ -79,12 +79,15 @@ def create_arguments(filename, file, config_file,
"""
options = {'source="' + escape(filename, '"\\') + '"',
'blank=' + _map_to_r_bool(r_keep_blank_lines),
'brace.newline=' + _map_to_r_bool(r_braces_on_next_line),
'comment=' + _map_to_r_bool(r_keep_comments),
'arrow=' + _map_to_r_bool(r_use_arrows),
'indent=' + str(indent_size)}
if r_max_expression_length:
options.add('width.cutoff=' + str(r_max_expression_length))
if r_braces_on_next_line is not None:
options.add('brace.newline=' +
_map_to_r_bool(r_braces_on_next_line))
if r_use_arrows is not None:
options.add('arrow=' + _map_to_r_bool(r_use_arrows))

rcode = 'library(formatR);formatR::tidy_source({})'.format(
','.join(options))
Expand Down
14 changes: 14 additions & 0 deletions tests/r/FormatRBearTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@
}
"""

good_file_7 = """1 + 1
if (TRUE) {
x = 1 # inline comments
} else {
x <- 2
print("Oh no... ask the right bracket to go away!")
}
"""

bad_file_1 = """1+1
if(TRUE){
Expand Down Expand Up @@ -129,3 +137,9 @@
valid_files=(good_file_6,),
invalid_files=(bad_file_3,),
settings={'r_max_expression_length': '25'})

FormatRBearDefaultSettingsTest = verify_local_bear(
FormatRBear,
valid_files=(good_file_7,),
invalid_files=(bad_file_3,),
settings={})

0 comments on commit c8810e3

Please sign in to comment.