Skip to content

Change linter_level= arg order for readability #2361

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

Merged
merged 2 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions R/T_and_F_symbol_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ T_and_F_symbol_linter <- function() { # nolint: object_name.

replacement_map <- c(T = "TRUE", F = "FALSE")

Linter(function(source_expression) {
Linter(linter_level = "expression", function(source_expression) {
xml <- source_expression$xml_parsed_content
if (is.null(xml)) return(list())
bad_usage <- xml_find_all(xml, usage_xpath)
Expand All @@ -66,5 +66,5 @@ T_and_F_symbol_linter <- function() { # nolint: object_name.
make_lints(bad_usage, "Use %s instead of the symbol %s."),
make_lints(bad_assignment, "Don't use %2$s as a variable name, as it can break code relying on %2$s being %1$s.")
)
}, linter_level = "expression")
})
}
4 changes: 2 additions & 2 deletions R/any_duplicated_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ any_duplicated_linter <- function() {

uses_nrow_xpath <- "./parent::expr/expr/expr[1]/SYMBOL_FUNCTION_CALL[text() = 'nrow']"

Linter(function(source_expression) {
Linter(linter_level = "expression", function(source_expression) {
xml <- source_expression$xml_parsed_content
if (is.null(xml)) return(list())

Expand All @@ -111,5 +111,5 @@ any_duplicated_linter <- function() {
)

c(any_duplicated_lints, length_unique_lints)
}, linter_level = "expression")
})
}
4 changes: 2 additions & 2 deletions R/any_is_na_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ any_is_na_linter <- function() {
]
"

Linter(function(source_expression) {
Linter(linter_level = "expression", function(source_expression) {
xml <- source_expression$xml_parsed_content
if (is.null(xml)) return(list())

Expand All @@ -58,5 +58,5 @@ any_is_na_linter <- function() {
lint_message = "anyNA(x) is better than any(is.na(x)).",
type = "warning"
)
}, linter_level = "expression")
})
}
4 changes: 2 additions & 2 deletions R/assignment_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ assignment_linter <- function(allow_cascading_assign = TRUE,
if (!allow_pipe_assign) "//SPECIAL[text() = '%<>%']"
))

Linter(function(source_expression) {
Linter(linter_level = "expression", function(source_expression) {
xml <- source_expression$xml_parsed_content
if (is.null(xml)) return(list())

Expand All @@ -123,5 +123,5 @@ assignment_linter <- function(allow_cascading_assign = TRUE,

lint_message <- sprintf(lint_message_fmt, operator)
xml_nodes_to_lints(bad_expr, source_expression, lint_message, type = "style")
}, linter_level = "expression")
})
}
4 changes: 2 additions & 2 deletions R/backport_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ backport_linter <- function(r_version = getRversion(), except = character()) {

names_xpath <- "//SYMBOL | //SYMBOL_FUNCTION_CALL"

Linter(function(source_expression) {
Linter(linter_level = "expression", function(source_expression) {
xml <- source_expression$xml_parsed_content
if (is.null(xml)) return(list())

Expand All @@ -72,7 +72,7 @@ backport_linter <- function(r_version = getRversion(), except = character()) {
lint_message = lint_message,
type = "warning"
)
}, linter_level = "expression")
})
}

normalize_r_version <- function(r_version) {
Expand Down
4 changes: 2 additions & 2 deletions R/boolean_arithmetic_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ boolean_arithmetic_linter <- function() {
")
any_xpath <- paste(length_xpath, "|", sum_xpath)

Linter(function(source_expression) {
Linter(linter_level = "expression", function(source_expression) {
xml <- source_expression$xml_parsed_content
if (is.null(xml)) return(list())

Expand All @@ -71,5 +71,5 @@ boolean_arithmetic_linter <- function() {
),
type = "warning"
)
}, linter_level = "expression")
})
}
4 changes: 2 additions & 2 deletions R/brace_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ brace_linter <- function(allow_single_line = FALSE) {
]
"

Linter(function(source_expression) {
Linter(linter_level = "expression", function(source_expression) {
xml <- source_expression$xml_parsed_content
if (is.null(xml)) return(list())
lints <- list()
Expand Down Expand Up @@ -208,5 +208,5 @@ brace_linter <- function(allow_single_line = FALSE) {
)

lints
}, linter_level = "expression")
})
}
4 changes: 2 additions & 2 deletions R/class_equals_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class_equals_linter <- function() {
]
"

Linter(function(source_expression) {
Linter(linter_level = "expression", function(source_expression) {
xml <- source_expression$xml_parsed_content
if (is.null(xml)) return(list())

Expand All @@ -61,5 +61,5 @@ class_equals_linter <- function() {
lint_message = lint_message,
type = "warning"
)
}, linter_level = "expression")
})
}
4 changes: 2 additions & 2 deletions R/commas_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ commas_linter <- function(allow_trailing = FALSE) {
"]"
)

Linter(function(source_expression) {
Linter(linter_level = "expression", function(source_expression) {
xml <- source_expression$xml_parsed_content
if (is.null(xml)) return(list())

Expand All @@ -98,5 +98,5 @@ commas_linter <- function(allow_trailing = FALSE) {
)

c(before_lints, after_lints)
}, linter_level = "expression")
})
}
5 changes: 3 additions & 2 deletions R/comment_linters.R
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ commented_code_linter <- function() {
anything
)
)
Linter(function(source_expression) {

Linter(linter_level = "file", function(source_expression) {
xml <- source_expression$full_xml_parsed_content
if (is.null(xml)) return(list())
all_comment_nodes <- xml_find_all(xml, "//COMMENT")
Expand Down Expand Up @@ -105,7 +106,7 @@ commented_code_linter <- function() {
}

lint_list
}, linter_level = "file")
})
}

# is given text parsable
Expand Down
5 changes: 2 additions & 3 deletions R/comparison_negation_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,12 @@ comparison_negation_linter <- function() {
]
")

Linter(function(source_expression) {
Linter(linter_level = "expression", function(source_expression) {
xml <- source_expression$xml_parsed_content
if (is.null(xml)) return(list())

bad_expr <- xml_find_all(xml, xpath)


comparator_node <- xml_find_first(bad_expr, "expr/expr/*[2]")
comparator_name <- xml_name(comparator_node)

Expand All @@ -85,5 +84,5 @@ comparison_negation_linter <- function() {
lint_message = glue("Use x {inverse} y, not !(x {comparator_text} y)."),
type = "warning"
)
}, linter_level = "expression")
})
}
4 changes: 2 additions & 2 deletions R/condition_message_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ condition_message_linter <- function() {
/parent::expr
")

Linter(function(source_expression) {
Linter(linter_level = "expression", function(source_expression) {
xml <- source_expression$xml_parsed_content
if (is.null(xml)) return(list())

Expand All @@ -72,5 +72,5 @@ condition_message_linter <- function() {
'(using "" as a separator). For translatable strings, prefer using gettextf().'
)
xml_nodes_to_lints(bad_expr, source_expression = source_expression, lint_message = lint_message, type = "warning")
}, linter_level = "expression")
})
}
4 changes: 2 additions & 2 deletions R/conjunct_test_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ conjunct_test_linter <- function(allow_named_stopifnot = TRUE,
/expr[AND]
")

Linter(function(source_expression) {
Linter(linter_level = "file", function(source_expression) {
# need the full file to also catch usages at the top level
xml <- source_expression$full_xml_parsed_content
if (is.null(xml)) return(list())
Expand Down Expand Up @@ -157,5 +157,5 @@ conjunct_test_linter <- function(allow_named_stopifnot = TRUE,
}

lints
}, linter_level = "file")
})
}
4 changes: 2 additions & 2 deletions R/consecutive_assertion_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ consecutive_assertion_linter <- function() {
]
"

Linter(function(source_expression) {
Linter(linter_level = "file", function(source_expression) {
# need the full file to also catch usages at the top level
xml <- source_expression$full_xml_parsed_content
if (is.null(xml)) return(list())
Expand All @@ -61,5 +61,5 @@ consecutive_assertion_linter <- function() {
lint_message = sprintf("Unify consecutive calls to %s().", matched_function),
type = "warning"
)
}, linter_level = "file")
})
}
4 changes: 2 additions & 2 deletions R/consecutive_mutate_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ consecutive_mutate_linter <- function(invalid_backends = "dbplyr") {
/following-sibling::expr[{ mutate_cond }]
")

Linter(function(source_expression) {
Linter(linter_level = "file", function(source_expression) {
# need the full file to also catch usages at the top level
xml <- source_expression$full_xml_parsed_content
if (is.null(xml)) return(list())
Expand All @@ -94,5 +94,5 @@ consecutive_mutate_linter <- function(invalid_backends = "dbplyr") {
lint_message = "Unify consecutive calls to mutate().",
type = "warning"
)
}, linter_level = "file")
})
}
4 changes: 2 additions & 2 deletions R/cyclocomp_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#' @seealso [linters] for a complete list of linters available in lintr.
#' @export
cyclocomp_linter <- function(complexity_limit = 15L) {
Linter(function(source_expression) {
Linter(linter_level = "expression", function(source_expression) {
complexity <- try_silently(
cyclocomp::cyclocomp(parse(text = source_expression$content))
)
Expand All @@ -42,5 +42,5 @@ cyclocomp_linter <- function(complexity_limit = 15L) {
ranges = list(rep(col1, 2L)),
line = source_expression$lines[1L]
)
}, linter_level = "expression")
})
}
4 changes: 2 additions & 2 deletions R/duplicate_argument_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ duplicate_argument_linter <- function(except = c("mutate", "transmute")) {
xpath_call_with_args <- "//EQ_SUB/parent::expr"
xpath_arg_name <- "./EQ_SUB/preceding-sibling::*[1]"

Linter(function(source_expression) {
Linter(linter_level = "file", function(source_expression) {
xml <- source_expression$full_xml_parsed_content
if (is.null(xml)) return(list())

Expand All @@ -61,5 +61,5 @@ duplicate_argument_linter <- function(except = c("mutate", "transmute")) {
lint_message = "Duplicate arguments in function call.",
type = "warning"
)
}, linter_level = "file")
})
}
4 changes: 2 additions & 2 deletions R/equals_na_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ equals_na_linter <- function() {
/parent::expr
")

Linter(function(source_expression) {
Linter(linter_level = "expression", function(source_expression) {
xml <- source_expression$xml_parsed_content
if (is.null(xml)) return(list())

Expand All @@ -58,5 +58,5 @@ equals_na_linter <- function() {
lint_message = "Use is.na for comparisons to NA (not == or != or %in%)",
type = "warning"
)
}, linter_level = "expression")
})
}
4 changes: 2 additions & 2 deletions R/expect_comparison_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ expect_comparison_linter <- function() {
`==` = "expect_identical"
)

