Consider unsafe-fixes settings for code actions (#15666)

## Summary

Closes: #13960 

## Test Plan

Using the example from
https://github.com/astral-sh/ruff-vscode/issues/672:


https://github.com/user-attachments/assets/7bdb01ef-8752-4cb7-9b5d-8a0d131984da
This commit is contained in:
Dhruv Manilawala 2025-01-22 13:44:13 +05:30 committed by GitHub
parent 792f9e357e
commit 043ff61a0b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 13 additions and 2 deletions

View file

@ -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;
@ -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,

View file

@ -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,
@ -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.
@ -77,6 +80,7 @@ impl RuffSettings {
RuffSettings {
path,
unsafe_fixes: fallback.unsafe_fixes,
file_resolver: fallback.file_resolver,
formatter: fallback.formatter,
linter: fallback.linter,
@ -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 {
@ -143,6 +152,7 @@ impl RuffSettingsIndex {
directory.to_path_buf(),
Arc::new(RuffSettings {
path: Some(pyproject),
unsafe_fixes: settings.unsafe_fixes,
file_resolver: settings.file_resolver,
linter: settings.linter,
formatter: settings.formatter,
@ -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,