-
Notifications
You must be signed in to change notification settings - Fork 195
Description
Request
Consider the following code:
library(lintr)
f <- tempfile(fileext = ".R")
writeLines("do_thing <- T", f)
lintr::lint(
filename = f
, linters = list(
"tf" = lintr::T_and_F_symbol_linter
)
, cache = FALSE
)On {lintr} 2.0.1 installed from CRAN and on the latest version from GitHub (801fac3, installed with remotes::install_github("r-lib/lintr")), this produces the following output (the (...) is mine, just to make the path a bit more readable):
(...)/T/RtmpIvPGWZ/fileb817b0f6442.R:1:14: style: Use TRUE instead of the symbol T.
do_thing <- T
~^
As a user of {lintr}, I'd like to see the linter name printed in the output, like this:
(...)/RtmpIvPGWZ/fileb817b0f6442.R:1:14: style: [T_and_F_symbol_linter] Use TRUE instead of the symbol T.
do_thing <- T
~^
Motivation
I learned tonight from @MichaelChirico that as of {lintr} 3.0.0, it'll be possible to use a comment like the following to say "ignore warnings from a specific linter on this line" (microsoft/LightGBM#5249 (comment)).
x <- T # nolint: T_and_F_symbol_linter`I totally see the value in being specific there and would like to do that. But since the linter name isn't printed in the warnings from lintr::lint(), figuring out the right value to add in that comment will require some trial-and-error or searching in this package's source code.
References:
As an example, flake8 also supports such targeted comments (https://flake8.pycqa.org/en/3.1.1/user/ignoring-errors.html#in-line-ignoring-errors), and I've found it really helpful that it prints in its output exactly the code that should be added to # noqa comments.
echo "x = (1,2,3,y)" > ./out.py
flake8 ./out.py./out.py:1:7: E231 missing whitespace after ','
./out.py:1:9: E231 missing whitespace after ','
./out.py:1:11: E231 missing whitespace after ','
./out.py:1:12: F821 undefined name 'y'
Example suppressing one specific warning:
echo "x = (1,2,3,y) # noqa: E231" > ./out.py
flake8 ./out.py./out.py:1:12: F821 undefined name 'y'
Thanks for your time and consideration!