@codacy/tools-sqlfluff-3
v0.3.5
Published
SQLFluff adapter — CLI-mode SQL linter
Downloads
479
Readme
@codacy/tools-sqlfluff-3
Table of Contents
Overview
Multi-dialect SQL linter using SQLFluff. Uses the CLI execution strategy -- spawns sqlfluff lint --format json from a managed Python venv via spawnTool() and parses its JSON output.
| Property | Value |
| ------------- | -------------------------------------- |
| Tool ID | SQLFluff |
| Codacy UUID | eebd5ab6-3bef-4192-843c-f52bc4dce861 |
| Strategy | CLI |
| Languages | SQL |
| Binary | sqlfluff (pip-installed in venv) |
| File patterns | **/*.sql |
Updating patterns
# Re-fetch pattern metadata from the Codacy API
pnpm prefetch
# Commit the result
git add src/patterns.jsonThe prefetch script calls packages/tools/scripts/fetch-patterns.mjs with the tool UUID to download pattern metadata from the Codacy API.
Pattern IDs follow the format SQLFluff_AL01_aliasing.table, SQLFluff_LT01_layout.spacing, etc. -- they include both the short code and the rule name.
Updating the SQLFluff version
- Update
preferredVersioninsrc/adapter.ts - Update the
PIP_PACKAGESarray with the new pinned version - Run
pnpm prefetchto check for new/removed rules - Run
pnpm testto verify compatibility - If the major version changes, create a new adapter package (
sqlfluff-4/)
Development
pnpm build # Build with tsup
pnpm test # Run tests (requires sqlfluff in PATH or venv)To install sqlfluff locally for testing:
pip install sqlfluff==3.3.0Notes for maintainers
- Multi-dialect support: SQLFluff supports ANSI, PostgreSQL, MySQL, BigQuery, Snowflake, and many more SQL dialects. The generated config defaults to
dialect = ansi. Users can override this via a local.sqlfluffconfig file. - Python pip dependency: SQLFluff requires Python 3 as a runtime. The adapter uses an isolated venv at
~/.codacy/runtimes/sqlfluff-3/venv/. - Pattern ID mapping: SQLFluff's JSON output reports
code(e.g.AL01) but Codacy pattern IDs include both code and name (e.g.SQLFluff_AL01_aliasing.table). The adapter builds aCODE_TO_PATTERNreverse lookup map frompatterns.jsonat module initialization. - Config generation: When patterns are enabled but no local config exists, the adapter generates a
.sqlfluffINI file in.codacy/generated/withdialect = ansi,templater = raw, and aruleslist derived from the enabled pattern codes. - Exit code 0 = no violations, 1 = violations found (normal), 2 = error.
start_line_noandstart_line_posin sqlfluff's JSON output are 1-based, matching Codacy's convention.- Config file detection only checks for
.sqlfluffin the repository root. - Pattern filtering is both config-level (generated config only enables the requested rules) and post-hoc (results are filtered by enabled pattern IDs as a safety net).
