metaconfig/parser: apply clippy suggestions

Reviewed By: farnz

Differential Revision: D21838128

fbshipit-source-id: 10ba30c9f15b7119e6a6537a7e3c605f6d0698aa
This commit is contained in:
Mark Thomas 2020-06-02 09:24:20 -07:00 committed by Facebook GitHub Bot
parent c6d694b758
commit 5bf8469e9d
3 changed files with 18 additions and 33 deletions

View File

@ -106,7 +106,7 @@ fn parse_common_config(common: RawCommonConfig) -> Result<CommonConfig> {
let mut tiers_num = 0;
let security_config: Vec<_> = common
.whitelist_entry
.unwrap_or(vec![])
.unwrap_or_default()
.into_iter()
.map(|whitelist_entry| {
let has_tier = whitelist_entry.tier.is_some();
@ -156,24 +156,16 @@ fn parse_common_config(common: RawCommonConfig) -> Result<CommonConfig> {
);
}
let loadlimiter_category = match common.loadlimiter_category {
Some(category) => {
if category.len() > 0 {
Some(category)
} else {
None
}
}
None => None,
};
let loadlimiter_category = common
.loadlimiter_category
.filter(|category| !category.is_empty());
let scuba_censored_table = common.scuba_censored_table;
return Ok(CommonConfig {
Ok(CommonConfig {
security_config,
loadlimiter_category,
scuba_censored_table,
});
})
}
fn parse_repo_config(
@ -396,15 +388,15 @@ fn is_commit_sync_config_relevant_to_repo(
fn validate_commit_sync_config(commit_sync_config: &CommitSyncConfig) -> Result<()> {
let all_prefixes_with_direction: Vec<(&MPath, CommitSyncDirection)> = commit_sync_config
.small_repos
.iter()
.flat_map(|(_, small_repo_sync_config)| {
.values()
.flat_map(|small_repo_sync_config| {
let SmallRepoCommitSyncConfig {
default_action,
map,
direction,
..
} = small_repo_sync_config;
let all_prefixes = map.into_iter().map(|(_, target_prefix)| target_prefix);
let all_prefixes = map.values();
match default_action {
DefaultSmallToLargeCommitSyncPathAction::PrependPrefix(prefix) => {
all_prefixes.chain(vec![prefix].into_iter())
@ -490,10 +482,7 @@ fn parse_commit_sync_config(
impl RepoConfigs {
/// Get individual `RepoConfig`, given a repo_id
pub fn get_repo_config<'a>(
&'a self,
repo_id: RepositoryId,
) -> Option<(&'a String, &'a RepoConfig)> {
pub fn get_repo_config(&self, repo_id: RepositoryId) -> Option<(&String, &RepoConfig)> {
self.repos
.iter()
.find(|(_, repo_config)| repo_config.repoid == repo_id)

View File

@ -5,7 +5,6 @@
* GNU General Public License version 2.
*/
use std::collections::BTreeSet;
use std::convert::TryInto;
use anyhow::{anyhow, Result};
@ -95,9 +94,7 @@ impl Convert for RawHookConfig {
type Output = HookParams;
fn convert(self) -> Result<Self::Output> {
let bypass_commit_message = self
.bypass_commit_string
.map(|s| HookBypass::CommitMessage(s));
let bypass_commit_message = self.bypass_commit_string.map(HookBypass::CommitMessage);
let bypass_pushvar = self.bypass_pushvar.and_then(|s| {
let pushvar: Vec<_> = s.split('=').map(|val| val.to_string()).collect();
@ -274,7 +271,7 @@ impl Convert for RawSourceControlServiceMonitoring {
let bookmarks_to_report_age = self
.bookmarks_to_report_age
.into_iter()
.map(|bookmark| BookmarkName::new(bookmark))
.map(BookmarkName::new)
.collect::<Result<Vec<_>>>()?;
Ok(SourceControlServiceMonitoring {
bookmarks_to_report_age,
@ -300,7 +297,7 @@ impl Convert for RawDerivedDataConfig {
Ok(DerivedDataConfig {
scuba_table: self.scuba_table,
derived_data_types: self.derived_data_types.unwrap_or(BTreeSet::new()),
derived_data_types: self.derived_data_types.unwrap_or_default(),
unode_version,
})
}

View File

@ -19,8 +19,8 @@ use repos::{
use crate::errors::ConfigurationError;
const CONFIGERATOR_CRYPTO_PROJECT: &'static str = "SCM";
const CONFIGERATOR_PREFIX: &'static str = "configerator://";
const CONFIGERATOR_CRYPTO_PROJECT: &str = "SCM";
const CONFIGERATOR_PREFIX: &str = "configerator://";
pub(crate) fn read_raw_configs(fb: FacebookInit, config_path: &Path) -> Result<RawRepoConfigs> {
if config_path.starts_with(CONFIGERATOR_PREFIX) {
@ -122,8 +122,7 @@ where
.into());
}
let content = std::fs::read(path)?;
let res = read_toml::<T>(&content);
res
read_toml::<T>(&content)
}
/// Helper to read toml files which throws an error upon encountering
@ -140,8 +139,8 @@ where
unused.insert(path.to_string());
})?;
if unused.len() > 0 {
Err(anyhow!("unknown keys in config parsing: `{:?}`", unused))?;
if !unused.is_empty() {
return Err(anyhow!("unknown keys in config parsing: `{:?}`", unused));
}
Ok(t)