feat: references check

... and fixes: parse fields without tags and other logical errors
This commit is contained in:
2024-12-30 21:15:15 +07:00
parent d4ef9b3ec6
commit 49878c333c
8 changed files with 196 additions and 76 deletions

View File

@@ -0,0 +1,12 @@
package tests
import (
"golang.org/x/tools/go/analysis/analysistest"
"gormlint/referencesCheck"
"testing"
)
func TestReferenceCheck(t *testing.T) {
t.Parallel()
analysistest.Run(t, analysistest.TestData(), referencesCheck.ReferenceAnalyzer, "references_check")
}

View File

@@ -0,0 +1,24 @@
package references_check
type WorkArea struct {
Id uint `gorm:"primaryKey"`
Workshop Workshop `gorm:"foreignKey:WorkshopId;references:Id;"`
WorkshopId uint
}
type Workshop struct {
Id uint `gorm:"primaryKey"`
Name string
WorkAreas []WorkArea `gorm:"constraint:OnDelete:CASCADE;"`
}
type TeamType struct {
Code uint `gorm:"primaryKey"`
Name string `gorm:"not null"`
}
type TeamTask struct {
Id uint `gorm:"primaryKey"`
TeamTypeId uint
TeamType TeamType `gorm:"references:Code;"`
}

View File

@@ -0,0 +1,19 @@
package references_check
type User struct {
Name string
CompanyID string
Company Company `gorm:"references:code"` // want "Related field \"code\" doesn't exist on model \"Company\""
}
type Company struct {
ID int
Code string
Name string
}
type Order struct {
Id uint `gorm:"primaryKey"`
CompanyID string `gorm:"references:Code"` // want "Related model \"string\" doesn't exist"
Company Company
}