Skip to content

ci: H-1 batch 4 — Ruff SIM + RUF#111

Merged
rolandpg merged 1 commit into
masterfrom
fix/audit-h1-ruff-batch-4-simruf
Apr 25, 2026
Merged

ci: H-1 batch 4 — Ruff SIM + RUF#111
rolandpg merged 1 commit into
masterfrom
fix/audit-h1-ruff-batch-4-simruf

Conversation

@rolandpg
Copy link
Copy Markdown
Owner

Summary

Adds SIM (flake8-simplify) and RUF (ruff-specific) to the ruff select list. Surfaced 37 findings; 17 auto/unsafe-fixed, 16 manual fixes, plus RUF002/RUF003 ignored globally for stylistic unicode (en-dash and ×).

Manual fixes

  • RUF012 mutable default class attr (4) — annotated ClassVar[...] on EntityExtractor.REGEX_PATTERNS / ENTITY_TYPES / _NAME_STOPWORDS, NoteConstructor.CAUSAL_RELATIONS
  • SIM102 nested if (4) — flattened to and-combined in ontology + governance_validator
  • SIM105 try-except-pass (2) — contextlib.suppress in llm_providers + lance row delete
  • SIM108 if-else → ternary (1) — compact_lance mode dispatch
  • SIM103 return negated (1) — vector_retriever variance check
  • F401 orphan probe-import (1) — dateparserimportlib.util.find_spec

Why ignore RUF002/RUF003

Codebase consistently uses (EN DASH) as typographic separator in comments and docstrings, and × in performance docs ("32× improvement"). Stylistic, not bugs.

Test plan

  • ruff check src/ clean
  • ruff format --check src/ clean
  • 87/89 critical tests pass (2 pre-existing env-dependent: test_ingest_relationship, test_intent_classification)
  • CI green

🤖 Generated with Claude Code

Adds SIM (flake8-simplify) and RUF (ruff-specific) to the ruff `select`
list. Surfaced 37 findings; 17 auto/unsafe-fixed, 16 manual fixes, plus
RUF002/RUF003 (ambiguous unicode in docstrings/comments) ignored
globally — the en-dash and × characters are intentional.

## Manual fixes

- **RUF012** (mutable default class attribute, 4 cases) — annotated as
  `ClassVar[...]`: `EntityExtractor.REGEX_PATTERNS / ENTITY_TYPES /
  _NAME_STOPWORDS`, `NoteConstructor.CAUSAL_RELATIONS`.
- **SIM102** (nested if → and-combined) — flattened in `ontology.py`
  (3 cases) and `governance_validator.py`. The latter also removed a
  no-op `pass`-only branch left over from a placeholder.
- **SIM105** (try-except-pass → contextlib.suppress) — applied to
  `llm_providers/__init__.py` and `memory_store.py` Lance delete-row.
- **SIM108** (if-else → ternary) — `compact_lance.py` mode dispatch.
- **SIM103** (return negated) — `vector_retriever._is_valid_embedding`.
- **F401** (unused `import dateparser`) — replaced probe-import with
  `importlib.util.find_spec("dateparser")` in temporal-boost path.

## Why ignore RUF002/RUF003

The codebase uses `–` (EN DASH) in comments and docstrings as a
typographic separator (e.g., "0.0–10.0", "—") and `×` in performance
docs (e.g., "32× improvement"). These are intentional stylistic
choices. A top-level ignore matches the actual authoring conventions.

