Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return no. of records processed #30

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@ _testmain.go
*.exe
*.test
*.prof

vendor
15 changes: 14 additions & 1 deletion Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions linter.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func (e CSVError) Error() string {

// Validate tests whether or not a CSV lints according to RFC 4180.
// The lazyquotes option will attempt to parse lines that aren't quoted properly.
func Validate(reader io.Reader, delimiter rune, lazyquotes bool) ([]CSVError, bool, error) {
func Validate(reader io.Reader, delimiter rune, lazyquotes bool) ([]CSVError, bool, error, int) {
r := csv.NewReader(reader)
r.TrailingComma = true
r.FieldsPerRecord = -1
Expand All @@ -43,14 +43,14 @@ func Validate(reader io.Reader, delimiter rune, lazyquotes bool) ([]CSVError, bo
}
parsedErr, ok := err.(*csv.ParseError)
if !ok {
return errors, true, err
return errors, true, err, records
}
errors = append(errors, CSVError{
Record: nil,
Num: records,
err: parsedErr.Err,
})
return errors, true, nil
return errors, true, nil, records
}
if header == nil {
header = record
Expand All @@ -63,5 +63,5 @@ func Validate(reader io.Reader, delimiter rune, lazyquotes bool) ([]CSVError, bo
})
}
}
return errors, false, nil
return errors, false, nil, records
}
5 changes: 3 additions & 2 deletions linter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package csvlint

import (
"encoding/csv"
"github.com/stretchr/testify/assert"
"os"
"testing"

"github.com/stretchr/testify/assert"
)

var validationTable = []struct {
Expand Down Expand Up @@ -57,7 +58,7 @@ func TestTable(t *testing.T) {
if test.comma == 0 {
comma = ','
}
invalids, halted, err := Validate(f, comma, false)
invalids, halted, err, _ := Validate(f, comma, false)
assert.Equal(t, test.err, err)
assert.Equal(t, halted, test.halted)
assert.Equal(t, test.invalids, invalids)
Expand Down