Skip to content

Commit 368f3bf

Browse files
committed
set up linting and fix some lint
Signed-off-by: Elliot Murphy <statik@users.noreply.github.com>
1 parent fecf76f commit 368f3bf

8 files changed

Lines changed: 68 additions & 24 deletions

File tree

.golangci.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ linters-settings:
2020
min-occurrences: 3
2121
lll:
2222
line-length: 120
23-
maligned:
24-
suggest-new: true
2523
misspell:
2624
locale: US
2725
funlen:
@@ -34,6 +32,15 @@ linters:
3432
# prealloc is not recommended by `golangci-lint` developers.
3533
- prealloc
3634
- gochecknoglobals
35+
- interfacer
36+
- scopelint
37+
- maligned
38+
- forbidigo
39+
- gochecknoinits
40+
- exhaustivestruct
41+
- testpackage
42+
- ifshort
43+
- gofumpt
3744

3845
run:
3946
skip-files:

BUILD.bazel

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ go_library(
2121
go_binary(
2222
name = "vbs-linux",
2323
embed = [":go_default_library"],
24-
goos = "linux",
2524
goarch = "amd64",
25+
goos = "linux",
2626
visibility = ["//visibility:public"],
2727
x_defs = {
2828
"version": VERSION,
@@ -32,8 +32,8 @@ go_binary(
3232
go_binary(
3333
name = "vbs-darwin",
3434
embed = [":go_default_library"],
35-
goos = "darwin",
3635
goarch = "amd64",
36+
goos = "darwin",
3737
visibility = ["//visibility:public"],
3838
x_defs = {
3939
"version": VERSION,
@@ -43,8 +43,8 @@ go_binary(
4343
go_binary(
4444
name = "vbs-windows",
4545
embed = [":go_default_library"],
46-
goos = "windows",
4746
goarch = "amd64",
47+
goos = "windows",
4848
visibility = ["//visibility:public"],
4949
x_defs = {
5050
"version": VERSION,
@@ -125,3 +125,17 @@ sh_binary(
125125
tags = ["manual"],
126126
visibility = ["//visibility:public"],
127127
)
128+
129+
sh_binary(
130+
name = "lint",
131+
srcs = ["lint.sh"],
132+
args = [
133+
"$(location @bazel_gazelle//cmd/gazelle)",
134+
],
135+
data = [
136+
"@bazel_gazelle//cmd/gazelle",
137+
"@go_sdk//:files",
138+
],
139+
tags = ["manual"],
140+
visibility = ["//visibility:public"],
141+
)

cmd/chapters.go

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ var chapterSplitCmd = &cobra.Command{
4646
}
4747

4848
func chapterSplit(cmd *cobra.Command, args []string) {
49-
5049
_, err := exec.LookPath("ffprobe")
5150

5251
if err != nil {
@@ -67,6 +66,10 @@ func chapterSplit(cmd *cobra.Command, args []string) {
6766
}
6867

6968
data, err := getChapters(target)
69+
if err != nil {
70+
log.Fatal().Err(err).Msg("Could not extract chapters")
71+
}
72+
7073
base := strings.Trim(path.Base(target), path.Ext(target))
7174
targetdir := fmt.Sprintf("split_%s", base)
7275
err = os.MkdirAll(targetdir, 0777)
@@ -79,18 +82,19 @@ func chapterSplit(cmd *cobra.Command, args []string) {
7982

8083
for _, c := range data.Chapters {
8184
wg.Add(1)
85+
8286
go copyChapter(&wg, c, target, targetdir)
8387
}
8488

8589
wg.Wait()
8690
}
8791

88-
func copyChapter(wg *sync.WaitGroup, c chapter, sourcefile, targetdir string) error {
92+
func copyChapter(wg *sync.WaitGroup, c chapter, sourcefile, targetdir string) {
8993
defer wg.Done()
9094

9195
title := strings.Trim(c.Tags.Title, " \n\r")
9296
safetitle := sanitize.Name(title)
93-
prefix := fmt.Sprintf("%03d_", c.Id)
97+
prefix := fmt.Sprintf("%03d_", c.ID)
9498
outfile := filepath.Join(targetdir, prefix+safetitle+path.Ext(sourcefile))
9599

96100
cmd := exec.Command("ffmpeg",
@@ -107,8 +111,6 @@ func copyChapter(wg *sync.WaitGroup, c chapter, sourcefile, targetdir string) er
107111
if err != nil {
108112
log.Error().Err(err).Msgf("%s: %s\n", outfile, output)
109113
}
110-
111-
return err
112114
}
113115

114116
// sample json output
@@ -135,7 +137,7 @@ type tags struct {
135137
type chapter struct {
136138
StartTime string `json:"start_time"`
137139
EndTime string `json:"end_time"`
138-
Id int `json:"id"`
140+
ID int `json:"id"`
139141
Tags tags `json:"tags"`
140142
}
141143

@@ -154,16 +156,19 @@ func getChapters(target string) (ffmprobeResponse, error) {
154156
response := ffmprobeResponse{}
155157

156158
if err != nil {
157-
return response, err
159+
return response, fmt.Errorf("could not probe chapters: %w", err)
158160
}
159161

160162
err = json.Unmarshal(output, &response)
161163

162-
return response, err
164+
if err != nil {
165+
return response, fmt.Errorf("failed unmarshaling ffprobe response: %w", err)
166+
}
167+
168+
return response, nil
163169
}
164170

165171
func chapterList(cmd *cobra.Command, args []string) {
166-
167172
_, err := exec.LookPath("ffprobe")
168173

169174
if err != nil {
@@ -191,7 +196,7 @@ func chapterList(cmd *cobra.Command, args []string) {
191196

192197
formattedJSON, err := json.MarshalIndent(data, "", " ")
193198
if err != nil {
194-
log.Fatal().Err(err).Msg("Trouble marshalling to JSON")
199+
log.Fatal().Err(err).Msg("Trouble marshaling to JSON")
195200
}
196201

197202
_, _ = os.Stdout.Write(formattedJSON)

cmd/ivs.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ var ivsPutMetadataCmd = &cobra.Command{
3838
Short: "Send payload to IVS PutMetadata.",
3939
Long: `Send messages to IVS using PutMetadata API.`,
4040
Run: ivsPutMetadata,
41-
Args: cobra.ExactArgs(2),
41+
Args: cobra.ExactArgs(2), //nolint:gomnd // this is an appropriate magic number
4242
}
4343

4444
func ivsOscBridge(cmd *cobra.Command, args []string) {
@@ -51,7 +51,7 @@ func ivsOscBridge(cmd *cobra.Command, args []string) {
5151
svc := ivs.New(s)
5252

5353
d := osc.NewStandardDispatcher()
54-
d.AddMsgHandler("/vbs/ivsbridge", func(msg *osc.Message) {
54+
_ = d.AddMsgHandler("/vbs/ivsbridge", func(msg *osc.Message) {
5555
log.Debug().Msg(msg.String())
5656
data := fmt.Sprintf("%v", msg.Arguments[0])
5757
input := &ivs.PutMetadataInput{
@@ -70,8 +70,7 @@ func ivsOscBridge(cmd *cobra.Command, args []string) {
7070
Dispatcher: d,
7171
}
7272

73-
err := server.ListenAndServe()
74-
if err != nil {
73+
if err := server.ListenAndServe(); err != nil {
7574
log.Error().Err(err).Msg("error from server.ListenAndServe")
7675
}
7776
}

cmd/root.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ import (
2929

3030
var cfgFile string
3131

32-
// Debug controls whether or not debug messages should be printed
32+
// Debug controls whether or not to enable debug level logging.
3333
var Debug bool
3434

35-
// rootCmd represents the base command when called without any subcommands
35+
// rootCmd represents the base command when called without any subcommands.
3636
var rootCmd = &cobra.Command{
3737
Version: "dev",
3838
Use: "vbs",
@@ -59,6 +59,7 @@ use at your own risk.
5959
// This is called by main.main(). It only needs to happen once to the rootCmd.
6060
func Execute(v string) {
6161
rootCmd.SetVersionTemplate(v)
62+
6263
if err := rootCmd.Execute(); err != nil {
6364
log.Error().Err(err).Msg("error running root command")
6465
os.Exit(1)
@@ -67,6 +68,7 @@ func Execute(v string) {
6768

6869
func init() {
6970
zerolog.TimeFieldFormat = time.RFC3339
71+
7072
if isatty.IsTerminal(os.Stdout.Fd()) {
7173
output := zerolog.ConsoleWriter{Out: os.Stderr}
7274
log.Logger = log.With().Caller().Logger().Output(output)

lint.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env bash
2+
set -eo pipefail
3+
4+
export RUNFILES_DIR="$PWD"/..
5+
export PATH="$PWD/external/go_sdk/bin:$PATH"
6+
gazelle="$PWD/$1"
7+
8+
echo "Using these commands"
9+
command -v golangci-lint
10+
echo "$gazelle"
11+
12+
cd "$BUILD_WORKSPACE_DIRECTORY"
13+
14+
golangci-lint run

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
"github.com/kindlyops/vbs/cmd"
1919
)
2020

21-
// these are filled out as linker flags by bazel
21+
// these are filled out as linker flags by bazel.
2222
var (
2323
version = "dev"
2424
)

main_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func TestMain(m *testing.M) {
1717
os.Exit(m.Run())
1818
}
1919

20-
// Make sure that the x_defs override is working with the bazel build
20+
// Make sure that the x_defs override is working with the bazel build.
2121
func TestDefaultVersion(t *testing.T) {
2222
t.Parallel()
2323

@@ -37,18 +37,21 @@ func TestCLIVersion(t *testing.T) {
3737
if _, err = os.Stat(path); os.IsNotExist(err) {
3838
t.Fatalf("Missing binary %v", path)
3939
}
40+
4041
file, err := filepath.EvalSymlinks(path)
4142
if err != nil {
4243
t.Fatalf("Invalid filename %v", path)
4344
}
45+
4446
cmd := exec.Command(file, "--version")
4547
cmd.Stderr = os.Stderr
48+
4649
res, err := cmd.Output()
4750
if err != nil {
4851
t.Fatalf("failed running '%v': %v", path, err)
4952
}
50-
output := strings.TrimSpace(string(res))
5153

54+
output := strings.TrimSpace(string(res))
5255
if output != "dev.bazel version" {
5356
t.Error("Expected", "dev.bazel version", "got", output)
5457
}

0 commit comments

Comments
 (0)