r-lib / lintr

Static Code Analysis for R
https://lintr.r-lib.org
Other
1.19k stars 184 forks source link

Lints() constructor to vectorize Lint()? #2067

Open MichaelChirico opened 1 year ago

MichaelChirico commented 1 year ago

Now that we have a series of consistency checks built into Lint():

https://github.com/r-lib/lintr/blob/f8bb91e7f0fd749f9a28523006a4cedd369c2688/R/lint.R#L374-L395

It may make sense to offer a vectorized interface for constructing lints so these consistency checks can be vectorized for efficiency, rather than running the checks lint-by-lint.

AshesITR commented 1 year ago

The output type of Lint() should stay c("lint", "list") IMO.

What we could do is create a new Lints() constructor with vectorized checks. But I'm not sure about the performance benefits of doing that vs. the added complexity.

How much faster is lint_package() on a package with many lints if you comment out the consistency checks? That could give us an idea if it's worth it.

MichaelChirico commented 1 year ago

Yes, Lints() with vectorized checks producing a list() of Lint() is what I had in mind (i.e. replacing our common pattern of lapply(lints, \(l) Lint(...)) with Lints(...) providing suitably vectorized metadata).