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); diagnostics.push(diagnostic);
} }
} }
} else {
} }
} }
} }

View file

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

View file

@ -317,7 +317,7 @@ impl From<&Configuration> for RuleTable {
// The fixable set keeps track of which rules are fixable. // The fixable set keeps track of which rules are fixable.
let mut fixable_set: RuleSet = RuleSelector::All let mut fixable_set: RuleSet = RuleSelector::All
.into_iter() .into_iter()
.chain(RuleSelector::Nursery.into_iter()) .chain(&RuleSelector::Nursery)
.collect(); .collect();
// Ignores normally only subtract from the current set of selected // 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""" """See Docs.md"""
# %% # %%
@ -106,11 +108,14 @@ for group, group_nodes in nodes_grouped.items():
# Generate `FormatRule`, `AsFormat` and `IntoFormat` # 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. 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::context::PyFormatContext;
use crate::{AsFormat, FormatNodeRule, IntoFormat}; use crate::{AsFormat, FormatNodeRule, IntoFormat};
use ruff_formatter::formatter::Formatter; use ruff_formatter::formatter::Formatter;
use ruff_formatter::{FormatOwnedWithRule, FormatRefWithRule, FormatResult, FormatRule}; use ruff_formatter::{FormatOwnedWithRule, FormatRefWithRule, FormatResult, FormatRule};
use rustpython_parser::ast; use rustpython_parser::ast;
""" # noqa: E501 """ # noqa: E501
for node in nodes: for node in nodes:
text = f""" text = f"""
@ -136,7 +141,7 @@ for node in nodes:
fn format(&self) -> Self::Format<'_> {{ fn format(&self) -> Self::Format<'_> {{
FormatRefWithRule::new( FormatRefWithRule::new(
self, 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 {{ fn into_format(self) -> Self::Format {{
FormatOwnedWithRule::new( FormatOwnedWithRule::new(
self, 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