From 97c2990c7a7512f508f9442c3087071053f3b2c3 Mon Sep 17 00:00:00 2001 From: Jared Baker Date: Thu, 7 Mar 2024 12:16:49 -0500 Subject: [PATCH] chore: fix linter findings --- cli/cmds.go | 21 ++++++++++----------- lib/blocks/blockreader.go | 7 +++---- lib/blocks/blockreader_test.go | 2 +- lib/upgrade012/upgrade_test.go | 1 + 4 files changed, 15 insertions(+), 16 deletions(-) diff --git a/cli/cmds.go b/cli/cmds.go index dcaf7054..8a4731e8 100644 --- a/cli/cmds.go +++ b/cli/cmds.go @@ -41,7 +41,7 @@ func Make() *cobra.Command { Long: `A small utility that formats terraform blocks found in files. Primarily intended to help with terraform provider development.`, Args: cobra.RangeArgs(0, 0), SilenceErrors: true, - RunE: func(cmd *cobra.Command, args []string) error { + RunE: func(_ *cobra.Command, _ []string) error { return fmt.Errorf("no command specified") }, } @@ -299,7 +299,6 @@ func allFiles(fs afero.Fs, path string, pattern string) ([]string, error) { return nil }, ) - if err != nil { return nil, fmt.Errorf("error walking path (%s): %w", path, err) } @@ -307,7 +306,7 @@ func allFiles(fs afero.Fs, path string, pattern string) ([]string, error) { return filenames, nil } -func versionCmd(cmd *cobra.Command, args []string) { +func versionCmd(_ *cobra.Command, _ []string) { fmt.Println("terrafmt v" + version.Version + "-" + version.GitCommit) } @@ -315,7 +314,7 @@ type textBlockWriter struct { writer io.Writer } -func (w textBlockWriter) Write(index, startLine, endLine int, text string) { +func (w textBlockWriter) Write(index, _, endLine int, text string) { fmt.Fprint(w.writer, c.Sprintf("\n####### B%d @ #%d\n", index, endLine)) fmt.Fprint(w.writer, text) } @@ -326,7 +325,7 @@ type zeroTerminatedBlockWriter struct { writer io.Writer } -func (w zeroTerminatedBlockWriter) Write(index, startLine, endLine int, text string) { +func (w zeroTerminatedBlockWriter) Write(_, _, _ int, text string) { fmt.Fprint(w.writer, text) fmt.Fprint(w.writer, "\x00") } @@ -380,7 +379,7 @@ func (w jsonBlockWriter) Close() error { func findBlocksInFile(fs afero.Fs, log *logrus.Logger, filename string, verbose, zeroTerminated, jsonOutput, fmtverbs bool, stdin io.Reader, stdout, stderr io.Writer) error { var blockWriter blocks.BlockWriter - // nolint: gocritic + //nolint: gocritic if zeroTerminated { blockWriter = zeroTerminatedBlockWriter{ writer: stdout, @@ -400,7 +399,7 @@ func findBlocksInFile(fs afero.Fs, log *logrus.Logger, filename string, verbose, ReadOnly: true, LineRead: blocks.ReaderIgnore, BlockWriter: blockWriter, - BlockRead: func(br *blocks.Reader, i int, b string, preserveIndent bool) error { + BlockRead: func(br *blocks.Reader, _ int, b string, _ bool) error { if fmtverbs { b = verbs.Escape(b) } @@ -433,7 +432,7 @@ func diffFile(fs afero.Fs, log *logrus.Logger, filename string, fmtverbs, verbos Log: log, ReadOnly: true, LineRead: blocks.ReaderPassthrough, - BlockRead: func(br *blocks.Reader, i int, b string, preserveIndent bool) error { + BlockRead: func(br *blocks.Reader, _ int, b string, preserveIndent bool) error { var fb string var err error if fmtverbs { @@ -464,7 +463,7 @@ func diffFile(fs afero.Fs, log *logrus.Logger, filename string, fmtverbs, verbos for scanner.Scan() { l := scanner.Text() - // nolint: gocritic + //nolint: gocritic if strings.HasPrefix(l, "+") { fmt.Fprint(outW, c.Sprintf("%s\n", l)) } else if strings.HasPrefix(l, "-") { @@ -504,7 +503,7 @@ func formatFile(fs afero.Fs, log *logrus.Logger, filename string, fmtverbs, fixF br := blocks.Reader{ Log: log, LineRead: blocks.ReaderPassthrough, - BlockRead: func(br *blocks.Reader, i int, b string, preserveIndent bool) error { + BlockRead: func(br *blocks.Reader, _ int, b string, preserveIndent bool) error { var fb string var err error if fmtverbs { @@ -582,7 +581,7 @@ func upgrade012File(fs afero.Fs, log *logrus.Logger, filename string, fmtverbs, br := blocks.Reader{ Log: log, LineRead: blocks.ReaderPassthrough, - BlockRead: func(br *blocks.Reader, i int, b string, preserveIndent bool) error { + BlockRead: func(br *blocks.Reader, _ int, b string, preserveIndent bool) error { var fb string var err error if fmtverbs { diff --git a/lib/blocks/blockreader.go b/lib/blocks/blockreader.go index 568c3ec4..b851bc69 100644 --- a/lib/blocks/blockreader.go +++ b/lib/blocks/blockreader.go @@ -62,12 +62,12 @@ type Reader struct { BlockWriter BlockWriter } -func ReaderPassthrough(br *Reader, number int, line string) error { +func ReaderPassthrough(br *Reader, _ int, line string) error { _, err := br.Writer.Write([]byte(line)) return err } -func ReaderIgnore(br *Reader, number int, line string) error { +func ReaderIgnore(_ *Reader, _ int, _ string) error { return nil } @@ -313,9 +313,8 @@ func (br *Reader) doTheThingPatternMatch(fs afero.Fs, filename string, stdin io. block = "" break - } else { - block += l2 } + block += l2 } // ensure last block in the file was property handled diff --git a/lib/blocks/blockreader_test.go b/lib/blocks/blockreader_test.go index 91961736..aa6efa66 100644 --- a/lib/blocks/blockreader_test.go +++ b/lib/blocks/blockreader_test.go @@ -270,7 +270,7 @@ func TestBlockDetection(t *testing.T) { Log: log, ReadOnly: true, LineRead: ReaderIgnore, - BlockRead: func(br *Reader, i int, b string, preserveIndent bool) error { + BlockRead: func(br *Reader, _ int, b string, _ bool) error { actualBlocks = append(actualBlocks, block{ leadingPadding: br.CurrentNodeLeadingPadding, text: b, diff --git a/lib/upgrade012/upgrade_test.go b/lib/upgrade012/upgrade_test.go index a187e90f..afa35d52 100644 --- a/lib/upgrade012/upgrade_test.go +++ b/lib/upgrade012/upgrade_test.go @@ -161,6 +161,7 @@ Hi there i am going to fail... =C } for _, test := range tests { + test := test t.Run(test.name, func(t *testing.T) { t.Parallel()