Fix formatter generate.py (#5829)

This commit is contained in:
Micha Reiser 2023-07-17 12:41:27 +02:00 committed by GitHub
parent fb336898a5
commit 21063544f7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 393 additions and 152 deletions

View file

@ -115,7 +115,6 @@ pub(crate) fn check_physical_lines(
diagnostics.push(diagnostic);
}
}
} else {
}
}
}

View file

@ -208,12 +208,7 @@ fn check_positional_args(
(ErrorKind::ThirdArgBadAnnotation, is_traceback_type),
];
for (arg, (error_info, predicate)) in positional_args
.iter()
.skip(1)
.take(3)
.zip(validations.into_iter())
{
for (arg, (error_info, predicate)) in positional_args.iter().skip(1).take(3).zip(validations) {
let Some(annotation) = arg.def.annotation.as_ref() else {
continue;
};

View file

@ -317,7 +317,7 @@ impl From<&Configuration> for RuleTable {
// The fixable set keeps track of which rules are fixable.
let mut fixable_set: RuleSet = RuleSelector::All
.into_iter()
.chain(RuleSelector::Nursery.into_iter())
.chain(&RuleSelector::Nursery)
.collect();
// Ignores normally only subtract from the current set of selected

9
crates/ruff_python_formatter/generate.py Normal file → Executable file
View file

@ -1,3 +1,5 @@
#! /usr/bin/python
"""See Docs.md"""
# %%
@ -106,11 +108,14 @@ for group, group_nodes in nodes_grouped.items():
# Generate `FormatRule`, `AsFormat` and `IntoFormat`
generated = """//! This is a generated file. Don't modify it by hand! Run `crates/ruff_python_formatter/generate.py` to re-generate the file.
#![allow(unknown_lints, clippy::default_constructed_unit_structs)]
use crate::context::PyFormatContext;
use crate::{AsFormat, FormatNodeRule, IntoFormat};
use ruff_formatter::formatter::Formatter;
use ruff_formatter::{FormatOwnedWithRule, FormatRefWithRule, FormatResult, FormatRule};
use rustpython_parser::ast;
""" # noqa: E501
for node in nodes:
text = f"""
@ -136,7 +141,7 @@ for node in nodes:
fn format(&self) -> Self::Format<'_> {{
FormatRefWithRule::new(
self,
crate::{groups[group_for_node(node)]}::{to_camel_case(node)}::Format{node},
crate::{groups[group_for_node(node)]}::{to_camel_case(node)}::Format{node}::default(),
)
}}
}}
@ -149,7 +154,7 @@ for node in nodes:
fn into_format(self) -> Self::Format {{
FormatOwnedWithRule::new(
self,
crate::{groups[group_for_node(node)]}::{to_camel_case(node)}::Format{node},
crate::{groups[group_for_node(node)]}::{to_camel_case(node)}::Format{node}::default(),
)
}}
}}

File diff suppressed because it is too large Load diff