-
Notifications
You must be signed in to change notification settings - Fork 0
URL and case rules fix #29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. WalkthroughThis PR extends the case-rule system to support alternative term variations by adding an Changes
Sequence DiagramsequenceDiagram
participant Caller
participant Determiner
participant RangeBuilder
participant RuleChecker
participant Validator
Caller->>Determiner: checkSpelling(content)
activate Determiner
Determiner->>RangeBuilder: `#buildExcludedRanges`(content)
activate RangeBuilder
RangeBuilder->>RangeBuilder: `#addMatchedRanges` (URLs)
RangeBuilder->>RangeBuilder: `#addPathRanges`
RangeBuilder->>RangeBuilder: `#addCodeBlockRanges`
RangeBuilder->>RangeBuilder: `#mergeRanges`
RangeBuilder-->>Determiner: excludedRanges[]
deactivate RangeBuilder
Determiner->>Determiner: `#getSanitizedContent` (remove excluded)
Determiner->>Determiner: `#createIsExcludedChecker`
rect rgb(220, 240, 255)
Note over Determiner,RuleChecker: Check General Rules
Determiner->>RuleChecker: `#checkGeneralRules`(sanitized, isExcluded)
RuleChecker->>Validator: validate matches not in excluded ranges
Validator-->>RuleChecker: mistakes[]
RuleChecker-->>Determiner: generalMistakes[]
end
rect rgb(220, 240, 255)
Note over Determiner,RuleChecker: Check Case Rules
Determiner->>RuleChecker: `#checkCaseRules`(sanitized, isExcluded)
RuleChecker->>Validator: validate term + alternatives in excluded ranges
Validator-->>RuleChecker: mistakes[]
RuleChecker-->>Determiner: caseMistakes[]
end
Determiner->>Determiner: merge all mistakes
Determiner-->>Caller: mistakes[]
deactivate Determiner
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes
Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches✅ Passed checks (4 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (8)
🧰 Additional context used🧠 Learnings (1)📚 Learning: 2025-10-31T12:45:58.617ZApplied to files:
🧬 Code graph analysis (2)determiner.test.ts (2)
determiner.ts (2)
🪛 ast-grep (0.39.7)determiner.ts[warning] 56-56: Regular expression constructed from variable input detected. This can lead to Regular Expression Denial of Service (ReDoS) attacks if the variable contains malicious patterns. Use libraries like 'recheck' to validate regex safety or use static patterns. (regexp-from-variable) [warning] 211-211: Regular expression constructed from variable input detected. This can lead to Regular Expression Denial of Service (ReDoS) attacks if the variable contains malicious patterns. Use libraries like 'recheck' to validate regex safety or use static patterns. (regexp-from-variable) [warning] 216-216: Regular expression constructed from variable input detected. This can lead to Regular Expression Denial of Service (ReDoS) attacks if the variable contains malicious patterns. Use libraries like 'recheck' to validate regex safety or use static patterns. (regexp-from-variable) [warning] 247-247: Regular expression constructed from variable input detected. This can lead to Regular Expression Denial of Service (ReDoS) attacks if the variable contains malicious patterns. Use libraries like 'recheck' to validate regex safety or use static patterns. (regexp-from-variable) 🔇 Additional comments (21)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds support for alternative case forms in case rules and refactors the spell-checking logic. The main changes include:
- Adding an
alternativesfield toCaseRuleto allow multiple valid case forms (e.g., "JavaScript" can also be "javascript") - Refactoring the
Determinerclass to use a more modular approach with separate methods for building excluded ranges, checking general rules, and checking case rules - Improving URL detection to use a more comprehensive regex pattern that covers various URL schemes (not just http/https)
- Adding comprehensive test coverage for the new alternatives feature and URL/path exclusion logic
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| models.ts | Adds alternatives field to CaseRule interface and schema with validation |
| determiner.ts | Refactors spell-checking logic into modular methods and improves URL regex to support multiple schemes |
| determiner.test.ts | Adds comprehensive test coverage for alternatives feature and URL/path exclusion scenarios |
| database.ts | Updates addRule method to accept alternatives parameter |
| database-test-utils.ts | Updates mock database to support alternatives parameter |
| database-interfaces.ts | Updates interface definition to include alternatives parameter |
| README.md | Updates documentation with correct repository URLs, adds shell syntax highlighting, documents alternatives feature, removes duplicate setup instructions |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
determiner.ts
Outdated
|
|
||
| // https://datatracker.ietf.org/doc/html/rfc1738#section-2.1 | ||
| // https://datatracker.ietf.org/doc/html/rfc1738#section-3.1 | ||
| #URL_REGEX = /[a-zA-Z0-9+.-]*:\/\/[^\s]+/g; |
Copilot
AI
Oct 31, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The URL regex is defined as a class property with the g flag, which makes it stateful. When reused multiple times (as in lines 57 and 98), the regex's lastIndex property won't reset between different strings, causing unpredictable matching behavior. This is a common bug with shared regex instances. Either remove the g flag and create new regex instances when needed, or reset lastIndex before each use.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot open a new pull request to apply changes based on this feedback
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Yi-Jyun Pan <me@pan93.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 7 out of 8 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This pull request introduces enhancements to the spelling and case rule detection logic, as well as improvements to documentation and database interfaces. The main focus is to support alternative case forms for terms, refine the exclusion logic for spellchecking, and clarify setup instructions.
Documentation improvements:
README.mdto use correct repository URLs, add shell/env block formatting, and clarify installation/startup steps. Redundant setup instructions were removed for clarity. [1] [2] [3]Appcan also be written asapp.Database and model changes:
CaseRuleinterface and schema now support an optionalalternativesfield (array of strings) for alternative case forms.ICaseDatabaseinterface and its implementations (CaseDatabase,MockCaseDatabase) soaddRuleaccepts an optionalalternativesparameter. [1] [2] [3]Spellchecking logic improvements:
Determinerclass indeterminer.tsto modularize and improve exclusion logic for URLs, paths, code blocks, and mentions. Added helper methods for building/merging exclusion ranges and for checking matches outside excluded ranges.I also resolved the case-checking issues evident in the CI. There should be no spelling or casing problems in this codebase now.
Minor dependency and import updates:
determiner.tsto include the newCaseRuletype.Fixed #26
Fixed https://discord.com/channels/1259032762422136902/1259032897373999144/1433821827364425758
Summary by CodeRabbit
New Features
Documentation
Tests