From 8b7720e3bf7ca84b83fe4a31432104aa9dc23e01 Mon Sep 17 00:00:00 2001 From: SmallCoccinelle <89733524+SmallCoccinelle@users.noreply.github.com> Date: Wed, 20 Oct 2021 07:34:19 +0200 Subject: [PATCH] Enable the appendAssign lint check (#1865) * Make copies of buffers Avoid reusing one of the incoming arrays as a append extension, and make a copy of the data. It's cleaner in the long run and possibly easier for the GC to maintain. * Avoid appendAssign problems in tag code Reuse the existing slice when appending. * Fix appendAssign in encoder_scene_preview_chunk Appending and creating a new slice is somewhat unintuitive since the underlying slice might be extended to satisfy the new capacity. This sometimes leads to faulty logic. Rewrite the code so it reuses `args` for all appending, and builds one array clearly in the code. It follows the general style of the function where `args` is being built in small incremental batches and avoids the introduction of new names. * Enable the appendAssign check This makes us pass all gocritic warnings. Co-authored-by: WithoutPants <53250216+WithoutPants@users.noreply.github.com> --- .golangci.yml | 4 ---- pkg/autotag/scene_test.go | 6 ++++-- pkg/ffmpeg/encoder_scene_preview_chunk.go | 8 ++++---- pkg/sqlite/tag.go | 4 ++-- 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index ce6b3018e..ad200b40b 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -36,10 +36,6 @@ linters: # Project-specific linter overrides linters-settings: - gocritic: - disabled-checks: - - appendAssign - gofmt: simplify: false diff --git a/pkg/autotag/scene_test.go b/pkg/autotag/scene_test.go index 3bf9b33e9..67e727a1b 100644 --- a/pkg/autotag/scene_test.go +++ b/pkg/autotag/scene_test.go @@ -67,7 +67,8 @@ func generateFalseNamePatterns(name string, separator, ext string) []string { } func generateTestPaths(testName, ext string) (scenePatterns []string, falseScenePatterns []string) { - separators := append(testSeparators, testEndSeparators...) + separators := testSeparators + separators = append(separators, testEndSeparators...) for _, separator := range separators { scenePatterns = append(scenePatterns, generateNamePatterns(testName, separator, ext)...) @@ -115,7 +116,8 @@ func generateTestTable(testName, ext string) []pathTestTable { var scenePatterns []string var falseScenePatterns []string - separators := append(testSeparators, testEndSeparators...) + separators := testSeparators + separators = append(separators, testEndSeparators...) for _, separator := range separators { scenePatterns = append(scenePatterns, generateNamePatterns(testName, separator, ext)...) diff --git a/pkg/ffmpeg/encoder_scene_preview_chunk.go b/pkg/ffmpeg/encoder_scene_preview_chunk.go index 3d8ea6062..92d660b94 100644 --- a/pkg/ffmpeg/encoder_scene_preview_chunk.go +++ b/pkg/ffmpeg/encoder_scene_preview_chunk.go @@ -85,11 +85,11 @@ func (e *Encoder) ScenePreviewVideoChunk(probeResult VideoFile, options ScenePre "-strict", "-2", } - args3 := append(args, args2...) - args3 = append(args3, argsAudio...) - finalArgs := append(args3, options.OutputPath) + args = append(args, args2...) + args = append(args, argsAudio...) + args = append(args, options.OutputPath) - _, err := e.run(probeResult.Path, finalArgs, nil) + _, err := e.run(probeResult.Path, args, nil) return err } diff --git a/pkg/sqlite/tag.go b/pkg/sqlite/tag.go index 5373088ae..a4906c4dc 100644 --- a/pkg/sqlite/tag.go +++ b/pkg/sqlite/tag.go @@ -649,13 +649,13 @@ func (qb *tagQueryBuilder) Merge(source []int, destination int) error { "performers_tags": "performer_id", } - tagArgs := append(args, destination) + args = append(args, destination) for table, idColumn := range tagTables { _, err := qb.tx.Exec(`UPDATE `+table+` SET tag_id = ? WHERE tag_id IN `+inBinding+` AND NOT EXISTS(SELECT 1 FROM `+table+` o WHERE o.`+idColumn+` = `+table+`.`+idColumn+` AND o.tag_id = ?)`, - tagArgs..., + args..., ) if err != nil { return err