Skip to content

Commit

Permalink
Add golangci-lint as an aspect (#95)
Browse files Browse the repository at this point in the history
* Add golangci-lint as an aspect

* Update .golangci.yaml

Paste documentation about the "don't download" option

* Address review comments

* chore: add golangci-lint to README

* chore(golangci-lint): add version placeholder for fetch

* chore: remove stray comment

* Add lint error

* chore: add test assertion for go lint

---------

Co-authored-by: Alex Eagle <[email protected]>
  • Loading branch information
psalaberria002 and alexeagle authored Jan 11, 2024
1 parent 2b7f46f commit 260ee0f
Show file tree
Hide file tree
Showing 18 changed files with 509 additions and 68 deletions.
2 changes: 1 addition & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ bazel_dep(name = "rules_buf", version = "0.1.1")
# Needed due to rules_proto leaking the dependency
bazel_dep(name = "protobuf", version = "21.7", repo_name = "com_google_protobuf")

bazel_dep(name = "rules_go", version = "0.39.1", dev_dependency = True)
bazel_dep(name = "rules_go", version = "0.39.1", repo_name = "io_bazel_rules_go")
bazel_dep(name = "gazelle", version = "0.31.0", dev_dependency = True)
bazel_dep(name = "bazel_skylib_gazelle_plugin", version = "1.4.1", dev_dependency = True)
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ We treat type-checkers as a build tool, not as a linter. This is for a few reaso
| SQL | [prettier-plugin-sql] | |
| Starlark (Bazel) | [Buildifier] | |
| Swift | [SwiftFormat] (1) | |
| Go | [gofmt] | |
| Go | [gofmt] | [golangci-lint] |
| Protocol Buffers | [buf] | [buf lint] |
| Terraform | [terraform] fmt | |
| Jsonnet | [jsonnetfmt] | |
Expand All @@ -93,6 +93,7 @@ We treat type-checkers as a build tool, not as a linter. This is for a few reaso
[ruff]: https://docs.astral.sh/ruff/
[shellcheck]: https://www.shellcheck.net/
[shfmt]: https://github.com/mvdan/sh
[golangci-lint]: https://github.com/golangci/golangci-lint

1. Non-hermetic: requires that a swift toolchain is installed on the machine.
See https://github.com/bazelbuild/rules_swift#1-install-swift
Expand Down
5 changes: 5 additions & 0 deletions docs/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ stardoc_with_diff_test(
bzl_library_target = "//lint:ruff",
)

stardoc_with_diff_test(
name = "golangci-lint",
bzl_library_target = "//lint:golangci-lint",
)

stardoc_with_diff_test(
name = "shellcheck",
bzl_library_target = "//lint:shellcheck",
Expand Down
81 changes: 81 additions & 0 deletions docs/golangci-lint.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions example/.golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Refer to golangci-lint's example config file for more options and information:
# https://github.com/golangci/golangci-lint/blob/master/.golangci.reference.yml

run:
timeout: 5m

# Prevent non-hermetic behavior. Per the documentation:
# > If invoked with -mod=readonly, the go command is disallowed from the implicit
# > automatic updating of go.mod described above. Instead, it fails when any changes
# > to go.mod are needed. This setting is most useful to check that go.mod does
# > not need updates, such as in a continuous integration and testing system.
modules-download-mode: readonly

linters:
enable:
# Default
- errcheck
- gosimple
- govet
- ineffassign
- staticcheck
- typecheck
- unused
1 change: 1 addition & 0 deletions example/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ exports_files(
".ruff.toml",
".shellcheckrc",
".scalafmt.conf",
".golangci.yaml",
],
visibility = ["//visibility:public"],
)
Expand Down
4 changes: 2 additions & 2 deletions example/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ bazel_dep(name = "rules_buf", version = "0.2.0")
bazel_dep(name = "bazel_skylib", version = "1.4.2")
bazel_dep(name = "rules_java", version = "5.5.0")
bazel_dep(name = "rules_jvm_external", version = "4.5")
bazel_dep(name = "rules_go", version = "0.42.0")
bazel_dep(name = "rules_go", version = "0.42.0", repo_name = "io_bazel_rules_go")
bazel_dep(name = "rules_proto", version = "5.3.0-21.7")
bazel_dep(name = "rules_python", version = "0.26.0")
bazel_dep(name = "buildifier_prebuilt", version = "6.3.3")
Expand Down Expand Up @@ -50,7 +50,7 @@ pip.parse(
)
use_repo(pip, "pip")

go_sdk = use_extension("@rules_go//go:extensions.bzl", "go_sdk")
go_sdk = use_extension("@io_bazel_rules_go//go:extensions.bzl", "go_sdk")
go_sdk.download(
name = "go_sdk",
version = "1.20.3",
Expand Down
Loading

0 comments on commit 260ee0f

Please sign in to comment.