lint

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2026 License: Apache-2.0 Imports: 33 Imported by: 0

Documentation

Overview

Package lint holds the rules that aicoded check applies to an app's code after go vet, and that the delivery pipeline will apply too, such as which packages and names app code may use and which files an app may hold. Run loads the app's packages without their tests, type-checks them, and reports every finding as a coded problem with its position and fix. Nothing in the app can turn a finding off: comments such as //nolint have no effect.

Rules returns every rule with its code and the sentences the docs show for it.

Index

Constants

View Source
const Framework = "aicoded.dev/framework"

Framework is the module path of the framework.

Variables

This section is empty.

Functions

func Banned

func Banned(path, name string) string

Banned returns the code of the rule that refuses, in a hand-written file of an app that declares no modules, the import of the package at path when name is "", or else the use of its member name: a function, variable, constant or type, or a method or field written Type.Name, which is refused also when its type is. It returns "" when no rule refuses it. Banned("os", "") is "E-LINT-001", Banned("database/sql", "Open") is "E-LINT-006", Banned("net/http", "Request") is "" and Banned("net/http", "Client.Do") is "E-LINT-009".

Banned answers for the packages of the standard library and the framework: a path whose first element has no dot names one of them, and any other path is E-LINT-002, a module that is not declared. Every answer holds in a generated file too, except E-LINT-005 and the import of a package that only generated files may import, which it may make. A change of a variable of the standard library or the framework is E-LINT-009 even where Banned allows its use.

func Blocks

func Blocks() []string

Blocks returns the import paths of the framework's packages that app code may import.

func Precheck

func Precheck(ctx context.Context, dir string) ([]*errs.Error, error)

Precheck reports, with E-LINT-011, what Run checks in the app in dir before it runs any other go command, since it decides which files and tools the go command uses: a GOFLAGS entry other than the few lint allows, in the environment or in what go env prints, and a vendor folder at the app root. aicoded check runs it before go build and go vet. Its error says that dir cannot be resolved.

Types

type Config

type Config struct {
	// Generated lists the files aicoded generate owns in the app, relative to its folder and
	// slash-separated. Every other file is checked as hand-written, whatever its name or header.
	// E-LINT-001, E-LINT-006, E-LINT-007 and E-LINT-009 read generated files too, and a generated
	// file may also import the packages only generated files may import; E-LINT-004 and
	// E-LINT-005 read hand-written files only. A problem in a generated file is reported where
	// its //line comment points, such as the line of the template that the code was written from,
	// when that comment names a file in the app folder, and at the generated file otherwise.
	Generated []string
	// Modules lists the module paths of the modules: section of the app's permission list.
	Modules []string
	// FrameworkDir is the framework checkout that the aicoded running lint was installed from,
	// or "" for a released aicoded. The app's go.mod may replace the framework with this folder,
	// and with nothing else: every other replace directive is E-LINT-011.
	FrameworkDir string
}

Config is what Run needs to know about the app besides its code.

type Result

type Result struct {
	// Problems are the findings, sorted by position. Each has a "file:line" position, relative
	// to the app folder and slash-separated; a file of a declared module is written
	// module@version/path, and a file outside the app folder by its absolute path. A GOFLAGS
	// finding has the position GOFLAGS, and a vendor folder with no vendor/modules.txt the
	// position vendor.
	Problems []*errs.Error
	// Writes are the tables that the app's constant SQL writes, with how, each once, sorted.
	Writes []Write
	// Stopped is true when what Precheck reports stopped Run before it loaded the app: Problems
	// then holds only those findings, and Writes is empty.
	Stopped bool
}

Result is what Run found.

func Run

func Run(ctx context.Context, dir string, cfg Config) (Result, error)

Run checks the app in dir. It loads every package of the app with cgo off, without tests, and applies every rule. Its error is E-CHK-007 when the go command is a newer Go than the one this program was built with; any other error says that a package could not be loaded or type-checked, or that ctx ended. What the rules find is in the Result.

type Rule

type Rule struct {
	Code  string // "E-LINT-001"
	Title string // the title of the rule's page, docs/errors/<Code>.md
	Dont  string // what app code must not do, in one sentence
	Do    string // what it does instead, in one sentence
	Fix   string // the one-line fix of every finding of the rule
}

Rule is one rule of lint, as the docs show it.

func Rules

func Rules() []Rule

Rules returns every rule, sorted by code.

type Write

type Write struct {
	Table string // as the SQL names it, without backquotes
	Op    string // INSERT, UPDATE, DELETE or REPLACE
}

Write is a table that SQL writes, and how.

Jump to

Keyboard shortcuts

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