Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider unsafe-fixes settings for code actions #15666

Merged
merged 1 commit into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions crates/ruff_server/src/fix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use ruff_linter::package::PackageRoot;
use ruff_linter::{
linter::{FixerResult, LinterResult},
packaging::detect_package_root,
settings::{flags, types::UnsafeFixes, LinterSettings},
settings::{flags, LinterSettings},
};
use ruff_notebook::SourceValue;
use ruff_source_file::LineIndex;
Expand Down Expand Up @@ -71,7 +71,7 @@ pub(crate) fn fix_all(
&query.virtual_file_path(),
package,
flags::Noqa::Enabled,
UnsafeFixes::Disabled,
query.settings().unsafe_fixes(),
linter_settings,
&source_kind,
source_type,
Expand Down
11 changes: 11 additions & 0 deletions crates/ruff_server/src/session/index/ruff_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::sync::Arc;
use anyhow::Context;
use ignore::{WalkBuilder, WalkState};

use ruff_linter::settings::types::UnsafeFixes;
use ruff_linter::{
display_settings, fs::normalize_path_to, settings::types::FilePattern,
settings::types::PreviewMode,
Expand All @@ -23,6 +24,8 @@ pub struct RuffSettings {
/// The path to this configuration file, used for debugging.
/// The default fallback configuration does not have a file path.
path: Option<PathBuf>,
/// Toggle for unsafe fixes.
unsafe_fixes: UnsafeFixes,
/// Settings used to manage file inclusion and exclusion.
file_resolver: ruff_workspace::FileResolverSettings,
/// Settings to pass into the Ruff linter.
Expand Down Expand Up @@ -77,6 +80,7 @@ impl RuffSettings {

RuffSettings {
path,
unsafe_fixes: fallback.unsafe_fixes,
file_resolver: fallback.file_resolver,
formatter: fallback.formatter,
linter: fallback.linter,
Expand All @@ -97,6 +101,11 @@ impl RuffSettings {
pub(crate) fn formatter(&self) -> &ruff_workspace::FormatterSettings {
&self.formatter
}

/// Return the [`UnsafeFixes`] for this [`RuffSettings`].
pub(crate) fn unsafe_fixes(&self) -> UnsafeFixes {
self.unsafe_fixes
}
}

impl RuffSettingsIndex {
Expand Down Expand Up @@ -143,6 +152,7 @@ impl RuffSettingsIndex {
directory.to_path_buf(),
Arc::new(RuffSettings {
path: Some(pyproject),
unsafe_fixes: settings.unsafe_fixes,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you remember what's the reason for only storing parts of the settings instead of the entire settings struct with accessors for the linter/formatter settings?

Copy link
Member Author

@dhruvmanila dhruvmanila Jan 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it started out with just having LinterSettings and FormatterSettings (#10950) but later on we realized (via bug reports) that exclusions weren't being considered by the server which led to adding the FileResolverSettings (#11551).

It makes me wonder if we should simply store the entire Settings struct in RuffSettings. It seems like we eventually will need all of them anyway?

Yeah, I agree. I can do that as a follow-up.

file_resolver: settings.file_resolver,
linter: settings.linter,
formatter: settings.formatter,
Expand Down Expand Up @@ -267,6 +277,7 @@ impl RuffSettingsIndex {
directory,
Arc::new(RuffSettings {
path: Some(pyproject),
unsafe_fixes: settings.unsafe_fixes,
file_resolver: settings.file_resolver,
linter: settings.linter,
formatter: settings.formatter,
Expand Down
Loading