Skip to content

Commit f4ad664

Browse files
authored
Merge pull request #152 from a5chin/feature/sqlfluff
Add sqlfluff
2 parents e818a2c + a0ef3bc commit f4ad664

File tree

18 files changed

+363
-25
lines changed

18 files changed

+363
-25
lines changed

.devcontainer/devcontainer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"vscode": {
1414
"extensions": [
1515
"charliermarsh.ruff",
16+
"dorzey.vscode-sqlfluff",
1617
"exiasr.hadolint",
1718
"kevinrose.vsc-python-indent",
1819
"mosapride.zenkaku",

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ pytest-coverage.txt
182182
.coveragerc
183183
.env.local
184184
.pre-commit-config.yaml
185+
.sqlfluff
185186
assets
186187
LICENSE
187188
noxfile.py

.github/workflows/format.yml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ on:
77
- ".github/actions/setup-python-with-uv/action.yml"
88
- ".github/workflows/format.yml"
99
- "**.py"
10+
- "**.sql"
1011
- ".python-version"
12+
- ".sqlfluff"
1113
- "pyproject.toml"
1214
- "ruff.toml"
1315
- "uv.lock"
@@ -18,7 +20,9 @@ on:
1820
- ".github/actions/setup-python-with-uv/action.yml"
1921
- ".github/workflows/format.yml"
2022
- "**.py"
23+
- "**.sql"
2124
- ".python-version"
25+
- ".sqlfluff"
2226
- "pyproject.toml"
2327
- "ruff.toml"
2428
- "uv.lock"
@@ -35,4 +39,17 @@ jobs:
3539
uses: ./.github/actions/setup-python-with-uv
3640

3741
- name: Format by Ruff
38-
run: uv run nox -s fmt
42+
run: uv run nox -s fmt -- --ruff
43+
44+
sqlfluff:
45+
runs-on: ubuntu-latest
46+
47+
steps:
48+
- name: Checkout
49+
uses: actions/checkout@v6
50+
51+
- name: Setup Python with uv
52+
uses: ./.github/actions/setup-python-with-uv
53+
54+
- name: Format by SQLFluff
55+
run: uv run nox -s fmt -- --sqlfluff

.github/workflows/lint.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ on:
77
- ".github/actions/setup-python-with-uv/action.yml"
88
- ".github/workflows/lint.yml"
99
- "**.py"
10+
- "**.sql"
1011
- ".python-version"
12+
- ".sqlfluff"
1113
- "pyproject.toml"
1214
- "pyrightconfig.json"
1315
- "ruff.toml"
@@ -19,7 +21,9 @@ on:
1921
- ".github/actions/setup-python-with-uv/action.yml"
2022
- ".github/workflows/lint.yml"
2123
- "**.py"
24+
- "**.sql"
2225
- ".python-version"
26+
- ".sqlfluff"
2327
- "pyproject.toml"
2428
- "pyrightconfig.json"
2529
- "ruff.toml"
@@ -51,3 +55,16 @@ jobs:
5155

5256
- name: Lint by Ruff
5357
run: uv run nox -s lint -- --ruff
58+
59+
sqlfluff:
60+
runs-on: ubuntu-latest
61+
62+
steps:
63+
- name: Checkout
64+
uses: actions/checkout@v6
65+
66+
- name: Setup Python with uv
67+
uses: ./.github/actions/setup-python-with-uv
68+
69+
- name: Lint by SQLFluff
70+
run: uv run nox -s lint -- --sqlfluff

.pre-commit-config.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,18 @@ repos:
5454
types: ["dockerfile"]
5555
entry: hadolint
5656

57+
- repo: https://github.com/sqlfluff/sqlfluff
58+
rev: 3.5.0
59+
hooks:
60+
- id: sqlfluff-lint
61+
name: SQLFluff Lint
62+
description: "Lints sql files with `SQLFluff`"
63+
types: [sql]
64+
65+
- id: sqlfluff-fix
66+
name: SQLFluff Fix
67+
description: "Fixes sql lint errors with `SQLFluff`"
68+
types: [sql]
69+
5770
ci:
5871
autoupdate_schedule: weekly

.sqlfluff

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[sqlfluff]
2+
dialect = bigquery
3+
max_line_length = 80
4+
5+
exclude_rules =
6+
7+
[sqlfluff:indentation]
8+
tab_space_size = 2
9+
10+
[sqlfluff:rules:ambiguous.join]
11+
fully_qualify_join_types = both
12+
13+
[sqlfluff:rules:structure.unused_join]
14+
forbid_unused_join = True

.vscode/cspell.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"apdisk",
1111
"autoflake",
1212
"autolabeler",
13+
"beartype",
1314
"buildkit",
1415
"buildx",
1516
"caplog",
@@ -40,6 +41,7 @@
4041
"ipynb",
4142
"ipython",
4243
"isort",
44+
"jaxtyping",
4345
"junitxml",
4446
"kevinrose",
4547
"kwargs",
@@ -96,9 +98,11 @@
9698
"spyderproject",
9799
"spyproject",
98100
"sqlalchemy",
101+
"sqlfluff",
99102
"stmts",
100103
"superfences",
101104
"tamasfe",
105+
"templater",
102106
"testpaths",
103107
"timemachine",
104108
"toolsai",

.vscode/extensions.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"recommendations": [
33
"charliermarsh.ruff",
44
"codezombiech.gitignore",
5+
"dorzey.vscode-sqlfluff",
56
"eamodio.gitlens",
67
"exiasr.hadolint",
78
"kevinrose.vsc-python-indent",

.vscode/settings.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
"tests"
1414
],
1515
"python.testing.unittestEnabled": false,
16+
"sqlfluff.config": "${workspaceFolder}/.sqlfluff",
17+
"sqlfluff.executablePath": "/home/vscode/.venv/bin/sqlfluff",
18+
"sqlfluff.format.enabled": true,
19+
"sqlfluff.linter.run": "onType",
1620
"terminal.integrated.defaultProfile.linux": "zsh",
1721
"terminal.integrated.profiles.linux": {
1822
"zsh": {
@@ -61,6 +65,11 @@
6165
"editor.formatOnSave": true,
6266
"editor.tabSize": 4
6367
},
68+
"[sql]": {
69+
"editor.defaultFormatter": "dorzey.vscode-sqlfluff",
70+
"editor.formatOnSave": true,
71+
"editor.tabSize": 2
72+
},
6473
"[toml]": {
6574
"editor.defaultFormatter": "tamasfe.even-better-toml",
6675
"editor.formatOnSave": true,

CLAUDE.md

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,24 +42,40 @@ uv run pytest
4242

4343
### Linting & Formatting
4444
```bash
45-
# Format code
46-
uv run nox -s fmt
45+
# Format code with Ruff
46+
uv run nox -s fmt -- --ruff
47+
48+
# Format SQL files with SQLFluff
49+
uv run nox -s fmt -- --sqlfluff
50+
51+
# Format both Python and SQL
52+
uv run nox -s fmt -- --ruff --sqlfluff
4753

4854
# Lint with both Pyright and Ruff
4955
uv run nox -s lint -- --pyright --ruff
5056

57+
# Lint with all tools (Pyright, Ruff, SQLFluff)
58+
uv run nox -s lint -- --pyright --ruff --sqlfluff
59+
5160
# Lint with Pyright only
5261
uv run nox -s lint -- --pyright
5362

5463
# Lint with Ruff only
5564
uv run nox -s lint -- --ruff
5665

66+
# Lint SQL files only
67+
uv run nox -s lint -- --sqlfluff
68+
5769
# Run Ruff directly
5870
uv run ruff check . --fix
5971
uv run ruff format .
6072

6173
# Run Pyright directly
6274
uv run pyright
75+
76+
# Run SQLFluff directly
77+
uv run sqlfluff lint .
78+
uv run sqlfluff fix .
6379
```
6480

6581
### Pre-commit Hooks
@@ -164,6 +180,12 @@ Tests in `tests/tools/` mirror the package structure:
164180
- Reports: HTML + terminal
165181
- Import mode: importlib
166182

183+
**SQLFluff (.sqlfluff)**:
184+
- Dialect: BigQuery
185+
- Max line length: 80
186+
- Tab space size: 2
187+
- Custom rules for join qualification and unused joins
188+
167189
### Nox Task Automation
168190

169191
The `noxfile.py` uses a custom `CLIArgs` parser (Pydantic-based):
@@ -181,6 +203,8 @@ def lint(session: nox.Session) -> None:
181203
session.run("uv", "run", "pyright")
182204
if args.ruff:
183205
session.run("uv", "run", "ruff", "check", ".", "--fix")
206+
if args.sqlfluff:
207+
session.run("uv", "run", "sqlfluff", "lint", ".")
184208
```
185209

186210
## Key Patterns for Development

0 commit comments

Comments
 (0)