Skip to content

Refine HTML tag predicates for clarity#209

Merged
leynos merged 2 commits intomainfrom
codex/extract-predicate-functions-from-conditionals
Sep 13, 2025
Merged

Refine HTML tag predicates for clarity#209
leynos merged 2 commits intomainfrom
codex/extract-predicate-functions-from-conditionals

Conversation

@leynos
Copy link
Copy Markdown
Owner

@leynos leynos commented Sep 11, 2025

Summary

  • simplify ignored HTML tag detection
  • streamline bold tag predicate

Testing

  • make fmt
  • make lint
  • make test

closes #49


https://chatgpt.com/codex/tasks/task_e_68c2b5cc5b908322ada77a0979cc5f0c

Summary by Sourcery

Refactor HTML tag predicate functions to use the matches! macro and lowercase conversion for clearer and more concise code

Enhancements:

  • Replace chained eq_ignore_ascii_case calls in is_ignored_tag with a single matches! construct
  • Simplify is_bold_tag by using matches! on lowercase tag strings

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Sep 11, 2025

Summary by CodeRabbit

  • Refactor
    • Simplified internal logic for detecting ignored and bold HTML elements to improve readability and maintainability.
    • Behaviour remains unchanged with no impact on output or functionality.
    • No changes to public APIs or user-facing features.

Walkthrough

Refactor internal HTML tag predicate helpers in src/html.rs: replace chained eq_ignore_ascii_case OR expressions with matches!(tag, t if t.eq_ignore_ascii_case(...)) for is_ignored_tag and is_bold_tag. Preserve function signatures and public APIs. No behavioural changes.

Changes

