Enforce SQL Formatting with pre-commit and GitHub Actions
SQL style drift rarely comes from one bad decision. It comes from a hundred small ones: one developer's editor inserts two spaces after SELECT , another aligns joins differently, and a third commits a query that was formatted by a tool nobody else has installed. The pull request then contains a mix of logic changes and whitespace churn, and reviewers spend their attention on spacing instead of…
Enforcing consistent SQL formatting is crucial for maintaining code quality and reducing reviewer fatigue. A single bad habit quickly propagates, resulting in a variety of formatting styles across the codebase. Each developer's editor settings, such as space insertion, join alignment, and formatting tools, contribute to this drift.
Pull requests often contain a mix of logical changes and whitespace alterations, causing reviewers to focus on formatting rather than correctness. Format-on-save settings are personal preferences, not team policies, leading to inconsistent formatting when multiple tools are used. To address this issue, a shared SQL formatting setup can be established using SQLFluff, pre-commit, and GitHub Actions.
This solution separates formatting failures from lint failures and ensures consistent formatting across the team.
Rewritten by urgent.news; may contain errors — check the original.
Source: dev.to