Skip to content

Commit

Permalink
Add linter configs
Browse files Browse the repository at this point in the history
  • Loading branch information
smbl64 committed Oct 8, 2023
1 parent ea72d3b commit 1ffcb08
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 4 deletions.
45 changes: 45 additions & 0 deletions .golangci.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
[output]
format = "colored-line-number"

[linters]
enable = [
# Visit https://golangci-lint.run/usage/linters/
# for the full, current list of available linters.

# Default linters
"deadcode", # Finds unused code
"errcheck", # Detect unchecked errors
"gosimple", # Suggest code simplifications
"govet", # Reports suspicious constructs
"ineffassign", # Detects unused variable assignments
"staticcheck", # go vet on steroids
"structcheck", # Find unused struct fields
"typecheck", # Standard Go type checks
"unused", # Detect unused constants, variables, functions and types
"varcheck", # Find unused global variables and constants

# Suggested additional linters
"gocyclo", # or "cyclop", # Detect cyclomatic complexity
"goconst", # Detect repeated values that can be made constants
"gofumpt", # Or "gofmt", # Enforce standard formatting
"goimports", # Ensure standard import formatting/ordering
"misspell", # Fix spelling errors
"revive", # General purpose linter
"unconvert", # Detect unnecessary type conversions
"unparam", # Detect unused function parameters

# Optional
"bodyclose", # Check whether HTTP response bodies are closed
# "goerr113", # Enforce standard error handling practices
# "depguard", # Forbid certain package imports
# "dupl", # Detect duplicate code
# "errchkjson", # some JSON-specific checks
# "gomnd", # Magic number detection
"nakedret", # Detect naked returns
# "rowserrcheck", # Check whether Err of rows is checked
# "sqlclosecheck", # Ensure sql.Rows and sql.Stmt are closed
"tparallel", # Detects inappropriate use of t.Parallel()
]

[issues]
exclude-use-default = false
24 changes: 20 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// nolint: revive
package main

import (
Expand Down Expand Up @@ -40,10 +41,15 @@ func process(videoID, filename string) error {
if err != nil {
return err
}
defer resp.Body.Close()
defer func() {
err := resp.Body.Close()
if err != nil {
fmt.Printf("failed to close the body: %s", err)
}
}()

if resp.StatusCode != http.StatusOK {
return fmt.Errorf("Bad status code: %d", resp.StatusCode)
return fmt.Errorf("bad status code: %d", resp.StatusCode)
}

bodyBytes, err := io.ReadAll(resp.Body)
Expand Down Expand Up @@ -99,13 +105,23 @@ func downloadFile(url, filename string) (err error) {
if err != nil {
return err
}
defer resp.Body.Close()
defer func() {
err := resp.Body.Close()
if err != nil {
fmt.Printf("failed to close the body: %s", err)
}
}()

out, err := os.Create(filename)
if err != nil {
return err
}
defer out.Close()
defer func() {
err := out.Close()
if err != nil {
fmt.Printf("failed to close the output file: %s", err)
}
}()

n, err := io.Copy(out, resp.Body)
if err != nil {
Expand Down

0 comments on commit 1ffcb08

Please sign in to comment.