Skip to content

Commit

Permalink
Add WJ
Browse files Browse the repository at this point in the history
  • Loading branch information
bugadani committed Oct 2, 2020
1 parent 998bd3b commit 572e4c4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
7 changes: 5 additions & 2 deletions clippy_lints/src/unicode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,17 @@ fn escape<T: Iterator<Item = char>>(s: T) -> String {

fn check_str(cx: &LateContext<'_>, span: Span, id: HirId) {
let string = snippet(cx, span, "");
if string.chars().any(|c| ['\u{200B}', '\u{ad}'].contains(&c)) {
if string.chars().any(|c| ['\u{200B}', '\u{ad}', '\u{2060}'].contains(&c)) {
span_lint_and_sugg(
cx,
INVISIBLE_CHARACTERS,
span,
"invisible character detected",
"consider replacing the string with",
string.replace("\u{200B}", "\\u{200B}").replace("\u{ad}", "\\u{AD}"),
string
.replace("\u{200B}", "\\u{200B}")
.replace("\u{ad}", "\\u{AD}")
.replace("\u{2060}", "\\u{2060}"),
Applicability::MachineApplicable,
);
}
Expand Down
2 changes: 2 additions & 0 deletions tests/ui/unicode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ fn zero() {
print!("This\u{200B}is\u{200B}fine");
print!("Here >­< is a SHY, and ­another");
print!("This\u{ad}is\u{ad}fine");
print!("Here >⁠< is a WJ, and ⁠another");
print!("This\u{2060}is\u{2060}fine");
}

#[warn(clippy::unicode_not_nfc)]
Expand Down
12 changes: 9 additions & 3 deletions tests/ui/unicode.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,27 @@ error: invisible character detected
LL | print!("Here >­< is a SHY, and ­another");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider replacing the string with: `"Here >/u{AD}< is a SHY, and /u{AD}another"`

error: invisible character detected
--> $DIR/unicode.rs:7:12
|
LL | print!("Here >⁠< is a WJ, and ⁠another");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider replacing the string with: `"Here >/u{2060}< is a WJ, and /u{2060}another"`

error: non-NFC Unicode sequence detected
--> $DIR/unicode.rs:11:12
--> $DIR/unicode.rs:13:12
|
LL | print!("̀àh?");
| ^^^^^ help: consider replacing the string with: `"̀àh?"`
|
= note: `-D clippy::unicode-not-nfc` implied by `-D warnings`

error: literal non-ASCII character detected
--> $DIR/unicode.rs:17:12
--> $DIR/unicode.rs:19:12
|
LL | print!("Üben!");
| ^^^^^^^ help: consider replacing the string with: `"/u{dc}ben!"`
|
= note: `-D clippy::non-ascii-literal` implied by `-D warnings`

error: aborting due to 4 previous errors
error: aborting due to 5 previous errors

0 comments on commit 572e4c4

Please sign in to comment.