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, a returning command's read)
- 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 ¶
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.
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 ¶
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 ¶
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.
type Resolver ¶
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.
Source Files
¶
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. |