@@ -8,18 +8,18 @@ use rustc_span::source_map::Span;
8
8
use unicode_normalization:: UnicodeNormalization ;
9
9
10
10
declare_clippy_lint ! {
11
- /// **What it does:** Checks for the Unicode zero-width space in the code.
11
+ /// **What it does:** Checks for invisible Unicode characters in the code.
12
12
///
13
13
/// **Why is this bad?** Having an invisible character in the code makes for all
14
14
/// sorts of April fools, but otherwise is very much frowned upon.
15
15
///
16
16
/// **Known problems:** None.
17
17
///
18
- /// **Example:** You don't see it, but there may be a zero-width space
19
- /// somewhere in this text.
18
+ /// **Example:** You don't see it, but there may be a zero-width space or soft hyphen
19
+ /// somewhere in this text.
20
20
pub ZERO_WIDTH_SPACE ,
21
21
correctness,
22
- "using a zero-width space in a string literal, which is confusing"
22
+ "using an invisible character in a string literal, which is confusing"
23
23
}
24
24
25
25
declare_clippy_lint ! {
@@ -91,14 +91,14 @@ fn escape<T: Iterator<Item = char>>(s: T) -> String {
91
91
92
92
fn check_str ( cx : & LateContext < ' _ > , span : Span , id : HirId ) {
93
93
let string = snippet ( cx, span, "" ) ;
94
- if string. contains ( '\u{200B}' ) {
94
+ if let Some ( invisible ) = string. chars ( ) . find ( |c| [ '\u{200B}' , '\u{ad}' ] . contains ( & c ) ) {
95
95
span_lint_and_sugg (
96
96
cx,
97
97
ZERO_WIDTH_SPACE ,
98
98
span,
99
- "zero-width space detected" ,
99
+ & format ! ( "invisible character detected: {:?}" , invisible ) ,
100
100
"consider replacing the string with" ,
101
- string. replace ( "\u{200B} " , "\\ u{200B}" ) ,
101
+ string. replace ( "\u{200B} " , "\\ u{200B}" ) . replace ( " \u{ad} " , " \\ u{AD}" ) ,
102
102
Applicability :: MachineApplicable ,
103
103
) ;
104
104
}
0 commit comments