Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve formatting for brace_linter() file #1825

Merged
merged 3 commits into from
Dec 9, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 55 additions & 36 deletions R/brace_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -153,42 +153,61 @@ brace_linter <- function(allow_single_line = FALSE) {
xml <- source_expression$xml_parsed_content
lints <- list()

lints <- c(lints, xml_nodes_to_lints(
xml2::xml_find_all(xml, xp_open_curly),
source_expression = source_expression,
lint_message =
"Opening curly braces should never go on their own line and should always be followed by a new line."
))

lints <- c(lints, xml_nodes_to_lints(
xml2::xml_find_all(xml, xp_paren_brace),
source_expression = source_expression,
lint_message = "There should be a space before an opening curly brace."
))

lints <- c(lints, xml_nodes_to_lints(
xml2::xml_find_all(xml, xp_closed_curly),
source_expression = source_expression,
lint_message = "Closing curly-braces should always be on their own line, unless they are followed by an else."
))

lints <- c(lints, xml_nodes_to_lints(
xml2::xml_find_all(xml, xp_else_same_line),
source_expression = source_expression,
lint_message = "`else` should come on the same line as the previous `}`."
))

lints <- c(lints, xml_nodes_to_lints(
xml2::xml_find_all(xml, xp_function_brace),
source_expression = source_expression,
lint_message = "Any function spanning multiple lines should use curly braces."
))

lints <- c(lints, xml_nodes_to_lints(
xml2::xml_find_all(xml, xp_if_else_match_brace),
source_expression = source_expression,
lint_message = "Either both or neither branch in `if`/`else` should use curly braces."
))
lints <- c(
lints,
xml_nodes_to_lints(
xml2::xml_find_all(xml, xp_open_curly),
source_expression = source_expression,
lint_message =
"Opening curly braces should never go on their own line and should always be followed by a new line."
)
)

lints <- c(
lints,
xml_nodes_to_lints(
xml2::xml_find_all(xml, xp_paren_brace),
source_expression = source_expression,
lint_message = "There should be a space before an opening curly brace."
)
)

lints <- c(
lints,
xml_nodes_to_lints(
xml2::xml_find_all(xml, xp_closed_curly),
source_expression = source_expression,
lint_message =
"Closing curly-braces should always be on their own line, unless they are followed by an else."
)
)

lints <- c(
lints,
xml_nodes_to_lints(
xml2::xml_find_all(xml, xp_else_same_line),
source_expression = source_expression,
lint_message = "`else` should come on the same line as the previous `}`."
)
)

lints <- c(
lints,
xml_nodes_to_lints(
xml2::xml_find_all(xml, xp_function_brace),
source_expression = source_expression,
lint_message = "Any function spanning multiple lines should use curly braces."
)
)

lints <- c(
lints,
xml_nodes_to_lints(
xml2::xml_find_all(xml, xp_if_else_match_brace),
source_expression = source_expression,
lint_message = "Either both or neither branch in `if`/`else` should use curly braces."
)
)

lints
})
Expand Down