josephleblanc / web_crawler

Crawl a given royalroad seed page for story text
1 stars 0 forks source link

Using Clippy for great good #1

Closed guygastineau closed 2 years ago

guygastineau commented 2 years ago

The first thing that comes to mind for me is eliminating the warnings flagged by clippy and the compiler. When I run cargo clippy in the project directory I get the following:

warning: unused import: `std::error::Error`
 --> src/lib.rs:1:5
  |
1 | use std::error::Error;
  |     ^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

warning: unused import: `std::fs`
 --> src/lib.rs:2:5
  |
2 | use std::fs;
  |     ^^^^^^^

warning: single-character string constant used as pattern
  --> src/lib.rs:18:15
   |
18 |         .find("\"")
   |               ^^^^ help: try using a `char` instead: `'\"'`
   |
   = note: `#[warn(clippy::single_char_pattern)]` on by default
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#single_char_pattern

warning: `web_crawler` (lib) generated 3 warnings
warning: unused variable: `f`
  --> src/main.rs:43:13
   |
43 |     let mut f = fs::File::create("body.html");
   |             ^ help: if this is intentional, prefix it with an underscore: `_f`
   |
   = note: `#[warn(unused_variables)]` on by default

warning: variable does not need to be mutable
  --> src/main.rs:43:9
   |
43 |     let mut f = fs::File::create("body.html");
   |         ----^
   |         |
   |         help: remove this `mut`
   |
   = note: `#[warn(unused_mut)]` on by default

warning: unused `std::result::Result` that must be used
  --> src/main.rs:52:5
   |
52 |     file.write_all(extract_chapter_header(&html_chapter).unwrap().as_bytes());
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: `#[warn(unused_must_use)]` on by default
   = note: this `Result` may be an `Err` variant, which should be handled

warning: unused `std::result::Result` that must be used
  --> src/main.rs:53:5
   |
53 |     file.write_all(current_body.unwrap().as_bytes());
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: this `Result` may be an `Err` variant, which should be handled

warning: unused `std::result::Result` that must be used
  --> src/main.rs:71:9
   |
71 |         file.write_all(extract_chapter_header(&html_chapter).unwrap().as_bytes());
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: this `Result` may be an `Err` variant, which should be handled

warning: unused `std::result::Result` that must be used
  --> src/main.rs:72:9
   |
72 |         file.write_all(current_body.unwrap().as_bytes());
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: this `Result` may be an `Err` variant, which should be handled

warning: `web_crawler` (bin "web_crawler") generated 6 warnings
    Finished dev [unoptimized + debuginfo] target(s) in 9.88s

Most of these are pretty easy to fix, and the compiler warning messages make the fixes clear. Let me know if the rationale for any of the warnings is unclear.

josephleblanc commented 2 years ago

I hadn't seen the cargo clippy command before, thanks for sharing that. All fixed now.

Is this when I would consider closing the issue?

guygastineau commented 2 years ago

Yep, although you could have made a PR with a closing reference to this issue to have it close automatically when the PR is merged. There was no reason to do so in this case, unless you just wanted to see how it works.