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

Staticcheck ST1003 #649

Closed
roychoo opened this issue Aug 21, 2019 · 9 comments
Closed

Staticcheck ST1003 #649

roychoo opened this issue Aug 21, 2019 · 9 comments
Labels
area: config Related to .golangci.yml and/or cli options area: docs question Further information is requested

Comments

@roychoo
Copy link

roychoo commented Aug 21, 2019

Hi,
this is not a bug report.

want to ask regarding the configuration of staticcheck, i.e ST1003 as some check are not enabled by default, i tried to find more info in the documents but to no avail. It doesnt seem to support staticcheck.conf

Please do let me know how can i configure it

@tpounds tpounds added the question Further information is requested label Oct 6, 2019
@tpounds tpounds added the area: config Related to .golangci.yml and/or cli options label Dec 30, 2019
@terwey
Copy link

terwey commented Apr 27, 2020

I managed to get this working by adding:

issues:
  # Excluding configuration per-path, per-linter, per-text and per-source
  exclude-rules:
    - linters:
       - stylecheck
      text: "ST1003:"

    - linters:
       - stylecheck
      text: "ST1000:"

@ernado
Copy link
Member

ernado commented Apr 27, 2020

I think that the initial issue was about enabling back default excludes.
This will be possible via include option in upcoming release.

@csilvers
Copy link
Contributor

It supported staticcheck.conf for me! Perhaps this has been fixed in the latest golangci-lint.

@jbelmont
Copy link

How did you get it to work with config file?

@csilvers
Copy link
Contributor

We just put a staticcheck.conf in our repo-root and ran golangci-lint, and it respected the conf file. I don't remember the details now, unfortunately.

@jbelmont
Copy link

So we have the following staticcheck.conf file:

checks = ["all", "-SA6005", "-SA9003", "-SA4010", "-SA4006"]

Here is our .golangci.yml file:

run:
  deadline: 5m

linters-settings:
  gofmt:
    simplify: false

  govet:
    check-shadowing: false

    enable:
      - unmarshal
      - printf
      - tests
      - bools
      - assign
      - buildtag
      - unreachable
    enable-all: false
    disable-all: true

linters:
  enable:
    - gofmt
    - govet
    - staticcheck

  enable-all: false
  disable-all: true
  fast: false

issues:
  max-issues-per-linter: 50
  max-same-issues: 10

  exclude-rules:
    # Exclude some linters from running on tests files.
    - path: _test\.go
      linters:
        - gofmt

When we run the following command:

golangci-lint run ./...

We are seeing entries still for SA6005 and SA4010 so it doesn't seem to respect the staticcheck conf file

We tried the following version 1.30 and 1.27:

golangci-lint --version
golangci-lint has version 1.30.0 built from 45b90f6 on 2020-08-03T03:10:34Z

Is there anything we are doing wrong that you see?

@csilvers
Copy link
Contributor

Not that I can see, but I'm no expert on staticcheck for sure.

Our staticcheck.conf file looked like this:

initialisms = [
    # These are the defaults from https://staticcheck.io/docs/options
    "ACL", "API", "ASCII", "CPU", "CSS", "DNS", "EOF", "GUID", "HTML",
    "HTTP", "HTTPS", "ID", "IP", "JSON", "QPS", "RAM", "RPC", "SLA",
    "SMTP", "SQL", "SSH", "TCP", "TLS", "TTL", "UDP", "UI", "GID",
    "UID", "UUID", "URI", "URL", "UTF8", "VM", "XML", "XMPP", "XSRF",
    "XSS",
    # Google initialisms.
    "GCS", "GCE", "GCP", "GAE",
]

So maybe only initialisms is supported? You could try that and see if at least that kind of modification works.

@jbelmont
Copy link

Sorry for the late reply @csilvers we ended up just doing this:

Screen Shot 2020-08-18 at 11 18 09 AM

Essentially adding a yaml list per static check to disable, this was the only reliable way to get this working since we couldn't use the staticcheck.conf file reliably.

We didn't try initialisms like you proposed although that would be interesting if initialisms is the way over checks.

@ldez
Copy link
Member

ldez commented May 17, 2021

More explanation about staticcheck configuration in: #1989 (comment)

Closed in favor of #1275

@ldez ldez closed this as completed May 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: config Related to .golangci.yml and/or cli options area: docs question Further information is requested
Projects
None yet
Development

No branches or pull requests

7 participants