Skip to main content

wowlab_tidy/languages/rust/rules/correctness/
ambiguous_unicode.rs

1use crate::{Example, FileCtx, Violation, languages::unicode::ambiguous_unicode_violations};
2
3#[rustfmt::skip]
4const EXAMPLES: &[Example] = &[
5    Example { label: "cyrillic a homoglyph", code: "let x = \"p\u{0430}ssword\";", pass: false },
6    Example { label: "en dash instead of minus", code: "// range 1\u{2013}5", pass: false },
7    Example { label: "curly apostrophe", code: "// don\u{2019}t", pass: false },
8    Example { label: "multiplication sign", code: "// 4\u{00D7}4 matrix", pass: false },
9    Example { label: "normal ASCII", code: "let x = \"hello world\";", pass: true },
10    Example { label: "unambiguous non-ASCII", code: "// r\u{00E9}sum\u{00E9}", pass: true },
11];
12
13crate::line_rule!(
14    ambiguous_unicode,
15    "Ban Unicode characters visually confusable with ASCII (homoglyphs).",
16    "Homoglyphs like Cyrillic U+0430 vs Latin 'a' make code read one way but compile another (trojan-source risk).",
17    High,
18);
19
20fn check_ambiguous_unicode(ctx: &FileCtx<'_>) -> Vec<Violation> {
21    ambiguous_unicode_violations(ctx)
22}
23
24crate::tidy_test!(check_ambiguous_unicode, {
25    crate::example_tests!(EXAMPLES, check_ambiguous_unicode);
26});