Configs2026年5月17日·1 分钟阅读

SQLFluff — Modular SQL Linter and Auto-Formatter

A configurable SQL linter and formatter supporting over 20 SQL dialects, designed to enforce style rules and catch errors in data pipelines.

Agent 就绪

这个资产可以被 Agent 直接读取和安装

TokRepo 同时提供通用 CLI 命令、安装契约、metadata JSON、按适配器生成的安装计划和原始内容链接,方便 Agent 判断适配度、风险和下一步动作。

Native · 98/100策略:允许
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Single
信任
信任等级:Established
入口
SQLFluff Overview
通用 CLI 安装命令
npx tokrepo install ae7d585b-51a7-11f1-9bc6-00163e2b0d79

Introduction

SQLFluff is an open-source SQL linter that brings the same code-quality discipline to SQL that ESLint brings to JavaScript. It parses, analyzes, and auto-fixes SQL files across many dialects, helping data teams enforce consistent formatting in version-controlled analytics repos.

What SQLFluff Does

  • Lints SQL files against configurable rules for style and correctness
  • Auto-fixes violations with a single command
  • Supports 20+ dialects including PostgreSQL, BigQuery, Snowflake, Redshift, and SparkSQL
  • Integrates with CI pipelines, pre-commit hooks, and dbt projects
  • Provides a templating layer to handle Jinja and dbt macros

Architecture Overview

SQLFluff parses SQL into an abstract syntax tree using dialect-specific grammars. Each rule inspects tree nodes and emits lint violations with optional fix patches. The fix engine applies non-conflicting patches in a single pass; conflicting fixes require multiple passes. A plugin system allows third-party rules.

Self-Hosting & Configuration

  • Install via pip: pip install sqlfluff
  • Configure with .sqlfluff file in your project root
  • Set dialect: [sqlfluff] dialect = bigquery
  • Exclude rules: [sqlfluff:rules] exclude_rules = L011,L031
  • Integrate with pre-commit by adding the sqlfluff hook entry

Key Features

  • Over 60 built-in lint rules covering indentation, aliasing, joins, and naming
  • Dialect-aware parsing handles syntax differences correctly
  • Jinja and dbt templating support for analytics SQL
  • Configurable via TOML or INI-style config files
  • Plugin architecture for custom rules

Comparison with Similar Tools

  • sqlfmt — opinionated formatter with fewer configuration options
  • pg_format — PostgreSQL-only, no lint rules
  • sql-formatter — JavaScript library focused on pretty-printing, no linting
  • dbt SQLFluff plugin — extends SQLFluff with dbt-aware templating
  • SonarQube SQL — enterprise tool with broader scope but commercial licensing

FAQ

Q: Does SQLFluff work with dbt projects? A: Yes. It has built-in dbt templating support and can parse Jinja macros before linting.

Q: Can I use SQLFluff in CI? A: Yes. Run sqlfluff lint --format github-annotation for inline PR comments in GitHub Actions.

Q: How do I ignore a specific violation? A: Add -- noqa: L042 as an inline comment on the offending line.

Q: Does it support BigQuery and Snowflake? A: Yes, both are first-class supported dialects with dedicated grammar files.

Sources

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产