Skip to content

fix(npm): remove extra quotes in code action version replacements#29

Merged
bug-ops merged 2 commits intomainfrom
fix/npm-code-action-quotes
Dec 24, 2025
Merged

fix(npm): remove extra quotes in code action version replacements#29
bug-ops merged 2 commits intomainfrom
fix/npm-code-action-quotes

Conversation

@bug-ops
Copy link
Owner

@bug-ops bug-ops commented Dec 24, 2025

Summary

Fixes a bug where code actions in package.json were adding duplicate quotes around version strings, resulting in malformed JSON like:

"typescript": ""6.0.0"",

Instead of:

"typescript": "6.0.0",

Root Cause

The npm parser creates version_range positions 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_edit spans 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

  • All 378 workspace tests pass
  • Manual testing confirms code actions produce valid JSON

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.
@github-actions github-actions bot added rust Rust code changes needs-review Needs review size: XS <10 lines changed labels Dec 24, 2025
@github-actions github-actions bot added size: S 10-50 lines changed and removed size: XS <10 lines changed labels Dec 24, 2025
@codecov-commenter
Copy link

codecov-commenter commented Dec 24, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.

Impacted file tree graph

@@            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              
Flag Coverage Δ
deps-cargo 78.00% <ø> (ø)
deps-core 89.34% <ø> (ø)
deps-lsp 78.00% <ø> (ø)
deps-npm 88.71% <100.00%> (-0.01%) ⬇️
deps-pypi 85.94% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
crates/deps-npm/src/formatter.rs 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@bug-ops bug-ops merged commit d5823be into main Dec 24, 2025
20 checks passed
@bug-ops bug-ops deleted the fix/npm-code-action-quotes branch December 24, 2025 00:51
@bug-ops bug-ops mentioned this pull request Dec 24, 2025
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-review Needs review rust Rust code changes size: S 10-50 lines changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants