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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,6 +87,8 @@ func TestMultiline(t *testing.T) {
|
||||
multilineCase{name: "marker in line comment", file: "marker_in_line.c"},
|
||||
multilineCase{name: "unterminated", file: "unterminated.c"},
|
||||
multilineCase{name: "conf fallback", file: "fallback.conf"},
|
||||
multilineCase{name: "doc comments js", file: "doc_js.js"},
|
||||
multilineCase{name: "doc comments rust", file: "doc_rs.rs"},
|
||||
multilineCase{name: "git straddle kept", file: "straddle.js",
|
||||
gitMode: true, ranges: []git.LineRange{{Start: 4, End: 4}}},
|
||||
multilineCase{name: "git range removes inside block", file: "range_inside.js",
|
||||
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
/**
|
||||
* Adds two numbers.
|
||||
* @param {number} a
|
||||
* @param {number} b
|
||||
* @returns {number}
|
||||
*/
|
||||
function add(a, b) {
|
||||
/*
|
||||
* plain block comment
|
||||
*/
|
||||
return a + b; // plain line comment
|
||||
}
|
||||
|
||||
/*! license banner */
|
||||
/** single-line doc */
|
||||
function noop() {}
|
||||
@@ -0,0 +1,13 @@
|
||||
/**
|
||||
* Adds two numbers.
|
||||
* @param {number} a
|
||||
* @param {number} b
|
||||
* @returns {number}
|
||||
*/
|
||||
function add(a, b) {
|
||||
return a + b;
|
||||
}
|
||||
|
||||
/*! license banner */
|
||||
/** single-line doc */
|
||||
function noop() {}
|
||||
@@ -0,0 +1,9 @@
|
||||
//! Crate-level docs.
|
||||
|
||||
/// Adds two numbers.
|
||||
/// Returns the sum.
|
||||
pub fn add(a: i32, b: i32) -> i32 {
|
||||
// plain line comment
|
||||
/* plain block comment */
|
||||
a + b
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
//! Crate-level docs.
|
||||
|
||||
/// Adds two numbers.
|
||||
/// Returns the sum.
|
||||
pub fn add(a: i32, b: i32) -> i32 {
|
||||
a + b
|
||||
}
|
||||
Reference in New Issue
Block a user