Skip to content

Commit 41e8403

Browse files
committed
linting updates
1 parent 4672d31 commit 41e8403

File tree

6 files changed

+28
-45
lines changed

6 files changed

+28
-45
lines changed

src/cache/file.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,27 +21,23 @@ const DEFAULT_CACHE_CAPACITY: usize = 10000;
2121

2222
impl Caching for GlobalCache {
2323
fn get_file_owner(&self, path: &Path) -> Result<Option<FileOwnerCacheEntry>, Error> {
24-
if let Some(cache_mutex) = self.file_owner_cache.as_ref() {
25-
if let Ok(cache) = cache_mutex.lock() {
26-
if let Some(cached_entry) = cache.get(path) {
24+
if let Some(cache_mutex) = self.file_owner_cache.as_ref()
25+
&& let Ok(cache) = cache_mutex.lock()
26+
&& let Some(cached_entry) = cache.get(path) {
2727
let timestamp = get_file_timestamp(path)?;
2828
if cached_entry.timestamp == timestamp {
2929
return Ok(Some(cached_entry.clone()));
3030
}
3131
}
32-
}
33-
}
3432
Ok(None)
3533
}
3634

3735
fn write_file_owner(&self, path: &Path, owner: Option<String>) {
38-
if let Some(cache_mutex) = self.file_owner_cache.as_ref() {
39-
if let Ok(mut cache) = cache_mutex.lock() {
40-
if let Ok(timestamp) = get_file_timestamp(path) {
36+
if let Some(cache_mutex) = self.file_owner_cache.as_ref()
37+
&& let Ok(mut cache) = cache_mutex.lock()
38+
&& let Ok(timestamp) = get_file_timestamp(path) {
4139
cache.insert(path.to_path_buf(), FileOwnerCacheEntry { timestamp, owner });
4240
}
43-
}
44-
}
4541
}
4642

4743
fn persist_cache(&self) -> Result<(), Error> {

src/ownership/file_generator.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,14 @@ impl FileGenerator {
4949
}
5050

5151
pub fn compare_lines(a: &String, b: &String) -> Ordering {
52-
if let Some((prefix, _)) = a.split_once("**") {
53-
if b.starts_with(prefix) {
52+
if let Some((prefix, _)) = a.split_once("**")
53+
&& b.starts_with(prefix) {
5454
return Ordering::Less;
5555
}
56-
}
57-
if let Some((prefix, _)) = b.split_once("**") {
58-
if a.starts_with(prefix) {
56+
if let Some((prefix, _)) = b.split_once("**")
57+
&& a.starts_with(prefix) {
5958
return Ordering::Greater;
6059
}
61-
}
6260
a.cmp(b)
6361
}
6462

src/ownership/for_file_fast.rs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,10 @@ pub fn find_file_owners(project_root: &Path, config: &Config, file_path: &Path)
3232
if let Some(rel_str) = relative_file_path.to_str() {
3333
let is_config_owned = glob_list_matches(rel_str, &config.owned_globs);
3434
let is_config_unowned = glob_list_matches(rel_str, &config.unowned_globs);
35-
if is_config_owned && !is_config_unowned {
36-
if let Some(team) = teams_by_name.get(&team_name) {
35+
if is_config_owned && !is_config_unowned
36+
&& let Some(team) = teams_by_name.get(&team_name) {
3737
sources_by_team.entry(team.name.clone()).or_default().push(Source::TeamFile);
3838
}
39-
}
4039
}
4140
}
4241

@@ -194,33 +193,29 @@ fn nearest_package_owner(
194193
if let Some(rel_str) = parent_rel.to_str() {
195194
if glob_list_matches(rel_str, &config.ruby_package_paths) {
196195
let pkg_yml = current.join("package.yml");
197-
if pkg_yml.exists() {
198-
if let Ok(owner) = read_ruby_package_owner(&pkg_yml) {
199-
if let Some(team) = teams_by_name.get(&owner) {
196+
if pkg_yml.exists()
197+
&& let Ok(owner) = read_ruby_package_owner(&pkg_yml)
198+
&& let Some(team) = teams_by_name.get(&owner) {
200199
let package_path = parent_rel.join("package.yml");
201200
let package_glob = format!("{rel_str}/**/**");
202201
return Some((
203202
team.name.clone(),
204203
Source::Package(package_path.to_string_lossy().to_string(), package_glob),
205204
));
206205
}
207-
}
208-
}
209206
}
210207
if glob_list_matches(rel_str, &config.javascript_package_paths) {
211208
let pkg_json = current.join("package.json");
212-
if pkg_json.exists() {
213-
if let Ok(owner) = read_js_package_owner(&pkg_json) {
214-
if let Some(team) = teams_by_name.get(&owner) {
209+
if pkg_json.exists()
210+
&& let Ok(owner) = read_js_package_owner(&pkg_json)
211+
&& let Some(team) = teams_by_name.get(&owner) {
215212
let package_path = parent_rel.join("package.json");
216213
let package_glob = format!("{rel_str}/**/**");
217214
return Some((
218215
team.name.clone(),
219216
Source::Package(package_path.to_string_lossy().to_string(), package_glob),
220217
));
221218
}
222-
}
223-
}
224219
}
225220
}
226221
if current == project_root {

src/ownership/mapper/package_mapper.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,10 @@ fn remove_nested_packages<'a>(packages: &'a [&'a Package]) -> Vec<&'a Package> {
122122

123123
for package in packages.iter().sorted_by_key(|package| package.package_root()) {
124124
if let Some(last_package) = top_level_packages.last() {
125-
if let (Some(current_root), Some(last_root)) = (package.package_root(), last_package.package_root()) {
126-
if !current_root.starts_with(last_root) {
125+
if let (Some(current_root), Some(last_root)) = (package.package_root(), last_package.package_root())
126+
&& !current_root.starts_with(last_root) {
127127
top_level_packages.push(package);
128128
}
129-
}
130129
} else {
131130
top_level_packages.push(package);
132131
}

src/ownership/validator.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,13 @@ impl Validator {
7474
.files
7575
.par_iter()
7676
.flat_map(|file| {
77-
if let Some(owner) = &file.owner {
78-
if !team_names.contains(owner) {
77+
if let Some(owner) = &file.owner
78+
&& !team_names.contains(owner) {
7979
return Some(Error::InvalidTeam {
8080
name: owner.clone(),
8181
path: project.relative_path(&file.path).to_owned(),
8282
});
8383
}
84-
}
8584

8685
None
8786
})

src/project_builder.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,12 @@ impl<'a> ProjectBuilder<'a> {
6161
builder.filter_entry(move |entry: &DirEntry| {
6262
let path = entry.path();
6363
let file_name = entry.file_name().to_str().unwrap_or("");
64-
if let Some(ft) = entry.file_type() {
65-
if ft.is_dir() {
66-
if let Ok(rel) = path.strip_prefix(&base_path) {
67-
if rel.components().count() == 1 && ignore_dirs.iter().any(|d| *d == file_name) {
64+
if let Some(ft) = entry.file_type()
65+
&& ft.is_dir()
66+
&& let Ok(rel) = path.strip_prefix(&base_path)
67+
&& rel.components().count() == 1 && ignore_dirs.iter().any(|d| *d == file_name) {
6868
return false;
6969
}
70-
}
71-
}
72-
}
7370

7471
true
7572
});
@@ -92,11 +89,10 @@ impl<'a> ProjectBuilder<'a> {
9289
let _ = tx.send(entry_type);
9390
}
9491
Err(report) => {
95-
if let Ok(mut slot) = error_holder.lock() {
96-
if slot.is_none() {
92+
if let Ok(mut slot) = error_holder.lock()
93+
&& slot.is_none() {
9794
*slot = Some(report);
9895
}
99-
}
10096
}
10197
}
10298
}

0 commit comments

Comments
 (0)