mirror of
https://github.com/astral-sh/ruff.git
synced 2025-07-24 13:33:50 +00:00
Improve formatter contributor docs (#6776)
The docs were out of date, and the new version incorporates some feedback. I tried to keep the language concise and the information ordered by how early you need it, so people can get the relevant information quickly before jumping into the code. I did some minor format_dev changes for consistency in the docs. --------- Co-authored-by: Micha Reiser <micha@reiser.io>
This commit is contained in:
parent
04a9a8dd03
commit
d376cb4c2a
3 changed files with 218 additions and 108 deletions
|
@ -207,8 +207,15 @@ pub(crate) struct Args {
|
|||
pub(crate) fn main(args: &Args) -> anyhow::Result<ExitCode> {
|
||||
setup_logging(&args.log_level_args, args.log_file.as_deref())?;
|
||||
|
||||
let mut error_file = match &args.error_file {
|
||||
Some(error_file) => Some(BufWriter::new(
|
||||
File::create(error_file).context("Couldn't open error file")?,
|
||||
)),
|
||||
None => None,
|
||||
};
|
||||
|
||||
let all_success = if args.multi_project {
|
||||
format_dev_multi_project(args)?
|
||||
format_dev_multi_project(args, error_file)?
|
||||
} else {
|
||||
let result = format_dev_project(&args.files, args.stability_check, args.write)?;
|
||||
let error_count = result.error_count();
|
||||
|
@ -216,6 +223,9 @@ pub(crate) fn main(args: &Args) -> anyhow::Result<ExitCode> {
|
|||
if result.error_count() > 0 {
|
||||
error!(parent: None, "{}", result.display(args.format));
|
||||
}
|
||||
if let Some(error_file) = &mut error_file {
|
||||
write!(error_file, "{}", result.display(args.format)).unwrap();
|
||||
}
|
||||
info!(
|
||||
parent: None,
|
||||
"Done: {} stability errors, {} files, similarity index {:.5}), took {:.2}s, {} input files contained syntax errors ",
|
||||
|
@ -281,7 +291,10 @@ fn setup_logging(log_level_args: &LogLevelArgs, log_file: Option<&Path>) -> io::
|
|||
}
|
||||
|
||||
/// Checks a directory of projects
|
||||
fn format_dev_multi_project(args: &Args) -> anyhow::Result<bool> {
|
||||
fn format_dev_multi_project(
|
||||
args: &Args,
|
||||
mut error_file: Option<BufWriter<File>>,
|
||||
) -> anyhow::Result<bool> {
|
||||
let mut total_errors = 0;
|
||||
let mut total_files = 0;
|
||||
let mut total_syntax_error_in_input = 0;
|
||||
|
@ -307,13 +320,6 @@ fn format_dev_multi_project(args: &Args) -> anyhow::Result<bool> {
|
|||
pb_span.pb_set_length(project_paths.len() as u64);
|
||||
let pb_span_enter = pb_span.enter();
|
||||
|
||||
let mut error_file = match &args.error_file {
|
||||
Some(error_file) => Some(BufWriter::new(
|
||||
File::create(error_file).context("Couldn't open error file")?,
|
||||
)),
|
||||
None => None,
|
||||
};
|
||||
|
||||
let mut results = Vec::new();
|
||||
|
||||
for project_path in project_paths {
|
||||
|
@ -344,7 +350,6 @@ fn format_dev_multi_project(args: &Args) -> anyhow::Result<bool> {
|
|||
}
|
||||
if let Some(error_file) = &mut error_file {
|
||||
write!(error_file, "{}", result.display(args.format)).unwrap();
|
||||
error_file.flush().unwrap();
|
||||
}
|
||||
results.push(result);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue