Skip to content

Refactor regex construction#137

Closed
leynos wants to merge 2 commits intomainfrom
codex/replace-unwrap-with-expect-for-regex
Closed

Refactor regex construction#137
leynos wants to merge 2 commits intomainfrom
codex/replace-unwrap-with-expect-for-regex

Conversation

@leynos
Copy link
Copy Markdown
Owner

@leynos leynos commented Jul 29, 2025

Summary

  • use expect rather than unwrap when constructing regexes
  • keep clippy clean

Testing

  • make lint
  • make test

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

Summary by Sourcery

Refactor regex construction by replacing unwrap calls with expect and descriptive panic messages, and harmonize lazy_static regex initializers for improved safety and clippy compliance.

Enhancements:

  • Replace unwrap() with expect() and descriptive error messages for all lazy-initialized regexes
  • Standardize regex initialization closures across multiple modules for consistency

@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented Jul 29, 2025

Reviewer's Guide

Refactors all regex initializations to use expect with descriptive messages instead of unwrap, and adjusts closure formatting to satisfy clippy linting.

Class diagram for updated regex initialization patterns

classDiagram
    class LazyLock~Regex~ {
        +new(fn() -> Regex)
    }
    class Regex {
        +new(pattern: &str) Result<Regex, Error>
    }
    class Error

    LazyLock~Regex~ o-- Regex
    Regex --> Error : Result

    %% Example static usage
    class FENCE_RE {
        <<static>>
        +Regex
    }
    class BULLET_RE {
        <<static>>
        +Regex
    }
    class FOOTNOTE_RE {
        <<static>>
        +Regex
    }
    class BLOCKQUOTE_RE {
        <<static>>
        +Regex
    }
    class TABLE_START_RE {
        <<static>>
        +Regex
    }
    class TABLE_END_RE {
        <<static>>
        +Regex
    }
    class DOT_RE {
        <<static>>
        +Regex
    }
    class SENTINEL_RE {
        <<static>>
        +Regex
    }
    class SEP_RE {
        <<static>>
        +Regex
    }

    FENCE_RE --|> LazyLock~Regex~
    BULLET_RE --|> LazyLock~Regex~
    FOOTNOTE_RE --|> LazyLock~Regex~
    BLOCKQUOTE_RE --|> LazyLock~Regex~
    TABLE_START_RE --|> LazyLock~Regex~
    TABLE_END_RE --|> LazyLock~Regex~
    DOT_RE --|> LazyLock~Regex~
    SENTINEL_RE --|> LazyLock~Regex~
    SEP_RE --|> LazyLock~Regex~

    %% Note: All statics now use expect() instead of unwrap() for error handling
Loading

File-Level Changes

Change Details Files
Replace unwrap with expect in regex initializers and reformat closures
  • Replaced all Regex::new(...).unwrap() calls with expect("")
  • Converted single-line lazy initializations into block closures for multi-line expect invocations
src/wrap.rs
src/fences.rs
src/html.rs
src/ellipsis.rs
src/reflow.rs
src/table.rs

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

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jul 29, 2025

Summary by CodeRabbit

  • Refactor

    • Simplified initialisation of regular expressions across multiple modules by introducing and using a new macro for lazy regex compilation.
    • Improved code consistency and readability by replacing manual lazy initialisation with macro-based declarations.
    • Enhanced documentation comments in one module for better integration with Rust tooling.
  • New Features

    • Added a reusable macro for concise and safe lazy regex initialisation.
  • Documentation

    • Updated module-level documentation for improved clarity.

Walkthrough

Refactor the lazy initialisation of static regex variables across multiple modules by introducing and applying a new lazy_regex! macro. Replace manual LazyLock initialisation with macro invocations, standardising error messaging and simplifying code. Add the macro module to the crate root, and update relevant imports and documentation comments.

Changes

