diff --git a/.cargo/config.toml b/.cargo/config.toml index d6ef99b66f..0d426a9f6e 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,37 +1,3 @@ [alias] dev = "run --package ruff_dev --bin ruff_dev" benchmark = "bench -p ruff_benchmark --bench linter --bench formatter --" - -[target.'cfg(all())'] -rustflags = [ - # CLIPPY LINT SETTINGS - # This is a workaround to configure lints for the entire workspace, pending the ability to configure this via TOML. - # See: `https://github.com/rust-lang/cargo/issues/5034` - # `https://github.com/EmbarkStudios/rust-ecosystem/issues/22#issuecomment-947011395` - "-Dunsafe_code", - "-Wclippy::pedantic", - # Allowed pedantic lints - "-Wclippy::char_lit_as_u8", - "-Aclippy::collapsible_else_if", - "-Aclippy::collapsible_if", - "-Aclippy::implicit_hasher", - "-Aclippy::match_same_arms", - "-Aclippy::missing_errors_doc", - "-Aclippy::missing_panics_doc", - "-Aclippy::module_name_repetitions", - "-Aclippy::must_use_candidate", - "-Aclippy::similar_names", - "-Aclippy::too_many_lines", - # Disallowed restriction lints - "-Wclippy::print_stdout", - "-Wclippy::print_stderr", - "-Wclippy::dbg_macro", - "-Wclippy::empty_drop", - "-Wclippy::empty_structs_with_brackets", - "-Wclippy::exit", - "-Wclippy::get_unwrap", - "-Wclippy::rc_buffer", - "-Wclippy::rc_mutex", - "-Wclippy::rest_pat_in_fully_bound_structs", - "-Wunreachable_pub" -] diff --git a/Cargo.toml b/Cargo.toml index 52055dd4a2..c52264fe4b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -55,6 +55,38 @@ unicode-width = { version = "0.1.11" } uuid = { version = "1.5.0", features = ["v4", "fast-rng", "macro-diagnostics", "js"] } wsl = { version = "0.1.0" } +[workspace.lints.rust] +unsafe_code = "warn" +unreachable_pub = "warn" + +[workspace.lints.clippy] +pedantic = { level = "warn", priority = -2 } +# Allowed pedantic lints +char_lit_as_u8 = "allow" +collapsible_else_if = "allow" +collapsible_if = "allow" +implicit_hasher = "allow" +match_same_arms = "allow" +missing_errors_doc = "allow" +missing_panics_doc = "allow" +module_name_repetitions = "allow" +must_use_candidate = "allow" +similar_names = "allow" +too_many_lines = "allow" +# To allow `#[allow(clippy::all)]` in `crates/ruff_python_parser/src/python.rs`. +needless_raw_string_hashes = "allow" +# Disallowed restriction lints +print_stdout = "warn" +print_stderr = "warn" +dbg_macro = "warn" +empty_drop = "warn" +empty_structs_with_brackets = "warn" +exit = "warn" +get_unwrap = "warn" +rc_buffer = "warn" +rc_mutex = "warn" +rest_pat_in_fully_bound_structs = "warn" + [profile.release] lto = "fat" codegen-units = 1 diff --git a/crates/flake8_to_ruff/Cargo.toml b/crates/flake8_to_ruff/Cargo.toml index 2dfc22c75b..89669f6ab9 100644 --- a/crates/flake8_to_ruff/Cargo.toml +++ b/crates/flake8_to_ruff/Cargo.toml @@ -34,3 +34,6 @@ toml = { workspace = true } [dev-dependencies] pretty_assertions = "1.3.0" + +[lints] +workspace = true diff --git a/crates/ruff_benchmark/Cargo.toml b/crates/ruff_benchmark/Cargo.toml index 2dc1259d31..192add9fd9 100644 --- a/crates/ruff_benchmark/Cargo.toml +++ b/crates/ruff_benchmark/Cargo.toml @@ -46,6 +46,9 @@ ruff_python_formatter = { path = "../ruff_python_formatter" } ruff_python_index = { path = "../ruff_python_index" } ruff_python_parser = { path = "../ruff_python_parser" } +[lints] +workspace = true + [features] codspeed = ["codspeed-criterion-compat"] diff --git a/crates/ruff_cache/Cargo.toml b/crates/ruff_cache/Cargo.toml index 7adcf640bc..d82f83bd15 100644 --- a/crates/ruff_cache/Cargo.toml +++ b/crates/ruff_cache/Cargo.toml @@ -20,3 +20,6 @@ seahash = "4.1.0" [dev-dependencies] ruff_macros = { path = "../ruff_macros" } + +[lints] +workspace = true diff --git a/crates/ruff_cli/Cargo.toml b/crates/ruff_cli/Cargo.toml index ab07b2dcb6..c6fef7b3e6 100644 --- a/crates/ruff_cli/Cargo.toml +++ b/crates/ruff_cli/Cargo.toml @@ -76,3 +76,6 @@ mimalloc = "0.1.39" [target.'cfg(all(not(target_os = "windows"), not(target_os = "openbsd"), any(target_arch = "x86_64", target_arch = "aarch64", target_arch = "powerpc64")))'.dependencies] tikv-jemallocator = "0.5.0" + +[lints] +workspace = true diff --git a/crates/ruff_cli/src/commands/check.rs b/crates/ruff_cli/src/commands/check.rs index c4e63f3e86..fb5332277e 100644 --- a/crates/ruff_cli/src/commands/check.rs +++ b/crates/ruff_cli/src/commands/check.rs @@ -202,12 +202,12 @@ fn lint_path( match result { Ok(inner) => inner, Err(error) => { - let message = r#"This indicates a bug in Ruff. If you could open an issue at: + let message = r"This indicates a bug in Ruff. If you could open an issue at: https://github.com/astral-sh/ruff/issues/new?title=%5BLinter%20panic%5D ...with the relevant file contents, the `pyproject.toml` settings, and the following stack trace, we'd be very appreciative! -"#; +"; error!( "{}{}{} {message}\n{error}", diff --git a/crates/ruff_cli/src/commands/format.rs b/crates/ruff_cli/src/commands/format.rs index 2db1338d4d..1b2e431b8e 100644 --- a/crates/ruff_cli/src/commands/format.rs +++ b/crates/ruff_cli/src/commands/format.rs @@ -660,12 +660,12 @@ impl Display for FormatCommandError { } } Self::Panic(path, err) => { - let message = r#"This indicates a bug in Ruff. If you could open an issue at: + let message = r"This indicates a bug in Ruff. If you could open an issue at: https://github.com/astral-sh/ruff/issues/new?title=%5BFormatter%20panic%5D ...with the relevant file contents, the `pyproject.toml` settings, and the following stack trace, we'd be very appreciative! -"#; +"; if let Some(path) = path { write!( f, diff --git a/crates/ruff_cli/src/commands/rule.rs b/crates/ruff_cli/src/commands/rule.rs index 8df1eacb1e..6867805518 100644 --- a/crates/ruff_cli/src/commands/rule.rs +++ b/crates/ruff_cli/src/commands/rule.rs @@ -63,7 +63,7 @@ fn format_rule_text(rule: Rule) -> String { if rule.is_preview() || rule.is_nursery() { output.push_str( - r#"This rule is in preview and is not stable. The `--preview` flag is required for use."#, + r"This rule is in preview and is not stable. The `--preview` flag is required for use.", ); output.push('\n'); output.push('\n'); diff --git a/crates/ruff_cli/tests/format.rs b/crates/ruff_cli/tests/format.rs index c4527e9a79..c5c3995633 100644 --- a/crates/ruff_cli/tests/format.rs +++ b/crates/ruff_cli/tests/format.rs @@ -395,9 +395,9 @@ fn deprecated_options() -> Result<()> { let ruff_toml = tempdir.path().join("ruff.toml"); fs::write( &ruff_toml, - r#" + r" tab-size = 2 -"#, +", )?; insta::with_settings!({filters => vec![ @@ -407,10 +407,10 @@ tab-size = 2 .args(["format", "--config"]) .arg(&ruff_toml) .arg("-") - .pass_stdin(r#" + .pass_stdin(r" if True: pass - "#), @r###" + "), @r###" success: true exit_code: 0 ----- stdout ----- @@ -443,9 +443,9 @@ format = "json" .args(["check", "--select", "F401", "--no-cache", "--config"]) .arg(&ruff_toml) .arg("-") - .pass_stdin(r#" + .pass_stdin(r" import os - "#), @r###" + "), @r###" success: false exit_code: 2 ----- stdout ----- diff --git a/crates/ruff_dev/Cargo.toml b/crates/ruff_dev/Cargo.toml index 52526e59c1..d17e22289c 100644 --- a/crates/ruff_dev/Cargo.toml +++ b/crates/ruff_dev/Cargo.toml @@ -48,9 +48,12 @@ tracing-indicatif = { workspace = true } tracing-subscriber = { workspace = true, features = ["env-filter"] } imara-diff = "0.1.5" +[dev-dependencies] +indoc = "2.0.4" + [features] # Turn off rayon for profiling singlethreaded = [] -[dev-dependencies] -indoc = "2.0.4" +[lints] +workspace = true diff --git a/crates/ruff_dev/src/generate_docs.rs b/crates/ruff_dev/src/generate_docs.rs index 1b557b68bc..db9402b146 100644 --- a/crates/ruff_dev/src/generate_docs.rs +++ b/crates/ruff_dev/src/generate_docs.rs @@ -49,7 +49,7 @@ pub(crate) fn main(args: &Args) -> Result<()> { if rule.is_preview() || rule.is_nursery() { output.push_str( - r#"This rule is unstable and in [preview](../preview.md). The `--preview` flag is required for use."#, + r"This rule is unstable and in [preview](../preview.md). The `--preview` flag is required for use.", ); output.push('\n'); output.push('\n'); diff --git a/crates/ruff_formatter/Cargo.toml b/crates/ruff_formatter/Cargo.toml index fc28b2fd0f..1652327290 100644 --- a/crates/ruff_formatter/Cargo.toml +++ b/crates/ruff_formatter/Cargo.toml @@ -29,3 +29,6 @@ insta = { workspace = true } [features] serde = ["dep:serde", "ruff_text_size/serde"] schemars = ["dep:schemars", "ruff_text_size/schemars"] + +[lints] +workspace = true diff --git a/crates/ruff_formatter/src/printer/mod.rs b/crates/ruff_formatter/src/printer/mod.rs index eda85658e3..e35c44ec28 100644 --- a/crates/ruff_formatter/src/printer/mod.rs +++ b/crates/ruff_formatter/src/printer/mod.rs @@ -1711,14 +1711,14 @@ mod tests { )); assert_eq!( - r#"a + "a b c d d c b -a"#, +a", formatted.as_code() ); } @@ -2047,10 +2047,10 @@ two lines`, assert_eq!( printed.as_code(), - r#"Group with id-2 + "Group with id-2 Group with id-1 does not fit on the line because it exceeds the line width of 80 characters by Group 2 fits -Group 1 breaks"# +Group 1 breaks" ); } diff --git a/crates/ruff_index/Cargo.toml b/crates/ruff_index/Cargo.toml index 29e55d60b4..6864774a2a 100644 --- a/crates/ruff_index/Cargo.toml +++ b/crates/ruff_index/Cargo.toml @@ -17,3 +17,6 @@ ruff_macros = { path = "../ruff_macros" } [dev-dependencies] static_assertions = "1.1.0" + +[lints] +workspace = true diff --git a/crates/ruff_linter/Cargo.toml b/crates/ruff_linter/Cargo.toml index ed965df8d1..69601ba8e9 100644 --- a/crates/ruff_linter/Cargo.toml +++ b/crates/ruff_linter/Cargo.toml @@ -86,3 +86,6 @@ default = [] schemars = ["dep:schemars"] # Enables the UnreachableCode rule unreachable-code = [] + +[lints] +workspace = true diff --git a/crates/ruff_linter/src/fix/mod.rs b/crates/ruff_linter/src/fix/mod.rs index 069bf6e8f7..c9d8e6bb2e 100644 --- a/crates/ruff_linter/src/fix/mod.rs +++ b/crates/ruff_linter/src/fix/mod.rs @@ -171,7 +171,7 @@ mod tests { #[test] fn empty_file() { - let locator = Locator::new(r#""#); + let locator = Locator::new(r""); let diagnostics = create_diagnostics([]); let FixResult { code, @@ -225,10 +225,10 @@ print("hello world") #[test] fn apply_one_replacement() { let locator = Locator::new( - r#" + r" class A(object): ... -"# +" .trim(), ); let diagnostics = create_diagnostics([Edit::replacement( @@ -243,10 +243,10 @@ class A(object): } = apply_fixes(diagnostics.iter(), &locator); assert_eq!( code, - r#" + r" class A(Bar): ... -"# +" .trim(), ); assert_eq!(fixes.values().sum::(), 1); @@ -262,10 +262,10 @@ class A(Bar): #[test] fn apply_one_removal() { let locator = Locator::new( - r#" + r" class A(object): ... -"# +" .trim(), ); let diagnostics = create_diagnostics([Edit::deletion(TextSize::new(7), TextSize::new(15))]); @@ -276,10 +276,10 @@ class A(object): } = apply_fixes(diagnostics.iter(), &locator); assert_eq!( code, - r#" + r" class A: ... -"# +" .trim() ); assert_eq!(fixes.values().sum::(), 1); @@ -295,10 +295,10 @@ class A: #[test] fn apply_two_removals() { let locator = Locator::new( - r#" + r" class A(object, object, object): ... -"# +" .trim(), ); let diagnostics = create_diagnostics([ @@ -313,10 +313,10 @@ class A(object, object, object): assert_eq!( code, - r#" + r" class A(object): ... -"# +" .trim() ); assert_eq!(fixes.values().sum::(), 2); @@ -334,10 +334,10 @@ class A(object): #[test] fn ignore_overlapping_fixes() { let locator = Locator::new( - r#" + r" class A(object): ... -"# +" .trim(), ); let diagnostics = create_diagnostics([ @@ -351,10 +351,10 @@ class A(object): } = apply_fixes(diagnostics.iter(), &locator); assert_eq!( code, - r#" + r" class A: ... -"# +" .trim(), ); assert_eq!(fixes.values().sum::(), 1); diff --git a/crates/ruff_linter/src/importer/insertion.rs b/crates/ruff_linter/src/importer/insertion.rs index 4a2c782c18..cdfff44694 100644 --- a/crates/ruff_linter/src/importer/insertion.rs +++ b/crates/ruff_linter/src/importer/insertion.rs @@ -373,18 +373,18 @@ mod tests { Insertion::own_line("", TextSize::from(40), "\n") ); - let contents = r#" + let contents = r" x = 1 -"# +" .trim_start(); assert_eq!( insert(contents)?, Insertion::own_line("", TextSize::from(0), "\n") ); - let contents = r#" + let contents = r" #!/usr/bin/env python3 -"# +" .trim_start(); assert_eq!( insert(contents)?, @@ -457,10 +457,10 @@ x = 1 Insertion::inline("", TextSize::from(9), "; ") ); - let contents = r#" + let contents = r" if True: pass -"# +" .trim_start(); assert_eq!( insert(contents, TextSize::from(0)), diff --git a/crates/ruff_linter/src/message/mod.rs b/crates/ruff_linter/src/message/mod.rs index 0e5520b5a7..69f7241b04 100644 --- a/crates/ruff_linter/src/message/mod.rs +++ b/crates/ruff_linter/src/message/mod.rs @@ -199,7 +199,7 @@ def fibonacci(n): TextSize::from(99), ))); - let file_2 = r#"if a == 1: pass"#; + let file_2 = r"if a == 1: pass"; let undefined_name = Diagnostic::new( DiagnosticKind { diff --git a/crates/ruff_linter/src/rules/flake8_copyright/mod.rs b/crates/ruff_linter/src/rules/flake8_copyright/mod.rs index 4f09279047..534f2eaf09 100644 --- a/crates/ruff_linter/src/rules/flake8_copyright/mod.rs +++ b/crates/ruff_linter/src/rules/flake8_copyright/mod.rs @@ -12,11 +12,11 @@ mod tests { #[test] fn notice() { let diagnostics = test_snippet( - r#" + r" # Copyright 2023 import os -"# +" .trim(), &settings::LinterSettings::for_rules(vec![Rule::MissingCopyrightNotice]), ); @@ -26,11 +26,11 @@ import os #[test] fn notice_with_c() { let diagnostics = test_snippet( - r#" + r" # Copyright (C) 2023 import os -"# +" .trim(), &settings::LinterSettings::for_rules(vec![Rule::MissingCopyrightNotice]), ); @@ -40,11 +40,11 @@ import os #[test] fn notice_with_caps() { let diagnostics = test_snippet( - r#" + r" # COPYRIGHT (C) 2023 import os -"# +" .trim(), &settings::LinterSettings::for_rules(vec![Rule::MissingCopyrightNotice]), ); @@ -54,11 +54,11 @@ import os #[test] fn notice_with_range() { let diagnostics = test_snippet( - r#" + r" # Copyright (C) 2021-2023 import os -"# +" .trim(), &settings::LinterSettings::for_rules(vec![Rule::MissingCopyrightNotice]), ); @@ -68,11 +68,11 @@ import os #[test] fn valid_author() { let diagnostics = test_snippet( - r#" + r" # Copyright (C) 2023 Ruff import os -"# +" .trim(), &settings::LinterSettings { flake8_copyright: super::settings::Settings { @@ -88,11 +88,11 @@ import os #[test] fn invalid_author() { let diagnostics = test_snippet( - r#" + r" # Copyright (C) 2023 Some Author import os -"# +" .trim(), &settings::LinterSettings { flake8_copyright: super::settings::Settings { @@ -108,9 +108,9 @@ import os #[test] fn small_file() { let diagnostics = test_snippet( - r#" + r" import os -"# +" .trim(), &settings::LinterSettings { flake8_copyright: super::settings::Settings { @@ -126,7 +126,7 @@ import os #[test] fn late_notice() { let diagnostics = test_snippet( - r#" + r" # Content Content Content Content Content Content Content Content Content Content # Content Content Content Content Content Content Content Content Content Content # Content Content Content Content Content Content Content Content Content Content @@ -149,7 +149,7 @@ import os # Content Content Content Content Content Content Content Content Content Content # Copyright 2023 -"# +" .trim(), &settings::LinterSettings::for_rules(vec![Rule::MissingCopyrightNotice]), ); @@ -159,8 +159,8 @@ import os #[test] fn char_boundary() { let diagnostics = test_snippet( - r#"কককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককক -"# + r"কককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককককক +" .trim(), &settings::LinterSettings::for_rules(vec![Rule::MissingCopyrightNotice]), ); diff --git a/crates/ruff_linter/src/rules/flake8_type_checking/mod.rs b/crates/ruff_linter/src/rules/flake8_type_checking/mod.rs index 14bb56bdba..ec5d504a0f 100644 --- a/crates/ruff_linter/src/rules/flake8_type_checking/mod.rs +++ b/crates/ruff_linter/src/rules/flake8_type_checking/mod.rs @@ -171,18 +171,18 @@ mod tests { } #[test_case( - r#" + r" from __future__ import annotations import pandas as pd def f(x: pd.DataFrame): pass - "#, + ", "no_typing_import" )] #[test_case( - r#" + r" from __future__ import annotations from typing import TYPE_CHECKING @@ -191,11 +191,11 @@ mod tests { def f(x: pd.DataFrame): pass - "#, + ", "typing_import_before_package_import" )] #[test_case( - r#" + r" from __future__ import annotations import pandas as pd @@ -204,11 +204,11 @@ mod tests { def f(x: pd.DataFrame): pass - "#, + ", "typing_import_after_package_import" )] #[test_case( - r#" + r" from __future__ import annotations import pandas as pd @@ -217,11 +217,11 @@ mod tests { pass from typing import TYPE_CHECKING - "#, + ", "typing_import_after_usage" )] #[test_case( - r#" + r" from __future__ import annotations from typing import TYPE_CHECKING @@ -233,11 +233,11 @@ mod tests { def f(x: pd.DataFrame): pass - "#, + ", "type_checking_block_own_line" )] #[test_case( - r#" + r" from __future__ import annotations from typing import TYPE_CHECKING @@ -248,11 +248,11 @@ mod tests { def f(x: pd.DataFrame): pass - "#, + ", "type_checking_block_inline" )] #[test_case( - r#" + r" from __future__ import annotations from typing import TYPE_CHECKING @@ -265,11 +265,11 @@ mod tests { def f(x: pd.DataFrame): pass - "#, + ", "type_checking_block_comment" )] #[test_case( - r#" + r" from __future__ import annotations from typing import TYPE_CHECKING @@ -281,11 +281,11 @@ mod tests { if TYPE_CHECKING: import os - "#, + ", "type_checking_block_after_usage" )] #[test_case( - r#" + r" from __future__ import annotations from pandas import ( @@ -295,11 +295,11 @@ mod tests { def f(x: DataFrame): pass - "#, + ", "import_from" )] #[test_case( - r#" + r" from __future__ import annotations from typing import TYPE_CHECKING @@ -314,11 +314,11 @@ mod tests { def f(x: DataFrame): pass - "#, + ", "import_from_type_checking_block" )] #[test_case( - r#" + r" from __future__ import annotations from typing import TYPE_CHECKING @@ -330,11 +330,11 @@ mod tests { def f(x: DataFrame, y: Series): pass - "#, + ", "multiple_members" )] #[test_case( - r#" + r" from __future__ import annotations from typing import TYPE_CHECKING @@ -343,11 +343,11 @@ mod tests { def f(x: os, y: sys): pass - "#, + ", "multiple_modules_same_type" )] #[test_case( - r#" + r" from __future__ import annotations from typing import TYPE_CHECKING @@ -356,7 +356,7 @@ mod tests { def f(x: os, y: pandas): pass - "#, + ", "multiple_modules_different_types" )] fn contents(contents: &str, snapshot: &str) { diff --git a/crates/ruff_linter/src/rules/mccabe/rules/function_is_too_complex.rs b/crates/ruff_linter/src/rules/mccabe/rules/function_is_too_complex.rs index c56ae7e2ed..62a01e6232 100644 --- a/crates/ruff_linter/src/rules/mccabe/rules/function_is_too_complex.rs +++ b/crates/ruff_linter/src/rules/mccabe/rules/function_is_too_complex.rs @@ -166,10 +166,10 @@ mod tests { #[test] fn trivial() -> Result<()> { - let source = r#" + let source = r" def trivial(): pass -"#; +"; let stmts = parse_suite(source, "")?; assert_eq!(get_complexity_number(&stmts), 1); Ok(()) @@ -177,10 +177,10 @@ def trivial(): #[test] fn expr_as_statement() -> Result<()> { - let source = r#" + let source = r" def expr_as_statement(): 0xF00D -"#; +"; let stmts = parse_suite(source, "")?; assert_eq!(get_complexity_number(&stmts), 1); Ok(()) @@ -188,12 +188,12 @@ def expr_as_statement(): #[test] fn sequential() -> Result<()> { - let source = r#" + let source = r" def sequential(n): k = n + 4 s = k + n return s -"#; +"; let stmts = parse_suite(source, "")?; assert_eq!(get_complexity_number(&stmts), 1); Ok(()) @@ -234,11 +234,11 @@ def nested_ifs(): #[test] fn for_loop() -> Result<()> { - let source = r#" + let source = r" def for_loop(): for i in range(10): print(i) -"#; +"; let stmts = parse_suite(source, "")?; assert_eq!(get_complexity_number(&stmts), 2); Ok(()) @@ -246,13 +246,13 @@ def for_loop(): #[test] fn for_else() -> Result<()> { - let source = r#" + let source = r" def for_else(mylist): for i in mylist: print(i) else: print(None) -"#; +"; let stmts = parse_suite(source, "")?; assert_eq!(get_complexity_number(&stmts), 2); Ok(()) @@ -260,13 +260,13 @@ def for_else(mylist): #[test] fn recursive() -> Result<()> { - let source = r#" + let source = r" def recursive(n): if n > 4: return f(n - 1) else: return n -"#; +"; let stmts = parse_suite(source, "")?; assert_eq!(get_complexity_number(&stmts), 2); Ok(()) @@ -274,7 +274,7 @@ def recursive(n): #[test] fn nested_functions() -> Result<()> { - let source = r#" + let source = r" def nested_functions(): def a(): def b(): @@ -283,7 +283,7 @@ def nested_functions(): b() a() -"#; +"; let stmts = parse_suite(source, "")?; assert_eq!(get_complexity_number(&stmts), 3); Ok(()) @@ -291,7 +291,7 @@ def nested_functions(): #[test] fn try_else() -> Result<()> { - let source = r#" + let source = r" def try_else(): try: print(1) @@ -301,7 +301,7 @@ def try_else(): print(3) else: print(4) -"#; +"; let stmts = parse_suite(source, "")?; assert_eq!(get_complexity_number(&stmts), 4); Ok(()) @@ -309,7 +309,7 @@ def try_else(): #[test] fn nested_try_finally() -> Result<()> { - let source = r#" + let source = r" def nested_try_finally(): try: try: @@ -318,7 +318,7 @@ def nested_try_finally(): print(2) finally: print(3) -"#; +"; let stmts = parse_suite(source, "")?; assert_eq!(get_complexity_number(&stmts), 1); Ok(()) @@ -326,7 +326,7 @@ def nested_try_finally(): #[test] fn foobar() -> Result<()> { - let source = r#" + let source = r" async def foobar(a, b, c): await whatever(a, b, c) if await b: @@ -335,7 +335,7 @@ async def foobar(a, b, c): pass async for x in a: pass -"#; +"; let stmts = parse_suite(source, "")?; assert_eq!(get_complexity_number(&stmts), 3); Ok(()) @@ -343,10 +343,10 @@ async def foobar(a, b, c): #[test] fn annotated_assign() -> Result<()> { - let source = r#" + let source = r" def annotated_assign(): x: Any = None -"#; +"; let stmts = parse_suite(source, "")?; assert_eq!(get_complexity_number(&stmts), 1); Ok(()) @@ -354,7 +354,7 @@ def annotated_assign(): #[test] fn class() -> Result<()> { - let source = r#" + let source = r" class Class: def handle(self, *args, **options): if args: @@ -382,7 +382,7 @@ class Class: pass return ServiceProvider(Logger()) -"#; +"; let stmts = parse_suite(source, "")?; assert_eq!(get_complexity_number(&stmts), 9); Ok(()) @@ -390,13 +390,13 @@ class Class: #[test] fn finally() -> Result<()> { - let source = r#" + let source = r" def process_detect_lines(): try: pass finally: pass -"#; +"; let stmts = parse_suite(source, "")?; assert_eq!(get_complexity_number(&stmts), 1); Ok(()) @@ -419,12 +419,12 @@ def process_detect_lines(): #[test] fn with() -> Result<()> { - let source = r#" + let source = r" def with_lock(): with lock: if foo: print('bar') -"#; +"; let stmts = parse_suite(source, "")?; assert_eq!(get_complexity_number(&stmts), 2); Ok(()) diff --git a/crates/ruff_linter/src/rules/pandas_vet/mod.rs b/crates/ruff_linter/src/rules/pandas_vet/mod.rs index 3422fc71ab..f00ad67bef 100644 --- a/crates/ruff_linter/src/rules/pandas_vet/mod.rs +++ b/crates/ruff_linter/src/rules/pandas_vet/mod.rs @@ -30,17 +30,17 @@ mod tests { "PD002_fail" )] #[test_case( - r#" + r" import pandas as pd nas = pd.isna(val) - "#, + ", "PD003_pass" )] #[test_case( - r#" + r" import pandas as pd nulls = pd.isnull(val) - "#, + ", "PD003_fail" )] #[test_case( @@ -51,17 +51,17 @@ mod tests { "PD003_allows_other_calls" )] #[test_case( - r#" + r" import pandas as pd not_nas = pd.notna(val) - "#, + ", "PD004_pass" )] #[test_case( - r#" + r" import pandas as pd not_nulls = pd.notnull(val) - "#, + ", "PD004_fail" )] #[test_case( @@ -73,11 +73,11 @@ mod tests { "PD007_pass_loc" )] #[test_case( - r#" + r" import pandas as pd x = pd.DataFrame() new_x = x.iloc[[1, 3, 5], [1, 3]] - "#, + ", "PD007_pass_iloc" )] #[test_case( @@ -134,19 +134,19 @@ mod tests { "PD008_fail" )] #[test_case( - r#" + r" import pandas as pd x = pd.DataFrame() index = x.iloc[:, 1:3] - "#, + ", "PD009_pass" )] #[test_case( - r#" + r" import pandas as pd x = pd.DataFrame() index = x.iat[:, 1:3] - "#, + ", "PD009_fail" )] #[test_case( @@ -178,80 +178,80 @@ mod tests { "PD010_fail_pivot" )] #[test_case( - r#" + r" import pandas as pd x = pd.DataFrame() result = x.to_array() - "#, + ", "PD011_pass_to_array" )] #[test_case( - r#" + r" import pandas as pd x = pd.DataFrame() result = x.array - "#, + ", "PD011_pass_array" )] #[test_case( - r#" + r" import pandas as pd x = pd.DataFrame() result = x.values - "#, + ", "PD011_fail_values" )] #[test_case( - r#" + r" import pandas as pd x = pd.DataFrame() result = x.values() - "#, + ", "PD011_pass_values_call" )] #[test_case( - r#" + r" import pandas as pd x = pd.DataFrame() x.values = 1 - "#, + ", "PD011_pass_values_store" )] #[test_case( - r#" + r" class Class: def __init__(self, values: str) -> None: self.values = values print(self.values) - "#, + ", "PD011_pass_values_instance" )] #[test_case( - r#" + r" import pandas as pd result = {}.values - "#, + ", "PD011_pass_values_dict" )] #[test_case( - r#" + r" import pandas as pd result = pd.values - "#, + ", "PD011_pass_values_import" )] #[test_case( - r#" + r" import pandas as pd result = x.values - "#, + ", "PD011_pass_values_unbound" )] #[test_case( - r#" + r" import pandas as pd result = values - "#, + ", "PD011_pass_node_name" )] #[test_case( @@ -267,33 +267,33 @@ mod tests { "PD013_pass" )] #[test_case( - r#" + r" import numpy as np arrays = [np.random.randn(3, 4) for _ in range(10)] np.stack(arrays, axis=0).shape - "#, + ", "PD013_pass_numpy" )] #[test_case( - r#" + r" import pandas as pd y = x.stack(level=-1, dropna=True) - "#, + ", "PD013_pass_unbound" )] #[test_case( - r#" + r" import pandas as pd x = pd.DataFrame() y = x.stack(level=-1, dropna=True) - "#, + ", "PD013_fail_stack" )] #[test_case( - r#" + r" import pandas as pd pd.stack( - "#, + ", "PD015_pass_merge_on_dataframe" )] #[test_case( @@ -306,12 +306,12 @@ mod tests { "PD015_pass_merge_on_dataframe_with_multiple_args" )] #[test_case( - r#" + r" import pandas as pd x = pd.DataFrame() y = pd.DataFrame() pd.merge(x, y) - "#, + ", "PD015_fail_merge_on_pandas_object" )] #[test_case( @@ -321,31 +321,31 @@ mod tests { "PD015_pass_other_pd_function" )] #[test_case( - r#" + r" import pandas as pd employees = pd.DataFrame(employee_dict) - "#, + ", "PD901_pass_non_df" )] #[test_case( - r#" + r" import pandas as pd employees_df = pd.DataFrame(employee_dict) - "#, + ", "PD901_pass_part_df" )] #[test_case( - r#" + r" import pandas as pd my_function(df=data) - "#, + ", "PD901_pass_df_param" )] #[test_case( - r#" + r" import pandas as pd df = pd.DataFrame() - "#, + ", "PD901_fail_df_var" )] fn contents(contents: &str, snapshot: &str) { diff --git a/crates/ruff_linter/src/rules/pycodestyle/rules/logical_lines/mod.rs b/crates/ruff_linter/src/rules/pycodestyle/rules/logical_lines/mod.rs index 2ee7025ee7..8fcfca6d76 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/rules/logical_lines/mod.rs +++ b/crates/ruff_linter/src/rules/pycodestyle/rules/logical_lines/mod.rs @@ -518,10 +518,10 @@ mod tests { #[test] fn multi_line() { assert_logical_lines( - r#" + r" x = 1 y = 2 -z = x + 1"# +z = x + 1" .trim(), &["x = 1", "y = 2", "z = x + 1"], ); @@ -530,14 +530,14 @@ z = x + 1"# #[test] fn indented() { assert_logical_lines( - r#" + r" x = [ 1, 2, 3, ] y = 2 -z = x + 1"# +z = x + 1" .trim(), &["x = [\n 1,\n 2,\n 3,\n]", "y = 2", "z = x + 1"], ); @@ -551,11 +551,11 @@ z = x + 1"# #[test] fn function_definition() { assert_logical_lines( - r#" + r" def f(): x = 1 -f()"# - .trim(), +f()" + .trim(), &["def f():", "x = 1", "f()"], ); } @@ -583,11 +583,11 @@ f()"# #[test] fn empty_line() { assert_logical_lines( - r#" + r" if False: print() -"# +" .trim(), &["if False:", "print()", ""], ); diff --git a/crates/ruff_linter/src/rules/pydocstyle/rules/triple_quotes.rs b/crates/ruff_linter/src/rules/pydocstyle/rules/triple_quotes.rs index d9db36f397..773ee26fe7 100644 --- a/crates/ruff_linter/src/rules/pydocstyle/rules/triple_quotes.rs +++ b/crates/ruff_linter/src/rules/pydocstyle/rules/triple_quotes.rs @@ -44,7 +44,7 @@ impl Violation for TripleSingleQuotes { let TripleSingleQuotes { expected_quote } = self; match expected_quote { Quote::Double => format!(r#"Use triple double quotes `"""`"#), - Quote::Single => format!(r#"Use triple single quotes `'''`"#), + Quote::Single => format!(r"Use triple single quotes `'''`"), } } diff --git a/crates/ruff_linter/src/rules/pyflakes/mod.rs b/crates/ruff_linter/src/rules/pyflakes/mod.rs index be2b9040d7..9f10564991 100644 --- a/crates/ruff_linter/src/rules/pyflakes/mod.rs +++ b/crates/ruff_linter/src/rules/pyflakes/mod.rs @@ -311,7 +311,7 @@ mod tests { } #[test_case( - r#" + r" import os def f(): @@ -320,11 +320,11 @@ mod tests { # Despite this `del`, `import os` in `f` should still be flagged as shadowing an unused # import. del os - "#, + ", "del_shadowed_global_import_in_local_scope" )] #[test_case( - r#" + r" import os def f(): @@ -333,11 +333,11 @@ mod tests { # Despite this `del`, `import os` in `f` should still be flagged as shadowing an unused # import. (This is a false negative, but is consistent with Pyflakes.) del os - "#, + ", "del_shadowed_global_import_in_global_scope" )] #[test_case( - r#" + r" def f(): import os import os @@ -345,11 +345,11 @@ mod tests { # Despite this `del`, `import os` should still be flagged as shadowing an unused # import. del os - "#, + ", "del_shadowed_local_import_in_local_scope" )] #[test_case( - r#" + r" import os def f(): @@ -362,11 +362,11 @@ mod tests { # `import os` doesn't need to be flagged as shadowing an import. os = 1 print(os) - "#, + ", "del_shadowed_import_shadow_in_local_scope" )] #[test_case( - r#" + r" x = 1 def foo(): @@ -376,11 +376,11 @@ mod tests { # entirely after the `del` statement. However, it should be an F821 # error, because the name is defined in the scope, but unbound. x += 1 - "#, + ", "augmented_assignment_after_del" )] #[test_case( - r#" + r" def f(): x = 1 @@ -393,11 +393,11 @@ mod tests { # be unbound after the `except` block (assuming an exception is raised # and caught). print(x) - "#, + ", "print_in_body_after_shadowing_except" )] #[test_case( - r#" + r" def f(): x = 1 @@ -412,11 +412,11 @@ mod tests { # be unbound after the `except` block (assuming an exception is raised # and caught). print(x) - "#, + ", "print_in_body_after_double_shadowing_except" )] #[test_case( - r#" + r" def f(): try: x = 3 @@ -424,11 +424,11 @@ mod tests { print(x) else: print(x) - "#, + ", "print_in_try_else_after_shadowing_except" )] #[test_case( - r#" + r" def f(): list = [1, 2, 3] @@ -440,20 +440,20 @@ mod tests { print(e) else: print(e) - "#, + ", "print_in_if_else_after_shadowing_except" )] #[test_case( - r#" + r" def f(): x = 1 del x del x - "#, + ", "double_del" )] #[test_case( - r#" + r" x = 1 def f(): @@ -464,11 +464,11 @@ mod tests { # This should resolve to the `x` in `x = 1`. print(x) - "#, + ", "load_after_unbind_from_module_scope" )] #[test_case( - r#" + r" x = 1 def f(): @@ -484,11 +484,11 @@ mod tests { # This should resolve to the `x` in `x = 1`. print(x) - "#, + ", "load_after_multiple_unbinds_from_module_scope" )] #[test_case( - r#" + r" x = 1 def f(): @@ -505,11 +505,11 @@ mod tests { # This should resolve to the `x` in `x = 1`. print(x) - "#, + ", "load_after_unbind_from_nested_module_scope" )] #[test_case( - r#" + r" class C: x = 1 @@ -522,7 +522,7 @@ mod tests { # This should raise an F821 error, rather than resolving to the # `x` in `x = 1`. print(x) - "#, + ", "load_after_unbind_from_class_scope" )] fn contents(contents: &str, snapshot: &str) { @@ -588,10 +588,10 @@ mod tests { #[test] fn undefined_in_list_comp() { flakes( - r#" + r" [a for a in range(10)] a - "#, + ", &[Rule::UndefinedName], ); } @@ -602,13 +602,13 @@ mod tests { // // The exc variable is unused inside the exception handler. flakes( - r#" + r" try: raise ValueError('ve') except ValueError as exc: pass exc - "#, + ", &[Rule::UnusedVariable, Rule::UndefinedName], ); } @@ -620,13 +620,13 @@ mod tests { // This shows the example in test_undefinedExceptionName is // different. flakes( - r#" + r" try: raise ValueError('ve') except ValueError as exc: e = exc e - "#, + ", &[], ); } @@ -638,14 +638,14 @@ mod tests { // Last line will raise UnboundLocalError. // The exc variable is unused inside the exception handler. flakes( - r#" + r" try: raise ValueError('ve') except ValueError as exc: pass print(exc) exc = 'Original value' - "#, + ", &[Rule::UnusedVariable, Rule::UndefinedName], ); } @@ -654,12 +654,12 @@ mod tests { fn del_exception_in_except() { // The exception name can be deleted in the except: block. flakes( - r#" + r" try: pass except Exception as exc: del exc - "#, + ", &[], ); } @@ -667,12 +667,12 @@ mod tests { #[test] fn functions_need_global_scope() { flakes( - r#" + r" class a: def b(): fu fu = 1 - "#, + ", &[], ); } @@ -723,18 +723,18 @@ mod tests { // name warning if used in class scope. flakes("__module__", &[Rule::UndefinedName]); flakes( - r#" + r" class Foo: __module__ - "#, + ", &[], ); flakes( - r#" + r" class Foo: def bar(self): __module__ - "#, + ", &[Rule::UndefinedName], ); } @@ -745,28 +745,28 @@ mod tests { // name warning if used in class scope. flakes("__qualname__", &[Rule::UndefinedName]); flakes( - r#" + r" class Foo: __qualname__ - "#, + ", &[], ); flakes( - r#" + r" class Foo: def bar(self): __qualname__ - "#, + ", &[Rule::UndefinedName], ); flakes( - r#" + r" def f(): __qualname__ = 1 class Foo: __qualname__ - "#, + ", &[Rule::UnusedVariable], ); } @@ -788,27 +788,27 @@ mod tests { // "global" can make an otherwise undefined name in another function // defined. flakes( - r#" + r" def a(): global fu; fu = 1 def b(): fu - "#, + ", &[], ); flakes( - r#" + r" def c(): bar def b(): global bar; bar = 1 - "#, + ", &[], ); // TODO(charlie): Extract globals recursively (such that we don't raise F821). flakes( - r#" + r" def c(): bar def d(): def b(): global bar; bar = 1 - "#, + ", &[Rule::UndefinedName], ); } @@ -817,10 +817,10 @@ mod tests { fn defined_by_global_multiple_names() { // "global" can accept multiple names. flakes( - r#" + r" def a(): global fu, bar; fu = 1; bar = 2 def b(): fu; bar - "#, + ", &[], ); } @@ -829,11 +829,11 @@ mod tests { fn global_in_global_scope() { // A global statement in the global scope is ignored. flakes( - r#" + r" global x def foo(): print(x) - "#, + ", &[Rule::UndefinedName], ); } @@ -842,13 +842,13 @@ mod tests { fn global_reset_name_only() { // A global statement does not prevent other names being undefined. flakes( - r#" + r" def f1(): s def f2(): global m - "#, + ", &[Rule::UndefinedName], ); } @@ -863,13 +863,13 @@ mod tests { fn del_global() { // Del a global binding from a function. flakes( - r#" + r" a = 1 def f(): global a del a a - "#, + ", &[], ); } @@ -884,13 +884,13 @@ mod tests { fn del_conditional() { // Ignores conditional bindings deletion. flakes( - r#" + r" context = None test = True if False: del(test) assert(test) - "#, + ", &[], ); } @@ -900,14 +900,14 @@ mod tests { // Ignored conditional bindings deletion even if they are nested in other // blocks. flakes( - r#" + r" context = None test = True if False: with context(): del(test) assert(test) - "#, + ", &[], ); } @@ -917,13 +917,13 @@ mod tests { // Ignore bindings deletion if called inside the body of a while // statement. flakes( - r#" + r" def test(): foo = 'bar' while False: del foo assert(foo) - "#, + ", &[], ); } @@ -933,13 +933,13 @@ mod tests { // Ignore bindings deletion if called inside the body of a while // statement and name is used inside while's test part. flakes( - r#" + r" def _worker(): o = True while o is not True: del o o = False - "#, + ", &[], ); } @@ -949,7 +949,7 @@ mod tests { // Ignore bindings deletions if node is part of while's test, even when // del is in a nested block. flakes( - r#" + r" context = None def _worker(): o = True @@ -958,7 +958,7 @@ mod tests { with context(): del o o = False - "#, + ", &[], ); } @@ -967,12 +967,12 @@ mod tests { fn global_from_nested_scope() { // Global names are available from nested scopes. flakes( - r#" + r" a = 1 def b(): def c(): a - "#, + ", &[], ); } @@ -982,13 +982,13 @@ mod tests { // Test that referencing a local name that shadows a global, before it is // defined, generates a warning. flakes( - r#" + r" a = 1 def fun(): a a = 2 return a - "#, + ", &[Rule::UndefinedLocal], ); } @@ -999,7 +999,7 @@ mod tests { // global declared in an enclosing scope, before it is defined, generates // a warning. flakes( - r#" + r" a = 1 def fun(): global a @@ -1007,7 +1007,7 @@ mod tests { a a = 2 return a - "#, + ", &[Rule::UndefinedLocal], ); } @@ -1019,7 +1019,7 @@ mod tests { // warning is emitted, even if there is a class scope between the enclosing // scope and the local scope. flakes( - r#" + r" def f(): x = 1 class g: @@ -1028,7 +1028,7 @@ mod tests { x = None print(x, a) print(x) - "#, + ", &[Rule::UndefinedLocal], ); } @@ -1038,7 +1038,7 @@ mod tests { // Test that referencing a local name in a nested scope that shadows a // global, before it is defined, generates a warning. flakes( - r#" + r" def fun(): a = 1 def fun2(): @@ -1046,7 +1046,7 @@ mod tests { a = 1 return a return a - "#, + ", &[Rule::UndefinedLocal], ); } @@ -1054,7 +1054,7 @@ mod tests { #[test] fn undefined_augmented_assignment() { flakes( - r#" + r" def f(seq): a = 0 seq[a] += 1 @@ -1063,7 +1063,7 @@ mod tests { a -= 3 d += 4 e[any] = 5 - "#, + ", &[ Rule::UndefinedName, Rule::UndefinedName, @@ -1078,7 +1078,7 @@ mod tests { fn nested_class() { // Nested classes can access enclosing scope. flakes( - r#" + r" def f(foo): class C: bar = foo @@ -1087,7 +1087,7 @@ mod tests { return C() f(123).f() - "#, + ", &[], ); } @@ -1096,14 +1096,14 @@ mod tests { fn bad_nested_class() { // Free variables in nested classes must bind at class creation. flakes( - r#" + r" def f(): class C: bar = foo foo = 456 return foo f() - "#, + ", &[Rule::UndefinedName], ); } @@ -1112,10 +1112,10 @@ mod tests { fn defined_as_star_args() { // Star and double-star arg names are defined. flakes( - r#" + r" def f(a, *b, **c): print(a, b, c) - "#, + ", &[], ); } @@ -1124,24 +1124,24 @@ mod tests { fn defined_as_star_unpack() { // Star names in unpack are defined. flakes( - r#" + r" a, *b = range(10) print(a, b) - "#, + ", &[], ); flakes( - r#" + r" *a, b = range(10) print(a, b) - "#, + ", &[], ); flakes( - r#" + r" a, *b, c = range(10) print(a, b, c) - "#, + ", &[], ); } @@ -1151,24 +1151,24 @@ mod tests { // In stable, starred names in unpack are used if RHS is not a tuple/list literal. // In preview, these should be marked as unused. flakes( - r#" + r" def f(): a, *b = range(10) - "#, + ", &[], ); flakes( - r#" + r" def f(): (*a, b) = range(10) - "#, + ", &[], ); flakes( - r#" + r" def f(): [a, *b, c] = range(10) - "#, + ", &[], ); } @@ -1177,18 +1177,18 @@ mod tests { fn keyword_only_args() { // Keyword-only arg names are defined. flakes( - r#" + r" def f(*, a, b=None): print(a, b) - "#, + ", &[], ); flakes( - r#" + r" import default_b def f(*, a, b=default_b): print(a, b) - "#, + ", &[], ); } @@ -1197,10 +1197,10 @@ mod tests { fn keyword_only_args_undefined() { // Typo in kwonly name. flakes( - r#" + r" def f(*, a, b=default_c): print(a, b) - "#, + ", &[Rule::UndefinedName], ); } @@ -1209,20 +1209,20 @@ mod tests { fn annotation_undefined() { // Undefined annotations. flakes( - r#" + r" from abc import note1, note2, note3, note4, note5 def func(a: note1, *args: note2, b: note3=12, **kw: note4) -> note5: pass - "#, + ", &[], ); flakes( - r#" + r" def func(): d = e = 42 def func(a: {1, d}) -> (lambda c: e): pass - "#, + ", &[], ); } @@ -1230,10 +1230,10 @@ mod tests { #[test] fn meta_class_undefined() { flakes( - r#" + r" from abc import ABCMeta class A(metaclass=ABCMeta): pass - "#, + ", &[], ); } @@ -1267,12 +1267,12 @@ mod tests { // Some compatibility code checks explicitly for NameError. // It should not trigger warnings. flakes( - r#" + r" try: socket_map except NameError: socket_map = {} - "#, + ", &[], ); flakes( @@ -1286,21 +1286,21 @@ mod tests { ); // If NameError is not explicitly handled, generate a warning. flakes( - r#" + r" try: socket_map except: socket_map = {} - "#, + ", &[Rule::UndefinedName], ); flakes( - r#" + r" try: socket_map except Exception: socket_map = {} - "#, + ", &[Rule::UndefinedName], ); } @@ -1309,30 +1309,30 @@ mod tests { fn defined_in_class() { // Defined name for generator expressions and dict/set comprehension. flakes( - r#" + r" class A: T = range(10) Z = (x for x in T) L = [x for x in T] B = dict((i, str(i)) for i in T) - "#, + ", &[], ); flakes( - r#" + r" class A: T = range(10) X = {x for x in T} Y = {x:x for x in T} - "#, + ", &[], ); flakes( - r#" + r" class A: T = 1 @@ -1340,7 +1340,7 @@ mod tests { X = (T for x in range(10)) Y = [x for x in range(10) if T] Z = [x for x in range(10) for y in T] - "#, + ", &[ Rule::UndefinedName, Rule::UndefinedName, @@ -1353,12 +1353,12 @@ mod tests { fn defined_in_class_nested() { // Defined name for nested generator expressions in a class. flakes( - r#" + r" class A: T = range(10) Z = (x for x in (a for a in T)) - "#, + ", &[], ); } @@ -1367,22 +1367,22 @@ mod tests { fn undefined_in_loop() { // The loop variable is defined after the expression is computed. flakes( - r#" + r" for i in range(i): print(i) - "#, + ", &[Rule::UndefinedName], ); flakes( - r#" + r" [42 for i in range(i)] - "#, + ", &[Rule::UndefinedName], ); flakes( - r#" + r" (42 for i in range(i)) - "#, + ", &[Rule::UndefinedName], ); } @@ -1392,9 +1392,9 @@ mod tests { // Defined name referenced from a lambda function within a dict/set // comprehension. flakes( - r#" + r" {lambda: id(x) for x in range(10)} - "#, + ", &[], ); } @@ -1404,9 +1404,9 @@ mod tests { // Defined name referenced from a lambda function within a generator // expression. flakes( - r#" + r" any(lambda: id(x) for x in range(10)) - "#, + ", &[], ); } @@ -1416,9 +1416,9 @@ mod tests { // Undefined name referenced from a lambda function within a dict/set // comprehension. flakes( - r#" + r" {lambda: id(y) for x in range(10)} - "#, + ", &[Rule::UndefinedName], ); } @@ -1428,9 +1428,9 @@ mod tests { // Undefined name referenced from a lambda function within a generator // expression. flakes( - r#" + r" any(lambda: id(y) for x in range(10)) - "#, + ", &[Rule::UndefinedName], ); } @@ -1438,18 +1438,18 @@ mod tests { #[test] fn dunder_class() { flakes( - r#" + r" class Test(object): def __init__(self): print(__class__.__name__) self.x = 1 t = Test() - "#, + ", &[], ); flakes( - r#" + r" class Test(object): print(__class__.__name__) @@ -1457,11 +1457,11 @@ mod tests { self.x = 1 t = Test() - "#, + ", &[Rule::UndefinedName], ); flakes( - r#" + r" class Test(object): X = [__class__ for _ in range(10)] @@ -1469,17 +1469,17 @@ mod tests { self.x = 1 t = Test() - "#, + ", &[Rule::UndefinedName], ); flakes( - r#" + r" def f(self): print(__class__.__name__) self.x = 1 f() - "#, + ", &[Rule::UndefinedName], ); } @@ -1554,13 +1554,13 @@ mod tests { // Test that importing a module twice within an if // block does raise a warning. flakes( - r#" + r" i = 2 if i==1: import os import os os.path - "#, + ", &[Rule::RedefinedWhileUnused], ); } @@ -1570,14 +1570,14 @@ mod tests { // Test that importing a module twice in if // and else blocks does not raise a warning. flakes( - r#" + r" i = 2 if i==1: import os else: import os os.path - "#, + ", &[], ); } @@ -1587,14 +1587,14 @@ mod tests { // Test that importing a module twice in a try block // does raise a warning. flakes( - r#" + r" try: import os import os except: pass os.path - "#, + ", &[Rule::RedefinedWhileUnused], ); } @@ -1604,13 +1604,13 @@ mod tests { // Test that importing a module twice in a try // and except block does not raise a warning. flakes( - r#" + r" try: import os except: import os os.path - "#, + ", &[], ); } @@ -1620,7 +1620,7 @@ mod tests { // Test that importing a module twice using a nested // try/except and if blocks does not issue a warning. flakes( - r#" + r" try: if True: if True: @@ -1628,7 +1628,7 @@ mod tests { except: import os os.path - "#, + ", &[], ); } @@ -1636,7 +1636,7 @@ mod tests { #[test] fn redefined_try_except_multi() { flakes( - r#" + r" try: from aa import mixer except AttributeError: @@ -1646,7 +1646,7 @@ mod tests { except: from dd import mixer mixer(123) - "#, + ", &[], ); } @@ -1654,7 +1654,7 @@ mod tests { #[test] fn redefined_try_else() { flakes( - r#" + r" try: from aa import mixer except ImportError: @@ -1662,7 +1662,7 @@ mod tests { else: from bb import mixer mixer(123) - "#, + ", &[Rule::RedefinedWhileUnused], ); } @@ -1670,7 +1670,7 @@ mod tests { #[test] fn redefined_try_except_else() { flakes( - r#" + r" try: import funca except ImportError: @@ -1679,7 +1679,7 @@ mod tests { else: from bbb import funcb print(funca, funcb) - "#, + ", &[], ); } @@ -1687,7 +1687,7 @@ mod tests { #[test] fn redefined_try_except_finally() { flakes( - r#" + r" try: from aa import a except ImportError: @@ -1695,7 +1695,7 @@ mod tests { finally: a = 42 print(a) - "#, + ", &[], ); } @@ -1703,7 +1703,7 @@ mod tests { #[test] fn redefined_try_except_else_finally() { flakes( - r#" + r" try: import b except ImportError: @@ -1714,7 +1714,7 @@ mod tests { finally: a = 42 print(a, b) - "#, + ", &[], ); } @@ -1722,11 +1722,11 @@ mod tests { #[test] fn redefined_by_function() { flakes( - r#" + r" import fu def fu(): pass - "#, + ", &[Rule::RedefinedWhileUnused], ); } @@ -1736,13 +1736,13 @@ mod tests { // Test that shadowing a global name with a nested function definition // generates a warning. flakes( - r#" + r" import fu def bar(): def baz(): def fu(): pass - "#, + ", &[Rule::UnusedImport, Rule::RedefinedWhileUnused], ); } @@ -1752,14 +1752,14 @@ mod tests { // Test that shadowing a global name with a nested function definition // generates a warning. flakes( - r#" + r" import fu def bar(): import fu def baz(): def fu(): pass - "#, + ", &[ Rule::UnusedImport, Rule::RedefinedWhileUnused, @@ -1774,7 +1774,7 @@ mod tests { // Test that a global import which is redefined locally, // but used later in another scope does not generate a warning. flakes( - r#" + r" import unittest, transport class GetTransportTestCase(unittest.TestCase): @@ -1784,7 +1784,7 @@ mod tests { class TestTransportMethodArgs(unittest.TestCase): def test_send_defaults(self): - transport.Transport()"#, + transport.Transport()", &[], ); } @@ -1792,11 +1792,11 @@ mod tests { #[test] fn redefined_by_class() { flakes( - r#" + r" import fu class fu: pass - "#, + ", &[Rule::RedefinedWhileUnused], ); } @@ -1806,11 +1806,11 @@ mod tests { // If an imported name is redefined by a class statement which also uses // that name in the bases list, no warning is emitted. flakes( - r#" + r" from fu import bar class bar(bar): pass - "#, + ", &[], ); } @@ -1820,12 +1820,12 @@ mod tests { // Test that shadowing a global with a class attribute does not produce a // warning. flakes( - r#" + r" import fu class bar: fu = 1 print(fu) - "#, + ", &[], ); } @@ -1834,20 +1834,20 @@ mod tests { fn import_in_class() { // Test that import within class is a locally scoped attribute. flakes( - r#" + r" class bar: import fu - "#, + ", &[], ); flakes( - r#" + r" class bar: import fu fu - "#, + ", &[Rule::UndefinedName], ); } @@ -1855,11 +1855,11 @@ mod tests { #[test] fn used_in_function() { flakes( - r#" + r" import fu def fun(): print(fu) - "#, + ", &[], ); } @@ -1867,21 +1867,21 @@ mod tests { #[test] fn shadowed_by_parameter() { flakes( - r#" + r" import fu def fun(fu): print(fu) - "#, + ", &[Rule::UnusedImport, Rule::RedefinedWhileUnused], ); flakes( - r#" + r" import fu def fun(fu): print(fu) print(fu) - "#, + ", &[], ); } @@ -1905,10 +1905,10 @@ mod tests { #[test] fn used_in_if_body() { flakes( - r#" + r" import fu if True: print(fu) - "#, + ", &[], ); } @@ -1916,10 +1916,10 @@ mod tests { #[test] fn used_in_if_conditional() { flakes( - r#" + r" import fu if fu: pass - "#, + ", &[], ); } @@ -1927,11 +1927,11 @@ mod tests { #[test] fn used_in_elif_conditional() { flakes( - r#" + r" import fu if False: pass elif fu: pass - "#, + ", &[], ); } @@ -1939,11 +1939,11 @@ mod tests { #[test] fn used_in_else() { flakes( - r#" + r" import fu if False: pass else: print(fu) - "#, + ", &[], ); } @@ -1956,11 +1956,11 @@ mod tests { #[test] fn used_in_class() { flakes( - r#" + r" import fu class bar: bar = fu - "#, + ", &[], ); } @@ -1968,11 +1968,11 @@ mod tests { #[test] fn used_in_class_base() { flakes( - r#" + r" import fu class bar(object, fu.baz): pass - "#, + ", &[], ); } @@ -1980,12 +1980,12 @@ mod tests { #[test] fn not_used_in_nested_scope() { flakes( - r#" + r" import fu def bleh(): pass print(fu) - "#, + ", &[], ); } @@ -1993,11 +1993,11 @@ mod tests { #[test] fn used_in_for() { flakes( - r#" + r" import fu for bar in range(9): print(fu) - "#, + ", &[], ); } @@ -2005,13 +2005,13 @@ mod tests { #[test] fn used_in_for_else() { flakes( - r#" + r" import fu for bar in range(10): pass else: print(fu) - "#, + ", &[], ); } @@ -2019,11 +2019,11 @@ mod tests { #[test] fn redefined_by_for() { flakes( - r#" + r" import fu for fu in range(2): pass - "#, + ", &[Rule::ImportShadowedByLoopVar], ); } @@ -2033,12 +2033,12 @@ mod tests { // Test that shadowing a global name with a for loop variable generates a // warning. flakes( - r#" + r" import fu fu.bar() for fu in (): pass - "#, + ", &[Rule::ImportShadowedByLoopVar], ); } @@ -2048,21 +2048,21 @@ mod tests { // Test that shadowing a global name with a for loop variable nested in a // tuple unpack generates a warning. flakes( - r#" + r" import fu fu.bar() for (x, y, z, (a, b, c, (fu,))) in (): pass - "#, + ", &[Rule::ImportShadowedByLoopVar], ); flakes( - r#" + r" import fu fu.bar() for [x, y, z, (a, b, c, (fu,))] in (): pass - "#, + ", &[Rule::ImportShadowedByLoopVar], ); } @@ -2070,11 +2070,11 @@ mod tests { #[test] fn used_in_return() { flakes( - r#" + r" import fu def fun(): return fu - "#, + ", &[], ); } @@ -2128,11 +2128,11 @@ mod tests { #[test] fn used_in_try() { flakes( - r#" + r" import fu try: fu except: pass - "#, + ", &[], ); } @@ -2140,11 +2140,11 @@ mod tests { #[test] fn used_in_except() { flakes( - r#" + r" import fu try: fu except: pass - "#, + ", &[], ); } @@ -2152,11 +2152,11 @@ mod tests { #[test] fn redefined_by_except() { flakes( - r#" + r" import fu try: pass except Exception as fu: pass - "#, + ", &[Rule::UnusedVariable, Rule::RedefinedWhileUnused], ); } @@ -2164,10 +2164,10 @@ mod tests { #[test] fn used_in_raise() { flakes( - r#" + r" import fu raise fu.bar - "#, + ", &[], ); } @@ -2175,11 +2175,11 @@ mod tests { #[test] fn used_in_yield() { flakes( - r#" + r" import fu def gen(): yield fu - "#, + ", &[], ); } @@ -2193,11 +2193,11 @@ mod tests { #[test] fn used_in_parameter_default() { flakes( - r#" + r" import fu def f(bar=fu): pass - "#, + ", &[], ); } @@ -2227,20 +2227,20 @@ mod tests { #[test] fn used_in_try_finally() { flakes( - r#" + r" import fu try: pass finally: fu - "#, + ", &[], ); flakes( - r#" + r" import fu try: fu finally: pass - "#, + ", &[], ); } @@ -2248,19 +2248,19 @@ mod tests { #[test] fn used_in_while() { flakes( - r#" + r" import fu while 0: fu - "#, + ", &[], ); flakes( - r#" + r" import fu while fu: pass - "#, + ", &[], ); } @@ -2270,10 +2270,10 @@ mod tests { // A 'global' statement shadowing an unused import should not prevent it // from being reported. flakes( - r#" + r" import fu def f(): global fu - "#, + ", &[Rule::UnusedImport], ); } @@ -2283,11 +2283,11 @@ mod tests { // A 'global' statement shadowing a used import should not cause it to be // reported as unused. flakes( - r#" + r" import foo def f(): global foo def g(): foo.is_used() - "#, + ", &[], ); } @@ -2297,10 +2297,10 @@ mod tests { // Binding an import to a declared global should not cause it to be // reported as unused. flakes( - r#" + r" def f(): global foo; import foo def g(): foo.is_used() - "#, + ", &[], ); } @@ -2313,9 +2313,9 @@ mod tests { #[test] fn used_in_lambda() { flakes( - r#"import fu; + r"import fu; lambda: fu - "#, + ", &[], ); } @@ -2342,11 +2342,11 @@ mod tests { #[test] fn unused_in_nested_scope() { flakes( - r#" + r" def bar(): import fu fu - "#, + ", &[Rule::UnusedImport, Rule::UndefinedName], ); } @@ -2354,12 +2354,12 @@ mod tests { #[test] fn methods_dont_use_class_scope() { flakes( - r#" + r" class bar: import fu def fun(self): fu - "#, + ", &[Rule::UndefinedName], ); } @@ -2367,12 +2367,12 @@ mod tests { #[test] fn nested_functions_nest_scope() { flakes( - r#" + r" def a(): def b(): fu import fu - "#, + ", &[], ); } @@ -2380,13 +2380,13 @@ mod tests { #[test] fn nested_class_and_function_scope() { flakes( - r#" + r" def a(): import fu class b: def c(self): print(fu) - "#, + ", &[], ); } @@ -2395,10 +2395,10 @@ mod tests { fn package_import() { // If a dotted name is imported and used, no warning is reported. flakes( - r#" + r" import fu.bar fu.bar - "#, + ", &[], ); } @@ -2415,18 +2415,18 @@ mod tests { // If a submodule of a package is imported twice, an unused import warning and a // redefined while unused warning are reported. flakes( - r#" + r" import fu.bar, fu.bar fu.bar - "#, + ", &[Rule::RedefinedWhileUnused], ); flakes( - r#" + r" import fu.bar import fu.bar fu.bar - "#, + ", &[Rule::RedefinedWhileUnused], ); } @@ -2436,18 +2436,18 @@ mod tests { // If two different submodules of a package are imported, no duplicate import // warning is reported for the package. flakes( - r#" + r" import fu.bar, fu.baz fu.bar, fu.baz - "#, + ", &[], ); flakes( - r#" + r" import fu.bar import fu.baz fu.bar, fu.baz - "#, + ", &[], ); } @@ -2455,38 +2455,38 @@ mod tests { #[test] fn aliased_submodule_import() { flakes( - r#" + r" import fu.bar as baz import fu.bar as baz baz - "#, + ", &[Rule::RedefinedWhileUnused], ); flakes( - r#" + r" import fu.bar as baz import baz baz - "#, + ", &[Rule::RedefinedWhileUnused], ); flakes( - r#" + r" import fu.bar as baz import fu.bar as bop baz, bop - "#, + ", &[], ); flakes( - r#" + r" import foo.baz import foo.baz as foo foo - "#, + ", &[Rule::RedefinedWhileUnused], ); } @@ -2495,20 +2495,20 @@ mod tests { fn used_package_with_submodule_import() { // Usage of package marks submodule imports as used. flakes( - r#" + r" import fu import fu.bar fu.x - "#, + ", &[], ); flakes( - r#" + r" import fu.bar import fu fu.x - "#, + ", &[], ); } @@ -2517,20 +2517,20 @@ mod tests { fn used_package_with_submodule_import_of_alias() { // Usage of package by alias marks submodule imports as used. flakes( - r#" + r" import foo as f import foo.bar f.bar.do_something() - "#, + ", &[], ); flakes( - r#" + r" import foo as f import foo.bar.blah f.bar.blah.do_something() - "#, + ", &[], ); } @@ -2539,10 +2539,10 @@ mod tests { fn unused_package_with_submodule_import() { // When a package and its submodule are imported, only report once. flakes( - r#" + r" import fu import fu.bar - "#, + ", &[Rule::UnusedImport], ); } @@ -2558,13 +2558,13 @@ mod tests { #[test] fn trying_multiple_imports() { flakes( - r#" + r" try: import fu except ImportError: import bar as fu fu - "#, + ", &[], ); } @@ -2572,13 +2572,13 @@ mod tests { #[test] fn non_global_does_not_redefine() { flakes( - r#" + r" import fu def a(): fu = 3 return fu fu - "#, + ", &[], ); } @@ -2586,11 +2586,11 @@ mod tests { #[test] fn functions_run_later() { flakes( - r#" + r" def a(): fu import fu - "#, + ", &[], ); } @@ -2598,12 +2598,12 @@ mod tests { #[test] fn function_names_are_bound_now() { flakes( - r#" + r" import fu def fu(): fu fu - "#, + ", &[Rule::RedefinedWhileUnused], ); } @@ -2617,12 +2617,12 @@ mod tests { fn imported_in_class() { // Imports in class scope can be used through self. flakes( - r#" + r" class C: import i def __init__(self): self.i - "#, + ", &[], ); } @@ -2631,13 +2631,13 @@ mod tests { fn import_used_in_method_definition() { // Method named 'foo' with default args referring to module named 'foo'. flakes( - r#" + r" import foo class Thing(object): def foo(self, parser=foo.parse_foo): pass - "#, + ", &[], ); } @@ -2659,18 +2659,18 @@ mod tests { fn future_import_first() { // __future__ imports must come before anything else. flakes( - r#" + r" x = 5 from __future__ import division - "#, + ", &[Rule::LateFutureImport], ); flakes( - r#" + r" from foo import bar from __future__ import division bar - "#, + ", &[Rule::LateFutureImport], ); } @@ -2679,12 +2679,12 @@ mod tests { fn future_import_used() { // __future__ is special, but names are injected in the namespace. flakes( - r#" + r" from __future__ import division from __future__ import print_function assert print_function is not division - "#, + ", &[], ); } @@ -2693,9 +2693,9 @@ mod tests { fn future_import_undefined() { // Importing undefined names from __future__ fails. flakes( - r#" + r" from __future__ import print_statement - "#, + ", &[Rule::FutureFeatureNotDefined], ); } @@ -2704,9 +2704,9 @@ mod tests { fn future_import_star() { // Importing '*' from __future__ fails. flakes( - r#" + r" from __future__ import * - "#, + ", &[Rule::FutureFeatureNotDefined], ); } @@ -2773,14 +2773,14 @@ mod tests { fn augmented_assignment() { // The C{__all__} variable is defined incrementally. flakes( - r#" + r" import a import c __all__ = ['a'] __all__ += ['b'] if 1 < 3: __all__ += ['c', 'd'] - "#, + ", &[Rule::UndefinedExport, Rule::UndefinedExport], ); } @@ -2789,10 +2789,10 @@ mod tests { fn list_concatenation_assignment() { // The C{__all__} variable is defined through list concatenation. flakes( - r#" + r" import sys __all__ = ['a'] + ['b'] + ['c'] - "#, + ", &[ Rule::UnusedImport, Rule::UndefinedExport, @@ -2806,10 +2806,10 @@ mod tests { fn tuple_concatenation_assignment() { // The C{__all__} variable is defined through tuple concatenation. flakes( - r#" + r" import sys __all__ = ('a',) + ('b',) + ('c',) - "#, + ", &[ Rule::UnusedImport, Rule::UndefinedExport, @@ -2822,10 +2822,10 @@ mod tests { #[test] fn all_with_attributes() { flakes( - r#" + r" from foo import bar __all__ = [bar.__name__] - "#, + ", &[], ); } @@ -2833,10 +2833,10 @@ mod tests { #[test] fn all_with_names() { flakes( - r#" + r" from foo import bar __all__ = [bar] - "#, + ", &[], ); } @@ -2844,11 +2844,11 @@ mod tests { #[test] fn all_with_attributes_added() { flakes( - r#" + r" from foo import bar from bar import baz __all__ = [bar.__name__] + [baz.__name__] - "#, + ", &[], ); } @@ -2856,11 +2856,11 @@ mod tests { #[test] fn all_mixed_attributes_and_strings() { flakes( - r#" + r" from foo import bar from foo import baz __all__ = ['bar', baz.__name__] - "#, + ", &[], ); } @@ -2880,11 +2880,11 @@ mod tests { fn import_star_exported() { // Report undefined if import * is used flakes( - r#" + r" from math import * __all__ = ['sin', 'cos'] csc(1) - "#, + ", &[ Rule::UndefinedLocalWithImportStar, Rule::UndefinedLocalWithImportStarUsage, @@ -2899,11 +2899,11 @@ mod tests { fn import_star_not_exported() { // Report unused import when not needed to satisfy __all__. flakes( - r#" + r" from foolib import * a = 1 __all__ = ['a'] - "#, + ", &[Rule::UndefinedLocalWithImportStar, Rule::UnusedImport], ); } @@ -2966,12 +2966,12 @@ mod tests { // but using an undefined name as a class decorator results in an // undefined name warning. flakes( - r#" + r" from interior import decorate @decorate class foo: pass - "#, + ", &[], ); @@ -2986,11 +2986,11 @@ mod tests { ); flakes( - r#" + r" @decorate class foo: pass - "#, + ", &[Rule::UndefinedName], ); } @@ -3000,7 +3000,7 @@ mod tests { fn typing_overload() { // Allow intentional redefinitions via @typing.overload. flakes( - r#" + r" import typing from typing import overload @@ -3025,7 +3025,7 @@ mod tests { def g(s): return s - "#, + ", &[], ); } @@ -3034,7 +3034,7 @@ mod tests { fn typing_extensions_overload() { // Allow intentional redefinitions via @typing_extensions.overload. flakes( - r#" + r" import typing_extensions from typing_extensions import overload @@ -3059,7 +3059,7 @@ mod tests { def g(s): return s - "#, + ", &[], ); } @@ -3068,7 +3068,7 @@ mod tests { fn typing_overload_async() { // Allow intentional redefinitions via @typing.overload (async). flakes( - r#" + r" from typing import overload @overload @@ -3081,7 +3081,7 @@ mod tests { async def f(s): return s - "#, + ", &[], ); } @@ -3089,7 +3089,7 @@ mod tests { #[test] fn overload_with_multiple_decorators() { flakes( - r#" + r" from typing import overload dec = lambda f: f @@ -3105,7 +3105,7 @@ mod tests { @dec def f(x): return x - "#, + ", &[], ); } @@ -3113,7 +3113,7 @@ mod tests { #[test] fn overload_in_class() { flakes( - r#" + r" from typing import overload class C: @@ -3126,7 +3126,7 @@ mod tests { pass def f(self, x): return x - "#, + ", &[], ); } @@ -3135,7 +3135,7 @@ mod tests { fn aliased_typing_import() { // Detect when typing is imported as another name. flakes( - r#" + r" import typing as t @t.overload @@ -3148,7 +3148,7 @@ mod tests { def f(s): return s - "#, + ", &[], ); } @@ -3157,7 +3157,7 @@ mod tests { fn not_a_typing_overload() { // regression test for @typing.overload detection bug in 2.1.0. flakes( - r#" + r" def foo(x): return x @@ -3167,7 +3167,7 @@ mod tests { def bar(): pass - "#, + ", &[Rule::RedefinedWhileUnused], ); } @@ -3175,50 +3175,50 @@ mod tests { #[test] fn variable_annotations() { flakes( - r#" + r" name: str age: int - "#, + ", &[], ); flakes( - r#" + r" name: str = 'Bob' age: int = 18 - "#, + ", &[], ); flakes( - r#" + r" class C: name: str age: int - "#, + ", &[], ); flakes( - r#" + r" class C: name: str = 'Bob' age: int = 18 - "#, + ", &[], ); flakes( - r#" + r" def f(): name: str age: int - "#, + ", &[Rule::UnusedAnnotation, Rule::UnusedAnnotation], ); flakes( - r#" + r" def f(): name: str = 'Bob' age: int = 18 foo: not_a_real_type = None - "#, + ", &[ Rule::UnusedVariable, Rule::UnusedVariable, @@ -3227,217 +3227,217 @@ mod tests { ], ); flakes( - r#" + r" def f(): name: str print(name) - "#, + ", &[Rule::UndefinedName], ); flakes( - r#" + r" from typing import Any def f(): a: Any - "#, + ", &[Rule::UnusedAnnotation], ); flakes( - r#" + r" foo: not_a_real_type - "#, + ", &[Rule::UndefinedName], ); flakes( - r#" + r" foo: not_a_real_type = None - "#, + ", &[Rule::UndefinedName], ); flakes( - r#" + r" class C: foo: not_a_real_type - "#, + ", &[Rule::UndefinedName], ); flakes( - r#" + r" class C: foo: not_a_real_type = None - "#, + ", &[Rule::UndefinedName], ); flakes( - r#" + r" def f(): class C: foo: not_a_real_type - "#, + ", &[Rule::UndefinedName], ); flakes( - r#" + r" def f(): class C: foo: not_a_real_type = None - "#, + ", &[Rule::UndefinedName], ); flakes( - r#" + r" from foo import Bar bar: Bar - "#, + ", &[], ); flakes( - r#" + r" from foo import Bar bar: 'Bar' - "#, + ", &[], ); flakes( - r#" + r" import foo bar: foo.Bar - "#, + ", &[], ); flakes( - r#" + r" import foo bar: 'foo.Bar' - "#, + ", &[], ); flakes( - r#" + r" from foo import Bar def f(bar: Bar): pass - "#, + ", &[], ); flakes( - r#" + r" from foo import Bar def f(bar: 'Bar'): pass - "#, + ", &[], ); flakes( - r#" + r" from foo import Bar def f(bar) -> Bar: return bar - "#, + ", &[], ); flakes( - r#" + r" from foo import Bar def f(bar) -> 'Bar': return bar - "#, + ", &[], ); flakes( - r#" + r" bar: 'Bar' - "#, + ", &[Rule::UndefinedName], ); flakes( - r#" + r" bar: 'foo.Bar' - "#, + ", &[Rule::UndefinedName], ); flakes( - r#" + r" from foo import Bar bar: str - "#, + ", &[Rule::UnusedImport], ); flakes( - r#" + r" from foo import Bar def f(bar: str): pass - "#, + ", &[Rule::UnusedImport], ); flakes( - r#" + r" def f(a: A) -> A: pass class A: pass - "#, + ", &[Rule::UndefinedName, Rule::UndefinedName], ); flakes( - r#" + r" def f(a: 'A') -> 'A': return a class A: pass - "#, + ", &[], ); flakes( - r#" + r" a: A class A: pass - "#, + ", &[Rule::UndefinedName], ); flakes( - r#" + r" a: 'A' class A: pass - "#, + ", &[], ); flakes( - r#" + r" T: object def f(t: T): pass - "#, + ", &[Rule::UndefinedName], ); flakes( - r#" + r" T: object def g(t: 'T'): pass - "#, + ", &[Rule::UndefinedName], ); flakes( - r#" + r" T = object def f(t: T): pass - "#, + ", &[], ); flakes( - r#" + r" T = object def g(t: 'T'): pass - "#, + ", &[], ); flakes( - r#" + r" a: 'A B' - "#, + ", &[Rule::ForwardAnnotationSyntaxError], ); flakes( - r#" + r" a: 'A; B' - "#, + ", &[Rule::ForwardAnnotationSyntaxError], ); flakes( - r#" + r" a: '1 + 2' - "#, + ", &[], ); flakes( @@ -3451,9 +3451,9 @@ mod tests { #[test] fn variable_annotation_references_self_name_undefined() { flakes( - r#" + r" x: int = x - "#, + ", &[Rule::UndefinedName], ); } @@ -3461,58 +3461,58 @@ mod tests { #[test] fn use_pep695_type_aliass() { flakes( - r#" + r" from typing_extensions import TypeAlias from foo import Bar bar: TypeAlias = Bar - "#, + ", &[], ); flakes( - r#" + r" from typing_extensions import TypeAlias from foo import Bar bar: TypeAlias = 'Bar' - "#, + ", &[], ); flakes( - r#" + r" from typing_extensions import TypeAlias from foo import Bar class A: bar: TypeAlias = Bar - "#, + ", &[], ); flakes( - r#" + r" from typing_extensions import TypeAlias from foo import Bar class A: bar: TypeAlias = 'Bar' - "#, + ", &[], ); flakes( - r#" + r" from typing_extensions import TypeAlias bar: TypeAlias - "#, + ", &[], ); flakes( - r#" + r" from typing_extensions import TypeAlias from foo import Bar bar: TypeAlias - "#, + ", &[Rule::UnusedImport], ); } @@ -3520,11 +3520,11 @@ mod tests { #[test] fn annotating_an_import() { flakes( - r#" + r" from a import b, c b: c print(b) - "#, + ", &[], ); } @@ -3533,27 +3533,27 @@ mod tests { fn unused_annotation() { // Unused annotations are fine in module and class scope. flakes( - r#" + r" x: int class Cls: y: int - "#, + ", &[], ); flakes( - r#" + r" def f(): x: int - "#, + ", &[Rule::UnusedAnnotation], ); // This should only print one UnusedVariable message. flakes( - r#" + r" def f(): x: int x = 3 - "#, + ", &[Rule::UnusedVariable], ); } @@ -3561,10 +3561,10 @@ mod tests { #[test] fn unassigned_annotation_is_undefined() { flakes( - r#" + r" name: str print(name) - "#, + ", &[Rule::UndefinedName], ); } @@ -3572,10 +3572,10 @@ mod tests { #[test] fn annotated_async_def() { flakes( - r#" + r" class c: pass async def func(c: c) -> None: pass - "#, + ", &[], ); } @@ -3583,44 +3583,44 @@ mod tests { #[test] fn postponed_annotations() { flakes( - r#" + r" from __future__ import annotations def f(a: A) -> A: pass class A: b: B class B: pass - "#, + ", &[], ); flakes( - r#" + r" from __future__ import annotations def f(a: A) -> A: pass class A: b: Undefined class B: pass - "#, + ", &[Rule::UndefinedName], ); flakes( - r#" + r" from __future__ import annotations T: object def f(t: T): pass def g(t: 'T'): pass - "#, + ", &[Rule::UndefinedName, Rule::UndefinedName], ); flakes( - r#" + r" from __future__ import annotations T = object def f(t: T): pass def g(t: 'T'): pass - "#, + ", &[], ); } @@ -3645,14 +3645,14 @@ mod tests { #[test] fn return_annotation_is_class_scope_variable() { flakes( - r#" + r" from typing import TypeVar class Test: Y = TypeVar('Y') def t(self, x: Y) -> Y: return x - "#, + ", &[], ); } @@ -3660,12 +3660,12 @@ mod tests { #[test] fn return_annotation_is_function_body_variable() { flakes( - r#" + r" class Test: def t(self) -> Y: Y = 2 return Y - "#, + ", &[Rule::UndefinedName], ); } @@ -3673,11 +3673,11 @@ mod tests { #[test] fn positional_only_argument_annotations() { flakes( - r#" + r" from x import C def f(c: C, /): ... - "#, + ", &[], ); } @@ -3685,13 +3685,13 @@ mod tests { #[test] fn partially_quoted_type_annotation() { flakes( - r#" + r" from queue import Queue from typing import Optional def f() -> Optional['Queue[str]']: return None - "#, + ", &[], ); } @@ -3699,12 +3699,12 @@ mod tests { #[test] fn partially_quoted_type_assignment() { flakes( - r#" + r" from queue import Queue from typing import Optional MaybeQueue = Optional['Queue[str]'] - "#, + ", &[], ); } @@ -3712,12 +3712,12 @@ mod tests { #[test] fn nested_partially_quoted_type_assignment() { flakes( - r#" + r" from queue import Queue from typing import Callable Func = Callable[['Queue[str]'], None] - "#, + ", &[], ); } @@ -3725,11 +3725,11 @@ mod tests { #[test] fn quoted_type_cast() { flakes( - r#" + r" from typing import cast, Optional maybe_int = cast('Optional[int]', 42) - "#, + ", &[], ); } @@ -3740,11 +3740,11 @@ mod tests { // argument to `cast` doesn't cause issues when (only) the _second_ // argument is a literal str which looks a bit like a type annotation. flakes( - r#" + r" from typing import cast a_string = cast(str, 'Optional[int]') - "#, + ", &[], ); } @@ -3752,11 +3752,11 @@ mod tests { #[test] fn quoted_type_cast_renamed_import() { flakes( - r#" + r" from typing import cast as tsac, Optional as Maybe maybe_int = tsac('Maybe[int]', 42) - "#, + ", &[], ); } @@ -3764,11 +3764,11 @@ mod tests { #[test] fn quoted_type_var_constraints() { flakes( - r#" + r" from typing import TypeVar, Optional T = TypeVar('T', 'str', 'Optional[int]', bytes) - "#, + ", &[], ); } @@ -3776,12 +3776,12 @@ mod tests { #[test] fn quoted_type_var_bound() { flakes( - r#" + r" from typing import TypeVar, Optional, List T = TypeVar('T', bound='Optional[int]') S = TypeVar('S', int, bound='List[int]') - "#, + ", &[], ); } @@ -3789,12 +3789,12 @@ mod tests { #[test] fn literal_type_typing() { flakes( - r#" + r" from typing import Literal def f(x: Literal['some string']) -> None: return None - "#, + ", &[], ); } @@ -3802,12 +3802,12 @@ mod tests { #[test] fn literal_type_typing_extensions() { flakes( - r#" + r" from typing_extensions import Literal def f(x: Literal['some string']) -> None: return None - "#, + ", &[], ); } @@ -3815,12 +3815,12 @@ mod tests { #[test] fn annotated_type_typing_missing_forward_type_multiple_args() { flakes( - r#" + r" from typing import Annotated def f(x: Annotated['integer', 1]) -> None: return None - "#, + ", &[Rule::UndefinedName], ); } @@ -3828,12 +3828,12 @@ mod tests { #[test] fn annotated_type_typing_with_string_args() { flakes( - r#" + r" from typing import Annotated def f(x: Annotated[int, '> 0']) -> None: return None - "#, + ", &[], ); } @@ -3841,12 +3841,12 @@ mod tests { #[test] fn annotated_type_typing_with_string_args_in_union() { flakes( - r#" + r" from typing import Annotated, Union def f(x: Union[Annotated['int', '>0'], 'integer']) -> None: return None - "#, + ", &[Rule::UndefinedName], ); } @@ -3857,7 +3857,7 @@ mod tests { fn literal_type_some_other_module() { // err on the side of false-negatives for types named Literal. flakes( - r#" + r" from my_module import compat from my_module.compat import Literal @@ -3865,7 +3865,7 @@ mod tests { return None def g(x: Literal['some string']) -> None: return None - "#, + ", &[], ); } @@ -3873,12 +3873,12 @@ mod tests { #[test] fn literal_union_type_typing() { flakes( - r#" + r" from typing import Literal def f(x: Literal['some string', 'foo bar']) -> None: return None - "#, + ", &[], ); } @@ -3902,7 +3902,7 @@ mod tests { #[test] fn partial_string_annotations_with_future_annotations() { flakes( - r#" + r" from __future__ import annotations from queue import Queue @@ -3910,7 +3910,7 @@ mod tests { def f() -> Optional['Queue[str]']: return None - "#, + ", &[], ); } @@ -3937,7 +3937,7 @@ mod tests { fn idiomiatic_typing_guards() { // typing.TYPE_CHECKING: python3.5.3+. flakes( - r#" + r" from typing import TYPE_CHECKING if TYPE_CHECKING: @@ -3945,23 +3945,23 @@ mod tests { def f() -> T: pass - "#, + ", &[], ); // False: the old, more-compatible approach. flakes( - r#" + r" if False: from t import T def f() -> T: pass - "#, + ", &[], ); // Some choose to assign a constant and do it that way. flakes( - r#" + r" MYPY = False if MYPY: @@ -3969,7 +3969,7 @@ mod tests { def f() -> T: pass - "#, + ", &[], ); } @@ -3977,7 +3977,7 @@ mod tests { #[test] fn typing_guard_for_protocol() { flakes( - r#" + r" from typing import TYPE_CHECKING if TYPE_CHECKING: @@ -3988,7 +3988,7 @@ mod tests { class C(Protocol): def f() -> int: pass - "#, + ", &[], ); } diff --git a/crates/ruff_linter/src/rules/pylint/rules/too_many_branches.rs b/crates/ruff_linter/src/rules/pylint/rules/too_many_branches.rs index 7c083b10f7..57d4476ec6 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/too_many_branches.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/too_many_branches.rs @@ -187,7 +187,7 @@ mod tests { #[test] fn if_else_nested_if_else() -> Result<()> { - let source: &str = r#" + let source: &str = r" if x == 0: # 3 return else: @@ -195,19 +195,19 @@ else: pass else: pass -"#; +"; test_helper(source, 4)?; Ok(()) } #[test] fn for_else() -> Result<()> { - let source: &str = r#" + let source: &str = r" for _ in range(x): # 2 pass else: pass -"#; +"; test_helper(source, 2)?; Ok(()) @@ -215,14 +215,14 @@ else: #[test] fn while_if_else_if() -> Result<()> { - let source: &str = r#" + let source: &str = r" while x < 1: # 4 if x: pass else: if x: pass -"#; +"; test_helper(source, 4)?; Ok(()) @@ -230,7 +230,7 @@ else: #[test] fn nested_def() -> Result<()> { - let source: &str = r#" + let source: &str = r" if x: # 2 pass else: @@ -241,7 +241,7 @@ def g(x): pass return 1 -"#; +"; test_helper(source, 2)?; Ok(()) @@ -249,7 +249,7 @@ return 1 #[test] fn try_except_except_else_finally() -> Result<()> { - let source: &str = r#" + let source: &str = r" try: pass except: @@ -260,7 +260,7 @@ else: pass finally: pass -"#; +"; test_helper(source, 5)?; Ok(()) diff --git a/crates/ruff_linter/src/rules/pylint/rules/too_many_return_statements.rs b/crates/ruff_linter/src/rules/pylint/rules/too_many_return_statements.rs index dc84eac2f4..2086ea4b8c 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/too_many_return_statements.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/too_many_return_statements.rs @@ -110,7 +110,7 @@ mod tests { #[test] fn if_() -> Result<()> { - let source = r#" + let source = r" x = 1 if x == 1: # 9 return @@ -130,7 +130,7 @@ if x == 8: return if x == 9: return -"#; +"; test_helper(source, 9)?; Ok(()) @@ -138,12 +138,12 @@ if x == 9: #[test] fn for_else() -> Result<()> { - let source = r#" + let source = r" for _i in range(10): return else: return -"#; +"; test_helper(source, 2)?; Ok(()) @@ -151,12 +151,12 @@ else: #[test] fn async_for_else() -> Result<()> { - let source = r#" + let source = r" async for _i in range(10): return else: return -"#; +"; test_helper(source, 2)?; Ok(()) @@ -164,7 +164,7 @@ else: #[test] fn nested_def_ignored() -> Result<()> { - let source = r#" + let source = r" def f(): return @@ -173,7 +173,7 @@ if x == 1: print() else: print() -"#; +"; test_helper(source, 0)?; Ok(()) @@ -181,7 +181,7 @@ else: #[test] fn while_nested_if() -> Result<()> { - let source = r#" + let source = r" x = 1 while x < 10: print() @@ -189,7 +189,7 @@ while x < 10: return x += 1 return -"#; +"; test_helper(source, 2)?; Ok(()) @@ -197,12 +197,12 @@ return #[test] fn with_if() -> Result<()> { - let source = r#" + let source = r" with a as f: return if f == 1: return -"#; +"; test_helper(source, 2)?; Ok(()) @@ -210,12 +210,12 @@ with a as f: #[test] fn async_with_if() -> Result<()> { - let source = r#" + let source = r" async with a as f: return if f == 1: return -"#; +"; test_helper(source, 2)?; Ok(()) @@ -223,7 +223,7 @@ async with a as f: #[test] fn try_except_except_else_finally() -> Result<()> { - let source = r#" + let source = r" try: print() return @@ -235,7 +235,7 @@ else: return finally: return -"#; +"; test_helper(source, 5)?; Ok(()) @@ -243,14 +243,14 @@ finally: #[test] fn class_def_ignored() -> Result<()> { - let source = r#" + let source = r" class A: def f(self): return def g(self): return -"#; +"; test_helper(source, 0)?; Ok(()) diff --git a/crates/ruff_linter/src/rules/pylint/rules/too_many_statements.rs b/crates/ruff_linter/src/rules/pylint/rules/too_many_statements.rs index 406f5959fc..646eb66e03 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/too_many_statements.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/too_many_statements.rs @@ -163,10 +163,10 @@ mod tests { #[test] fn pass() -> Result<()> { - let source: &str = r#" + let source: &str = r" def f(): pass -"#; +"; let stmts = parse_suite(source, "")?; assert_eq!(num_statements(&stmts), 2); Ok(()) @@ -174,13 +174,13 @@ def f(): #[test] fn if_else() -> Result<()> { - let source: &str = r#" + let source: &str = r" def f(): if a: print() else: print() -"#; +"; let stmts = parse_suite(source, "")?; assert_eq!(num_statements(&stmts), 5); Ok(()) @@ -188,14 +188,14 @@ def f(): #[test] fn if_else_if_corner() -> Result<()> { - let source: &str = r#" + let source: &str = r" def f(): if a: print() else: if a: print() -"#; +"; let stmts = parse_suite(source, "")?; assert_eq!(num_statements(&stmts), 6); Ok(()) @@ -203,13 +203,13 @@ def f(): #[test] fn if_elif() -> Result<()> { - let source: &str = r#" + let source: &str = r" def f(): if a: print() elif a: print() -"#; +"; let stmts = parse_suite(source, "")?; assert_eq!(num_statements(&stmts), 5); Ok(()) @@ -217,7 +217,7 @@ def f(): #[test] fn if_elif_else() -> Result<()> { - let source: &str = r#" + let source: &str = r" def f(): if a: print() @@ -227,7 +227,7 @@ def f(): print() else: print() -"#; +"; let stmts = parse_suite(source, "")?; assert_eq!(num_statements(&stmts), 9); Ok(()) @@ -235,7 +235,7 @@ def f(): #[test] fn many_statements() -> Result<()> { - let source: &str = r#" + let source: &str = r" async def f(): a = 1 b = 2 @@ -256,7 +256,7 @@ async def f(): a -= 1 import time pass -"#; +"; let stmts = parse_suite(source, "")?; assert_eq!(num_statements(&stmts), 19); Ok(()) @@ -264,11 +264,11 @@ async def f(): #[test] fn for_() -> Result<()> { - let source: &str = r#" + let source: &str = r" def f(): for i in range(10): pass -"#; +"; let stmts = parse_suite(source, "")?; assert_eq!(num_statements(&stmts), 2); Ok(()) @@ -276,13 +276,13 @@ def f(): #[test] fn for_else() -> Result<()> { - let source: &str = r#" + let source: &str = r" def f(): for i in range(10): print() else: print() -"#; +"; let stmts = parse_suite(source, "")?; assert_eq!(num_statements(&stmts), 3); Ok(()) @@ -290,14 +290,14 @@ def f(): #[test] fn nested_def() -> Result<()> { - let source: &str = r#" + let source: &str = r" def f(): def g(): print() print() print() -"#; +"; let stmts = parse_suite(source, "")?; assert_eq!(num_statements(&stmts), 5); Ok(()) @@ -305,7 +305,7 @@ def f(): #[test] fn nested_class() -> Result<()> { - let source: &str = r#" + let source: &str = r" def f(): class A: def __init__(self): @@ -315,7 +315,7 @@ def f(): pass print() -"#; +"; let stmts = parse_suite(source, "")?; assert_eq!(num_statements(&stmts), 3); Ok(()) @@ -323,10 +323,10 @@ def f(): #[test] fn return_not_counted() -> Result<()> { - let source: &str = r#" + let source: &str = r" def f(): return -"#; +"; let stmts = parse_suite(source, "")?; assert_eq!(num_statements(&stmts), 1); Ok(()) @@ -334,7 +334,7 @@ def f(): #[test] fn with() -> Result<()> { - let source: &str = r#" + let source: &str = r" def f(): with a: if a: @@ -342,7 +342,7 @@ def f(): else: print() -"#; +"; let stmts = parse_suite(source, "")?; assert_eq!(num_statements(&stmts), 6); Ok(()) @@ -350,13 +350,13 @@ def f(): #[test] fn try_except() -> Result<()> { - let source: &str = r#" + let source: &str = r" def f(): try: print() except Exception: raise -"#; +"; let stmts = parse_suite(source, "")?; assert_eq!(num_statements(&stmts), 5); Ok(()) @@ -364,7 +364,7 @@ def f(): #[test] fn try_except_else() -> Result<()> { - let source: &str = r#" + let source: &str = r" def f(): try: print() @@ -372,7 +372,7 @@ def f(): pass else: print() -"#; +"; let stmts = parse_suite(source, "")?; assert_eq!(num_statements(&stmts), 7); Ok(()) @@ -380,7 +380,7 @@ def f(): #[test] fn try_except_else_finally() -> Result<()> { - let source: &str = r#" + let source: &str = r" def f(): try: print() @@ -390,7 +390,7 @@ def f(): print() finally: pass -"#; +"; let stmts = parse_suite(source, "")?; assert_eq!(num_statements(&stmts), 10); Ok(()) @@ -398,7 +398,7 @@ def f(): #[test] fn try_except_except() -> Result<()> { - let source: &str = r#" + let source: &str = r" def f(): try: print() @@ -406,7 +406,7 @@ def f(): pass except Exception: raise -"#; +"; let stmts = parse_suite(source, "")?; assert_eq!(num_statements(&stmts), 8); Ok(()) @@ -414,7 +414,7 @@ def f(): #[test] fn try_except_except_finally() -> Result<()> { - let source: &str = r#" + let source: &str = r" def f(): try: print() @@ -424,7 +424,7 @@ def f(): pass finally: print() -"#; +"; let stmts = parse_suite(source, "")?; assert_eq!(num_statements(&stmts), 11); Ok(()) @@ -432,11 +432,11 @@ def f(): #[test] fn yield_() -> Result<()> { - let source: &str = r#" + let source: &str = r" def f(): for i in range(10): yield i -"#; +"; let stmts = parse_suite(source, "")?; assert_eq!(num_statements(&stmts), 2); Ok(()) diff --git a/crates/ruff_linter/src/rules/pyupgrade/fixes.rs b/crates/ruff_linter/src/rules/pyupgrade/fixes.rs index f890fa55cb..3c099346e7 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/fixes.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/fixes.rs @@ -104,145 +104,145 @@ mod tests { #[test] fn once() { - let source = r#"from foo import bar, baz, bop, qux as q"#; - let expected = r#"from foo import bar, baz, qux as q"#; + let source = r"from foo import bar, baz, bop, qux as q"; + let expected = r"from foo import bar, baz, qux as q"; let actual = remove_import_members(source, &["bop"]); assert_eq!(expected, actual); } #[test] fn twice() { - let source = r#"from foo import bar, baz, bop, qux as q"#; - let expected = r#"from foo import bar, qux as q"#; + let source = r"from foo import bar, baz, bop, qux as q"; + let expected = r"from foo import bar, qux as q"; let actual = remove_import_members(source, &["baz", "bop"]); assert_eq!(expected, actual); } #[test] fn aliased() { - let source = r#"from foo import bar, baz, bop as boop, qux as q"#; - let expected = r#"from foo import bar, baz, qux as q"#; + let source = r"from foo import bar, baz, bop as boop, qux as q"; + let expected = r"from foo import bar, baz, qux as q"; let actual = remove_import_members(source, &["bop"]); assert_eq!(expected, actual); } #[test] fn parenthesized() { - let source = r#"from foo import (bar, baz, bop, qux as q)"#; - let expected = r#"from foo import (bar, baz, qux as q)"#; + let source = r"from foo import (bar, baz, bop, qux as q)"; + let expected = r"from foo import (bar, baz, qux as q)"; let actual = remove_import_members(source, &["bop"]); assert_eq!(expected, actual); } #[test] fn last_import() { - let source = r#"from foo import bar, baz, bop, qux as q"#; - let expected = r#"from foo import bar, baz, bop"#; + let source = r"from foo import bar, baz, bop, qux as q"; + let expected = r"from foo import bar, baz, bop"; let actual = remove_import_members(source, &["qux"]); assert_eq!(expected, actual); } #[test] fn first_import() { - let source = r#"from foo import bar, baz, bop, qux as q"#; - let expected = r#"from foo import baz, bop, qux as q"#; + let source = r"from foo import bar, baz, bop, qux as q"; + let expected = r"from foo import baz, bop, qux as q"; let actual = remove_import_members(source, &["bar"]); assert_eq!(expected, actual); } #[test] fn first_two_imports() { - let source = r#"from foo import bar, baz, bop, qux as q"#; - let expected = r#"from foo import bop, qux as q"#; + let source = r"from foo import bar, baz, bop, qux as q"; + let expected = r"from foo import bop, qux as q"; let actual = remove_import_members(source, &["bar", "baz"]); assert_eq!(expected, actual); } #[test] fn first_two_imports_multiline() { - let source = r#"from foo import ( + let source = r"from foo import ( bar, baz, bop, qux as q -)"#; - let expected = r#"from foo import ( +)"; + let expected = r"from foo import ( bop, qux as q -)"#; +)"; let actual = remove_import_members(source, &["bar", "baz"]); assert_eq!(expected, actual); } #[test] fn multiline_once() { - let source = r#"from foo import ( + let source = r"from foo import ( bar, baz, bop, qux as q, -)"#; - let expected = r#"from foo import ( +)"; + let expected = r"from foo import ( bar, baz, qux as q, -)"#; +)"; let actual = remove_import_members(source, &["bop"]); assert_eq!(expected, actual); } #[test] fn multiline_twice() { - let source = r#"from foo import ( + let source = r"from foo import ( bar, baz, bop, qux as q, -)"#; - let expected = r#"from foo import ( +)"; + let expected = r"from foo import ( bar, qux as q, -)"#; +)"; let actual = remove_import_members(source, &["baz", "bop"]); assert_eq!(expected, actual); } #[test] fn multiline_comment() { - let source = r#"from foo import ( + let source = r"from foo import ( bar, baz, # This comment should be removed. bop, # This comment should be retained. qux as q, -)"#; - let expected = r#"from foo import ( +)"; + let expected = r"from foo import ( bar, baz, # This comment should be retained. qux as q, -)"#; +)"; let actual = remove_import_members(source, &["bop"]); assert_eq!(expected, actual); } #[test] fn multi_comment_first_import() { - let source = r#"from foo import ( + let source = r"from foo import ( # This comment should be retained. bar, # This comment should be removed. baz, bop, qux as q, -)"#; - let expected = r#"from foo import ( +)"; + let expected = r"from foo import ( # This comment should be retained. baz, bop, qux as q, -)"#; +)"; let actual = remove_import_members(source, &["bar"]); assert_eq!(expected, actual); } diff --git a/crates/ruff_linter/src/rules/ruff/rules/unreachable.rs b/crates/ruff_linter/src/rules/ruff/rules/unreachable.rs index 100ca9ddd4..8f5db5a35b 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/unreachable.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/unreachable.rs @@ -1045,7 +1045,7 @@ mod tests { #[test_case("match.py")] fn control_flow_graph(filename: &str) { let path = PathBuf::from_iter(["resources/test/fixtures/control-flow-graph", filename]); - let source = fs::read_to_string(&path).expect("failed to read file"); + let source = fs::read_to_string(path).expect("failed to read file"); let stmts = parse(&source, Mode::Module, filename) .unwrap_or_else(|err| panic!("failed to parse source: '{source}': {err}")) .expect_module() diff --git a/crates/ruff_macros/Cargo.toml b/crates/ruff_macros/Cargo.toml index 2cd64bbe54..0f24d5e248 100644 --- a/crates/ruff_macros/Cargo.toml +++ b/crates/ruff_macros/Cargo.toml @@ -21,3 +21,6 @@ proc-macro2 = { workspace = true } quote = { workspace = true } syn = { workspace = true, features = ["derive", "parsing", "extra-traits", "full"] } itertools = { workspace = true } + +[lints] +workspace = true diff --git a/crates/ruff_macros/src/rule_namespace.rs b/crates/ruff_macros/src/rule_namespace.rs index 8d573d84b4..34ef3252da 100644 --- a/crates/ruff_macros/src/rule_namespace.rs +++ b/crates/ruff_macros/src/rule_namespace.rs @@ -64,7 +64,7 @@ pub(crate) fn derive_impl(input: DeriveInput) -> syn::Result syn::Result<(String, String)> { .ok_or_else(|| { Error::new( doc_lit.span(), - r#"expected doc comment to be in the form of `/// [name](https://example.com/)`"#, + "expected doc comment to be in the form of `/// [name](https://example.com/)`", ) }) } diff --git a/crates/ruff_notebook/Cargo.toml b/crates/ruff_notebook/Cargo.toml index 1ef679bbea..565d2daab2 100644 --- a/crates/ruff_notebook/Cargo.toml +++ b/crates/ruff_notebook/Cargo.toml @@ -29,3 +29,6 @@ uuid = { workspace = true } [dev-dependencies] insta = { workspace = true } test-case = { workspace = true } + +[lints] +workspace = true diff --git a/crates/ruff_python_ast/Cargo.toml b/crates/ruff_python_ast/Cargo.toml index c35a54bb5a..460bdf48c9 100644 --- a/crates/ruff_python_ast/Cargo.toml +++ b/crates/ruff_python_ast/Cargo.toml @@ -33,3 +33,6 @@ ruff_python_parser = { path = "../ruff_python_parser" } [features] serde = ["dep:serde", "ruff_text_size/serde"] + +[lints] +workspace = true diff --git a/crates/ruff_python_ast/src/identifier.rs b/crates/ruff_python_ast/src/identifier.rs index ffbb8c152f..566b9c7925 100644 --- a/crates/ruff_python_ast/src/identifier.rs +++ b/crates/ruff_python_ast/src/identifier.rs @@ -229,7 +229,7 @@ mod tests { #[test] fn extract_global_names() { - let contents = r#"global X,Y, Z"#.trim(); + let contents = r"global X,Y, Z".trim(); let mut names = IdentifierTokenizer::new( contents, diff --git a/crates/ruff_python_ast/tests/identifier.rs b/crates/ruff_python_ast/tests/identifier.rs index a32dd12c26..73dcabd188 100644 --- a/crates/ruff_python_ast/tests/identifier.rs +++ b/crates/ruff_python_ast/tests/identifier.rs @@ -5,12 +5,12 @@ use ruff_python_ast::identifier; #[test] fn extract_else_range() -> Result<(), ParseError> { - let contents = r#" + let contents = r" for x in y: pass else: pass -"# +" .trim(); let stmts = parse_suite(contents, "")?; let stmt = stmts.first().unwrap(); diff --git a/crates/ruff_python_ast/tests/parenthesize.rs b/crates/ruff_python_ast/tests/parenthesize.rs index 69a68f7f82..906fb8e7fc 100644 --- a/crates/ruff_python_ast/tests/parenthesize.rs +++ b/crates/ruff_python_ast/tests/parenthesize.rs @@ -5,7 +5,7 @@ use ruff_text_size::TextRange; #[test] fn test_parenthesized_name() { - let source_code = r#"(x) + 1"#; + let source_code = r"(x) + 1"; let expr = parse_expression(source_code, "").unwrap(); let bin_op = expr.as_bin_op_expr().unwrap(); @@ -22,7 +22,7 @@ fn test_parenthesized_name() { #[test] fn test_non_parenthesized_name() { - let source_code = r#"x + 1"#; + let source_code = r"x + 1"; let expr = parse_expression(source_code, "").unwrap(); let bin_op = expr.as_bin_op_expr().unwrap(); @@ -39,7 +39,7 @@ fn test_non_parenthesized_name() { #[test] fn test_parenthesized_argument() { - let source_code = r#"f((a))"#; + let source_code = r"f((a))"; let expr = parse_expression(source_code, "").unwrap(); let call = expr.as_call_expr().unwrap(); @@ -57,7 +57,7 @@ fn test_parenthesized_argument() { #[test] fn test_non_parenthesized_argument() { - let source_code = r#"f(a)"#; + let source_code = r"f(a)"; let expr = parse_expression(source_code, "").unwrap(); let call = expr.as_call_expr().unwrap(); @@ -75,7 +75,7 @@ fn test_non_parenthesized_argument() { #[test] fn test_parenthesized_tuple_member() { - let source_code = r#"(a, (b))"#; + let source_code = r"(a, (b))"; let expr = parse_expression(source_code, "").unwrap(); let tuple = expr.as_tuple_expr().unwrap(); @@ -92,7 +92,7 @@ fn test_parenthesized_tuple_member() { #[test] fn test_non_parenthesized_tuple_member() { - let source_code = r#"(a, b)"#; + let source_code = r"(a, b)"; let expr = parse_expression(source_code, "").unwrap(); let tuple = expr.as_tuple_expr().unwrap(); @@ -109,7 +109,7 @@ fn test_non_parenthesized_tuple_member() { #[test] fn test_twice_parenthesized_name() { - let source_code = r#"((x)) + 1"#; + let source_code = r"((x)) + 1"; let expr = parse_expression(source_code, "").unwrap(); let bin_op = expr.as_bin_op_expr().unwrap(); @@ -126,7 +126,7 @@ fn test_twice_parenthesized_name() { #[test] fn test_twice_parenthesized_argument() { - let source_code = r#"f(((a + 1)))"#; + let source_code = r"f(((a + 1)))"; let expr = parse_expression(source_code, "").unwrap(); let call = expr.as_call_expr().unwrap(); diff --git a/crates/ruff_python_ast/tests/preorder.rs b/crates/ruff_python_ast/tests/preorder.rs index 02f1c3bea3..106ce91389 100644 --- a/crates/ruff_python_ast/tests/preorder.rs +++ b/crates/ruff_python_ast/tests/preorder.rs @@ -17,7 +17,7 @@ use ruff_python_parser::{parse_tokens, Mode}; #[test] fn function_arguments() { - let source = r#"def a(b, c,/, d, e = 20, *args, named=5, other=20, **kwargs): pass"#; + let source = r"def a(b, c,/, d, e = 20, *args, named=5, other=20, **kwargs): pass"; let trace = trace_preorder_visitation(source); @@ -26,7 +26,7 @@ fn function_arguments() { #[test] fn function_positional_only_with_default() { - let source = r#"def a(b, c = 34,/, e = 20, *args): pass"#; + let source = r"def a(b, c = 34,/, e = 20, *args): pass"; let trace = trace_preorder_visitation(source); @@ -35,7 +35,7 @@ fn function_positional_only_with_default() { #[test] fn compare() { - let source = r#"4 < x < 5"#; + let source = r"4 < x < 5"; let trace = trace_preorder_visitation(source); @@ -71,13 +71,13 @@ fn set_comprehension() { #[test] fn match_class_pattern() { - let source = r#" + let source = r" match x: case Point2D(0, 0): ... case Point3D(x=0, y=0, z=0): ... -"#; +"; let trace = trace_preorder_visitation(source); @@ -86,7 +86,7 @@ match x: #[test] fn decorators() { - let source = r#" + let source = r" @decorator def a(): pass @@ -94,7 +94,7 @@ def a(): @test class A: pass -"#; +"; let trace = trace_preorder_visitation(source); @@ -103,7 +103,7 @@ class A: #[test] fn type_aliases() { - let source = r#"type X[T: str, U, *Ts, **P] = list[T]"#; + let source = r"type X[T: str, U, *Ts, **P] = list[T]"; let trace = trace_preorder_visitation(source); @@ -112,7 +112,7 @@ fn type_aliases() { #[test] fn class_type_parameters() { - let source = r#"class X[T: str, U, *Ts, **P]: ..."#; + let source = r"class X[T: str, U, *Ts, **P]: ..."; let trace = trace_preorder_visitation(source); @@ -121,7 +121,7 @@ fn class_type_parameters() { #[test] fn function_type_parameters() { - let source = r#"def X[T: str, U, *Ts, **P](): ..."#; + let source = r"def X[T: str, U, *Ts, **P](): ..."; let trace = trace_preorder_visitation(source); diff --git a/crates/ruff_python_ast/tests/visitor.rs b/crates/ruff_python_ast/tests/visitor.rs index 0765f5e7d6..a503009566 100644 --- a/crates/ruff_python_ast/tests/visitor.rs +++ b/crates/ruff_python_ast/tests/visitor.rs @@ -18,7 +18,7 @@ use ruff_python_ast::{ #[test] fn function_arguments() { - let source = r#"def a(b, c,/, d, e = 20, *args, named=5, other=20, **kwargs): pass"#; + let source = r"def a(b, c,/, d, e = 20, *args, named=5, other=20, **kwargs): pass"; let trace = trace_visitation(source); @@ -27,7 +27,7 @@ fn function_arguments() { #[test] fn function_positional_only_with_default() { - let source = r#"def a(b, c = 34,/, e = 20, *args): pass"#; + let source = r"def a(b, c = 34,/, e = 20, *args): pass"; let trace = trace_visitation(source); @@ -36,7 +36,7 @@ fn function_positional_only_with_default() { #[test] fn compare() { - let source = r#"4 < x < 5"#; + let source = r"4 < x < 5"; let trace = trace_visitation(source); @@ -72,13 +72,13 @@ fn set_comprehension() { #[test] fn match_class_pattern() { - let source = r#" + let source = r" match x: case Point2D(0, 0): ... case Point3D(x=0, y=0, z=0): ... -"#; +"; let trace = trace_visitation(source); @@ -87,7 +87,7 @@ match x: #[test] fn decorators() { - let source = r#" + let source = r" @decorator def a(): pass @@ -95,7 +95,7 @@ def a(): @test class A: pass -"#; +"; let trace = trace_visitation(source); @@ -104,7 +104,7 @@ class A: #[test] fn type_aliases() { - let source = r#"type X[T: str, U, *Ts, **P] = list[T]"#; + let source = r"type X[T: str, U, *Ts, **P] = list[T]"; let trace = trace_visitation(source); @@ -113,7 +113,7 @@ fn type_aliases() { #[test] fn class_type_parameters() { - let source = r#"class X[T: str, U, *Ts, **P]: ..."#; + let source = r"class X[T: str, U, *Ts, **P]: ..."; let trace = trace_visitation(source); @@ -122,7 +122,7 @@ fn class_type_parameters() { #[test] fn function_type_parameters() { - let source = r#"def X[T: str, U, *Ts, **P](): ..."#; + let source = r"def X[T: str, U, *Ts, **P](): ..."; let trace = trace_visitation(source); diff --git a/crates/ruff_python_codegen/Cargo.toml b/crates/ruff_python_codegen/Cargo.toml index 563552c908..6c55754be3 100644 --- a/crates/ruff_python_codegen/Cargo.toml +++ b/crates/ruff_python_codegen/Cargo.toml @@ -20,3 +20,6 @@ ruff_source_file = { path = "../ruff_source_file" } once_cell = { workspace = true } +[lints] +workspace = true + diff --git a/crates/ruff_python_codegen/src/generator.rs b/crates/ruff_python_codegen/src/generator.rs index fc57856633..3c83bc26d9 100644 --- a/crates/ruff_python_codegen/src/generator.rs +++ b/crates/ruff_python_codegen/src/generator.rs @@ -1473,7 +1473,7 @@ mod tests { assert_round_trip!("return await (await bar())"); assert_round_trip!("(5).foo"); assert_round_trip!(r#"our_dict = {"a": 1, **{"b": 2, "c": 3}}"#); - assert_round_trip!(r#"j = [1, 2, 3]"#); + assert_round_trip!(r"j = [1, 2, 3]"); assert_round_trip!( r#"def test(a1, a2, b1=j, b2="123", b3={}, b4=[]): pass"# @@ -1511,32 +1511,32 @@ mod tests { pass"# ); assert_round_trip!( - r#"class Foo(Bar, object): - pass"# + r"class Foo(Bar, object): + pass" ); assert_round_trip!( - r#"class Foo[T]: - pass"# + r"class Foo[T]: + pass" ); assert_round_trip!( - r#"class Foo[T](Bar): - pass"# + r"class Foo[T](Bar): + pass" ); assert_round_trip!( - r#"class Foo[*Ts]: - pass"# + r"class Foo[*Ts]: + pass" ); assert_round_trip!( - r#"class Foo[**P]: - pass"# + r"class Foo[**P]: + pass" ); assert_round_trip!( - r#"class Foo[T, U, *Ts, **P]: - pass"# + r"class Foo[T, U, *Ts, **P]: + pass" ); assert_round_trip!( - r#"def f() -> (int, str): - pass"# + r"def f() -> (int, str): + pass" ); assert_round_trip!("[await x async for x in y]"); assert_round_trip!("[await i for i in b if await c]"); @@ -1550,102 +1550,102 @@ mod tests { return datum"# ); assert_round_trip!( - r#"def f() -> (int, int): - pass"# + r"def f() -> (int, int): + pass" ); assert_round_trip!( - r#"def test(a, b, /, c, *, d, **kwargs): - pass"# + r"def test(a, b, /, c, *, d, **kwargs): + pass" ); assert_round_trip!( - r#"def test(a=3, b=4, /, c=7): - pass"# + r"def test(a=3, b=4, /, c=7): + pass" ); assert_round_trip!( - r#"def test(a, b=4, /, c=8, d=9): - pass"# + r"def test(a, b=4, /, c=8, d=9): + pass" ); assert_round_trip!( - r#"def test[T](): - pass"# + r"def test[T](): + pass" ); assert_round_trip!( - r#"def test[*Ts](): - pass"# + r"def test[*Ts](): + pass" ); assert_round_trip!( - r#"def test[**P](): - pass"# + r"def test[**P](): + pass" ); assert_round_trip!( - r#"def test[T, U, *Ts, **P](): - pass"# + r"def test[T, U, *Ts, **P](): + pass" ); assert_round_trip!( - r#"def call(*popenargs, timeout=None, **kwargs): - pass"# + r"def call(*popenargs, timeout=None, **kwargs): + pass" ); assert_round_trip!( - r#"@functools.lru_cache(maxsize=None) + r"@functools.lru_cache(maxsize=None) def f(x: int, y: int) -> int: - return x + y"# + return x + y" ); assert_round_trip!( - r#"try: + r"try: pass except Exception as e: - pass"# + pass" ); assert_round_trip!( - r#"try: + r"try: pass except* Exception as e: - pass"# + pass" ); assert_round_trip!( - r#"match x: + r"match x: case [1, 2, 3]: return 2 case 4 as y: - return y"# + return y" ); - assert_eq!(round_trip(r#"x = (1, 2, 3)"#), r#"x = 1, 2, 3"#); - assert_eq!(round_trip(r#"-(1) + ~(2) + +(3)"#), r#"-1 + ~2 + +3"#); + assert_eq!(round_trip(r"x = (1, 2, 3)"), r"x = 1, 2, 3"); + assert_eq!(round_trip(r"-(1) + ~(2) + +(3)"), r"-1 + ~2 + +3"); assert_round_trip!( - r#"def f(): + r"def f(): def f(): - pass"# + pass" ); assert_round_trip!( - r#"@foo + r"@foo def f(): @foo def f(): - pass"# + pass" ); assert_round_trip!( - r#"@foo + r"@foo class Foo: @foo def f(): - pass"# + pass" ); - assert_round_trip!(r#"[lambda n: n for n in range(10)]"#); - assert_round_trip!(r#"[n[0:2] for n in range(10)]"#); - assert_round_trip!(r#"[n[0] for n in range(10)]"#); - assert_round_trip!(r#"[(n, n * 2) for n in range(10)]"#); - assert_round_trip!(r#"[1 if n % 2 == 0 else 0 for n in range(10)]"#); - assert_round_trip!(r#"[n % 2 == 0 or 0 for n in range(10)]"#); - assert_round_trip!(r#"[(n := 2) for n in range(10)]"#); - assert_round_trip!(r#"((n := 2) for n in range(10))"#); - assert_round_trip!(r#"[n * 2 for n in range(10)]"#); - assert_round_trip!(r#"{n * 2 for n in range(10)}"#); - assert_round_trip!(r#"{i: n * 2 for i, n in enumerate(range(10))}"#); + assert_round_trip!(r"[lambda n: n for n in range(10)]"); + assert_round_trip!(r"[n[0:2] for n in range(10)]"); + assert_round_trip!(r"[n[0] for n in range(10)]"); + assert_round_trip!(r"[(n, n * 2) for n in range(10)]"); + assert_round_trip!(r"[1 if n % 2 == 0 else 0 for n in range(10)]"); + assert_round_trip!(r"[n % 2 == 0 or 0 for n in range(10)]"); + assert_round_trip!(r"[(n := 2) for n in range(10)]"); + assert_round_trip!(r"((n := 2) for n in range(10))"); + assert_round_trip!(r"[n * 2 for n in range(10)]"); + assert_round_trip!(r"{n * 2 for n in range(10)}"); + assert_round_trip!(r"{i: n * 2 for i, n in enumerate(range(10))}"); assert_round_trip!( "class SchemaItem(NamedTuple): fields: ((\"property_key\", str),)" @@ -1659,25 +1659,25 @@ class Foo: assert_round_trip!("x += (i := 1)"); // Type aliases - assert_round_trip!(r#"type Foo = int | str"#); - assert_round_trip!(r#"type Foo[T] = list[T]"#); - assert_round_trip!(r#"type Foo[*Ts] = ..."#); - assert_round_trip!(r#"type Foo[**P] = ..."#); - assert_round_trip!(r#"type Foo[T, U, *Ts, **P] = ..."#); + assert_round_trip!(r"type Foo = int | str"); + assert_round_trip!(r"type Foo[T] = list[T]"); + assert_round_trip!(r"type Foo[*Ts] = ..."); + assert_round_trip!(r"type Foo[**P] = ..."); + assert_round_trip!(r"type Foo[T, U, *Ts, **P] = ..."); // https://github.com/astral-sh/ruff/issues/6498 - assert_round_trip!(r#"f(a=1, *args, **kwargs)"#); - assert_round_trip!(r#"f(*args, a=1, **kwargs)"#); - assert_round_trip!(r#"f(*args, a=1, *args2, **kwargs)"#); + assert_round_trip!(r"f(a=1, *args, **kwargs)"); + assert_round_trip!(r"f(*args, a=1, **kwargs)"); + assert_round_trip!(r"f(*args, a=1, *args2, **kwargs)"); assert_round_trip!("class A(*args, a=2, *args2, **kwargs):\n pass"); } #[test] fn quote() { assert_eq!(round_trip(r#""hello""#), r#""hello""#); - assert_eq!(round_trip(r#"'hello'"#), r#""hello""#); - assert_eq!(round_trip(r#"u'hello'"#), r#"u"hello""#); - assert_eq!(round_trip(r#"r'hello'"#), r#""hello""#); - assert_eq!(round_trip(r#"b'hello'"#), r#"b"hello""#); + assert_eq!(round_trip(r"'hello'"), r#""hello""#); + assert_eq!(round_trip(r"u'hello'"), r#"u"hello""#); + assert_eq!(round_trip(r"r'hello'"), r#""hello""#); + assert_eq!(round_trip(r"b'hello'"), r#"b"hello""#); assert_eq!(round_trip(r#"("abc" "def" "ghi")"#), r#""abcdefghi""#); assert_eq!(round_trip(r#""he\"llo""#), r#"'he"llo'"#); assert_eq!(round_trip(r#"f"abc{'def'}{1}""#), r#"f"abc{'def'}{1}""#); @@ -1697,16 +1697,16 @@ class Foo: fn indent() { assert_eq!( round_trip( - r#" + r" if True: pass -"# +" .trim(), ), - r#" + r" if True: pass -"# +" .trim() .replace('\n', LineEnding::default().as_str()) ); @@ -1730,14 +1730,14 @@ if True: LineEnding::default(), r#""hello""# ), - r#"'hello'"# + r"'hello'" ); assert_eq!( round_trip_with( &Indentation::default(), Quote::Double, LineEnding::default(), - r#"'hello'"# + r"'hello'" ), r#""hello""# ); @@ -1746,9 +1746,9 @@ if True: &Indentation::default(), Quote::Single, LineEnding::default(), - r#"'hello'"# + r"'hello'" ), - r#"'hello'"# + r"'hello'" ); } @@ -1759,16 +1759,16 @@ if True: &Indentation::new(" ".to_string()), Quote::default(), LineEnding::default(), - r#" + r" if True: pass -"# +" .trim(), ), - r#" + r" if True: pass -"# +" .trim() .replace('\n', LineEnding::default().as_str()) ); @@ -1777,16 +1777,16 @@ if True: &Indentation::new(" ".to_string()), Quote::default(), LineEnding::default(), - r#" + r" if True: pass -"# +" .trim(), ), - r#" + r" if True: pass -"# +" .trim() .replace('\n', LineEnding::default().as_str()) ); @@ -1795,16 +1795,16 @@ if True: &Indentation::new("\t".to_string()), Quote::default(), LineEnding::default(), - r#" + r" if True: pass -"# +" .trim(), ), - r#" + r" if True: pass -"# +" .trim() .replace('\n', LineEnding::default().as_str()) ); diff --git a/crates/ruff_python_codegen/src/stylist.rs b/crates/ruff_python_codegen/src/stylist.rs index 1c3740bbce..e54ef0e1cc 100644 --- a/crates/ruff_python_codegen/src/stylist.rs +++ b/crates/ruff_python_codegen/src/stylist.rs @@ -190,7 +190,7 @@ mod tests { #[test] fn indentation() { - let contents = r#"x = 1"#; + let contents = r"x = 1"; let locator = Locator::new(contents); let tokens: Vec<_> = lex(contents, Mode::Module).collect(); assert_eq!( @@ -198,10 +198,10 @@ mod tests { &Indentation::default() ); - let contents = r#" + let contents = r" if True: pass -"#; +"; let locator = Locator::new(contents); let tokens: Vec<_> = lex(contents, Mode::Module).collect(); assert_eq!( @@ -209,10 +209,10 @@ if True: &Indentation(" ".to_string()) ); - let contents = r#" + let contents = r" if True: pass -"#; +"; let locator = Locator::new(contents); let tokens: Vec<_> = lex(contents, Mode::Module).collect(); assert_eq!( @@ -220,10 +220,10 @@ if True: &Indentation(" ".to_string()) ); - let contents = r#" + let contents = r" if True: pass -"#; +"; let locator = Locator::new(contents); let tokens: Vec<_> = lex(contents, Mode::Module).collect(); assert_eq!( @@ -232,13 +232,13 @@ if True: ); // TODO(charlie): Should non-significant whitespace be detected? - let contents = r#" + let contents = r" x = ( 1, 2, 3, ) -"#; +"; let locator = Locator::new(contents); let tokens: Vec<_> = lex(contents, Mode::Module).collect(); assert_eq!( @@ -247,11 +247,11 @@ x = ( ); // formfeed indent, see `detect_indention` comment. - let contents = r#" + let contents = r" class FormFeedIndent: def __init__(self, a=[]): print(a) -"#; +"; let locator = Locator::new(contents); let tokens: Vec<_> = lex(contents, Mode::Module).collect(); assert_eq!( @@ -262,7 +262,7 @@ class FormFeedIndent: #[test] fn quote() { - let contents = r#"x = 1"#; + let contents = r"x = 1"; let locator = Locator::new(contents); let tokens: Vec<_> = lex(contents, Mode::Module).collect(); assert_eq!( @@ -270,7 +270,7 @@ class FormFeedIndent: Quote::default() ); - let contents = r#"x = '1'"#; + let contents = r"x = '1'"; let locator = Locator::new(contents); let tokens: Vec<_> = lex(contents, Mode::Module).collect(); assert_eq!( @@ -278,7 +278,7 @@ class FormFeedIndent: Quote::Single ); - let contents = r#"x = f'1'"#; + let contents = r"x = f'1'"; let locator = Locator::new(contents); let tokens: Vec<_> = lex(contents, Mode::Module).collect(); assert_eq!( @@ -373,9 +373,9 @@ a = f"v" Quote::Double ); - let contents = r#" + let contents = r" f'''Module docstring.''' -"#; +"; let locator = Locator::new(contents); let tokens: Vec<_> = lex(contents, Mode::Module).collect(); assert_eq!( diff --git a/crates/ruff_python_formatter/Cargo.toml b/crates/ruff_python_formatter/Cargo.toml index 14e2ed5c84..24325082f0 100644 --- a/crates/ruff_python_formatter/Cargo.toml +++ b/crates/ruff_python_formatter/Cargo.toml @@ -55,3 +55,6 @@ required-features = ["serde"] default = ["serde"] serde = ["dep:serde", "ruff_formatter/serde", "ruff_source_file/serde", "ruff_python_ast/serde"] schemars = ["dep:schemars", "ruff_formatter/schemars"] + +[lints] +workspace = true diff --git a/crates/ruff_python_formatter/src/comments/debug.rs b/crates/ruff_python_formatter/src/comments/debug.rs index 6f12bf690c..b28d992058 100644 --- a/crates/ruff_python_formatter/src/comments/debug.rs +++ b/crates/ruff_python_formatter/src/comments/debug.rs @@ -198,11 +198,11 @@ mod tests { range: TextRange::default(), }); - let source = r#"# leading comment + let source = r"# leading comment continue; # trailing # break leading break; -"#; +"; let source_code = SourceCode::new(source); diff --git a/crates/ruff_python_formatter/src/comments/mod.rs b/crates/ruff_python_formatter/src/comments/mod.rs index 48733c652a..32e68982ec 100644 --- a/crates/ruff_python_formatter/src/comments/mod.rs +++ b/crates/ruff_python_formatter/src/comments/mod.rs @@ -610,11 +610,11 @@ test(10, 20) #[test] fn only_comments() { - let source = r#" + let source = r" # Some comment # another comment -"#; +"; let test_case = CommentsTestCase::from_code(source); let comments = test_case.to_comments(); @@ -624,7 +624,7 @@ test(10, 20) #[test] fn empty_file() { - let source = r#""#; + let source = r""; let test_case = CommentsTestCase::from_code(source); let comments = test_case.to_comments(); @@ -634,12 +634,12 @@ test(10, 20) #[test] fn dangling_comment() { - let source = r#" + let source = r" def test( # Some comment ): pass -"#; +"; let test_case = CommentsTestCase::from_code(source); let comments = test_case.to_comments(); @@ -649,12 +649,12 @@ def test( #[test] fn parenthesized_expression() { - let source = r#" + let source = r" a = ( # Trailing comment 10 + # More comments 3 ) -"#; +"; let test_case = CommentsTestCase::from_code(source); let comments = test_case.to_comments(); @@ -664,11 +664,11 @@ a = ( # Trailing comment #[test] fn parenthesized_trailing_comment() { - let source = r#"( + let source = r"( a # comment ) -"#; +"; let test_case = CommentsTestCase::from_code(source); let comments = test_case.to_comments(); @@ -728,7 +728,7 @@ print("test") #[test] fn if_elif_else_comments() { - let source = r#" + let source = r" if x == y: pass # trailing `pass` comment # Root `if` trailing comment @@ -741,7 +741,7 @@ elif x < y: else: pass # `else` trailing comment -"#; +"; let test_case = CommentsTestCase::from_code(source); let comments = test_case.to_comments(); @@ -751,7 +751,7 @@ else: #[test] fn if_elif_if_else_comments() { - let source = r#" + let source = r" if x == y: pass elif x < y: @@ -761,7 +761,7 @@ elif x < y: # Leading else comment else: pass -"#; +"; let test_case = CommentsTestCase::from_code(source); let comments = test_case.to_comments(); @@ -855,10 +855,10 @@ print("Next statement"); #[test] fn leading_most_outer() { - let source = r#" + let source = r" # leading comment x -"#; +"; let test_case = CommentsTestCase::from_code(source); let comments = test_case.to_comments(); @@ -869,10 +869,10 @@ x // Comment should be attached to the statement #[test] fn trailing_most_outer() { - let source = r#" + let source = r" x # trailing comment y # trailing last node -"#; +"; let test_case = CommentsTestCase::from_code(source); let comments = test_case.to_comments(); @@ -882,11 +882,11 @@ y # trailing last node #[test] fn trailing_most_outer_nested() { - let source = r#" + let source = r" x + ( 3 # trailing comment ) # outer -"#; +"; let test_case = CommentsTestCase::from_code(source); let comments = test_case.to_comments(); @@ -896,12 +896,12 @@ x + ( #[test] fn trailing_after_comma() { - let source = r#" + let source = r" def test( a, # Trailing comment for argument `a` b, ): pass -"#; +"; let test_case = CommentsTestCase::from_code(source); let comments = test_case.to_comments(); @@ -911,7 +911,7 @@ def test( #[test] fn positional_argument_only_comment() { - let source = r#" + let source = r" def test( a, # trailing positional comment # Positional arguments only after here @@ -919,7 +919,7 @@ def test( # leading b comment b, ): pass -"#; +"; let test_case = CommentsTestCase::from_code(source); let comments = test_case.to_comments(); @@ -929,7 +929,7 @@ def test( #[test] fn positional_argument_only_leading_comma_comment() { - let source = r#" + let source = r" def test( a # trailing positional comment # Positional arguments only after here @@ -937,7 +937,7 @@ def test( # leading b comment b, ): pass -"#; +"; let test_case = CommentsTestCase::from_code(source); let comments = test_case.to_comments(); @@ -947,14 +947,14 @@ def test( #[test] fn positional_argument_only_comment_without_following_node() { - let source = r#" + let source = r" def test( a, # trailing positional comment # Positional arguments only after here /, # trailing positional argument comment. # Trailing on new line ): pass -"#; +"; let test_case = CommentsTestCase::from_code(source); let comments = test_case.to_comments(); @@ -964,7 +964,7 @@ def test( #[test] fn non_positional_arguments_with_defaults() { - let source = r#" + let source = r" def test( a=10 # trailing positional comment # Positional arguments only after here @@ -972,7 +972,7 @@ def test( # leading comment for b b=20 ): pass -"#; +"; let test_case = CommentsTestCase::from_code(source); let comments = test_case.to_comments(); @@ -982,12 +982,12 @@ def test( #[test] fn non_positional_arguments_slash_on_same_line() { - let source = r#" + let source = r" def test(a=10,/, # trailing positional argument comment. # leading comment for b b=20 ): pass -"#; +"; let test_case = CommentsTestCase::from_code(source); let comments = test_case.to_comments(); @@ -997,7 +997,7 @@ def test(a=10,/, # trailing positional argument comment. #[test] fn binary_expression_left_operand_comment() { - let source = r#" + let source = r" a = ( 5 # trailing left comment @@ -1005,7 +1005,7 @@ a = ( # leading right comment 3 ) -"#; +"; let test_case = CommentsTestCase::from_code(source); let comments = test_case.to_comments(); @@ -1015,14 +1015,14 @@ a = ( #[test] fn binary_expression_left_operand_trailing_end_of_line_comment() { - let source = r#" + let source = r" a = ( 5 # trailing left comment + # trailing operator comment # leading right comment 3 ) -"#; +"; let test_case = CommentsTestCase::from_code(source); let comments = test_case.to_comments(); @@ -1032,7 +1032,7 @@ a = ( #[test] fn nested_binary_expression() { - let source = r#" + let source = r" a = ( (5 # trailing left comment * @@ -1041,7 +1041,7 @@ a = ( # leading right comment 3 ) -"#; +"; let test_case = CommentsTestCase::from_code(source); let comments = test_case.to_comments(); @@ -1051,10 +1051,10 @@ a = ( #[test] fn while_trailing_end_of_line_comment() { - let source = r#"while True: + let source = r"while True: if something.changed: do.stuff() # trailing comment -"#; +"; let test_case = CommentsTestCase::from_code(source); @@ -1065,11 +1065,11 @@ a = ( #[test] fn while_trailing_else_end_of_line_comment() { - let source = r#"while True: + let source = r"while True: pass else: # trailing comment pass -"#; +"; let test_case = CommentsTestCase::from_code(source); diff --git a/crates/ruff_python_formatter/src/comments/placement.rs b/crates/ruff_python_formatter/src/comments/placement.rs index 2858819c2e..5fe12bd190 100644 --- a/crates/ruff_python_formatter/src/comments/placement.rs +++ b/crates/ruff_python_formatter/src/comments/placement.rs @@ -2281,10 +2281,10 @@ mod tests { assert_eq!( max_empty_lines( - r#"# This multiline comments section + r"# This multiline comments section # should be split from the statement # above by two lines. -"# +" ), 0 ); diff --git a/crates/ruff_python_formatter/src/expression/string.rs b/crates/ruff_python_formatter/src/expression/string.rs index 279b7dfb38..0fef24af91 100644 --- a/crates/ruff_python_formatter/src/expression/string.rs +++ b/crates/ruff_python_formatter/src/expression/string.rs @@ -51,7 +51,7 @@ impl<'a> AnyString<'a> { .slice(f_string.range) .trim_start_matches(|c| c != '"' && c != '\''); let triple_quoted = - unprefixed.starts_with(r#"""""#) || unprefixed.starts_with(r#"'''"#); + unprefixed.starts_with(r#"""""#) || unprefixed.starts_with(r"'''"); if f_string.values.iter().any(|value| match value { Expr::FormattedValue(ast::ExprFormattedValue { range, .. }) => { let string_content = locator.slice(*range); diff --git a/crates/ruff_python_formatter/src/lib.rs b/crates/ruff_python_formatter/src/lib.rs index 4159bda82d..d85806e3df 100644 --- a/crates/ruff_python_formatter/src/lib.rs +++ b/crates/ruff_python_formatter/src/lib.rs @@ -183,17 +183,17 @@ mod tests { /// Very basic test intentionally kept very similar to the CLI #[test] fn basic() -> Result<()> { - let input = r#" + let input = r" # preceding if True: pass # trailing -"#; - let expected = r#"# preceding +"; + let expected = r"# preceding if True: pass # trailing -"#; +"; let actual = format_module_source(input, PyFormatOptions::default())? .as_code() .to_string(); @@ -241,11 +241,11 @@ def main() -> None: assert_eq!( printed.as_code(), - r#"for converter in connection.ops.get_db_converters( + r"for converter in connection.ops.get_db_converters( expression ) + expression.get_db_converters(connection): ... -"# +" ); } @@ -304,9 +304,9 @@ def main() -> None: // 77 after g group (leading quote) let fits = - r#"aaaaaaaaaa bbbbbbbbbb cccccccccc dddddddddd eeeeeeeeee ffffffffff gggggggggg h"#; + r"aaaaaaaaaa bbbbbbbbbb cccccccccc dddddddddd eeeeeeeeee ffffffffff gggggggggg h"; let breaks = - r#"aaaaaaaaaa bbbbbbbbbb cccccccccc dddddddddd eeeeeeeeee ffffffffff gggggggggg hh"#; + r"aaaaaaaaaa bbbbbbbbbb cccccccccc dddddddddd eeeeeeeeee ffffffffff gggggggggg hh"; let output = format!( SimpleFormatContext::default(), diff --git a/crates/ruff_python_formatter/src/statement/suite.rs b/crates/ruff_python_formatter/src/statement/suite.rs index beac36ffb9..65ed7faec1 100644 --- a/crates/ruff_python_formatter/src/statement/suite.rs +++ b/crates/ruff_python_formatter/src/statement/suite.rs @@ -685,7 +685,7 @@ mod tests { use crate::PyFormatOptions; fn format_suite(level: SuiteKind) -> String { - let source = r#" + let source = r" a = 10 @@ -704,7 +704,7 @@ def func(): pass def trailing_func(): pass -"#; +"; let statements = parse_suite(source, "test.py").unwrap(); @@ -730,7 +730,7 @@ def trailing_func(): assert_eq!( formatted, - r#"a = 10 + r"a = 10 three_leading_newlines = 80 @@ -755,7 +755,7 @@ def func(): def trailing_func(): pass -"# +" ); } @@ -765,7 +765,7 @@ def trailing_func(): assert_eq!( formatted, - r#"a = 10 + r"a = 10 three_leading_newlines = 80 @@ -784,7 +784,7 @@ def func(): def trailing_func(): pass -"# +" ); } } diff --git a/crates/ruff_python_index/Cargo.toml b/crates/ruff_python_index/Cargo.toml index b82aaeeab9..1d58538623 100644 --- a/crates/ruff_python_index/Cargo.toml +++ b/crates/ruff_python_index/Cargo.toml @@ -23,3 +23,6 @@ ruff_text_size = { path = "../ruff_text_size" } itertools = { workspace = true } [dev-dependencies] + +[lints] +workspace = true diff --git a/crates/ruff_python_index/src/indexer.rs b/crates/ruff_python_index/src/indexer.rs index 78bf2606b2..8e9e209196 100644 --- a/crates/ruff_python_index/src/indexer.rs +++ b/crates/ruff_python_index/src/indexer.rs @@ -238,18 +238,18 @@ mod tests { #[test] fn continuation() { - let contents = r#"x = 1"#; + let contents = r"x = 1"; let lxr: Vec = lexer::lex(contents, Mode::Module).collect(); let indexer = Indexer::from_tokens(&lxr, &Locator::new(contents)); assert_eq!(indexer.continuation_line_starts(), &[]); - let contents = r#" + let contents = r" # Hello, world! x = 1 y = 2 - "# + " .trim(); let lxr: Vec = lexer::lex(contents, Mode::Module).collect(); diff --git a/crates/ruff_python_literal/Cargo.toml b/crates/ruff_python_literal/Cargo.toml index bce3c89a37..070e4704c6 100644 --- a/crates/ruff_python_literal/Cargo.toml +++ b/crates/ruff_python_literal/Cargo.toml @@ -21,3 +21,6 @@ unic-ucd-category = "0.9" [dev-dependencies] rand = "0.8.5" + +[lints] +workspace = true diff --git a/crates/ruff_python_parser/Cargo.toml b/crates/ruff_python_parser/Cargo.toml index 46a97eabd4..25afcf6a08 100644 --- a/crates/ruff_python_parser/Cargo.toml +++ b/crates/ruff_python_parser/Cargo.toml @@ -35,3 +35,6 @@ insta = { workspace = true } anyhow = { workspace = true } lalrpop = { version = "0.20.0", default-features = false, optional = true } tiny-keccak = { version = "2", features = ["sha3"] } + +[lints] +workspace = true diff --git a/crates/ruff_python_parser/src/lexer.rs b/crates/ruff_python_parser/src/lexer.rs index 0ca7cbc80d..2ce3d17c8e 100644 --- a/crates/ruff_python_parser/src/lexer.rs +++ b/crates/ruff_python_parser/src/lexer.rs @@ -1973,9 +1973,9 @@ def f(arg=%timeit a = b): #[test] fn tet_too_low_dedent() { let tokens: Vec<_> = lex( - r#"if True: + "if True: pass - pass"#, + pass", Mode::Module, ) .collect(); @@ -2198,10 +2198,10 @@ f"{(lambda x:{x})}" assert_eq!(lex_fstring_error(r#"f"""{""""#), UnclosedLbrace); assert_eq!(lex_fstring_error(r#"f""#), UnterminatedString); - assert_eq!(lex_fstring_error(r#"f'"#), UnterminatedString); + assert_eq!(lex_fstring_error(r"f'"), UnterminatedString); assert_eq!(lex_fstring_error(r#"f""""#), UnterminatedTripleQuotedString); - assert_eq!(lex_fstring_error(r#"f'''"#), UnterminatedTripleQuotedString); + assert_eq!(lex_fstring_error(r"f'''"), UnterminatedTripleQuotedString); assert_eq!( lex_fstring_error(r#"f"""""#), UnterminatedTripleQuotedString diff --git a/crates/ruff_python_parser/src/parser.rs b/crates/ruff_python_parser/src/parser.rs index a196c68ffc..82b5a26b8f 100644 --- a/crates/ruff_python_parser/src/parser.rs +++ b/crates/ruff_python_parser/src/parser.rs @@ -741,12 +741,12 @@ array[3:5, *indexes_to_select] #[test] fn test_try() { let parse_ast = parse_suite( - r#"try: + r"try: raise ValueError(1) except TypeError as e: print(f'caught {type(e)}') except OSError as e: - print(f'caught {type(e)}')"#, + print(f'caught {type(e)}')", "", ) .unwrap(); @@ -865,7 +865,7 @@ x = type = 1 #[test] fn numeric_literals() { - let source = r#"x = 123456789 + let source = r"x = 123456789 x = 123456 x = .1 x = 1. @@ -883,14 +883,14 @@ x = 0O777 x = 0.000000006 x = 10000 x = 133333 -"#; +"; insta::assert_debug_snapshot!(parse_suite(source, "").unwrap()); } #[test] fn numeric_literals_attribute_access() { - let source = r#"x = .1.is_integer() + let source = r"x = .1.is_integer() x = 1. .imag x = 1E+1.imag x = 1E-1.real @@ -910,7 +910,7 @@ if 10 .real: y = 100[no] y = 100(no) -"#; +"; assert_debug_snapshot!(parse_suite(source, "").unwrap()); } @@ -1173,9 +1173,9 @@ match x: #[test] fn test_variadic_generics() { let parse_ast = parse_suite( - r#" + r" def args_to_tuple(*args: *Ts) -> Tuple[*Ts]: ... -"#, +", "", ) .unwrap(); @@ -1185,7 +1185,7 @@ def args_to_tuple(*args: *Ts) -> Tuple[*Ts]: ... #[test] fn decorator_ranges() { let parse_ast = parse_suite( - r#" + r" @my_decorator def test(): pass @@ -1193,7 +1193,7 @@ def test(): @class_decorator class Abcd: pass -"# +" .trim(), "", ) @@ -1280,10 +1280,10 @@ foo.bar[0].baz[2].egg?? #[test] fn test_ipython_escape_command_parse_error() { - let source = r#" + let source = r" a = 1 %timeit a == 1 - "# + " .trim(); let lxr = lexer::lex_starts_at(source, Mode::Ipython, TextSize::default()); let parse_err = parse_tokens(lxr, source, Mode::Module, "").unwrap_err(); diff --git a/crates/ruff_python_resolver/Cargo.toml b/crates/ruff_python_resolver/Cargo.toml index 306325cbbb..9f8406520c 100644 --- a/crates/ruff_python_resolver/Cargo.toml +++ b/crates/ruff_python_resolver/Cargo.toml @@ -20,3 +20,6 @@ log = { workspace = true } env_logger = "0.10.0" tempfile = "3.8.1" insta = { workspace = true } + +[lints] +workspace = true diff --git a/crates/ruff_python_resolver/src/search.rs b/crates/ruff_python_resolver/src/search.rs index 83eb9d4f3a..5c35fa7b58 100644 --- a/crates/ruff_python_resolver/src/search.rs +++ b/crates/ruff_python_resolver/src/search.rs @@ -116,7 +116,7 @@ fn find_paths_from_pth_files(parent_dir: &Path) -> io::Result 0 && file_len < 64 * 1024 }) .filter_map(|path| { - let data = fs::read_to_string(&path).ok()?; + let data = fs::read_to_string(path).ok()?; for line in data.lines() { let trimmed_line = line.trim(); if !trimmed_line.is_empty() diff --git a/crates/ruff_python_semantic/Cargo.toml b/crates/ruff_python_semantic/Cargo.toml index 602a0e27c1..696643e09c 100644 --- a/crates/ruff_python_semantic/Cargo.toml +++ b/crates/ruff_python_semantic/Cargo.toml @@ -26,3 +26,6 @@ smallvec = { workspace = true } [dev-dependencies] ruff_python_parser = { path = "../ruff_python_parser" } + +[lints] +workspace = true diff --git a/crates/ruff_python_stdlib/Cargo.toml b/crates/ruff_python_stdlib/Cargo.toml index 807ccc0f5c..19d5df0328 100644 --- a/crates/ruff_python_stdlib/Cargo.toml +++ b/crates/ruff_python_stdlib/Cargo.toml @@ -14,3 +14,6 @@ license = { workspace = true } [dependencies] unicode-ident = { workspace = true } + +[lints] +workspace = true diff --git a/crates/ruff_python_trivia/Cargo.toml b/crates/ruff_python_trivia/Cargo.toml index e77cf41bac..e17aafc44b 100644 --- a/crates/ruff_python_trivia/Cargo.toml +++ b/crates/ruff_python_trivia/Cargo.toml @@ -23,3 +23,6 @@ unicode-ident = { workspace = true } insta = { workspace = true } ruff_python_ast = { path = "../ruff_python_ast" } ruff_python_parser = { path = "../ruff_python_parser" } + +[lints] +workspace = true diff --git a/crates/ruff_python_trivia/src/textwrap.rs b/crates/ruff_python_trivia/src/textwrap.rs index 33d92c0205..e0d07e8f3b 100644 --- a/crates/ruff_python_trivia/src/textwrap.rs +++ b/crates/ruff_python_trivia/src/textwrap.rs @@ -337,10 +337,10 @@ mod tests { #[test] fn dedent_non_python_whitespace() { - let text = r#"        C = int(f.rea1,0],[-1,0,1]], + let text = r"        C = int(f.rea1,0],[-1,0,1]], [[-1,-1,1],[1,1,-1],[0,-1,0]], [[-1,-1,-1],[1,1,0],[1,0,1]] - ]"#; + ]"; assert_eq!(dedent(text), text); } } diff --git a/crates/ruff_python_trivia/src/tokenizer.rs b/crates/ruff_python_trivia/src/tokenizer.rs index f19b30ed4c..7865a80187 100644 --- a/crates/ruff_python_trivia/src/tokenizer.rs +++ b/crates/ruff_python_trivia/src/tokenizer.rs @@ -1184,9 +1184,9 @@ mod tests { #[test] fn tokenize_slash() { - let source = r#" # trailing positional comment + let source = r" # trailing positional comment # Positional arguments only after here - ,/"#; + ,/"; let test_case = tokenize(source); @@ -1229,8 +1229,8 @@ mod tests { #[test] fn triple_quoted_multiline_string_containing_comment() { let test_case = tokenize( - r#"'''This string contains a hash looking like a comment -# This is not a comment'''"#, + r"'''This string contains a hash looking like a comment +# This is not a comment'''", ); assert_debug_snapshot!(test_case.tokenize_reverse()); @@ -1274,7 +1274,7 @@ mod tests { #[test] fn empty_string_literal() { - let test_case = tokenize(r#"'' # a comment '"#); + let test_case = tokenize(r"'' # a comment '"); assert_debug_snapshot!(test_case.tokenize_reverse()); } diff --git a/crates/ruff_python_trivia/src/whitespace.rs b/crates/ruff_python_trivia/src/whitespace.rs index 78688f5e4a..81b6a5bcbd 100644 --- a/crates/ruff_python_trivia/src/whitespace.rs +++ b/crates/ruff_python_trivia/src/whitespace.rs @@ -114,10 +114,10 @@ mod tests { let locator = Locator::new(contents); assert!(!has_trailing_content(stmt.end(), &locator)); - let contents = r#" + let contents = r" x = 1 y = 2 -"# +" .trim(); let program = parse_suite(contents, "")?; let stmt = program.first().unwrap(); diff --git a/crates/ruff_shrinking/Cargo.toml b/crates/ruff_shrinking/Cargo.toml index 7aff7d7e06..5676f4f079 100644 --- a/crates/ruff_shrinking/Cargo.toml +++ b/crates/ruff_shrinking/Cargo.toml @@ -16,3 +16,6 @@ ruff_text_size = { path = "../ruff_text_size" } shlex = "1.2.0" tracing = { workspace = true } tracing-subscriber = { workspace = true, features = ["env-filter"] } + +[lints] +workspace = true diff --git a/crates/ruff_source_file/Cargo.toml b/crates/ruff_source_file/Cargo.toml index 9d02d7d2a2..d96a80f795 100644 --- a/crates/ruff_source_file/Cargo.toml +++ b/crates/ruff_source_file/Cargo.toml @@ -21,6 +21,8 @@ serde = { workspace = true, optional = true } [dev-dependencies] insta = { workspace = true } - [features] serde = ["dep:serde", "ruff_text_size/serde"] + +[lints] +workspace = true diff --git a/crates/ruff_text_size/Cargo.toml b/crates/ruff_text_size/Cargo.toml index 7878d5e16b..8c6f7e225e 100644 --- a/crates/ruff_text_size/Cargo.toml +++ b/crates/ruff_text_size/Cargo.toml @@ -16,6 +16,9 @@ static_assertions = { version = "1.1.0" } [features] serde = ["dep:serde"] +[lints] +workspace = true + [[test]] name = "serde" path = "tests/serde.rs" diff --git a/crates/ruff_wasm/Cargo.toml b/crates/ruff_wasm/Cargo.toml index 34d1e278e1..d8884eb14a 100644 --- a/crates/ruff_wasm/Cargo.toml +++ b/crates/ruff_wasm/Cargo.toml @@ -42,3 +42,6 @@ js-sys = { version = "0.3.61" } [dev-dependencies] wasm-bindgen-test = { version = "0.3.34" } + +[lints] +workspace = true diff --git a/crates/ruff_workspace/Cargo.toml b/crates/ruff_workspace/Cargo.toml index af86e64035..645c32be59 100644 --- a/crates/ruff_workspace/Cargo.toml +++ b/crates/ruff_workspace/Cargo.toml @@ -44,8 +44,9 @@ toml = { workspace = true } [dev-dependencies] tempfile = "3.8.1" - [features] +default = [] schemars = [ "dep:schemars", "ruff_formatter/schemars", "ruff_python_formatter/schemars" ] -default = [] +[lints] +workspace = true diff --git a/crates/ruff_workspace/src/pyproject.rs b/crates/ruff_workspace/src/pyproject.rs index 5462fa6aec..3fe7fe35bc 100644 --- a/crates/ruff_workspace/src/pyproject.rs +++ b/crates/ruff_workspace/src/pyproject.rs @@ -169,21 +169,21 @@ mod tests { #[test] fn deserialize() -> Result<()> { - let pyproject: Pyproject = toml::from_str(r#""#)?; + let pyproject: Pyproject = toml::from_str(r"")?; assert_eq!(pyproject.tool, None); let pyproject: Pyproject = toml::from_str( - r#" + r" [tool.black] -"#, +", )?; assert_eq!(pyproject.tool, Some(Tools { ruff: None })); let pyproject: Pyproject = toml::from_str( - r#" + r" [tool.black] [tool.ruff] -"#, +", )?; assert_eq!( pyproject.tool, @@ -193,11 +193,11 @@ mod tests { ); let pyproject: Pyproject = toml::from_str( - r#" + r" [tool.black] [tool.ruff] line-length = 79 -"#, +", )?; assert_eq!( pyproject.tool, @@ -275,11 +275,11 @@ ignore = ["E501"] ); assert!(toml::from_str::( - r#" + r" [tool.black] [tool.ruff] line_length = 79 -"#, +", ) .is_err()); @@ -293,12 +293,12 @@ select = ["E123"] .is_err()); assert!(toml::from_str::( - r#" + r" [tool.black] [tool.ruff] line-length = 79 other-attribute = 1 -"#, +", ) .is_err()); diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 50fa4928b9..71326c3d73 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,2 +1,2 @@ [toolchain] -channel = "1.73" +channel = "1.74"