diff --git a/R/T_and_F_symbol_linter.R b/R/T_and_F_symbol_linter.R index 89289880b..b6c1300c7 100644 --- a/R/T_and_F_symbol_linter.R +++ b/R/T_and_F_symbol_linter.R @@ -46,7 +46,7 @@ T_and_F_symbol_linter <- function() { # nolint: object_name. 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) bad_assignment <- xml_find_all(xml, assignment_xpath) diff --git a/R/any_duplicated_linter.R b/R/any_duplicated_linter.R index cb20da3f8..bb0351a96 100644 --- a/R/any_duplicated_linter.R +++ b/R/any_duplicated_linter.R @@ -87,7 +87,6 @@ any_duplicated_linter <- function() { Linter(linter_level = "expression", function(source_expression) { xml <- source_expression$xml_parsed_content - if (is.null(xml)) return(list()) any_duplicated_expr <- xml_find_all(xml, any_duplicated_xpath) any_duplicated_lints <- xml_nodes_to_lints( diff --git a/R/any_is_na_linter.R b/R/any_is_na_linter.R index ed0ce8639..1e01ff687 100644 --- a/R/any_is_na_linter.R +++ b/R/any_is_na_linter.R @@ -48,7 +48,6 @@ any_is_na_linter <- function() { 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) diff --git a/R/assignment_linter.R b/R/assignment_linter.R index ce2698119..da42b5119 100644 --- a/R/assignment_linter.R +++ b/R/assignment_linter.R @@ -101,7 +101,6 @@ assignment_linter <- function(allow_cascading_assign = TRUE, 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) if (length(bad_expr) == 0L) { diff --git a/R/backport_linter.R b/R/backport_linter.R index 7a37d80ff..8c46023fe 100644 --- a/R/backport_linter.R +++ b/R/backport_linter.R @@ -49,7 +49,6 @@ backport_linter <- function(r_version = getRversion(), except = character()) { Linter(linter_level = "expression", function(source_expression) { xml <- source_expression$xml_parsed_content - if (is.null(xml)) return(list()) all_names_nodes <- xml_find_all(xml, names_xpath) all_names <- xml_text(all_names_nodes) diff --git a/R/boolean_arithmetic_linter.R b/R/boolean_arithmetic_linter.R index 0dee92137..c6ef4158a 100644 --- a/R/boolean_arithmetic_linter.R +++ b/R/boolean_arithmetic_linter.R @@ -57,7 +57,6 @@ boolean_arithmetic_linter <- function() { Linter(linter_level = "expression", function(source_expression) { xml <- source_expression$xml_parsed_content - if (is.null(xml)) return(list()) any_expr <- xml_find_all(xml, any_xpath) diff --git a/R/brace_linter.R b/R/brace_linter.R index 417be0684..eebdb90ec 100644 --- a/R/brace_linter.R +++ b/R/brace_linter.R @@ -148,7 +148,7 @@ brace_linter <- function(allow_single_line = FALSE) { Linter(linter_level = "expression", function(source_expression) { xml <- source_expression$xml_parsed_content - if (is.null(xml)) return(list()) + lints <- list() lints <- c( diff --git a/R/class_equals_linter.R b/R/class_equals_linter.R index a210be31a..99b7dea56 100644 --- a/R/class_equals_linter.R +++ b/R/class_equals_linter.R @@ -46,7 +46,6 @@ class_equals_linter <- function() { 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) diff --git a/R/commas_linter.R b/R/commas_linter.R index af4226cee..aeaf42878 100644 --- a/R/commas_linter.R +++ b/R/commas_linter.R @@ -79,7 +79,6 @@ commas_linter <- function(allow_trailing = FALSE) { Linter(linter_level = "expression", function(source_expression) { xml <- source_expression$xml_parsed_content - if (is.null(xml)) return(list()) before_lints <- xml_nodes_to_lints( xml_find_all(xml, xpath_before), diff --git a/R/comment_linters.R b/R/comment_linters.R index e444a9b32..cc8ab06c2 100644 --- a/R/comment_linters.R +++ b/R/comment_linters.R @@ -78,7 +78,7 @@ commented_code_linter <- function() { 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") all_comments <- xml_text(all_comment_nodes) code_candidates <- re_matches(all_comments, code_candidate_regex, global = FALSE, locations = TRUE) diff --git a/R/comparison_negation_linter.R b/R/comparison_negation_linter.R index a1c83eaa8..f2c3424ab 100644 --- a/R/comparison_negation_linter.R +++ b/R/comparison_negation_linter.R @@ -62,7 +62,6 @@ comparison_negation_linter <- function() { 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) diff --git a/R/condition_call_linter.R b/R/condition_call_linter.R index b30ff24ae..2204d807f 100644 --- a/R/condition_call_linter.R +++ b/R/condition_call_linter.R @@ -85,7 +85,6 @@ condition_call_linter <- function(display_call = FALSE) { 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) diff --git a/R/condition_message_linter.R b/R/condition_message_linter.R index 1004f5161..9f33a6797 100644 --- a/R/condition_message_linter.R +++ b/R/condition_message_linter.R @@ -58,7 +58,6 @@ condition_message_linter <- function() { 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) sep_value <- get_r_string(bad_expr, xpath = "./expr/SYMBOL_SUB[text() = 'sep']/following-sibling::expr/STR_CONST") diff --git a/R/conjunct_test_linter.R b/R/conjunct_test_linter.R index b85804adc..7a920a392 100644 --- a/R/conjunct_test_linter.R +++ b/R/conjunct_test_linter.R @@ -119,7 +119,6 @@ conjunct_test_linter <- function(allow_named_stopifnot = TRUE, 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()) test_expr <- xml_find_all(xml, test_xpath) diff --git a/R/consecutive_assertion_linter.R b/R/consecutive_assertion_linter.R index 7f074f13b..c662f8cfa 100644 --- a/R/consecutive_assertion_linter.R +++ b/R/consecutive_assertion_linter.R @@ -50,7 +50,6 @@ consecutive_assertion_linter <- function() { 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()) bad_expr <- xml_find_all(xml, xpath) diff --git a/R/consecutive_mutate_linter.R b/R/consecutive_mutate_linter.R index 40e061fe3..5aec97fa6 100644 --- a/R/consecutive_mutate_linter.R +++ b/R/consecutive_mutate_linter.R @@ -74,7 +74,6 @@ consecutive_mutate_linter <- function(invalid_backends = "dbplyr") { 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()) attach_str <- get_r_string(xml_find_all(xml, attach_pkg_xpath)) if (any(invalid_backends %in% attach_str)) { diff --git a/R/duplicate_argument_linter.R b/R/duplicate_argument_linter.R index d152d9e3f..d4241b299 100644 --- a/R/duplicate_argument_linter.R +++ b/R/duplicate_argument_linter.R @@ -49,7 +49,6 @@ duplicate_argument_linter <- function(except = c("mutate", "transmute")) { Linter(linter_level = "file", function(source_expression) { xml <- source_expression$full_xml_parsed_content - if (is.null(xml)) return(list()) call_expr <- xml_find_all(xml, xpath_call_with_args) diff --git a/R/equals_na_linter.R b/R/equals_na_linter.R index 8f9084f9d..8a1ceabdc 100644 --- a/R/equals_na_linter.R +++ b/R/equals_na_linter.R @@ -48,7 +48,6 @@ equals_na_linter <- function() { 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) diff --git a/R/expect_comparison_linter.R b/R/expect_comparison_linter.R index b4ef31934..fe93b5908 100644 --- a/R/expect_comparison_linter.R +++ b/R/expect_comparison_linter.R @@ -65,7 +65,6 @@ expect_comparison_linter <- function() { 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) diff --git a/R/expect_identical_linter.R b/R/expect_identical_linter.R index 7a551a746..6293786f6 100644 --- a/R/expect_identical_linter.R +++ b/R/expect_identical_linter.R @@ -83,7 +83,6 @@ expect_identical_linter <- function() { 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) xml_nodes_to_lints( diff --git a/R/expect_length_linter.R b/R/expect_length_linter.R index 66626cdf0..7d170d71c 100644 --- a/R/expect_length_linter.R +++ b/R/expect_length_linter.R @@ -34,7 +34,6 @@ expect_length_linter <- function() { 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) diff --git a/R/expect_named_linter.R b/R/expect_named_linter.R index 802076fc8..9d86a9a57 100644 --- a/R/expect_named_linter.R +++ b/R/expect_named_linter.R @@ -43,7 +43,6 @@ expect_named_linter <- function() { 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) diff --git a/R/expect_null_linter.R b/R/expect_null_linter.R index 4f04e071d..dd51fa352 100644 --- a/R/expect_null_linter.R +++ b/R/expect_null_linter.R @@ -55,7 +55,6 @@ expect_null_linter <- function() { 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) diff --git a/R/expect_s3_class_linter.R b/R/expect_s3_class_linter.R index 3bd028f7c..e4051b050 100644 --- a/R/expect_s3_class_linter.R +++ b/R/expect_s3_class_linter.R @@ -71,7 +71,6 @@ expect_s3_class_linter <- function() { 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) diff --git a/R/expect_s4_class_linter.R b/R/expect_s4_class_linter.R index 77ce252ed..4ef021a7e 100644 --- a/R/expect_s4_class_linter.R +++ b/R/expect_s4_class_linter.R @@ -34,7 +34,6 @@ expect_s4_class_linter <- function() { Linter(linter_level = "expression", function(source_expression) { xml <- source_expression$xml_parsed_content - if (is.null(xml)) return(list()) # TODO(michaelchirico): also catch expect_{equal,identical}(methods::is(x), k). # this seems empirically rare, but didn't check many S4-heavy packages. diff --git a/R/expect_true_false_linter.R b/R/expect_true_false_linter.R index 8f7b384ed..6df426579 100644 --- a/R/expect_true_false_linter.R +++ b/R/expect_true_false_linter.R @@ -41,7 +41,6 @@ expect_true_false_linter <- function() { 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) diff --git a/R/expect_type_linter.R b/R/expect_type_linter.R index 30174c6fd..17f81c6d1 100644 --- a/R/expect_type_linter.R +++ b/R/expect_type_linter.R @@ -61,7 +61,6 @@ expect_type_linter <- function() { 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) diff --git a/R/extraction_operator_linter.R b/R/extraction_operator_linter.R index fe95630cb..b4903e459 100644 --- a/R/extraction_operator_linter.R +++ b/R/extraction_operator_linter.R @@ -63,7 +63,7 @@ extraction_operator_linter <- function() { Linter(linter_level = "expression", function(source_expression) { xml <- source_expression$xml_parsed_content - if (is.null(xml)) return(list()) + bad_exprs <- xml_find_all(xml, xpath) msgs <- sprintf("Use `[[` instead of `%s` to extract an element.", xml_text(bad_exprs)) diff --git a/R/fixed_regex_linter.R b/R/fixed_regex_linter.R index 5c456683c..a1798de02 100644 --- a/R/fixed_regex_linter.R +++ b/R/fixed_regex_linter.R @@ -141,7 +141,6 @@ fixed_regex_linter <- function(allow_unescaped = FALSE) { Linter(linter_level = "expression", function(source_expression) { xml <- source_expression$xml_parsed_content - if (is.null(xml)) return(list()) patterns <- xml_find_all(xml, xpath) pattern_strings <- get_r_string(patterns) diff --git a/R/function_argument_linter.R b/R/function_argument_linter.R index 7268eac9a..921e002b2 100644 --- a/R/function_argument_linter.R +++ b/R/function_argument_linter.R @@ -61,7 +61,6 @@ function_argument_linter <- function() { 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) diff --git a/R/function_left_parentheses_linter.R b/R/function_left_parentheses_linter.R index 176e5f9ea..07e4ee438 100644 --- a/R/function_left_parentheses_linter.R +++ b/R/function_left_parentheses_linter.R @@ -59,7 +59,6 @@ function_left_parentheses_linter <- function() { # nolint: object_length. Linter(linter_level = "expression", function(source_expression) { xml <- source_expression$xml_parsed_content - if (is.null(xml)) return(list()) bad_line_fun_exprs <- xml_find_all(xml, bad_line_fun_xpath) bad_line_fun_lints <- xml_nodes_to_lints( diff --git a/R/if_not_else_linter.R b/R/if_not_else_linter.R index 58ffa214b..9985d7a1e 100644 --- a/R/if_not_else_linter.R +++ b/R/if_not_else_linter.R @@ -85,7 +85,6 @@ if_not_else_linter <- function(exceptions = c("is.null", "is.na", "missing")) { Linter(linter_level = "expression", function(source_expression) { xml <- source_expression$xml_parsed_content - if (is.null(xml)) return(list()) if_expr <- xml_find_all(xml, if_xpath) if_lints <- xml_nodes_to_lints( diff --git a/R/if_switch_linter.R b/R/if_switch_linter.R index 0d21dd209..97b985dac 100644 --- a/R/if_switch_linter.R +++ b/R/if_switch_linter.R @@ -63,7 +63,6 @@ if_switch_linter <- function() { 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) diff --git a/R/ifelse_censor_linter.R b/R/ifelse_censor_linter.R index 11bd7dd7e..ce27eac8a 100644 --- a/R/ifelse_censor_linter.R +++ b/R/ifelse_censor_linter.R @@ -48,7 +48,6 @@ ifelse_censor_linter <- function() { 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) diff --git a/R/implicit_assignment_linter.R b/R/implicit_assignment_linter.R index c62960c57..db7ed5ba9 100644 --- a/R/implicit_assignment_linter.R +++ b/R/implicit_assignment_linter.R @@ -105,7 +105,6 @@ implicit_assignment_linter <- function(except = c("bquote", "expression", "expr" 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()) bad_expr <- xml_find_all(xml, xpath) diff --git a/R/implicit_integer_linter.R b/R/implicit_integer_linter.R index 5dae749a8..b41210fa0 100644 --- a/R/implicit_integer_linter.R +++ b/R/implicit_integer_linter.R @@ -53,7 +53,6 @@ implicit_integer_linter <- function(allow_colon = FALSE) { } Linter(linter_level = "file", function(source_expression) { xml <- source_expression$full_xml_parsed_content - if (is.null(xml)) return(list()) numbers <- xml_find_all(xml, xpath) diff --git a/R/indentation_linter.R b/R/indentation_linter.R index 066f19899..4c968ffff 100644 --- a/R/indentation_linter.R +++ b/R/indentation_linter.R @@ -213,7 +213,7 @@ indentation_linter <- function(indent = 2L, hanging_indent_style = c("tidy", "al # will have "# comment" as a separate expression xml <- source_expression$full_xml_parsed_content - if (is.null(xml)) return(list()) + # Indentation increases by 1 for: # - { } blocks that span multiple lines # - ( ), [ ], or [[ ]] calls that span multiple lines diff --git a/R/infix_spaces_linter.R b/R/infix_spaces_linter.R index 13b3c4cc9..c7fa7bb1b 100644 --- a/R/infix_spaces_linter.R +++ b/R/infix_spaces_linter.R @@ -107,7 +107,7 @@ infix_spaces_linter <- function(exclude_operators = NULL, allow_multiple_spaces 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) xml_nodes_to_lints( diff --git a/R/inner_combine_linter.R b/R/inner_combine_linter.R index fddd15fd8..9b466a5aa 100644 --- a/R/inner_combine_linter.R +++ b/R/inner_combine_linter.R @@ -85,7 +85,6 @@ inner_combine_linter <- function() { 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) diff --git a/R/is_numeric_linter.R b/R/is_numeric_linter.R index c9d22103d..7acc08a3e 100644 --- a/R/is_numeric_linter.R +++ b/R/is_numeric_linter.R @@ -71,7 +71,6 @@ is_numeric_linter <- function() { Linter(linter_level = "expression", function(source_expression) { xml <- source_expression$xml_parsed_content - if (is.null(xml)) return(list()) or_expr <- xml_find_all(xml, or_xpath) or_lints <- xml_nodes_to_lints( diff --git a/R/keyword_quote_linter.R b/R/keyword_quote_linter.R index ee2b22ec3..836c7cc1a 100644 --- a/R/keyword_quote_linter.R +++ b/R/keyword_quote_linter.R @@ -96,7 +96,6 @@ keyword_quote_linter <- function() { Linter(linter_level = "expression", function(source_expression) { xml <- source_expression$xml_parsed_content - if (is.null(xml)) return(list()) call_arg_expr <- xml_find_all(xml, call_arg_xpath) diff --git a/R/length_test_linter.R b/R/length_test_linter.R index 901d04462..724b53f0d 100644 --- a/R/length_test_linter.R +++ b/R/length_test_linter.R @@ -29,7 +29,6 @@ length_test_linter <- function() { 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) expr_parts <- vapply(lapply(bad_expr, xml_find_all, "expr[2]/*"), xml_text, character(3L)) diff --git a/R/library_call_linter.R b/R/library_call_linter.R index aa7b0ba40..aa311039c 100644 --- a/R/library_call_linter.R +++ b/R/library_call_linter.R @@ -147,7 +147,6 @@ library_call_linter <- function(allow_preamble = TRUE) { Linter(linter_level = "file", function(source_expression) { xml <- source_expression$full_xml_parsed_content - if (is.null(xml)) return(list()) upfront_call_expr <- xml_find_all(xml, upfront_call_xpath) diff --git a/R/list_comparison_linter.R b/R/list_comparison_linter.R index c1676c120..02ed9dcd2 100644 --- a/R/list_comparison_linter.R +++ b/R/list_comparison_linter.R @@ -41,7 +41,6 @@ list_comparison_linter <- function() { 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) diff --git a/R/literal_coercion_linter.R b/R/literal_coercion_linter.R index 5cc230376..734ed85c4 100644 --- a/R/literal_coercion_linter.R +++ b/R/literal_coercion_linter.R @@ -75,7 +75,6 @@ literal_coercion_linter <- function() { 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) diff --git a/R/make_linter_from_xpath.R b/R/make_linter_from_xpath.R index ded1fd921..f539308c7 100644 --- a/R/make_linter_from_xpath.R +++ b/R/make_linter_from_xpath.R @@ -25,7 +25,7 @@ make_linter_from_xpath <- function(xpath, function() { Linter(linter_level = level, function(source_expression) { xml <- source_expression[[xml_key]] - if (is.null(xml)) return(list()) + expr <- xml_find_all(xml, xpath) diff --git a/R/matrix_apply_linter.R b/R/matrix_apply_linter.R index 7b3bb29e9..33a845aa2 100644 --- a/R/matrix_apply_linter.R +++ b/R/matrix_apply_linter.R @@ -78,7 +78,6 @@ matrix_apply_linter <- function() { 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) diff --git a/R/missing_argument_linter.R b/R/missing_argument_linter.R index 9c23ffcb0..93b36e10d 100644 --- a/R/missing_argument_linter.R +++ b/R/missing_argument_linter.R @@ -48,7 +48,6 @@ missing_argument_linter <- function(except = c("alist", "quote", "switch"), allo Linter(linter_level = "file", function(source_expression) { xml <- source_expression$full_xml_parsed_content - if (is.null(xml)) return(list()) missing_args <- xml_find_all(xml, xpath) function_call_name <- get_r_string(xml_find_chr(missing_args, to_function_xpath)) diff --git a/R/missing_package_linter.R b/R/missing_package_linter.R index c056f1333..aac6bda9e 100644 --- a/R/missing_package_linter.R +++ b/R/missing_package_linter.R @@ -44,7 +44,6 @@ missing_package_linter <- function() { Linter(linter_level = "file", function(source_expression) { xml <- source_expression$full_xml_parsed_content - if (is.null(xml)) return(list()) pkg_calls <- xml_find_all(xml, call_xpath) pkg_names <- get_r_string(xml_find_all( diff --git a/R/namespace_linter.R b/R/namespace_linter.R index d709e6b38..d6579a86a 100644 --- a/R/namespace_linter.R +++ b/R/namespace_linter.R @@ -41,7 +41,6 @@ namespace_linter <- function(check_exports = TRUE, check_nonexports = TRUE) { Linter(linter_level = "file", function(source_expression) { xml <- source_expression$full_xml_parsed_content - if (is.null(xml)) return(list()) ns_nodes <- xml_find_all(xml, "//NS_GET | //NS_GET_INT") diff --git a/R/nested_ifelse_linter.R b/R/nested_ifelse_linter.R index 8657333ff..b783f52f5 100644 --- a/R/nested_ifelse_linter.R +++ b/R/nested_ifelse_linter.R @@ -88,7 +88,6 @@ nested_ifelse_linter <- function() { 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) diff --git a/R/nested_pipe_linter.R b/R/nested_pipe_linter.R index a7a8c323b..fd595b233 100644 --- a/R/nested_pipe_linter.R +++ b/R/nested_pipe_linter.R @@ -69,7 +69,6 @@ nested_pipe_linter <- function( 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) diff --git a/R/nzchar_linter.R b/R/nzchar_linter.R index f15b4d88f..f0073ca9e 100644 --- a/R/nzchar_linter.R +++ b/R/nzchar_linter.R @@ -94,7 +94,6 @@ nzchar_linter <- function() { Linter(linter_level = "expression", function(source_expression) { xml <- source_expression$xml_parsed_content - if (is.null(xml)) return(list()) comparison_expr <- xml_find_all(xml, comparison_xpath) comparison_lints <- xml_nodes_to_lints( diff --git a/R/object_length_linter.R b/R/object_length_linter.R index ced9a13e9..0109856bb 100644 --- a/R/object_length_linter.R +++ b/R/object_length_linter.R @@ -39,7 +39,6 @@ object_length_linter <- function(length = 30L) { Linter(linter_level = "file", function(source_expression) { xml <- source_expression$full_xml_parsed_content - if (is.null(xml)) return(list()) assignments <- xml_find_all(xml, object_name_xpath) diff --git a/R/object_name_linter.R b/R/object_name_linter.R index f8e5e6422..90e28b487 100644 --- a/R/object_name_linter.R +++ b/R/object_name_linter.R @@ -112,7 +112,6 @@ object_name_linter <- function(styles = c("snake_case", "symbols"), regexes = ch Linter(linter_level = "file", function(source_expression) { xml <- source_expression$full_xml_parsed_content - if (is.null(xml)) return(list()) assignments <- xml_find_all(xml, object_name_xpath) diff --git a/R/object_overwrite_linter.R b/R/object_overwrite_linter.R index 3f43fba69..6c2eaa27d 100644 --- a/R/object_overwrite_linter.R +++ b/R/object_overwrite_linter.R @@ -95,7 +95,6 @@ object_overwrite_linter <- function( Linter(linter_level = "expression", function(source_expression) { xml <- source_expression$xml_parsed_content - if (is.null(xml)) return(list()) assigned_exprs <- xml_find_all(xml, xpath_assignments) assigned_symbols <- get_r_string(assigned_exprs, "SYMBOL|STR_CONST") diff --git a/R/object_usage_linter.R b/R/object_usage_linter.R index dcf41e449..5d222e232 100644 --- a/R/object_usage_linter.R +++ b/R/object_usage_linter.R @@ -58,7 +58,6 @@ object_usage_linter <- function(interpret_glue = TRUE, skip_with = TRUE) { declared_globals <- try_silently(globalVariables(package = pkg_name %||% globalenv())) xml <- source_expression$full_xml_parsed_content - if (is.null(xml)) return(list()) # run the following at run-time, not "compile" time to allow package structure to change env <- make_check_env(pkg_name, xml) diff --git a/R/one_call_pipe_linter.R b/R/one_call_pipe_linter.R index ab27e5172..b11e3a7b7 100644 --- a/R/one_call_pipe_linter.R +++ b/R/one_call_pipe_linter.R @@ -67,7 +67,6 @@ one_call_pipe_linter <- function() { 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) pipe <- xml_find_chr(bad_expr, "string(SPECIAL | PIPE)") diff --git a/R/outer_negation_linter.R b/R/outer_negation_linter.R index a6338c5a1..a68134db4 100644 --- a/R/outer_negation_linter.R +++ b/R/outer_negation_linter.R @@ -52,7 +52,6 @@ outer_negation_linter <- function() { 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) diff --git a/R/package_hooks_linter.R b/R/package_hooks_linter.R index 1234109c0..112d84210 100644 --- a/R/package_hooks_linter.R +++ b/R/package_hooks_linter.R @@ -128,7 +128,6 @@ package_hooks_linter <- function() { Linter(linter_level = "file", function(source_expression) { xml <- source_expression$full_xml_parsed_content - if (is.null(xml)) return(list()) any_hook <- xml_find_first(xml, any_hook_xpath) if (is.na(any_hook)) { diff --git a/R/paste_linter.R b/R/paste_linter.R index 802c078ef..57ebcfb93 100644 --- a/R/paste_linter.R +++ b/R/paste_linter.R @@ -163,7 +163,7 @@ paste_linter <- function(allow_empty_sep = FALSE, Linter(linter_level = "expression", function(source_expression) { xml <- source_expression$xml_parsed_content - if (is.null(xml)) return(list()) + optional_lints <- list() # Both of these look for paste(..., sep = "..."), differing in which 'sep' is linted, diff --git a/R/pipe_call_linter.R b/R/pipe_call_linter.R index 5f2723999..e0b55279e 100644 --- a/R/pipe_call_linter.R +++ b/R/pipe_call_linter.R @@ -28,7 +28,6 @@ pipe_call_linter <- function() { 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) pipe <- xml_text(xml_find_first(bad_expr, "preceding-sibling::SPECIAL[1]")) diff --git a/R/pipe_consistency_linter.R b/R/pipe_consistency_linter.R index 85b429aa4..323e0ef78 100644 --- a/R/pipe_consistency_linter.R +++ b/R/pipe_consistency_linter.R @@ -40,7 +40,6 @@ pipe_consistency_linter <- function(pipe = c("auto", "%>%", "|>")) { Linter(linter_level = "file", function(source_expression) { xml <- source_expression$full_xml_parsed_content - if (is.null(xml)) return(list()) match_magrittr <- xml_find_all(xml, xpath_magrittr) match_native <- xml_find_all(xml, xpath_native) diff --git a/R/pipe_continuation_linter.R b/R/pipe_continuation_linter.R index aabe58f77..10d55b548 100644 --- a/R/pipe_continuation_linter.R +++ b/R/pipe_continuation_linter.R @@ -69,7 +69,6 @@ pipe_continuation_linter <- function() { Linter(linter_level = "file", function(source_expression) { xml <- source_expression$full_xml_parsed_content - if (is.null(xml)) return(list()) pipe_exprs <- xml_find_all(xml, xpath) pipe_text <- xml_text(pipe_exprs) diff --git a/R/quotes_linter.R b/R/quotes_linter.R index e93ca7a7b..10099463e 100644 --- a/R/quotes_linter.R +++ b/R/quotes_linter.R @@ -62,7 +62,7 @@ quotes_linter <- function(delimiter = c('"', "'")) { Linter(linter_level = "expression", function(source_expression) { xml <- source_expression$xml_parsed_content - if (is.null(xml)) return(list()) + string_exprs <- xml_find_all(xml, "//STR_CONST") is_bad <- re_matches(xml_text(string_exprs), quote_regex) diff --git a/R/redundant_equals_linter.R b/R/redundant_equals_linter.R index d8087400e..48d524c5b 100644 --- a/R/redundant_equals_linter.R +++ b/R/redundant_equals_linter.R @@ -45,7 +45,6 @@ redundant_equals_linter <- function() { 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) op <- xml_text(xml_find_first(bad_expr, "*[2]")) diff --git a/R/redundant_ifelse_linter.R b/R/redundant_ifelse_linter.R index 81acb5c33..57be2b34c 100644 --- a/R/redundant_ifelse_linter.R +++ b/R/redundant_ifelse_linter.R @@ -72,7 +72,7 @@ redundant_ifelse_linter <- function(allow10 = FALSE) { Linter(linter_level = "expression", function(source_expression) { xml <- source_expression$xml_parsed_content - if (is.null(xml)) return(list()) + lints <- list() tf_expr <- xml_find_all(xml, tf_xpath) diff --git a/R/regex_subset_linter.R b/R/regex_subset_linter.R index 619c53764..556a2beaf 100644 --- a/R/regex_subset_linter.R +++ b/R/regex_subset_linter.R @@ -69,7 +69,6 @@ regex_subset_linter <- function() { Linter(linter_level = "expression", function(source_expression) { xml <- source_expression$xml_parsed_content - if (is.null(xml)) return(list()) grep_expr <- xml_find_all(xml, grep_xpath) diff --git a/R/repeat_linter.R b/R/repeat_linter.R index 8bb0e30c1..877ff0da7 100644 --- a/R/repeat_linter.R +++ b/R/repeat_linter.R @@ -24,7 +24,7 @@ repeat_linter <- function() { Linter(linter_level = "expression", function(source_expression) { xml <- source_expression$xml_parsed_content - if (is.null(xml)) return(list()) + lints <- xml_find_all(xml, xpath) xml_nodes_to_lints( diff --git a/R/return_linter.R b/R/return_linter.R index 758a26be8..4094ca755 100644 --- a/R/return_linter.R +++ b/R/return_linter.R @@ -130,7 +130,6 @@ return_linter <- function( Linter(linter_level = "expression", function(source_expression) { xml <- source_expression$xml_parsed_content - if (is.null(xml)) return(list()) body_expr <- xml_find_all(xml, body_xpath) diff --git a/R/sample_int_linter.R b/R/sample_int_linter.R index ef76d178b..a797f29df 100644 --- a/R/sample_int_linter.R +++ b/R/sample_int_linter.R @@ -67,7 +67,6 @@ sample_int_linter <- function() { 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) first_call <- xp_call_name(bad_expr, depth = 2L) diff --git a/R/scalar_in_linter.R b/R/scalar_in_linter.R index fb8340942..77ca70285 100644 --- a/R/scalar_in_linter.R +++ b/R/scalar_in_linter.R @@ -39,7 +39,6 @@ scalar_in_linter <- function() { 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) in_op <- xml_find_chr(bad_expr, "string(SPECIAL)") diff --git a/R/semicolon_linter.R b/R/semicolon_linter.R index 4feca5b95..5faf5e12c 100644 --- a/R/semicolon_linter.R +++ b/R/semicolon_linter.R @@ -87,7 +87,7 @@ semicolon_linter <- function(allow_compound = FALSE, allow_trailing = FALSE) { Linter(linter_level = "file", function(source_expression) { xml <- source_expression$full_xml_parsed_content - if (is.null(xml)) return(list()) + bad_exprs <- xml_find_all(xml, xpath) if (need_detection) { is_trailing <- is.na(xml_find_first(bad_exprs, compound_xpath)) diff --git a/R/seq_linter.R b/R/seq_linter.R index a2e08523c..5c4bb6c13 100644 --- a/R/seq_linter.R +++ b/R/seq_linter.R @@ -88,7 +88,6 @@ seq_linter <- function() { Linter(linter_level = "expression", function(source_expression) { xml <- source_expression$xml_parsed_content - if (is.null(xml)) return(list()) badx <- xml_find_all(xml, xpath) diff --git a/R/settings.R b/R/settings.R index d696ad4a1..167fcd6ac 100644 --- a/R/settings.R +++ b/R/settings.R @@ -37,7 +37,7 @@ #' whereas the DCF approach requires somewhat awkward formatting of parseable R code within #' valid DCF key-value pairs. The main disadvantage of the R file is it might be _too_ flexible, #' with users tempted to write configs with side effects causing hard-to-detect bugs or -#" otherwise "abusing" the ability to evaluate generic R code. Other recursive key-value stores +# " otherwise "abusing" the ability to evaluate generic R code. Other recursive key-value stores #' like YAML could work, but require new dependencies and are harder to parse #' both programmatically and visually. #' Here is an example of a `.lintr.R` file: diff --git a/R/sort_linter.R b/R/sort_linter.R index 7a3b4315f..6691f8494 100644 --- a/R/sort_linter.R +++ b/R/sort_linter.R @@ -100,7 +100,6 @@ sort_linter <- function() { Linter(linter_level = "expression", function(source_expression) { xml <- source_expression$xml_parsed_content - if (is.null(xml)) return(list()) order_expr <- xml_find_all(xml, order_xpath) diff --git a/R/spaces_inside_linter.R b/R/spaces_inside_linter.R index 6c1826678..7d114883c 100644 --- a/R/spaces_inside_linter.R +++ b/R/spaces_inside_linter.R @@ -54,7 +54,6 @@ spaces_inside_linter <- function() { Linter(linter_level = "file", function(source_expression) { xml <- source_expression$full_xml_parsed_content - if (is.null(xml)) return(list()) left_expr <- xml_find_all(xml, left_xpath) left_msg <- ifelse( diff --git a/R/sprintf_linter.R b/R/sprintf_linter.R index d0f24f0fb..ac8e7de23 100644 --- a/R/sprintf_linter.R +++ b/R/sprintf_linter.R @@ -106,7 +106,6 @@ sprintf_linter <- function() { Linter(linter_level = "file", function(source_expression) { xml <- source_expression$full_xml_parsed_content - if (is.null(xml)) return(list()) sprintf_calls <- xml_find_all(xml, call_xpath) diff --git a/R/string_boundary_linter.R b/R/string_boundary_linter.R index 6121061e9..becc64bec 100644 --- a/R/string_boundary_linter.R +++ b/R/string_boundary_linter.R @@ -144,7 +144,7 @@ string_boundary_linter <- function(allow_grepl = FALSE) { Linter(linter_level = "expression", function(source_expression) { xml <- source_expression$xml_parsed_content - if (is.null(xml)) return(list()) + lints <- list() str_detect_lint_data <- get_regex_lint_data(xml, str_detect_xpath) @@ -153,7 +153,7 @@ string_boundary_linter <- function(allow_grepl = FALSE) { lints <- c(lints, xml_nodes_to_lints( str_detect_lint_data$lint_expr, source_expression = source_expression, - lint_message = paste(str_detect_lint_message, "Doing so is more readable and more efficient."), + lint_message = paste(str_detect_lint_message, "Doing so is more readable and more efficient."), type = "warning" )) @@ -164,7 +164,7 @@ string_boundary_linter <- function(allow_grepl = FALSE) { lints <- c(lints, xml_nodes_to_lints( grepl_lint_data$lint_expr, source_expression = source_expression, - lint_message = paste(grepl_lint_message, "Doing so is more readable and more efficient."), + lint_message = paste(grepl_lint_message, "Doing so is more readable and more efficient."), type = "warning" )) } diff --git a/R/strings_as_factors_linter.R b/R/strings_as_factors_linter.R index 97522182c..ae9a3787b 100644 --- a/R/strings_as_factors_linter.R +++ b/R/strings_as_factors_linter.R @@ -84,7 +84,6 @@ strings_as_factors_linter <- function() { 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) diff --git a/R/system_file_linter.R b/R/system_file_linter.R index 0e8081c5d..3ff20dfca 100644 --- a/R/system_file_linter.R +++ b/R/system_file_linter.R @@ -36,7 +36,6 @@ system_file_linter <- function() { 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) diff --git a/R/undesirable_function_linter.R b/R/undesirable_function_linter.R index 3b4f225bc..c96604179 100644 --- a/R/undesirable_function_linter.R +++ b/R/undesirable_function_linter.R @@ -84,7 +84,7 @@ undesirable_function_linter <- function(fun = default_undesirable_functions, Linter(linter_level = "expression", function(source_expression) { xml <- source_expression$xml_parsed_content - if (is.null(xml)) return(list()) + matched_nodes <- xml_find_all(xml, xpath) fun_names <- get_r_string(matched_nodes) diff --git a/R/undesirable_operator_linter.R b/R/undesirable_operator_linter.R index 483149119..734e6c485 100644 --- a/R/undesirable_operator_linter.R +++ b/R/undesirable_operator_linter.R @@ -68,7 +68,6 @@ undesirable_operator_linter <- function(op = default_undesirable_operators) { Linter(linter_level = "expression", function(source_expression) { xml <- source_expression$xml_parsed_content - if (is.null(xml)) return(list()) bad_op <- xml_find_all(xml, xpath) diff --git a/R/unnecessary_concatenation_linter.R b/R/unnecessary_concatenation_linter.R index 05a4f51ae..092b78b67 100644 --- a/R/unnecessary_concatenation_linter.R +++ b/R/unnecessary_concatenation_linter.R @@ -98,7 +98,7 @@ unnecessary_concatenation_linter <- function(allow_single_expression = TRUE) { # Linter(linter_level = "expression", function(source_expression) { xml <- source_expression$xml_parsed_content - if (is.null(xml)) return(list()) + c_calls <- xml_find_all(xml, call_xpath) # bump count(args) by 1 if inside a pipeline diff --git a/R/unnecessary_lambda_linter.R b/R/unnecessary_lambda_linter.R index 023867d59..3b956d8e2 100644 --- a/R/unnecessary_lambda_linter.R +++ b/R/unnecessary_lambda_linter.R @@ -161,7 +161,6 @@ unnecessary_lambda_linter <- function(allow_comparison = FALSE) { Linter(linter_level = "expression", function(source_expression) { xml <- source_expression$xml_parsed_content - if (is.null(xml)) return(list()) default_fun_expr <- xml_find_all(xml, default_fun_xpath) diff --git a/R/unnecessary_nesting_linter.R b/R/unnecessary_nesting_linter.R index a7676c37b..fdd2a4798 100644 --- a/R/unnecessary_nesting_linter.R +++ b/R/unnecessary_nesting_linter.R @@ -143,7 +143,6 @@ unnecessary_nesting_linter <- function(allow_assignment = TRUE) { Linter(linter_level = "expression", function(source_expression) { xml <- source_expression$xml_parsed_content - if (is.null(xml)) return(list()) if_else_exit_expr <- xml_find_all(xml, if_else_exit_xpath) if_else_exit_lints <- xml_nodes_to_lints( diff --git a/R/unnecessary_placeholder_linter.R b/R/unnecessary_placeholder_linter.R index cc31cef3c..9e546326d 100644 --- a/R/unnecessary_placeholder_linter.R +++ b/R/unnecessary_placeholder_linter.R @@ -51,7 +51,6 @@ unnecessary_placeholder_linter <- function() { 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) diff --git a/R/unreachable_code_linter.R b/R/unreachable_code_linter.R index 32ed5e696..124b5a12f 100644 --- a/R/unreachable_code_linter.R +++ b/R/unreachable_code_linter.R @@ -136,7 +136,6 @@ unreachable_code_linter <- function(allow_comment_regex = getOption("covr.exclud Linter(linter_level = "expression", function(source_expression) { xml <- source_expression$xml_parsed_content - if (is.null(xml)) return(list()) # run here because 'settings$exclude_end' may not be set correctly at "compile time". # also build with '|', not rex::rex(or(.)), the latter which will double-escape the regex. diff --git a/R/unused_import_linter.R b/R/unused_import_linter.R index 504fb2bcc..4850030b4 100644 --- a/R/unused_import_linter.R +++ b/R/unused_import_linter.R @@ -76,7 +76,6 @@ unused_import_linter <- function(allow_ns_usage = FALSE, Linter(linter_level = "file", function(source_expression) { xml <- source_expression$full_xml_parsed_content - if (is.null(xml)) return(list()) import_exprs <- xml_find_all(xml, import_xpath) if (length(import_exprs) == 0L) { diff --git a/R/vector_logic_linter.R b/R/vector_logic_linter.R index 1cac35b1f..1b18ceda0 100644 --- a/R/vector_logic_linter.R +++ b/R/vector_logic_linter.R @@ -83,7 +83,7 @@ vector_logic_linter <- function() { 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) op <- xml_text(bad_expr) diff --git a/R/with_id.R b/R/with_id.R index 3380d432c..c8ae5149a 100644 --- a/R/with_id.R +++ b/R/with_id.R @@ -1,4 +1,3 @@ - #' Extract row by ID #' #' @describeIn ids_with_token diff --git a/R/yoda_test_linter.R b/R/yoda_test_linter.R index bff26a46e..56163b4da 100644 --- a/R/yoda_test_linter.R +++ b/R/yoda_test_linter.R @@ -57,7 +57,6 @@ yoda_test_linter <- function() { 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) diff --git a/tests/testthat/test-get_source_expressions.R b/tests/testthat/test-get_source_expressions.R index add9c3538..5d60abfae 100644 --- a/tests/testthat/test-get_source_expressions.R +++ b/tests/testthat/test-get_source_expressions.R @@ -371,10 +371,18 @@ patrick::with_parameters_test_that( linter <- eval(call(linter)) } expression <- expressions[[expression_idx]] - expect_no_warning({ - lints <- linter(expression) - }) - expect_length(lints, 0L) + is_valid_linter_level <- + (is_linter_level(linter, "expression") && is_lint_level(expression, "expression")) || + (is_linter_level(linter, "file") && is_lint_level(expression, "file")) + if (is_valid_linter_level) { + expect_no_warning({ + lints <- linter(expression) + }) + expect_length(lints, 0L) + } else { + # suppress "empty test" skips + expect_true(TRUE) + } }, .test_name = param_df$.test_name, linter = param_df$linter,