github.com/vanstinator/golangci-lint@v0.0.0-20240223191551-cc572f00d9d1/pkg/fsutils/files.go (about) 1 package fsutils 2 3 import "path/filepath" 4 5 // Files combines different operations related to handling file paths and content. 6 type Files struct { 7 *LineCache 8 pathPrefix string 9 } 10 11 func NewFiles(lc *LineCache, pathPrefix string) *Files { 12 return &Files{ 13 LineCache: lc, 14 pathPrefix: pathPrefix, 15 } 16 } 17 18 // WithPathPrefix takes a path that is relative to the current directory (as used in issues) 19 // and adds the configured path prefix, if there is one. 20 // The resulting path then can be shown to the user or compared against paths specified in the configuration. 21 func (f *Files) WithPathPrefix(relativePath string) string { 22 return WithPathPrefix(f.pathPrefix, relativePath) 23 } 24 25 // WithPathPrefix takes a path that is relative to the current directory (as used in issues) 26 // and adds the configured path prefix, if there is one. 27 // The resulting path then can be shown to the user or compared against paths specified in the configuration. 28 func WithPathPrefix(pathPrefix, relativePath string) string { 29 if pathPrefix == "" { 30 return relativePath 31 } 32 return filepath.Join(pathPrefix, relativePath) 33 }