Skip to content

Add ruff linting and apply code style fixes#16

Merged
iDavi merged 4 commits into
mainfrom
claude/nifty-gates-i8ytcx
Jun 26, 2026
Merged

Add ruff linting and apply code style fixes#16
iDavi merged 4 commits into
mainfrom
claude/nifty-gates-i8ytcx

Conversation

@iDavi

@iDavi iDavi commented Jun 26, 2026

Copy link
Copy Markdown
Owner

Summary

This PR introduces ruff as the project's linter and applies comprehensive code style fixes across the codebase to comply with the new linting rules.

Key Changes

Linting Infrastructure:

  • Added ruff as a dev dependency (>=0.15) in pyproject.toml
  • Configured ruff with strict linting rules targeting Python 3.10+
  • Added GitHub Actions workflow (.github/workflows/lint.yml) to enforce linting on all pushes and PRs
  • Configured ruff to catch common code smells including dead code, blind excepts, magic numbers, and other AI-generated code patterns

Code Style Fixes Applied:

  • Import sorting: Reorganized imports to follow standard library → third-party → local convention across multiple files
  • Line length: Reformatted long lines to respect the 120-character limit
  • Magic numbers: Extracted hardcoded values into named constants (e.g., _FOLD_LIMIT, _UNIT_STEP, _UTF8_CONT_MASK)
  • String encoding: Simplified .encode("utf-8") to .encode() where appropriate
  • Operator spacing: Fixed spacing around operators (e.g., 2 ** 152**15)
  • Exception handling: Replaced try/except blocks with contextlib.suppress() for cleaner code
  • Function signatures: Reformatted multi-line function arguments for consistency
  • Variable naming: Improved clarity by using more descriptive variable names (e.g., pathnorm to avoid shadowing)
  • Comment alignment: Standardized inline comment spacing

Notable Implementation Details:

  • Added noqa comment in magicicapsula/commands/config.py to suppress a false positive (config module iteration)
  • Configured bugbear to recognize KdfParams as an immutable dataclass safe for use as a default argument
  • Preserved intentional exception handling patterns with explicit ignore rules (e.g., TRY003 for CLI error messages)

https://claude.ai/code/session_01ARYv6iMTZ7UiZnbUL1LnJC

claude added 4 commits June 24, 2026 14:13
Configure ruff (lint + format) in pyproject.toml with a 120-char line
length matching the existing style, and enable a curated ruleset
(E, F, W, I, UP, B, SIM, C4, RUF). Add a `dev` optional-dependency
group and a CI workflow that runs `ruff check` and `ruff format --check`
on every push and pull request.

Bring the codebase fully into compliance:
- apply ruff formatting across all modules
- raise from None in date/init error paths (B904)
- use contextlib.suppress for the size-tally OSError (SIM105)
- drop the redundant utf-8 encode argument in ics (UP012)
- treat the immutable KdfParams dataclass as a safe default (B008)

Closes #12

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ARYv6iMTZ7UiZnbUL1LnJC
Add focused rule groups that flag the patterns most often left behind by
AI-generated code, then bring the codebase into compliance:

- ERA: commented-out / dead code
- BLE: blind `except:` that swallows everything
- RET: redundant else/return after a return
- PERF: obvious performance anti-patterns
- PIE: unnecessary pass / redundant constructs
- TRY: exception-handling anti-patterns (TRY003 ignored as too noisy
  for a small CLI's raise-site messages)
- PLW: pylint warnings, e.g. clobbered loop variables
- PLR2004: unexplained magic numbers in comparisons

Most groups were already clean, so they act as guardrails. Fixed the
few real smells they surfaced:
- name the byte-unit step constant in status size formatting
- name the RFC 5545 fold limit and utf-8 continuation-byte masks in ics
- stop reusing the loop variable while normalizing paths in _pack

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ARYv6iMTZ7UiZnbUL1LnJC
main added `info --json` after this branch was cut; its print(json.dumps(...))
block wasn't ruff-formatted, so the lint workflow failed on the PR's merge
commit even though the branch passed on its own. Reformat it to satisfy
`ruff format --check`.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ARYv6iMTZ7UiZnbUL1LnJC

@iDavi iDavi left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

looks good

@iDavi iDavi merged commit 2c1c8b0 into main Jun 26, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants