mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 02:38:25 +00:00
Support multiple files
This commit is contained in:
parent
92238b4138
commit
6257dd00c7
3 changed files with 34 additions and 29 deletions
|
@ -5,9 +5,20 @@ use anyhow::Result;
|
|||
use clap::{Parser, ValueHint};
|
||||
use log::{error, info};
|
||||
use rayon::prelude::*;
|
||||
use rust_python_linter::fs::collect_python_files;
|
||||
use rust_python_linter::linter::check_path;
|
||||
use rust_python_linter::message::Message;
|
||||
use walkdir::{DirEntry, WalkDir};
|
||||
use walkdir::DirEntry;
|
||||
|
||||
#[derive(Debug, Parser)]
|
||||
#[clap(name = "rust-python-linter")]
|
||||
#[clap(about = "A bare-bones Python linter written in Rust", long_about = None)]
|
||||
struct Cli {
|
||||
#[clap(parse(from_os_str), value_hint = ValueHint::AnyPath, required = true)]
|
||||
files: Vec<PathBuf>,
|
||||
#[clap(short, long, action)]
|
||||
verbose: bool,
|
||||
}
|
||||
|
||||
fn set_up_logging(verbose: bool) -> Result<()> {
|
||||
fern::Dispatch::new()
|
||||
|
@ -31,27 +42,6 @@ fn set_up_logging(verbose: bool) -> Result<()> {
|
|||
.map_err(|e| e.into())
|
||||
}
|
||||
|
||||
#[derive(Debug, Parser)]
|
||||
#[clap(name = "rust-python-linter")]
|
||||
#[clap(about = "A bare-bones Python linter written in Rust", long_about = None)]
|
||||
struct Cli {
|
||||
#[clap(name = "filename", parse(from_os_str), value_hint = ValueHint::DirPath)]
|
||||
filename: PathBuf,
|
||||
#[clap(short, long, action)]
|
||||
verbose: bool,
|
||||
// /// Files to process
|
||||
// #[clap(name = "FILE", parse(from_os_str), value_hint = ValueHint::AnyPath)]
|
||||
// files: Vec<PathBuf>,
|
||||
}
|
||||
|
||||
fn is_not_hidden(entry: &DirEntry) -> bool {
|
||||
entry
|
||||
.file_name()
|
||||
.to_str()
|
||||
.map(|s| entry.depth() == 0 || !s.starts_with('.'))
|
||||
.unwrap_or(false)
|
||||
}
|
||||
|
||||
fn main() -> Result<()> {
|
||||
let cli = Cli::parse();
|
||||
|
||||
|
@ -59,13 +49,7 @@ fn main() -> Result<()> {
|
|||
|
||||
// Collect all the files to check.
|
||||
let start = Instant::now();
|
||||
let files: Vec<DirEntry> = WalkDir::new(cli.filename)
|
||||
.follow_links(true)
|
||||
.into_iter()
|
||||
.filter_entry(is_not_hidden)
|
||||
.filter_map(|entry| entry.ok())
|
||||
.filter(|entry| entry.path().to_string_lossy().ends_with(".py"))
|
||||
.collect();
|
||||
let files: Vec<DirEntry> = cli.files.iter().flat_map(collect_python_files).collect();
|
||||
let duration = start.elapsed();
|
||||
info!("Identified files to lint in: {:?}", duration);
|
||||
|
||||
|
|
20
src/fs.rs
Normal file
20
src/fs.rs
Normal file
|
@ -0,0 +1,20 @@
|
|||
use std::path::PathBuf;
|
||||
use walkdir::{DirEntry, WalkDir};
|
||||
|
||||
fn is_not_hidden(entry: &DirEntry) -> bool {
|
||||
entry
|
||||
.file_name()
|
||||
.to_str()
|
||||
.map(|s| entry.depth() == 0 || !s.starts_with('.'))
|
||||
.unwrap_or(false)
|
||||
}
|
||||
|
||||
pub fn collect_python_files(path: &PathBuf) -> Vec<DirEntry> {
|
||||
WalkDir::new(path)
|
||||
.follow_links(true)
|
||||
.into_iter()
|
||||
.filter_entry(is_not_hidden)
|
||||
.filter_map(|entry| entry.ok())
|
||||
.filter(|entry| entry.path().to_string_lossy().ends_with(".py"))
|
||||
.collect()
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
mod cache;
|
||||
mod check;
|
||||
pub mod fs;
|
||||
pub mod linter;
|
||||
pub mod message;
|
||||
mod parser;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue