coop-sql-review 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- coop_sql_review-0.1.0/.gitignore +8 -0
- coop_sql_review-0.1.0/LICENSE +21 -0
- coop_sql_review-0.1.0/PKG-INFO +244 -0
- coop_sql_review-0.1.0/README.md +215 -0
- coop_sql_review-0.1.0/pyproject.toml +54 -0
- coop_sql_review-0.1.0/src/coop_sql_review/__init__.py +3 -0
- coop_sql_review-0.1.0/src/coop_sql_review/__main__.py +4 -0
- coop_sql_review-0.1.0/src/coop_sql_review/cli.py +321 -0
- coop_sql_review-0.1.0/src/coop_sql_review/data/standards.md +564 -0
- coop_sql_review-0.1.0/src/coop_sql_review/diagnostics.py +47 -0
- coop_sql_review-0.1.0/src/coop_sql_review/engine.py +87 -0
- coop_sql_review-0.1.0/src/coop_sql_review/finding.py +54 -0
- coop_sql_review-0.1.0/src/coop_sql_review/identifiers.py +45 -0
- coop_sql_review-0.1.0/src/coop_sql_review/parser.py +214 -0
- coop_sql_review-0.1.0/src/coop_sql_review/report.py +125 -0
- coop_sql_review-0.1.0/src/coop_sql_review/rules/__init__.py +32 -0
- coop_sql_review-0.1.0/src/coop_sql_review/rules/base.py +68 -0
- coop_sql_review-0.1.0/src/coop_sql_review/rules/helpers.py +89 -0
- coop_sql_review-0.1.0/src/coop_sql_review/rules/sql_alias_descriptive.py +44 -0
- coop_sql_review-0.1.0/src/coop_sql_review/rules/sql_bronze_raw_names.py +85 -0
- coop_sql_review-0.1.0/src/coop_sql_review/rules/sql_ctas_explicit_cast.py +115 -0
- coop_sql_review-0.1.0/src/coop_sql_review/rules/sql_cte_prefix.py +44 -0
- coop_sql_review-0.1.0/src/coop_sql_review/rules/sql_date_filter_param.py +61 -0
- coop_sql_review-0.1.0/src/coop_sql_review/rules/sql_distinct_smell.py +48 -0
- coop_sql_review-0.1.0/src/coop_sql_review/rules/sql_exists_comment.py +49 -0
- coop_sql_review-0.1.0/src/coop_sql_review/rules/sql_exists_why_quality.py +52 -0
- coop_sql_review-0.1.0/src/coop_sql_review/rules/sql_filter_upstream.py +49 -0
- coop_sql_review-0.1.0/src/coop_sql_review/rules/sql_header_comment.py +55 -0
- coop_sql_review-0.1.0/src/coop_sql_review/rules/sql_implicit_convert.py +123 -0
- coop_sql_review-0.1.0/src/coop_sql_review/rules/sql_insert_alias_match.py +59 -0
- coop_sql_review-0.1.0/src/coop_sql_review/rules/sql_join_filter.py +110 -0
- coop_sql_review-0.1.0/src/coop_sql_review/rules/sql_no_alter_column.py +51 -0
- coop_sql_review-0.1.0/src/coop_sql_review/rules/sql_no_select_star.py +43 -0
- coop_sql_review-0.1.0/src/coop_sql_review/rules/sql_order_by_in_view.py +95 -0
- coop_sql_review-0.1.0/src/coop_sql_review/rules/sql_prefer_cte.py +50 -0
- coop_sql_review-0.1.0/src/coop_sql_review/rules/sql_query_label.py +85 -0
- coop_sql_review-0.1.0/src/coop_sql_review/rules/sql_sargability.py +89 -0
- coop_sql_review-0.1.0/src/coop_sql_review/rules/sql_scd2_correct.py +92 -0
- coop_sql_review-0.1.0/src/coop_sql_review/rules/sql_silver_pascalcase.py +96 -0
- coop_sql_review-0.1.0/src/coop_sql_review/rules/sql_singleton_insert.py +51 -0
- coop_sql_review-0.1.0/src/coop_sql_review/rules/sql_table_layer_name.py +45 -0
- coop_sql_review-0.1.0/src/coop_sql_review/rules/sql_try_cast_bronze.py +79 -0
- coop_sql_review-0.1.0/src/coop_sql_review/rules/sql_txn_short.py +50 -0
- coop_sql_review-0.1.0/src/coop_sql_review/rules/sql_type_datetime.py +39 -0
- coop_sql_review-0.1.0/src/coop_sql_review/rules/sql_type_deprecated.py +45 -0
- coop_sql_review-0.1.0/src/coop_sql_review/rules/sql_type_money.py +39 -0
- coop_sql_review-0.1.0/src/coop_sql_review/rules/sql_type_nvarchar.py +39 -0
- coop_sql_review-0.1.0/src/coop_sql_review/rules/sql_upsert_choice.py +45 -0
- coop_sql_review-0.1.0/src/coop_sql_review/sql_common.py +160 -0
- coop_sql_review-0.1.0/src/coop_sql_review/sql_model.py +139 -0
- coop_sql_review-0.1.0/src/coop_sql_review/standards.py +84 -0
- coop_sql_review-0.1.0/src/coop_sql_review/upgrade.py +322 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Aaron Jennings
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: coop-sql-review
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Offline, advisory SQL standards linter for Microsoft Fabric Data Warehouse: parses .sql files and reports anything that doesn't match the team's SQL standards. Human report + machine JSON for the company agent. Never edits or blocks.
|
|
5
|
+
Project-URL: Homepage, https://github.com/kabukisensei/coop-sql-review
|
|
6
|
+
Author: Aaron Jennings
|
|
7
|
+
License: MIT
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Keywords: data-warehouse,fabric,linter,sql,standards,tsql
|
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
|
11
|
+
Classifier: Environment :: Console
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Classifier: Topic :: Database
|
|
19
|
+
Classifier: Topic :: Software Development :: Quality Assurance
|
|
20
|
+
Requires-Python: >=3.10
|
|
21
|
+
Requires-Dist: click>=8.1
|
|
22
|
+
Requires-Dist: pydantic>=2.5
|
|
23
|
+
Requires-Dist: pyyaml>=6.0
|
|
24
|
+
Requires-Dist: sqlglot>=25.0
|
|
25
|
+
Provides-Extra: dev
|
|
26
|
+
Requires-Dist: pytest>=8.0; extra == 'dev'
|
|
27
|
+
Requires-Dist: ruff>=0.5; extra == 'dev'
|
|
28
|
+
Description-Content-Type: text/markdown
|
|
29
|
+
|
|
30
|
+
# coop-sql-review
|
|
31
|
+
|
|
32
|
+
A friendly tool that **reads your `.sql` files and points out anything that doesn't follow our
|
|
33
|
+
SQL standards** for the Fabric data warehouse. It is **advisory only** — it never changes,
|
|
34
|
+
rejects, or deletes anything. It just prints a report so you can fix things before committing.
|
|
35
|
+
|
|
36
|
+
It works completely **offline** (your SQL never leaves your machine) and runs the same on
|
|
37
|
+
**Windows and Mac**.
|
|
38
|
+
|
|
39
|
+
---
|
|
40
|
+
|
|
41
|
+
## 1. What you need first
|
|
42
|
+
|
|
43
|
+
- **Python 3.10 or newer.** To check what you have, open a terminal (see below) and type:
|
|
44
|
+
```
|
|
45
|
+
python --version
|
|
46
|
+
```
|
|
47
|
+
If that says 3.10 or higher, you're set. If it says "command not found" or an older version,
|
|
48
|
+
install Python from https://www.python.org/downloads/ (tick *"Add Python to PATH"* on Windows).
|
|
49
|
+
|
|
50
|
+
- **How to open a terminal:**
|
|
51
|
+
- **Windows:** press the Start button, type `Terminal`, press Enter.
|
|
52
|
+
- **Mac:** press `Cmd+Space`, type `Terminal`, press Enter.
|
|
53
|
+
|
|
54
|
+
You'll type commands at the blinking prompt and press Enter after each one.
|
|
55
|
+
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
## 2. Install it (one time)
|
|
59
|
+
|
|
60
|
+
We use **pipx**, which keeps the tool tidy and separate from everything else on your machine.
|
|
61
|
+
|
|
62
|
+
**Step 1 — install pipx** (skip if you already have it):
|
|
63
|
+
```
|
|
64
|
+
python -m pip install --user pipx
|
|
65
|
+
python -m pipx ensurepath
|
|
66
|
+
```
|
|
67
|
+
**Close and reopen your terminal** after this (so it picks up the new command).
|
|
68
|
+
|
|
69
|
+
**Step 2 — install coop-sql-review:**
|
|
70
|
+
```
|
|
71
|
+
pipx install coop-sql-review
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
**Check it worked:**
|
|
75
|
+
```
|
|
76
|
+
coop-sql-review --version
|
|
77
|
+
```
|
|
78
|
+
You should see a version number like `coop-sql-review, version 0.1.0`.
|
|
79
|
+
|
|
80
|
+
> Not published to PyPI yet? Install straight from the repository instead:
|
|
81
|
+
> ```
|
|
82
|
+
> pipx install git+https://github.com/kabukisensei/coop-sql-review.git
|
|
83
|
+
> ```
|
|
84
|
+
|
|
85
|
+
---
|
|
86
|
+
|
|
87
|
+
## 3. Use it
|
|
88
|
+
|
|
89
|
+
The main command is **`check`**. Point it at a file or a folder of `.sql` files.
|
|
90
|
+
|
|
91
|
+
**Check one file:**
|
|
92
|
+
```
|
|
93
|
+
coop-sql-review check path/to/my_query.sql
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
**Check a whole folder** (it looks in sub-folders too):
|
|
97
|
+
```
|
|
98
|
+
coop-sql-review check path/to/sql-folder
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
> **Tip (don't know the path?)** Type `coop-sql-review check ` (with a trailing space), then
|
|
102
|
+
> **drag the file or folder from your file explorer onto the terminal window** — it pastes the
|
|
103
|
+
> path for you. Then press Enter.
|
|
104
|
+
|
|
105
|
+
That's it. The tool prints a report and **always finishes successfully** — it won't block you.
|
|
106
|
+
|
|
107
|
+
---
|
|
108
|
+
|
|
109
|
+
## 4. Reading the report
|
|
110
|
+
|
|
111
|
+
A typical report looks like this:
|
|
112
|
+
|
|
113
|
+
```
|
|
114
|
+
silver/dim_customer.sql
|
|
115
|
+
! silver/dim_customer.sql:12 [warning] SQL-NO-SELECT-STAR (§11)
|
|
116
|
+
SELECT * in production code — list the columns explicitly (§11).
|
|
117
|
+
x silver/dim_customer.sql:4 [error] SQL-NO-ALTER-COLUMN (§9)
|
|
118
|
+
ALTER COLUMN is not supported in Fabric DW — use the CTAS + RENAME workaround (§9).
|
|
119
|
+
|
|
120
|
+
Checked 1 file(s): 1 error, 1 warning.
|
|
121
|
+
Advisory only - nothing was changed or blocked.
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
- Each line shows **`file:line`**, a **severity**, the **rule** that fired, and the **§ section**
|
|
125
|
+
of the standards it comes from.
|
|
126
|
+
- **Severities:**
|
|
127
|
+
- **error** — almost certainly broken in Fabric (e.g. `ALTER COLUMN`, which Fabric rejects).
|
|
128
|
+
- **warning** — against the standard; worth fixing.
|
|
129
|
+
- **info** — a style/nice-to-have suggestion.
|
|
130
|
+
- **Diagnostics** (a separate section, if shown) are *processing* notes — e.g. "this statement
|
|
131
|
+
uses syntax we couldn't fully read." They tell you where the tool's checking may be incomplete,
|
|
132
|
+
so nothing fails silently.
|
|
133
|
+
- **Agent review** — a few checks (like "is this MERGE the right choice?") need human/agent
|
|
134
|
+
judgment, so they're listed separately rather than flagged as pass/fail.
|
|
135
|
+
|
|
136
|
+
**Show only the important stuff** (hide the info-level suggestions):
|
|
137
|
+
```
|
|
138
|
+
coop-sql-review check sql-folder --min-severity warning
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
---
|
|
142
|
+
|
|
143
|
+
## 5. All the commands
|
|
144
|
+
|
|
145
|
+
| Command | What it does |
|
|
146
|
+
|---|---|
|
|
147
|
+
| `coop-sql-review check [paths...]` | Check files/folders against the standards (the main command). |
|
|
148
|
+
| `coop-sql-review rules` | List every rule it checks, with severity and tier. |
|
|
149
|
+
| `coop-sql-review help` | Show help. `help check` shows help for one command. |
|
|
150
|
+
| `coop-sql-review update` | Update the tool to the newest version (same as `upgrade`). |
|
|
151
|
+
| `coop-sql-review upgrade` | Update the tool to the newest version. |
|
|
152
|
+
| `coop-sql-review --version` | Show the installed version. |
|
|
153
|
+
|
|
154
|
+
### Options for `check`
|
|
155
|
+
|
|
156
|
+
| Option | Meaning |
|
|
157
|
+
|---|---|
|
|
158
|
+
| `--min-severity error\|warning\|info` | Hide findings below this level. Default `info` (show all). |
|
|
159
|
+
| `--format text\|json` | `text` (default) for humans, `json` for tools/the agent. |
|
|
160
|
+
| `--standards <file>` | Check against a specific standards file (default: the built-in copy). |
|
|
161
|
+
| `--config <rules.yml>` | Turn rules on/off or change their severity (see §7). |
|
|
162
|
+
| `--log-file <file>` | Also write the diagnostics (parse problems, errors) to a file. |
|
|
163
|
+
| `--strict` | Exit with an error code if any finding **at or above `--min-severity`** remains — for CI gates (see §6). |
|
|
164
|
+
| `--dialect <name>` | SQL dialect to parse (default `tsql`, which fits Fabric). |
|
|
165
|
+
|
|
166
|
+
Run `coop-sql-review rules` any time to see the current full list of checks.
|
|
167
|
+
|
|
168
|
+
---
|
|
169
|
+
|
|
170
|
+
## 6. Use it in CI (optional)
|
|
171
|
+
|
|
172
|
+
By default the tool **never fails a build** (it's advisory). If a team *wants* a gate, add
|
|
173
|
+
`--strict` with a severity floor — it then exits with an error code when something at/above that
|
|
174
|
+
level is found:
|
|
175
|
+
|
|
176
|
+
```
|
|
177
|
+
coop-sql-review check sql-folder --strict --min-severity warning
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
For a machine-readable report (e.g. to attach to a build or feed the company agent):
|
|
181
|
+
```
|
|
182
|
+
coop-sql-review check sql-folder --format json > sql-review.json
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
---
|
|
186
|
+
|
|
187
|
+
## 7. Customising the rules (optional)
|
|
188
|
+
|
|
189
|
+
Create a small `rules.yml` to disable a rule or change its severity — no reinstall needed:
|
|
190
|
+
|
|
191
|
+
```yaml
|
|
192
|
+
rules:
|
|
193
|
+
SQL-DISTINCT-SMELL:
|
|
194
|
+
enabled: false # turn this rule off
|
|
195
|
+
SQL-NO-SELECT-STAR:
|
|
196
|
+
severity: error # treat SELECT * as an error instead of a warning
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
Then:
|
|
200
|
+
```
|
|
201
|
+
coop-sql-review check sql-folder --config rules.yml
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
To check against the team's canonical standards file directly:
|
|
205
|
+
```
|
|
206
|
+
coop-sql-review check sql-folder --standards path/to/sql-standards.md
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
---
|
|
210
|
+
|
|
211
|
+
## 8. Keeping it up to date
|
|
212
|
+
|
|
213
|
+
```
|
|
214
|
+
coop-sql-review update
|
|
215
|
+
```
|
|
216
|
+
This updates the tool (and safe dependency updates) to the latest version. It's the only command
|
|
217
|
+
that uses the internet.
|
|
218
|
+
|
|
219
|
+
---
|
|
220
|
+
|
|
221
|
+
## 9. Troubleshooting
|
|
222
|
+
|
|
223
|
+
- **`coop-sql-review: command not found`** — you likely skipped `pipx ensurepath`, or didn't
|
|
224
|
+
reopen the terminal. Run `python -m pipx ensurepath`, then close and reopen the terminal.
|
|
225
|
+
- **`externally-managed-environment` error on install** — that's why we use **pipx** (above)
|
|
226
|
+
instead of plain `pip`. Use the pipx steps in §2.
|
|
227
|
+
- **It conflicts with another tool's packages** — pipx isolates coop-sql-review so this shouldn't
|
|
228
|
+
happen; if you installed with plain `pip`, uninstall and reinstall with pipx.
|
|
229
|
+
- **Windows: odd characters in the report** — the tool prints UTF-8 and is tested on Windows; if
|
|
230
|
+
your console looks garbled, use Windows Terminal (the default on Windows 11).
|
|
231
|
+
- **"No .sql files found"** — double-check the folder path; the tool only reads files ending in
|
|
232
|
+
`.sql`.
|
|
233
|
+
|
|
234
|
+
---
|
|
235
|
+
|
|
236
|
+
## For developers & AI agents
|
|
237
|
+
|
|
238
|
+
- Architecture, the rule engine, and how to add a rule: see **`CLAUDE.md`**.
|
|
239
|
+
- What to build and why: **`SPEC.md`**; the full rule taxonomy: **`RULES.md`**.
|
|
240
|
+
- The standards being enforced: **`docs/standards.md`** (bundled with the tool).
|
|
241
|
+
- Run the tests: `PYTHONPATH=src python -m pytest -q` · lint: `ruff check src tests`.
|
|
242
|
+
|
|
243
|
+
This tool reuses the proven skeleton and conventions from the company's `coop-data-doc` tool
|
|
244
|
+
and shared CLI playbook.
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
# coop-sql-review
|
|
2
|
+
|
|
3
|
+
A friendly tool that **reads your `.sql` files and points out anything that doesn't follow our
|
|
4
|
+
SQL standards** for the Fabric data warehouse. It is **advisory only** — it never changes,
|
|
5
|
+
rejects, or deletes anything. It just prints a report so you can fix things before committing.
|
|
6
|
+
|
|
7
|
+
It works completely **offline** (your SQL never leaves your machine) and runs the same on
|
|
8
|
+
**Windows and Mac**.
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## 1. What you need first
|
|
13
|
+
|
|
14
|
+
- **Python 3.10 or newer.** To check what you have, open a terminal (see below) and type:
|
|
15
|
+
```
|
|
16
|
+
python --version
|
|
17
|
+
```
|
|
18
|
+
If that says 3.10 or higher, you're set. If it says "command not found" or an older version,
|
|
19
|
+
install Python from https://www.python.org/downloads/ (tick *"Add Python to PATH"* on Windows).
|
|
20
|
+
|
|
21
|
+
- **How to open a terminal:**
|
|
22
|
+
- **Windows:** press the Start button, type `Terminal`, press Enter.
|
|
23
|
+
- **Mac:** press `Cmd+Space`, type `Terminal`, press Enter.
|
|
24
|
+
|
|
25
|
+
You'll type commands at the blinking prompt and press Enter after each one.
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
## 2. Install it (one time)
|
|
30
|
+
|
|
31
|
+
We use **pipx**, which keeps the tool tidy and separate from everything else on your machine.
|
|
32
|
+
|
|
33
|
+
**Step 1 — install pipx** (skip if you already have it):
|
|
34
|
+
```
|
|
35
|
+
python -m pip install --user pipx
|
|
36
|
+
python -m pipx ensurepath
|
|
37
|
+
```
|
|
38
|
+
**Close and reopen your terminal** after this (so it picks up the new command).
|
|
39
|
+
|
|
40
|
+
**Step 2 — install coop-sql-review:**
|
|
41
|
+
```
|
|
42
|
+
pipx install coop-sql-review
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
**Check it worked:**
|
|
46
|
+
```
|
|
47
|
+
coop-sql-review --version
|
|
48
|
+
```
|
|
49
|
+
You should see a version number like `coop-sql-review, version 0.1.0`.
|
|
50
|
+
|
|
51
|
+
> Not published to PyPI yet? Install straight from the repository instead:
|
|
52
|
+
> ```
|
|
53
|
+
> pipx install git+https://github.com/kabukisensei/coop-sql-review.git
|
|
54
|
+
> ```
|
|
55
|
+
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
## 3. Use it
|
|
59
|
+
|
|
60
|
+
The main command is **`check`**. Point it at a file or a folder of `.sql` files.
|
|
61
|
+
|
|
62
|
+
**Check one file:**
|
|
63
|
+
```
|
|
64
|
+
coop-sql-review check path/to/my_query.sql
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
**Check a whole folder** (it looks in sub-folders too):
|
|
68
|
+
```
|
|
69
|
+
coop-sql-review check path/to/sql-folder
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
> **Tip (don't know the path?)** Type `coop-sql-review check ` (with a trailing space), then
|
|
73
|
+
> **drag the file or folder from your file explorer onto the terminal window** — it pastes the
|
|
74
|
+
> path for you. Then press Enter.
|
|
75
|
+
|
|
76
|
+
That's it. The tool prints a report and **always finishes successfully** — it won't block you.
|
|
77
|
+
|
|
78
|
+
---
|
|
79
|
+
|
|
80
|
+
## 4. Reading the report
|
|
81
|
+
|
|
82
|
+
A typical report looks like this:
|
|
83
|
+
|
|
84
|
+
```
|
|
85
|
+
silver/dim_customer.sql
|
|
86
|
+
! silver/dim_customer.sql:12 [warning] SQL-NO-SELECT-STAR (§11)
|
|
87
|
+
SELECT * in production code — list the columns explicitly (§11).
|
|
88
|
+
x silver/dim_customer.sql:4 [error] SQL-NO-ALTER-COLUMN (§9)
|
|
89
|
+
ALTER COLUMN is not supported in Fabric DW — use the CTAS + RENAME workaround (§9).
|
|
90
|
+
|
|
91
|
+
Checked 1 file(s): 1 error, 1 warning.
|
|
92
|
+
Advisory only - nothing was changed or blocked.
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
- Each line shows **`file:line`**, a **severity**, the **rule** that fired, and the **§ section**
|
|
96
|
+
of the standards it comes from.
|
|
97
|
+
- **Severities:**
|
|
98
|
+
- **error** — almost certainly broken in Fabric (e.g. `ALTER COLUMN`, which Fabric rejects).
|
|
99
|
+
- **warning** — against the standard; worth fixing.
|
|
100
|
+
- **info** — a style/nice-to-have suggestion.
|
|
101
|
+
- **Diagnostics** (a separate section, if shown) are *processing* notes — e.g. "this statement
|
|
102
|
+
uses syntax we couldn't fully read." They tell you where the tool's checking may be incomplete,
|
|
103
|
+
so nothing fails silently.
|
|
104
|
+
- **Agent review** — a few checks (like "is this MERGE the right choice?") need human/agent
|
|
105
|
+
judgment, so they're listed separately rather than flagged as pass/fail.
|
|
106
|
+
|
|
107
|
+
**Show only the important stuff** (hide the info-level suggestions):
|
|
108
|
+
```
|
|
109
|
+
coop-sql-review check sql-folder --min-severity warning
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
---
|
|
113
|
+
|
|
114
|
+
## 5. All the commands
|
|
115
|
+
|
|
116
|
+
| Command | What it does |
|
|
117
|
+
|---|---|
|
|
118
|
+
| `coop-sql-review check [paths...]` | Check files/folders against the standards (the main command). |
|
|
119
|
+
| `coop-sql-review rules` | List every rule it checks, with severity and tier. |
|
|
120
|
+
| `coop-sql-review help` | Show help. `help check` shows help for one command. |
|
|
121
|
+
| `coop-sql-review update` | Update the tool to the newest version (same as `upgrade`). |
|
|
122
|
+
| `coop-sql-review upgrade` | Update the tool to the newest version. |
|
|
123
|
+
| `coop-sql-review --version` | Show the installed version. |
|
|
124
|
+
|
|
125
|
+
### Options for `check`
|
|
126
|
+
|
|
127
|
+
| Option | Meaning |
|
|
128
|
+
|---|---|
|
|
129
|
+
| `--min-severity error\|warning\|info` | Hide findings below this level. Default `info` (show all). |
|
|
130
|
+
| `--format text\|json` | `text` (default) for humans, `json` for tools/the agent. |
|
|
131
|
+
| `--standards <file>` | Check against a specific standards file (default: the built-in copy). |
|
|
132
|
+
| `--config <rules.yml>` | Turn rules on/off or change their severity (see §7). |
|
|
133
|
+
| `--log-file <file>` | Also write the diagnostics (parse problems, errors) to a file. |
|
|
134
|
+
| `--strict` | Exit with an error code if any finding **at or above `--min-severity`** remains — for CI gates (see §6). |
|
|
135
|
+
| `--dialect <name>` | SQL dialect to parse (default `tsql`, which fits Fabric). |
|
|
136
|
+
|
|
137
|
+
Run `coop-sql-review rules` any time to see the current full list of checks.
|
|
138
|
+
|
|
139
|
+
---
|
|
140
|
+
|
|
141
|
+
## 6. Use it in CI (optional)
|
|
142
|
+
|
|
143
|
+
By default the tool **never fails a build** (it's advisory). If a team *wants* a gate, add
|
|
144
|
+
`--strict` with a severity floor — it then exits with an error code when something at/above that
|
|
145
|
+
level is found:
|
|
146
|
+
|
|
147
|
+
```
|
|
148
|
+
coop-sql-review check sql-folder --strict --min-severity warning
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
For a machine-readable report (e.g. to attach to a build or feed the company agent):
|
|
152
|
+
```
|
|
153
|
+
coop-sql-review check sql-folder --format json > sql-review.json
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
---
|
|
157
|
+
|
|
158
|
+
## 7. Customising the rules (optional)
|
|
159
|
+
|
|
160
|
+
Create a small `rules.yml` to disable a rule or change its severity — no reinstall needed:
|
|
161
|
+
|
|
162
|
+
```yaml
|
|
163
|
+
rules:
|
|
164
|
+
SQL-DISTINCT-SMELL:
|
|
165
|
+
enabled: false # turn this rule off
|
|
166
|
+
SQL-NO-SELECT-STAR:
|
|
167
|
+
severity: error # treat SELECT * as an error instead of a warning
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
Then:
|
|
171
|
+
```
|
|
172
|
+
coop-sql-review check sql-folder --config rules.yml
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
To check against the team's canonical standards file directly:
|
|
176
|
+
```
|
|
177
|
+
coop-sql-review check sql-folder --standards path/to/sql-standards.md
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
---
|
|
181
|
+
|
|
182
|
+
## 8. Keeping it up to date
|
|
183
|
+
|
|
184
|
+
```
|
|
185
|
+
coop-sql-review update
|
|
186
|
+
```
|
|
187
|
+
This updates the tool (and safe dependency updates) to the latest version. It's the only command
|
|
188
|
+
that uses the internet.
|
|
189
|
+
|
|
190
|
+
---
|
|
191
|
+
|
|
192
|
+
## 9. Troubleshooting
|
|
193
|
+
|
|
194
|
+
- **`coop-sql-review: command not found`** — you likely skipped `pipx ensurepath`, or didn't
|
|
195
|
+
reopen the terminal. Run `python -m pipx ensurepath`, then close and reopen the terminal.
|
|
196
|
+
- **`externally-managed-environment` error on install** — that's why we use **pipx** (above)
|
|
197
|
+
instead of plain `pip`. Use the pipx steps in §2.
|
|
198
|
+
- **It conflicts with another tool's packages** — pipx isolates coop-sql-review so this shouldn't
|
|
199
|
+
happen; if you installed with plain `pip`, uninstall and reinstall with pipx.
|
|
200
|
+
- **Windows: odd characters in the report** — the tool prints UTF-8 and is tested on Windows; if
|
|
201
|
+
your console looks garbled, use Windows Terminal (the default on Windows 11).
|
|
202
|
+
- **"No .sql files found"** — double-check the folder path; the tool only reads files ending in
|
|
203
|
+
`.sql`.
|
|
204
|
+
|
|
205
|
+
---
|
|
206
|
+
|
|
207
|
+
## For developers & AI agents
|
|
208
|
+
|
|
209
|
+
- Architecture, the rule engine, and how to add a rule: see **`CLAUDE.md`**.
|
|
210
|
+
- What to build and why: **`SPEC.md`**; the full rule taxonomy: **`RULES.md`**.
|
|
211
|
+
- The standards being enforced: **`docs/standards.md`** (bundled with the tool).
|
|
212
|
+
- Run the tests: `PYTHONPATH=src python -m pytest -q` · lint: `ruff check src tests`.
|
|
213
|
+
|
|
214
|
+
This tool reuses the proven skeleton and conventions from the company's `coop-data-doc` tool
|
|
215
|
+
and shared CLI playbook.
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "coop-sql-review"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Offline, advisory SQL standards linter for Microsoft Fabric Data Warehouse: parses .sql files and reports anything that doesn't match the team's SQL standards. Human report + machine JSON for the company agent. Never edits or blocks."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
license = { text = "MIT" }
|
|
12
|
+
authors = [{ name = "Aaron Jennings" }]
|
|
13
|
+
keywords = ["sql", "linter", "fabric", "data-warehouse", "tsql", "standards"]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Development Status :: 3 - Alpha",
|
|
16
|
+
"Environment :: Console",
|
|
17
|
+
"Intended Audience :: Developers",
|
|
18
|
+
"License :: OSI Approved :: MIT License",
|
|
19
|
+
"Programming Language :: Python :: 3.10",
|
|
20
|
+
"Programming Language :: Python :: 3.11",
|
|
21
|
+
"Programming Language :: Python :: 3.12",
|
|
22
|
+
"Programming Language :: Python :: 3.13",
|
|
23
|
+
"Topic :: Database",
|
|
24
|
+
"Topic :: Software Development :: Quality Assurance",
|
|
25
|
+
]
|
|
26
|
+
dependencies = [
|
|
27
|
+
"pydantic>=2.5",
|
|
28
|
+
"PyYAML>=6.0",
|
|
29
|
+
"sqlglot>=25.0",
|
|
30
|
+
"click>=8.1",
|
|
31
|
+
]
|
|
32
|
+
|
|
33
|
+
[project.optional-dependencies]
|
|
34
|
+
dev = ["pytest>=8.0", "ruff>=0.5"]
|
|
35
|
+
|
|
36
|
+
[project.scripts]
|
|
37
|
+
coop-sql-review = "coop_sql_review.cli:main"
|
|
38
|
+
|
|
39
|
+
[project.urls]
|
|
40
|
+
Homepage = "https://github.com/kabukisensei/coop-sql-review"
|
|
41
|
+
|
|
42
|
+
[tool.hatch.build.targets.wheel]
|
|
43
|
+
packages = ["src/coop_sql_review"]
|
|
44
|
+
|
|
45
|
+
[tool.hatch.build]
|
|
46
|
+
# Ship the bundled standards so `coop-sql-review` works with no --standards flag.
|
|
47
|
+
include = ["src/coop_sql_review/**/*.py", "src/coop_sql_review/data/*.md"]
|
|
48
|
+
|
|
49
|
+
[tool.pytest.ini_options]
|
|
50
|
+
testpaths = ["tests"]
|
|
51
|
+
|
|
52
|
+
[tool.ruff]
|
|
53
|
+
line-length = 110
|
|
54
|
+
target-version = "py310"
|