### Install golangci-lint using go install Source: https://golangci-lint.run/docs/welcome/install/local Install golangci-lint directly using the 'go install' command. This method is not recommended due to potential issues with Go versions and dependency management. ```bash go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.12.2 ``` -------------------------------- ### Golangci-lint Configuration File Example Source: https://golangci-lint.run/docs/configuration/file This is a basic example of a golangci-lint configuration file. It shows the structure for defining versions, linters, formatters, issues, output, run, and severity options. Use this as a template for your own configurations. ```yaml # See the dedicated "version" documentation section. version: "2" linters: # See the dedicated "linters" documentation section. option: value formatters: # See the dedicated "formatters" documentation section. option: value issues: # See the dedicated "issues" documentation section. option: value # Output configuration options. output: # See the dedicated "output" documentation section. option: value # Options for analysis running. run: # See the dedicated "run" documentation section. option: value severity: # See the dedicated "severity" documentation section. option: value ``` -------------------------------- ### Install Golangci-lint using curl to GOPATH/bin Source: https://golangci-lint.run/docs/welcome/install/local Installs the golangci-lint binary to your Go workspace's bin directory using curl. Ensure you have curl installed. ```bash # binary will be $(go env GOPATH)/bin/golangci-lint curl -sSfL https://golangci-lint.run/install.sh | sh -s -- -b $(go env GOPATH)/bin v2.12.2 ``` -------------------------------- ### Setup a Go workspace Source: https://golangci-lint.run/docs/welcome/install/local Initialize a Go workspace to manage multiple modules, useful when isolating tools like golangci-lint. ```bash go work init . golangci-lint ``` -------------------------------- ### Install Golangci-lint using curl to current directory Source: https://golangci-lint.run/docs/welcome/install/local Installs the golangci-lint binary into the current directory using curl. Ensure you have curl installed. ```bash # or install it into ./bin/ curl -sSfL https://golangci-lint.run/install.sh | sh -s v2.12.2 ``` -------------------------------- ### Build and Run Golangci-lint Source: https://golangci-lint.run/docs/contributing/workflow Build the project and run the linter with verbose output. This is a good way to ensure your setup is correct. ```bash make build ./golangci-lint run -v ``` -------------------------------- ### Install Golangci-lint using wget on Alpine Linux Source: https://golangci-lint.run/docs/welcome/install/local Installs the golangci-lint binary using wget, suitable for Alpine Linux where curl might not be pre-installed. Ensure you have wget installed. ```bash # In Alpine Linux (as it does not come with curl by default) wget -O- -nv https://golangci-lint.run/install.sh | sh -s v2.12.2 ``` -------------------------------- ### Install golangci-lint with mise Source: https://golangci-lint.run/docs/welcome/install/local Use the mise package manager to install a specific version of golangci-lint. Note that mise uses the aqua backend. ```bash mise use -g golangci-lint@v2.12.2 ``` -------------------------------- ### Reference Configuration Example (.custom-gcl.yml) Source: https://golangci-lint.run/docs/plugins/module-plugins Detailed configuration for building a custom golangci-lint binary with various plugin types. Supports plugins from Go proxies and local sources, with options for import paths and relative/absolute paths. ```yaml # The golangci-lint version used to build the custom binary. # Required. version: v2.0.0 # The name of the custom binary. # Optional. # Default: custom-gcl name: custom-golangci-lint # The directory path used to store the custom binary. # Optional. # Default: . destination: ./my/path/ # The list of the plugins to integrate inside the custom binary. plugins: # a plugin from a Go proxy - module: 'github.com/example/plugin3' version: v1.2.3 # a plugin from a Go proxy (with a specific import path) - module: 'github.com/example/plugin4' import: 'github.com/example/plugin4/foo' version: v1.0.0 # a plugin from local source (with absolute path) - module: 'github.com/example/plugin2' path: /my/local/path/plugin2 # a plugin from local source (with relative path) - module: 'github.com/example/plugin1' path: ./my/local/path/plugin1 # a plugin from local source (with absolute path and a specific import path) - module: 'github.com/example/plugin2' import: 'github.com/example/plugin4/foo' path: /my/local/path/plugin2 ``` -------------------------------- ### Verify Golangci-lint installation Source: https://golangci-lint.run/docs/welcome/install/local Checks the installed version of golangci-lint to confirm successful installation. ```bash golangci-lint --version ``` -------------------------------- ### Migrate Configuration to JSON Format Source: https://golangci-lint.run/docs/product/migration-guide Specify the output format for the migration using the `--format` flag. This example sets the output to JSON. ```bash golangci-lint migrate --format json ``` -------------------------------- ### Revive Linter Configuration Example Source: https://golangci-lint.run/docs/linters/configuration Example configuration for the Revive linter, showing how to set severity, disable rules, and exclude files. This is a general configuration block. ```yaml revive: severity: warning disabled: false exclude: [""] ``` -------------------------------- ### Linter Settings Example Source: https://golangci-lint.run/docs/configuration/file Provides a placeholder for configuring specific settings for individual linters. Refer to the dedicated documentation for available options. ```yaml settings: option: value ``` -------------------------------- ### Install Golangci-lint using Chocolatey on Windows Source: https://golangci-lint.run/docs/welcome/install/local Installs golangci-lint using the Chocolatey package manager on Windows. ```powershell choco install golangci-lint ``` -------------------------------- ### VS Code Settings for Golangci-lint v2 Extension Installation Source: https://golangci-lint.run/docs/welcome/integrations Configure VS Code to use golangci-lint v2 installed via the Go extension. This setup allows v1 to coexist with v2. ```json "go.lintTool": "golangci-lint-v2", "go.lintFlags": [ "--path-mode=abs", "--fast-only" ], "go.formatTool": "custom", "go.alternateTools": { "customFormatter": "golangci-lint-v2" }, "go.formatFlags": [ "fmt", "--stdin" ] ``` -------------------------------- ### Module Plugin Configuration Example (.custom-gcl.yml) Source: https://golangci-lint.run/docs/plugins/module-plugins Configure plugins from a Go proxy or local source using module paths and versions. This file defines the plugins to be included in a custom golangci-lint binary. ```yaml version: v2.12.2 plugins: # a plugin from a Go proxy - module: 'github.com/golangci/plugin1' import: 'github.com/golangci/plugin1/foo' version: v1.0.0 # a plugin from local source - module: 'github.com/golangci/plugin2' path: /my/local/path/plugin2 ``` -------------------------------- ### Install Golangci-lint using MacPorts Source: https://golangci-lint.run/docs/welcome/install/local Installs golangci-lint using MacPorts. Note that this installation method is community-driven and not officially maintained by the golangci team. ```bash sudo port install golangci-lint ``` -------------------------------- ### Install Golangci-lint using Homebrew on macOS Source: https://golangci-lint.run/docs/welcome/install/local Installs golangci-lint using the Homebrew package manager on macOS. This is the recommended method for macOS users. ```bash brew install golangci-lint ``` -------------------------------- ### Install Bash Completion v2 and Configure for macOS Source: https://golangci-lint.run/docs/welcome/integrations Instructions for installing bash-completion v2 and configuring it for use with Bash 4.1+ on macOS. This is required for golangci-lint completion to work correctly. ```bash brew install bash-completion@2 echo 'export BASH_COMPLETION_COMPAT_DIR="/usr/local/etc/bash_completion.d"' >>~/.bashrc echo '[[ -r "/usr/local/etc/profile.d/bash_completion.sh" ]] && . "/usr/local/etc/profile.d/bash_completion.sh"' >>~/.bashrc exec bash # reload and replace (if it was updated) type _init_completion && echo "completion is OK" # verify that bash-completion v2 is correctly installed ``` -------------------------------- ### VS Code Settings for Manual Golangci-lint Installation Source: https://golangci-lint.run/docs/welcome/integrations Configure VS Code to use a manually installed golangci-lint. Ensure you do not use `--fast-only` to avoid editor freezes. ```json "go.lintTool": "golangci-lint", "go.lintFlags": [ "--path-mode=abs", "--fast-only" ], "go.formatTool": "custom", "go.alternateTools": { "customFormatter": "golangci-lint" }, "go.formatFlags": [ "fmt", "--stdin" ] ``` -------------------------------- ### Install Golangci-lint using Scoop on Windows Source: https://golangci-lint.run/docs/welcome/install/local Installs golangci-lint using the Scoop package manager on Windows. Note that this package is not officially maintained by the golangci team. ```powershell scoop install main/golangci-lint ``` -------------------------------- ### Registering and Configuring Linters Source: https://golangci-lint.run/docs/contributing/architecture This snippet shows how linters are registered and configured within the builder. It includes examples of setting metadata like version, URL, and analysis type. ```go func (b LinterBuilder) Build(cfg *config.Config) []*linter.Config { // ... return []*linter.Config{ // ... linter.NewConfig(golinters.NewBodyclose()). WithSince("v1.18.0"). WithLoadForGoAnalysis(). WithURL("https://github.com/timakin/bodyclose"), // ... linter.NewConfig(golinters.NewGovet(govetCfg)). WithGroups(config.GroupStandard). WithSince("v1.0.0"). WithLoadForGoAnalysis(). WithURL("https://pkg.go.dev/cmd/vet"), // ... } } ``` -------------------------------- ### Add golangci-lint as a tool with a dedicated module Source: https://golangci-lint.run/docs/welcome/install/local Add golangci-lint as a tool to the dedicated module using 'go get -tool'. ```bash go get -tool -modfile=golangci-lint/go.mod github.com/golangci/golangci-lint/v2/cmd/golangci-lint ``` -------------------------------- ### Add golangci-lint as a tool with a dedicated module file Source: https://golangci-lint.run/docs/welcome/install/local Add golangci-lint as a tool to the dedicated module file using 'go get -tool'. ```bash go get -tool -modfile=golangci-lint.mod github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.12.2 ``` -------------------------------- ### Configure testifylint checkers Source: https://golangci-lint.run/docs/linters/configuration Example configuration for the testifylint linter, showing how to enable all checkers, disable specific ones, and enable others by name. Use this to customize the linting rules applied to testify usage. ```yaml linters: settings: testifylint: # Enable all checkers (https://github.com/Antonboom/testifylint#checkers). # Default: false enable-all: true # Disable checkers by name # (in addition to default # suite-thelper # ). disable: - blank-import - bool-compare - compares - contains - empty - encoded-compare - equal-values - error-is-as - error-nil - expected-actual - float-compare - formatter - go-require - len - negative-positive - nil-compare - regexp - require-error - suite-broken-parallel - suite-dont-use-pkg - suite-extra-assert-call - suite-method-signature - suite-subtest-run - suite-thelper - useless-assert # Disable all checkers (https://github.com/Antonboom/testifylint#checkers). # Default: false disable-all: true # Enable checkers by name # (in addition to default # blank-import, bool-compare, compares, contains, empty, encoded-compare, equal-values, error-is-as, error-nil, # expected-actual, go-require, float-compare, formatter, len, negative-positive, nil-compare, regexp, require-error, # suite-broken-parallel, suite-dont-use-pkg, suite-extra-assert-call, suite-subtest-run, suite-method-signature, # useless-assert # ). enable: - blank-import - bool-compare - compares - contains - empty - encoded-compare - equal-values - error-is-as - error-nil - expected-actual - float-compare - formatter - go-require - len - negative-positive - nil-compare - regexp - require-error - suite-broken-parallel - suite-dont-use-pkg - suite-extra-assert-call - suite-method-signature - suite-subtest-run - suite-thelper - useless-assert ``` -------------------------------- ### Configure Custom Linter in .golangci.yml Source: https://golangci-lint.run/docs/plugins/go-plugins Example configuration for adding a custom linter plugin to your project's `.golangci.yml` file. This includes the path to the plugin and optional settings. ```yaml version: "2" linters: settings: custom: example: path: /example.so description: The description of the linter original-url: github.com/golangci/example-linter settings: # Settings are optional. one: Foo two: - name: Bar three: name: Bar ``` -------------------------------- ### Build the Golangci-lint Website Source: https://golangci-lint.run/docs/contributing/website Execute this command in the root of the repository to build the static website. This command is used for production builds. ```bash # (in the root of the repository) make docs_build ``` -------------------------------- ### golangci-lint migrate command help Source: https://golangci-lint.run/docs/configuration/cli Shows help for the 'migrate' command, used to convert configuration files from v1 to v2. Useful for understanding migration options and formats. ```bash $ golangci-lint migrate -h Migrate configuration file from v1 to v2. Usage: golangci-lint migrate [flags] Flags: -c, --config PATH Read config from file path PATH --no-config Don't read config file --format string Output file format. By default, the format of the input configuration file is used. It can be 'yml', 'yaml', 'toml', or 'json'. --skip-validation Skip validation of the configuration file against the JSON Schema for v1. Global Flags: --color string Use color when printing; can be 'always', 'auto', or 'never' (default "auto") -h, --help Help for a command -v, --verbose Verbose output ``` -------------------------------- ### Display Help Information Source: https://golangci-lint.run/docs/configuration/cli Shows the general usage and available commands for the golangci-lint CLI. ```bash $ golangci-lint -h Smart, fast linters runner. Usage: golangci-lint [flags] golangci-lint [command] Available Commands: cache Cache control and information. completion Generate the autocompletion script for the specified shell config Configuration file information and verification. custom Build a version of golangci-lint with custom linters. fmt Format Go source files. formatters List current formatters configuration. help Display extra help linters List current linters configuration. migrate Migrate configuration file from v1 to v2. run Lint the code. version Display the golangci-lint version. Flags: --color string Use color when printing; can be 'always', 'auto', or 'never' (default "auto") -h, --help Help for a command -v, --verbose Verbose output --version Print version Use "golangci-lint [command] --help" for more information about a command. ``` -------------------------------- ### Display golangci-lint config help Source: https://golangci-lint.run/docs/configuration/cli Shows help information for the 'config' command, including available subcommands and flags. ```bash $ golangci-lint config -h Configuration file information and verification. Usage: golangci-lint config [flags] golangci-lint config [command] Available Commands: path Print used configuration path. verify Verify configuration against JSON schema. Flags: -c, --config PATH Read config from file path PATH --no-config Don't read config file Global Flags: --color string Use color when printing; can be 'always', 'auto', or 'never' (default "auto") -h, --help Help for a command -v, --verbose Verbose output Use "golangci-lint config [command] --help" for more information about a command. ``` -------------------------------- ### Build the Golangci-lint Website (Alternative) Source: https://golangci-lint.run/docs/contributing/website An alternative method to build the website, which includes copying JSON schema and expanding templates before initiating the build process within the docs directory. ```bash # (in the root of the repository) make website_copy_jsonschema website_expand_templates cd docs/ # (inside the docs/ folder) make build ``` -------------------------------- ### golangci-lint fmt command help Source: https://golangci-lint.run/docs/configuration/cli Displays help information for the 'fmt' command, which formats Go source files. Use this to understand available flags for formatting operations. ```bash $ golangci-lint fmt -h Format Go source files. Usage: golangci-lint fmt [flags] Flags: -c, --config PATH Read config from file path PATH --no-config Don't read config file -E, --enable strings Enable specific formatter -d, --diff Display diffs instead of rewriting files --diff-colored Display diffs instead of rewriting files (with colors) --stdin Use standard input for piping source files Global Flags: --color string Use color when printing; can be 'always', 'auto', or 'never' (default "auto") -h, --help Help for a command -v, --verbose Verbose output ``` -------------------------------- ### Run Basic Linting with Golangci-lint Source: https://golangci-lint.run/docs/welcome/quick-start Execute golangci-lint with default settings to analyze your project. This command analyzes all packages in the current directory recursively. ```bash golangci-lint run ``` ```bash golangci-lint run ./... ``` -------------------------------- ### Upgrade Golangci-lint using Homebrew on macOS Source: https://golangci-lint.run/docs/welcome/install/local Upgrades an existing golangci-lint installation to the latest version using Homebrew on macOS. ```bash brew upgrade golangci-lint ``` -------------------------------- ### Display golangci-lint version help Source: https://golangci-lint.run/docs/configuration/cli Shows help information for the 'version' command, used to display the golangci-lint version. ```bash $ golangci-lint version -h Display the golangci-lint version. Usage: golangci-lint version [flags] Flags: --debug Add build information --json Display as JSON --short Display only the version number Global Flags: --color string Use color when printing; can be 'always', 'auto', or 'never' (default "auto") -h, --help Help for a command -v, --verbose Verbose output ``` -------------------------------- ### Get Enabled Linters Map Source: https://golangci-lint.run/docs/contributing/architecture Retrieves a map of all enabled linters, potentially after filtering based on configuration and command-line requests. ```go func (m *Manager) GetEnabledLintersMap() (map[string]*linter.Config, error) ``` -------------------------------- ### Display golangci-lint custom help Source: https://golangci-lint.run/docs/configuration/cli Shows help information for the 'custom' command, used for building golangci-lint with custom linters. ```bash $ golangci-lint custom -h Build a version of golangci-lint with custom linters. Usage: golangci-lint custom [flags] Flags: --destination string The directory path used to store the custom binary --name string The name of the custom binary --version string The golangci-lint version used to build the custom binary Global Flags: --color string Use color when printing; can be 'always', 'auto', or 'never' (default "auto") -h, --help Help for a command -v, --verbose Verbose output ``` -------------------------------- ### Run golangci-lint using go tool with a dedicated module file Source: https://golangci-lint.run/docs/welcome/install/local Execute golangci-lint using the 'go tool' command, specifying the dedicated module file. ```bash go tool -modfile=golangci-lint.mod golangci-lint run ``` -------------------------------- ### golangci-lint formatters command help Source: https://golangci-lint.run/docs/configuration/cli Provides help for the 'formatters' command, which lists the current formatter configurations. Use this to see which formatters are enabled or available. ```bash $ golangci-lint formatters -h List current formatters configuration. Usage: golangci-lint formatters [flags] Flags: -c, --config PATH Read config from file path PATH --no-config Don't read config file -E, --enable strings Enable specific formatter --json Display as JSON Global Flags: --color string Use color when printing; can be 'always', 'auto', or 'never' (default "auto") -h, --help Help for a command -v, --verbose Verbose output ``` -------------------------------- ### Enable Verbose Output Source: https://golangci-lint.run/docs/contributing/debug Use the -v flag to get a verbose output of the linter's execution. This is useful for understanding the general flow of the linter. ```bash golang-lint run -v ``` -------------------------------- ### Serve the Golangci-lint Website Locally Source: https://golangci-lint.run/docs/contributing/website Run this command in the root of the repository to serve the website locally for development. The Hugo server supports hot reload for most changes. ```bash # (in the root of the repository) make docs_serve ``` -------------------------------- ### Serve the Golangci-lint Website Locally (Alternative) Source: https://golangci-lint.run/docs/contributing/website An alternative method to serve the website locally, involving expanding templates and then running a local Hugo server within the docs directory. This also supports hot reload. ```bash # (in the root of the repository) make website_expand_templates cd docs/ # (inside the docs/ folder) make serve ``` -------------------------------- ### Golangci-lint Help Command Source: https://golangci-lint.run/docs/configuration/cli Displays general help information for the golangci-lint CLI and its subcommands. ```bash $ golangci-lint help -h Display extra help Usage: golangci-lint help [flags] golangci-lint help [command] Available Commands: formatters Display help for formatters. linters Display help for linters. Global Flags: --color string Use color when printing; can be 'always', 'auto', or 'never' (default "auto") -h, --help Help for a command -v, --verbose Verbose output Use "golangci-lint help [command] --help" for more information about a command. ``` -------------------------------- ### Exclude Specific Linters in a Block Source: https://golangci-lint.run/docs/linters/false-positives Use `//nolint:` at the beginning of a line to exclude issues from a specific linter for the following code block. This example excludes issues from the `govet` linter. ```go //nolint:govet var ( a int b int ) ``` -------------------------------- ### Run golangci-lint with Docker Source: https://golangci-lint.run/docs/welcome/install/local Execute golangci-lint within a Docker container, mounting the current directory as the application context. ```bash docker run --rm -v $(pwd):/app -w /app golangci/golangci-lint:v2.12.2 golangci-lint run ``` ```bash docker run -t --rm -v $(pwd):/app -w /app golangci/golangci-lint:v2.12.2 golangci-lint run ``` -------------------------------- ### Exclude Specific Linters Inline Source: https://golangci-lint.run/docs/linters/false-positives To exclude issues from specific linters on a single line, list them after `//nolint:`. For example, `//nolint:wsl,unused` excludes warnings from the `wsl` and `unused` linters. ```go var bad_name int //nolint:wsl,unused ``` -------------------------------- ### Build a Go Plugin Source: https://golangci-lint.run/docs/plugins/go-plugins Command to build a Go plugin from your linter's source file. This creates a `.so` file that golangci-lint can use. ```bash go build -buildmode=plugin plugin/example.go ``` -------------------------------- ### Create a Go Plugin Source: https://golangci-lint.run/docs/plugins/go-plugins This is the signature required for the `New` function in your Go plugin. It must return a slice of `analysis.Analyzer` structs or an error. ```go func New(conf any) ([]*analysis.Analyzer, error) { // ... } ``` -------------------------------- ### Golangci-lint Cache Command Help Source: https://golangci-lint.run/docs/configuration/cli Displays help for the 'cache' command, which controls and provides information about the linter cache. ```bash $ golangci-lint cache -h Cache control and information. Usage: golangci-lint cache [flags] golangci-lint cache [command] Available Commands: clean Clean cache status Show cache status Global Flags: --color string Use color when printing; can be 'always', 'auto', or 'never' (default "auto") -h, --help Help for a command -v, --verbose Verbose output Use "golangci-lint cache [command] --help" for more information about a command. ``` -------------------------------- ### Initialize a dedicated module file in a dedicated directory Source: https://golangci-lint.run/docs/welcome/install/local Create a Go module file within a dedicated directory for isolating golangci-lint. ```bash # 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 ``` -------------------------------- ### Display Help for the 'run' Command Source: https://golangci-lint.run/docs/configuration/cli Shows detailed usage and flags specific to the 'run' command, which lints the code. ```bash $ golangci-lint run -h Lint the code. Usage: golangci-lint run [flags] Flags: -c, --config PATH Read config from file path PATH --no-config Don't read config file --default string Default set of linters to enable (default "standard") -D, --disable strings Disable specific linter -E, --enable strings Enable specific linter --enable-only strings Override linters configuration section to only run the specific linter(s) --fast-only Filter enabled linters to run only fast linters -j, --concurrency int Number of CPUs to use (Default: Automatically set to match Linux container CPU quota and fall back to the number of logical CPUs in the machine) --modules-download-mode string Modules download mode. If not empty, passed as -mod= to go tools --issues-exit-code int Exit code when issues were found (default 1) --build-tags strings Build tags --timeout duration Timeout for total work. Disabled by default --tests Analyze tests (*_test.go) (default true) --allow-parallel-runners Allow multiple parallel golangci-lint instances running. If false (default) - golangci-lint acquires file lock on start. --allow-serial-runners Allow multiple golangci-lint instances running, but serialize them around a lock. If false (default) - golangci-lint exits with an error if it fails to acquire file lock on start. --path-prefix string Path prefix to add to output --path-mode string Path mode to use (empty, or 'abs') --show-stats Show statistics per linter (default true) --output.text.path stdout Output path can be either stdout, `stderr` or path to the file to write to. --output.text.print-linter-name Print linter name in the end of issue text. (default true) --output.text.print-issued-lines Print lines of code with issue. (default true) --output.text.colors Use colors. (default true) --output.json.path stdout Output path can be either stdout, `stderr` or path to the file to write to. --output.tab.path stdout Output path can be either stdout, `stderr` or path to the file to write to. --output.tab.print-linter-name Print linter name in the end of issue text. (default true) --output.tab.colors Use colors. (default true) --output.html.path stdout Output path can be either stdout, `stderr` or path to the file to write to. --output.checkstyle.path stdout Output path can be either stdout, `stderr` or path to the file to write to. --output.code-climate.path stdout Output path can be either stdout, `stderr` or path to the file to write to. --output.junit-xml.path stdout Output path can be either stdout, `stderr` or path to the file to write to. ``` -------------------------------- ### Run golangci-lint using go tool with a dedicated module Source: https://golangci-lint.run/docs/welcome/install/local Execute golangci-lint using the 'go tool' command within the context of a dedicated module. ```bash go tool golangci-lint run ``` -------------------------------- ### Create a dedicated directory for go tool Source: https://golangci-lint.run/docs/welcome/install/local Prepare a dedicated directory for isolating golangci-lint when using 'go tool' with a dedicated module. ```bash mkdir golangci-lint ``` -------------------------------- ### Display Version Information as JSON Source: https://golangci-lint.run/docs/product/changelog Use the --json flag with the 'version' command to display the golangci-lint version in JSON format. ```bash golangci-lint version --json ``` -------------------------------- ### Golangci-lint Linters Command Help Source: https://golangci-lint.run/docs/configuration/cli Shows help information for the 'linters' command, detailing flags for configuration and filtering. ```bash $ golangci-lint linters -h List current linters configuration. Usage: golangci-lint linters [flags] Flags: -c, --config PATH Read config from file path PATH --no-config Don't read config file --default string Default set of linters to enable (default "standard") -D, --disable strings Disable specific linter -E, --enable strings Enable specific linter --enable-only strings Override linters configuration section to only run the specific linter(s) --fast-only Filter enabled linters to run only fast linters --json Display as JSON Global Flags: --color string Use color when printing; can be 'always', 'auto', or 'never' (default "auto") -h, --help Help for a command -v, --verbose Verbose output ``` -------------------------------- ### Initialize a dedicated module file for go tool Source: https://golangci-lint.run/docs/welcome/install/local Create a dedicated Go module file to isolate golangci-lint when using 'go tool'. This prevents conflicts with project dependencies. ```bash # 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 ``` -------------------------------- ### Run Configuration Migration Source: https://golangci-lint.run/docs/product/migration-guide Use the `migrate` command to automatically update your configuration file to the latest version. Comments within the configuration file are not migrated and must be added manually. ```bash golangci-lint migrate ``` -------------------------------- ### Disable All and Enable All Replacement Source: https://golangci-lint.run/docs/product/migration-guide Replaced '--disable-all' with '--default=none' and '--enable-all' with '--default=all'. ```bash # --disable-all has been replaced with --default=none. # --enable-all has been replaced with --default=all. ``` -------------------------------- ### Replace linters.enable-all with linters.default: all Source: https://golangci-lint.run/docs/product/migration-guide Use `linters.default: all` instead of `linters.enable-all: true` for enabling all linters. ```yaml linters: enable-all: true ``` ```yaml linters: default: all ``` -------------------------------- ### Show Help for Completion Command Source: https://golangci-lint.run/docs/configuration/cli Displays the help message for the `golangci-lint completion` command, outlining its usage and available sub-commands for shell autocompletion. ```bash $ golangci-lint completion -h Generate the autocompletion script for golangci-lint for the specified shell. See each sub-command's help for details on how to use the generated script. Usage: golangci-lint completion [command] Available Commands: bash Generate the autocompletion script for bash fish Generate the autocompletion script for fish powershell Generate the autocompletion script for powershell zsh Generate the autocompletion script for zsh Global Flags: --color string Use color when printing; can be 'always', 'auto', or 'never' (default "auto") -h, --help Help for a command -v, --verbose Verbose output Use "golangci-lint completion [command] --help" for more information about a command. ``` -------------------------------- ### Valid Nolint Syntax Source: https://golangci-lint.run/docs/linters/false-positives Demonstrates the correct syntax for `nolint` directives, which requires no spaces between `//`, `nolint`, `:`, and the linter name. ```go //nolint:xxx ``` -------------------------------- ### Load Packages Function Source: https://golangci-lint.run/docs/contributing/architecture Initiates the package loading process, determining the necessary load mode based on enabled linters and handling potential errors. ```go func (l *PackageLoader) Load(ctx context.Context, linters []*linter.Config) (pkgs, deduplicatedPkgs []*packages.Package, err error) { loadMode := findLoadMode(linters) pkgs, err = l.loadPackages(ctx, loadMode) if err != nil { return nil, nil, fmt.Errorf("failed to load packages: %w", err) } // ... ``` -------------------------------- ### Specify Directories or Files for Formatting Source: https://golangci-lint.run/docs/welcome/quick-start Target specific directories or files for code formatting. This allows for granular control over which parts of your project are formatted. ```bash golangci-lint fmt dir1 dir2/... ``` ```bash golangci-lint fmt file1.go ``` -------------------------------- ### Display Configuration Path as JSON Source: https://golangci-lint.run/docs/product/changelog Use the --json flag with the 'config path' command to output the configuration path in JSON format. ```bash golangci-lint config path --json ```