Skip to content

hhatto/cargo-strict

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

49 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cargo-strict build

check unwrap strict code.

Installation

$ 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();";
}

Usage 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();

Usage 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();";
 }

About

avoid unwrap() method

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages