Move error and warning messages into log macro (#2669)

This commit is contained in:
Charlie Marsh 2023-02-08 14:39:09 -05:00 committed by GitHub
parent 75fad989f4
commit 81abc5d7d8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 61 additions and 56 deletions

View file

@ -7,7 +7,7 @@ use std::path::Path;
use anyhow::Result;
use colored::Colorize;
use log::debug;
use log::{debug, error};
use ruff::linter::{lint_fix, lint_only, LinterResult};
use ruff::message::Message;
use ruff::settings::{flags, AllSettings, Settings};
@ -105,17 +105,12 @@ pub fn lint_path(
if let Some(err) = parse_error {
// Notify the user of any parse errors.
#[allow(clippy::print_stderr)]
{
eprintln!(
"{}{} {}{}{} {err}",
"error".red().bold(),
":".bold(),
"Failed to parse ".bold(),
fs::relativize_path(path).bold(),
":".bold()
);
}
error!(
"{}{}{} {err}",
"Failed to parse ".bold(),
fs::relativize_path(path).bold(),
":".bold()
);
// Purge the cache.
cache::del(path, package.as_ref(), settings, autofix.into());
@ -210,15 +205,10 @@ pub fn lint_stdin(
};
if let Some(err) = parse_error {
#[allow(clippy::print_stderr)]
{
eprintln!(
"{}{} Failed to parse {}: {err}",
"error".red().bold(),
":".bold(),
path.map_or_else(|| "-".into(), fs::relativize_path).bold()
);
}
error!(
"Failed to parse {}: {err}",
path.map_or_else(|| "-".into(), fs::relativize_path).bold()
);
}
Ok(Diagnostics { messages, fixed })

View file

@ -3,16 +3,17 @@ use std::path::PathBuf;
use std::process::ExitCode;
use std::sync::mpsc::channel;
use anyhow::Result;
use clap::{CommandFactory, Parser, Subcommand};
use colored::Colorize;
use notify::{recommended_watcher, RecursiveMode, Watcher};
use ::ruff::logging::{set_up_logging, LogLevel};
use ::ruff::resolver::PyprojectDiscovery;
use ::ruff::settings::types::SerializationFormat;
use ::ruff::settings::CliSettings;
use ::ruff::{fix, fs, warn_user_once};
use anyhow::Result;
use args::{Args, CheckArgs, Command};
use clap::{CommandFactory, Parser, Subcommand};
use colored::Colorize;
use notify::{recommended_watcher, RecursiveMode, Watcher};
use printer::{Printer, Violations};
pub(crate) mod args;