Skip to content

Commit 349231e

Browse files
committed
docs: go tool note
1 parent 4fbd027 commit 349231e

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

docs/src/docs/welcome/install.mdx

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,75 @@ These installations aren't recommended because of the following points:
164164
go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@{.LatestVersion}
165165
```
166166

167+
<details><summary>`go tool` usage recommendations</summary>
168+
169+
We don't recommend using `go tool`.
170+
171+
But if you want to use `go tool` to install and run golangci-lint (once again we don't recommend that),
172+
the best approach is to use a dedicated module or module file to isolate golangci-lint from other tools or dependencies.
173+
174+
This approach avoid to modifying your project dependencies and the golangci-lint dependencies.
175+
176+
**⚠️ IMPORTANT ⚠️: You should never update golangci-lint dependencies manually.**
177+
178+
**Method 1 (dedicated module file)**
179+
180+
```sh
181+
# Create a dedicated module file
182+
go mod init -modfile=golangci-lint.mod <your_module_path>/golangci-lint
183+
# Example: go mod init -modfile=golangci-lint.mod github.com/org/repo/golangci-lint
184+
```
185+
186+
```sh
187+
# Add golangci-lint as a tool
188+
go get -tool -modfile=golangci-lint.mod github.com/golangci/golangci-lint/v2/cmd/golangci-lint@{.LatestVersion}
189+
```
190+
191+
```sh
192+
# Run golangci-lint as a tool
193+
go tool -modfile=golangci-lint.mod golangci-lint run
194+
```
195+
196+
```sh
197+
# Update golangci-lint
198+
go get -tool -modfile=golangci-lint.mod github.com/golangci/v2/golangci-lint/cmd/golangci-lint@latest
199+
```
200+
201+
**Method 2 (dedicated module)**
202+
203+
```sh
204+
# Create a dedicated directory
205+
mkdir golangci-lint
206+
```
207+
208+
```sh
209+
# Create a dedicated module file
210+
go mod init -modfile=tools/go.mod <your_module_path>/golangci-lint
211+
# Example: go mod init -modfile=golangci-lint/go.mod github.com/org/repo/golangci-lint
212+
```
213+
214+
```sh
215+
# Setup a Go workspace
216+
go work init . golangci-lint
217+
```
218+
219+
```sh
220+
# Add golangci-lint as a tool
221+
go get -tool -modfile=golangci-lint/go.mod github.com/golangci/golangci-lint/v2/cmd/golangci-lint
222+
```
223+
224+
```sh
225+
# Run golangci-lint as a tool
226+
go tool golangci-lint run
227+
```
228+
229+
```sh
230+
# Update golangci-lint
231+
go get -tool -modfile=golangci-lint/go.mod github.com/golangci/golangci-lint/v2/cmd/golangci-lint@latest
232+
```
233+
234+
</details>
235+
167236
## Next
168237

169238
[Quick Start: how to use `golangci-lint`](/welcome/quick-start/).

0 commit comments

Comments
 (0)