Linter(function(source_expression) {
Linter(linter_level = "expression", function(source_expression) {
xml <- source_expression$xml_parsed_content
if (is.null(xml)) return(list())

Expand All @@ -73,5 +73,5 @@ expect_comparison_linter <- function() {
expectation <- comparator_expectation_map[comparator]
lint_message <- sprintf("%s(x, y) is better than expect_true(x %s y).", expectation, comparator)
xml_nodes_to_lints(bad_expr, source_expression, lint_message = lint_message, type = "warning")
}, linter_level = "expression")
})
}
4 changes: 2 additions & 2 deletions R/expect_identical_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ expect_identical_linter <- function() {
"
xpath <- paste(expect_equal_xpath, "|", expect_true_xpath)

Linter(function(source_expression) {
Linter(linter_level = "expression", function(source_expression) {
xml <- source_expression$xml_parsed_content
if (is.null(xml)) return(list())

Expand All @@ -95,5 +95,5 @@ expect_identical_linter <- function() {
),
type = "warning"
)
}, linter_level = "expression")
})
}
4 changes: 2 additions & 2 deletions R/expect_length_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ expect_length_linter <- function() {
/parent::expr[not(SYMBOL_SUB[text() = 'info' or contains(text(), 'label')])]
")

Linter(function(source_expression) {
Linter(linter_level = "expression", function(source_expression) {
xml <- source_expression$xml_parsed_content
if (is.null(xml)) return(list())

bad_expr <- xml_find_all(xml, xpath)
matched_function <- xp_call_name(bad_expr)
lint_message <- sprintf("expect_length(x, n) is better than %s(length(x), n)", matched_function)
xml_nodes_to_lints(bad_expr, source_expression, lint_message, type = "warning")
}, linter_level = "expression")
})
}
4 changes: 2 additions & 2 deletions R/expect_named_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ expect_named_linter <- function() {
/parent::expr
"

Linter(function(source_expression) {
Linter(linter_level = "expression", function(source_expression) {
xml <- source_expression$xml_parsed_content
if (is.null(xml)) return(list())

Expand All @@ -50,5 +50,5 @@ expect_named_linter <- function() {
lint_message <- sprintf("expect_named(x, n) is better than %s(names(x), n)", matched_function)

xml_nodes_to_lints(bad_expr, source_expression = source_expression, lint_message, type = "warning")
}, linter_level = "expression")
})
}
4 changes: 2 additions & 2 deletions R/expect_null_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ expect_null_linter <- function() {
"
xpath <- paste(expect_equal_identical_xpath, "|", expect_true_xpath)

Linter(function(source_expression) {
Linter(linter_level = "expression", function(source_expression) {
xml <- source_expression$xml_parsed_content
if (is.null(xml)) return(list())

Expand All @@ -71,5 +71,5 @@ expect_null_linter <- function() {
lint_message = msg,
type = "warning"
)
}, linter_level = "expression")
})
}
4 changes: 2 additions & 2 deletions R/expect_s3_class_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ expect_s3_class_linter <- function() {
")
xpath <- paste(expect_equal_identical_xpath, "|", expect_true_xpath)

Linter(function(source_expression) {
Linter(linter_level = "expression", function(source_expression) {
xml <- source_expression$xml_parsed_content
if (is.null(xml)) return(list())

Expand All @@ -86,5 +86,5 @@ expect_s3_class_linter <- function() {
lint_message = paste(msg, "Note also expect_s4_class() available for testing S4 objects."),
type = "warning"
)
}, linter_level = "expression")
})
}
Loading