Stacked on fix/audit-h1-ruff-batch-3-up (PR #109).
Copilot AI review requested due to automatic review settings April 25, 2026 05:09
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

Expands the project’s Ruff lint coverage by enabling SIM (flake8-simplify) and RUF (Ruff-specific) rules, then applies mechanical refactors and small typing fixes across the codebase to make the new rules pass.

Changes:

  • Update Ruff configuration to select SIM and RUF, and globally ignore RUF002/RUF003 for intentional Unicode punctuation in comments/docstrings.
  • Refactor multiple sites to satisfy SIM* rules (flatten nested ifs, replace try/except/pass with contextlib.suppress, simplify list concatenation patterns).
  • Fix typing issues surfaced by Ruff (e.g., optional parameter annotations, ClassVar for mutable class attributes).

Reviewed changes

Copilot reviewed 18 out of 18 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/zettelforge/vector_retriever.py Simplifies variance check return logic for embeddings (SIM103).
src/zettelforge/vector_memory.py Collapses chunking if/else into a conditional expression (SIM108).
src/zettelforge/synthesis_generator.py Corrects tier_filter typing to list[str] | None.
src/zettelforge/sqlite_backend.py Uses contextlib.suppress during WAL checkpoint and simplifies list building.
src/zettelforge/scripts/compact_lance.py Simplifies mode dispatch to a conditional expression (SIM108).
src/zettelforge/ontology.py Flattens nested conditionals in validators and query helpers (SIM102).
src/zettelforge/note_constructor.py Annotates mutable class attribute with ClassVar (RUF012).
src/zettelforge/memory_store.py Replaces try/except/pass with contextlib.suppress for best-effort deletes (SIM105).
src/zettelforge/memory_manager.py Removes unused local (_intent_meta), replaces probe-import with find_spec, updates optional typing.
src/zettelforge/llm_providers/init.py Replaces try/except ValueError with contextlib.suppress during provider registration (SIM105).
src/zettelforge/knowledge_graph.py Simplifies list extension pattern for DFS paths.
src/zettelforge/graph_retriever.py Simplifies list extension pattern for BFS paths.
src/zettelforge/governance_validator.py Flattens nested if structure (SIM102) and removes no-op branch.
src/zettelforge/entity_indexer.py Adds ClassVar for mutable class attrs, uses contextlib.suppress for cleanup, minor iteration simplification.
src/zettelforge/demo.py Removes unused return value binding.
src/zettelforge/config.py Replaces nested try/except/pass with contextlib.suppress for float parsing (SIM105).
src/zettelforge/init.py Reorders __all__ entries (no functional change).
pyproject.toml Enables Ruff SIM + RUF and ignores RUF002/RUF003 globally.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@rolandpg rolandpg merged commit 95cd298 into master Apr 25, 2026
16 checks passed
@rolandpg rolandpg deleted the fix/audit-h1-ruff-batch-4-simruf branch April 25, 2026 05:11
rolandpg added a commit that referenced this pull request Apr 25, 2026
… work

The [Unreleased] section was empty since v2.4.3 cut. Captures
everything merged since: RFC-011 local LLM backend (#104), RFC-012
LiteLLM (#108), the H-1 Ruff ratchet (#106 #107 #109 #111 #113),
the L-4 CI shell-precedence fix (#112), the spec-drift validator
broadening + GOV-009 Snyk declarations (#114), and a CONTRIBUTING.md
accuracy pass (#115).

Adds a compliance-audit closure table mirroring the running scoreboard
in TODO.md, scoped to what shipped — outstanding items (H-3 mypy,
H-4 GOV-006, M-2 RFC template, M-4 lock file) listed below the table
as remaining work for v2.5.x.

Targets v2.5.0 release.
rolandpg added a commit that referenced this pull request Apr 25, 2026
… work (#116)

The [Unreleased] section was empty since v2.4.3 cut. Captures
everything merged since: RFC-011 local LLM backend (#104), RFC-012
LiteLLM (#108), the H-1 Ruff ratchet (#106 #107 #109 #111 #113),
the L-4 CI shell-precedence fix (#112), the spec-drift validator
broadening + GOV-009 Snyk declarations (#114), and a CONTRIBUTING.md
accuracy pass (#115).

Adds a compliance-audit closure table mirroring the running scoreboard
in TODO.md, scoped to what shipped — outstanding items (H-3 mypy,
H-4 GOV-006, M-2 RFC template, M-4 lock file) listed below the table
as remaining work for v2.5.x.

Targets v2.5.0 release.
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