Skip to content

Commit

Permalink
refactor: remove unnecessary string hashes (#13250)
Browse files Browse the repository at this point in the history
  • Loading branch information
hamirmahal authored Sep 18, 2024
1 parent c173ec5 commit 8b3da18
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 19 deletions.
4 changes: 2 additions & 2 deletions crates/red_knot_python_semantic/src/semantic_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1027,7 +1027,7 @@ class C[T]:
}

let TestCase { db, file } = test_case(
r#"
r"
class Test:
def foo():
def bar():
Expand All @@ -1036,7 +1036,7 @@ class Test:
pass
def x():
pass"#,
pass",
);

let index = semantic_index(&db, file);
Expand Down
12 changes: 6 additions & 6 deletions crates/ruff/tests/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,18 +326,18 @@ fn docstring_options() -> Result<()> {
let ruff_toml = tempdir.path().join("ruff.toml");
fs::write(
&ruff_toml,
r#"
r"
[format]
docstring-code-format = true
docstring-code-line-length = 20
"#,
",
)?;

assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
.args(["format", "--config"])
.arg(&ruff_toml)
.arg("-")
.pass_stdin(r#"
.pass_stdin(r"
def f(x):
'''
Something about `f`. And an example:
Expand All @@ -357,7 +357,7 @@ def f(x):
>>> foo, bar, quux = this_is_a_long_line(lion, hippo, lemur, bear)
'''
pass
"#), @r###"
"), @r###"
success: true
exit_code: 0
----- stdout -----
Expand Down Expand Up @@ -509,9 +509,9 @@ fn syntax_error() -> Result<()> {

fs::write(
tempdir.path().join("main.py"),
r#"
r"
from module import =
"#,
",
)?;

assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
Expand Down
12 changes: 6 additions & 6 deletions crates/ruff/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,15 +158,15 @@ fn check_default_files() -> Result<()> {
let tempdir = TempDir::new()?;
fs::write(
tempdir.path().join("foo.py"),
r#"
r"
import foo # unused import
"#,
",
)?;
fs::write(
tempdir.path().join("bar.py"),
r#"
r"
import bar # unused import
"#,
",
)?;

assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
Expand Down Expand Up @@ -906,10 +906,10 @@ fn full_output_preview_config() -> Result<()> {
let pyproject_toml = tempdir.path().join("pyproject.toml");
fs::write(
&pyproject_toml,
r#"
r"
[tool.ruff]
preview = true
"#,
",
)?;
let mut cmd = RuffCheck::default().config(&pyproject_toml).build();
assert_cmd_snapshot!(cmd.pass_stdin("l = 1"), @r###"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pub struct MissingFStringSyntax;
impl AlwaysFixableViolation for MissingFStringSyntax {
#[derive_message_formats]
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 {
Expand Down
8 changes: 4 additions & 4 deletions crates/ruff_python_formatter/tests/normalizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl Transformer for Normalizer {
fn visit_string_literal(&self, string_literal: &mut ast::StringLiteral) {
static STRIP_DOC_TESTS: Lazy<Regex> = Lazy::new(|| {
Regex::new(
r#"(?mx)
r"(?mx)
(
# strip doctest PS1 prompt lines
^\s*>>>\s.*(\n|$)
Expand All @@ -71,7 +71,7 @@ impl Transformer for Normalizer {
# Also handles the case of an empty ... line.
^\s*\.\.\.((\n|$)|\s.*(\n|$))
)+
"#,
",
)
.unwrap()
});
Expand All @@ -80,11 +80,11 @@ impl Transformer for Normalizer {
// impossible) to detect a reStructuredText block with a simple
// regex. So we just look for the start of a block and remove
// 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(|| {
// 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
Expand Down

0 comments on commit 8b3da18

Please sign in to comment.