8000 fix(python): map ruff syntax errors to parse-error instead of a null smell by LiinaSuoniemi · Pull Request #69 · habit-hooks/habit-hooks · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion docs/python-plugin.spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,38 @@ habit-sensors --all | jq -c 'sort_by(.smell)[] | {smell, language, key: (.issues
{"smell":"unused-variable","language":"python","key":"billing.py","line":5,"source":"ruff:F841"}
```

## ruff maps a syntax error to parse-error

A file ruff cannot parse surfaces as `parse-error` (ruff reports it as
`invalid-syntax`), not a null smell, so a broken file is still coached rather
than silently mislabelled. This mirrors the TS plugin, where `eslint:fatal`
maps to `parse-error`.

📄.habit-hooks/config.toml
```toml
plugins = ["python"]

[sensors.deptry]
disabled = true
```

📄ruff.toml @plugins/python/src/habit_hooks_python/ruff.toml

📄broken.py
```python
def broken(:
return 1
```

```bash
habit-sensors --all | jq -c '.[] | {smell, source: .issues[0].details.source}'
```

🖥️ ✅
```json
{"smell":"parse-error","source":"ruff:invalid-syntax"}
```

## deptry sensor maps DEP002 to unused-dependency

The `deptry` sensor runs deptry against a temp JSON report and shapes each
Expand Down Expand Up @@ -173,7 +205,8 @@ ruff check --output-format=json --select=C901,PLR0913,PLR0915,F841,F401,BLE001 $
"PLR0915": "oversized-function",
"F841": "unused-variable",
"F401": "unused-import",
"BLE001": "swallowed-exception"
"BLE001": "swallowed-exception",
"invalid-syntax": "parse-error"
}[.code])})
| group_by(.smell)
| map({
Expand Down
1 change: 1 addition & 0 deletions docs/smell-vocabulary.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ only the plugin's sensors differ).
| `ruff:F841` | `unused-variable` |
| `ruff:F401` | `unused-import` |
| `ruff:BLE001` | `swallowed-exception` |
| `ruff:invalid-syntax` | `parse-error` |
| `jscpd:duplication` | `duplicated-code` |
| `deptry:DEP002` | `unused-dependency` |
| `line-count:max-module-lines` | `oversized-file` |
Expand Down
3 changes: 2 additions & 1 deletion plugins/python/src/habit_hooks_python/sensors/ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ ruff check --output-format=json --select=C901,PLR0913,PLR0915,F841,F401,BLE001 $
"PLR0915": "oversized-function",
"F841": "unused-variable",
"F401": "unused-import",
"BLE001": "swallowed-exception"
"BLE001": "swallowed-exception",
"invalid-syntax": "parse-error"
}[.code])})
| group_by(.smell)
| map({
Expand Down
Loading
0