tooling: Enable ruff preview rules for comment and operator spacing#343
tooling: Enable ruff preview rules for comment and operator spacing#343
Conversation
There was a problem hiding this comment.
Pull request overview
Enables a small, explicit set of Ruff preview lint rules to catch operator/comment spacing issues that were previously skipped, and applies auto-fixes to a handful of example files.
Changes:
- Turn on
preview = truewithexplicit-preview-rules = trueand explicitly enable E225/E261/E262/E265. - Add global ignores for RUF001/002/003 (ambiguous Unicode) to allow intentional
µusage. - Auto-fix inline comment spacing in WSEN-PADS examples and one LIS2MDL line.
Reviewed changes
Copilot reviewed 1 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| pyproject.toml | Enables specific Ruff preview rules and adds ignores for ambiguous-Unicode checks. |
| lib/wsen-pads/examples/threshold_alert.py | Fixes inline comment spacing to satisfy E261/E262. |
| lib/wsen-pads/examples/pressure_trend.py | Fixes inline comment spacing to satisfy E261/E262. |
| lib/wsen-pads/examples/altitude.py | Fixes inline comment spacing to satisfy E261/E262. |
| lib/lis2mdl/lis2mdl/device.py | Adjusts inline comment spacing on heading calculation line. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
pyproject.toml
Outdated
| "RUF001", # ambiguous unicode in string (µ for microtesla is intentional) | ||
| "RUF002", # ambiguous unicode in docstring | ||
| "RUF003", # ambiguous unicode in comment |
There was a problem hiding this comment.
RUF001/RUF002/RUF003 are being ignored globally, which disables ambiguous-Unicode detection across the entire repository (not just the intentional µ usage). To retain protection against accidental/confusable characters elsewhere, scope these ignores to only the files that actually contain µ (e.g. via [tool.ruff.lint.per-file-ignores] for the lib/lis2mdl/** paths) or use targeted # noqa: RUF00{1,2,3} on the specific lines where µ is intentional.
There was a problem hiding this comment.
Fixed in 46459d3: RUF001/002/003 are now scoped to lib/lis2mdl/**/*.py via per-file-ignores instead of being globally ignored. Ambiguous unicode detection remains active for the rest of the codebase.
| y = (y - self.y_off) / (self.y_scale or 1.0) | ||
| # IMPORTANT: atan2(Y, X) | ||
| ang = math.degrees(math.atan2(x, y)) # atan2(Y, X) for compass heading (Y is forward, X is right) | ||
| ang = math.degrees(math.atan2(x, y)) # atan2(Y, X) for compass heading (Y is forward, X is right) |
There was a problem hiding this comment.
heading_from_vectors() computes ang using math.atan2(x, y), but both the preceding comment and the tilt-compensated path use the atan2(y, x) convention (see heading_with_tilt_compensation() using math.atan2(yh, xh)). With a flat accelerometer input (roll/pitch = 0), this makes heading_flat_only() inconsistent with the tilt-compensated heading. Align the argument order (or adjust the comments) so both methods produce the same heading when the board is flat.
| ang = math.degrees(math.atan2(x, y)) # atan2(Y, X) for compass heading (Y is forward, X is right) | |
| ang = math.degrees(math.atan2(y, x)) # atan2(Y, X) for compass heading (Y is forward, X is right) |
There was a problem hiding this comment.
Out of scope for this PR — this is a pre-existing bug in the LIS2MDL compass heading code, not related to the ruff preview rules change. Created a note to investigate separately.
|
🎉 This PR is included in version 0.11.1 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
Closes #342
Summary
Enables 4 ruff preview rules that were silently skipped despite
"E"being selected:##Configuration approach
Uses
explicit-preview-rules = trueso that only the 4 listed preview rules are activated — not all preview rules in every selected group. This avoids false positives from other preview rules (PLC0415 lazy imports, PLR6301 staticmethod suggestions, PLR6201 set literals incompatible with MicroPython, etc.).Fixes applied
µfor microtesla) added to ignore list — intentional usageImpact
ruff checknow catches comment spacing issues that were missed in PR feat(vl53l1x): Add proximity alert example with buzzer. #337Test plan
ruff check lib/ tests/passesmake test— 305 mock tests pass