ast-grep icon indicating copy to clipboard operation
ast-grep copied to clipboard

[feature] support error/warning suppression

Open HerringtonDarkholme opened this issue 2 years ago • 1 comments
trafficstars

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?

HerringtonDarkholme avatar Jun 07 '23 16:06 HerringtonDarkholme

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

chrisgrieser avatar Nov 05 '23 15:11 chrisgrieser

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.

monotkate avatar Mar 18 '24 19:03 monotkate

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!

HerringtonDarkholme avatar Mar 18 '24 20:03 HerringtonDarkholme

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 avatar Mar 19 '24 07:03 HerringtonDarkholme

@HerringtonDarkholme how to ignore a specific rule?

q0w avatar Mar 19 '24 08:03 q0w

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.

q0w avatar Mar 19 '24 09:03 q0w

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)

image

monotkate avatar Mar 20 '24 00:03 monotkate

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.

HerringtonDarkholme avatar Mar 20 '24 00:03 HerringtonDarkholme

Just shipped some new fixes. Feedback welcome!

HerringtonDarkholme avatar Mar 20 '24 08:03 HerringtonDarkholme

I guess it works

q0w avatar Mar 20 '24 11:03 q0w

I always find it surprising it returns number of files with errors rather than overall number of errors)

Same

q0w avatar Mar 20 '24 11:03 q0w

@q0w @chrisgrieser error count is fixed in 0b9c15932072fa9a7662e12bb84e0307a3d54a1f thanks for your feedback!

HerringtonDarkholme avatar Mar 22 '24 08:03 HerringtonDarkholme

will ship in 0.20.0!

HerringtonDarkholme avatar Mar 24 '24 04:03 HerringtonDarkholme

0.20.1 is shipped!

HerringtonDarkholme avatar Mar 25 '24 05:03 HerringtonDarkholme