Skip to content

Commit

Permalink
tidy up
Browse files Browse the repository at this point in the history
  • Loading branch information
ntBre committed Feb 20, 2025
1 parent d9d6022 commit 778c559
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 15 deletions.
6 changes: 3 additions & 3 deletions crates/ruff_linter/src/settings/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use rustc_hash::FxHashSet;
use std::fmt::{Display, Formatter};
use std::path::{Path, PathBuf};
use std::sync::LazyLock;
use types::CompiledPerFileVersionList;
use types::CompiledPerFileTargetVersionList;

use crate::codes::RuleCodePrefix;
use ruff_macros::CacheKey;
Expand Down Expand Up @@ -230,7 +230,7 @@ pub struct LinterSettings {
/// See [`LinterSettings::resolve_target_version`] for a way to check a given [`Path`]
/// against these patterns, while falling back to `unresolved_target_version` if none of them
/// match.
pub per_file_target_version: CompiledPerFileVersionList,
pub per_file_target_version: CompiledPerFileTargetVersionList,
pub preview: PreviewMode,
pub explicit_preview_rules: bool,

Expand Down Expand Up @@ -390,7 +390,7 @@ impl LinterSettings {
Self {
exclude: FilePatternSet::default(),
unresolved_target_version: PythonVersion::default(),
per_file_target_version: CompiledPerFileVersionList::default(),
per_file_target_version: CompiledPerFileTargetVersionList::default(),
project_root: project_root.to_path_buf(),
rules: DEFAULT_SELECTORS
.iter()
Expand Down
12 changes: 7 additions & 5 deletions crates/ruff_linter/src/settings/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,8 @@ impl<T> PerFile<T> {
}

/// Per-file ignored linting rules.
///
/// See [`PerFile`] for details of the representation.
#[derive(Debug, Clone)]
pub struct PerFileIgnore(PerFile<RuleSet>);

Expand Down Expand Up @@ -780,15 +782,15 @@ impl PerFileTargetVersion {
}

#[derive(CacheKey, Clone, Debug, Default)]
pub struct CompiledPerFileVersionList(CompiledPerFileList<ast::PythonVersion>);
pub struct CompiledPerFileTargetVersionList(CompiledPerFileList<ast::PythonVersion>);

impl CompiledPerFileVersionList {
impl CompiledPerFileTargetVersionList {
/// Given a list of [`PerFileTargetVersion`] patterns, create a compiled set of globs.
///
/// Returns an error if either of the glob patterns cannot be parsed.
pub fn resolve(per_file_ignores: Vec<PerFileTargetVersion>) -> Result<Self> {
pub fn resolve(per_file_versions: Vec<PerFileTargetVersion>) -> Result<Self> {
Ok(Self(CompiledPerFileList::resolve(
per_file_ignores.into_iter().map(|version| version.0),
per_file_versions.into_iter().map(|version| version.0),
)?))
}

Expand All @@ -797,7 +799,7 @@ impl CompiledPerFileVersionList {
}
}

impl Display for CompiledPerFileVersionList {
impl Display for CompiledPerFileTargetVersionList {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
self.0.fmt(f)
}
Expand Down
9 changes: 5 additions & 4 deletions crates/ruff_workspace/src/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use ruff_linter::rules::{flake8_import_conventions, isort, pycodestyle};
use ruff_linter::settings::fix_safety_table::FixSafetyTable;
use ruff_linter::settings::rule_table::RuleTable;
use ruff_linter::settings::types::{
CompiledPerFileIgnoreList, CompiledPerFileVersionList, ExtensionMapping, FilePattern,
CompiledPerFileIgnoreList, CompiledPerFileTargetVersionList, ExtensionMapping, FilePattern,
FilePatternSet, OutputFormat, PerFileIgnore, PerFileTargetVersion, PreviewMode,
RequiredVersion, UnsafeFixes,
};
Expand Down Expand Up @@ -176,9 +176,10 @@ impl Configuration {
PreviewMode::Enabled => ruff_python_formatter::PreviewMode::Enabled,
};

let per_file_target_version =
CompiledPerFileVersionList::resolve(self.per_file_target_version.unwrap_or_default())
.context("failed to resolve `per-file-target-version` table")?;
let per_file_target_version = CompiledPerFileTargetVersionList::resolve(
self.per_file_target_version.unwrap_or_default(),
)
.context("failed to resolve `per-file-target-version` table")?;

let formatter = FormatterSettings {
exclude: FilePatternSet::try_from_iter(format.exclude.unwrap_or_default())?,
Expand Down
6 changes: 3 additions & 3 deletions crates/ruff_workspace/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use ruff_formatter::{FormatOptions, IndentStyle, IndentWidth, LineWidth};
use ruff_graph::AnalyzeSettings;
use ruff_linter::display_settings;
use ruff_linter::settings::types::{
CompiledPerFileVersionList, ExtensionMapping, FilePattern, FilePatternSet, OutputFormat,
CompiledPerFileTargetVersionList, ExtensionMapping, FilePattern, FilePatternSet, OutputFormat,
UnsafeFixes,
};
use ruff_linter::settings::LinterSettings;
Expand Down Expand Up @@ -175,7 +175,7 @@ pub struct FormatterSettings {
/// See [`FormatterSettings::resolve_target_version`] for a way to check a given [`Path`]
/// against these patterns, while falling back to `unresolved_target_version` if none of them
/// match.
pub per_file_target_version: CompiledPerFileVersionList,
pub per_file_target_version: CompiledPerFileTargetVersionList,

pub line_width: LineWidth,

Expand Down Expand Up @@ -257,7 +257,7 @@ impl Default for FormatterSettings {
exclude: FilePatternSet::default(),
extension: ExtensionMapping::default(),
unresolved_target_version: default_options.target_version(),
per_file_target_version: CompiledPerFileVersionList::default(),
per_file_target_version: CompiledPerFileTargetVersionList::default(),
preview: PreviewMode::Disabled,
line_width: default_options.line_width(),
line_ending: LineEnding::Auto,
Expand Down

0 comments on commit 778c559

Please sign in to comment.