fix: dx check now respects files to ignore (e.g. .gitignore) (#4038)
closes #3751
This commit is contained in:
1 parent
6733e43cc2
commit
74789c4b13
3 files changed
+19
-44
No files matched your search
@@ -1,5 +1,5 @@
|
||||
use super::*;
|
||||
use crate::DioxusCrate;
|
||||
use crate::{metadata::collect_rs_files, DioxusCrate};
|
||||
use anyhow::Context;
|
||||
use dioxus_autofmt::{IndentOptions, IndentType};
|
||||
use rayon::prelude::*;
|
||||
@@ -126,20 +126,6 @@ fn refactor_file(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
use std::ffi::OsStr;
|
||||
fn get_project_files(dir: impl AsRef<Path>) -> Vec<PathBuf> {
|
||||
let mut files = Vec::new();
|
||||
for result in ignore::Walk::new(dir) {
|
||||
let path = result.unwrap().into_path();
|
||||
if let Some(ext) = path.extension() {
|
||||
if ext == OsStr::new("rs") {
|
||||
files.push(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
files
|
||||
}
|
||||
|
||||
fn format_file(
|
||||
path: impl AsRef<Path>,
|
||||
indent: IndentOptions,
|
||||
@@ -185,7 +171,7 @@ fn autoformat_project(
|
||||
format_rust_code: bool,
|
||||
dir: impl AsRef<Path>,
|
||||
) -> Result<()> {
|
||||
let files_to_format = get_project_files(dir);
|
||||
let files_to_format = collect_rs_files(dir);
|
||||
|
||||
if files_to_format.is_empty() {
|
||||
return Ok(());
|
||||
|
||||
@@ -4,10 +4,9 @@
|
||||
//! https://github.com/rust-lang/rustfmt/blob/master/src/bin/main.rs
|
||||
|
||||
use super::*;
|
||||
use crate::DioxusCrate;
|
||||
use crate::{metadata::collect_rs_files, DioxusCrate};
|
||||
use anyhow::Context;
|
||||
use futures_util::{stream::FuturesUnordered, StreamExt};
|
||||
use std::path::Path;
|
||||
|
||||
/// Check the Rust files in the project for issues.
|
||||
#[derive(Clone, Debug, Parser)]
|
||||
@@ -54,7 +53,7 @@ async fn check_file_and_report(path: PathBuf) -> Result<()> {
|
||||
/// Doesn't do mod-descending, so it will still try to check unreachable files. TODO.
|
||||
async fn check_project_and_report(dioxus_crate: DioxusCrate) -> Result<()> {
|
||||
let mut files_to_check = vec![dioxus_crate.main_source_file()];
|
||||
collect_rs_files(&dioxus_crate.crate_dir(), &mut files_to_check);
|
||||
files_to_check.extend(collect_rs_files(dioxus_crate.crate_dir()));
|
||||
check_files_and_report(files_to_check).await
|
||||
}
|
||||
|
||||
@@ -106,28 +105,3 @@ async fn check_files_and_report(files_to_check: Vec<PathBuf>) -> Result<()> {
|
||||
_ => Err(format!("{} issues found.", total_issues).into()),
|
||||
}
|
||||
}
|
||||
|
||||
fn collect_rs_files(folder: &Path, files: &mut Vec<PathBuf>) {
|
||||
let Ok(folder) = folder.read_dir() else {
|
||||
return;
|
||||
};
|
||||
|
||||
// load the gitignore
|
||||
for entry in folder {
|
||||
let Ok(entry) = entry else {
|
||||
continue;
|
||||
};
|
||||
|
||||
let path = entry.path();
|
||||
|
||||
if path.is_dir() {
|
||||
collect_rs_files(&path, files);
|
||||
}
|
||||
|
||||
if let Some(ext) = path.extension() {
|
||||
if ext == "rs" {
|
||||
files.push(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
use std::error::Error;
|
||||
use std::{
|
||||
env,
|
||||
ffi::OsStr,
|
||||
fmt::{Display, Formatter},
|
||||
fs,
|
||||
path::{Path, PathBuf},
|
||||
@@ -62,3 +63,17 @@ fn contains_manifest(path: &Path) -> bool {
|
||||
})
|
||||
.unwrap_or(false)
|
||||
}
|
||||
|
||||
/// Collects all `.rs` files in the provided directory, respecting files to ignore (e.g. `.gitignore`)
|
||||
pub(crate) fn collect_rs_files(dir: impl AsRef<Path>) -> Vec<PathBuf> {
|
||||
let mut files = Vec::new();
|
||||
for result in ignore::Walk::new(dir) {
|
||||
let path = result.unwrap().into_path();
|
||||
if let Some(ext) = path.extension() {
|
||||
if ext == OsStr::new("rs") {
|
||||
files.push(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
files
|
||||
}
|
||||
Reference in new issue
Block a user