Extract shared is_valid_class_name to beamtalk-core#2820
Merged
Conversation
validate_class_name was duplicated between beamtalk-lsp and beamtalk-mcp with slightly diverging logic. Extract the canonical boolean check to beamtalk_core::source_analysis::is_valid_class_name so the rule lives once in the right bounded context. Both crates keep their own error types and messages; they delegate the structural check to the shared function.
✅ Claude Review — PASSReview SummaryOverall: PASS — clean refactoring, no issues. This PR extracts the class-name validation predicate into CorrectnessThe invariant claimed by the
No panic is reachable at runtime. Existing LSP tests ( The MCP simplification is equivalent to the previous three-condition check. Behavior is preserved across both surfaces. BlockersNone. SuggestionsNone. NitsNone. |
After the three exhaustive checks (empty / not-uppercase / bad-char), the terminal Err could never fire. Replace the if-let with an unwrap() that is guaranteed to succeed at that point, eliminating the dead branch.
Addresses review nit: the bad-char search is safe today but silently forward-couples on is_valid_class_name's exact conditions. Use .expect() to name the invariant so a future added condition surfaces a clear panic message rather than a bare unwrap on a should-be-validation path. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015RFHaym8aCseDmmZ417jn2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
validate_class_namewas duplicated betweenbeamtalk-lspandbeamtalk-mcpwith slightly diverging implementations. This PR extracts the canonical boolean check tobeamtalk_core::source_analysis::is_valid_class_nameso the naming rule lives once in the correct DDD bounded context (Source Analysis → Language Service).Changes
crates/beamtalk-core/src/source_analysis/mod.rs: Addpub fn is_valid_class_name(name: &str) -> bool— non-empty, starts with ASCII uppercase, all chars alphanumeric or_. Includes 5 unit tests.crates/beamtalk-lsp/src/server.rs:validate_class_namedelegates the structural check tois_valid_class_name; keeps its detailed per-character error messages for the LSPResult<(), String>type.crates/beamtalk-mcp/src/server.rs:validate_class_namedelegates directly tois_valid_class_name; keeps itsrmcp::ErrorDataerror type.No behaviour change — both implementations agreed on which names are valid. No new crate dependencies (both LSP and MCP already depend on beamtalk-core).
Generated by Claude Code