fix(npm): remove extra quotes in code action version replacements#29
Merged
fix(npm): remove extra quotes in code action version replacements#29
Conversation
When applying code actions to update package.json versions, the formatter was adding quotes around version strings. However, the parser's version_range already excludes quotes (it spans only the version text itself, not the surrounding JSON quotes). This caused double-quoting: Before: "typescript": "5.0.0" After: "typescript": ""6.0.0"" (WRONG) Root cause: NpmFormatter.format_version_for_code_action was adding quotes that already exist in the JSON structure. Fix: Return version string without quotes. The TextEdit replaces only the version content (not the quotes), so no additional quotes should be added. Cargo ecosystem is unaffected - toml_edit spans include quotes, so CargoFormatter correctly adds quotes when replacing the full span.
Codecov Report✅ All modified and coverable lines are covered by tests. @@ Coverage Diff @@
## main #29 +/- ##
==========================================
- Coverage 84.61% 84.61% -0.01%
==========================================
Files 42 42
Lines 9047 9046 -1
==========================================
- Hits 7655 7654 -1
Misses 1392 1392
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
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
Fixes a bug where code actions in
package.jsonwere adding duplicate quotes around version strings, resulting in malformed JSON like:Instead of:
Root Cause
The npm parser creates
version_rangepositions that exclude the JSON quotes - the range only spans the version text itself. However,NpmFormatter::format_version_for_code_action()was wrapping the version in quotes, causing double quotes when the TextEdit replaced the range.Fix
Changed
NpmFormatter::format_version_for_code_action()to return version strings without quotes, since the replacement range already excludes them.Why Cargo Is Unaffected
The Cargo ecosystem correctly adds quotes because
toml_editspans include the quotes as part of the string value. This is a fundamental difference between how TOML and JSON parsers handle string spans.Test plan