incu6us / goimports-reviser

Right imports sorting & code formatting tool (goimports alternative)
MIT License
600 stars 72 forks source link

Switch to Go 1.18 build tags (//go:build) #77

Closed mszostok closed 2 years ago

mszostok commented 2 years ago

Hi @incu6us! First, thanks for this great tool! I started using it but I ran into an issue with Go 1.18. After investigation, I detected the problem and here is the PR to fix this.

Overview

Currently, the goimports-reviser cannot be executed against Go code in 1.18 that uses build tags. In such case, we got error:

-: build constraints exclude all Go files in /{redacted}/test/e2e
2022/07/15 00:36:22 package has an errors
main.main
    /Users/mszostok/workspace/go/src/github.com/goimports-reviser/main.go:175
runtime.main
    /usr/local/Cellar/go/1.18.2/libexec/src/runtime/proc.go:250
runtime.goexit
    /usr/local/Cellar/go/1.18.2/libexec/src/runtime/asm_amd64.s:1571

Investigation

The problem is that they removed support for // +build tags. According to the 1.18 release notes:

//go:build lines

Since the release of Go 1.18 marks the end of support for Go 1.16, all supported versions of Go now understand //go:build >lines. In Go 1.18, go fix now removes the now-obsolete // +build lines in modules declaring go 1.18 or later in their go.mod >files.

For more information, see https://go.dev/design/draft-gobuild.

source: https://tip.golang.org/doc/go1.18

codecov[bot] commented 2 years ago

Codecov Report

Merging #77 (5bb2075) into master (09d6d35) will decrease coverage by 0.61%. The diff coverage is 33.33%.

@@            Coverage Diff             @@
##           master      #77      +/-   ##
==========================================
- Coverage   92.96%   92.35%   -0.62%     
==========================================
  Files           5        5              
  Lines         327      327              
==========================================
- Hits          304      302       -2     
- Misses         13       14       +1     
- Partials       10       11       +1     
Impacted Files Coverage Δ
pkg/astutil/astutil.go 80.00% <33.33%> (-4.45%) :arrow_down:

:mega: Codecov can now indicate which changes are the most critical in Pull Requests. Learn more

incu6us commented 2 years ago

thanks for help, merging