xxpxxxxp / intellij-plugin-golangci-lint

GolangCI-Lint integration for IDEA
GNU General Public License v3.0
223 stars 14 forks source link

Go linter running error #144

Closed kpvt001 closed 1 year ago

kpvt001 commented 1 year ago

Please make sure no syntax or config error, then run 'go mod tidy' to ensure deps ok.

Running go build . or go vet ./... working fine.

Each project use different goland instance.

Already set go path to .zshrc file.

xxpxxxxp commented 1 year ago

Hi @kpvt001 , please paste the error log here for debugging, you can find it in Goland or Intellij by clicking Hi @kpvt001 ,请找一下error日志贴到这里来辅助找问题,可以在你的IDE里依此点: Help -> Show Log in ... -> open the log file, search for go-linter

gcstang commented 1 year ago

Ran into the same error, not sure where it's looking but I have a project open in IntelliJ that is one level above all my projects (I've worked this way for years).

<pathx> <project1> <project2> <project3> ... Is this plugin looking for the .go files to be directly in the project?

2023-07-05 07:29:49,624 [1419871] WARN - go-linter - Run error: level=error msg="Running error: context loading failed: no go files to analyze" . Please make sure the project has no syntax error.

xxpxxxxp commented 1 year ago

Hi @gcstang , the plugin has several different working modes, each needing corresponding setting. The out-of-box config is working for single project as you mentioned. For your case, you can follow I have multiple Go sub-projects in the root project: Uncheck Project Root. Be aware that only the config file directly under the project root will be used.

Ref: https://github.com/xxpxxxxp/intellij-plugin-golangci-lint#setting-guide

gcstang commented 1 year ago

Now I see this error, does the plugin UI not work when using this configuration and I have to create a config file manually?

2023-07-06 07:19:35,384 [ 533413] WARN - go-linter - Run error: level=error msg="Running error: context loading failed: no go files to analyze" . Please make sure the project has no syntax error.

xxpxxxxp commented 1 year ago

@gcstang sorry I'm confused, it's still the same error as before? Would you paste the content of <your project path>/.idea/golinter.xml here for me to debug.

gcstang commented 1 year ago

@gcstang sorry I'm confused, it's still the same error as before? Would you paste the content of <your project path>/.idea/golinter.xml here for me to debug.

`<?xml version="1.0" encoding="UTF-8"?>

`
xxpxxxxp commented 1 year ago

@gcstang sorry for the late reply, in the log where you find such log, there's also a following line that prints a debug command, would you paste that line too

2023-07-06 07:19:35,384 [ 533413] WARN - go-linter - Run error: level=error msg="Running error: context loading failed: no go files to analyze"
. Please make sure the project has no syntax error.
gcstang commented 1 year ago

@gcstang sorry for the late reply, in the log where you find such log, there's also a following line that prints a debug command, would you paste that line too

2023-07-06 07:19:35,384 [ 533413] WARN - go-linter - Run error: level=error msg="Running error: context loading failed: no go files to analyze"
. Please make sure the project has no syntax error.

2023-07-11 07:29:13,110 [ 207849] WARN - go-linter - Debug command: cd '/Users/myuser/dev/GoLang/src/github.com/example-goproject/cmd/example-goproject' && export PATH='/Users/myuser/go/bin:/usr/bin:/bin:/usr/sbin:/sbin' && export GOPATH='' && export GO111MODULE='on' && '/Users/myuser/dev/GoLang/bin/golangci-lint' 'run' '--out-format' 'json' '--allow-parallel-runners' '-j' '2' '--issues-exit-code' '1' '--max-issues-per-linter' '0' '--max-same-issues' '0' '--no-config' '--disable-all' '-E' 'exportloopref,predeclared,funlen,gocritic,goconst,reassign,sqlclosecheck,gocognit,ineffassign,revive,prealloc,staticcheck,interfacer,govet,dupl,errorlint,misspell,gochecknoinits,nosprintfhostport,makezero,bodyclose,gosec,maligned,godox,unconvert,stylecheck,whitespace,goprintffuncname,gosimple,goimports,gocyclo,gocheckcompilerdirectives' '--build-tags' 'unix' '.'

xxpxxxxp commented 1 year ago

Thanks @gcstang ! I'm suspecting the empty GOPATH, or the build tag is causing the issue. Would you try run the debug command in a terminal, see if any output, and try without export GOPATH='', also try without '--build-tags' 'unix'

gcstang commented 1 year ago

Thanks @gcstang ! I'm suspecting the empty GOPATH, or the build tag is causing the issue. Would you try run the debug command in a terminal, see if any output, and try without export GOPATH='', also try without '--build-tags' 'unix'

My GOPATH is not empty; in IntelliJ it's configured (checkbox) to "Use GOPATH that's defined in system environment"

This works correctly using the DEBUG line from a iTerm terminal.

xxpxxxxp commented 1 year ago

You mean when try run the command without export GOPATH='', it works fine? It's a known issue sometimes the plugin cannot pickup environment variables of system, especially when it's defined in 3rd party terminal (.zshrc etc). I'll see what I can do to workaround. For now, a simple fix could be adding the same global GOPATH to Project GOPATH in settings like below It will not impact IDE behavior but make the plugin happy

image

gcstang commented 1 year ago

Copying the path works for now. Is there something that provides more meaning for the Problems found within the UI? i.e. ineffectual assignment to val

xxpxxxxp commented 1 year ago

glad it works. For the hint text, it's from the underlying linters: https://golangci-lint.run/usage/linters/ Unless they provide more info, there's nothing the plugin can do.