keywordcase

package module
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2026 License: MIT Imports: 6 Imported by: 0

README

yze-sql-keywordcase

A SQL analyzer in the yze suite that reports PostgreSQL keywords not written in lowercase (uppercase is the error), per the gomatic SQL standard. It tokenizes each .sql file 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 lowercase.

  • Rule: yze/keywordcase · Tool: yze · Category: sql (the yze-sql-* repo name carries the language group; the rule id stays flat).
  • Library: Diagnostics(path, source) and Report(read, files) emit go-yze Diagnostics (the stickler-json contract); a lexical scan error comes back wrapped in go-sql's ErrScan.
  • Bundled into yze: the yze aggregator imports this analyzer and runs it over the .sql files under its pattern roots, so yze (and stickler, which runs yze) lint SQL alongside Go. The standalone cmd/yze-sql-keywordcase <paths...> binary remains for direct use.

Because go-sql wraps full PostgreSQL, the recognized keyword set is complete (not a DDL subset).

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.

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, source string) ([]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.

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