Skip to content

Commit

Permalink
feat: allow paths and globs for --ignore-package
Browse files Browse the repository at this point in the history
  • Loading branch information
QuiiBz committed Dec 23, 2023
1 parent 2baf9c7 commit 94daac7
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,13 @@ You can ignore a specific rule by using `--ignore-rule <name>` (or `-r <name>`):
sherif -r packages-without-package-json -r root-package-manager-field
```

You can ignore all issues in a package by using `--ignore-package <name>` (or `-p <name>`):
You can ignore all issues in a package by using `--ignore-package <pathOrName>` (or `-p <pathOrName>`):

```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**
Expand Down
2 changes: 1 addition & 1 deletion src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub struct Args {
#[arg(long, short)]
pub ignore_dependency: Vec<String>,

/// Ignore rules for the given package name.
/// Ignore rules for the given package name or path.
#[arg(long, short = 'p')]
pub ignore_package: Vec<String>,

Expand Down
6 changes: 2 additions & 4 deletions src/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
17 changes: 17 additions & 0 deletions src/packages/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,21 @@ impl Package {
pub fn get_dev_dependencies(&self) -> Option<IndexMap<String, SemVersion>> {
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,
}
}
}

0 comments on commit 94daac7

Please sign in to comment.