feat(config): preserve doc-style comments by default

Strip pass was eating JSDoc/Javadoc blocks. Add default preserve
patterns for /** blocks, /*! banners, /// and //! line docs.
Opt out by overriding preserve in .shush.toml.
This commit is contained in:
2026-07-08 13:24:29 -05:00
parent 272ce89ec5
commit 59c48a36cb
7 changed files with 80 additions and 0 deletions
+4
View File
@@ -87,6 +87,10 @@ func Default() *Config {
"@generated",
"DO NOT EDIT",
`/^#\s*v\d+(\.\d+)*$/`,
`/^\/\*\*/`,
`/^\/\*!/`,
`/^\/\/\//`,
`/^\/\/!/`,
},
ContextLines: 3,
}
+29
View File
@@ -85,3 +85,32 @@ func TestShouldPreserveVersionPins(t *testing.T) {
}
}
}
func TestShouldPreserveDocComments(t *testing.T) {
cfg := Default()
preserved := []string{
"/**\n * JSDoc block\n * @param x foo\n */",
"/** single-line doc */",
"/*! license banner */",
"/// Rust or C# doc comment",
"//! Rust inner doc comment",
}
for _, c := range preserved {
if !cfg.ShouldPreserveComment(c) {
t.Errorf("doc comment not preserved by default: %q", c)
}
}
stripped := []string{
"/* plain block comment */",
"// plain line comment",
"# hash comment",
"/*\n * multi-line non-doc block\n */",
}
for _, c := range stripped {
if cfg.ShouldPreserveComment(c) {
t.Errorf("non-doc comment wrongly preserved: %q", c)
}
}
}