Open csgillespie opened 4 years ago
Exlusions only take effect for lint_dir()
and lint_package()
.
What is your expected behaviour for calling lint()
on an excluded file?
I suppose I was expecting it to return NULL
Exclusions can be passed into lint()
as part of the dots argument (or pulled in from the .lintr config). This is quite useful when excluding specific lines within a file. It seems reasonable to exit-early from linting excluded files, though it may not lead to any significant performance improvements.
Do we know if get_source_expressions
is ran for all excluded files when calling lint_[package|dir]
?
get_source_expressions is only called by lint()
IINM, so completely excluded files are optimized away by lint_dir()
and not read at all.
When calling lint_dir
, filenames that are completely excluded are filtered out by lint_dir
, and all other files are passed along (one-by-one) to lint
along with the set of exclusions
. Since the exclusions
are passed into lint
from lint_dir
the completely-excluded files could be filtered out within lint
. This would make lint
respect any complete-exclusions parsed from the .lintr or passed in by the user (though I'll admit it seems strange to completely-exclude a file that you pass into lint
).
If a file is completely excluded in the exclusions: blah
section of .lintr, and lint(that_file)
is called, any lints that are found in that file are not reported (they are filtered out when calling exclude(lints, ...) just before returning from lint
). This means that filtering-out completely-excluded files is performed twice during the lint_dir
workflow and once in the lint
workflow. So there's a bit of duplicated logic in there.
It might make sense to push the complete-exclusion filtering into lint
and remove it from both lint_dir
and exclude
This will be easier after #2135
When I call
lintr::lint
on a file, it runsget_source_expression
regardless if the file should be excludedI think if we move the
get_source_expression
down a few lines, this should solve the issue.The use case here is I run lintr::lint on a bunch of .Rmd files. But occasionally I want to exclude the files from linting.