diff --git a/README.md b/README.md index ea0ab16..ca8f607 100644 --- a/README.md +++ b/README.md @@ -73,11 +73,13 @@ You can ignore a specific rule by using `--ignore-rule ` (or `-r `): sherif -r packages-without-package-json -r root-package-manager-field ``` -You can ignore all issues in a package by using `--ignore-package ` (or `-p `): +You can ignore all issues in a package by using `--ignore-package ` (or `-p `): ```bash -# Ignore all issues in the package +# Ignore all issues in the `@repo/tools` package sherif -p @repo/tools +# Ignore all issues for packages inside `./integrations/*` +sherif -p ./integrations/* ``` > **Note** diff --git a/src/args.rs b/src/args.rs index 0e50371..63e3c64 100644 --- a/src/args.rs +++ b/src/args.rs @@ -15,7 +15,7 @@ pub struct Args { #[arg(long, short)] pub ignore_dependency: Vec, - /// Ignore rules for the given package name. + /// Ignore rules for the given package name or path. #[arg(long, short = 'p')] pub ignore_package: Vec, diff --git a/src/collect.rs b/src/collect.rs index 669d65c..72f3501 100644 --- a/src/collect.rs +++ b/src/collect.rs @@ -199,10 +199,8 @@ pub fn collect_issues(args: &Args, packages_list: PackagesList) -> IssuesList<'_ let mut all_dependencies = IndexMap::new(); for package in packages { - if let Some(package_name) = package.get_name() { - if args.ignore_package.contains(package_name) { - continue; - } + if package.is_ignored(&args.ignore_package) { + continue; } let package_type = PackageType::Package(package.get_path()); diff --git a/src/packages/mod.rs b/src/packages/mod.rs index 7315fa2..b2f8d7f 100644 --- a/src/packages/mod.rs +++ b/src/packages/mod.rs @@ -142,4 +142,21 @@ impl Package { pub fn get_dev_dependencies(&self) -> Option> { self.get_deps(&self.inner.dev_dependencies) } + + pub fn is_ignored(&self, ignored_packages: &[String]) -> bool { + match self.get_name() { + Some(name) => ignored_packages.iter().any(|ignored_package| { + match ignored_package.ends_with('*') { + true => { + let ignored_package = ignored_package.trim_end_matches('*'); + + name.starts_with(ignored_package) + || self.get_path().starts_with(ignored_package) + } + false => ignored_package == name || ignored_package == &self.get_path(), + } + }), + None => false, + } + } }