mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-09 10:00:25 +00:00
Adapt BoolLike to flags (#3175)
This commit is contained in:
parent
6e54cd8233
commit
c8c575dd43
5 changed files with 6 additions and 27 deletions
|
@ -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)
|
||||||
|
|
|
@ -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()
|
||||||
|
|
|
@ -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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -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) {
|
||||||
|
|
|
@ -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) =
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue