Documentation ¶
Overview ¶
Package linter provides functions to check and fix files for trailing whitespaces and blank lines. It offers three main components:
- Manager, which wraps a file and provides a simple interface for opening, closing and reading lines.
- Replacer, which wraps two Manager instances and provides a simple interface for safely replacing a file with another. The intention is that the replacer is used by in-place formatters.
- Linter, which wraps a Manager and a list of checkers and provides a simple interface for linting and fixing
Index ¶
- Variables
- type Checker
- type Linter
- func (l *Linter) Fix(file Writeable) (err error)
- func (l *Linter) GetIssues() (rows [][]int, errs []error)
- func (l *Linter) HasCheckers() bool
- func (l *Linter) HasIssues() bool
- func (l *Linter) InsertChecker(c Checker)
- func (l *Linter) Lint(file Readable) (err error)
- func (l *Linter) Summary() (ok bool)
- type Main
- type ReadStringer
- type ReadWriteSeekerCloser
- type Readable
- type Reader
- func (f *Reader) Close() error
- func (f *Reader) HasLines() bool
- func (f *Reader) Load(filename ...string) error
- func (f *Reader) Next() (line string, err error)
- func (f *Reader) Open() (err error)
- func (f *Reader) Rename(name string) error
- func (f *Reader) ReplaceWith(replacement *Reader) (err error)
- func (f *Reader) Reset() error
- func (f *Reader) Save() error
- func (f *Reader) Write(lines ...string) error
- type Writeable
- type Writer
Constants ¶
This section is empty.
Variables ¶
var ErrNoCheckers = errors.New("no checkers configured")
ErrNoCheckers is returned when no checkers have been configured.
Functions ¶
This section is empty.
Types ¶
type Checker ¶
type Checker interface { Analyze(string, int) Finalize() Results() ([]int, error) Fix(string) string Stop() int }
Checker represents a line analyser.
type Linter ¶
type Linter struct { // Name contains the name of file to lint. Name string // Checkers contains the checkers to be used. Checkers []Checker // Error contains the error, if any. Error error // Touched is a flag whether the file has been touched. Touched bool }
Linter represents a file linter.
func (*Linter) Fix ¶ added in v0.1.0
Fix fixes the file by removing trailing whitespaces and blank lines.
func (*Linter) GetIssues ¶ added in v0.1.0
GetIssues returns a list of rows with issues and a list of errors.
func (*Linter) HasCheckers ¶
HasCheckers returns true if the linter has checkers configured.
func (*Linter) HasIssues ¶
HasIssues takes a list of errors and returns false if all errors are nil.
func (*Linter) InsertChecker ¶
InsertChecker adds a checker to the list of checkers in use.
type Main ¶ added in v0.1.0
type Main = *Reader
Main is an alias for Reader, to be used as a base for other types.
type ReadStringer ¶ added in v0.1.0
ReadStringer is a simplified version of bufio.Reader.
type ReadWriteSeekerCloser ¶ added in v0.1.0
type ReadWriteSeekerCloser interface { io.ReadWriteSeeker io.Closer }
ReadWriteSeekerCloser is a combination of io.ReadWriteSeeker and io.Closer.
type Readable ¶ added in v0.1.0
type Readable interface { Open() error Close() error HasLines() bool Next() (string, error) Load(...string) error }
Readable describes a file that can be read from.
type Reader ¶ added in v0.1.0
type Reader struct { // Name is the name of the file to open. Should be a full or relative path. Name string // contains filtered or unexported fields }
Reader represents a wrapped management of file handling. Given a name, it can open, close and read lines from the file, until EOF.
func CreateShadow ¶ added in v0.1.0
CreateShadow creates a new shadow file for the given file.
func (*Reader) Close ¶ added in v0.1.0
Close closes the file. Returns nil if the file is already closed.
func (*Reader) HasLines ¶ added in v0.1.0
HasLines returns true if there are lines available to read.
func (*Reader) Load ¶ added in v0.1.0
Load opens the file. It allows for reusing the same file manager for a new file. If no filename is provided, it equates to calling Open().
func (*Reader) Open ¶ added in v0.1.0
Open the file for reading. Returns an error if the file doesn't exist.
func (*Reader) ReplaceWith ¶ added in v0.1.0
ReplaceWith replaces the current file with the given file.
func (*Reader) Reset ¶ added in v0.1.0
Reset resets the file to the beginning and assigns a fresh reader.
type Writer ¶ added in v0.1.0
Writer enables formatting of a file, by first writing to a temporary file. When the formatting is done, the original file is replaced with the temporary file.