From 550e7d20b22eef1702020dc86c41f5a29985faf6 Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Sun, 9 Mar 2025 21:19:52 +0100 Subject: [PATCH 1/2] docs: go tool note --- docs/src/docs/welcome/install.mdx | 70 +++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/docs/src/docs/welcome/install.mdx b/docs/src/docs/welcome/install.mdx index 2d57c4424ea2..71134ddbe745 100644 --- a/docs/src/docs/welcome/install.mdx +++ b/docs/src/docs/welcome/install.mdx @@ -164,6 +164,76 @@ These installations aren't recommended because of the following points: go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@{.LatestVersion} ``` +
+`go tool` usage recommendations + +We don't recommend using `go tool`. + +But if you want to use `go tool` to install and run golangci-lint (once again we don't recommend that), +the best approach is to use a dedicated module or module file to isolate golangci-lint from other tools or dependencies. + +This approach avoid to modifying your project dependencies and the golangci-lint dependencies. + +**⚠️ IMPORTANT ⚠️: You should never update golangci-lint dependencies manually.** + +**Method 1 (dedicated module file)** + +```sh +# Create a dedicated module file +go mod init -modfile=golangci-lint.mod /golangci-lint +# Example: go mod init -modfile=golangci-lint.mod github.com/org/repo/golangci-lint +``` + +```sh +# Add golangci-lint as a tool +go get -tool -modfile=golangci-lint.mod github.com/golangci/golangci-lint/v2/cmd/golangci-lint@{.LatestVersion} +``` + +```sh +# Run golangci-lint as a tool +go tool -modfile=golangci-lint.mod golangci-lint run +``` + +```sh +# Update golangci-lint +go get -tool -modfile=golangci-lint.mod github.com/golangci/v2/golangci-lint/cmd/golangci-lint@latest +``` + +**Method 2 (dedicated module)** + +```sh +# Create a dedicated directory +mkdir golangci-lint +``` + +```sh +# Create a dedicated module file +go mod init -modfile=tools/go.mod /golangci-lint +# Example: go mod init -modfile=golangci-lint/go.mod github.com/org/repo/golangci-lint +``` + +```sh +# Setup a Go workspace +go work init . golangci-lint +``` + +```sh +# Add golangci-lint as a tool +go get -tool -modfile=golangci-lint/go.mod github.com/golangci/golangci-lint/v2/cmd/golangci-lint +``` + +```sh +# Run golangci-lint as a tool +go tool golangci-lint run +``` + +```sh +# Update golangci-lint +go get -tool -modfile=golangci-lint/go.mod github.com/golangci/golangci-lint/v2/cmd/golangci-lint@latest +``` + +
+ ## Next [Quick Start: how to use `golangci-lint`](/welcome/quick-start/). From 2c0a255e2a01c0ef24960c4810c84749e4141c0e Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Sat, 15 Mar 2025 18:48:19 +0100 Subject: [PATCH 2/2] review --- docs/src/docs/welcome/install.mdx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/src/docs/welcome/install.mdx b/docs/src/docs/welcome/install.mdx index 71134ddbe745..f96eae6447e7 100644 --- a/docs/src/docs/welcome/install.mdx +++ b/docs/src/docs/welcome/install.mdx @@ -172,11 +172,11 @@ We don't recommend using `go tool`. But if you want to use `go tool` to install and run golangci-lint (once again we don't recommend that), the best approach is to use a dedicated module or module file to isolate golangci-lint from other tools or dependencies. -This approach avoid to modifying your project dependencies and the golangci-lint dependencies. +This approach avoids modifying your project dependencies and the golangci-lint dependencies. **⚠️ IMPORTANT ⚠️: You should never update golangci-lint dependencies manually.** -**Method 1 (dedicated module file)** +**Method 1: dedicated module file** ```sh # Create a dedicated module file @@ -199,7 +199,7 @@ go tool -modfile=golangci-lint.mod golangci-lint run go get -tool -modfile=golangci-lint.mod github.com/golangci/v2/golangci-lint/cmd/golangci-lint@latest ``` -**Method 2 (dedicated module)** +**Method 2: dedicated module** ```sh # Create a dedicated directory