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

Can't disable specific revive rules after upgrading from 1.37.0 to 1.37.1 #1770

Closed
3 tasks done
ejain opened this issue Feb 23, 2021 · 6 comments · Fixed by #1772 or #1831
Closed
3 tasks done

Can't disable specific revive rules after upgrading from 1.37.0 to 1.37.1 #1770

ejain opened this issue Feb 23, 2021 · 6 comments · Fixed by #1772 or #1831
Labels
bug Something isn't working

Comments

@ejain
Copy link

ejain commented Feb 23, 2021

After upgrading from 1.37.0 to 1.37.1, configuring explicit rules for the revive linter in the linters-settings no longer prevents other revive rules from running. This is unfortunate, as revive doesn't output rule codes that could be used to filter on...

Thank you for creating the issue!

  • Yes, I'm using a binary release within 2 latest major releases. Only such installations are supported.
  • Yes, I've searched similar issues on GitHub and didn't find any.
  • Yes, I've included all information below (version, config, etc).

Please include the following information:

Version of golangci-lint
$ golangci-lint --version
golangci-lint has version 1.37.1 built from b39dbcd on 2021-02-22T04:34:44Z
Config file
linters-settings:
  revive:
    rules:
      - name: if-return
        severity: error
      - name: var-declaration
        severity: error
linters:
  disable-all: true
  enable:
    - revive
Go environment
$ go version && go env
go version go1.15.8 darwin/amd64
@ejain ejain added the bug Something isn't working label Feb 23, 2021
@boring-cyborg
Copy link

boring-cyborg bot commented Feb 23, 2021

Hey, thank you for opening your first Issue ! 🙂 If you would like to contribute we have a guide for contributors.

@ldez
Copy link
Member

ldez commented Feb 23, 2021

Hello,

the difference between v1.37.0 and v1.37.1 is that we follow the revive way to apply rules: some rules are applied by default.

https://github.com/mgechev/revive/blob/389ba853b0b3587f0c3b71b5f0c61ea4e23928ec/config/config.go#L155

@ocavue
Copy link

ocavue commented Mar 10, 2021

In revive, some rules are applied by default when not config file provided. However, if you provide a config file, you must explicitly enable the rules that you want to use. By doing that, revive allows users to disable any rule even they are enabled by default. Here is an example.

  1. make sure that I have the latest version of revive and golangci-lint:
$ go get -u github.com/mgechev/revive
$ golangci-lint --version
golangci-lint has version 1.38.0 built from 507703b on 2021-03-03T14:50:52Z
  1. prepare a file
$ cat enterprise/server/demo.go
package server

func MyFunction() int {
	if 1+1 == 2 {
		return 2
	} else {
		return 0
	}
}
  1. when using revive without a config file, revive will throw two errors indent-error-flow and exported
$ revive -formatter friendly enterprise/server/demo.go
  ⚠  https://revive.run/r#exported  exported function MyFunction should have comment or be unexported
  enterprise/server/demo.go:3:1

  ⚠  https://revive.run/r#indent-error-flow  if block ends with a return statement, so drop this else and outdent its block
  enterprise/server/demo.go:6:9

⚠ 2 problems (0 errors, 2 warnings)

Warnings:
  1  exported
  1  indent-error-flow
  1. when using revive with the following config file, revive only throws one error exported.
$ cat revive.toml
[rule.exported]
$ revive -formatter friendly -config revive.toml enterprise/server/demo.go
  ⚠  https://revive.run/r#exported  exported function MyFunction should have comment or be unexported
  enterprise/server/demo.go:3:1

⚠ 1 problem (0 errors, 1 warning)

Warnings:
  1  exported
  1. when using golang-ci with the same config, golang-ci will still throw the error indent-error-flow, which means I'm not able to disable it like what I did with revive command:
$ cat .golangci.yaml
linters-settings:
  revive:
    rules:
      - name: exported
        severity: error
linters:
  disable-all: true
  enable:
    - revive
$ golangci-lint run enterprise/server/... | grep 'enterprise/server/demo.go'
enterprise/server/demo.go:6:9: indent-error-flow: if block ends with a return statement, so drop this else and outdent its block (revive)

@ldez I hope we can re-open this issue and discuss a way to disable revive rules

@ldez ldez reopened this Mar 10, 2021
@ldez
Copy link
Member

ldez commented Mar 10, 2021

I will try to fix that but that will be breaking once again.

@ldez
Copy link
Member

ldez commented Mar 10, 2021

The main difficulty is that revive use a filename to detect if the default rules must be applied, but in golangci-lint we cannot do that because the revive rules are not defined in a dedicated file.

@ldez
Copy link
Member

ldez commented Mar 10, 2021

reflect.DeepEqual will do the job 😉

Take a look at my PR #1831

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
3 participants