Cohort / File(s) Summary
HTML tag predicate refactor
src/html.rs
Replace chained tag.eq_ignore_ascii_case("...") OR expressions with `matches!(tag, t if t.eq_ignore_ascii_case("...")

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

Tidy checks in a single sweep,
Match the tags where secrets keep.
Strong or bold, ignored or seen,
Clean predicates keep code serene.
Small change, neat result — Rust stays keen.

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (4 passed)
Check name Status Explanation
Title Check ✅ Passed Accept the title "Refine HTML tag predicates for clarity" as it succinctly and accurately summarises the primary change: refactoring is_ignored_tag and is_bold_tag in src/html.rs to use matches! for clearer, case-insensitive checks.
Linked Issues Check ✅ Passed Confirm that the PR fulfils the coding objective from issue [#49] by extracting conditional logic into predicate functions: is_ignored_tag and is_bold_tag in src/html.rs now consolidate tag checks using matches! while preserving case-insensitive behaviour, directly addressing the rustfmt-induced readability problem.
Out of Scope Changes Check ✅ Passed Confirm that no out-of-scope changes were introduced: modifications are limited to internal predicate logic in src/html.rs, with no public signature changes or unrelated file edits observed.
Description Check ✅ Passed Accept the pull request description as related to the changeset; it summarises the refactor, lists the test commands, and references the issue closed (#49).
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch codex/extract-predicate-functions-from-conditionals

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e31dbea and b7ae942.

📒 Files selected for processing (1)
  • src/html.rs (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.rs

📄 CodeRabbit inference engine (AGENTS.md)

**/*.rs: Clippy warnings MUST be disallowed.
Fix any warnings emitted during tests in the code itself rather than silencing them.
Where a function is too long, extract meaningfully named helper functions adhering to separation of concerns and CQRS.
Where a function has too many parameters, group related parameters in meaningfully named structs.
Where a function is returning a large error consider using Arc to reduce the amount of data returned.
Every module must begin with a module level (//!) comment explaining the module's purpose and utility.
Document public APIs using Rustdoc comments (///) so documentation can be generated with cargo doc.
Prefer immutable data and avoid unnecessary mut bindings.
Handle errors with the Result type instead of panicking where feasible.
Avoid unsafe code unless absolutely necessary and document any usage clearly.
Place function attributes after doc comments.
Do not use return in single-line functions.
Use predicate functions for conditional criteria with more than two branches.
Lints must not be silenced except as a last resort.
Lint rule suppressions must be tightly scoped and include a clear reason.
Prefer expect over allow.
Prefer .expect() over .unwrap().
Use concat!() to combine long string literals rather than escaping newlines with a backslash.
Prefer semantic error enums: Derive std::error::Error (via the thiserror crate) for any condition the caller might inspect, retry, or map to an HTTP status.
Use an opaque error only at the app boundary: Use eyre::Report for human-readable logs; these should not be exposed in public APIs.
Never export the opaque type from a library: Convert to domain enums at API boundaries, and to eyre only in the main main() entrypoint or top-level async task.

Files:

  • src/html.rs

⚙️ CodeRabbit configuration file

**/*.rs: * Seek to keep the cyclomatic complexity of functions no more than 12.

  • Adhere to single responsibility and CQRS

  • Place function attributes after doc comments.

  • Do not use return in single-line functions.

  • Move conditionals with >2 branches into a predicate function.

  • Avoid unsafe unless absolutely necessary.

  • Every module must begin with a //! doc comment that explains the module's purpose and utility.

  • Comments and docs must follow en-GB-oxendict (-ize / -our) spelling and grammar

  • Lints must not be silenced except as a last resort.

    • #[allow] is forbidden.
    • Only narrowly scoped #[expect(lint, reason = "...")] is allowed.
    • No lint groups, no blanket or file-wide suppression.
    • Include FIXME: with link if a fix is expected.
  • Where code is only used by specific features, it must be conditionally compiled or a conditional expectation for unused_code applied.

  • Use rstest fixtures for shared setup and to avoid repetition between tests.

  • Replace duplicated tests with #[rstest(...)] parameterised cases.

  • Prefer mockall for mocks/stubs.

  • Prefer .expect() over .unwrap()

  • Ensure that any API or behavioural changes are reflected in the documentation in docs/

  • Ensure that any completed roadmap steps are recorded in the appropriate roadmap in docs/

  • Files must not exceed 400 lines in length

    • Large modules must be decomposed
    • Long match statements or dispatch tables should be decomposed by domain and collocated with targets
    • Large blocks of inline data (e.g., test fixtures, constants or templates) must be moved to external files and inlined at compile-time or loaded at run-time.
  • Environment access (env::set_var and env::remove_var) are always unsafe in Rust 2024 and MUST be marked as such

    • For testing of functionality depending upon environment variables, dependency injection and the mockable crate are the preferred option.
    • If mockable cannot be used, env mutations in tests ...

Files:

  • src/html.rs
🔇 Additional comments (2)
src/html.rs (2)

36-43: Adopt allocation-free case-insensitive checks; LGTM.

Use of a matches! guard with eq_ignore_ascii_case removes per-call lowercase allocation and keeps the predicate clear. No behavioural change.


115-118: Use non-alloc guard for bold tags; LGTM.

Match on a guard with eq_ignore_ascii_case for "strong" and "b" to stay allocation-free and readable.


Comment @coderabbitai help to get the list of available commands and usage tips.

@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented Sep 11, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Refactors HTML tag predicates by replacing repetitive eq_ignore_ascii_case chains with matches! over a single lowercase conversion, improving readability and consistency.

File-Level Changes

Change Details Files
Simplify ignored tag detection predicate
  • Replace multiple eq_ignore_ascii_case OR conditions with a single matches! macro
  • Convert tag to lowercase once before pattern matching
src/html.rs
Streamline bold tag predicate
  • Replace OR chain of eq_ignore_ascii_case with matches! macro
  • Apply the same lowercase conversion approach for consistency
src/html.rs

Assessment against linked issues

Issue Objective Addressed Explanation
#49 Improve readability of conditional expressions split across lines by rustfmt, specifically by extracting relevant conditionals as predicate functions.

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

sourcery-ai[bot]

This comment was marked as resolved.

@leynos
Copy link
Copy Markdown
Owner Author

leynos commented Sep 12, 2025

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Sep 12, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2e7a3dd and e31dbea.

📒 Files selected for processing (1)
  • src/html.rs (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.rs

⚙️ CodeRabbit configuration file

**/*.rs: * Seek to keep the cyclomatic complexity of functions no more than 12.

  • Adhere to single responsibility and CQRS

  • Place function attributes after doc comments.

  • Do not use return in single-line functions.

  • Move conditionals with >2 branches into a predicate function.

  • Avoid unsafe unless absolutely necessary.

  • Every module must begin with a //! doc comment that explains the module's purpose and utility.

  • Comments and docs must follow en-GB-oxendict (-ize / -our) spelling and grammar

  • Lints must not be silenced except as a last resort.

    • #[allow] is forbidden.
    • Only narrowly scoped #[expect(lint, reason = "...")] is allowed.
    • No lint groups, no blanket or file-wide suppression.
    • Include FIXME: with link if a fix is expected.
  • Where code is only used by specific features, it must be conditionally compiled or a conditional expectation for unused_code applied.

  • Use rstest fixtures for shared setup and to avoid repetition between tests.

  • Replace duplicated tests with #[rstest(...)] parameterised cases.

  • Prefer mockall for mocks/stubs.

  • Prefer .expect() over .unwrap()

  • Ensure that any API or behavioural changes are reflected in the documentation in docs/

  • Ensure that any completed roadmap steps are recorded in the appropriate roadmap in docs/

  • Files must not exceed 400 lines in length

    • Large modules must be decomposed
    • Long match statements or dispatch tables should be decomposed by domain and collocated with targets
    • Large blocks of inline data (e.g., test fixtures, constants or templates) must be moved to external files and inlined at compile-time or loaded at run-time.
  • Environment access (env::set_var and env::remove_var) are always unsafe in Rust 2024 and MUST be marked as such

    • For testing of functionality depending upon environment variables, dependency injection and the mockable crate are the preferred option.
    • If mockable cannot be used, env mutations in tests ...

Files:

  • src/html.rs
⏰ Context from checks skipped due to timeout of 120000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Sourcery review

Comment thread src/html.rs
Comment thread src/html.rs
@leynos leynos merged commit 2285211 into main Sep 13, 2025
3 checks passed
@leynos leynos deleted the codex/extract-predicate-functions-from-conditionals branch September 13, 2025 23:22
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.

Improve readability of conditional expressions split across lines by rustfmt

1 participant