← 返回 CLI 目录
SQLFluff
$ sqlfluff 社区开源 低风险 SQLFluff · 代码托管与研发协同 · MIT · macos / linux / windows
模块化 SQL 检查与格式化 CLI,支持超过 25 种方言(含 Postgres、BigQuery、Snowflake、DuckDB)及 Jinja/dbt 模板。提供 sqlfluff lint --format json 结构化诊断与 sqlfluff fix --force 非交互修复。
FCRS-1.0 综合评分
85 /100
良好 (Good)
中置信度 (源码/文档)
零摩擦安装命令
brew install sqlfluff CLI vs MCP 选型建议 仅 CLI 可用
在本地离线解析并格式化 .sql 与 dbt 模型,直接运行 CLI 稳定且确定。
Agent 友好度体检单
✓ 原生 JSON 输出
— 字段裁剪
✓ 无头非交互
— 支持 Dry-Run
✓ 只读模式开关
✓ 支持 NO_COLOR
✓ 自省/Schema 发现
— 官方 SKILL.md
当前为静态评估(本机尚未安装或尚未运行探针)。可在本地运行 npm run data:probe 并提交 data/probes/ 升级为实测证据。
FCRS-1.0 六维评分拆解
Agent 友好度 21 / 25
支持 lint --format json、--nocolor、--nofail 与 --dialect,但 sqlfluff fix 默认会交互询问确认,需传 --force。
sqlfluff lint --format jsonoutputs structured violation arrayssqlfluff fixprompts[Y/n]when unfixable violations exist unless--forceis supplied
安全与权限边界 21 / 25
仅操作本地文件;lint 严格只读,fix 默认带确认保护(传入 --force 除外)。
- Read-only
lintsubcommand and explicitfixsubcommand
安装与运行摩擦 12 / 15
可通过 Homebrew、PyPI 与 uvx 安装,但 dbt 项目需额外安装 sqlfluff-templater-dbt 及对应适配器。
- Easy
brew/pip/uvxinstall; dbt projects need extra templater packages
能力覆盖与边际价值 14 / 15
在现代数据栈中具备无可替代的 SQL 方言覆盖率与 Jinja/dbt 模板感知能力。
- Supports 25+ SQL dialects plus Jinja/dbt templates
维护与来源背书 8 / 10
活跃维护的社区标准工具(sqlfluff/sqlfluff),采用 MIT 协议。
- Active
sqlfluff/sqlfluffrepository
文档与可验证性 9 / 10
docs.sqlfluff.com 提供完备的规则目录、CLI 参考与各方言文档。
- Official docs at docs.sqlfluff.com
安全边界、鉴权与放权指南
鉴权方式
无需鉴权
凭证存储位置
离线本地 SQL 解析与检查器,不存储凭证(除非可选的 dbt 适配器读取本地 profile)。
潜在副作用
只读查询 本地写入
费用与配额提示
MIT 开源 Python 包,完全免费。
可复制到 CLAUDE.md / AGENTS.md 的安全护栏
# SQLFluff (sqlfluff) Agent Rules - Always run `sqlfluff lint --format json --nocolor` first; pass `--dialect` if `.sqlfluff` is absent. - Pass `--force` (`-f`) on `sqlfluff fix` so it does not hang waiting on an interactive `[Y/n]` prompt.
Agent 高频安全命令配方
只读查询(安全推荐)
以 JSON 输出检查 SQL 文件
sqlfluff lint --dialect postgres --format json --nocolor models/
按 SQL 文件输出 JSON 违规数组,不修改磁盘文件。
受控写入与预演
非交互式自动修复 SQL 格式
sqlfluff fix --dialect postgres --force models/orders.sql
通过 --force 跳过交互确认,原地应用 SQLFluff 格式修复。
核心优势
- + 原生
lint --format json --nocolor返回精确的行号、列号与规则编号。 - + 原生支持 25+ SQL 方言及 Jinja/dbt 模板语法。
注意事项与踩坑点
- !
sqlfluff fix若未传--force可能弹出[Y/n]交互提示导致无头 Agent 卡住。 - ! 仓库缺少
.sqlfluff配置时必须显式指定--dialect。
已验证兼容的 Agent 宿主
Claude Code Codex CLI Gemini CLI