Add a CLI flag to force-ignore noqa directives (#3296)

This commit is contained in:
Charlie Marsh 2023-03-01 22:28:13 -05:00 committed by GitHub
parent 4a70a4c323
commit 3ed539d50e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 55 additions and 15 deletions

View file

@ -26,6 +26,7 @@ pub fn run(
pyproject_strategy: &PyprojectDiscovery,
overrides: &Overrides,
cache: flags::Cache,
noqa: flags::Noqa,
autofix: fix::FixMode,
) -> Result<Diagnostics> {
// Collect all the Python files to check.
@ -84,7 +85,7 @@ pub fn run(
.and_then(|parent| package_roots.get(parent))
.and_then(|package| *package);
let settings = resolver.resolve_all(path, pyproject_strategy);
lint_path(path, package, settings, cache, autofix)
lint_path(path, package, settings, cache, noqa, autofix)
.map_err(|e| (Some(path.to_owned()), e.to_string()))
}
Err(e) => Err((

View file

@ -4,6 +4,7 @@ use std::path::Path;
use anyhow::Result;
use ruff::resolver::PyprojectDiscovery;
use ruff::settings::flags;
use ruff::{fix, packaging, resolver};
use crate::args::Overrides;
@ -21,6 +22,7 @@ pub fn run_stdin(
filename: Option<&Path>,
pyproject_strategy: &PyprojectDiscovery,
overrides: &Overrides,
noqa: flags::Noqa,
autofix: fix::FixMode,
) -> Result<Diagnostics> {
if let Some(filename) = filename {
@ -33,7 +35,7 @@ pub fn run_stdin(
.and_then(Path::parent)
.and_then(|path| packaging::detect_package_root(path, &settings.lib.namespace_packages));
let stdin = read_from_stdin()?;
let mut diagnostics = lint_stdin(filename, package_root, &stdin, &settings.lib, autofix)?;
let mut diagnostics = lint_stdin(filename, package_root, &stdin, &settings.lib, noqa, autofix)?;
diagnostics.messages.sort_unstable();
Ok(diagnostics)
}