Skip to content

Better support for linting a general vector of files #2135

@MichaelChirico

Description

@MichaelChirico

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:

  1. Use lint_dir() with non-default patterns=. This is not very flexible -- patterns= is passed to dir(patterns=), which only operates on basename().
  2. manually loop over the vector with lint(). This sacrifices several things handled by lint_dir(), like a progress meter, possible parallelization (Paralleisation of lint_dir #485), flatten_lints() merging results, etc.
  3. 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:

  1. lint_dir() gets an argument specifying a vector of files, e.g. files=, user can specify either path= or files= and the rest, including lint_package() is unchanged.
  2. lint() accepts a vector of file names in filename=.
  3. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    featurea feature request or enhancement

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions