avoid unwrap() method
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
examples
src
.gitignore
Cargo.lock
Cargo.toml
README.md

README.md

cargo-strict

check unwrap strict code.

Instllation

$ cargo install --git https://github.com/hhatto/cargo-strict.git

Usage

$ cargo strict

input:

$ cat examples/simple.rs
fn main() {
    let s = "Hello world";  /* .unwrap() */
    let _ = s.find("wo").unwrap();
    // let _ = s.find("wo").unwrap();
    let ignore = "s.unwrap();";
}

as linter

$ cargo strict
./examples/simple.rs:2:24:     let _ = s.find("wo").unwrap();
./src/main.rs:96:36:     let input = File::open(filename).unwrap();
$ cargo strict example/simple.rs
./examples/simple.rs:2:24:     let _ = s.find("wo").unwrap();

as formatter

$ cargo strict --fix
$ git diff
diff --git a/examples/simple.rs b/examples/simple.rs
index e066898..dbe188b 100644
--- a/examples/simple.rs
+++ b/examples/simple.rs
@@ -1,6 +1,6 @@
 fn main() {
     let s = "Hello world";  /* .unwrap() */
-    let _ = s.find("wo").unwrap();
+    let _ = s.find("wo").expect("error-id:5cb0410ba34b040dbbde09dc1991685d");
     // let _ = s.find("wo").unwrap();
     let ignore = "s.unwrap();";
 }