diff --git a/.golangci.yml b/.golangci.yml index e3400d6..7886c7c 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -10,6 +10,7 @@ linters: enable: - errcheck - errname + - gochecksumtype - govet - ineffassign - revive diff --git a/internal/schema/ast/ast.go b/internal/schema/ast/ast.go index d01359a..e435cb0 100644 --- a/internal/schema/ast/ast.go +++ b/internal/schema/ast/ast.go @@ -42,7 +42,8 @@ import ( // The human readable format is not 1-1 convertible with JSON. The JSON format // is lossy. It loses formatting, such as comments, ordering of fields, etc... - +// +//sumtype:decl type Node interface { isNode() // Pos returns first token of the node @@ -97,6 +98,7 @@ func (s *Schema) End() token.Position { return token.Position{} } +//sumtype:decl type Declaration interface { Node isDecl() @@ -165,6 +167,8 @@ func (t *CommonTypeDecl) End() token.Position { // 1. A record type // 2. A set type (Set) // 3. A path (Namespace::EntityType or String) +// +//sumtype:decl type Type interface { Node isType() @@ -377,6 +381,8 @@ func (r *Ref) End() token.Position { } // Name is an IDENT or STR +// +//sumtype:decl type Name interface { Node isName() diff --git a/internal/schema/ast/ast_test.go b/internal/schema/ast/ast_test.go index 3792dfc..2f1f7fa 100644 --- a/internal/schema/ast/ast_test.go +++ b/internal/schema/ast/ast_test.go @@ -116,32 +116,6 @@ func Test_formatter_printInd_panic(t *testing.T) { p.printInd("test") } -type unknownNode struct { - Node // Embed Node interface to satisfy type checker -} - -func Test_formatter_print_panic(t *testing.T) { - p := &formatter{ - w: &bytes.Buffer{}, - } - - defer func() { - r := recover() - if r == nil { - t.Fatal("expected panic, got none") - } - msg, ok := r.(string) - if !ok { - t.Fatalf("expected string panic, got %T", r) - } - if !strings.Contains(msg, "unhandled node type") { - t.Errorf("expected panic message about unhandled type, got %q", msg) - } - }() - - p.print(unknownNode{}) -} - func Test_printBracketList_panic(t *testing.T) { p := &formatter{ w: &bytes.Buffer{}, @@ -164,26 +138,3 @@ func Test_printBracketList_panic(t *testing.T) { var emptyList []Node printBracketList(p, emptyList, false) } - -type unknownType struct { - Type // Embed Type interface to satisfy it -} - -func TestConvertType_Panic(t *testing.T) { - defer func() { - r := recover() - if r == nil { - t.Fatal("expected panic, got none") - } - msg, ok := r.(string) - if !ok { - t.Fatalf("expected string panic, got %T", r) - } - expected := "unknownType is not an AST type" - if !strings.Contains(msg, expected) { - t.Errorf("expected panic message to contain %q, got %q", expected, msg) - } - }() - - convertType(unknownType{}) -} diff --git a/internal/schema/ast/convert_human.go b/internal/schema/ast/convert_human.go index 5ade4e8..4586ce1 100644 --- a/internal/schema/ast/convert_human.go +++ b/internal/schema/ast/convert_human.go @@ -104,6 +104,10 @@ func convertNamespace(n *Namespace) *JSONNamespace { commonType.Annotations[a.Key.String()] = a.Value.String() } jsNamespace.CommonTypes[astDecl.Name.String()] = commonType + case *CommentBlock: + // comment blocks intentionally dropped. + case *Namespace: + // namespaces intentionally not handled. } } return jsNamespace diff --git a/internal/schema/ast/convert_json.go b/internal/schema/ast/convert_json.go index c0f353e..86f69d1 100644 --- a/internal/schema/ast/convert_json.go +++ b/internal/schema/ast/convert_json.go @@ -192,6 +192,8 @@ func convertJSONAppliesTo(appliesTo *JSONAppliesTo) *AppliesTo { at.ContextRecord = t case *Path: at.ContextPath = t + case *SetType: + panic("SetType not yet handled in convertJSONAppliesTo") } }