Skip to content

STYLE003: Detect inconsistent SQL keyword case #19

Open

Description

@RAprogramm

Summary

Add a rule to detect inconsistent casing of SQL keywords within a single query (e.g., mixing SELECT with from or Where).

Why This Matters

Consistent keyword casing is a code quality issue:

  • Readability — mixed case is visually jarring and harder to scan
  • Team standards — inconsistency suggests lack of formatting discipline
  • Professional appearance — code reviews flag this immediately
  • Maintenance — consistent style makes patterns easier to recognize

The Professional Standard

Most SQL style guides recommend one of:

  1. UPPERCASE keywords (most common in enterprise)

    SELECT id, name FROM users WHERE status = 'active' ORDER BY name;
  2. lowercase keywords (common in modern tooling)

    select id, name from users where status = 'active' order by name;

Both are valid — but mixing them is not:

-- This is ugly and unprofessional:
SELECT id, name from Users WHERE status = 'active' Order By name;

Rule Specification

Property Value
Rule ID STYLE003
Name Inconsistent keyword case
Category Style
Severity Info
Default Enabled

Detection Patterns

-- Should trigger (mixed case)
SELECT id FROM users where status = 'active';
select * From orders WHERE id = 1;
SELECT name, Select email FROM users;  -- even worse

-- Should NOT trigger (consistent)
SELECT * FROM users WHERE id = 1;
select * from users where id = 1;

Keywords to Check

Primary: SELECT, FROM, WHERE, JOIN, LEFT, RIGHT, INNER, OUTER, ON, AND, OR, NOT, IN, ORDER, BY, GROUP, HAVING, LIMIT, OFFSET, INSERT, INTO, VALUES, UPDATE, SET, DELETE, CREATE, ALTER, DROP, TABLE, INDEX, AS, DISTINCT, UNION, ALL, BETWEEN, LIKE, IS, NULL, EXISTS, CASE, WHEN, THEN, ELSE, END

Suggested Message

"Inconsistent SQL keyword casing: found both 'SELECT' and 'from'. Use consistent case for all keywords (either UPPERCASE or lowercase) for better readability."

References

Implementation Notes

  • Extract all SQL keywords from query
  • Check if all are uppercase, all lowercase, or mixed
  • Consider: PascalCase identifiers (table/column names) are fine
  • Mixed case = trigger rule
  • Don't flag: quoted identifiers, string literals
  • Configurable: preferred style (UPPER vs lower) as optional enforcement

Activity

  1. RAprogramm commented on Jul 14, 2026

    @RAprogramm
    OwnerAuthor

    Blocked on architecture: rules receive statements re-serialized from the sqlparser AST (verified: 'select id From users' reaches rules as 'SELECT id FROM users'), so the original keyword case is already normalized away. Implementing STYLE003 requires threading the pre-parse source text (or statement spans) into Query, which is a breaking change to the public Query struct. Deferring until a major/minor API revision carries that field.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions