ast-grep
ast-grep copied to clipboard
[feature] support error/warning suppression
Discussed in https://github.com/ast-grep/ast-grep/discussions/445
Originally posted by q0w June 7, 2023
What do you think about adding support for # ast-grep: rule-id mechanism to ignore specific rules on specific lines of code?
Came here searching for that. Would indeed like to have such a feature, yes.
Though, I'd rather call it "ignore via inline comment" or something, since I think noqa is mostly only the terminology in python.
Also, to be in line with what other linters commonly do, it should rather be something like # ast-grep-disable: rule-id
What are the chances of this feature getting added in the near future? We have a ton of uses ast-grep for custom linting rules, but not having this makes it difficult to roll them out to large files without blocking people on a ton of unrelated changes. Not an ideal scenario in general, but we can get around this with most linters with inline ignores.
Hi @monotkate, thanks for using ast-grep! I will look at this soon. I will give it back about the timeline for suppression by this weekend.
Thanks!
Hi @monotkate I have pushed a commit to the main branch and would you like to build the CLI from source? https://github.com/ast-grep/ast-grep?tab=readme-ov-file#installation
The latest commit will suppress errors if a line is following ast-grep-ignore. e.g.
// ast-grep-ignore
errorCode()
I have not had time to test it thoroughly but I would like to collect some early feedback from real-world usage. Thanks!
@HerringtonDarkholme how to ignore a specific rule?
I guess ast-grep supresses errors but still returns non-exit code and counts them as errors
Error: 2 error(s) found in code.
Help: Scan succeeded and found error level diagnostics in the codebase.
Little bit of work to convince it to use the right version, but it seems to generally work as expected!
# ast-grep-ignore
tags=[f"provider_id:{provider_id}"],
Like @q0w mentioned though, it's definitely still returning an error exit (sidenote: I always find it surprising it returns number of files with errors rather than overall number of errors)
Thanks for your feedback! The feature is not completed yet and I will improve it more! I don't have too much time right now but I will try ship some fixes this week.
Just shipped some new fixes. Feedback welcome!
I guess it works
I always find it surprising it returns number of files with errors rather than overall number of errors)
Same
@q0w @chrisgrieser error count is fixed in 0b9c15932072fa9a7662e12bb84e0307a3d54a1f thanks for your feedback!
will ship in 0.20.0!
0.20.1 is shipped!