rust-lang / rust-clippy

A bunch of lints to catch common mistakes and improve your Rust code. Book: https://doc.rust-lang.org/clippy/
https://rust-lang.github.io/rust-clippy/
Other
11.03k stars 1.48k forks source link

Clippy does not check fancy_regex (or friends) #10205

Open schneems opened 1 year ago

schneems commented 1 year ago

Summary

Hello and thank you for this amazing project!

I see that this Regex lint https://rust-lang.github.io/rust-clippy/master/index.html#invalid_regex will only check a Regex from the regex crate. I would like the ability to lint Regex creation in other crates, specifically fancy_regex.

I'm reporting this as a bug since after https://github.com/rust-lang/regex/issues/607 I believed that I was able to use unwrap/expect unchecked with regex creation since I've got clippy configured to check my project. Later I realized I need multiple different regex crates. I think if someone comes across that issue and sees that Regex::new() is checked, they might not realize or remember they're using an unsupported crate.

Lint Name

invalid_regex

Reproducer

I tried this code:

let _foo = fancy_regex::Regex::new("(").unwrap();

I expected to see this happen:

error: regex syntax error: unclosed group
   --> commons/src/gem_version.rs:198:39
    |
198 |         let _foo = fancy_regex::Regex::new("(").unwrap();

Instead, this happened:

$ cargo clippy --all-targets
    Blocking waiting for file lock on build directory
    Checking commons v0.1.0 (/Users/rschneeman/Documents/projects/work/buildpacks/buildpacks-ruby/commons)
    Finished dev [unoptimized + debuginfo] target(s) in 0.93s

Version

$ rustc -Vv
rustc 1.66.1 (90743e729 2023-01-10)
binary: rustc
commit-hash: 90743e7298aca107ddaa0c202a4d3604e29bfeb6
commit-date: 2023-01-10
host: x86_64-apple-darwin
release: 1.66.1
LLVM version: 15.0.2
schneems commented 1 month ago

There are also other regex crates such as https://crates.io/crates/regex-lite