Adapt BoolLike to flags (#3175)

This commit is contained in:
Jeong YunWon 2023-02-24 06:31:46 +09:00 committed by GitHub
parent 6e54cd8233
commit c8c575dd43
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 6 additions and 27 deletions

View file

@ -295,7 +295,7 @@ impl<'a> Checker<'a> {
// members from the fix that will eventually be excluded by a `noqa`. // members from the fix that will eventually be excluded by a `noqa`.
// Unfortunately, we _do_ want to register a `Diagnostic` for each // Unfortunately, we _do_ want to register a `Diagnostic` for each
// eventually-ignored import, so that our `noqa` counts are accurate. // eventually-ignored import, so that our `noqa` counts are accurate.
if matches!(self.noqa, flags::Noqa::Disabled) { if !self.noqa.to_bool() {
return false; return false;
} }
noqa::rule_is_ignored(code, lineno, self.noqa_line_for, self.locator) noqa::rule_is_ignored(code, lineno, self.noqa_line_for, self.locator)

View file

@ -199,7 +199,7 @@ pub fn check_path(
}; };
// Enforce `noqa` directives. // Enforce `noqa` directives.
if (matches!(noqa, flags::Noqa::Enabled) && !diagnostics.is_empty()) if (noqa.into() && !diagnostics.is_empty())
|| settings || settings
.rules .rules
.iter_enabled() .iter_enabled()

View file

@ -15,34 +15,14 @@ impl From<fix::FixMode> for Autofix {
} }
} }
#[derive(Debug, Copy, Clone, Hash)] #[derive(Debug, Copy, Clone, Hash, result_like::BoolLike)]
pub enum Noqa { pub enum Noqa {
Enabled, Enabled,
Disabled, Disabled,
} }
impl From<bool> for Noqa { #[derive(Debug, Copy, Clone, Hash, result_like::BoolLike)]
fn from(value: bool) -> Self {
if value {
Self::Enabled
} else {
Self::Disabled
}
}
}
#[derive(Debug, Copy, Clone, Hash)]
pub enum Cache { pub enum Cache {
Enabled, Enabled,
Disabled, Disabled,
} }
impl From<bool> for Cache {
fn from(value: bool) -> Self {
if value {
Self::Enabled
} else {
Self::Disabled
}
}
}

View file

@ -40,7 +40,7 @@ pub fn run(
} }
// Initialize the cache. // Initialize the cache.
if matches!(cache, flags::Cache::Enabled) { if cache.into() {
match &pyproject_strategy { match &pyproject_strategy {
PyprojectDiscovery::Fixed(settings) => { PyprojectDiscovery::Fixed(settings) => {
if let Err(e) = cache::init(&settings.cli.cache_dir) { if let Err(e) = cache::init(&settings.cli.cache_dir) {

View file

@ -65,8 +65,7 @@ pub fn lint_path(
// to cache `fixer::Mode::Apply`, since a file either has no fixes, or we'll // 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 // 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.) // to reason about. We need to come up with a better solution here.)
let metadata = if matches!(cache, flags::Cache::Enabled) let metadata = if cache.into() && matches!(autofix, fix::FixMode::None | fix::FixMode::Generate)
&& matches!(autofix, fix::FixMode::None | fix::FixMode::Generate)
{ {
let metadata = path.metadata()?; let metadata = path.metadata()?;
if let Some(messages) = if let Some(messages) =