shithub: hugo

Download patch

ref: 5f2e1cb8969c2adac6c866b57cc331e1bc16d4e9
parent: c8ce65046dc7539f3bf5f6dd35fa7ece2bec866d
author: Cameron Moore <[email protected]>
date: Thu Sep 6 10:21:18 EDT 2018

hugofs: Fix golint issues

Fix godoc issues and the following:

hugofs/noop_fs.go:25:2: error var noOpErr should have name of the form errFoo

--- a/hugofs/basepath_real_filename_fs.go
+++ b/hugofs/basepath_real_filename_fs.go
@@ -36,16 +36,20 @@
 	return f.realFilename
 }
 
+// NewBasePathRealFilenameFs returns a new NewBasePathRealFilenameFs instance
+// using base.
 func NewBasePathRealFilenameFs(base *afero.BasePathFs) *BasePathRealFilenameFs {
 	return &BasePathRealFilenameFs{BasePathFs: base}
 }
 
-// This is a thin wrapper around afero.BasePathFs that provides the real filename
-// in Stat and LstatIfPossible.
+// BasePathRealFilenameFs is a thin wrapper around afero.BasePathFs that
+// provides the real filename in Stat and LstatIfPossible.
 type BasePathRealFilenameFs struct {
 	*afero.BasePathFs
 }
 
+// Stat returns the os.FileInfo structure describing a given file.  If there is
+// an error, it will be of type *os.PathError.
 func (b *BasePathRealFilenameFs) Stat(name string) (os.FileInfo, error) {
 	fi, err := b.BasePathFs.Stat(name)
 	if err != nil {
@@ -64,6 +68,9 @@
 	return &realFilenameInfo{FileInfo: fi, realFilename: filename}, nil
 }
 
+// LstatIfPossible returns the os.FileInfo structure describing a given file.
+// It attempts to use Lstat if supported or defers to the os.  In addition to
+// the FileInfo, a boolean is returned telling whether Lstat was called.
 func (b *BasePathRealFilenameFs) LstatIfPossible(name string) (os.FileInfo, bool, error) {
 
 	fi, ok, err := b.BasePathFs.LstatIfPossible(name)
--- a/hugofs/language_fs.go
+++ b/hugofs/language_fs.go
@@ -51,6 +51,7 @@
 	BaseDir() string
 }
 
+// LanguageDirsMerger implements the afero.DirsMerger interface.
 var LanguageDirsMerger = func(lofi, bofi []os.FileInfo) ([]os.FileInfo, error) {
 	m := make(map[string]*LanguageFileInfo)
 
@@ -84,6 +85,8 @@
 	return merged, nil
 }
 
+// LanguageFileInfo is a super-set of os.FileInfo with additional information
+// about the file in relation to its Hugo language.
 type LanguageFileInfo struct {
 	os.FileInfo
 	lang                string
@@ -99,22 +102,27 @@
 	weight int
 }
 
+// Filename returns a file's real filename.
 func (fi *LanguageFileInfo) Filename() string {
 	return fi.realFilename
 }
 
+// Path returns a file's relative filename.
 func (fi *LanguageFileInfo) Path() string {
 	return fi.relFilename
 }
 
+// RealName returns a file's real name.
 func (fi *LanguageFileInfo) RealName() string {
 	return fi.realName
 }
 
+// BaseDir returns a file's base directory.
 func (fi *LanguageFileInfo) BaseDir() string {
 	return fi.baseDir
 }
 
+// Lang returns a file's language.
 func (fi *LanguageFileInfo) Lang() string {
 	return fi.lang
 }
@@ -157,6 +165,7 @@
 	return fis, err
 }
 
+// LanguageFs represents a language filesystem.
 type LanguageFs struct {
 	// This Fs is usually created with a BasePathFs
 	basePath   string
@@ -166,6 +175,7 @@
 	afero.Fs
 }
 
+// NewLanguageFs creates a new LanguageFs.
 func NewLanguageFs(lang string, languages map[string]bool, fs afero.Fs) *LanguageFs {
 	if lang == "" {
 		panic("no lang set for the language fs")
@@ -181,10 +191,12 @@
 	return &LanguageFs{lang: lang, languages: languages, basePath: basePath, Fs: fs, nameMarker: marker}
 }
 
+// Lang returns a language filesystem's language.
 func (fs *LanguageFs) Lang() string {
 	return fs.lang
 }
 
+// Stat returns the os.FileInfo of a given file.
 func (fs *LanguageFs) Stat(name string) (os.FileInfo, error) {
 	name, err := fs.realName(name)
 	if err != nil {
@@ -199,6 +211,7 @@
 	return fs.newLanguageFileInfo(name, fi)
 }
 
+// Open opens the named file for reading.
 func (fs *LanguageFs) Open(name string) (afero.File, error) {
 	name, err := fs.realName(name)
 	if err != nil {
@@ -212,6 +225,9 @@
 	return &languageFile{File: f, fs: fs}, nil
 }
 
+// LstatIfPossible returns the os.FileInfo structure describing a given file.
+// It attempts to use Lstat if supported or defers to the os.  In addition to
+// the FileInfo, a boolean is returned telling whether Lstat was called.
 func (fs *LanguageFs) LstatIfPossible(name string) (os.FileInfo, bool, error) {
 	name, err := fs.realName(name)
 	if err != nil {
--- a/hugofs/noop_fs.go
+++ b/hugofs/noop_fs.go
@@ -22,9 +22,12 @@
 )
 
 var (
-	noOpErr          = errors.New("this is a filesystem that does nothing and this operation is not supported")
+	errNoOp          = errors.New("this is a filesystem that does nothing and this operation is not supported")
 	_       afero.Fs = (*noOpFs)(nil)
-	NoOpFs           = &noOpFs{}
+
+	// NoOpFs provides a no-op filesystem that implements the afero.Fs
+	// interface.
+	NoOpFs = &noOpFs{}
 )
 
 type noOpFs struct {
@@ -31,15 +34,15 @@
 }
 
 func (fs noOpFs) Create(name string) (afero.File, error) {
-	return nil, noOpErr
+	return nil, errNoOp
 }
 
 func (fs noOpFs) Mkdir(name string, perm os.FileMode) error {
-	return noOpErr
+	return errNoOp
 }
 
 func (fs noOpFs) MkdirAll(path string, perm os.FileMode) error {
-	return noOpErr
+	return errNoOp
 }
 
 func (fs noOpFs) Open(name string) (afero.File, error) {
@@ -51,15 +54,15 @@
 }
 
 func (fs noOpFs) Remove(name string) error {
-	return noOpErr
+	return errNoOp
 }
 
 func (fs noOpFs) RemoveAll(path string) error {
-	return noOpErr
+	return errNoOp
 }
 
 func (fs noOpFs) Rename(oldname string, newname string) error {
-	return noOpErr
+	return errNoOp
 }
 
 func (fs noOpFs) Stat(name string) (os.FileInfo, error) {
@@ -71,9 +74,9 @@
 }
 
 func (fs noOpFs) Chmod(name string, mode os.FileMode) error {
-	return noOpErr
+	return errNoOp
 }
 
 func (fs noOpFs) Chtimes(name string, atime time.Time, mtime time.Time) error {
-	return noOpErr
+	return errNoOp
 }
--- a/hugofs/rootmapping_fs.go
+++ b/hugofs/rootmapping_fs.go
@@ -94,6 +94,8 @@
 		rootMapToReal: rootMapToReal.Commit().Root()}, nil
 }
 
+// Stat returns the os.FileInfo structure describing a given file.  If there is
+// an error, it will be of type *os.PathError.
 func (fs *RootMappingFs) Stat(name string) (os.FileInfo, error) {
 	if fs.isRoot(name) {
 		return newRootMappingDirFileInfo(name), nil
@@ -107,6 +109,7 @@
 
 }
 
+// Open opens the named file for reading.
 func (fs *RootMappingFs) Open(name string) (afero.File, error) {
 	if fs.isRoot(name) {
 		return &rootMappingFile{name: name, fs: fs}, nil
@@ -119,6 +122,9 @@
 	return &rootMappingFile{File: f, name: name, fs: fs}, nil
 }
 
+// LstatIfPossible returns the os.FileInfo structure describing a given file.
+// It attempts to use Lstat if supported or defers to the os.  In addition to
+// the FileInfo, a boolean is returned telling whether Lstat was called.
 func (fs *RootMappingFs) LstatIfPossible(name string) (os.FileInfo, bool, error) {
 	if fs.isRoot(name) {
 		return newRootMappingDirFileInfo(name), false, nil