This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
collate-sqlfluff is an open-metadata fork of SQLFluff — a dialect-flexible SQL linter and formatter. The package installs as collate-sqlfluff but imports as sqlfluff.
pip install -e .
# Or create a full dev virtualenv with tox (pick a dbt env from tox.ini):
tox -e dbt180 --devenv .venv && source .venv/bin/activate# Full test suite via tox (pick your Python version from tox.ini envlist)
tox -e py313
# Run specific tests directly
pytest -vv test/core/parser/parser_test.py
pytest -vv -k "test_rule_AL02" test/
# Run a specific test class/method
pytest test/api/test_cli_commands.py::TestLint::test_lint
# Dialect-specific test suites (use markers)
pytest -vv -m parse_suite test/
pytest -vv -m fix_suite test/
pytest -vv -m rules_suite test/
# dbt plugin tests (requires a dbt tox env)
tox -e dbt180 -- plugins/sqlfluff-templater-dbttox -e linting # ruff, black (check), flake8, lint-imports
tox -e mypy # type checking (strict on sqlfluff.core)python test/generate_parse_fixture_yml.py
# Or via tox:
tox -e generate-fixture-ymltox -e generate-fixture-yml,linting,mypy,cov-init,py313,cov-report- Templater — expands Jinja/dbt/placeholder templates into raw SQL
- Lexer — tokenizes SQL into typed segments
- Parser — builds a parse tree using dialect-specific grammars
- Linter — applies rules to the parse tree and reports violations
api/— Public Python API (lint,fix,parse,list_rules,list_dialects)cli/— Click-based CLI (sqlfluff lint,sqlfluff fix,sqlfluff parse)core/— Core engine (strictest mypy checking):parser/— Lexer, parser, grammar matchinglinter/— Linting orchestrationrules/— Base rule class and rule infrastructuretemplaters/— Jinja, dbt, placeholder, python templatersconfig/— Configuration loading and resolutiondialects/— Dialect registry and base/common segment definitions
dialects/— SQL dialect implementations. Each dialect has adialect_<name>.pyand usually adialect_<name>_keywords.py. Dialects inherit from ANSI.rules/— Rule plugins organized by category:capitalisation/,aliasing/,layout/,references/,ambiguous/,structure/,convention/,jinja/,tsql/utils/— Testing utilities and reflow helpers
sqlfluff-templater-dbt/— dbt templater (version-pinned to main package)sqlfluff-plugin-example/— Example plugin template for custom rules
Mirror the source structure. Test files use *_test.py naming. Key markers: parse_suite, fix_suite, rules_suite, dbt, integration.
- 100% coverage required — enforced in CI (dbt templater excluded from default coverage)
- lint-imports enforces strict dependency layering — import cycles between packages will fail CI
- mypy --strict applies to
sqlfluff.core— all other packages get standard mypy - Fixture generation — after modifying dialect grammar, run
python test/generate_parse_fixture_yml.pyto regenerate YAML parse fixtures before committing - Plugin install order matters — the dbt templater pins its version to the main package, so it must be installed after the main package
- Use the virtual environment when present — before running Python, pytest, tox, or any project commands, check for a virtual environment (common locations:
venv/,.venv/,env/) and use its Python binary (e.g.venv/bin/python). Do not use the system Python when a project venv exists. - Dialect grammar changes must be backed by sources — all grammar additions or modifications must reference the official database documentation and match its syntax exactly. If the reported behavior conflicts with the official docs, verify against a live database instance before proceeding. Cite sources (doc links, issue references, verification results) in both code comments and test files.