sqlint

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package sqlint checks the authored SQL files of a module against the conventions the loader cannot, or should not, enforce at runtime:

  • every statement directory compiles against the pattern sources the runtime registers (the header grammar, the parameter syntax, the field contract, includes resolving)
  • every pattern directory validates as a catalog source
  • a file is named for its operation and not its SQL verb
  • the parameter delimiter does not appear inside a comment or a string literal
  • a standard-tier file uses no native form the configured engine declares
  • a statement that includes one of the guard protocol's patterns includes both: guard_set beside guard_where in a SET statement, and guard_where beside guard_set
  • a migration headed "transaction: none" contains exactly one statement

It is a sub-module of sqlate so the TOML parser it sources enters a build only through this import; cmd/sqlint is its command, and a harness calls the package.

Configuration

sqlint.toml at the module root configures the linter, one file per module, read by Load:

  • a table per role (statements, patterns, migrations) with the directory globs it covers and the switches of its checks
  • an override table per directory set that needs an exception
  • the pattern sources by namespace
  • the engine

A source or the engine is a path: a directory of the tree, or a module path resolved through the Resolver to the version go.mod pins. A producer, a module or a directory that contains its own sqlint.toml, declares in its [export] table what a consumer reads: the directory its patterns publish, the overlay directory an engine supplies, and the native forms an engine names, each a regular expression under the name a finding reports. A bare directory is the pattern files themselves, the module's own. Absent the file, the roles are the conventions as they stand, every check on, and no source is registered.

Running

Lint walks a filesystem under a Config and returns every Finding: the file, the line when the check has one, and the message. Errors in the configuration's own syntax are Load's; a source or engine that does not resolve is a finding against sqlint.toml.

Index

Constants

View Source
const File = "sqlint.toml"

File is the configuration file's name, at the module root and in each producer.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Engine is the path of the engine whose export declares the native
	// forms; empty means the native-forms check has no list.
	Engine string
	// Sources maps a namespace to the source registered under it.
	Sources map[string]Source
	// Roles maps each role's name to the role.
	Roles map[string]*Role
	// Export is what this module declares to a consumer.
	Export Export
}

Config is the parsed configuration.

func Load

func Load(fsys fs.FS) (*Config, error)

Load reads File at the root of fsys; a missing file is the defaults. Every configuration error is reported, joined, and each line begins with the file's name; the configuration returned beside them contains what parsed.

type Export

type Export struct {
	Patterns    string            `toml:"patterns"`
	Overlay     string            `toml:"overlay"`
	NativeForms map[string]string `toml:"native_forms"`
}

Export is a producer's declaration: the directory its namespace publishes, the overlay directory an engine supplies, and the native forms an engine names, each a regular expression under the name the finding reports, so the engine states in what position a spelling counts, word boundaries and case, and not only which spelling.

type Finding

type Finding struct {
	Path    string
	Line    int
	Message string
}

Finding is one convention a file fails: its path, the 1-based line when the check has one (0 otherwise), and the message.

func Lint

func Lint(fsys fs.FS, cfg *Config, resolve Resolver) []Finding

Lint walks fsys under cfg and returns every finding, in walk order. A nil cfg is the defaults. resolve turns a module path into its root filesystem; nil refuses every module path. A source or engine that does not resolve is a finding against File; the rest of the tree is linted with what did.

func (Finding) String

func (f Finding) String() string

String renders the finding as path:line: message, or path: message when the check has no line.

type Resolver

type Resolver func(module string) (fs.FS, error)

Resolver turns a module path into the filesystem of the module's root directory, where its sqlint.toml is read. A nil Resolver refuses every module path.

func GoList

func GoList(root string) Resolver

GoList resolves a module path through go list -m in the module at root, to the directory of the version its go.mod pins, a workspace or replace directive included, so a source's files are the ones the runtime embeds.

type Role

type Role struct {
	Dirs      []string
	Checks    map[string]bool
	Overrides map[string]map[string]bool
}

Role is one role's directory globs and switches, with any per-glob overrides.

type Source

type Source struct {
	Path    string `toml:"path"`
	Overlay string `toml:"overlay"`
}

Source is one registered pattern namespace: a path, and for the library an optional engine overlay respelling its patterns.

Directories

Path Synopsis
cmd
sqlint command
Command sqlint runs the sqlint package over a module: it reads sqlint.toml at the root given as its one argument (the working directory by default), resolves module paths through go list in that module, walks the tree, and prints every finding as file:line: message, sorted.
Command sqlint runs the sqlint package over a module: it reads sqlint.toml at the root given as its one argument (the working directory by default), resolves module paths through go list in that module, walks the tree, and prints every finding as file:line: message, sorted.

Jump to

Keyboard shortcuts

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