@@ -30,9 +30,8 @@ pub fn check(cx: &LateContext<'_>, doc: &str, fragments: Fragments<'_>) {
30
30
}
31
31
}
32
32
33
+ /// If punctuation is missing, returns the offset where new punctuation should be inserted.
33
34
#[ must_use]
34
- /// If punctuation is missing, returns the docstring and the offset
35
- /// where new punctuation should be inserted.
36
35
fn is_missing_punctuation ( doc_string : & str ) -> Option < usize > {
37
36
const TERMINAL_PUNCTUATION_MARKS : & [ char ] = & [ '.' , '?' , '!' , '…' ] ;
38
37
@@ -65,22 +64,27 @@ fn is_missing_punctuation(doc_string: &str) -> Option<usize> {
65
64
Event :: InlineHtml ( _) | Event :: Start ( Tag :: Image { .. } ) | Event :: End ( TagEnd :: Image ) => {
66
65
text_offset = None ;
67
66
} ,
68
- Event :: Text ( ..) | Event :: Start ( Tag :: Link { .. } ) | Event :: End ( TagEnd :: Link )
69
- if no_report_depth == 0 && !offset. is_empty ( ) =>
70
- {
71
- text_offset = Some ( offset) ;
67
+ Event :: Start ( Tag :: Link { .. } ) | Event :: End ( TagEnd :: Link ) if no_report_depth == 0 && !offset. is_empty ( ) => {
68
+ text_offset = Some ( offset. end ) ;
69
+ } ,
70
+ Event :: Text ( ..) if no_report_depth == 0 && !offset. is_empty ( ) => {
71
+ if doc_string[ ..offset. end ] . trim_end ( ) . ends_with ( ')' ) {
72
+ text_offset = Some ( offset. end - 1 ) ;
73
+ } else {
74
+ text_offset = Some ( offset. end ) ;
75
+ }
72
76
} ,
73
77
_ => { } ,
74
78
}
75
79
}
76
80
77
81
let text_offset = text_offset?;
78
- if doc_string[ ..text_offset. end ]
79
- . trim_end_matches ( | c : char | c . is_whitespace ( ) || c == ')' || c == ']' || c == '}' )
82
+ if doc_string[ ..text_offset]
83
+ . trim_end ( )
80
84
. ends_with ( TERMINAL_PUNCTUATION_MARKS )
81
85
{
82
86
None
83
87
} else {
84
- Some ( text_offset. end )
88
+ Some ( text_offset)
85
89
}
86
90
}
0 commit comments