Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ jobs:
- name: Setup Go environment
uses: ./.github/actions/setup

- name: Check gofumpt
run: test -z "$(go tool gofumpt -l .)"
- name: Run gostyle
uses: k1LoW/gostyle-action@e1b847d37b3041c5fdb8b911bcf00b350779ca61 # v1.5.1

- name: Run go vet
run: go vet -all -vettool=$(go tool -n csvppvet) ./...
- name: Run golangci-lint
uses: golangci/golangci-lint-action@1e7e51e771db61008b38414a730f564565cf7c20 # v9.2.0
with:
version: v2.9.0
58 changes: 58 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
version: "2"

linters:
enable:
# Defaults
- govet
- staticcheck
- errcheck
- ineffassign
- unused
# Additional
- gosec
- bidichk
- errorlint
- bodyclose
- unconvert
- usestdlibvars
- modernize
- exhaustive
exclusions:
rules:
- path: _test\.go
linters:
- errcheck
- gosec
- unused
settings:
staticcheck:
checks:
- "all"
- "-ST1000"
errcheck:
check-type-assertions: true
check-blank: true
unused:
parameters-are-used: false
exhaustive:
default-signifies-exhaustive: true
gosec:
excludes:
- G304

formatters:
enable:
- gofumpt
- goimports
settings:
goimports:
local-prefixes:
- github.com/osamingo/go-csvpp

run:
timeout: 5m
modules-download-mode: readonly

issues:
max-issues-per-linter: 0
max-same-issues: 0
8 changes: 6 additions & 2 deletions cmd/csvpp/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func init() {
rootCmd.AddCommand(convertCmd)
}

