rust-lang / rust-lang/rust-clippy

Clippy does not check fancy_regex (or friends)

Open
#10,205 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug I-false-negative
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the invalid_regex lint and its existing handling of the regex crate, then compare that with the reported fancy_regex::Regex::new("(") reproducer. Determine how support for other regex crates should be represented and verify that the reproducer produces the expected unclosed-group diagnostic.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.