@@ -24,22 +24,9 @@ modify_defaults <- function(defaults, ...) {
2424 }
2525 vals <- list (... )
2626 nms <- names2(vals )
27- missing <- ! nzchar(nms , keepNA = TRUE )
28- if (any(missing )) {
29- args <- as.character(eval(substitute(alist(... )[missing ])))
30- # foo_linter(x=1) => "foo"
31- # var[["foo"]] => "foo"
32- nms [missing ] <- re_substitutes(
33- re_substitutes(
34- # Very long input might have newlines which are not caught
35- # by . in a perl regex; see #774
36- re_substitutes(args , rex(" (" , anything ), " " , options = " s" ),
37- rex(start , anything , ' ["' %or % " ::" ),
38- " "
39- ),
40- rex(' "]' , anything , end ),
41- " "
42- )
27+ missing_index <- ! nzchar(nms , keepNA = TRUE )
28+ if (any(missing_index )) {
29+ nms [missing_index ] <- guess_names(... , missing_index = missing_index )
4330 }
4431
4532 to_null <- vapply(vals , is.null , logical (1L ))
@@ -160,6 +147,22 @@ linters_with_tags <- function(tags, ..., packages = "lintr", exclude_tags = "dep
160147# ' absolute_path_linter()
161148# ' )
162149linters_with_defaults <- function (... , defaults = default_linters ) {
150+ dots <- list (... )
151+ if (missing(defaults ) && " default" %in% names(dots )) {
152+ warning(
153+ " 'default' is not an argument to linters_with_defaults(). Did you mean 'defaults'? " ,
154+ " This warning will be removed when with_defaults() is fully deprecated."
155+ )
156+ defaults <- dots $ default
157+ nms <- names2(dots )
158+ missing_index <- ! nzchar(nms , keepNA = TRUE )
159+ if (any(missing_index )) {
160+ names(dots )[missing_index ] <- guess_names(... , missing_index = missing_index )
161+ }
162+ dots $ default <- NULL
163+ dots <- c(dots , list (defaults = defaults ))
164+ return (do.call(modify_defaults , dots ))
165+ }
163166 modify_defaults(... , defaults = defaults )
164167}
165168
@@ -181,3 +184,16 @@ call_linter_factory <- function(linter_factory, linter_name, package) {
181184 attr(linter , " name" ) <- linter_name
182185 linter
183186}
187+
188+ guess_names <- function (... , missing_index ) {
189+ args <- as.character(eval(substitute(alist(... )[missing_index ])))
190+ # foo_linter(x=1) => "foo"
191+ # var[["foo"]] => "foo"
192+ # strip call: foo_linter(x=1) --> foo_linter
193+ # NB: Very long input might have newlines which are not caught
194+ # by . in a perl regex; see #774
195+ args <- re_substitutes(args , rex(" (" , anything ), " " , options = " s" )
196+ # strip extractors: pkg::foo_linter, var[["foo_linter"]] --> foo_linter
197+ args <- re_substitutes(args , rex(start , anything , ' ["' %or % " ::" ), " " )
198+ re_substitutes(args , rex(' "]' , anything , end ), " " )
199+ }
0 commit comments