Skip to content

Instantly share code, notes, and snippets.

@rinx
Created September 1, 2024 13:44
Show Gist options
  • Save rinx/5870abbd78a08c29369d6a85e669e709 to your computer and use it in GitHub Desktop.
Save rinx/5870abbd78a08c29369d6a85e669e709 to your computer and use it in GitHub Desktop.
ast-grep rule for forcing to use project-scope internal error packages in Go project
# yaml-language-server: $schema=https://raw.githubusercontent.com/ast-grep/ast-grep/main/schemas/rule.json
## FIXME: Replace <INTERNAL_ERRORS_PACKAGE> as your package path
id: use-internal-errors-package
message: use <INTERNAL_ERRORS_PACKAGE> instead
severity: warning
language: Go
rule:
kind: import_spec
any:
- has:
field: path
regex: ^"errors"$
- has:
field: path
regex: ^"github.com/pkg/errors"$
- has:
field: path
regex: ^"golang.org/x/xerrors"$
- has:
field: path
regex: ^"github.com/cockroachdb/errors"$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment