feat: dbt-aware rule pack scaffolding + DBT001 model-without-test#57
Merged
Conversation
[pre-commit.ci] auto-applied fixes from configured hooks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed
First slice of the [dbt-aware rule pack ADR]: scaffolding + the simplest of the seven proposed rules (DBT001
model-without-test). The remaining six rules and the Jinja preprocessor are intentionally deferred to follow-up PRs.New modules:
sql_guard/dbt.py— project discovery (find_dbt_project,load_dbt_project,DbtProject,DbtModelEntry). Walks up from a path to finddbt_project.yml, parsesmodel-paths, and reads everyschema.ymlunder those paths. Supports bothtests:(dbt ≤1.4) anddata_tests:(dbt ≥1.5) spellings. Tolerates malformedschema.ymlwithout crashing the lint run.sql_guard/rules/dbt.py—ModelWithoutTestrule class.Rule API change:
Rule.check_file(file) -> list[Finding]extension point on the base class. Default returns[]so line- and statement-rules pay nothing. File-level rules (e.g. DBT001) override it. Checker runscheck_fileafter the existing line and statement passes.Wiring:
build_dbt_rules(project)registry helper mirrorsbuild_contract_rules(contract).get_rules(..., dbt_project=...)accepts the project and appends DBT rules when set.--dbtCLI flag, auto-discoversdbt_project.ymlfrom the first checked path. Silent without the flag. Surfaces a yellow warning when--dbtis supplied but no project is found.Related issue
[ADR] dbt-aware rule pack — implementation of DBT001 only; remaining rules are explicitly out of scope for this PR.
If this adds or changes a rule
DBT001)build_dbt_rulesrather thanALL_RULES, opt-in pattern)tests/fixtures/dbt_project/(YAML only; no.sqlfiles so existingfiles_checkedcounts aren't bumped)tests/test_dbt_rules.pytests/test_dbt_rules.pyWhy no README update: the README rule table doesn't grow until at least three DBT rules exist, to avoid churning the table on every PR while the pack is still small.
Tests
pytest -qpasses (280 passed, 1 skipped — up from 254 on main)ruff check .passestests/test_dbt_discovery.py, 12 intests/test_dbt_rules.py(including end-to-end CLI integration).Checklist
CHANGELOG.md[Unreleased]entry addedAnything else reviewers should know
Deferred to follow-up PRs (per the ADR):
direct-table-ref), DBT003 (incremental-without-unique-key), DBT004 (hook-with-ddl), DBT005 (select-star-in-mart), DBT006 (model-without-description), DBT007 (var-injection-risk)Compatibility:
--dbtis opt-in.Rule.check_filemethod has a sensible default; no existing rule needs modification.