| indentation_linter {lintr} | R Documentation |
Check that indentation is consistent
Description
Check that indentation is consistent
Usage
indentation_linter(
indent = 2L,
hanging_indent_style = c("tidy", "always", "never"),
assignment_as_infix = TRUE
)
Arguments
indent |
Number of spaces, that a code block should be indented by relative to its parent code block.
Used for multi-line code blocks ( |
hanging_indent_style |
Indentation style for multi-line function calls with arguments in their first line.
Defaults to tidyverse style, i.e. a block indent is used if the function call terminates with # complies to any style
map(
x,
f,
additional_arg = 42
)
# complies to "tidy" and "never"
map(x, f,
additional_arg = 42
)
# complies to "always"
map(x, f,
additional_arg = 42
)
# complies to "tidy" and "always"
map(x, f,
additional_arg = 42)
# complies to "never"
map(x, f,
additional_arg = 42)
# complies to "tidy"
function(
a,
b) {
# body
}
|
assignment_as_infix |
Treat # complies to any style
variable <- a %+%
b %+%
c
# complies to assignment_as_infix = TRUE
variable <-
a %+%
b %+%
c
# complies to assignment_as_infix = FALSE
variable <-
a %+%
b %+%
c
|
Tags
configurable, default, readability, style
See Also
-
linters for a complete list of linters available in lintr.
Examples
# will produce lints
code_lines <- "if (TRUE) {\n1 + 1\n}"
writeLines(code_lines)
lint(
text = code_lines,
linters = indentation_linter()
)
code_lines <- "if (TRUE) {\n 1 + 1\n}"
writeLines(code_lines)
lint(
text = code_lines,
linters = indentation_linter()
)
code_lines <- "map(x, f,\n additional_arg = 42\n)"
writeLines(code_lines)
lint(
text = code_lines,
linters = indentation_linter(hanging_indent_style = "always")
)
code_lines <- "map(x, f,\n additional_arg = 42)"
writeLines(code_lines)
lint(
text = code_lines,
linters = indentation_linter(hanging_indent_style = "never")
)
# okay
code_lines <- "map(x, f,\n additional_arg = 42\n)"
writeLines(code_lines)
lint(
text = code_lines,
linters = indentation_linter()
)
code_lines <- "if (TRUE) {\n 1 + 1\n}"
writeLines(code_lines)
lint(
text = code_lines,
linters = indentation_linter(indent = 4)
)