Skip to content

VS Code can't find .golangci.yml #463

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

Closed
ran-berenfeld opened this issue Mar 27, 2019 · 8 comments
Closed

VS Code can't find .golangci.yml #463

ran-berenfeld opened this issue Mar 27, 2019 · 8 comments

Comments

@ran-berenfeld
Copy link

ran-berenfeld commented Mar 27, 2019

Hello

I am running golangci-lint from the golang extention, latest vscode version and latest golang extention.
the problem is that I have excluded some test in the .golangci.yml file, however when vscode runs golangci-lint, the errors are shown.
How can I tell vscode to also use the .golangci.yml file I have in the workspace directory ?

.golangci.yml file :

run:
  deadline: 5m

issues:
  max-issues-per-linter: 0
  max-same-issues: 0
  # disable some excludes that golangci-lint has by default. see https://github.com/golangci/golangci-lint
  exclude-use-default: false
  exclude-rules:
      # Disable duplicate code or unused params validation in testing
      - path: _test\.go$
        linters:
          - dupl
          - unparam
      # These checks are not really useful
      - linters:
        - errcheck
        text: "Error return value of `.*(Close|Remove)` is not checked"
      # We read arbitrary files in build system, it's not a problem
      - path: build/
        linters:
        - gosec
        text: "Potential file inclusion via variable"
      # We run arbitrary subprocesses in build system, it's not a problem
      - path: build/
        linters:
        - gosec
        text: "Subprocess (launching should be audited|launched with variable)"

linters:
  enable-all: true
  disable:
    # This project does not have a rule to have no globals
    - gochecknoglobals
    # This project does not have a rule to have no inits
    - gochecknoinits
    # This test has too many false positives
    - gocyclo
    # This project does not have a standard line length
    - lll
    # This project does not have a rule to forbid naked returns
    - nakedret
    # This project does not care about optimizing out few bytes of memory
    - maligned
@jirfag
Copy link
Contributor

jirfag commented Apr 20, 2019

Hi!
Can you reproduce it without VS Code? Where is .golangci.yml located?

@jirfag jirfag changed the title golangci VS Code can't find .golangci.yml Apr 20, 2019
@jirfag jirfag changed the title VS Code can't find .golangci.yml VS Code can't find .golangci.yml Apr 20, 2019
@ran-berenfeld
Copy link
Author

hello
.golangci.yml is located in the workspace root.

@michaelshobbs
Copy link

I am seeing similar behavior. This seems to be an issue when VSCode runs golangci-lint from within a package. If it executes golangci-lint from the root, the settings from .golangci.yml are applied.

Not sure what the right solution here is though 😕

@michaelshobbs
Copy link

I found the solution in #582

    "go.lintFlags": [
        "--config=${workspaceFolder}/.golangci.yml",
        "--fast"
    ],

@matoous
Copy link
Contributor

matoous commented Sep 25, 2019

Since we have a solution I am closing this issue. Feel free to comment if more things need to be made clear.

@matoous matoous closed this as completed Sep 25, 2019
@evermile-mitko
Copy link

my 5 cents here: it appeared that the "--config=${workspaceFolder}/.golangci.yml", was not working for me and changing it to "-c", "${workspaceFolder}/.golangci.yml" did the trick. My user settings in VS code are now:

"go.lintTool":"golangci-lint",
    "go.lintFlags": [
        "-c", "${workspaceFolder}/.golangci.yml",
        "--fast"
    ]

@smhmayboudi
Copy link

today @evermile-mitko is not working so I changed it to @michaelshobbs solution !?

@icio
Copy link

icio commented Aug 18, 2023

I was getting the impression that VSCode couldn't find the config file, and it turned out that it's because I had some issues.excludeRules with a path relative to the config file in the workspace root, but when golangci-lint is run from within a subdirectory (as I suspect Go: Lint on Save = package does) then the path wouldn't match any more and the excluded messages would re-appear. Setting Go: Lint on Save = workspace resolved this because the path exclusion would then work again. #3717

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants