source: Fix golint godoc issues

This commit is contained in:
Cameron Moore 2018-09-06 14:42:55 -05:00 committed by Bjørn Erik Pedersen
parent 5f2e1cb896
commit 600047ff1c
3 changed files with 46 additions and 17 deletions

View file

@ -34,6 +34,7 @@ var (
_ ReadableFile = (*FileInfo)(nil) _ ReadableFile = (*FileInfo)(nil)
) )
// File represents a source file.
type File interface { type File interface {
// Filename gets the full path and filename to the file. // Filename gets the full path and filename to the file.
@ -84,6 +85,7 @@ type ReadableFile interface {
Open() (io.ReadCloser, error) Open() (io.ReadCloser, error)
} }
// FileInfo describes a source file.
type FileInfo struct { type FileInfo struct {
// Absolute filename to the file on disk. // Absolute filename to the file on disk.
@ -112,31 +114,56 @@ type FileInfo struct {
lazyInit sync.Once lazyInit sync.Once
} }
func (fi *FileInfo) Filename() string { return fi.filename } // Filename returns a file's filename.
func (fi *FileInfo) Path() string { return fi.relPath } func (fi *FileInfo) Filename() string { return fi.filename }
func (fi *FileInfo) Dir() string { return fi.relDir }
func (fi *FileInfo) Extension() string { return fi.Ext() } // Path returns a file's relative path.
func (fi *FileInfo) Ext() string { return fi.ext } func (fi *FileInfo) Path() string { return fi.relPath }
func (fi *FileInfo) Lang() string { return fi.lang }
func (fi *FileInfo) LogicalName() string { return fi.name } // Dir returns a file's directory.
func (fi *FileInfo) BaseFileName() string { return fi.baseName } func (fi *FileInfo) Dir() string { return fi.relDir }
// Extension returns a file's extension.
func (fi *FileInfo) Extension() string { return fi.Ext() }
// Ext returns a file's extension without the leading period.
func (fi *FileInfo) Ext() string { return fi.ext }
// Lang returns a file's language.
func (fi *FileInfo) Lang() string { return fi.lang }
// LogicalName returns a file's name.
func (fi *FileInfo) LogicalName() string { return fi.name }
// BaseFileName returns a file's base name.
func (fi *FileInfo) BaseFileName() string { return fi.baseName }
// TranslationBaseName returns a file's translation base name.
func (fi *FileInfo) TranslationBaseName() string { return fi.translationBaseName } func (fi *FileInfo) TranslationBaseName() string { return fi.translationBaseName }
// Section returns a file's section.
func (fi *FileInfo) Section() string { func (fi *FileInfo) Section() string {
fi.init() fi.init()
return fi.section return fi.section
} }
// UniqueID returns a file's unique identifier.
func (fi *FileInfo) UniqueID() string { func (fi *FileInfo) UniqueID() string {
fi.init() fi.init()
return fi.uniqueID return fi.uniqueID
} }
func (fi *FileInfo) FileInfo() os.FileInfo {
return fi.fi // FileInfo returns a file's underlying os.FileInfo.
} func (fi *FileInfo) FileInfo() os.FileInfo { return fi.fi }
func (fi *FileInfo) String() string { return fi.BaseFileName() } func (fi *FileInfo) String() string { return fi.BaseFileName() }
// Open implements ReadableFile.
func (fi *FileInfo) Open() (io.ReadCloser, error) {
f, err := fi.sp.SourceFs.Open(fi.Filename())
return f, err
}
// We create a lot of these FileInfo objects, but there are parts of it used only // We create a lot of these FileInfo objects, but there are parts of it used only
// in some cases that is slightly expensive to construct. // in some cases that is slightly expensive to construct.
func (fi *FileInfo) init() { func (fi *FileInfo) init() {
@ -155,6 +182,7 @@ func (fi *FileInfo) init() {
}) })
} }
// NewFileInfo returns a new FileInfo structure.
func (sp *SourceSpec) NewFileInfo(baseDir, filename string, isLeafBundle bool, fi os.FileInfo) *FileInfo { func (sp *SourceSpec) NewFileInfo(baseDir, filename string, isLeafBundle bool, fi os.FileInfo) *FileInfo {
var lang, translationBaseName, relPath string var lang, translationBaseName, relPath string
@ -218,12 +246,6 @@ func (sp *SourceSpec) NewFileInfo(baseDir, filename string, isLeafBundle bool, f
} }
// Open implements ReadableFile.
func (fi *FileInfo) Open() (io.ReadCloser, error) {
f, err := fi.sp.SourceFs.Open(fi.Filename())
return f, err
}
func printFs(fs afero.Fs, path string, w io.Writer) { func printFs(fs afero.Fs, path string, w io.Writer) {
if fs == nil { if fs == nil {
return return

View file

@ -24,6 +24,7 @@ import (
"golang.org/x/text/unicode/norm" "golang.org/x/text/unicode/norm"
) )
// Filesystem represents a source filesystem.
type Filesystem struct { type Filesystem struct {
files []ReadableFile files []ReadableFile
filesInit sync.Once filesInit sync.Once
@ -33,14 +34,17 @@ type Filesystem struct {
SourceSpec SourceSpec
} }
// Input describes a source input.
type Input interface { type Input interface {
Files() []ReadableFile Files() []ReadableFile
} }
// NewFilesystem returns a new filesytem for a given source spec.
func (sp SourceSpec) NewFilesystem(base string) *Filesystem { func (sp SourceSpec) NewFilesystem(base string) *Filesystem {
return &Filesystem{SourceSpec: sp, Base: base} return &Filesystem{SourceSpec: sp, Base: base}
} }
// Files returns a slice of readable files.
func (f *Filesystem) Files() []ReadableFile { func (f *Filesystem) Files() []ReadableFile {
f.filesInit.Do(func() { f.filesInit.Do(func() {
f.captureFiles() f.captureFiles()

View file

@ -76,6 +76,7 @@ func NewSourceSpec(ps *helpers.PathSpec, fs afero.Fs) *SourceSpec {
} }
// IgnoreFile returns whether a given file should be ignored.
func (s *SourceSpec) IgnoreFile(filename string) bool { func (s *SourceSpec) IgnoreFile(filename string) bool {
if filename == "" { if filename == "" {
if _, ok := s.SourceFs.(*afero.OsFs); ok { if _, ok := s.SourceFs.(*afero.OsFs); ok {
@ -109,6 +110,8 @@ func (s *SourceSpec) IgnoreFile(filename string) bool {
return false return false
} }
// IsRegularSourceFile returns whether filename represents a regular file in the
// source filesystem.
func (s *SourceSpec) IsRegularSourceFile(filename string) (bool, error) { func (s *SourceSpec) IsRegularSourceFile(filename string) (bool, error) {
fi, err := helpers.LstatIfPossible(s.SourceFs, filename) fi, err := helpers.LstatIfPossible(s.SourceFs, filename)
if err != nil { if err != nil {