Skip to content

tooling: Enable ruff preview rules for comment and operator spacing#343

Merged
nedseb merged 2 commits intomainfrom
tooling/ruff-preview-comment-spacing
Mar 30, 2026
Merged

tooling: Enable ruff preview rules for comment and operator spacing#343
nedseb merged 2 commits intomainfrom
tooling/ruff-preview-comment-spacing

Conversation

@nedseb
Copy link
Copy Markdown
Contributor

@nedseb nedseb commented Mar 30, 2026

Closes #342

Summary

Enables 4 ruff preview rules that were silently skipped despite "E" being selected:

Rule Description
E225 Missing whitespace around operator
E261 At least two spaces before inline comment
E262 Inline comment must start with #
E265 Block comment must start with #

Configuration approach

Uses explicit-preview-rules = true so 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

  • 6 E261 violations auto-fixed (missing two spaces before inline comments in lis2mdl and wsen-pads examples)
  • 3 RUF001/002/003 preview rules (ambiguous unicode µ for microtesla) added to ignore list — intentional usage

Impact

Test plan

  • ruff check lib/ tests/ passes
  • make test — 305 mock tests pass

Copilot AI review requested due to automatic review settings March 30, 2026 15:21
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 = true with explicit-preview-rules = true and 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
Comment on lines +92 to +94
"RUF001", # ambiguous unicode in string (µ for microtesla is intentional)
"RUF002", # ambiguous unicode in docstring
"RUF003", # ambiguous unicode in comment
Copy link

Copilot AI Mar 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
Copy link

Copilot AI Mar 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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)

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@nedseb nedseb merged commit 5323ba3 into main Mar 30, 2026
9 checks passed
@nedseb nedseb deleted the tooling/ruff-preview-comment-spacing branch March 30, 2026 15:33
@semantic-release-updater
Copy link
Copy Markdown

🎉 This PR is included in version 0.11.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tooling: Enable ruff preview rules for comment and operator spacing.

2 participants