func runConvert(cmd *cobra.Command, _ []string) (retErr error) {
func runConvert(cmd *cobra.Command, _ []string) (retErr error) { //nolint:unused // cobra handler signature
// Get flag values
inputFile, err := cmd.Flags().GetString("input")
if err != nil {
Expand Down Expand Up @@ -105,7 +105,11 @@ func runConvert(cmd *cobra.Command, _ []string) (retErr error) {
if err != nil {
return err
}
defer r.Close()
defer func() {
if cerr := r.Close(); cerr != nil && retErr == nil {
retErr = fmt.Errorf("failed to close input: %w", cerr)
}
}()

// Open output
w, err := fileutil.OpenOutput(outputFile, cmd.OutOrStdout())
Expand Down
22 changes: 11 additions & 11 deletions cmd/csvpp/internal/tui/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ func parseFilterQuery(s string) filterQuery {
return filterQuery{}
}

if idx := strings.Index(s, ":"); idx >= 0 {
col := strings.TrimSpace(s[:idx])
val := strings.TrimSpace(s[idx+1:])
if before, after, ok := strings.Cut(s, ":"); ok {
col := strings.TrimSpace(before)
val := strings.TrimSpace(after)
if col != "" {
return filterQuery{
column: strings.ToLower(col),
Expand Down Expand Up @@ -224,16 +224,16 @@ func (m Model) updateFilterMode(msg tea.KeyMsg) (tea.Model, tea.Cmd) { //nostyle
m.table.Focus()
m.clearFilter()
return m, nil
}

// Forward key to textinput
var cmd tea.Cmd
m.filterInput, cmd = m.filterInput.Update(msg)
default:
// Forward key to textinput
var cmd tea.Cmd
m.filterInput, cmd = m.filterInput.Update(msg)

// Real-time filtering
m.applyFilter()
// Real-time filtering
m.applyFilter()

return m, cmd
return m, cmd
}
}

// updateNormalMode handles key events in normal navigation mode.
Expand Down
10 changes: 7 additions & 3 deletions cmd/csvpp/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,16 @@ func init() {
rootCmd.AddCommand(validateCmd)
}

func runValidate(cmd *cobra.Command, args []string) error {
func runValidate(cmd *cobra.Command, args []string) (retErr error) {
r, err := fileutil.OpenInputFromArgs(args)
if err != nil {
return err
}
defer r.Close()
defer func() {
if cerr := r.Close(); cerr != nil && retErr == nil {
retErr = fmt.Errorf("failed to close input: %w", cerr)
}
}()

reader := csvpp.NewReader(r)

Expand All @@ -50,6 +54,6 @@ func runValidate(cmd *cobra.Command, args []string) error {
recordCount++
}

fmt.Fprintf(cmd.OutOrStdout(), "Valid CSV++ file with %d record(s)\n", recordCount)
fmt.Fprintf(cmd.OutOrStdout(), "Valid CSV++ file with %d record(s)\n", recordCount) //nolint:errcheck // stdout write error is not actionable
return nil
}
10 changes: 7 additions & 3 deletions cmd/csvpp/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,16 @@ func init() {
rootCmd.AddCommand(viewCmd)
}

func runView(cmd *cobra.Command, args []string) error {
func runView(cmd *cobra.Command, args []string) (retErr error) {
r, err := fileutil.OpenInputFromArgs(args)
if err != nil {
return err
}
defer r.Close()
defer func() {
if cerr := r.Close(); cerr != nil && retErr == nil {
retErr = fmt.Errorf("failed to close input: %w", cerr)
}
}()

reader := csvpp.NewReader(r)

Expand All @@ -50,7 +54,7 @@ func runView(cmd *cobra.Command, args []string) error {
// Check if stdout is a terminal
if !term.IsTerminal(int(os.Stdout.Fd())) {
// Plain text output for pipes
fmt.Fprint(cmd.OutOrStdout(), tui.PlainView(headers, records))
fmt.Fprint(cmd.OutOrStdout(), tui.PlainView(headers, records)) //nolint:errcheck // stdout write error is not actionable
return nil
}

Expand Down
12 changes: 0 additions & 12 deletions cmd/csvppvet/main.go

This file was deleted.

2 changes: 1 addition & 1 deletion csvpp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func TestParseError_Unwrap(t *testing.T) {
t.Parallel()

got := parseErr.Unwrap()
if got != originalErr {
if !errors.Is(got, originalErr) {
t.Errorf("ParseError.Unwrap() = %v, want %v", got, originalErr)
}
})
Expand Down
1 change: 1 addition & 0 deletions csvpputil/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package csvpputil

import (
"github.com/goccy/go-yaml"

"github.com/osamingo/go-csvpp"
)

Expand Down
4 changes: 2 additions & 2 deletions csvpputil/json_array_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ type JSONArrayWriterOption func(*JSONArrayWriter)
// Output order is always determined by the headers order.
//
// Deprecated: This option is no longer needed as output order follows headers order.
func WithDeterministic(_ bool) JSONArrayWriterOption {
return func(_ *JSONArrayWriter) {}
func WithDeterministic(_ bool) JSONArrayWriterOption { //nolint:unused // kept for API compatibility
return func(_ *JSONArrayWriter) {} //nolint:unused // kept for API compatibility
}

// JSONArrayWriter writes CSV++ records as a JSON array using streaming output.
Expand Down
3 changes: 2 additions & 1 deletion csvpputil/json_array_writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package csvpputil_test
import (
"bytes"
"encoding/json/v2"
"errors"
"io"
"testing"

Expand Down Expand Up @@ -112,7 +113,7 @@ func TestJSONArrayWriter_Write(t *testing.T) {
}

err := w.Write([]*csvpp.Field{{Value: "Alice"}})
if err != io.ErrClosedPipe {
if !errors.Is(err, io.ErrClosedPipe) {
t.Errorf("Write() error = %v, want %v", err, io.ErrClosedPipe)
}
})
Expand Down
1 change: 1 addition & 0 deletions csvpputil/yaml_array_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"io"

"github.com/goccy/go-yaml"

"github.com/osamingo/go-csvpp"
)

Expand Down
3 changes: 2 additions & 1 deletion csvpputil/yaml_array_writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package csvpputil_test

import (
"bytes"
"errors"
"io"
"testing"

Expand Down Expand Up @@ -97,7 +98,7 @@ func TestYAMLArrayWriter_Write(t *testing.T) {
}

err := w.Write([]*csvpp.Field{{Value: "Alice"}})
if err != io.ErrClosedPipe {
if !errors.Is(err, io.ErrClosedPipe) {
t.Errorf("Write() error = %v, want %v", err, io.ErrClosedPipe)
}
})
Expand Down
5 changes: 3 additions & 2 deletions example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package csvpp_test

import (
"bytes"
"errors"
"fmt"
"io"
"log"
Expand Down Expand Up @@ -29,7 +30,7 @@ Bob,555-9999,40.7128^-74.0060
// Read all records
for {
record, err := reader.Read()
if err == io.EOF {
if errors.Is(err, io.EOF) {
break
}
if err != nil {
Expand Down Expand Up @@ -82,7 +83,7 @@ Bob,77~82

for {
record, err := reader.Read()
if err == io.EOF {
if errors.Is(err, io.EOF) {
break
}
if err != nil {
Expand Down
Loading