mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-28 04:45:01 +00:00
Move fix::FixMode
to flags::FixMode
(#3753)
This commit is contained in:
parent
cd75b57036
commit
6ed6da3e82
8 changed files with 67 additions and 66 deletions
|
@ -12,11 +12,11 @@ use log::{debug, error};
|
|||
use rustc_hash::FxHashMap;
|
||||
use similar::TextDiff;
|
||||
|
||||
use ruff::fs;
|
||||
use ruff::jupyter::{is_jupyter_notebook, JupyterIndex, JupyterNotebook};
|
||||
use ruff::linter::{lint_fix, lint_only, FixTable, LinterResult};
|
||||
use ruff::message::Message;
|
||||
use ruff::settings::{flags, AllSettings, Settings};
|
||||
use ruff::{fix, fs};
|
||||
|
||||
use crate::cache;
|
||||
|
||||
|
@ -100,7 +100,7 @@ pub fn lint_path(
|
|||
settings: &AllSettings,
|
||||
cache: flags::Cache,
|
||||
noqa: flags::Noqa,
|
||||
autofix: fix::FixMode,
|
||||
autofix: flags::FixMode,
|
||||
) -> Result<Diagnostics> {
|
||||
// Check the cache.
|
||||
// TODO(charlie): `fixer::Mode::Apply` and `fixer::Mode::Diff` both have
|
||||
|
@ -110,7 +110,7 @@ pub fn lint_path(
|
|||
// to reason about. We need to come up with a better solution here.)
|
||||
let metadata = if cache.into()
|
||||
&& noqa.into()
|
||||
&& matches!(autofix, fix::FixMode::None | fix::FixMode::Generate)
|
||||
&& matches!(autofix, flags::FixMode::None | flags::FixMode::Generate)
|
||||
{
|
||||
let metadata = path.metadata()?;
|
||||
if let Some(messages) =
|
||||
|
@ -143,14 +143,14 @@ pub fn lint_path(
|
|||
error: parse_error,
|
||||
},
|
||||
fixed,
|
||||
) = if matches!(autofix, fix::FixMode::Apply | fix::FixMode::Diff) {
|
||||
) = if matches!(autofix, flags::FixMode::Apply | flags::FixMode::Diff) {
|
||||
if let Ok((result, transformed, fixed)) =
|
||||
lint_fix(&contents, path, package, noqa, &settings.lib)
|
||||
{
|
||||
if !fixed.is_empty() {
|
||||
if matches!(autofix, fix::FixMode::Apply) {
|
||||
if matches!(autofix, flags::FixMode::Apply) {
|
||||
write(path, transformed.as_bytes())?;
|
||||
} else if matches!(autofix, fix::FixMode::Diff) {
|
||||
} else if matches!(autofix, flags::FixMode::Diff) {
|
||||
let mut stdout = io::stdout().lock();
|
||||
TextDiff::from_lines(contents.as_str(), &transformed)
|
||||
.unified_diff()
|
||||
|
@ -243,7 +243,7 @@ pub fn lint_stdin(
|
|||
contents: &str,
|
||||
settings: &Settings,
|
||||
noqa: flags::Noqa,
|
||||
autofix: fix::FixMode,
|
||||
autofix: flags::FixMode,
|
||||
) -> Result<Diagnostics> {
|
||||
// Lint the inputs.
|
||||
let (
|
||||
|
@ -252,7 +252,7 @@ pub fn lint_stdin(
|
|||
error: parse_error,
|
||||
},
|
||||
fixed,
|
||||
) = if matches!(autofix, fix::FixMode::Apply | fix::FixMode::Diff) {
|
||||
) = if matches!(autofix, flags::FixMode::Apply | flags::FixMode::Diff) {
|
||||
if let Ok((result, transformed, fixed)) = lint_fix(
|
||||
contents,
|
||||
path.unwrap_or_else(|| Path::new("-")),
|
||||
|
@ -260,10 +260,10 @@ pub fn lint_stdin(
|
|||
noqa,
|
||||
settings,
|
||||
) {
|
||||
if matches!(autofix, fix::FixMode::Apply) {
|
||||
if matches!(autofix, flags::FixMode::Apply) {
|
||||
// Write the contents to stdout, regardless of whether any errors were fixed.
|
||||
io::stdout().write_all(transformed.as_bytes())?;
|
||||
} else if matches!(autofix, fix::FixMode::Diff) {
|
||||
} else if matches!(autofix, flags::FixMode::Diff) {
|
||||
// But only write a diff if it's non-empty.
|
||||
if !fixed.is_empty() {
|
||||
let text_diff = TextDiff::from_lines(contents, &transformed);
|
||||
|
@ -293,7 +293,7 @@ pub fn lint_stdin(
|
|||
let fixed = FxHashMap::default();
|
||||
|
||||
// Write the contents to stdout anyway.
|
||||
if matches!(autofix, fix::FixMode::Apply) {
|
||||
if matches!(autofix, flags::FixMode::Apply) {
|
||||
io::stdout().write_all(contents.as_bytes())?;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue