Skip to content

Commit

Permalink
test: add lint to avoid unwrap (#1422)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
wsxiaoys and autofix-ci[bot] authored Feb 9, 2024
1 parent 2542fde commit ee92a9f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
4 changes: 2 additions & 2 deletions crates/tabby-inference/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}

Expand Down
22 changes: 22 additions & 0 deletions rules/avoid-unwrap.yml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit ee92a9f

Please sign in to comment.