errorsis

package module
v0.0.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 2, 2025 License: BSD-2-Clause Imports: 5 Imported by: 0

README

ErrorsIs Linter

Go Reference Go Report Card Go golangci-lint

Overview

ErrorsIs is a custom Go linter that detects incorrect usage of the errors.Is() function, specifically focusing on cases where the second argument is a pointer to a struct that does not properly implement the error interface.

Features

  • Detects improper usage of errors.Is() where the second argument is a pointer to a struct that fails to implement error directly.
  • Supports type-safe matching of errors.Is() function calls, ensuring accurate analysis.

Build and Installation

Ensure you have Go installed (version 1.24+).

go build -trimpath -o errorsis ./cmd/errorsis

Build with golangci-lint

Note, golangci-lint supports two different ways of building and using plugins.

One is via a go plugin. This will only work with compatible versions of golangci-lint (we must use the same version of golang.org/x/tools as golangci-lint). This version has been built and tested against golangci-lint v2.4.0 (built from source, not sure about pre-built binaries). See the example linter for more details. To build for usage as a Go plugin:

go build -buildmode=plugin -o errorsis.so plugin/errorsis.go

The other is via its own module plugin system. See the example module linter for more details.

This package supports both, but note that the latter is preferred and recommended by golangci-lint.

Usage

To run the linter standalone directly on Go code:

./errorsis ./...

Usage with golangci-lint as Go plugin:

Add something like this to your .golangci.yml

    version: "2"
    linters:
      default: none
      enable:
        - errorsis
      settings:
        custom:
          errorsis:
            path: /path/to/git/errorsis/errorsis.so
            description: Detects incorrect usage of errors.Is

Usage with golangci-lint as Module plugin:

Create .custom-gcl.yml similar to this if using a local working copy:

version: v2.4.0
plugins:
  - module: "github.com/swills/errorsis"
    path: "/path/to/git/errorsis"

or like this if using Go proxy:

version: v2.4.0
plugins:
  - module: 'github.com/swills/errorsis'
    import: 'github.com/swills/errorsis'
    version: v0.0.5

And put something similar to this in your .golangci.yml:

version: "2"
linters:
  default: none
  enable:
    - errorsis
  settings:
    custom:
      errorsis:
        type: module
        description: Detects incorrect usage of errors.Is

Then run:

golangci-lint -v custom

to build the custom golangci-lint and finally, run it:

./custom-gcl run

Documentation

Overview

Package errorsis is the library used to implement the errorsis command-line tool.

Index

Constants

This section is empty.

Variables

View Source
var NoErrorIsStruct = &analysis.Analyzer{
	Name: "noerrorsisstruct",
	Doc:  "Avoid using errors.Is() with struct or struct pointer",
	Run:  noErrorIsStruct,
}

Functions

func New

func New(_ any) (register.LinterPlugin, error)

Types

This section is empty.

Directories

Path Synopsis
cmd
errorsis command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL