Documentation
¶
Overview ¶
Package linter provides a simple interface for linting, allowing for custom implementations
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type BatchLinter ¶ added in v1.0.12
type BatchLinter interface {
Linter
Batched() bool
RunBatch(ctx context.Context, filePaths []string) (reports []Report, rerun map[string][]Finding)
}
BatchLinter is optionally implemented by a Linter that can lint many files in a single run. When Batched is true RunBatch is used instead of Run. It returns a Report for each file it could decide, and the files it couldn't (e.g. the batch failed but a file's own result is unknown) to be given their own Run, each with the findings the batch had for it to carry over to that Run's Report.
type FailedResultError ¶ added in v1.0.0
type FailedResultError struct {
// contains filtered or unexported fields
}
FailedResultError means a linter didn't error but returned a failed result
func (*FailedResultError) Error ¶ added in v1.0.0
func (e *FailedResultError) Error() string
Error implements the error interface
type Finding ¶ added in v1.0.12
type Finding struct {
Tool string
File string
Line int // 0 when the tool didn't give one
Col int // 0 when the tool didn't give one
Message string
}
Finding is a problem a tool reported at a position in a file, as read from output led by the file's path
type GitHubReporter ¶ added in v1.0.12
type GitHubReporter struct {
Reporter
Out io.Writer
// Dir is prefixed to finding paths to make them relative to the repository root, when crie runs in a subdirectory
Dir string
}
GitHubReporter writes each report's findings as GitHub Actions workflow commands, which annotate the lines they're about on a pull request, then passes the report on to the Reporter it wraps
func (*GitHubReporter) Log ¶ added in v1.0.12
func (r *GitHubReporter) Log(rep *Report) error
Log writes a workflow command for each finding with a line, as an error if the report failed or else a warning. A failed file without any is still annotated, on the file as a whole.
type Linter ¶
type Linter interface {
Name() string
Setup(ctx context.Context) error
Cleanup(ctx context.Context) error
Run(ctx context.Context, filePath string) Report
}
Linter is a simple interface to enable a setup and check using WillRun before executing multiple Run's it is expected that Setup and Cleanup will be called exactly once given a context. Run may be called concurrently, its context is per file and carries the trace span for that run.
type Report ¶
type Report struct {
Target string
File string // the file the report is about, when it's about one
Err error
StdOut io.Reader
StdErr io.Reader
Findings []Finding
}
Report is used to state what issues a given file has
type Reporter ¶ added in v1.0.6
Reporter is used to report results to the user
func NewGitHubReporter ¶ added in v1.0.12
NewGitHubReporter annotates findings on out before reporting them with next
func NewStandardReporter ¶ added in v1.0.6
NewStandardReporter creates a new StandardReporter
func NewStructuredReporter ¶ added in v1.0.6
NewStructuredReporter creates a new StructuredReporter
type StandardReporter ¶ added in v1.0.6
type StandardReporter struct {
ShowPass bool
SrcOut logFormat
SrcErr logFormat
SrcInt logFormat
fold.Folder
}
StandardReporter is a Reporter that uses simple logging
func (*StandardReporter) Log ¶ added in v1.0.6
func (r *StandardReporter) Log(rep *Report) error
Log simple takes all fields and pushes them to our using the default logFormat
type StructuredReporter ¶ added in v1.0.6
type StructuredReporter struct {
ShowPass bool
SrcOut *log.Logger
SrcErr *log.Logger
SrcInt *log.Logger
}
StructuredReporter is a Reporter that uses structured logging
func (*StructuredReporter) Log ¶ added in v1.0.6
func (r *StructuredReporter) Log(rep *Report) error
Log simple takes all fields and pushes them to our using the default logFormat