github.com/amarpal/go-tools@v0.0.0-20240422043104-40142f59f616/lintcmd/directives.go (about) 1 package lintcmd 2 3 import ( 4 "strings" 5 6 "github.com/amarpal/go-tools/lintcmd/runner" 7 ) 8 9 func parseDirectives(dirs []runner.SerializedDirective) ([]ignore, []diagnostic) { 10 var ignores []ignore 11 var diagnostics []diagnostic 12 13 for _, dir := range dirs { 14 cmd := dir.Command 15 args := dir.Arguments 16 switch cmd { 17 case "ignore", "file-ignore": 18 if len(args) < 2 { 19 p := diagnostic{ 20 Diagnostic: runner.Diagnostic{ 21 Position: dir.NodePosition, 22 Message: "malformed linter directive; missing the required reason field?", 23 Category: "compile", 24 }, 25 Severity: severityError, 26 } 27 diagnostics = append(diagnostics, p) 28 continue 29 } 30 default: 31 // unknown directive, ignore 32 continue 33 } 34 checks := strings.Split(args[0], ",") 35 pos := dir.NodePosition 36 var ig ignore 37 switch cmd { 38 case "ignore": 39 ig = &lineIgnore{ 40 File: pos.Filename, 41 Line: pos.Line, 42 Checks: checks, 43 Pos: dir.DirectivePosition, 44 } 45 case "file-ignore": 46 ig = &fileIgnore{ 47 File: pos.Filename, 48 Checks: checks, 49 } 50 } 51 ignores = append(ignores, ig) 52 } 53 54 return ignores, diagnostics 55 }