Skip to content

Support clippy::needless_raw_strings lint#828

Merged
max-sixty merged 8 commits intomitsuhiko:masterfrom
max-sixty:raw-strings
Dec 15, 2025
Merged

Support clippy::needless_raw_strings lint#828
max-sixty merged 8 commits intomitsuhiko:masterfrom
max-sixty:raw-strings

Conversation

@max-sixty
Copy link
Copy Markdown
Collaborator

@max-sixty max-sixty commented Nov 24, 2025

this would fix #827

@mitsuhiko do you have thoughts? I'm mildly positive on it but will leave it open for a while because I think you voiced weak skepticism in the past.

Claude comment below


Changes

  • Modified to_inline() to only use raw strings when content contains backslashes or quotes
  • Removed newlines from raw string trigger condition
  • Added clippy::needless_raw_strings lint to the project
  • Force-updated all snapshots to use the new logic
  • Added allow attribute for vendored YAML code

Test Results

✅ All tests pass
✅ Zero clippy warnings in production code
✅ 44+ needless raw strings converted to regular strings

🤖 Generated with Claude Code

max-sixty and others added 2 commits November 24, 2025 11:06
[to be written by @max-sixty]

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This test uses raw string literals as test inputs to verify normalization
behavior with different string formats.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Comment thread cargo-insta/src/main.rs
@@ -1,4 +1,5 @@
#![warn(clippy::doc_markdown)]
#![warn(clippy::needless_raw_strings)]
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this isn't strictly necessary, I used this to test our approach was working. can remove at any light objection

Comment thread insta/src/snapshot.rs
if !has_control_chars && contents.contains(['\\', '"', '\n']) {
// We don't use raw strings just for newlines, as they can appear
// literally in regular strings (avoids clippy::needless_raw_strings).
if !has_control_chars && contents.contains(['\\', '"']) {
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these are the substantive changes

max-sixty and others added 6 commits November 24, 2025 11:26
Tests test_min_indentation and test_min_indentation_additional use raw
strings as test inputs to verify indentation handling behavior.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Add allow attributes to test_parse_yaml_error and test_empty_lines
which use raw strings as test input values.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Add new functional tests specifically for testing needless raw string
  handling (both as inputs and outputs)
- Remove #[allow(clippy::needless_raw_strings)] attributes from unit tests
- Convert needless raw strings in unit tests to regular strings
- Keep raw strings only where they're actually needed (contain quotes or
  backslashes)

This separates concerns: functional tests explicitly verify raw string
handling behavior, while unit tests focus on testing internal logic
without using needless raw strings.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Accept the correct diff output format for the functional tests.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@max-sixty
Copy link
Copy Markdown
Collaborator Author

will merge, but would be backward compat with existing snapshots if @mitsuhiko had strong reservations post

@max-sixty max-sixty merged commit 521812c into mitsuhiko:master Dec 15, 2025
15 checks passed
@max-sixty max-sixty deleted the raw-strings branch December 15, 2025 21:12
gaetschwartz added a commit to gaetschwartz/insta that referenced this pull request Dec 16, 2025
Revert accidental regression from ad13147 that added '\n' to the raw
string condition. Multiline content should not use raw string prefixes
unless it contains backslashes or quotes, matching upstream/master
behavior from PR mitsuhiko#828.
@max-sixty max-sixty mentioned this pull request Dec 18, 2025
2 tasks
max-sixty added a commit that referenced this pull request Dec 18, 2025
## Summary

- Add external diff tool support via `INSTA_DIFF_TOOL` environment
variable (#844)
- Add `test.disable_nextest_doctest` config option to `insta.yaml`
(#842)
- Skip non-insta snapshot files in unreferenced detection (#846)
- Collect warnings from tests for display after run (#840)
- Update TOML serialization to be up-to-date and backwards-compatible
(#834)
- Support `clippy::needless_raw_strings` lint (#828)

## Test plan

- [x] All tests pass
- [x] All lints pass

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude <noreply@anthropic.com>
gaetschwartz added a commit to gaetschwartz/insta that referenced this pull request Feb 3, 2026
Revert accidental regression from ad13147 that added '\n' to the raw
string condition. Multiline content should not use raw string prefixes
unless it contains backslashes or quotes, matching upstream/master
behavior from PR mitsuhiko#828.
gaetschwartz added a commit to gaetschwartz/insta that referenced this pull request Feb 26, 2026
Revert accidental regression from ad13147 that added '\n' to the raw
string condition. Multiline content should not use raw string prefixes
unless it contains backslashes or quotes, matching upstream/master
behavior from PR mitsuhiko#828.
gaetschwartz added a commit to gaetschwartz/insta that referenced this pull request Feb 28, 2026
Revert accidental regression from ad13147 that added '\n' to the raw
string condition. Multiline content should not use raw string prefixes
unless it contains backslashes or quotes, matching upstream/master
behavior from PR mitsuhiko#828.
gaetschwartz added a commit to gaetschwartz/insta that referenced this pull request Mar 14, 2026
Revert accidental regression from ad13147 that added '\n' to the raw
string condition. Multiline content should not use raw string prefixes
unless it contains backslashes or quotes, matching upstream/master
behavior from PR mitsuhiko#828.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Please support projects that use clippy::needless_raw_strings

1 participant