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

@ -57,6 +57,7 @@ pub fn lint_path(
package: Option<&Path>,
settings: &AllSettings,
cache: flags::Cache,
noqa: flags::Noqa,
autofix: fix::FixMode,
) -> Result<Diagnostics> {
// Check the cache.
@ -65,7 +66,9 @@ pub fn lint_path(
// to cache `fixer::Mode::Apply`, since a file either has no fixes, or we'll
// write the fixes to disk, thus invalidating the cache. But it's a bit hard
// to reason about. We need to come up with a better solution here.)
let metadata = if cache.into() && matches!(autofix, fix::FixMode::None | fix::FixMode::Generate)
let metadata = if cache.into()
&& noqa.into()
&& matches!(autofix, fix::FixMode::None | fix::FixMode::Generate)
{
let metadata = path.metadata()?;
if let Some(messages) =
@ -90,7 +93,8 @@ pub fn lint_path(
},
fixed,
) = if matches!(autofix, fix::FixMode::Apply | fix::FixMode::Diff) {
if let Ok((result, transformed, fixed)) = lint_fix(&contents, path, package, &settings.lib)
if let Ok((result, transformed, fixed)) =
lint_fix(&contents, path, package, noqa, &settings.lib)
{
if !fixed.is_empty() {
if matches!(autofix, fix::FixMode::Apply) {
@ -108,12 +112,26 @@ pub fn lint_path(
(result, fixed)
} else {
// If we fail to autofix, lint the original source code.
let result = lint_only(&contents, path, package, &settings.lib, autofix.into());
let result = lint_only(
&contents,
path,
package,
&settings.lib,
noqa,
autofix.into(),
);
let fixed = FxHashMap::default();
(result, fixed)
}
} else {
let result = lint_only(&contents, path, package, &settings.lib, autofix.into());
let result = lint_only(
&contents,
path,
package,
&settings.lib,
noqa,
autofix.into(),
);
let fixed = FxHashMap::default();
(result, fixed)
};
@ -158,6 +176,7 @@ pub fn lint_stdin(
package: Option<&Path>,
contents: &str,
settings: &Settings,
noqa: flags::Noqa,
autofix: fix::FixMode,
) -> Result<Diagnostics> {
// Lint the inputs.
@ -172,6 +191,7 @@ pub fn lint_stdin(
contents,
path.unwrap_or_else(|| Path::new("-")),
package,
noqa,
settings,
) {
if matches!(autofix, fix::FixMode::Apply) {
@ -201,6 +221,7 @@ pub fn lint_stdin(
path.unwrap_or_else(|| Path::new("-")),
package,
settings,
noqa,
autofix.into(),
);
let fixed = FxHashMap::default();
@ -218,6 +239,7 @@ pub fn lint_stdin(
path.unwrap_or_else(|| Path::new("-")),
package,
settings,
noqa,
autofix.into(),
);
let fixed = FxHashMap::default();