mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-28 21:05:08 +00:00
Remove parser dependency from ruff-python-ast (#6096)
This commit is contained in:
parent
99127243f4
commit
2cf00fee96
658 changed files with 1714 additions and 1546 deletions
|
@ -1,7 +1,7 @@
|
|||
use std::fmt::{Debug, Formatter, Write};
|
||||
|
||||
use itertools::Itertools;
|
||||
use rustpython_parser::ast::Ranged;
|
||||
use rustpython_ast::Ranged;
|
||||
|
||||
use ruff_formatter::SourceCode;
|
||||
|
||||
|
@ -179,7 +179,7 @@ impl Debug for DebugNodeCommentSlice<'_> {
|
|||
mod tests {
|
||||
use insta::assert_debug_snapshot;
|
||||
use ruff_text_size::{TextRange, TextSize};
|
||||
use rustpython_parser::ast::{StmtBreak, StmtContinue};
|
||||
use rustpython_ast::{StmtBreak, StmtContinue};
|
||||
|
||||
use ruff_formatter::SourceCode;
|
||||
use ruff_python_ast::node::AnyNode;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use ruff_text_size::{TextLen, TextRange, TextSize};
|
||||
use rustpython_parser::ast::Ranged;
|
||||
use rustpython_ast::Ranged;
|
||||
|
||||
use ruff_formatter::{format_args, write, FormatError, SourceCode};
|
||||
use ruff_python_ast::node::{AnyNodeRef, AstNode};
|
||||
|
|
|
@ -92,7 +92,7 @@ use std::cell::Cell;
|
|||
use std::fmt::Debug;
|
||||
use std::rc::Rc;
|
||||
|
||||
use rustpython_parser::ast::{Mod, Ranged};
|
||||
use rustpython_ast::{Mod, Ranged};
|
||||
|
||||
pub(crate) use format::{
|
||||
dangling_comments, dangling_node_comments, leading_alternate_branch_comments, leading_comments,
|
||||
|
@ -100,7 +100,7 @@ pub(crate) use format::{
|
|||
};
|
||||
use ruff_formatter::{SourceCode, SourceCodeSlice};
|
||||
use ruff_python_ast::node::AnyNodeRef;
|
||||
use ruff_python_ast::source_code::CommentRanges;
|
||||
use ruff_python_index::CommentRanges;
|
||||
|
||||
use crate::comments::debug::{DebugComment, DebugComments};
|
||||
use crate::comments::map::MultiMap;
|
||||
|
@ -414,12 +414,12 @@ struct CommentsData<'a> {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use insta::assert_debug_snapshot;
|
||||
use rustpython_parser::ast::Mod;
|
||||
use rustpython_ast::Mod;
|
||||
use rustpython_parser::lexer::lex;
|
||||
use rustpython_parser::{parse_tokens, Mode};
|
||||
|
||||
use ruff_formatter::SourceCode;
|
||||
use ruff_python_ast::source_code::{CommentRanges, CommentRangesBuilder};
|
||||
use ruff_python_index::{CommentRanges, CommentRangesBuilder};
|
||||
|
||||
use crate::comments::Comments;
|
||||
|
||||
|
|
|
@ -54,7 +54,7 @@ mod tests {
|
|||
use crate::comments::node_key::NodeRefEqualityKey;
|
||||
use ruff_python_ast::node::AnyNodeRef;
|
||||
use ruff_text_size::TextRange;
|
||||
use rustpython_parser::ast::StmtContinue;
|
||||
use rustpython_ast::StmtContinue;
|
||||
use std::collections::hash_map::DefaultHasher;
|
||||
use std::hash::{Hash, Hasher};
|
||||
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
use std::cmp::Ordering;
|
||||
|
||||
use ruff_text_size::TextRange;
|
||||
use rustpython_ast::{Expr, ExprIfExp, ExprSlice, Ranged};
|
||||
use rustpython_parser::ast;
|
||||
use rustpython_parser::ast::{Expr, ExprIfExp, ExprSlice, Ranged};
|
||||
|
||||
use ruff_python_ast::node::{AnyNodeRef, AstNode};
|
||||
use ruff_python_ast::source_code::Locator;
|
||||
use ruff_python_ast::whitespace;
|
||||
use ruff_python_trivia::{
|
||||
PythonWhitespace, SimpleToken, SimpleTokenKind, SimpleTokenizer, UniversalNewlines,
|
||||
indentation_at_offset, PythonWhitespace, SimpleToken, SimpleTokenKind, SimpleTokenizer,
|
||||
};
|
||||
use ruff_source_file::{Locator, UniversalNewlines};
|
||||
|
||||
use crate::comments::visitor::{CommentPlacement, DecoratedComment};
|
||||
use crate::expression::expr_slice::{assign_comment_in_slice, ExprSliceCommentSection};
|
||||
|
@ -89,10 +89,9 @@ fn handle_match_comment<'a>(
|
|||
|
||||
let next_case = match_stmt.cases.get(current_case_index + 1);
|
||||
|
||||
let comment_indentation =
|
||||
whitespace::indentation_at_offset(locator, comment.slice().range().start())
|
||||
.unwrap_or_default()
|
||||
.len();
|
||||
let comment_indentation = indentation_at_offset(locator, comment.slice().range().start())
|
||||
.unwrap_or_default()
|
||||
.len();
|
||||
let match_case_indentation = whitespace::indentation(locator, match_case).unwrap().len();
|
||||
|
||||
if let Some(next_case) = next_case {
|
||||
|
@ -174,10 +173,9 @@ fn handle_in_between_except_handlers_or_except_handler_and_else_or_finally_comme
|
|||
|
||||
// it now depends on the indentation level of the comment if it is a leading comment for e.g.
|
||||
// the following `finally` or indeed a trailing comment of the previous body's last statement.
|
||||
let comment_indentation =
|
||||
whitespace::indentation_at_offset(locator, comment.slice().range().start())
|
||||
.unwrap_or_default()
|
||||
.len();
|
||||
let comment_indentation = indentation_at_offset(locator, comment.slice().range().start())
|
||||
.unwrap_or_default()
|
||||
.len();
|
||||
|
||||
let Some(except_indentation) =
|
||||
whitespace::indentation(locator, preceding_except_handler).map(str::len)
|
||||
|
@ -269,10 +267,9 @@ fn handle_in_between_bodies_own_line_comment<'a>(
|
|||
|
||||
// it now depends on the indentation level of the comment if it is a leading comment for e.g.
|
||||
// the following `elif` or indeed a trailing comment of the previous body's last statement.
|
||||
let comment_indentation =
|
||||
whitespace::indentation_at_offset(locator, comment.slice().range().start())
|
||||
.unwrap_or_default()
|
||||
.len();
|
||||
let comment_indentation = indentation_at_offset(locator, comment.slice().range().start())
|
||||
.unwrap_or_default()
|
||||
.len();
|
||||
|
||||
let Some(preceding_indentation) = whitespace::indentation(locator, &preceding).map(str::len)
|
||||
else {
|
||||
|
@ -445,10 +442,9 @@ fn own_line_comment_after_branch<'a>(
|
|||
|
||||
// We only care about the length because indentations with mixed spaces and tabs are only valid if
|
||||
// the indent-level doesn't depend on the tab width (the indent level must be the same if the tab width is 1 or 8).
|
||||
let comment_indentation =
|
||||
whitespace::indentation_at_offset(locator, comment.slice().range().start())
|
||||
.unwrap_or_default()
|
||||
.len();
|
||||
let comment_indentation = indentation_at_offset(locator, comment.slice().range().start())
|
||||
.unwrap_or_default()
|
||||
.len();
|
||||
|
||||
// Keep the comment on the entire statement in case it's a trailing comment
|
||||
// ```python
|
||||
|
@ -459,10 +455,9 @@ fn own_line_comment_after_branch<'a>(
|
|||
// # Trailing if comment
|
||||
// ```
|
||||
// Here we keep the comment a trailing comment of the `if`
|
||||
let preceding_node_indentation =
|
||||
whitespace::indentation_at_offset(locator, preceding_node.start())
|
||||
.unwrap_or_default()
|
||||
.len();
|
||||
let preceding_node_indentation = indentation_at_offset(locator, preceding_node.start())
|
||||
.unwrap_or_default()
|
||||
.len();
|
||||
if comment_indentation == preceding_node_indentation {
|
||||
return CommentPlacement::Default(comment);
|
||||
}
|
||||
|
|
|
@ -1,14 +1,15 @@
|
|||
use std::iter::Peekable;
|
||||
|
||||
use ruff_text_size::{TextRange, TextSize};
|
||||
use rustpython_parser::ast::{
|
||||
use rustpython_ast::{
|
||||
Alias, Arg, ArgWithDefault, Arguments, Comprehension, Decorator, ElifElseClause, ExceptHandler,
|
||||
Expr, Keyword, MatchCase, Mod, Pattern, Ranged, Stmt, TypeParam, WithItem,
|
||||
};
|
||||
|
||||
use ruff_formatter::{SourceCode, SourceCodeSlice};
|
||||
use ruff_python_ast::node::AnyNodeRef;
|
||||
use ruff_python_ast::source_code::{CommentRanges, Locator};
|
||||
use ruff_python_index::CommentRanges;
|
||||
use ruff_source_file::Locator;
|
||||
// The interface is designed to only export the members relevant for iterating nodes in
|
||||
// pre-order.
|
||||
#[allow(clippy::wildcard_imports)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue