linter

package
v1.0.14 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: MIT Imports: 8 Imported by: 0

README

Linter

This package is for implementations of the Linter type in Crie, though the cli package is probably all that is needed there's no reason you can't directly call a library or service that isn't run as a command

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

func Result added in v1.0.0

func Result(err error) error

Result conditionally wraps an error with a FailedResultError or otherwise passes through nil, it should be used when a linter didn't error but returned a failed result

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

type Reporter interface {
	Log(rep *Report) error
}

Reporter is used to report results to the user

func NewGitHubReporter added in v1.0.12

func NewGitHubReporter(next Reporter, out io.Writer, dir string) Reporter

NewGitHubReporter annotates findings on out before reporting them with next

func NewStandardReporter added in v1.0.6

func NewStandardReporter(showPass bool) Reporter

NewStandardReporter creates a new StandardReporter

func NewStructuredReporter added in v1.0.6

func NewStructuredReporter(showPass bool) Reporter

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

Jump to

Keyboard shortcuts

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