Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: new help commands related to formatters #5517

Merged
merged 4 commits into from
Mar 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -153,5 +153,9 @@ jobs:

- run: ./golangci-lint help
- run: ./golangci-lint help linters
- run: ./golangci-lint help linters --json
- run: ./golangci-lint help formatters --json
- run: ./golangci-lint linters
- run: ./golangci-lint formatters
- run: ./golangci-lint version
- run: ./golangci-lint version --format json
5 changes: 5 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,11 @@ linters:
- gocritic
text: "hugeParam:"

# The codes are close but this is not duplication.
- path: pkg/commands/(formatters|linters).go
linters:
- dupl

formatters:
enable:
- gofmt
Expand Down
3 changes: 2 additions & 1 deletion assets/cli-help.json

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

4 changes: 2 additions & 2 deletions docs/src/docs/contributing/website.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Install Node.js (v20 or newer).

Run:

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

To do it run:

```sh
```bash
go run ./scripts/website/expand_templates/
```
9 changes: 5 additions & 4 deletions docs/src/docs/contributing/workflow.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Fork and clone [golangci-lint](https://github.com/golangci/golangci-lint) reposi

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

```sh
```bash
make build
./golangci-lint run -v
```
Expand All @@ -28,8 +28,8 @@ make build

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

```sh
$ make test
```bash
make test
```

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

After making a release you need to update
GitHub [Action config](https://github.com/golangci/golangci-lint/blob/HEAD/assets/github-action-config.json) by running:
```sh

```bash
make assets/github-action-config.json
```
22 changes: 19 additions & 3 deletions docs/src/docs/usage/configuration.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,23 @@
title: Configuration
---

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

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

```sh
```bash
golangci-lint linters
```

To see a list of formatters enabled by your configuration use:

```bash
golangci-lint formatters
```

## Config File

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

## Command-Line Options

### run

```sh
golangci-lint run -h
$ golangci-lint run -h
{.RunHelpText}
```

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

### fmt

```sh
$ golangci-lint fmt -h
{.FmtHelpText}
```

## Cache

GolangCI-Lint stores its cache in the subdirectory `golangci-lint` inside the [default user cache directory](https://pkg.go.dev/os#UserCacheDir).
Expand Down
33 changes: 9 additions & 24 deletions docs/src/docs/usage/false-positives.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Otherwise, some linters have dedicated configuration to exclude or disable rules

An example with `staticcheck`:

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

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

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

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

```yml
```yaml
issues:
exclude-rules:
- linters:
Expand All @@ -55,7 +55,7 @@ issues:

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

```yml
```yaml
issues:
exclude-rules:
- linters:
Expand All @@ -65,7 +65,7 @@ issues:

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

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

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

```yml
```yaml
issues:
exclude-rules:
- path: '(.+)_test\.go'
Expand All @@ -94,7 +94,7 @@ issues:
The opposite, excluding reports **except** for specific paths, is also possible.
In the following example, only test files get checked:

```yml
```yaml
issues:
exclude-rules:
- path-except: '(.+)_test\.go'
Expand All @@ -105,15 +105,15 @@ issues:

In the following example, all the reports related to the files (`exclude-files`) are excluded:

```yml
```yaml
issues:
exclude-files:
- path/to/a/file.go
```

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

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

{.ExclusionPresets}

### Default Directory Exclusions

By default, the reports from directory names, that match the following regular expressions, are excluded:

- `third_party$`
- `examples$`
- `Godeps$`
- `builtin$`

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.

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.

So we recommend setting `issues.exclude-dirs-use-default` to `false`.
6 changes: 6 additions & 0 deletions docs/src/docs/usage/formatters.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ title: Formatters

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

To see a list of supported formatters and which formatters are enabled/disabled:

```bash
golangci-lint help formatters
```

## All Formatters

{.Formatters}
Expand Down
Loading
Loading