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:
@@ -87,6 +87,10 @@ func Default() *Config {
|
||||
"@generated",
|
||||
"DO NOT EDIT",
|
||||
`/^#\s*v\d+(\.\d+)*$/`,
|
||||
`/^\/\*\*/`,
|
||||
`/^\/\*!/`,
|
||||
`/^\/\/\//`,
|
||||
`/^\/\/!/`,
|
||||
},
|
||||
ContextLines: 3,
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user