Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Split add_noqa process into distinctive edit generation and edit application stages #11265

Merged
merged 7 commits into from
May 10, 2024
Merged
65 changes: 65 additions & 0 deletions crates/ruff/tests/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1553,3 +1553,68 @@ def unused(x): # noqa: ANN001, ARG001, D103

Ok(())
}

#[test]
fn add_noqa_multiline_comment() -> Result<()> {
let tempdir = TempDir::new()?;
let ruff_toml = tempdir.path().join("ruff.toml");
fs::write(
&ruff_toml,
r#"
[lint]
select = ["UP031"]
"#,
)?;

let test_path = tempdir.path().join("noqa.py");

fs::write(
&test_path,
r#"
print(
"""First line
second line
third line
%s"""
% name
)
"#,
)?;

insta::with_settings!({
filters => vec![(tempdir_filter(&tempdir).as_str(), "[TMP]/")]
}, {
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
.current_dir(tempdir.path())
.args(STDIN_BASE_OPTIONS)
.args(["--config", &ruff_toml.file_name().unwrap().to_string_lossy()])
.arg(&test_path)
.arg("--preview")
.args(["--add-noqa"])
.arg("-")
.pass_stdin(r#"

"#), @r###"
success: true
exit_code: 0
----- stdout -----

----- stderr -----
Added 1 noqa directive.
"###);
});

let test_code = std::fs::read_to_string(&test_path).expect("should read test file");

insta::assert_snapshot!(test_code, @r###"
print(
"""First line
second line
third line
%s""" # noqa: UP031
% name
)
"###);

Ok(())
}
1 change: 1 addition & 0 deletions crates/ruff_linter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
//!
//! [Ruff]: https://github.com/astral-sh/ruff

pub use noqa::generate_noqa_edits;
#[cfg(feature = "clap")]
pub use registry::clap_completion::RuleParser;
#[cfg(feature = "clap")]
Expand Down