gormdeletedat

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

README

gormdeletedat

A Go linter that reports GORM model structs whose DeletedAt field is not typed as *gorm.DeletedAt.

Why

GORM's soft-delete functionality requires DeletedAt to be *gorm.DeletedAt (from gorm.io/gorm). Using a different type (e.g. time.Time, sql.NullTime, or a non-pointer gorm.DeletedAt) silently breaks soft-delete filtering.

Example

// Bad - will be flagged
type User struct {
    ID        uint
    DeletedAt time.Time
}

// Good
type User struct {
    ID        uint
    DeletedAt *gorm.DeletedAt
}

Usage

golangci-lint plugin

Add to .custom-gcl.yml:

plugins:
  - module: "github.com/amitaifrey/gormdeletedat"
    import: "github.com/amitaifrey/gormdeletedat/plugin"
    version: <version>

Add to .golangci.yml:

linters:
  enable:
    - gormdeletedat
  settings:
    custom:
      gormdeletedat:
        type: module
        description: "checks that GORM DeletedAt fields use *gorm.DeletedAt"
Standalone
go install github.com/amitaifrey/gormdeletedat/cmd/gormdeletedat@latest
gormdeletedat ./...

Documentation

Overview

Package gormdeletedat provides a Go analysis pass that reports GORM model structs whose DeletedAt field is not typed as *gorm.DeletedAt.

Index

Constants

This section is empty.

Variables

View Source
var Analyzer = &analysis.Analyzer{
	Name:     "gormdeletedat",
	Doc:      "reports GORM model structs where DeletedAt is not *gorm.DeletedAt",
	Requires: []*analysis.Analyzer{inspect.Analyzer},
	Run:      run,
}

Functions

This section is empty.

Types

This section is empty.

Directories

Path Synopsis
cmd
gormdeletedat command
Command gormdeletedat runs the gormdeletedat analyzer.
Command gormdeletedat runs the gormdeletedat analyzer.

Jump to

Keyboard shortcuts

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