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) 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 ReadStringer ¶
ReadStringer is a simplified version of bufio.Reader.
type ReadWriteSeekerCloser ¶
type ReadWriteSeekerCloser interface { io.ReadWriteSeeker io.Closer }
ReadWriteSeekerCloser is a combination of io.ReadWriteSeeker and io.Closer.
type Readable ¶
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 ¶
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 ¶
CreateShadow creates a new shadow file for the given file.
func (*Reader) Load ¶
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) ReplaceWith ¶
ReplaceWith replaces the current file with the given file.