mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-27 07:00:55 +00:00
Fix tests and make other ascii lints auto-fixable
This commit is contained in:
parent
859b329603
commit
36c8aaba8f
2 changed files with 15 additions and 33 deletions
|
@ -1,4 +1,4 @@
|
||||||
use crate::utils::{is_allowed, snippet, span_help_and_lint, span_lint_and_sugg};
|
use crate::utils::{is_allowed, snippet, span_lint_and_sugg};
|
||||||
use rustc::hir::*;
|
use rustc::hir::*;
|
||||||
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
|
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
|
||||||
use rustc::{declare_lint_pass, declare_tool_lint};
|
use rustc::{declare_lint_pass, declare_tool_lint};
|
||||||
|
@ -92,15 +92,14 @@ fn escape<T: Iterator<Item = char>>(s: T) -> String {
|
||||||
fn check_str(cx: &LateContext<'_, '_>, span: Span, id: HirId) {
|
fn check_str(cx: &LateContext<'_, '_>, span: Span, id: HirId) {
|
||||||
let string = snippet(cx, span, "");
|
let string = snippet(cx, span, "");
|
||||||
if string.contains('\u{200B}') {
|
if string.contains('\u{200B}') {
|
||||||
span_help_and_lint(
|
span_lint_and_sugg(
|
||||||
cx,
|
cx,
|
||||||
ZERO_WIDTH_SPACE,
|
ZERO_WIDTH_SPACE,
|
||||||
span,
|
span,
|
||||||
"zero-width space detected",
|
"zero-width space detected",
|
||||||
&format!(
|
"consider replacing the string with",
|
||||||
"Consider replacing the string with:\n\"{}\"",
|
string.replace("\u{200B}", "\\u{200B}"),
|
||||||
string.replace("\u{200B}", "\\u{200B}")
|
Applicability::MachineApplicable,
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if string.chars().any(|c| c as u32 > 0x7F) {
|
if string.chars().any(|c| c as u32 > 0x7F) {
|
||||||
|
@ -109,35 +108,24 @@ fn check_str(cx: &LateContext<'_, '_>, span: Span, id: HirId) {
|
||||||
NON_ASCII_LITERAL,
|
NON_ASCII_LITERAL,
|
||||||
span,
|
span,
|
||||||
"literal non-ASCII character detected",
|
"literal non-ASCII character detected",
|
||||||
&format!(
|
"consider replacing the string with",
|
||||||
"Consider replacing the string with:\n\"{}\"",
|
|
||||||
if is_allowed(cx, UNICODE_NOT_NFC, id) {
|
if is_allowed(cx, UNICODE_NOT_NFC, id) {
|
||||||
escape(string.chars())
|
escape(string.chars())
|
||||||
} else {
|
} else {
|
||||||
escape(string.nfc())
|
escape(string.nfc())
|
||||||
}
|
},
|
||||||
),
|
|
||||||
format!(
|
|
||||||
"{}",
|
|
||||||
if is_allowed(cx, UNICODE_NOT_NFC, id) {
|
|
||||||
escape(string.chars())
|
|
||||||
} else {
|
|
||||||
escape(string.nfc())
|
|
||||||
}
|
|
||||||
),
|
|
||||||
Applicability::MachineApplicable,
|
Applicability::MachineApplicable,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if is_allowed(cx, NON_ASCII_LITERAL, id) && string.chars().zip(string.nfc()).any(|(a, b)| a != b) {
|
if is_allowed(cx, NON_ASCII_LITERAL, id) && string.chars().zip(string.nfc()).any(|(a, b)| a != b) {
|
||||||
span_help_and_lint(
|
span_lint_and_sugg(
|
||||||
cx,
|
cx,
|
||||||
UNICODE_NOT_NFC,
|
UNICODE_NOT_NFC,
|
||||||
span,
|
span,
|
||||||
"non-nfc unicode sequence detected",
|
"non-nfc unicode sequence detected",
|
||||||
&format!(
|
"consider replacing the string with",
|
||||||
"Consider replacing the string with:\n\"{}\"",
|
string.nfc().collect::<String>(),
|
||||||
string.nfc().collect::<String>()
|
Applicability::MachineApplicable,
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,8 +5,6 @@ LL | print!("Here >< is a ZWS, and another");
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
|
|
||||||
= note: `-D clippy::zero-width-space` implied by `-D warnings`
|
= note: `-D clippy::zero-width-space` implied by `-D warnings`
|
||||||
= help: Consider replacing the string with:
|
|
||||||
""Here >/u{200B}< is a ZWS, and /u{200B}another""
|
|
||||||
|
|
||||||
error: non-nfc unicode sequence detected
|
error: non-nfc unicode sequence detected
|
||||||
--> $DIR/unicode.rs:9:12
|
--> $DIR/unicode.rs:9:12
|
||||||
|
@ -15,8 +13,6 @@ LL | print!("̀àh?");
|
||||||
| ^^^^^
|
| ^^^^^
|
||||||
|
|
|
|
||||||
= note: `-D clippy::unicode-not-nfc` implied by `-D warnings`
|
= note: `-D clippy::unicode-not-nfc` implied by `-D warnings`
|
||||||
= help: Consider replacing the string with:
|
|
||||||
""̀àh?""
|
|
||||||
|
|
||||||
error: literal non-ASCII character detected
|
error: literal non-ASCII character detected
|
||||||
--> $DIR/unicode.rs:15:12
|
--> $DIR/unicode.rs:15:12
|
||||||
|
@ -25,8 +21,6 @@ LL | print!("Üben!");
|
||||||
| ^^^^^^^
|
| ^^^^^^^
|
||||||
|
|
|
|
||||||
= note: `-D clippy::non-ascii-literal` implied by `-D warnings`
|
= note: `-D clippy::non-ascii-literal` implied by `-D warnings`
|
||||||
= help: Consider replacing the string with:
|
|
||||||
""/u{dc}ben!""
|
|
||||||
|
|
||||||
error: aborting due to 3 previous errors
|
error: aborting due to 3 previous errors
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue