mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-16 08:30:16 +00:00
Switch to Rust 2024 edition (#18129)
This commit is contained in:
parent
e67b35743a
commit
9ae698fe30
1082 changed files with 4211 additions and 3300 deletions
|
@ -1,4 +1,4 @@
|
|||
use ruff_formatter::{write, Argument, Arguments, FormatError};
|
||||
use ruff_formatter::{Argument, Arguments, FormatError, write};
|
||||
use ruff_python_ast::AnyNodeRef;
|
||||
use ruff_python_ast::{
|
||||
ElifElseClause, ExceptHandlerExceptHandler, MatchCase, StmtClassDef, StmtFor, StmtFunctionDef,
|
||||
|
@ -7,8 +7,8 @@ use ruff_python_ast::{
|
|||
use ruff_python_trivia::{SimpleToken, SimpleTokenKind, SimpleTokenizer};
|
||||
use ruff_text_size::{Ranged, TextRange, TextSize};
|
||||
|
||||
use crate::comments::{leading_alternate_branch_comments, trailing_comments, SourceComment};
|
||||
use crate::statement::suite::{contains_only_an_ellipsis, SuiteKind};
|
||||
use crate::comments::{SourceComment, leading_alternate_branch_comments, trailing_comments};
|
||||
use crate::statement::suite::{SuiteKind, contains_only_an_ellipsis};
|
||||
use crate::verbatim::write_suppressed_clause_header;
|
||||
use crate::{has_skip_comment, prelude::*};
|
||||
|
||||
|
@ -473,12 +473,22 @@ fn colon_range(after_keyword_or_condition: TextSize, source: &str) -> FormatResu
|
|||
range,
|
||||
}) => Ok(range),
|
||||
Some(token) => {
|
||||
debug_assert!(false, "Expected the colon marking the end of the case header but found {token:?} instead.");
|
||||
Err(FormatError::syntax_error("Expected colon marking the end of the case header but found another token instead."))
|
||||
debug_assert!(
|
||||
false,
|
||||
"Expected the colon marking the end of the case header but found {token:?} instead."
|
||||
);
|
||||
Err(FormatError::syntax_error(
|
||||
"Expected colon marking the end of the case header but found another token instead.",
|
||||
))
|
||||
}
|
||||
None => {
|
||||
debug_assert!(false, "Expected the colon marking the end of the case header but found the end of the range.");
|
||||
Err(FormatError::syntax_error("Expected the colon marking the end of the case header but found the end of the range."))
|
||||
debug_assert!(
|
||||
false,
|
||||
"Expected the colon marking the end of the case header but found the end of the range."
|
||||
);
|
||||
Err(FormatError::syntax_error(
|
||||
"Expected the colon marking the end of the case header but found the end of the range.",
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use ruff_formatter::{format_args, write, FormatError, RemoveSoftLinesBuffer};
|
||||
use ruff_formatter::{FormatError, RemoveSoftLinesBuffer, format_args, write};
|
||||
use ruff_python_ast::{
|
||||
AnyNodeRef, Expr, ExprAttribute, ExprCall, FString, Operator, StmtAssign, StringLike,
|
||||
TypeParams,
|
||||
|
@ -6,12 +6,12 @@ use ruff_python_ast::{
|
|||
|
||||
use crate::builders::parenthesize_if_expands;
|
||||
use crate::comments::{
|
||||
trailing_comments, Comments, LeadingDanglingTrailingComments, SourceComment,
|
||||
Comments, LeadingDanglingTrailingComments, SourceComment, trailing_comments,
|
||||
};
|
||||
use crate::context::{NodeLevel, WithNodeLevel};
|
||||
use crate::expression::parentheses::{
|
||||
is_expression_parenthesized, optional_parentheses, NeedsParentheses, OptionalParentheses,
|
||||
Parentheses, Parenthesize,
|
||||
NeedsParentheses, OptionalParentheses, Parentheses, Parenthesize, is_expression_parenthesized,
|
||||
optional_parentheses,
|
||||
};
|
||||
use crate::expression::{
|
||||
can_omit_optional_parentheses, has_own_parentheses, has_parentheses,
|
||||
|
@ -19,11 +19,11 @@ use crate::expression::{
|
|||
};
|
||||
use crate::other::f_string::FStringLayout;
|
||||
use crate::statement::trailing_semicolon;
|
||||
use crate::string::StringLikeExtensions;
|
||||
use crate::string::implicit::{
|
||||
FormatImplicitConcatenatedStringExpanded, FormatImplicitConcatenatedStringFlat,
|
||||
ImplicitConcatenatedLayout,
|
||||
};
|
||||
use crate::string::StringLikeExtensions;
|
||||
use crate::{has_skip_comment, prelude::*};
|
||||
|
||||
#[derive(Default)]
|
||||
|
@ -1153,7 +1153,10 @@ impl<'a> OptionalParenthesesInlinedComments<'a> {
|
|||
let (expression_inline_comments, trailing_own_line_comments) =
|
||||
expression_comments.trailing.split_at(after_end_of_line);
|
||||
|
||||
debug_assert!(trailing_own_line_comments.is_empty(), "The method should have returned early if the expression has trailing own line comments");
|
||||
debug_assert!(
|
||||
trailing_own_line_comments.is_empty(),
|
||||
"The method should have returned early if the expression has trailing own line comments"
|
||||
);
|
||||
|
||||
Some(OptionalParenthesesInlinedComments {
|
||||
expression: expression_inline_comments,
|
||||
|
|
|
@ -4,12 +4,12 @@ use ruff_python_ast::StmtAugAssign;
|
|||
use crate::comments::SourceComment;
|
||||
use crate::expression::parentheses::is_expression_parenthesized;
|
||||
use crate::statement::stmt_assign::{
|
||||
has_target_own_parentheses, AnyAssignmentOperator, AnyBeforeOperator,
|
||||
FormatStatementsLastExpression,
|
||||
AnyAssignmentOperator, AnyBeforeOperator, FormatStatementsLastExpression,
|
||||
has_target_own_parentheses,
|
||||
};
|
||||
use crate::statement::trailing_semicolon;
|
||||
use crate::{has_skip_comment, prelude::*};
|
||||
use crate::{AsFormat, FormatNodeRule};
|
||||
use crate::{has_skip_comment, prelude::*};
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct FormatStmtAugAssign;
|
||||
|
|
|
@ -6,9 +6,9 @@ use ruff_text_size::Ranged;
|
|||
use crate::comments::format::{
|
||||
empty_lines_after_leading_comments, empty_lines_before_trailing_comments,
|
||||
};
|
||||
use crate::comments::{leading_comments, trailing_comments, SourceComment};
|
||||
use crate::comments::{SourceComment, leading_comments, trailing_comments};
|
||||
use crate::prelude::*;
|
||||
use crate::statement::clause::{clause_body, clause_header, ClauseHeader};
|
||||
use crate::statement::clause::{ClauseHeader, clause_body, clause_header};
|
||||
use crate::statement::suite::SuiteKind;
|
||||
|
||||
#[derive(Default)]
|
||||
|
|
|
@ -2,8 +2,8 @@ use ruff_formatter::write;
|
|||
use ruff_python_ast::StmtDelete;
|
||||
use ruff_text_size::Ranged;
|
||||
|
||||
use crate::builders::{parenthesize_if_expands, PyFormatterExtensions};
|
||||
use crate::comments::{dangling_node_comments, SourceComment};
|
||||
use crate::builders::{PyFormatterExtensions, parenthesize_if_expands};
|
||||
use crate::comments::{SourceComment, dangling_node_comments};
|
||||
use crate::expression::maybe_parenthesize_expression;
|
||||
use crate::expression::parentheses::Parenthesize;
|
||||
use crate::{has_skip_comment, prelude::*};
|
||||
|
|
|
@ -6,7 +6,7 @@ use crate::expression::expr_tuple::TupleParentheses;
|
|||
use crate::expression::maybe_parenthesize_expression;
|
||||
use crate::expression::parentheses::Parenthesize;
|
||||
use crate::prelude::*;
|
||||
use crate::statement::clause::{clause_body, clause_header, ClauseHeader, ElseClause};
|
||||
use crate::statement::clause::{ClauseHeader, ElseClause, clause_body, clause_header};
|
||||
use crate::statement::suite::SuiteKind;
|
||||
|
||||
#[derive(Debug)]
|
||||
|
|
|
@ -4,7 +4,7 @@ use crate::comments::format::{
|
|||
use crate::expression::maybe_parenthesize_expression;
|
||||
use crate::expression::parentheses::{Parentheses, Parenthesize};
|
||||
use crate::prelude::*;
|
||||
use crate::statement::clause::{clause_body, clause_header, ClauseHeader};
|
||||
use crate::statement::clause::{ClauseHeader, clause_body, clause_header};
|
||||
use crate::statement::stmt_class_def::FormatDecorators;
|
||||
use crate::statement::suite::SuiteKind;
|
||||
use ruff_formatter::write;
|
||||
|
|
|
@ -5,7 +5,7 @@ use ruff_text_size::Ranged;
|
|||
use crate::expression::maybe_parenthesize_expression;
|
||||
use crate::expression::parentheses::Parenthesize;
|
||||
use crate::prelude::*;
|
||||
use crate::statement::clause::{clause_body, clause_header, ClauseHeader};
|
||||
use crate::statement::clause::{ClauseHeader, clause_body, clause_header};
|
||||
use crate::statement::suite::SuiteKind;
|
||||
|
||||
#[derive(Default)]
|
||||
|
|
|
@ -2,7 +2,7 @@ use ruff_formatter::write;
|
|||
use ruff_python_ast::StmtImportFrom;
|
||||
use ruff_text_size::Ranged;
|
||||
|
||||
use crate::builders::{parenthesize_if_expands, PyFormatterExtensions, TrailingComma};
|
||||
use crate::builders::{PyFormatterExtensions, TrailingComma, parenthesize_if_expands};
|
||||
use crate::comments::SourceComment;
|
||||
use crate::expression::parentheses::parenthesized;
|
||||
use crate::has_skip_comment;
|
||||
|
|
|
@ -6,7 +6,7 @@ use crate::context::{NodeLevel, WithNodeLevel};
|
|||
use crate::expression::maybe_parenthesize_expression;
|
||||
use crate::expression::parentheses::Parenthesize;
|
||||
use crate::prelude::*;
|
||||
use crate::statement::clause::{clause_header, ClauseHeader};
|
||||
use crate::statement::clause::{ClauseHeader, clause_header};
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct FormatStmtMatch;
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
use ruff_formatter::{write, FormatRuleWithOptions};
|
||||
use ruff_formatter::{FormatRuleWithOptions, write};
|
||||
use ruff_python_ast::{ExceptHandler, StmtTry};
|
||||
use ruff_text_size::Ranged;
|
||||
|
||||
use crate::comments;
|
||||
use crate::comments::leading_alternate_branch_comments;
|
||||
use crate::comments::SourceComment;
|
||||
use crate::comments::leading_alternate_branch_comments;
|
||||
use crate::other::except_handler_except_handler::{
|
||||
ExceptHandlerKind, FormatExceptHandlerExceptHandler,
|
||||
};
|
||||
use crate::prelude::*;
|
||||
use crate::statement::clause::{clause_body, clause_header, ClauseHeader, ElseClause};
|
||||
use crate::statement::clause::{ClauseHeader, ElseClause, clause_body, clause_header};
|
||||
use crate::statement::suite::SuiteKind;
|
||||
use crate::statement::{FormatRefWithRule, Stmt};
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ use ruff_text_size::Ranged;
|
|||
use crate::expression::maybe_parenthesize_expression;
|
||||
use crate::expression::parentheses::Parenthesize;
|
||||
use crate::prelude::*;
|
||||
use crate::statement::clause::{clause_body, clause_header, ClauseHeader, ElseClause};
|
||||
use crate::statement::clause::{ClauseHeader, ElseClause, clause_body, clause_header};
|
||||
use crate::statement::suite::SuiteKind;
|
||||
|
||||
#[derive(Default)]
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use ruff_formatter::{format_args, write, FormatContext, FormatError};
|
||||
use ruff_formatter::{FormatContext, FormatError, format_args, write};
|
||||
use ruff_python_ast::PythonVersion;
|
||||
use ruff_python_ast::{StmtWith, WithItem};
|
||||
use ruff_python_trivia::{SimpleTokenKind, SimpleTokenizer};
|
||||
|
@ -13,7 +13,7 @@ use crate::expression::parentheses::{
|
|||
use crate::other::commas;
|
||||
use crate::other::with_item::WithItemLayout;
|
||||
use crate::prelude::*;
|
||||
use crate::statement::clause::{clause_body, clause_header, ClauseHeader};
|
||||
use crate::statement::clause::{ClauseHeader, clause_body, clause_header};
|
||||
use crate::statement::suite::SuiteKind;
|
||||
|
||||
#[derive(Default)]
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use ruff_formatter::{
|
||||
write, FormatContext, FormatOwnedWithRule, FormatRefWithRule, FormatRuleWithOptions,
|
||||
FormatContext, FormatOwnedWithRule, FormatRefWithRule, FormatRuleWithOptions, write,
|
||||
};
|
||||
use ruff_python_ast::helpers::is_compound_statement;
|
||||
use ruff_python_ast::{self as ast, Expr, PySourceType, Stmt, Suite};
|
||||
|
@ -8,7 +8,7 @@ use ruff_python_trivia::{lines_after, lines_after_ignoring_end_of_line_trivia, l
|
|||
use ruff_text_size::{Ranged, TextRange};
|
||||
|
||||
use crate::comments::{
|
||||
leading_comments, trailing_comments, Comments, LeadingDanglingTrailingComments,
|
||||
Comments, LeadingDanglingTrailingComments, leading_comments, trailing_comments,
|
||||
};
|
||||
use crate::context::{NodeLevel, TopLevelStatementPosition, WithIndentLevel, WithNodeLevel};
|
||||
use crate::other::string_literal::StringLiteralKind;
|
||||
|
@ -916,10 +916,10 @@ mod tests {
|
|||
use ruff_python_parser::parse_module;
|
||||
use ruff_python_trivia::CommentRanges;
|
||||
|
||||
use crate::PyFormatOptions;
|
||||
use crate::comments::Comments;
|
||||
use crate::prelude::*;
|
||||
use crate::statement::suite::SuiteKind;
|
||||
use crate::PyFormatOptions;
|
||||
|
||||
fn format_suite(level: SuiteKind) -> String {
|
||||
let source = r"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue