Convert Figma logo to code with AI

golangci logogolangci-lint

Fast linters runner for Go

15,526
1,382
15,526
150

Top Related Projects

4,842

🔥 ~6x faster, stricter, configurable, extensible, and beautiful drop-in replacement for golint

Staticcheck - The advanced Go linter

7,791

Go security checker

errcheck checks that you checked errors.

Correct commonly misspelled English words in source files

Quick Overview

GolangCI-Lint is a fast, parallel, and highly customizable linter for Go programming language. It integrates multiple linters and static analysis tools into a single command-line interface, providing developers with a comprehensive code quality check for their Go projects.

Pros

  • Fast execution due to parallel processing and caching mechanisms
  • Extensive set of linters (over 50) included out of the box
  • Highly configurable with the ability to enable/disable specific linters and customize their settings
  • Integrates well with various CI/CD pipelines and IDEs

Cons

  • Can be overwhelming for beginners due to the large number of linters and configuration options
  • Some linters may produce false positives or conflicting suggestions
  • Requires regular updates to keep up with the latest Go language features and best practices
  • May have a learning curve for teams transitioning from simpler linting tools

Getting Started

To install GolangCI-Lint, run:

curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.53.3

Create a configuration file named .golangci.yml in your project root:

linters:
  enable:
    - gofmt
    - golint
    - govet
    - errcheck

issues:
  exclude-rules:
    - path: _test\.go
      linters:
        - errcheck

Run GolangCI-Lint in your project directory:

golangci-lint run

This will analyze your Go code using the enabled linters and display any issues found. Adjust the configuration file to customize the linting process according to your project's needs.

Competitor Comparisons

4,842

🔥 ~6x faster, stricter, configurable, extensible, and beautiful drop-in replacement for golint

Pros of Revive

  • Faster execution time, especially for large codebases
  • More customizable and configurable, allowing fine-tuned rule sets
  • Easier to extend with custom rules

Cons of Revive

  • Fewer built-in linters compared to golangci-lint
  • Less comprehensive documentation and community support
  • May require more initial setup and configuration

Code Comparison

Revive configuration example:

ignoreGeneratedHeader = false
severity = "warning"
confidence = 0.8
errorCode = 1
warningCode = 0

[rule.blank-imports]
[rule.context-as-argument]
[rule.context-keys-type]
[rule.dot-imports]
[rule.error-return]

golangci-lint configuration example:

linters:
  enable:
    - deadcode
    - errcheck
    - gosimple
    - govet
    - ineffassign
    - staticcheck
    - structcheck
    - typecheck
    - unused
    - varcheck

Both tools offer powerful linting capabilities for Go projects, with golangci-lint providing a more comprehensive out-of-the-box experience and Revive offering greater flexibility and performance. The choice between them depends on project requirements and team preferences.

Staticcheck - The advanced Go linter

Pros of go-tools

  • Focuses on in-depth static analysis tools for Go
  • Provides specialized analyzers for specific issues (e.g., nilness, printf)
  • Offers more granular control over individual analysis tools

Cons of go-tools

  • Less user-friendly for beginners compared to golangci-lint
  • Requires more setup and configuration to use multiple tools together
  • Lacks a unified command-line interface for running all tools at once

Code Comparison

go-tools (using staticcheck):

package main

func main() {
    var x *int
    _ = *x // staticcheck will detect potential nil pointer dereference
}

golangci-lint:

package main

func main() {
    var x *int
    _ = *x // golangci-lint will also detect this issue with default configuration
}

Both tools can detect similar issues, but go-tools provides more specialized analyzers for deeper analysis in specific areas. golangci-lint offers a more integrated approach, combining multiple linters and providing an easier setup for developers.

7,791

Go security checker

Pros of gosec

  • Specialized focus on security-related issues in Go code
  • Integrates well with CI/CD pipelines for automated security checks
  • Provides detailed explanations and remediation advice for identified vulnerabilities

Cons of gosec

  • Limited scope compared to golangci-lint, focusing only on security issues
  • May produce more false positives due to its security-centric approach
  • Requires separate installation and configuration from other linting tools

Code Comparison

gosec example:

// gosec G104
_, err := os.Open(filename)
if err != nil {
    log.Print(err)
}

golangci-lint example:

// golangci-lint
var x int
x = 5 // ineffectual assignment
fmt.Println(x)

gosec focuses on security issues like unchecked errors, while golangci-lint covers a broader range of code quality checks. golangci-lint is a more comprehensive tool that includes multiple linters, including security checks, making it suitable for general code quality improvement. gosec, on the other hand, is specifically tailored for identifying security vulnerabilities in Go code, making it an excellent choice for projects with high security requirements or as an additional layer of security checking alongside other linting tools.

errcheck checks that you checked errors.

Pros of errcheck

  • Focused specifically on error checking, providing in-depth analysis
  • Lightweight and fast, with minimal setup required
  • Can be easily integrated into existing workflows or CI/CD pipelines

Cons of errcheck

  • Limited scope compared to golangci-lint's comprehensive set of linters
  • Fewer configuration options and customization possibilities
  • May require additional tools for a complete code quality analysis

Code Comparison

errcheck usage:

errcheck ./...

golangci-lint usage:

golangci-lint run

Both tools can be used to detect unchecked errors, but golangci-lint offers a broader range of linters and more extensive configuration options. errcheck is more focused and lightweight, making it a good choice for projects that primarily need error checking.

golangci-lint provides a unified interface for multiple linters, including errcheck functionality, while errcheck concentrates solely on identifying unchecked errors. The choice between the two depends on the specific needs of the project and the desired level of code analysis.

For comprehensive code quality checks, golangci-lint is generally preferred due to its extensive feature set. However, for projects that require a quick and focused error checking tool, errcheck remains a viable option.

Correct commonly misspelled English words in source files

Pros of misspell

  • Focused solely on spelling errors, making it lightweight and fast
  • Can be used across multiple file types, not just Go code
  • Offers automatic correction of misspellings

Cons of misspell

  • Limited in scope compared to golangci-lint's comprehensive linting capabilities
  • Doesn't provide static analysis or code quality checks beyond spelling
  • Less actively maintained, with fewer recent updates

Code Comparison

misspell:

func (s *Speller) ReplaceGo(src []byte) ([]byte, bool) {
    fset := token.NewFileSet()
    f, err := parser.ParseFile(fset, "", src, parser.ParseComments)
    if err != nil {
        return src, false
    }

golangci-lint:

func (r *Runner) runAnalysis(ctx context.Context, args []string) ([]result.Issue, error) {
    enabledLinters, err := r.EnabledLinters(ctx)
    if err != nil {
        return nil, errors.Wrap(err, "failed to get enabled linters")
    }

While misspell focuses on identifying and correcting spelling errors, golangci-lint provides a more comprehensive suite of linting tools for Go projects. misspell is simpler and more specialized, while golangci-lint offers broader code analysis capabilities.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

golangci-lint logo

golangci-lint

Fast linters runner for Go


golangci-lint is a fast Go linters runner.

It runs linters in parallel, uses caching, supports YAML configuration, integrates with all major IDEs, and includes over a hundred linters.

Install golangci-lint

Documentation

Documentation is hosted at https://golangci-lint.run.

Social Networks

Join Slack Follow on Mastodon Follow on Bluesky Follow on Twitter

Supporting Us

Open Collective backers and sponsors GitHub Sponsors Linter Authors

golangci-lint is a free and open-source project built by volunteers.

If you value it, consider supporting us, we appreciate it! :heart:

Badges

Build Status License Release Docker GitHub Releases Stats of golangci-lint

Contributors

This project exists thanks to all the people who contribute. How to contribute.

Stargazers over time

Stargazers over time