Skip to content

Comments

feat: add rtk sqlfluff lint with JSON filter (~75% token reduction)#253

Open
TheGlitching wants to merge 1 commit intortk-ai:masterfrom
TheGlitching:feat/sqlfluff-lint
Open

feat: add rtk sqlfluff lint with JSON filter (~75% token reduction)#253
TheGlitching wants to merge 1 commit intortk-ai:masterfrom
TheGlitching:feat/sqlfluff-lint

Conversation

@TheGlitching
Copy link

@TheGlitching TheGlitching commented Feb 22, 2026

What & Why

Found sqlfluff lint as a missed opportunity using rtk discover on a
production dbt project — commands unhandled. This adds rtk sqlfluff lint
following the same pattern as rtk ruff.

How it works

  • Injects --format json automatically so output is structured
  • Groups violations by rule (top 10) and by file with per-file breakdown
  • Shows fixable count and suggests sqlfluff fix when relevant
  • fix, format, version subcommands pass through unchanged
  • Preserves exit codes for CI/CD
  • dbt-aware path compaction: keeps models/, macros/, seeds/ prefixes

Real-world discovery

While testing, I found that sqlfluff v3+ uses start_line_no/start_line_pos
in its JSON output (not line_no/line_pos as older docs suggest). Fixed and
covered with a regression test using actual command output.

Tests

13 tests: happy path, edge cases, JSON parse fallback, real schema
regression fixture, and token savings assertion (≥60% verified).

Example output

Before (sqlfluff lint models/):
~3,000 tokens of raw text with per-line violations

After (rtk sqlfluff lint models/):
SQLFluff: 10 violations in 3 files (2 fixable)
═══════════════════════════════════════
Top rules:
RF01 (4x)
LT09 (3x)
LT12 (2x)

Top files:
models/staging/stg_customers.sql (5 violations)
RF01 (2)
LT09 (2)
LT12 (1)
...

💡 Run sqlfluff fix to auto-fix 2 violations

…ction)

Adds `rtk sqlfluff lint` for SQL linting workflows, particularly dbt
projects. Discovered as a savings opportunity via `rtk discover`.

- Injects `--format json` automatically; passes through if user sets it
- Groups violations by rule (top N) and by file with per-file breakdown
- Shows fixable count and suggests `sqlfluff fix` when relevant
- Passes fix/format/version/parse subcommands through unchanged
- Preserves exit codes for CI/CD compatibility
- dbt-aware path compaction: keeps models/, macros/, seeds/ prefixes

Real-world tested on a production dbt project. Discovered that sqlfluff
v3+ uses `start_line_no`/`start_line_pos` field names (not `line_no`);
fixed and covered with a regression test using real command output.

13 tests: happy path, edge cases, JSON parse fallback, real schema
regression, and token savings assertion (≥60% verified).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant