You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

SQLFluff跳过宏文件Linting:如何同时检查dbt模型与宏

解决SQLFluff同时检查dbt模型与宏文件的问题

核心配置调整

问题根源是SQLFluff的dbt模板默认会跳过宏文件,只需修改项目根目录的.sqlfluff配置开启宏检查:

  1. 新增或修改[dbt]区块,开启宏文件检查:
[dbt]
dbt_include_macros = true
  1. 确保[core]区块包含模型和宏目录的路径,同时指定使用dbt模板:
[core]
include_paths = ["models", "macros"]
template = dbt
# 保留你原有的其他核心配置

验证pre-commit钩子配置

检查.pre-commit-config.yaml中的SQLFluff钩子,确保它加载正确配置并覆盖目标文件:

repos:
  - repo: https://github.com/sqlfluff/sqlfluff
    rev: <你的SQLFluff版本号>  # 例如3.2.0
    hooks:
      - id: sqlfluff-lint
        args: ["--config", ".sqlfluff", "models/", "macros/"]
        files: \.sql$

测试效果

执行以下命令验证配置生效:

pre-commit run --all-files

此时模型文件和宏文件都会被SQLFluff检查,不再出现宏文件被跳过的警告。

内容的提问来源于stack exchange,提问作者Masoud

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.13 02:55:00