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

Errors during golangci operation #3408

Open
4 tasks done
ids79 opened this issue Dec 9, 2022 · 9 comments
Open
4 tasks done

Errors during golangci operation #3408

ids79 opened this issue Dec 9, 2022 · 9 comments
Labels
platform: windows Issue that is related to Windows question Further information is requested

Comments

@ids79
Copy link

ids79 commented Dec 9, 2022

Welcome

  • 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.).
  • Yes, I've tried with the standalone linter if available (e.g., gocritic, go vet, etc.). (https://golangci-lint.run/usage/linters/)

Description of the problem

I am using the last version golangco 1.50.1 on local maschine (windows).
When I try to perform linter, I get following errors:

level=warning msg="[runner] Can't run linter goanalysis_metalinter: gci: 4:12: expected ';', found \"testing\" (and 3 more errors)"
level=error msg="Running error: 1 error occurred:\n\t* can't run linter goanalysis_metalinter: gci: 4:12: expected ';', found \"testing\" (and 3 more errors)\n\n"

What can they be related to?
How can I fix them?

Version of golangci-lint

$ golangci-lint --version
# Paste output here

1.50.1

Configuration file

$ cat .golangci.yml
# paste output here
run:
  tests: true
  build-tags:
    - bench
    - !bench

linters-settings:
  funlen:
    lines: 150
    statements: 80

issues:
  exclude-rules:
    - path: _test\.go
      linters:
        - errcheck
        - dupl
        - gocyclo
        - gosec

linters:
  disable-all: true
  enable:
    - asciicheck
    - bodyclose
    - depguard
    - dogsled
    - dupl
    - durationcheck
    - errorlint
    - exhaustive
    - exportloopref
    - funlen
    - gci
    - gocognit
    - goconst
    - gocritic
    - gocyclo
    - godot
    - gofmt
    - gofumpt
    - goheader
    - goprintffuncname
    - gosec
    - gosimple
    - govet
    - importas
    - ineffassign
    - lll
    - makezero
    - misspell
    - nestif
    - nilerr
    - noctx
    - nolintlint
    - prealloc
    - predeclared
    - revive
    - rowserrcheck
    - sqlclosecheck
    - staticcheck
    - stylecheck
    - tagliatelle
    - thelper
    - typecheck
    - unconvert
    - unparam
    - unused
    - wastedassign
    - whitespace

Go environment

$ go version && go env
# paste output here

windows

Verbose output of running

$ golangci-lint cache clean
$ golangci-lint run -v

level=info msg="[config_reader] Config search paths: [./ C:\\Users\\divanov\\Desktop\\GO\\otus_go_homework C:\\Users\\divanov\\Desktop\\GO C:\\Users\\divanov\\Desktop C:\\Users\\divanov C:\\Users C:\\ C:\\Users\\divanov\\go]"
level=info msg="[config_reader] Used config file .golangci.yml"
level=info msg="[lintersdb] Active 47 linters: [asciicheck bodyclose depguard dogsled dupl durationcheck errorlint exhaustive exportloopref funlen gci gocognit goconst gocritic gocyclo godot gofmt gofumpt goheader goprintffuncname gosec gosimple govet importas ineffassign lll makezero misspell nestif nilerr noctx nolintlint prealloc predeclared revive rowserrcheck sqlclosecheck staticcheck stylecheck tagliatelle thelper typecheck unconvert unparam unused wastedassign whitespace]"
level=info msg="[loader] Using build tags: [bench ]"
level=info msg="[loader] Go packages loading at mode 575 (compiled_files|deps|files|imports|exports_file|name|types_sizes) took 243.6534ms"
level=info msg="[runner/filename_unadjuster] Pre-built 0 adjustments in 0s"
level=info msg="[linters_context] importas settings found, but no aliases listed. List aliases under alias: key."
level=error msg="[linters_context] typechecking error: pattern ./...: directory prefix . does not contain modules listed in go.work or their selected dependencies"
level=info msg="[linters_context/goanalysis] analyzers took 6.9762ms with top 10 stages: buildir: 4.9827ms, fact_deprecated: 1.9935ms, cgocall: 0s, ST1020: 0s, gosec: 0s, SA5002: 0s, SA6001: 0s, exportloopref: 0s, printf: 0s, SA1029: 0s"
level=info msg="[runner] processing took 0s with stages: exclude-rules: 0s, nolint: 0s, max_per_file_from_linter: 0s, severity-rules: 0s, path_prefixer: 0s, sort_results: 0s, filename_unadjuster: 0s, path_prettifier: 0s, skip_dirs: 0s, diff: 0s, max_same_issues: 0s, max_from_linter: 0s, autogenerated_exclude: 0s, exclude: 0s, uniq_by_line: 0s, source_code: 0s, path_shortener: 0s, cgo: 0s, skip_files: 0s, identifier_marker: 0s"
level=info msg="[runner] linters took 1.0423697s with stages: goanalysis_metalinter: 1.041954s"
level=info msg="File cache stats: 0 entries of total size 0B"
level=info msg="Memory: 15 samples, avg is 46.3MB, max is 56.9MB"
level=info msg="Execution took 1.3529325s"

Code example or link to a public repository

// add your code here
@ids79 ids79 added the bug Something isn't working label Dec 9, 2022
@boring-cyborg
Copy link

boring-cyborg bot commented Dec 9, 2022

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

@ldez ldez added the dependencies Relates to an upstream dependency label Dec 9, 2022
@ldez ldez added platform: windows Issue that is related to Windows question Further information is requested and removed bug Something isn't working dependencies Relates to an upstream dependency labels Dec 20, 2022
@ldez
Copy link
Member

ldez commented Dec 20, 2022

@ids79 @matjam have you tried with previous versions? (v1.50.0, v1.49.0, ...)

@ids79
Copy link
Author

ids79 commented Dec 21, 2022

Yes I have tried since 1.48.0 version. The Result the same.

@ldez
Copy link
Member

ldez commented Dec 21, 2022

So it seems related to a missing piece inside your OS.

Can you try the following commands and give me the output:

  • diff --help
  • diff.exe --help

@ids79
Copy link
Author

ids79 commented Dec 21, 2022

PS C:\Users\divanov\Desktop\GO\otus\struct> diff --help

Командлет Compare-Object в конвейере команд в позиции 1
Укажите значения для следующих параметров:
DifferenceObject[0]:

@alexandear
Copy link
Member

This issue appears because Windows doesn't have diff tool. diff is needed to compute the difference used in gofmt internal diff function.

A workaround for the issue is to append the directory with the program diff.exe to the Path environment variable. See https://stackoverflow.com/a/56206563. Assuming, you have git which contains diff.exe in C:\Program Files\Git\usr\bin. PowerShell command to modify Path user variable is the following:

[Environment]::SetEnvironmentVariable("Path", $env:Path + ";C:\Program Files\Git\usr\bin", "User")

Some may disagree that Windows has PowerShell with working diff. But it's an alias to PowerShell's Compare-Object. Compare-Object produces output in a different format than diff in Unix-like systems.

TimetoPretend54 added a commit to TimetoPretend54/go-chatgpt-copilot that referenced this issue May 23, 2023
Main is that the golang linter will not be able to run, this is due to
Powershell's choice of diff tool.
See golangci/golangci-lint#3408 (comment)
for more info.
@enumag
Copy link

enumag commented Jul 26, 2023

My colleague ran into this issue as well. He's working on Windows but the odd thing is that he's running go and golangci-lint inside a docker container.

Admittedly diff is missing in the docker container but if it was required then it should fail for me as well right? I'm running the linter inside docker as well, just my host system is ubuntu.

Why does linter behave differently when running inside docker?

@enumag
Copy link

enumag commented Jul 26, 2023

Ah okay it seems it's actually not a problem of the golangci-lint itself but rather gci in particular. So I disabled it in favor of goimports.

@golangci golangci deleted a comment from Antonboom Oct 1, 2023
trollixx added a commit to trollixx/golangci-lint that referenced this issue Oct 4, 2023
On Windows searching for `diff` returns PowerShell cmdlet,
rather than diff binary even when it is installed.

Related to golangci#3408.
trollixx added a commit to trollixx/gofmt that referenced this issue Oct 4, 2023
New version does not use external diff tool.

Related to golangci/golangci-lint#3408.
trollixx added a commit to trollixx/gofmt that referenced this issue Oct 4, 2023
On Windows searching for `diff` returns PowerShell cmdlet,
rather than diff binary even when it is installed.

Related to golangci/golangci-lint#3408.
trollixx added a commit to trollixx/gofmt that referenced this issue Oct 4, 2023
New version does not use external diff tool.

Related to golangci/golangci-lint#3408.
@trollixx
Copy link

trollixx commented Oct 4, 2023

Combination of the following pull requests addresses this issue on Windows when diff.exe is available:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platform: windows Issue that is related to Windows question Further information is requested
Projects
None yet
Development

No branches or pull requests

5 participants