Skip to content

Commit 23679e1

Browse files
authored
feat: new help commands related to formatters (#5517)
1 parent 9d5aef5 commit 23679e1

File tree

20 files changed

+506
-201
lines changed

20 files changed

+506
-201
lines changed

.github/workflows/pr.yml

+4
Original file line numberDiff line numberDiff line change
@@ -153,5 +153,9 @@ jobs:
153153

154154
- run: ./golangci-lint help
155155
- run: ./golangci-lint help linters
156+
- run: ./golangci-lint help linters --json
157+
- run: ./golangci-lint help formatters --json
156158
- run: ./golangci-lint linters
159+
- run: ./golangci-lint formatters
157160
- run: ./golangci-lint version
161+
- run: ./golangci-lint version --format json

.golangci.yml

+5
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,11 @@ linters:
182182
- gocritic
183183
text: "hugeParam:"
184184

185+
# The codes are close but this is not duplication.
186+
- path: pkg/commands/(formatters|linters).go
187+
linters:
188+
- dupl
189+
185190
formatters:
186191
enable:
187192
- gofmt

assets/cli-help.json

+2-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/src/docs/contributing/website.mdx

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ Install Node.js (v20 or newer).
4545

4646
Run:
4747

48-
```sh
48+
```bash
4949
npm install --legacy-peer-deps
5050
npm run start
5151
```
@@ -58,6 +58,6 @@ Also, there is no need to refresh a webpage: hot reload updates changed content
5858

5959
To do it run:
6060

61-
```sh
61+
```bash
6262
go run ./scripts/website/expand_templates/
6363
```

docs/src/docs/contributing/workflow.mdx

+5-4
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Fork and clone [golangci-lint](https://github.com/golangci/golangci-lint) reposi
1919

2020
A good way of making sure everything is all right is running the following:
2121

22-
```sh
22+
```bash
2323
make build
2424
./golangci-lint run -v
2525
```
@@ -28,8 +28,8 @@ make build
2828

2929
When you are satisfied with the changes, we suggest you run:
3030

31-
```sh
32-
$ make test
31+
```bash
32+
make test
3333
```
3434

3535
Which runs all the linters and tests.
@@ -58,6 +58,7 @@ A GitHub Action [workflow](https://github.com/golangci/golangci-lint/blob/HEAD/.
5858

5959
After making a release you need to update
6060
GitHub [Action config](https://github.com/golangci/golangci-lint/blob/HEAD/assets/github-action-config.json) by running:
61-
```sh
61+
62+
```bash
6263
make assets/github-action-config.json
6364
```

docs/src/docs/usage/configuration.mdx

+19-3
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,23 @@
22
title: Configuration
33
---
44

5-
The config file has lower priority than command-line options. If the same bool/string/int option is provided on the command-line
5+
The config file has lower priority than command-line options.
6+
If the same bool/string/int option is provided on the command-line
67
and in the config file, the option from command-line will be used.
78
Slice options (e.g. list of enabled/disabled linters) are combined from the command-line and config file.
89

910
To see a list of linters enabled by your configuration use:
1011

11-
```sh
12+
```bash
1213
golangci-lint linters
1314
```
1415

16+
To see a list of formatters enabled by your configuration use:
17+
18+
```bash
19+
golangci-lint formatters
20+
```
21+
1522
## Config File
1623

1724
GolangCI-Lint looks for config files in the following paths from the current working directory:
@@ -37,8 +44,10 @@ The configuration file can be validated with the JSON Schema: https://golangci-l
3744

3845
## Command-Line Options
3946

47+
### run
48+
4049
```sh
41-
golangci-lint run -h
50+
$ golangci-lint run -h
4251
{.RunHelpText}
4352
```
4453

@@ -48,6 +57,13 @@ in the format expected by the [pprof](https://github.com/google/pprof) visualiza
4857
When the `--trace-path` argument is specified, `golangci-lint` writes runtime tracing data in the format expected by
4958
the `go tool trace` command and visualization tool.
5059

60+
### fmt
61+
62+
```sh
63+
$ golangci-lint fmt -h
64+
{.FmtHelpText}
65+
```
66+
5167
## Cache
5268

5369
GolangCI-Lint stores its cache in the subdirectory `golangci-lint` inside the [default user cache directory](https://pkg.go.dev/os#UserCacheDir).

docs/src/docs/usage/false-positives.mdx

+9-24
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Otherwise, some linters have dedicated configuration to exclude or disable rules
1616

1717
An example with `staticcheck`:
1818

19-
```yml
19+
```yaml
2020
linters-settings:
2121
staticcheck:
2222
checks:
@@ -35,7 +35,7 @@ Also, you can use `issues.exclude-rules` config option for per-path or per-linte
3535

3636
In the following example, all the reports that contains the sentences defined in `exclude` are excluded:
3737

38-
```yml
38+
```yaml
3939
issues:
4040
exclude:
4141
- "Error return value of .((os\\.)?std(out|err)\\..*|.*Close|.*Flush|os\\.Remove(All)?|.*printf?|os\\.(Un)?Setenv). is not checked"
@@ -45,7 +45,7 @@ issues:
4545

4646
In the following example, all the reports from the linters (`linters`) that contains the text (`text`) are excluded:
4747

48-
```yml
48+
```yaml
4949
issues:
5050
exclude-rules:
5151
- linters:
@@ -55,7 +55,7 @@ issues:
5555

5656
In the following example, all the reports from the linters (`linters`) that originated from the source (`source`) are excluded:
5757

58-
```yml
58+
```yaml
5959
issues:
6060
exclude-rules:
6161
- linters:
@@ -65,7 +65,7 @@ issues:
6565

6666
In the following example, all the reports that contains the text (`text`) in the path (`path`) are excluded:
6767

68-
```yml
68+
```yaml
6969
issues:
7070
exclude-rules:
7171
- path: path/to/a/file.go
@@ -82,7 +82,7 @@ the `--path-prefix` parameter can be used to extend the paths before matching.
8282

8383
In the following example, all the reports from the linters (`linters`) that concerns the path (`path`) are excluded:
8484

85-
```yml
85+
```yaml
8686
issues:
8787
exclude-rules:
8888
- path: '(.+)_test\.go'
@@ -94,7 +94,7 @@ issues:
9494
The opposite, excluding reports **except** for specific paths, is also possible.
9595
In the following example, only test files get checked:
9696
97-
```yml
97+
```yaml
9898
issues:
9999
exclude-rules:
100100
- path-except: '(.+)_test\.go'
@@ -105,15 +105,15 @@ issues:
105105
106106
In the following example, all the reports related to the files (`exclude-files`) are excluded:
107107

108-
```yml
108+
```yaml
109109
issues:
110110
exclude-files:
111111
- path/to/a/file.go
112112
```
113113

114114
In the following example, all the reports related to the directories (`exclude-dirs`) are excluded:
115115

116-
```yml
116+
```yaml
117117
issues:
118118
exclude-dirs:
119119
- path/to/a/dir/
@@ -174,18 +174,3 @@ Use `//nolint` instead of `// nolint` because machine-readable comments should h
174174
Some exclusions are considered common. To help golangci-lint users those common exclusions are provided through presets.
175175

176176
{.ExclusionPresets}
177-
178-
### Default Directory Exclusions
179-
180-
By default, the reports from directory names, that match the following regular expressions, are excluded:
181-
182-
- `third_party$`
183-
- `examples$`
184-
- `Godeps$`
185-
- `builtin$`
186-
187-
This option has been defined when Go modules was not existed and when the golangci-lint core was different, this is not something we still recommend.
188-
189-
At some point, we will remove all those obsolete exclusions, but as it's a breaking changes it will only happen inside a major version.
190-
191-
So we recommend setting `issues.exclude-dirs-use-default` to `false`.

docs/src/docs/usage/formatters.mdx

+6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ title: Formatters
44

55
import { FaGithub, FaGitlab, FaArrowUp, FaCog } from "react-icons/fa";
66

7+
To see a list of supported formatters and which formatters are enabled/disabled:
8+
9+
```bash
10+
golangci-lint help formatters
11+
```
12+
713
## All Formatters
814

915
{.Formatters}

0 commit comments

Comments
 (0)