naming

package
v1.14.0 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package naming provides linter rules for SQL naming conventions and style.

Rules:

  • L024: Table alias required (multi-table queries)
  • L025: Reserved keyword used as identifier
  • L026: Implicit column list in INSERT
  • L027: UNION instead of UNION ALL
  • L028: Missing ORDER BY with LIMIT
  • L029: Subquery in WHERE can be a JOIN
  • L030: DISTINCT on many columns

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DistinctOnManyColumnsRule

type DistinctOnManyColumnsRule struct{ linter.BaseRule }

DistinctOnManyColumnsRule (L030) warns when DISTINCT is used with many columns. DISTINCT on many columns is often a sign of a missing GROUP BY or denormalized data. It also forces a sort over all projected columns, which is expensive.

func NewDistinctOnManyColumnsRule

func NewDistinctOnManyColumnsRule() *DistinctOnManyColumnsRule

NewDistinctOnManyColumnsRule creates a new L030 rule instance.

func (*DistinctOnManyColumnsRule) Check

Check inspects SELECT statements for DISTINCT with many columns.

func (*DistinctOnManyColumnsRule) Fix

func (r *DistinctOnManyColumnsRule) Fix(content string, violations []linter.Violation) (string, error)

Fix is a no-op: replacing DISTINCT with GROUP BY requires semantic understanding.

type ImplicitColumnListRule

type ImplicitColumnListRule struct{ linter.BaseRule }

ImplicitColumnListRule (L026) flags INSERT statements without an explicit column list. INSERT INTO table VALUES (...) is fragile — it breaks when columns are added/reordered.

func NewImplicitColumnListRule

func NewImplicitColumnListRule() *ImplicitColumnListRule

NewImplicitColumnListRule creates a new L026 rule instance.

func (*ImplicitColumnListRule) Check

Check inspects INSERT statements for missing column lists.

func (*ImplicitColumnListRule) Fix

func (r *ImplicitColumnListRule) Fix(content string, violations []linter.Violation) (string, error)

Fix is a no-op: adding column list requires schema knowledge.

type MissingOrderByLimitRule

type MissingOrderByLimitRule struct{ linter.BaseRule }

MissingOrderByLimitRule (L028) flags queries that use LIMIT/OFFSET without ORDER BY. Without ORDER BY, the rows returned by LIMIT are non-deterministic — different executions may return different rows, making pagination unreliable.

func NewMissingOrderByLimitRule

func NewMissingOrderByLimitRule() *MissingOrderByLimitRule

NewMissingOrderByLimitRule creates a new L028 rule instance.

func (*MissingOrderByLimitRule) Check

Check inspects SELECT statements for LIMIT/OFFSET without ORDER BY.

func (*MissingOrderByLimitRule) Fix

func (r *MissingOrderByLimitRule) Fix(content string, violations []linter.Violation) (string, error)

Fix is a no-op: choosing the right ORDER BY requires business logic.

type ReservedKeywordIdentifierRule

type ReservedKeywordIdentifierRule struct{ linter.BaseRule }

ReservedKeywordIdentifierRule (L025) flags table names or aliases that match SQL reserved keywords (without quoting). Using reserved words as identifiers requires quoting and is confusing for both humans and some SQL parsers.

func NewReservedKeywordIdentifierRule

func NewReservedKeywordIdentifierRule() *ReservedKeywordIdentifierRule

NewReservedKeywordIdentifierRule creates a new L025 rule instance.

func (*ReservedKeywordIdentifierRule) Check

Check inspects table names, aliases, and column names for reserved keyword conflicts.

func (*ReservedKeywordIdentifierRule) Fix

func (r *ReservedKeywordIdentifierRule) Fix(content string, violations []linter.Violation) (string, error)

Fix is a no-op: renaming identifiers requires schema changes.

type SubqueryCanBeJoinRule

type SubqueryCanBeJoinRule struct{ linter.BaseRule }

SubqueryCanBeJoinRule (L029) flags correlated EXISTS/IN subqueries in WHERE clauses that could be expressed more efficiently as a JOIN. EXISTS (SELECT ...) and IN (SELECT ...) can often be replaced with a JOIN or LEFT JOIN ... IS NULL for better performance and readability.

func NewSubqueryCanBeJoinRule

func NewSubqueryCanBeJoinRule() *SubqueryCanBeJoinRule

NewSubqueryCanBeJoinRule creates a new L029 rule instance.

func (*SubqueryCanBeJoinRule) Check

Check walks the AST looking for EXISTS/IN subqueries in WHERE clauses.

func (*SubqueryCanBeJoinRule) Fix

func (r *SubqueryCanBeJoinRule) Fix(content string, violations []linter.Violation) (string, error)

Fix is a no-op: rewriting subqueries as JOINs requires semantic understanding.

type TableAliasRequiredRule

type TableAliasRequiredRule struct{ linter.BaseRule }

TableAliasRequiredRule (L024) flags multi-table queries where any table has no alias. Unaliased tables in multi-table queries make column references ambiguous and harder to read.

func NewTableAliasRequiredRule

func NewTableAliasRequiredRule() *TableAliasRequiredRule

NewTableAliasRequiredRule creates a new L024 rule instance.

func (*TableAliasRequiredRule) Check

Check inspects SELECT statements with multiple tables for missing aliases.

func (*TableAliasRequiredRule) Fix

func (r *TableAliasRequiredRule) Fix(content string, violations []linter.Violation) (string, error)

Fix is a no-op: alias naming is a style decision.

type UnionAllPreferredRule

type UnionAllPreferredRule struct{ linter.BaseRule }

UnionAllPreferredRule (L027) flags UNION (deduplicating) when the caller likely meant UNION ALL. UNION performs a sort+dedup pass which is significantly more expensive than UNION ALL. If duplicates are intentionally removed, this is fine, but it should be an explicit choice.

func NewUnionAllPreferredRule

func NewUnionAllPreferredRule() *UnionAllPreferredRule

NewUnionAllPreferredRule creates a new L027 rule instance.

func (*UnionAllPreferredRule) Check

Check walks the AST looking for UNION without ALL.

func (*UnionAllPreferredRule) Fix

func (r *UnionAllPreferredRule) Fix(content string, violations []linter.Violation) (string, error)

Fix is a no-op: changing UNION to UNION ALL changes query semantics.

Jump to

Keyboard shortcuts

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