refactor: remove unnecessary string hashes (#13250)

This commit is contained in:
Hamir Mahal 2024-09-18 10:08:59 -07:00 committed by GitHub
parent c173ec5bc7
commit 8b3da1867e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 19 additions and 19 deletions

View file

@ -1027,7 +1027,7 @@ class C[T]:
} }
let TestCase { db, file } = test_case( let TestCase { db, file } = test_case(
r#" r"
class Test: class Test:
def foo(): def foo():
def bar(): def bar():
@ -1036,7 +1036,7 @@ class Test:
pass pass
def x(): def x():
pass"#, pass",
); );
let index = semantic_index(&db, file); let index = semantic_index(&db, file);

View file

@ -326,18 +326,18 @@ fn docstring_options() -> Result<()> {
let ruff_toml = tempdir.path().join("ruff.toml"); let ruff_toml = tempdir.path().join("ruff.toml");
fs::write( fs::write(
&ruff_toml, &ruff_toml,
r#" r"
[format] [format]
docstring-code-format = true docstring-code-format = true
docstring-code-line-length = 20 docstring-code-line-length = 20
"#, ",
)?; )?;
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
.args(["format", "--config"]) .args(["format", "--config"])
.arg(&ruff_toml) .arg(&ruff_toml)
.arg("-") .arg("-")
.pass_stdin(r#" .pass_stdin(r"
def f(x): def f(x):
''' '''
Something about `f`. And an example: Something about `f`. And an example:
@ -357,7 +357,7 @@ def f(x):
>>> foo, bar, quux = this_is_a_long_line(lion, hippo, lemur, bear) >>> foo, bar, quux = this_is_a_long_line(lion, hippo, lemur, bear)
''' '''
pass pass
"#), @r###" "), @r###"
success: true success: true
exit_code: 0 exit_code: 0
----- stdout ----- ----- stdout -----
@ -509,9 +509,9 @@ fn syntax_error() -> Result<()> {
fs::write( fs::write(
tempdir.path().join("main.py"), tempdir.path().join("main.py"),
r#" r"
from module import = from module import =
"#, ",
)?; )?;
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))

View file

@ -158,15 +158,15 @@ fn check_default_files() -> Result<()> {
let tempdir = TempDir::new()?; let tempdir = TempDir::new()?;
fs::write( fs::write(
tempdir.path().join("foo.py"), tempdir.path().join("foo.py"),
r#" r"
import foo # unused import import foo # unused import
"#, ",
)?; )?;
fs::write( fs::write(
tempdir.path().join("bar.py"), tempdir.path().join("bar.py"),
r#" r"
import bar # unused import import bar # unused import
"#, ",
)?; )?;
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
@ -906,10 +906,10 @@ fn full_output_preview_config() -> Result<()> {
let pyproject_toml = tempdir.path().join("pyproject.toml"); let pyproject_toml = tempdir.path().join("pyproject.toml");
fs::write( fs::write(
&pyproject_toml, &pyproject_toml,
r#" r"
[tool.ruff] [tool.ruff]
preview = true preview = true
"#, ",
)?; )?;
let mut cmd = RuffCheck::default().config(&pyproject_toml).build(); let mut cmd = RuffCheck::default().config(&pyproject_toml).build();
assert_cmd_snapshot!(cmd.pass_stdin("l = 1"), @r###" assert_cmd_snapshot!(cmd.pass_stdin("l = 1"), @r###"

View file

@ -61,7 +61,7 @@ pub struct MissingFStringSyntax;
impl AlwaysFixableViolation for MissingFStringSyntax { impl AlwaysFixableViolation for MissingFStringSyntax {
#[derive_message_formats] #[derive_message_formats]
fn message(&self) -> String { fn message(&self) -> String {
format!(r#"Possible f-string without an `f` prefix"#) format!(r"Possible f-string without an `f` prefix")
} }
fn fix_title(&self) -> String { fn fix_title(&self) -> String {

View file

@ -62,7 +62,7 @@ impl Transformer for Normalizer {
fn visit_string_literal(&self, string_literal: &mut ast::StringLiteral) { fn visit_string_literal(&self, string_literal: &mut ast::StringLiteral) {
static STRIP_DOC_TESTS: Lazy<Regex> = Lazy::new(|| { static STRIP_DOC_TESTS: Lazy<Regex> = Lazy::new(|| {
Regex::new( Regex::new(
r#"(?mx) r"(?mx)
( (
# strip doctest PS1 prompt lines # strip doctest PS1 prompt lines
^\s*>>>\s.*(\n|$) ^\s*>>>\s.*(\n|$)
@ -71,7 +71,7 @@ impl Transformer for Normalizer {
# Also handles the case of an empty ... line. # Also handles the case of an empty ... line.
^\s*\.\.\.((\n|$)|\s.*(\n|$)) ^\s*\.\.\.((\n|$)|\s.*(\n|$))
)+ )+
"#, ",
) )
.unwrap() .unwrap()
}); });
@ -80,11 +80,11 @@ impl Transformer for Normalizer {
// impossible) to detect a reStructuredText block with a simple // impossible) to detect a reStructuredText block with a simple
// regex. So we just look for the start of a block and remove // regex. So we just look for the start of a block and remove
// everything after it. Talk about a hammer. // everything after it. Talk about a hammer.
Regex::new(r#"::(?s:.*)"#).unwrap() Regex::new(r"::(?s:.*)").unwrap()
}); });
static STRIP_MARKDOWN_BLOCKS: Lazy<Regex> = Lazy::new(|| { static STRIP_MARKDOWN_BLOCKS: Lazy<Regex> = Lazy::new(|| {
// This covers more than valid Markdown blocks, but that's OK. // This covers more than valid Markdown blocks, but that's OK.
Regex::new(r#"(```|~~~)\p{any}*(```|~~~|$)"#).unwrap() Regex::new(r"(```|~~~)\p{any}*(```|~~~|$)").unwrap()
}); });
// Start by (1) stripping everything that looks like a code // Start by (1) stripping everything that looks like a code