Skip to content

Commit 550e7d2

Browse files
committed
docs: go tool note
1 parent 4fbd027 commit 550e7d2

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

docs/src/docs/welcome/install.mdx

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

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

0 commit comments

Comments
 (0)