csvlint

package module
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 15, 2021 License: Apache-2.0 Imports: 3 Imported by: 2

README

csvlint

csvlint is a library and command-line utility for linting CSV files according to RFC 4180.

It assumes that your CSV file has an initial header row.

Everything in this README file refers to the command-line utility. For information about the library, see godoc.

Installing

Standalone executables for multiple platforms are available via Github Releases.

You can also compile from source:

go get github.com/Clever/csvlint/cmd/csvlint

Usage

csvlint [options] /path/to/csv/file

Options

NOTE: The default settings validate that a CSV conforms to RFC 4180. By changing the settings, you can no longer strictly guarantee a CSV conforms to RFC 4180.

  • delimiter: the field delimiter, can be any single unicode character
    • default: "," (comma)
    • valid options: "\t", "|", "ஃ", etc
    • if you want multi-character delimiters, you're probably doing CSVs wrong
  • lazyquotes: allow a quote to appear in an unquoted field and a non-doubled quote to appear in a quoted field. WARNING: your file may pass linting, but not parse in the way you would expect
Examples
$ csvlint bad_quote.csv
Record #1 has error: bare " in non-quoted-field

unable to parse any further

$ csvlint --lazyquotes bad_quote.csv
file is valid

$ csvlint mult_long_columns.csv
Record #2 has error: wrong number of fields in line
Record #4 has error: wrong number of fields in line

$ csvlint --delimiter='\t' mult_long_columns_tabs.csv
Record #2 has error: wrong number of fields in line
Record #4 has error: wrong number of fields in line

$ csvlint one_long_column.csv
Record #2 has error: wrong number of fields in line

$ csvlint perfect.csv
file is valid
Exit codes

csvlint uses three different exit codes to mean different things:

  • 0 - the file is valid
  • 1 - couldn't parse the entire file
  • 2 - could parse the file, but there were lint failures

Vendoring

Please view the dev-handbook for instructions.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CSVError

type CSVError struct {
	// Record is the invalid record. This will be nil when we were unable to parse a record.
	Record []string
	// Num is the record number of this record.
	Num int
	// contains filtered or unexported fields
}

CSVError returns information about an invalid record in a CSV file

func Validate

func Validate(reader io.Reader, delimiter rune, lazyquotes bool) ([]CSVError, bool, error)

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 (CSVError) Error

func (e CSVError) Error() string

Error implements the error interface

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL