From 7c9ba8da0f8720c4292230ad8c875ff142e3dab6 Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Mon, 4 Nov 2024 12:02:59 -0600 Subject: [PATCH] fix println, add tests --- libs/sqf/src/analyze/lints/s08_format_args.rs | 4 +++- libs/sqf/tests/lints/s08_format_args.sqf | 6 +++++- .../lints__simple_s08_format_args.snap | 21 +++++++++++++++++++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/libs/sqf/src/analyze/lints/s08_format_args.rs b/libs/sqf/src/analyze/lints/s08_format_args.rs index e4ad15e8..34d66ebe 100644 --- a/libs/sqf/src/analyze/lints/s08_format_args.rs +++ b/libs/sqf/src/analyze/lints/s08_format_args.rs @@ -129,7 +129,9 @@ fn get_format_problem(input: &str, extra_args: usize) -> Option { .unwrap_or_default(); tokens.push(token_value); } else if c != '%' { - println!("format string: non-escaped \"%\" [at index {token_start}]"); + return Some(format!( + "format string: non-escaped \"%\" [at index {token_start}]" + )); } } if !token_active && c == '%' && outside_token { diff --git a/libs/sqf/tests/lints/s08_format_args.sqf b/libs/sqf/tests/lints/s08_format_args.sqf index 08364112..d492c023 100644 --- a/libs/sqf/tests/lints/s08_format_args.sqf +++ b/libs/sqf/tests/lints/s08_format_args.sqf @@ -8,7 +8,11 @@ format ["%1%2", 1]; // undefined tokens format ["%5", 1, 2 ,3 ,4, 5]; // skipped tokens formatText ["me too %1"]; - format ["%1%%", 100]; format ["%%%1%%", 100]; format ["%%%%%%%%%%%%%%%%"]; +format ["this code is 99% bug free"]; // non-escaped +format ["%1%"]; // non-escaped (prioity over unused) +format ["%%1", 1]; // unused args +format ["%%%1", 1]; +format ["%%%1%%%2 %% %%%3%%%%", 1, 2, 3]; diff --git a/libs/sqf/tests/snapshots/lints__simple_s08_format_args.snap b/libs/sqf/tests/snapshots/lints__simple_s08_format_args.snap index 26a08d69..28b32312 100644 --- a/libs/sqf/tests/snapshots/lints__simple_s08_format_args.snap +++ b/libs/sqf/tests/snapshots/lints__simple_s08_format_args.snap @@ -35,3 +35,24 @@ expression: lint(stringify! (s08_format_args)) │ 9 │ formatText ["me too %1"]; │ ^^^^^^^^^^^^^^^^^^^^^^^ format string: undefined tokens [used "%1", passed 0] + + +error[L-S08]: format string: non-escaped "%" [at index 16] + ┌─ s08_format_args.sqf:14:1 + │ +14 │ format ["this code is 99% bug free"]; // non-escaped + │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ format string: non-escaped "%" [at index 16] + + +error[L-S08]: format string: non-escaped "%" [at index 3] + ┌─ s08_format_args.sqf:15:1 + │ +15 │ format ["%1%"]; // non-escaped (prioity over unused) + │ ^^^^^^^^^^^^^ format string: non-escaped "%" [at index 3] + + +error[L-S08]: format string: unused args [used "%0", passed 1] + ┌─ s08_format_args.sqf:16:1 + │ +16 │ format ["%%1", 1]; // unused args + │ ^^^^^^^^^^^^^^^^ format string: unused args [used "%0", passed 1]