lint

package
v0.12.2 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package lint runs the checks of a project in one place: the checks of taply, with the ones that depend on a module run only when the module is enabled.

Index

Constants

View Source
const DefaultMaxLines = 1000

DefaultMaxLines is the file length limit of taply.

Variables

This section is empty.

Functions

func DownloadSquawk added in v0.5.8

func DownloadSquawk(ctx context.Context) (string, error)

DownloadSquawk returns the pinned squawk binary, downloading it into the user cache on first use and refusing a file whose digest does not match.

func ExecCommand added in v0.5.8

func ExecCommand(ctx context.Context, dir, name string, args ...string) ([]byte, error)

ExecCommand is Exec for real commands.

func Files

func Files(dir string, maxLines int) error

Files fails when a hand written Go file is longer than maxLines: a file that long is several files that have not been split yet. Generated files are exempt.

func Format

func Format(dir string) error

Format fails when a Go file of the project is not gofmt formatted.

func Names

func Names() []string

Names lists every check name, for flag help.

func Run

func Run(ctx context.Context, dir string, checks []Check, out io.Writer) error

Run runs the checks, reports each one and returns an error when any failed. All checks run even after a failure, so one run shows everything that needs fixing.

Types

type Check

type Check struct {
	Name string
	Run  func(ctx context.Context, dir string) error
}

Check is one named check.

func Checks

func Checks(opts Options, run Runner, verify func(ctx context.Context, dir string) error) []Check

Checks returns the checks for a project in the order they run: cheap ones first, so a formatting slip fails in a second rather than after the vulnerability scan.

type Exec added in v0.5.8

type Exec func(ctx context.Context, dir, name string, args ...string) ([]byte, error)

Exec runs a command and returns its combined output. Tests replace it.

type Migrations added in v0.5.8

type Migrations struct {
	Dir     string                                    // migrations folder in the project; codegen.MigrationsDir when empty
	Against string                                    // base branch; empty lints the files not committed yet
	Exec    Exec                                      // runs git and squawk
	Squawk  func(ctx context.Context) (string, error) // path to the squawk binary; DownloadSquawk when nil
}

Migrations lints the goose migrations a branch adds. Migrations already applied are history: the databases lived through them, and a rule added later must not turn every old file red.

func (Migrations) Run added in v0.5.8

func (m Migrations) Run(ctx context.Context, dir string) error

Run lints every migration the branch adds and returns all findings at once.

type Options

type Options struct {
	Skip     []string          // names of checks to skip
	MaxLines int               // file length limit; DefaultMaxLines when zero
	Against  string            // base branch: proto breaking changes are checked against it and migrations it lacks are linted
	Modules  []string          // enabled modules
	API      codegen.APILayout // where the proto files are; zero means the defaults
	Exec     Exec              // runs git and squawk for the migrations check
}

Options select what runs.

type Runner

type Runner func(ctx context.Context, dir string, out io.Writer, env []string, name string, args ...string) error

Runner runs a command in the project. Tests replace it.

Jump to

Keyboard shortcuts

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