Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

needless_raw_string_hashes lint on inline snapshots #389

Closed
dtolnay opened this issue Jul 3, 2023 · 0 comments · Fixed by #390
Closed

needless_raw_string_hashes lint on inline snapshots #389

dtolnay opened this issue Jul 3, 2023 · 0 comments · Fixed by #390
Labels
bug Something isn't working

Comments

@dtolnay
Copy link
Contributor

dtolnay commented Jul 3, 2023

What happened?

Calling your attention to the fact that as of nightly-2023-07-03, clippy has begun emitting a new lint on insta-generated inline snapshots.

I think the distinctive @r###" … "### is fine to keep, so hopefully we can suppress the lint with a allow(clippy::needless_raw_string_hashes) in the right place in insta's macros.

Reproduction steps

#[test]
fn repro() {
    insta::assert_debug_snapshot!(("x", 'x', b'x'), @r###"
    (
        "x",
        'x',
        120,
    )
    "###);
}
$ cargo clippy --tests

warning: unnecessary hashes around raw string literal
 --> src/main.rs:3:54
  |
3 |       insta::assert_debug_snapshot!(("x", 'x', b'x'), @r###"
  |  ______________________________________________________^
4 | |     (
5 | |         "x",
6 | |         'x',
7 | |         120,
8 | |     )
9 | |     "###);
  | |________^
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_raw_string_hashes
  = note: `#[warn(clippy::needless_raw_string_hashes)]` on by default
help: try
  |
3 ~     insta::assert_debug_snapshot!(("x", 'x', b'x'), @r#"
4 +     (
5 +         "x",
6 +         'x',
7 +         120,
8 +     )
9 ~     "#);
  |

Insta Version

1.30.0

rustc Version

nightly-2023-07-03

What did you expect?

No response

@dtolnay dtolnay added the bug Something isn't working label Jul 3, 2023
ilyagr added a commit to ilyagr/jj that referenced this issue Jul 10, 2023
…_hashes`

This is (almost) a result of running

    cargo +nightly clippy --workspace --all-targets --fix \
      --  -A 'clippy::needless_raw_string_hashes'

with yesterday's nightly clippy.

mitsuhiko/insta#389 causes numerous additional
`needless_raw_string_hashes` warnings, but it will hopefully be fixed soon.
For now, I recommend appending the second line to your invocations.
ilyagr added a commit to ilyagr/jj that referenced this issue Jul 10, 2023
…_hashes`

This is (almost) a result of running

    cargo +nightly clippy --workspace --all-targets --fix \
      --  -A 'clippy::needless_raw_string_hashes'

with yesterday's nightly clippy.

mitsuhiko/insta#389 causes numerous additional
`needless_raw_string_hashes` warnings, but it will hopefully be fixed soon.
For now, I recommend appending the second line to your invocations.
ilyagr added a commit to martinvonz/jj that referenced this issue Jul 10, 2023
…_hashes`

This is (almost) a result of running

    cargo +nightly clippy --workspace --all-targets --fix \
      --  -A 'clippy::needless_raw_string_hashes'

with yesterday's nightly clippy.

mitsuhiko/insta#389 causes numerous additional
`needless_raw_string_hashes` warnings, but it will hopefully be fixed soon.
For now, I recommend appending the second line to your invocations.
ilyagr added a commit to ilyagr/jj that referenced this issue Jul 10, 2023
…_hashes`

This is (almost) a result of running

    cargo +nightly clippy --workspace --all-targets --fix \
      --  -A 'clippy::needless_raw_string_hashes'

with yesterday's nightly clippy.

mitsuhiko/insta#389 causes numerous additional
`needless_raw_string_hashes` warnings, but it will hopefully be fixed soon.
For now, I recommend appending the second line to your invocations.
ilyagr added a commit to ilyagr/jj that referenced this issue Jul 10, 2023
https://github.com/ericseppanen/cargo-cranky seems like a useful tool for
cases like mitsuhiko/insta#389 and
martinvonz#1686.

It should probably not be checked in, though. It can be put into
`.git/info/excludes`, but that's harder on non-colocated repos and I'm not
100% certain jj properly ignores the files in there in all circumstances.
ilyagr added a commit to ilyagr/jj that referenced this issue Jul 10, 2023
https://github.com/ericseppanen/cargo-cranky seems like a useful tool for
cases like mitsuhiko/insta#389 (cc martinvonz#1834) and
martinvonz#1686.

It should probably not be checked in, though. It can be put into
`.git/info/excludes`, but that's harder on non-colocated repos and I'm not
100% certain jj properly ignores the files in there in all circumstances.

The idea is to use this with VS Code or to simplify command-line clippy
invocation.
ilyagr added a commit to ilyagr/jj that referenced this issue Jul 11, 2023
https://github.com/ericseppanen/cargo-cranky seems like a useful tool for
cases like mitsuhiko/insta#389 (cc martinvonz#1834) and
martinvonz#1686.

It should probably not be checked in, though. It can be put into
`.git/info/excludes`, but that's harder on non-colocated repos and I'm not
100% certain jj properly ignores the files in there in all circumstances.

The idea is to use this with VS Code or to simplify command-line clippy
invocation. For example, until mitsuhiko/insta#389
is fixed, you can put the following into your `Cranky.toml`:

```toml
allow = [
"clippy::needless_raw_string_hashes"
]
```

Then, you can have VS code use `cargo cranky` instead of `cargo check` or
`cargo clippy` and continue to use nightly clippy.

The other possible solution, of course, would be to switch to beta clippy.
ilyagr added a commit to ilyagr/jj that referenced this issue Jul 11, 2023
https://github.com/ericseppanen/cargo-cranky seems like a useful tool for
cases like mitsuhiko/insta#389 (cc martinvonz#1834) and
martinvonz#1686.

It should probably not be checked in, though. It can be put into
`.git/info/excludes`, but that's harder on non-colocated repos and I'm not
100% certain jj properly ignores the files in there in all circumstances.

The idea is to use this with VS Code or to simplify command-line clippy
invocation. For example, until mitsuhiko/insta#389
is fixed, you can put the following into your `Cranky.toml`:

```toml
allow = [
"clippy::needless_raw_string_hashes"
]
```

Then, you can have VS code use `cargo cranky` instead of `cargo check` or
`cargo clippy` and continue to use nightly clippy.

The other possible solution, of course, would be to switch to beta clippy.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant