Skip to content

Commit

Permalink
feat(linter): Add linter to the codebase (#146)
Browse files Browse the repository at this point in the history
This commit adds a linter to the codebase to ensure code quality and consistency.

The following changes were made:
- Adjusted functions to adhere to linter rules
- Made changes to commented lines to comply with linter recommendations

Note: No breaking changes were introduced in this commit.

Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com>
  • Loading branch information
rodneyosodo committed Feb 4, 2024
1 parent 2b7fe45 commit 8adc7c2
Show file tree
Hide file tree
Showing 24 changed files with 67 additions and 45 deletions.
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,4 @@ linters:
- goprintffuncname
- mirror
- nakedret
- gofumpt
2 changes: 1 addition & 1 deletion browser/files/localassets.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ func baseNames(n string) []string {
ext = path.Ext(n)
}
}

func escapeName(n string) string {
b := strings.Builder{}
for _, c := range n {
Expand All @@ -219,7 +220,6 @@ func (la *LocalAssetBrowser) ReadMetadataFromFile(a *browser.LocalAssetFile) err

// Open the file
r, err := a.PartialSourceReader()

if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions browser/files/localassets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ func (mfs *inMemFS) addFile(name string) *inMemFS {
return mfs
}
dir := path.Dir(name)
mfs.err = errors.Join(mfs.err, mfs.MkdirAll(dir, 0777))
mfs.err = errors.Join(mfs.err, mfs.WriteFile(name, []byte(name), 0777))
mfs.err = errors.Join(mfs.err, mfs.MkdirAll(dir, 0o777))
mfs.err = errors.Join(mfs.err, mfs.WriteFile(name, []byte(name), 0o777))
return mfs
}

Expand Down
2 changes: 1 addition & 1 deletion browser/gp/googlephotos.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ func matchEditedName(jsonName string, fileName string) bool {
return false
}

//TODO: This one interferes with matchVeryLongNameWithNumber
// TODO: This one interferes with matchVeryLongNameWithNumber

// matchForgottenDuplicates
// original_1d4caa6f-16c6-4c3d-901b-9387de10e528_.json
Expand Down
4 changes: 2 additions & 2 deletions browser/gp/testgp_samples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ func (mfs *inMemFS) addFile(name string, content []byte) *inMemFS {
return mfs
}
dir := path.Dir(name)
mfs.err = errors.Join(mfs.err, mfs.MkdirAll(dir, 0777))
mfs.err = errors.Join(mfs.err, mfs.WriteFile(name, content, 0777))
mfs.err = errors.Join(mfs.err, mfs.MkdirAll(dir, 0o777))
mfs.err = errors.Join(mfs.err, mfs.WriteFile(name, content, 0o777))
return mfs
}

Expand Down
31 changes: 20 additions & 11 deletions browser/gp/testgp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,16 @@ func TestBrowse(t *testing.T) {
gen func() *inMemFS
results []fileResult // file name / title
}{

{"simpleYear", simpleYear,
{
"simpleYear", simpleYear,
sortFileResult([]fileResult{
{name: "PXL_20230922_144936660.jpg", size: 10, title: "PXL_20230922_144936660.jpg"},
{name: "PXL_20230922_144956000.jpg", size: 20, title: "PXL_20230922_144956000.jpg"},
}),
},

{"simpleAlbum", simpleAlbum,
{
"simpleAlbum", simpleAlbum,
sortFileResult([]fileResult{
{name: "PXL_20230922_144936660.jpg", size: 10, title: "PXL_20230922_144936660.jpg"},
{name: "PXL_20230922_144934440.jpg", size: 15, title: "PXL_20230922_144934440.jpg"},
Expand All @@ -33,53 +34,61 @@ func TestBrowse(t *testing.T) {
}),
},

{"albumWithoutImage", albumWithoutImage,
{
"albumWithoutImage", albumWithoutImage,
sortFileResult([]fileResult{
{name: "PXL_20230922_144936660.jpg", size: 10, title: "PXL_20230922_144936660.jpg"},
{name: "PXL_20230922_144934440.jpg", size: 15, title: "PXL_20230922_144934440.jpg"},
}),
},
{"namesWithNumbers", namesWithNumbers,
{
"namesWithNumbers", namesWithNumbers,
sortFileResult([]fileResult{
{name: "IMG_3479.JPG", size: 10, title: "IMG_3479.JPG"},
{name: "IMG_3479(1).JPG", size: 12, title: "IMG_3479.JPG"},
{name: "IMG_3479(2).JPG", size: 15, title: "IMG_3479.JPG"},
}),
},
{"namesTruncated", namesTruncated,
{
"namesTruncated", namesTruncated,
sortFileResult([]fileResult{
{name: "😀😃😄😁😆😅😂🤣🥲☺️😊😇🙂🙃😉😌😍🥰😘😗😙😚😋😛.jpg", size: 10, title: "😀😃😄😁😆😅😂🤣🥲☺️😊😇🙂🙃😉😌😍🥰😘😗😙😚😋😛😝😜🤪🤨🧐🤓😎🥸🤩🥳😏😒😞😔😟😕🙁☹️😣😖😫😩🥺😢😭😤😠😡🤬🤯😳🥵🥶.jpg"},
{name: "PXL_20230809_203449253.LONG_EXPOSURE-02.ORIGINA.jpg", size: 40, title: "PXL_20230809_203449253.LONG_EXPOSURE-02.ORIGINAL.jpg"},
{name: "05yqt21kruxwwlhhgrwrdyb6chhwszi9bqmzu16w0 2.jpg", size: 25, title: "05yqt21kruxwwlhhgrwrdyb6chhwszi9bqmzu16w0 2.jpg"},
}),
},

{"imagesWithoutJSON", imagesEditedJSON,
{
"imagesWithoutJSON", imagesEditedJSON,
sortFileResult([]fileResult{
{name: "PXL_20220405_090123740.PORTRAIT.jpg", size: 41, title: "PXL_20220405_090123740.PORTRAIT.jpg"},
{name: "PXL_20220405_090123740.PORTRAIT-modifié.jpg", size: 21, title: "PXL_20220405_090123740.PORTRAIT.jpg"},
}),
},

{"titlesWithForbiddenChars", titlesWithForbiddenChars,
{
"titlesWithForbiddenChars", titlesWithForbiddenChars,
sortFileResult([]fileResult{
{name: "27_06_12 - 1.mov", size: 52, title: "27/06/12 - 1.mov"},
{name: "27_06_12 - 1.jpg", size: 24, title: "27/06/12 - 1.jpg"},
}),
},
{"namesIssue39", namesIssue39,
{
"namesIssue39", namesIssue39,
sortFileResult([]fileResult{
{name: "Backyard_ceremony_wedding_photography_xxxxxxx_m.jpg", size: 1, title: "Backyard_ceremony_wedding_photography_xxxxxxx_magnoliastudios-371.jpg"},
{name: "Backyard_ceremony_wedding_photography_xxxxxxx_m(1).jpg", size: 181, title: "Backyard_ceremony_wedding_photography_xxxxxxx_magnoliastudios-181.jpg"},
{name: "Backyard_ceremony_wedding_photography_xxxxxxx_m(494).jpg", size: 494, title: "Backyard_ceremony_wedding_photography_markham_magnoliastudios-19.jpg"},
}),
},
{"issue68MPFiles", issue68MPFiles,
{
"issue68MPFiles", issue68MPFiles,
sortFileResult([]fileResult{
{name: "PXL_20221228_185930354.MP.jpg", size: 2, title: "PXL_20221228_185930354.MP.jpg"},
}),
},
{"issue68LongExposure", issue68LongExposure,
{
"issue68LongExposure", issue68LongExposure,
sortFileResult([]fileResult{
{name: "PXL_20230814_201154491.LONG_EXPOSURE-01.COVER.jpg", size: 1, title: "PXL_20230814_201154491.LONG_EXPOSURE-01.COVER.jpg"},
{name: "PXL_20230814_201154491.LONG_EXPOSURE-02.ORIGINA.jpg", size: 2, title: "PXL_20230814_201154491.LONG_EXPOSURE-02.ORIGINAL.jpg"},
Expand Down
3 changes: 2 additions & 1 deletion browser/localfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func (l *LocalAssetFile) PartialSourceReader() (reader io.Reader, err error) {
return nil, err
}
tempDir = filepath.Join(tempDir, "github.com/simulot/immich-go")
os.Mkdir(tempDir, 0700)
os.Mkdir(tempDir, 0o700)
l.tempFile, err = os.CreateTemp(tempDir, "")
if err != nil {
return nil, err
Expand Down Expand Up @@ -173,6 +173,7 @@ func (l *LocalAssetFile) IsDir() bool { return false }
func (l *LocalAssetFile) Name() string {
return l.FileName
}

func (l *LocalAssetFile) Size() int64 {
return int64(l.FileSize)
}
Expand Down
1 change: 1 addition & 0 deletions cmdstack/cmdstack.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func initSack(xtx context.Context, ic *immich.ImmichClient, log *logger.Log, arg
err := cmd.Parse(args)
return &app, err
}

func NewStackCommand(ctx context.Context, ic *immich.ImmichClient, log *logger.Log, args []string) error {
app, err := initSack(ctx, ic, log, args)
if err != nil {
Expand Down
11 changes: 0 additions & 11 deletions cmdupload/e2e_upload_folder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ type testCase struct {
}

func runCase(t *testing.T, tc testCase) {

var myEnv map[string]string
myEnv, err := godotenv.Read("../.env")
if err != nil {
Expand Down Expand Up @@ -89,11 +88,9 @@ func runCase(t *testing.T, tc testCase) {
t.Errorf("unexpected err: %v", err)
return
}

}

func TestE2eUpload(t *testing.T) {

tests := []testCase{
{
name: "upload folder",
Expand Down Expand Up @@ -172,7 +169,6 @@ func TestE2eUpload(t *testing.T) {
// PXL_20231006_063536303 should be archived
// Google Photos/Album test 6-10-23/PXL_20231006_063851485.jpg.json is favorite and has a description
func Test_DescriptionAndFavorite(t *testing.T) {

tc := testCase{
name: "Test_DescriptionAndFavorite",
args: []string{
Expand All @@ -187,7 +183,6 @@ func Test_DescriptionAndFavorite(t *testing.T) {
}

func Test_PermissionError(t *testing.T) {

tc := testCase{
name: "Test_PermissionError",
args: []string{
Expand All @@ -200,7 +195,6 @@ func Test_PermissionError(t *testing.T) {
}

func Test_CreateAlbumFolder(t *testing.T) {

tc := testCase{
name: "Test_CreateAlbumFolder",
args: []string{
Expand All @@ -215,7 +209,6 @@ func Test_CreateAlbumFolder(t *testing.T) {
}

func Test_XMP(t *testing.T) {

tc := testCase{
name: "Test_XMP",
args: []string{
Expand Down Expand Up @@ -264,7 +257,6 @@ func Test_Album_Issue_119(t *testing.T) {
}

func Test_Issue_126A(t *testing.T) {

tc := testCase{
name: "Test_Issue_126A",
args: []string{
Expand All @@ -280,7 +272,6 @@ func Test_Issue_126A(t *testing.T) {
}

func Test_Issue_126B(t *testing.T) {

tc := testCase{
name: "Test_Issue_126B",
args: []string{
Expand All @@ -296,7 +287,6 @@ func Test_Issue_126B(t *testing.T) {
}

func Test_Issue_129(t *testing.T) {

tc := testCase{
name: "Test_Issue_129",
args: []string{
Expand All @@ -311,7 +301,6 @@ func Test_Issue_129(t *testing.T) {
}

func Test_Issue_128(t *testing.T) {

tc := testCase{
name: "Test_Issue_128",
args: []string{
Expand Down
4 changes: 3 additions & 1 deletion cmdupload/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,6 @@ func (app *UpCmd) handleAsset(ctx context.Context, a *browser.LocalAssetFile) er
a.AddAlbum(browser.LocalAlbum{Name: al.AlbumName})
}
ID, err = app.UploadAsset(ctx, a)

if err != nil {
app.deleteServerList = append(app.deleteServerList, advice.ServerAsset)
if app.Delete {
Expand Down Expand Up @@ -725,20 +724,23 @@ func (ai *AssetIndex) adviceSameOnServer(sa *immich.Asset) *Advice {
ServerAsset: sa,
}
}

func (ai *AssetIndex) adviceSmallerOnServer(sa *immich.Asset) *Advice {
return &Advice{
Advice: SmallerOnServer,
Message: fmt.Sprintf("An asset with the same name:%q and date:%q but with smaller size:%s exists on the server. Replace it.", sa.OriginalFileName, sa.ExifInfo.DateTimeOriginal.Format(time.DateTime), formatBytes(sa.ExifInfo.FileSizeInByte)),
ServerAsset: sa,
}
}

func (ai *AssetIndex) adviceBetterOnServer(sa *immich.Asset) *Advice {
return &Advice{
Advice: BetterOnServer,
Message: fmt.Sprintf("An asset with the same name:%q and date:%q but with bigger size:%s exists on the server. No need to upload.", sa.OriginalFileName, sa.ExifInfo.DateTimeOriginal.Format(time.DateTime), formatBytes(sa.ExifInfo.FileSizeInByte)),
ServerAsset: sa,
}
}

func (ai *AssetIndex) adviceNotOnServer() *Advice {
return &Advice{
Advice: NotOnServer,
Expand Down
11 changes: 9 additions & 2 deletions cmdupload/upload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,32 @@ import (
"github.com/simulot/immich-go/logger"
)

type stubIC struct {
}
type stubIC struct{}

func (c *stubIC) GetAllAssetsWithFilter(context.Context, *immich.GetAssetOptions, func(*immich.Asset)) error {
return nil
}

func (c *stubIC) AssetUpload(context.Context, *browser.LocalAssetFile) (immich.AssetResponse, error) {
return immich.AssetResponse{}, nil
}

func (c *stubIC) DeleteAssets(context.Context, []string, bool) error {
return nil
}

func (c *stubIC) GetAllAlbums(context.Context) ([]immich.AlbumSimplified, error) {
return nil, nil
}

func (c *stubIC) AddAssetToAlbum(context.Context, string, []string) ([]immich.UpdateAlbumResult, error) {
return nil, nil
}

func (c *stubIC) CreateAlbum(context.Context, string, []string) (immich.AlbumSimplified, error) {
return immich.AlbumSimplified{}, nil
}

func (c *stubIC) UpdateAssets(ctx context.Context, ids []string, isArchived bool, isFavorite bool, latitude float64, longitude float64, removeParent bool, stackParentId string) error {
return nil
}
Expand Down Expand Up @@ -77,9 +82,11 @@ func (c *icCatchUploadsAssets) AssetUpload(ctx context.Context, a *browser.Local
ID: a.FileName,
}, nil
}

func (c *icCatchUploadsAssets) AddAssetToAlbum(ctx context.Context, album string, ids []string) ([]immich.UpdateAlbumResult, error) {
return nil, nil
}

func (c *icCatchUploadsAssets) CreateAlbum(ctx context.Context, album string, ids []string) (immich.AlbumSimplified, error) {
if album == "" {
panic("can't create album without name")
Expand Down
5 changes: 3 additions & 2 deletions helpers/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func (d *DockerConnect) Upload(ctx context.Context, file string, size int64, r i
}()
hdr := tar.Header{
Name: path.Base(file),
Mode: 0644,
Mode: 0o644,
Size: size,
ModTime: time.Now(),
}
Expand Down Expand Up @@ -232,7 +232,7 @@ func (d *DockerConnect) BatchUpload(ctx context.Context, dir string) (*batchUplo

hdr := tar.Header{
Name: f.name,
Mode: 0644,
Mode: 0o644,
Size: int64(len(f.content)),
ModTime: time.Now(),
}
Expand Down Expand Up @@ -270,6 +270,7 @@ func (b *batchUploader) Upload(name string, content []byte) error {
err := <-b.fileErr
return err
}

func (b *batchUploader) Close() error {
close(b.fileChannel)
return nil
Expand Down
1 change: 1 addition & 0 deletions helpers/fshelper/removefs.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func DirRemoveFS(name string) fs.FS {

return fsys
}

func (fsys dirRemoveFS) Remove(name string) error {
return os.Remove(filepath.Join(fsys.dir, name))
}
Expand Down
3 changes: 2 additions & 1 deletion immich/asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,8 @@ func (ic *ImmichClient) GetAssetByID(ctx context.Context, id string) (*Asset, er
func (ic *ImmichClient) UpdateAssets(ctx context.Context, ids []string,
isArchived bool, isFavorite bool,
latitude float64, longitude float64,
removeParent bool, stackParentId string) error {
removeParent bool, stackParentId string,
) error {
type updAssets struct {
IDs []string `json:"ids"`
IsArchived bool `json:"isArchived"`
Expand Down

0 comments on commit 8adc7c2

Please sign in to comment.