mirror of
https://github.com/danog/gojekyll.git
synced 2024-11-26 21:04:39 +01:00
Fix some metalinter warnings
This commit is contained in:
parent
9301e82793
commit
af5236f7ae
1
build.go
1
build.go
@ -54,6 +54,7 @@ func (s *Site) WritePage(page *Page) error {
|
||||
if !page.Static && filepath.Ext(dst) == "" {
|
||||
dst = filepath.Join(dst, "/index.html")
|
||||
}
|
||||
// nolint: gas
|
||||
if err := os.MkdirAll(filepath.Dir(dst), 0755); err != nil {
|
||||
return err
|
||||
}
|
||||
|
16
helpers.go
16
helpers.go
@ -16,13 +16,13 @@ func copyFile(dst, src string, perm os.FileMode) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer inf.Close()
|
||||
defer inf.Close() // nolint: errcheck, gas
|
||||
outf, err := os.Create(dst)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err = io.Copy(outf, inf); err != nil {
|
||||
_ = os.Remove(dst)
|
||||
_ = os.Remove(dst) // nolint: gas
|
||||
return err
|
||||
}
|
||||
return outf.Close()
|
||||
@ -46,8 +46,8 @@ func getString(m map[interface{}]interface{}, k string, defaultValue string) str
|
||||
return defaultValue
|
||||
}
|
||||
|
||||
// alternative to http://left-pad.io
|
||||
func leftPad(s string, n int) string {
|
||||
// LeftPad pads a string. It's an alternative to http://left-pad.io
|
||||
func LeftPad(s string, n int) string {
|
||||
if n <= len(s) {
|
||||
return s
|
||||
}
|
||||
@ -84,11 +84,12 @@ func stringMap(m map[interface{}]interface{}) map[string]interface{} {
|
||||
return result
|
||||
}
|
||||
|
||||
func postfixWalk(path string, walkFn filepath.WalkFunc) error {
|
||||
// PostfixWalk is like filepath.Walk, but visits the directory after its contents.
|
||||
func PostfixWalk(path string, walkFn filepath.WalkFunc) error {
|
||||
if files, err := ioutil.ReadDir(path); err == nil {
|
||||
for _, stat := range files {
|
||||
if stat.IsDir() {
|
||||
if err = postfixWalk(filepath.Join(path, stat.Name()), walkFn); err != nil {
|
||||
if err = PostfixWalk(filepath.Join(path, stat.Name()), walkFn); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@ -99,6 +100,7 @@ func postfixWalk(path string, walkFn filepath.WalkFunc) error {
|
||||
return walkFn(path, info, err)
|
||||
}
|
||||
|
||||
// IsNotEmpty returns returns a boolean indicating whether the error is known to report that a directory is not empty.
|
||||
func IsNotEmpty(err error) bool {
|
||||
if err, ok := err.(*os.PathError); ok {
|
||||
return err.Err.(syscall.Errno) == syscall.ENOTEMPTY
|
||||
@ -129,7 +131,7 @@ func RemoveEmptyDirectories(path string) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
return postfixWalk(path, walkFn)
|
||||
return PostfixWalk(path, walkFn)
|
||||
}
|
||||
|
||||
func stringArrayToMap(strings []string) map[string]bool {
|
||||
|
@ -7,9 +7,9 @@ import (
|
||||
)
|
||||
|
||||
func TestLeftPad(t *testing.T) {
|
||||
assert.Equal(t, "abc", leftPad("abc", 0))
|
||||
assert.Equal(t, "abc", leftPad("abc", 3))
|
||||
assert.Equal(t, " abc", leftPad("abc", 6))
|
||||
assert.Equal(t, "abc", LeftPad("abc", 0))
|
||||
assert.Equal(t, "abc", LeftPad("abc", 3))
|
||||
assert.Equal(t, " abc", LeftPad("abc", 6))
|
||||
}
|
||||
|
||||
func TestGetXXX(t *testing.T) {
|
||||
|
@ -43,11 +43,11 @@ func TestWhereExpObjects(t *testing.T) {
|
||||
|
||||
data := map[string]interface{}{
|
||||
"array": []map[string]interface{}{
|
||||
map[string]interface{}{
|
||||
{
|
||||
"name": "A",
|
||||
"flag": true,
|
||||
},
|
||||
map[string]interface{}{
|
||||
{
|
||||
"name": "B",
|
||||
"flag": false,
|
||||
},
|
||||
|
3
main.go
3
main.go
@ -24,8 +24,7 @@ var options struct {
|
||||
const configurationFileLabel = "Configuration file:"
|
||||
|
||||
func printSetting(label string, value string) {
|
||||
fmt.Printf("%s %s\n",
|
||||
leftPad(label, len(configurationFileLabel)), value)
|
||||
fmt.Printf("%s %s\n", LeftPad(label, len(configurationFileLabel)), value)
|
||||
}
|
||||
|
||||
func printPathSetting(label string, path string) {
|
||||
|
4
site.go
4
site.go
@ -112,7 +112,7 @@ func (s *Site) readConfig(bytes []byte) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// KeepFile returns true iff clean should leave the file in the destination directory.
|
||||
// KeepFile returns a boolean indicating that clean should leave the file in the destination directory.
|
||||
func (s *Site) KeepFile(path string) bool {
|
||||
// TODO
|
||||
return false
|
||||
@ -134,7 +134,7 @@ func (s *Site) GetFileURL(path string) (string, bool) {
|
||||
return "", false
|
||||
}
|
||||
|
||||
// Exclude returns true iff a site excludes a file.
|
||||
// Exclude returns a boolean indicating that the site excludes a file.
|
||||
func (s *Site) Exclude(path string) bool {
|
||||
// TODO exclude based on glob, not exact match
|
||||
inclusionMap := stringArrayToMap(s.config.Include)
|
||||
|
Loading…
Reference in New Issue
Block a user