From ee92a9f1c3e473cd32ef6088fa5e4fd5279379bb Mon Sep 17 00:00:00 2001 From: Meng Zhang Date: Fri, 9 Feb 2024 11:19:01 -0800 Subject: [PATCH] test: add lint to avoid unwrap (#1422) * test: add lint to avoid unwrap * update * Update crates/tabby-inference/src/lib.rs * [autofix.ci] apply automated fixes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> --- crates/tabby-inference/src/lib.rs | 4 ++-- rules/avoid-unwrap.yml | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 rules/avoid-unwrap.yml diff --git a/crates/tabby-inference/src/lib.rs b/crates/tabby-inference/src/lib.rs index b858ba2537cd..1b0dd5624930 100644 --- a/crates/tabby-inference/src/lib.rs +++ b/crates/tabby-inference/src/lib.rs @@ -30,8 +30,8 @@ impl TextGenerationOptions { pub fn default_seed() -> u64 { std::time::SystemTime::now() .duration_since(std::time::UNIX_EPOCH) - .unwrap() - .as_millis() as u64 + .map(|x| x.as_millis() as u64) + .unwrap_or_default() } } diff --git a/rules/avoid-unwrap.yml b/rules/avoid-unwrap.yml new file mode 100644 index 000000000000..b76fdb09d20a --- /dev/null +++ b/rules/avoid-unwrap.yml @@ -0,0 +1,22 @@ +id: avoid-unwrap-if-possible +message: Avoid unwrap, consider return Result with meaningful error message. +severity: warning +language: rust +ignores: +- ./crates/aim-downloader/* +- ./crates/tabby/tests/* +rule: + all: + - any: + - kind: field_identifier + regex: ^unwrap$ + - kind: identifier + regex: ^unwrap$ + - not: + inside: + pattern: mod tests { $$$ } + stopBy: end + - not: + inside: + pattern: lazy_static! { $$$ } + stopBy: end \ No newline at end of file