-
Notifications
You must be signed in to change notification settings - Fork 188
Open
Labels
internalsIssues related to inner workings of lintr, i.e., not user-visibleIssues related to inner workings of lintr, i.e., not user-visible
Description
The need to spell out specific arguments is pretty brittle, but writing the XPath for the alternative case was proving too tricky. It's messy enough as is -- it may make sense to take another pass at writing the XPath from scratch to see if it can't be simplified.
lintr/R/inner_combine_linter.R
Lines 44 to 83 in 72eeefd
# See ?as.Date, ?as.POSIXct. tryFormats is not explicitly in any default | |
# POSIXct method, but it is in as.Date.character and as.POSIXlt.character -- | |
# the latter is what actually gets invoked when running as.POSIXct | |
# on a character. So it is indeed an argument by pass-through. | |
date_args <- c("format", "origin", "tz", "tryFormats") | |
date_funs <- c("as.Date", "as.POSIXct", "as.POSIXlt") | |
# See ?log. Only these two take a 'base' argument. | |
log_funs <- c("log", "logb") | |
log_args <- "base" | |
# See ?lubridate::ymd and ?lubridate::ymd_hms | |
lubridate_args <- c("quiet", "tz", "locale", "truncated") | |
lubridate_funs <- c( | |
"ymd", "ydm", "mdy", "myd", "dmy", "dym", | |
"yq", "ym", "my", | |
"ymd_hms", "ymd_hm", "ymd_h", "dmy_hms", "dmy_hm", "dmy_h", | |
"mdy_hms", "mdy_hm", "mdy_h", "ydm_hms", "ydm_hm", "ydm_h" | |
) | |
date_args_cond <- build_arg_condition(date_funs, date_args) | |
log_args_cond <- build_arg_condition(log_funs, log_args) | |
lubridate_args_cond <- build_arg_condition(lubridate_funs, lubridate_args) | |
c_expr_cond <- xp_and( | |
sprintf( | |
"expr[1][SYMBOL_FUNCTION_CALL[%s]]", | |
xp_text_in_table(c(no_arg_vectorized_funs, date_funs, log_funs, lubridate_funs)) | |
), | |
"not(following-sibling::expr[not(expr[1][SYMBOL_FUNCTION_CALL])])", | |
"not(expr[1]/SYMBOL_FUNCTION_CALL != following-sibling::expr/expr[1]/SYMBOL_FUNCTION_CALL)", | |
date_args_cond, | |
log_args_cond, | |
lubridate_args_cond | |
) | |
xpath <- glue(" | |
parent::expr[count(following-sibling::expr) > 1] | |
/following-sibling::expr[1][ {c_expr_cond} ] | |
/parent::expr | |
") |
Metadata
Metadata
Assignees
Labels
internalsIssues related to inner workings of lintr, i.e., not user-visibleIssues related to inner workings of lintr, i.e., not user-visible