homebrew-core/Formula/golangci-lint.rb

74 lines
2.4 KiB
Ruby

class GolangciLint < Formula
desc "Fast linters runner for Go"
homepage "https://golangci-lint.run/"
url "https://github.com/golangci/golangci-lint.git",
tag: "v1.37.1",
revision: "b39dbcd694baddce38eff2cb2aa86d4e4cf06753"
license "GPL-3.0-only"
revision 1
head "https://github.com/golangci/golangci-lint.git"
bottle do
sha256 cellar: :any_skip_relocation, arm64_big_sur: "4dbbabaed5b84204eca98dd6cc9cb082dd32083f88473bef82d581160f7d483b"
sha256 cellar: :any_skip_relocation, big_sur: "b1e4c1b455b53ee50d2152e6a66c9911659c3d9237404d8c5f6f4ba6be2b6bee"
sha256 cellar: :any_skip_relocation, catalina: "234bf03176ce12554dd9dff8ee0b4ba5fb2d032cd3aa03aed4a5e73909c9cead"
sha256 cellar: :any_skip_relocation, mojave: "f6719c949751e39fa6d58d3f10fcfff04943144cc374e593d5c7c70df6d9ccfb"
end
depends_on "go"
def install
ldflags = %W[
-s -w
-X main.version=#{version}
-X main.commit=#{Utils.git_short_head(length: 7)}
-X main.date=#{Time.now.utc.rfc3339}
].join(" ")
system "go", "build", *std_go_args, "-ldflags", ldflags, "./cmd/golangci-lint"
output = Utils.safe_popen_read("#{bin}/golangci-lint", "completion", "bash")
(bash_completion/"golangci-lint").write output
output = Utils.safe_popen_read("#{bin}/golangci-lint", "completion", "zsh")
(zsh_completion/"_golangci-lint").write output
output = Utils.safe_popen_read("#{bin}/golangci-lint", "completion", "fish")
(fish_completion/"golangci-lint.fish").write output
end
test do
str_version = shell_output("#{bin}/golangci-lint --version")
assert_match "golangci-lint has version #{version} built from", str_version
str_help = shell_output("#{bin}/golangci-lint --help")
str_default = shell_output("#{bin}/golangci-lint")
assert_equal str_default, str_help
assert_match "Usage:", str_help
assert_match "Available Commands:", str_help
(testpath/"try.go").write <<~EOS
package try
func add(nums ...int) (res int) {
for _, n := range nums {
res += n
}
return
}
EOS
args = %w[
--color=never
--disable-all
--issues-exit-code=0
--print-issued-lines=false
--enable=deadcode
].join(" ")
ok_test = shell_output("#{bin}/golangci-lint run #{args} #{testpath}/try.go")
expected_message = "try.go:3:6: `add` is unused (deadcode)"
assert_match expected_message, ok_test
end
end