Skip to content

Commit d5823be

Browse files
authored
fix(npm): remove extra quotes in code action version replacements (#29)
* fix(npm): remove extra quotes in code action version replacements 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. * style: fix formatting in npm formatter tests
1 parent 262df87 commit d5823be

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

crates/deps-npm/src/formatter.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ pub struct NpmFormatter;
44

55
impl EcosystemFormatter for NpmFormatter {
66
fn format_version_for_code_action(&self, version: &str) -> String {
7-
format!("\"{}\"", version)
7+
// Don't add quotes - version_range already excludes them from parser
8+
version.to_string()
89
}
910

1011
fn package_url(&self, name: &str) -> String {
@@ -41,14 +42,12 @@ mod tests {
4142
#[test]
4243
fn test_format_version() {
4344
let formatter = NpmFormatter;
45+
// Version should not include quotes - parser's version_range excludes them
4446
assert_eq!(
4547
formatter.format_version_for_code_action("1.0.214"),
46-
"\"1.0.214\""
47-
);
48-
assert_eq!(
49-
formatter.format_version_for_code_action("18.3.1"),
50-
"\"18.3.1\""
48+
"1.0.214"
5149
);
50+
assert_eq!(formatter.format_version_for_code_action("18.3.1"), "18.3.1");
5251
}
5352

5453
#[test]

0 commit comments

Comments
 (0)