-
Notifications
You must be signed in to change notification settings - Fork 192
Description
Sometimes, we want to lint a vector of files that's not neatly captured by lint_dir()
.
Currently, there's three ways to do so:
- Use
lint_dir()
with non-defaultpatterns=
. This is not very flexible --patterns=
is passed todir(patterns=)
, which only operates onbasename()
. - manually loop over the vector with
lint()
. This sacrifices several things handled bylint_dir()
, like a progress meter, possible parallelization (Paralleisation oflint_dir
#485),flatten_lints()
merging results, etc. - Use a
.lintr
config to set exclusions. This works well for simple packages/projects, but is not fully general and very clunky for interactive use cases.
One use case I have in mind is linting the R sources. lint_dir()
includes lots of files that we'd typically not want to lint, e.g. test scripts for the R parser that intentionally use bad R syntax, and the concatenated source all.R
files. It's very hard to get lint_dir()
to ignore those all.R
files especially, which is very inefficient, so the best way to lint the R sources currently is to filter list.files()
by hand, then lintr:::flatten_lints(lapply(filtered_files, lint, ...))
.
I can see two three (3rd thanks to @JSchoenbachler) options for improving this situation:
lint_dir()
gets an argument specifying a vector of files, e.g.files=
, user can specify eitherpath=
orfiles=
and the rest, includinglint_package()
is unchanged.lint()
accepts a vector of file names infilename=
.- A new
lint_files()
function.
I can see arguments for both; I'm currently leaning towards option (1) because the code change will be very small & will make it easier to plug in to parallelization in the future. The main advantage of option (2) is not growing the argument surface of any functions. (3) is also a new function, but we could have lint_dir()
call it so that all of the logic around combining lints over multiple files is still in one place.
Filing issue here for feedback/discussion.