Problem
The PR #337 contained several PEP 8 violations that ruff did not catch:
- `#buzzer initialisation` — missing space after `#` (E265)
- `buzzer_ch.pulse_width_percent(0) #comment` — missing two spaces before inline comment (E261)
- `1500- (distance * 5)` — missing space around operator (E225)
These were caught during manual code review but should have been flagged by the linter.
Root cause
These rules are in ruff preview mode and require `preview = true` in the ruff configuration to be active:
| Rule |
Description |
Status |
| E265 |
No space after block comment `#` |
Preview |
| E261 |
At least two spaces before inline comment |
Preview |
| E262 |
Inline comment must start with `# ` |
Preview |
| E225 |
Missing whitespace around operator |
Preview |
Our `pyproject.toml` selects `"E"` but ruff only enables stable E-rules by default. The preview rules are silently skipped.
Proposed fix
Add `preview = true` to the ruff lint configuration in `pyproject.toml`:
```toml
[tool.ruff.lint]
preview = true
select = [
...existing rules...
]
```
Impact assessment needed
Enabling preview mode activates all preview rules in the selected groups, not just E265/E261/E262/E225. Before merging:
- Run `ruff check --preview` on the full codebase to see how many new violations appear
- Add any false-positive or MicroPython-incompatible preview rules to the `ignore` list
- Fix or auto-fix the legitimate violations
Alternative: select specific preview rules
If enabling full preview mode causes too many new violations, an alternative is to explicitly select just the comment spacing rules and enable preview only for those:
```toml
[tool.ruff.lint]
preview = true
explicit-preview-rules = true
select = [
...existing rules...,
"E225",
"E261",
"E262",
"E265",
]
```
With `explicit-preview-rules = true`, only the preview rules explicitly listed in `select` are activated — the rest stay off.
Tasks
Related
Problem
The PR #337 contained several PEP 8 violations that ruff did not catch:
These were caught during manual code review but should have been flagged by the linter.
Root cause
These rules are in ruff preview mode and require `preview = true` in the ruff configuration to be active:
Our `pyproject.toml` selects `"E"` but ruff only enables stable E-rules by default. The preview rules are silently skipped.
Proposed fix
Add `preview = true` to the ruff lint configuration in `pyproject.toml`:
```toml
[tool.ruff.lint]
preview = true
select = [
...existing rules...
]
```
Impact assessment needed
Enabling preview mode activates all preview rules in the selected groups, not just E265/E261/E262/E225. Before merging:
Alternative: select specific preview rules
If enabling full preview mode causes too many new violations, an alternative is to explicitly select just the comment spacing rules and enable preview only for those:
```toml
[tool.ruff.lint]
preview = true
explicit-preview-rules = true
select = [
...existing rules...,
"E225",
"E261",
"E262",
"E265",
]
```
With `explicit-preview-rules = true`, only the preview rules explicitly listed in `select` are activated — the rest stay off.
Tasks
Related