github.com/haalcala/mattermost-server-change-repo@v0.0.0-20210713015153-16753fbeee5f/plugin/checker/render.go (about) 1 // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. 2 // See LICENSE.txt for license information. 3 4 package main 5 6 import ( 7 "fmt" 8 "go/token" 9 "os" 10 "path/filepath" 11 ) 12 13 func renderWithFilePosition(fset *token.FileSet, pos token.Pos, msg string) string { 14 var cwd string 15 if d, err := os.Getwd(); err == nil { 16 cwd = d 17 } 18 19 fpos := fset.Position(pos) 20 21 filename, err := filepath.Rel(cwd, fpos.Filename) 22 if err != nil { 23 // If deriving a relative path fails for some reason, 24 // we prefer to still print the absolute path to the file. 25 filename = fpos.Filename 26 } 27 28 return fmt.Sprintf("%s:%d:%d: %s", filename, fpos.Line, fpos.Column, msg) 29 }