Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added behavior to ignore matching directories #17

Merged
merged 7 commits into from
Oct 18, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion good-fences.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
.option('-o, --output <string>', 'path to write found violations')
.option('--baseUrl <string>', "Overrides `compilerOptions.baseUrl` property read from '--project' argument")
.option('--ignoreExternalFences', 'Ignore external fences (e.g. those in `node_modules`)', false)
.option('--ignoredDirs', 'Ignore matching dirs (e.g. `--ignoreDirs lib` will ignore all source and fence files in all subdirs with name `lib`', [])
.arguments('<path> [morePaths...]', 'Dirs to look for fence and source files')
program.parse(process.argv);

Expand All @@ -24,7 +25,8 @@
project: options.project,
baseUrl: options.baseUrl,
errOutputPath: options.errOutputPath,
ignoreExternalFences: options.ignoreExternalFences ? 1 : 0
ignoreExternalFences: options.ignoreExternalFences ? 1 : 0,
ignoredDirs: options.ignoredDirs
});
result.forEach(r => {
console.error(r.detailedMessage);
Expand Down
6 changes: 5 additions & 1 deletion src/good_fences_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@ impl GoodFencesRunner {
tsconfig_paths_json: TsconfigPathsJson,
directory_paths_to_walk: &Vec<&str>,
external_fences: ExternalFences,
ignored_dirs: Vec<String>,
) -> GoodFencesRunner {
// find files
let walked_files = directory_paths_to_walk
.iter()
.map(|path| discover_fences_and_files(path, external_fences))
.map(|path| discover_fences_and_files(path, external_fences, ignored_dirs.clone()))
.flatten();

let (fences_wrapped, sources_wrapped): (Vec<WalkFileData>, Vec<WalkFileData>) =
Expand Down Expand Up @@ -232,6 +233,7 @@ mod test {
.unwrap(),
&vec!["tests/good_fences_integration/src"],
ExternalFences::Ignore,
Vec::new(),
);

assert_eq!(
Expand Down Expand Up @@ -437,6 +439,7 @@ mod test {
.unwrap(),
&vec!["tests/good_fences_integration"],
ExternalFences::Ignore,
Vec::new(),
);

let mut violations = good_fences_runner.find_import_violations();
Expand Down Expand Up @@ -509,6 +512,7 @@ mod test {
.unwrap(),
&vec!["tests/good_fences_integration/src"],
ExternalFences::Ignore,
Vec::new(),
);

let orphans = good_fences_runner.find_undefined_tags();
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ pub fn good_fences(opts: GoodFencesOptions) -> Vec<GoodFencesError> {
Some(ief) => ief,
None => ExternalFences::Include,
},
opts.ignored_dirs,
);

println!("beginning fence evaluations");
Expand Down Expand Up @@ -79,6 +80,7 @@ pub struct GoodFencesOptions {
pub base_url: Option<String>,
pub err_output_path: Option<String>,
pub ignore_external_fences: Option<ExternalFences>,
pub ignored_dirs: Vec<String>,
}

#[napi]
Expand Down
26 changes: 17 additions & 9 deletions src/walk_dirs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,23 +56,25 @@ lazy_static! {
pub fn discover_fences_and_files(
start_path: &str,
ignore_external_fences: ExternalFences,
ignored_dirs: Vec<String>,
) -> Vec<WalkFileData> {
let walk_dir = WalkDirGeneric::<(TagList, WalkFileData)>::new(start_path).process_read_dir(
move |read_dir_state, children| {
// Custom filter -- retain only directories and fence.json files
children.retain(|dir_entry_result| {
dir_entry_result
.as_ref()
.map(|dir_entry| {
dir_entry.file_type.is_dir()
|| match dir_entry.file_name.to_str() {
Some(file_name_str) => {
!(ignore_external_fences == ExternalFences::Ignore
&& file_name_str == "node_modules")
&& should_retain_file(file_name_str)
}
None => false,
.map(|dir_entry| match dir_entry.file_name.to_str() {
Some(file_name_str) => {
if dir_entry.file_type.is_dir() {
return !(ignore_external_fences == ExternalFences::Ignore
&& file_name_str == "node_modules")
&& !ignored_dirs.contains(&file_name_str.to_string());
} else {
return should_retain_file(file_name_str);
}
}
None => todo!(),
})
.unwrap_or(false)
});
Expand Down Expand Up @@ -240,6 +242,7 @@ mod test {
let discovered: Vec<WalkFileData> = discover_fences_and_files(
"tests/walk_dir_simple",
crate::walk_dirs::ExternalFences::Ignore,
Vec::new(),
);

let expected_root_fence = Fence {
Expand Down Expand Up @@ -271,6 +274,7 @@ mod test {
let discovered: Vec<WalkFileData> = discover_fences_and_files(
"./tests/comments_panel_test",
crate::walk_dirs::ExternalFences::Ignore,
Vec::new(),
);

let expected = "tests/comments_panel_test/packages/accelerator/accelerator-common/src/CommentsPanel/index.ts";
Expand All @@ -294,6 +298,7 @@ mod test {
let discovered: Vec<WalkFileData> = discover_fences_and_files(
"tests/walk_dir_simple",
crate::walk_dirs::ExternalFences::Ignore,
Vec::new(),
);

let expected_subsubdir_fence = Fence {
Expand Down Expand Up @@ -322,6 +327,7 @@ mod test {
let discovered: Vec<WalkFileData> = discover_fences_and_files(
"tests/walk_dir_simple",
crate::walk_dirs::ExternalFences::Ignore,
Vec::new(),
);

let expected_root_ts_file = SourceFile {
Expand All @@ -348,6 +354,7 @@ mod test {
let discovered: Vec<WalkFileData> = discover_fences_and_files(
"tests/walk_dir_simple",
crate::walk_dirs::ExternalFences::Ignore,
Vec::new(),
);

let expected_subdir_ts_file = SourceFile {
Expand Down Expand Up @@ -375,6 +382,7 @@ mod test {
let discovered: Vec<WalkFileData> = discover_fences_and_files(
"tests/walk_dir_simple",
crate::walk_dirs::ExternalFences::Ignore,
Vec::new(),
);

let expected_subdir_ts_file = SourceFile {
Expand Down
Loading