rust-lang / rust-lang/rust-clippy

Replace `if s.split('.').count() == 1` with `if !s.contains('.')`

Open
#9,158 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-lint
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

What it does

I've found this "ingenious" snippet in a big Rust codebase, and Clippy didn't catch it.

Lint Name

str-split-count-1

Example
if url.split('|').count() == 1 {

}

Could be written as:

if !url.contains('.') {

}

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 by locating the Clippy lint implementation and tests for the proposed str-split-count-1 lint, then compare the issue's split-count example with the requested contains replacement. Done means the lint recognizes the single-delimiter split/count pattern and offers the equivalent contains-based suggestion with coverage for the shown Rust example.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 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.