Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sqf: fix suggestions for eventhandler casing #794

Merged
merged 3 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions libs/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@ pub use sign_version::BISignVersion;
#[must_use]
/// Returns up to 3 similar values from a haystack.
pub fn similar_values<'a>(search: &str, haystack: &'a [&str]) -> Vec<&'a str> {
let mut similar = haystack
let lower_case_haystack = haystack
.iter()
.map(|v| (v, strsim::levenshtein(v, search)))
.map(|v| (*v, v.to_lowercase()))
.collect::<Vec<_>>();
let mut similar = lower_case_haystack
.iter()
.map(|(v, vl)| (v, strsim::levenshtein(vl.as_str(), &search.to_lowercase())))
.collect::<Vec<_>>();
similar.sort_by_key(|(_, v)| *v);
similar.retain(|s| s.1 <= 3);
Expand Down
1 change: 1 addition & 0 deletions libs/sqf/tests/lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ fn test_analyze(dir: &str) {
};
}

analyze!(s02_event_handler_case);
analyze!(s03_static_typename);
analyze!(s04_command_case);
analyze!(s05_if_assign);
Expand Down
3 changes: 3 additions & 0 deletions libs/sqf/tests/lints/s02_event_handler_case/source.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
_this ctrlAddEventHandler ["lbdblclick", {
systemChat "Double click!";
}];
8 changes: 8 additions & 0 deletions libs/sqf/tests/lints/s02_event_handler_case/stdout.ansi
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
warning[L-S02UE]: Using `ctrlAddEventHandler` with unknown event `lbdblclick`
┌─ source.sqf:1:28
│
1 │ _this ctrlAddEventHandler ["lbdblclick", {
│ ^^^^^^^^^^^^ unknown event `lbdblclick`
│
= help: Did you mean: `LBDblClick`?

Loading