Suggest to use raw strings for strings with many quoted escapes

Open
#12,165 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

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

Research direction

Start by reviewing the referenced needless_raw_strings lint and the issue’s escaped-quote examples, including both ordinary and byte strings. Define the lint’s threshold and handling of other escapes or newlines, then add equivalent coverage and verify that suggested raw-string forms preserve the intended content.

Written by the indexing model from the issue text.

Description

A-lint
What it does

This is an inverse of the needless_raw_strings -- it suggests to use a raw string because there is a significant number of escaped quotes (more than 1?).

Note that this lint should only apply if the string has no other escaped special characters like \t. Newlines might be the only exception, especially if the string is already using the actual linebreaks rather than the \n.

Advantage

Makes code far more readable

Drawbacks

No response

Example
println!("{\"some\": \"values\"}");
println!(b"{\"some\": \"values\"}");

Could be written as:

println!(r#"{"some": "values"}"#);
println!(br#"{"some": "values"}"#);
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

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.

More from rust-lang/rust-clippy

All issues in rust-lang/rust-clippy

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.