mgechev / revive

🔥 ~6x faster, stricter, configurable, extensible, and beautiful drop-in replacement for golint
https://revive.run
MIT License
4.73k stars 276 forks source link

Disabling a rule for a block without reenable #885

Open yonderblue opened 1 year ago

yonderblue commented 1 year ago

There is the //revive:disable:blah and then //revive:enable:blah but being able to put the disable on a block like a func similar to how nolint is supported would be peachy.

chavacava commented 1 year ago

Hi @yonderblue thanks for the proposal. My understanding of your proposal is: scoped disabling directives. Current implementation uses position (line numbers) of directives without scoping information. I'm afraid, making directive scoped will require almost complete reworking of the implementation. Backward compatibility makes things harder (if not impossible) To resume, IMO the funtional gain does not worth the work and complexity grow. I'll let this usue open to discussion.

yonderblue commented 1 year ago

That is understandable. How about then splitting out into individual linters so that golangci-lint's existing scope and features could be used for each?

chavacava commented 1 year ago

I'm not sure I understand the "splitting out into individual linters" idea. Anyway, if you are using revive through golangci-lint you can fully delegate the disabling/enabling of rules to golangci-lint (in other words, use //nolint:blah instead of //revive:disable:blah

yonderblue commented 1 year ago

in other words, use //nolint:blah instead of //revive:disable:blah

Sorry I must have missed that support, or am trying it wrong? golangci-lint gives me for example:

apkg/afile.go:125:3: unhandled-error: Unhandled error in call to function e.Run (revive)
        e.Run(ctx) //nolint:unhandled-error

but using //revive:disable-line:unhandled-error in that same spot works.

chavacava commented 1 year ago

Well I'm not a golangci-lint user. My understanding is that golangci-lint implements its own mechanism for enabling/disabling rules independent of that from underlying linters. You might ask on the golangci-lint project on how to achieve scoped disabling (or why the annotation you tested is not working at expected)