Cohort / File(s) Change Summary
Macro Introduction
src/macros.rs
Add lazy_regex macro for concise, safe, lazy regex initialisation with custom error messages.
Macro Import in Crate Root
src/lib.rs
Add #[macro_use] mod macros; to enable crate-wide macro usage.
Breaks Regex Refactor
src/breaks.rs
Replace manual LazyLock regex initialisation with lazy_regex! macro for THEMATIC_BREAK_RE.
Ellipsis Regex Refactor
src/ellipsis.rs
Use lazy_regex! macro for DOT_RE static regex; add explicit LazyLock import.
Fences Regex Refactor
src/fences.rs
Convert FENCE_RE and ORPHAN_LANG_RE to use lazy_regex! macro.
Footnotes Regex Refactor
src/footnotes.rs
Refactor INLINE_FN_RE and FOOTNOTE_LINE_RE to use lazy_regex! macro; add explicit import.
HTML Regex Refactor
src/html.rs
Switch TABLE_START_RE and TABLE_END_RE to macro-based initialisation.
Lists Regex Refactor
src/lists.rs
Migrate HEADING_RE and NUMBERED_RE to lazy_regex! macro; add explicit import.
Reflow Regex and Docs Update
src/reflow.rs
Update file docs to //!; switch SENTINEL_RE to macro initialisation; add explicit import.
Table Regex Refactor
src/table.rs
Change SEP_RE to use lazy_regex! macro for initialisation.
Wrap Regex Refactor
src/wrap.rs
Refactor FENCE_RE, BULLET_RE, FOOTNOTE_RE, BLOCKQUOTE_RE to use lazy_regex! macro.

Sequence Diagram(s)

sequenceDiagram
    participant CallSite as Any Module
    participant Macro as lazy_regex! Macro
    participant LazyLock as LazyLock<Regex>
    participant Regex as Regex Engine

    CallSite->>Macro: Invoke lazy_regex!(pattern, message)
    Macro->>LazyLock: Create LazyLock with Regex::new(pattern)
    LazyLock->>Regex: Compile pattern on first access
    Regex-->>LazyLock: Return Regex or panic with message
    LazyLock-->>CallSite: Provide Regex reference
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

Poem

Regexes now sleep until needed,
With macros their births are conceded.
No more closures to write,
Just patterns in sight—
And errors explained if mis-seeded!

🦀✨

✨ 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/replace-unwrap-with-expect-for-regex

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey @leynos - I've reviewed your changes - here's some feedback:

  • Most of the diffs repeat the same LazyLock::new(|| Regex::new(...).expect(...)) pattern—consider extracting that into a small helper or macro to cut down on boilerplate.
  • You’re fully qualifying std::sync::LazyLock in every file; importing LazyLock at the top of each module (or using a common prelude) would make the initializations more concise.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Most of the diffs repeat the same LazyLock::new(|| Regex::new(...).expect(...)) pattern—consider extracting that into a small helper or macro to cut down on boilerplate.
- You’re fully qualifying std::sync::LazyLock in every file; importing LazyLock at the top of each module (or using a common prelude) would make the initializations more concise.

## Individual Comments

### Comment 1
<location> `src/wrap.rs:24` </location>
<code_context>
+    Regex::new(r"^(\s*(?:>\s*)+)(.*)$").expect("valid blockquote regex")
+});

 /// Markdown token emitted by [`tokenize_markdown`].
 #[derive(Debug, PartialEq)]
--- a/src/fences.rs
</code_context>

<issue_to_address>
The module does not begin with a `//!` comment as required.

Please add a `//!` module-level comment at the very top of the file to describe its purpose, as per the review instructions.
</issue_to_address>

### Comment 2
<location> `src/fences.rs:20` </location>
<code_context>
+        .expect("valid language regex")
 });

 /// Normalise a potential language specifier.
--- a/src/html.rs
+++ b/src/html.rs
</code_context>

<issue_to_address>
The module does not begin with a `//!` comment as required.

Please add a `//!` module-level comment at the very top of the file to describe its purpose, as per the review instructions.
</issue_to_address>

### Comment 3
<location> `src/html.rs:17` </location>
<code_context>

 /// Matches the start of an HTML `<table>` tag, ignoring case.
 static TABLE_START_RE: LazyLock<Regex> =
-    LazyLock::new(|| Regex::new(r"(?i)^<table(?:\s|>|$)").unwrap());
</code_context>

<issue_to_address>
The module does not begin with a `//!` comment as required.

Please add a `//!` module-level comment at the very top of the file to describe its purpose, as per the review instructions.
</issue_to_address>

### Comment 4
<location> `src/ellipsis.rs:15` </location>
<code_context>
-    std::sync::LazyLock::new(|| Regex::new(r"\.{3,}").unwrap());
+    std::sync::LazyLock::new(|| Regex::new(r"\.{3,}").expect("valid dot regex"));

 /// Replace `...` with `` outside code spans and fences.
 #[must_use]
--- a/src/reflow.rs
</code_context>

<issue_to_address>
The module does not begin with a `//!` comment as required.

Please add a `//!` module-level comment at the very top of the file to describe its purpose, as per the review instructions.
</issue_to_address>

### Comment 5
<location> `src/reflow.rs:13` </location>
<code_context>
-    std::sync::LazyLock::new(|| Regex::new(r"\|\s*\|\s*").unwrap());
+    std::sync::LazyLock::new(|| Regex::new(r"\|\s*\|\s*").expect("valid sentinel regex"));

 pub(crate) fn parse_rows(trimmed: &[String]) -> (Vec<Vec<String>>, bool) {
     let raw = trimmed.join(" ");
--- a/src/table.rs
</code_context>

<issue_to_address>
The module does not begin with a `//!` comment as required.

Please add a `//!` module-level comment at the very top of the file to describe its purpose, as per the review instructions.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread src/wrap.rs
Comment thread src/fences.rs
Comment thread src/html.rs
Comment thread src/ellipsis.rs
Comment thread src/reflow.rs
@leynos
Copy link
Copy Markdown
Owner Author

leynos commented Jul 29, 2025

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jul 29, 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.

@leynos
Copy link
Copy Markdown
Owner Author

leynos commented Jul 29, 2025

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jul 29, 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: 5

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 35b50b8 and be80b5e.

📒 Files selected for processing (11)
  • src/breaks.rs (1 hunks)
  • src/ellipsis.rs (1 hunks)
  • src/fences.rs (1 hunks)
  • src/footnotes.rs (1 hunks)
  • src/html.rs (1 hunks)
  • src/lib.rs (1 hunks)
  • src/lists.rs (2 hunks)
  • src/macros.rs (1 hunks)
  • src/reflow.rs (1 hunks)
  • src/table.rs (2 hunks)
  • src/wrap.rs (1 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.
  • 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.

Files:

  • src/macros.rs
  • src/footnotes.rs
  • src/reflow.rs
  • src/ellipsis.rs
  • src/breaks.rs
  • src/lib.rs
  • src/fences.rs
  • src/lists.rs
  • src/table.rs
  • src/wrap.rs
  • src/html.rs
🧬 Code Graph Analysis (3)
src/reflow.rs (1)
src/table.rs (2)
  • format_separator_cells (49-73)
  • split_cells (16-47)
src/ellipsis.rs (1)
src/wrap.rs (1)
  • tokenize_markdown (141-178)
src/breaks.rs (1)
src/wrap.rs (1)
  • is_fence (259-259)
🔇 Additional comments (24)
src/lib.rs (1)

15-16: LGTM! Clean macro module addition.

The #[macro_use] attribute correctly enables the lazy_regex! macro throughout the crate. The placement after documentation and before other modules follows standard conventions.

src/ellipsis.rs (1)

8-8: LGTM! Import addition supports type annotation.

The explicit LazyLock import is necessary for the type annotation in the static declaration.

src/footnotes.rs (1)

7-7: LGTM! Import addition supports type annotations.

The explicit LazyLock import is necessary for the type annotations in the static declarations.

src/macros.rs (3)

1-2: LGTM! Proper module documentation.

The module documentation clearly explains its purpose and follows the coding guideline requirement for //! comments.


3-13: LGTM! Comprehensive macro documentation.

The documentation includes a clear example showing usage with LazyLock type annotation and demonstrates testing the regex. This follows Rust documentation best practices.


14-19: LGTM! Well-implemented macro solution.

The macro perfectly addresses the PR objectives by:

  • Replacing unwrap() with expect() for better error handling
  • Standardising lazy regex initialization across the codebase
  • Enabling descriptive panic messages
  • Following Rust macro conventions with #[macro_export]

The implementation is clean, concise, and type-safe.

src/fences.rs (2)

11-14: LGTM: Clean macro-based regex initialization.

The lazy_regex! macro usage correctly replaces the manual LazyLock initialization whilst preserving the original regex pattern and providing a descriptive error message.


16-19: LGTM: Consistent regex initialization pattern.

The macro usage follows the same pattern as FENCE_RE with an appropriate descriptive error message for the language regex.

src/wrap.rs (5)

7-8: LGTM: Necessary import addition.

The explicit LazyLock import is required since the type is still used in the static variable declarations.


11-11: LGTM: Clean fence regex initialization.

The lazy_regex! macro usage correctly replaces manual initialization with a descriptive error message.


13-14: LGTM: Consistent bullet regex pattern.

Good use of the macro with descriptive error messaging. The trailing comma is acceptable Rust style.


16-17: LGTM: Proper footnote regex initialization.

The macro usage follows the established pattern with appropriate error messaging.


19-20: LGTM: Blockquote regex follows pattern.

Consistent with the other regex initializations and includes a descriptive error message.

src/lists.rs (3)

3-4: LGTM: Required import for LazyLock type.

The explicit import is necessary since LazyLock is still used in the type annotations.


14-14: LGTM: Heading regex uses consistent pattern.

The lazy_regex! macro correctly replaces manual initialization with a descriptive error message.


17-18: LGTM: Function-scoped regex initialization.

The macro usage is correct for the function-scoped static variable with appropriate error messaging.

src/reflow.rs (3)

1-5: LGTM: Proper module documentation.

The conversion to //! doc comments correctly follows Rust documentation conventions and resolves the previous review feedback.


6-6: LGTM: Required LazyLock import.

The explicit import is necessary for the type annotation in the static declaration.


12-12: LGTM: Sentinel regex follows established pattern.

The lazy_regex! macro usage is consistent with other files and includes a descriptive error message.

src/breaks.rs (3)

3-3: LGTM: Clean import consolidation.

Adding LazyLock to the import allows for cleaner usage without fully qualified paths.


11-14: LGTM: Thematic break regex follows pattern.

The lazy_regex! macro usage correctly replaces manual initialization whilst preserving the complex regex pattern and providing a descriptive error message.


16-16: LGTM: Cleaner LazyLock usage.

Using the imported LazyLock instead of the fully qualified path improves readability.

src/table.rs (2)

7-7: LGTM!

The LazyLock import remains necessary for the type annotation, even with the macro-based initialisation.


94-94: Excellent refactoring that improves consistency and error handling.

The migration to the lazy_regex! macro provides better error messaging and standardises regex initialisation across the codebase. The descriptive error message "valid separator regex" will aid debugging if the regex compilation fails.

Comment thread src/ellipsis.rs

static DOT_RE: std::sync::LazyLock<Regex> =
std::sync::LazyLock::new(|| Regex::new(r"\.{3,}").unwrap());
static DOT_RE: LazyLock<Regex> = lazy_regex!(r"\.{3,}", "valid dot regex");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Improve error message specificity.

Replace the generic "valid dot regex" with a more descriptive message that explains the regex's purpose.

-static DOT_RE: LazyLock<Regex> = lazy_regex!(r"\.{3,}", "valid dot regex");
+static DOT_RE: LazyLock<Regex> = lazy_regex!(r"\.{3,}", "ellipsis pattern regex should compile");
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
static DOT_RE: LazyLock<Regex> = lazy_regex!(r"\.{3,}", "valid dot regex");
-static DOT_RE: LazyLock<Regex> = lazy_regex!(r"\.{3,}", "valid dot regex");
+static DOT_RE: LazyLock<Regex> = lazy_regex!(r"\.{3,}", "ellipsis pattern regex should compile");
🤖 Prompt for AI Agents
In src/ellipsis.rs at line 14, the static regex DOT_RE uses a generic
description "valid dot regex" in the lazy_regex macro. Replace this string with
a more descriptive message that clearly explains the regex's purpose, such as
indicating it matches sequences of three or more dots, to improve error message
clarity.

Comment thread src/footnotes.rs
Comment on lines +11 to +14
static INLINE_FN_RE: LazyLock<Regex> = lazy_regex!(
r"(?P<pre>^|[^0-9])(?P<punc>[.!?);:])(?P<style>[*_]*)(?P<num>\d+)(?P<boundary>\s|$)",
"valid inline footnote regex",
);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Improve error message specificity.

Replace the generic error message with one that describes the regex's purpose.

 static INLINE_FN_RE: LazyLock<Regex> = lazy_regex!(
     r"(?P<pre>^|[^0-9])(?P<punc>[.!?);:])(?P<style>[*_]*)(?P<num>\d+)(?P<boundary>\s|$)",
-    "valid inline footnote regex",
+    "inline footnote reference pattern should compile",
 );
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
static INLINE_FN_RE: LazyLock<Regex> = lazy_regex!(
r"(?P<pre>^|[^0-9])(?P<punc>[.!?);:])(?P<style>[*_]*)(?P<num>\d+)(?P<boundary>\s|$)",
"valid inline footnote regex",
);
static INLINE_FN_RE: LazyLock<Regex> = lazy_regex!(
r"(?P<pre>^|[^0-9])(?P<punc>[.!?);:])(?P<style>[*_]*)(?P<num>\d+)(?P<boundary>\s|$)",
"inline footnote reference pattern should compile",
);
🤖 Prompt for AI Agents
In src/footnotes.rs around lines 11 to 14, the error message for the regex
initialization is generic. Update the error message string to specifically
describe the regex's purpose, such as indicating it is for matching valid inline
footnotes, to improve clarity when errors occur.

Comment thread src/footnotes.rs
Comment on lines +16 to +19
static FOOTNOTE_LINE_RE: LazyLock<Regex> = lazy_regex!(
r"^(?P<indent>\s*)(?P<num>\d+)\.\s+(?P<rest>.*)$",
"valid footnote line regex",
);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Improve error message specificity.

Replace the generic error message with one that describes the regex's purpose.

 static FOOTNOTE_LINE_RE: LazyLock<Regex> = lazy_regex!(
     r"^(?P<indent>\s*)(?P<num>\d+)\.\s+(?P<rest>.*)$",
-    "valid footnote line regex",
+    "footnote line pattern should compile",
 );
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
static FOOTNOTE_LINE_RE: LazyLock<Regex> = lazy_regex!(
r"^(?P<indent>\s*)(?P<num>\d+)\.\s+(?P<rest>.*)$",
"valid footnote line regex",
);
static FOOTNOTE_LINE_RE: LazyLock<Regex> = lazy_regex!(
r"^(?P<indent>\s*)(?P<num>\d+)\.\s+(?P<rest>.*)$",
- "valid footnote line regex",
+ "footnote line pattern should compile",
);
🤖 Prompt for AI Agents
In src/footnotes.rs around lines 16 to 19, the error message for the
FOOTNOTE_LINE_RE regex is generic. Update the error message string to
specifically describe that this regex matches a valid footnote line, including
details like indentation, footnote number, and the rest of the line, to improve
clarity and debugging.

Comment thread src/html.rs
/// Matches the start of an HTML `<table>` tag, ignoring case.
static TABLE_START_RE: LazyLock<Regex> =
LazyLock::new(|| Regex::new(r"(?i)^<table(?:\s|>|$)").unwrap());
lazy_regex!(r"(?i)^<table(?:\s|>|$)", "valid table start regex");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Improve error message specificity.

Replace the generic error message with one that describes the regex's purpose.

 static TABLE_START_RE: LazyLock<Regex> =
-    lazy_regex!(r"(?i)^<table(?:\s|>|$)", "valid table start regex");
+    lazy_regex!(r"(?i)^<table(?:\s|>|$)", "HTML table start pattern should compile");
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
lazy_regex!(r"(?i)^<table(?:\s|>|$)", "valid table start regex");
static TABLE_START_RE: LazyLock<Regex> =
lazy_regex!(r"(?i)^<table(?:\s|>|$)", "HTML table start pattern should compile");
🤖 Prompt for AI Agents
In src/html.rs at line 19, the lazy_regex macro uses a generic error message
"valid table start regex". Replace this message with a more descriptive one that
clearly states the regex is intended to match the start of a table tag in HTML,
improving clarity and maintainability.

Comment thread src/html.rs
lazy_regex!(r"(?i)^<table(?:\s|>|$)", "valid table start regex");
/// Matches the end of an HTML `</table>` tag, ignoring case.
static TABLE_END_RE: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"(?i)</table>").unwrap());
static TABLE_END_RE: LazyLock<Regex> = lazy_regex!(r"(?i)</table>", "valid table end regex");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Improve error message specificity.

Replace the generic error message with one that describes the regex's purpose.

-static TABLE_END_RE: LazyLock<Regex> = lazy_regex!(r"(?i)</table>", "valid table end regex");
+static TABLE_END_RE: LazyLock<Regex> = lazy_regex!(r"(?i)</table>", "HTML table end pattern should compile");
🤖 Prompt for AI Agents
In src/html.rs at line 21, the error message for the TABLE_END_RE regex is too
generic. Update the error message string to clearly describe the regex's
purpose, such as indicating it matches the closing table tag in a
case-insensitive manner, to improve clarity and debugging.

@leynos
Copy link
Copy Markdown
Owner Author

leynos commented Jul 29, 2025

Superseded by #144

@leynos leynos closed this Jul 29, 2025
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.

1 participant