Skip to content

Commit

Permalink
chore: fix linter findings
Browse files Browse the repository at this point in the history
  • Loading branch information
jar-b committed Mar 7, 2024
1 parent 5cfed0f commit 97c2990
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 16 deletions.
21 changes: 10 additions & 11 deletions cli/cmds.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
},
}
Expand Down Expand Up @@ -299,23 +299,22 @@ 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)
}

return filenames, nil
}

func versionCmd(cmd *cobra.Command, args []string) {
func versionCmd(_ *cobra.Command, _ []string) {
fmt.Println("terrafmt v" + version.Version + "-" + version.GitCommit)
}

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<white>#######</> <cyan>B%d</><darkGray> @ #%d</>\n", index, endLine))
fmt.Fprint(w.writer, text)
}
Expand All @@ -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")
}
Expand Down Expand Up @@ -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,
Expand All @@ -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)
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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("<green>%s</>\n", l))
} else if strings.HasPrefix(l, "-") {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
7 changes: 3 additions & 4 deletions lib/blocks/blockreader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/blocks/blockreader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions lib/upgrade012/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down

0 comments on commit 97c2990

Please sign in to comment.