mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-02 06:42:02 +00:00
Remove RustPython fork (#523)
This commit is contained in:
parent
b060ae2f22
commit
2415d73260
173 changed files with 2071 additions and 2056 deletions
|
@ -6,7 +6,10 @@ use std::path::Path;
|
|||
use anyhow::Result;
|
||||
#[cfg(not(target_family = "wasm"))]
|
||||
use log::debug;
|
||||
use rustpython_ast::{Mod, Suite};
|
||||
use rustpython_parser::error::ParseError;
|
||||
use rustpython_parser::lexer::LexResult;
|
||||
use rustpython_parser::parser::Mode;
|
||||
use rustpython_parser::{lexer, parser};
|
||||
|
||||
use crate::ast::types::Range;
|
||||
|
@ -36,6 +39,17 @@ pub(crate) fn tokenize(contents: &str) -> Vec<LexResult> {
|
|||
tokens
|
||||
}
|
||||
|
||||
/// Parse a full Python program from its tokens.
|
||||
pub(crate) fn parse_program_tokens(
|
||||
lxr: Vec<LexResult>,
|
||||
source_path: &str,
|
||||
) -> Result<Suite, ParseError> {
|
||||
parser::parse_tokens(lxr, Mode::Module, source_path).map(|top| match top {
|
||||
Mod::Module { body, .. } => body,
|
||||
_ => unreachable!(),
|
||||
})
|
||||
}
|
||||
|
||||
pub(crate) fn check_path(
|
||||
path: &Path,
|
||||
contents: &str,
|
||||
|
@ -65,7 +79,7 @@ pub(crate) fn check_path(
|
|||
.iter()
|
||||
.any(|check_code| matches!(check_code.lint_source(), LintSource::AST))
|
||||
{
|
||||
match parser::parse_program_tokens(tokens, "<filename>") {
|
||||
match parse_program_tokens(tokens, "<filename>") {
|
||||
Ok(python_ast) => {
|
||||
checks.extend(check_ast(&python_ast, &locator, settings, autofix, path))
|
||||
}
|
||||
|
@ -220,7 +234,7 @@ pub fn autoformat_path(path: &Path) -> Result<()> {
|
|||
let tokens: Vec<LexResult> = tokenize(&contents);
|
||||
|
||||
// Generate the AST.
|
||||
let python_ast = parser::parse_program_tokens(tokens, "<filename>")?;
|
||||
let python_ast = parse_program_tokens(tokens, "<filename>")?;
|
||||
let mut generator: SourceGenerator = Default::default();
|
||||
generator.unparse_suite(&python_ast)?;
|
||||
write(path, generator.generate()?)?;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue