diff --git a/.husky/lint-api.sh b/.husky/lint-api.sh new file mode 100644 index 00000000..4a9a8a81 --- /dev/null +++ b/.husky/lint-api.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +gofiles=$(git diff --cached --name-only --diff-filter=ACM | grep '.go$') +[ -z "$gofiles" ] && exit 0 + +# Automatically format go code, exit on error +echo "Formatting staged go files" +gofmt -w $gofiles diff --git a/.husky/lint-ui.sh b/.husky/lint-ui.sh new file mode 100644 index 00000000..3e563068 --- /dev/null +++ b/.husky/lint-ui.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +cd ui +npx lint-staged diff --git a/.husky/pre-commit b/.husky/pre-commit index c7e81ea6..608bb1be 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1,4 +1,8 @@ #!/bin/sh . "$(dirname "$0")/_/husky.sh" -cd ui && npx lint-staged +## Lint UI +sh "$(dirname "$0")/lint-ui.sh" + +## Lint API +sh "$(dirname "$0")/lint-api.sh" diff --git a/api/scanner/cache.go b/api/scanner/cache.go index 2f3b6eb7..246ef621 100644 --- a/api/scanner/cache.go +++ b/api/scanner/cache.go @@ -87,7 +87,7 @@ func (c *AlbumScannerCache) GetMediaType(path string) (*MediaType, error) { return mediaType, nil } -func (c *AlbumScannerCache) GetAlbumIgnore(path string) (*[]string) { +func (c *AlbumScannerCache) GetAlbumIgnore(path string) *[]string { c.mutex.Lock() defer c.mutex.Unlock() diff --git a/api/scanner/exif/exif.go b/api/scanner/exif/exif.go index 85f9eea0..2980d8a5 100644 --- a/api/scanner/exif/exif.go +++ b/api/scanner/exif/exif.go @@ -42,7 +42,6 @@ func SaveEXIF(tx *gorm.DB, media *models.Media) (*models.MediaEXIF, error) { parser = &externalExifParser{} } - exif, err := parser.ParseExif(media) if err != nil { return nil, errors.Wrap(err, "failed to parse exif data") diff --git a/api/scanner/scanner_user.go b/api/scanner/scanner_user.go index db38cb0c..96f68f64 100644 --- a/api/scanner/scanner_user.go +++ b/api/scanner/scanner_user.go @@ -17,7 +17,7 @@ import ( "gorm.io/gorm" ) -func getPhotoviewIgnore(ignorePath string) ([]string , error){ +func getPhotoviewIgnore(ignorePath string) ([]string, error) { var photoviewIgnore []string // Open .photoviewignore file, if exists @@ -30,13 +30,13 @@ func getPhotoviewIgnore(ignorePath string) ([]string , error){ defer photoviewIgnoreFile.Close() // Read and save .photoviewignore data - scanner := bufio.NewScanner(photoviewIgnoreFile) - for scanner.Scan() { + scanner := bufio.NewScanner(photoviewIgnoreFile) + for scanner.Scan() { photoviewIgnore = append(photoviewIgnore, scanner.Text()) log.Printf("Ignore found: %s", scanner.Text()) } - return photoviewIgnore, scanner.Err() + return photoviewIgnore, scanner.Err() } func findAlbumsForUser(db *gorm.DB, user *models.User, album_cache *AlbumScannerCache) ([]*models.Album, []error) { @@ -101,7 +101,7 @@ func findAlbumsForUser(db *gorm.DB, user *models.User, album_cache *AlbumScanner // Skip this dir if in ignore list ignorePaths := ignore.CompileIgnoreLines(albumIgnore...) - if (ignorePaths.MatchesPath(albumPath + "/")) { + if ignorePaths.MatchesPath(albumPath + "/") { log.Printf("Skip, directroy %s is in ignore file", albumPath) continue }