View source: R/indentation_linter.R
indentation_linter | R Documentation |
Check that indentation is consistent
indentation_linter(
indent = 2L,
hanging_indent_style = c("tidy", "always", "never"),
assignment_as_infix = TRUE
)
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 |
configurable, default, readability, style
linters for a complete list of linters available in lintr.
# 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)
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.