From d8b809849d32bb5aec135cc95c61801011df2e7f Mon Sep 17 00:00:00 2001 From: Michael Chirico Date: Sun, 17 Dec 2023 14:23:21 +0000 Subject: [PATCH] document --- man/if_switch_linter.Rd | 46 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/man/if_switch_linter.Rd b/man/if_switch_linter.Rd index 07eb548ae..e6aebfe47 100644 --- a/man/if_switch_linter.Rd +++ b/man/if_switch_linter.Rd @@ -8,8 +8,10 @@ if_switch_linter(max_branch_lines = 0L, max_branch_expr = 0L) } \arguments{ \item{max_branch_lines, max_branch_expr}{Integer, default 0 indicates "no maximum". -If set and \code{if}/\verb{else if}/.../\verb{else}chain where any branch occupies more than -this number of lines (resp. expressions) will not be linted. See examples.} +If set any \code{if}/\verb{else if}/.../\verb{else} chain where any branch occupies more than +this number of lines (resp. expressions) will not be linted. The conjugate +applies to \code{switch()} statements -- if these parameters are set, any \code{switch()} +statement with any overly-complicated branches will be linted. See examples.} } \description{ \code{\link[=switch]{switch()}} statements in R are used to delegate behavior based @@ -72,6 +74,26 @@ lint( linters = if_switch_linter() ) +code <- paste( + "switch(x,", + " a = {", + " 1", + " 2", + " 3", + " },", + " b = {", + " 1", + " 2", + " }", + ")", + sep = "\n" +) +writeLines(code) +lint( + text = code, + linters = if_switch_linter(max_branch_lines = 2L) +) + # okay lint( text = "switch(x, a = 1, b = 2, 3)", @@ -122,6 +144,26 @@ lint( linters = if_switch_linter(max_branch_expr = 2L) ) +code <- paste( + "switch(x,", + " a = {", + " 1", + " 2", + " 3", + " },", + " b = {", + " 1", + " 2", + " }", + ")", + sep = "\n" +) +writeLines(code) +lint( + text = code, + linters = if_switch_linter(max_branch_lines = 3L) +) + } \seealso{ \link{linters} for a complete list of linters available in lintr.