keywordcase

package module
v0.4.5 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2026 License: MIT Imports: 7 Imported by: 0

README

Documentation

Overview

Package keywordcase reports PostgreSQL keywords that are not written in lowercase, per the gomatic SQL standard (keywords are lowercase; uppercase and title-case are the error). It tokenizes SQL with the shared gomatic/go-sql library — a thin wrapper over libpg_query, PostgreSQL's own lexer — and flags any keyword token whose text is not already its lowercase form. Quoted identifiers and keyword text inside string literals are not keyword tokens, so they are never flagged.

The scanner classifies keywords by table lookup, context-free, so an unquoted identifier that spells an unreserved or column-name keyword (a column named Version, say) scans as a keyword token. The parse tree disambiguates: tokens it proves to be identifiers are never flagged, and when a source does not parse as SQL at all only the reserved and type/function-name keyword classes — which can never be bare identifiers — are flagged.

Dollar-quoted string bodies ($$…$$), the fleet-standard form for function and DO bodies, are scanned recursively so the SQL inside them is held to the same standard; a body that is not lexable SQL (a PL/Python body, say) is skipped silently, and recursion stops after [nestingLimit] levels of dollar quoting.

Index

Constants

View Source
const Category = "sql"

Category is the language group this analyzer belongs to, used by the yze suite to run it only when processing SQL.

View Source
const ErrReadFile errs.Const = "cannot read SQL file"

ErrReadFile reports that a SQL source file could not be read.

View Source
const Name = "keywordcase"

Name is the analyzer's stable identifier — the suffix of its flat rule id and the key the yze suite catalogs it under.

View Source
const Rule = Tool + "/" + Name

Rule is the stable, flat rule id every diagnostic carries: "yze/" + Name.

View Source
const Tool = "yze"

Tool is the suite name stamped on every diagnostic. The analyzer is bundled into the yze suite (the language group lives in the repo path and Category, not the rule id), so it reports as "yze", not a separate "yze-sql" tool.

Variables

This section is empty.

Functions

func Diagnostics

func Diagnostics(path Path, source sql.SQL) ([]goyze.Diagnostic, error)

Diagnostics reports every keyword token in source whose text is not its canonical lowercase spelling. A lexical error scanning source is returned (wrapped in sql.ErrScan) so the caller can surface it as a tool failure rather than a clean pass. path is stamped on each diagnostic's location. Positions are computed in a single forward pass over source, so a file of any size costs O(n).

func Report

func Report(read FileReader, files []string) (goyze.Report, error)

Report runs the keyword-case check over each file and aggregates the diagnostics into the lean stickler-json report. A read failure aborts with ErrReadFile; a lexical scan failure aborts with the wrapped sql.ErrScan.

Types

type FileReader

type FileReader func(path string) ([]byte, error)

FileReader reads a file's bytes; injected so aggregation is testable without the filesystem.

type Path added in v0.3.4

type Path string

Path is the file path stamped on each diagnostic's location.

Directories

Path Synopsis
cmd
yze-sql-keywordcase command
Command yze-sql-keywordcase reports PostgreSQL keywords that are not written in lowercase in the given .sql files and directories, emitting the lean stickler-json report the stickler runner consumes.
Command yze-sql-keywordcase reports PostgreSQL keywords that are not written in lowercase in the given .sql files and directories, emitting the lean stickler-json report the stickler runner consumes.

Jump to

Keyboard shortcuts

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