Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: include linter name in warnings #1357

Closed
jameslamb opened this issue Jun 4, 2022 · 6 comments · Fixed by #1363
Closed

Feature request: include linter name in warnings #1357

jameslamb opened this issue Jun 4, 2022 · 6 comments · Fixed by #1363

Comments

@jameslamb
Copy link

jameslamb commented Jun 4, 2022

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!

@MichaelChirico
Copy link
Collaborator

thanks for filing! indeed the though has crossed my mind a few times but I always forgot to file an issue.

v. important to be able to understand at a glance how to suppress each lint now that we have targeted suppression available

@AshesITR
Copy link
Collaborator

AshesITR commented Jun 4, 2022

That's a very reasonable request. So far, I've used as.data.frame(lints) to find the linter name, since the data frame contains a column linter.

We should also think about other output methods, e.g. GHA comments and RStudio Source Markers

@MichaelChirico
Copy link
Collaborator

I think for interactive use, as.data.frame() suffices, but not available when running as a plugin or in CI.

easiest to just part of print.lints

@AshesITR
Copy link
Collaborator

AshesITR commented Jun 4, 2022

Yep. Note GHA markers aren't made directly by print.lints IIRC.

@jameslamb
Copy link
Author

thanks so much @AshesITR !!

@AshesITR
Copy link
Collaborator

AshesITR commented Jun 5, 2022

Thank you for the suggestion!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants