Add `multiline_call_linter()`
Related but not the same as indentation_linter(), it would enforce the rules laid out in https://style.tidyverse.org/syntax.html#long-lines
It would produce three lints:
- Closing parentheses of multi line function calls are on their own line.
- Arguments on the first line of a multi line function call must be unnamed.
- Arguments on subsequent lines of a multi line function call must be named.
It needs an except= argument to whitelist some functions, notably paste(), paste0(), cat().
Please mention any additional functions you'd see fit for this.
Quoting examples from the styleguide:
# Good
do_something_very_complicated(
something = "that",
requires = many,
arguments = "some of which may be long"
)
map(x, f,
extra_argument_a = 10,
extra_argument_b = c(1, 43, 390, 210209)
)
paste0(
"Requirement: ", requires, "\n",
"Result: ", result, "\n"
)
# Bad
map(x, f,
additional_arg = 42)
do_something_very_complicated("that", requires, many, arguments,
"some of which may be long"
)
not_paste0(
"Requirement: ", requires, "\n",
"Result: ", result, "\n"
)
not_paste0(
a = 1, b = 2, c = 3, # maybe we optionally allow this style?
d = 4, e = 5, f = 6 # It's not tidyverse compliant but might be fairly common.
)
paste0(
"Requirement: ", requires,
"\n", "Result: ",
result, "\n")
plot() is another one where grouping keyword args helps a lot / putting every argument on its own line harms readability. e.g. I always like to put xlab= and xlim= or xaxt= on the same line
On Sun, Oct 16, 2022, 2:37 AM AshesITR @.***> wrote:
Related but not the same as indentation_linter(), it would enforce the rules laid out in https://style.tidyverse.org/syntax.html#long-lines It would produce three lints:
- Closing parentheses of multi line function calls are on their own line.
- Arguments on the first line of a multi line function call must be unnamed.
- Arguments on subsequent lines of a multi line function call must be named.
It needs an except= argument to whitelist some functions, notably paste(), paste0(), cat(). Please mention any additional functions you'd see fit for this.
Quoting examples from the styleguide:
Good
do_something_very_complicated( something = "that", requires = many, arguments = "some of which may be long" )
map(x, f, extra_argument_a = 10, extra_argument_b = c(1, 43, 390, 210209) )
paste0( "Requirement: ", requires, "\n", "Result: ", result, "\n" )
Bad
do_something_very_complicated("that", requires, many, arguments, "some of which may be long" )
not_paste0( "Requirement: ", requires, "\n", "Result: ", result, "\n" )
paste0( "Requirement: ", requires, "\n", "Result: ", result, "\n")
— Reply to this email directly, view it on GitHub https://github.com/r-lib/lintr/issues/1719, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB2BA5KVRVHHOL4RKS4ASJLWDPEGLANCNFSM6AAAAAARGI4BAQ . You are receiving this because you are subscribed to this thread.Message ID: @.***>
Arguments on subsequent lines of a multi line function call must be named.
IMHO this should not be or only be implemented as a (non-default) strict option, since this is stricter than what the tidyverse style-guide mentions.
Short unnamed arguments can also go on the same line as the function name, even if the whole function call spans multiple lines.
Emphasis mine. So this ought to be allowed:
map(
my_list,
some_function,
extra_argument_a = 10,
extra_argument_b = c(1, 43, 390, 210209)
)
(map() is not the best example for this anymore, since the tidyverse team recommends against passing arguments to .f via ... now, but that doesn't really matter here).
Arguments on subsequent lines of a multi line function call must be named.
IMHO this should not be or only be implemented as a (non-default)
strictoption, since this is stricter than what the tidyverse style-guide mentions.Short unnamed arguments can also go on the same line as the function name, even if the whole function call spans multiple lines.
Emphasis mine. So this ought to be allowed:
map( my_list, some_function, extra_argument_a = 10, extra_argument_b = c(1, 43, 390, 210209) )
I understand it to mean this style:
map(my_list, some_function,
extra_argument_a = 10,
extra_argument_b = c(1, 43, 390, 210209)
)
Yes, both styles should be allowed.