0Pricing
SQL Academy · Lesson

SQLFluff and Linting

Lint SQL with SQLFluff, enforce a house style, and auto-fix common formatting issues.

SQLFluff and Linting is a free SQL Academy lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the SQL Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Why Lint SQL?

SQL is hand-written, easy to format inconsistently. Linting enforces a house style automatically:

  • Lower vs UPPER keywords
  • Comma at end vs start of line
  • Naming conventions for tables, columns
  • Indentation
  • Anti-patterns (SELECT *, ambiguous joins, etc.)

SQLFluff: The De Facto Linter

Open source, dialect-aware, supports many SQL flavors and works great with dbt:

pip install sqlfluff

sqlfluff lint models/
sqlfluff fix models/   # auto-fix where safe

Configuring SQLFluff

A .sqlfluff config:

[sqlfluff]
dialect = postgres
templater = dbt
max_line_length = 120

[sqlfluff:rules:capitalisation.keywords]
capitalisation_policy = upper

[sqlfluff:rules:capitalisation.identifiers]
extended_capitalisation_policy = lower

Standard Rules

SQLFluff has 50+ rules — naming, layout, capitalisation, structure, ambiguity. Disable per-rule:

[sqlfluff]
exclude_rules = AM05, ST05

Inline Disabling

Skip a check for a single line:

SELECT *  -- noqa: AM04
FROM users;

Integration With dbt

SQLFluff understands Jinja and ref():

sqlfluff lint --templater dbt models/

Pre-Commit Hook

Run SQLFluff before every commit:

# .pre-commit-config.yaml
repos:
  - repo: https://github.com/sqlfluff/sqlfluff
    rev: 3.0.0
    hooks:
      - id: sqlfluff-lint
      - id: sqlfluff-fix

In CI

Block PRs with lint errors:

# GitHub Actions
- name: SQLFluff
  run: |
    pip install sqlfluff
    sqlfluff lint models/

Anti-Patterns to Lint

  • L044/AM04 — Avoid SELECT *
  • AM05 — Avoid implicit JOIN (comma)
  • ST05 — Avoid subqueries in FROM (use CTEs)
  • L010 — Inconsistent capitalisation

Formatter vs Linter

SQLFluff does both — checks AND auto-formats:

sqlfluff format models/    # newer: dedicated format command
sqlfluff fix models/       # alias for format + safe rule fixes

Other Tools

  • pg_format — pretty-prints SQL (PostgreSQL-focused)
  • SQLFluff is the most widely used; integrates with dbt
  • format-on-save in editors (VS Code, JetBrains)

Recap

Linting eliminates style debates and catches real bugs.

  • SQLFluff for lint + format
  • .sqlfluff configures rules
  • Run in pre-commit and CI
  • Combine with dbt for end-to-end SQL workflows

Quick Check

Which tool is the open-source standard for linting SQL (and works with dbt templates)?

Frequently asked questions

Is the “SQLFluff and Linting” lesson free?

Yes — the full text of “SQLFluff and Linting” is free to read here on the web, and the SQL Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the SQL Academy course, upgrade to CoddyKit PRO.

What will I learn in “SQLFluff and Linting”?

Lint SQL with SQLFluff, enforce a house style, and auto-fix common formatting issues. You practise SQL Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start SQL Academy?

No prior experience is required. SQL Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “SQLFluff and Linting” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this SQL Academy lesson?

Yes. Every SQL Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. DBT (Data Build Tool) Fundamentals
  2. SQLFluff and Linting
  3. Testing SQL: dbt tests, Great Expectations
  4. CI for Schema Changes (GitHub Actions)
← Back to SQL Academy