Fix clippy::map_unwrap_or (pedantic)

https://rust-lang.github.io/rust-clippy/master/index.html#map_unwrap_or

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
This commit is contained in:
Anders Kaseorg 2022-11-21 18:11:01 -08:00 committed by Charlie Marsh
parent bc95690725
commit 3b33a431d6
8 changed files with 23 additions and 38 deletions

View file

@ -121,10 +121,9 @@ pub fn match_call_path(
// `Match`).
if num_segments == 0 {
module.is_empty()
|| from_imports
.get(module)
.map(|imports| imports.contains(member) || imports.contains("*"))
.unwrap_or(false)
|| from_imports.get(module).map_or(false, |imports| {
imports.contains(member) || imports.contains("*")
})
} else {
let components: Vec<&str> = module.split('.').collect();
@ -148,8 +147,7 @@ pub fn match_call_path(
let member = components[cut];
if from_imports
.get(&module.as_str())
.map(|imports| imports.contains(member))
.unwrap_or(false)
.map_or(false, |imports| imports.contains(member))
{
return true;
}

View file

@ -603,8 +603,7 @@ where
.node
.asname
.as_ref()
.map(|asname| asname == &alias.node.name)
.unwrap_or(false)
.map_or(false, |asname| asname == &alias.node.name)
{
Some((
self.scopes[*(self
@ -823,8 +822,7 @@ where
.node
.asname
.as_ref()
.map(|asname| asname == &alias.node.name)
.unwrap_or(false)
.map_or(false, |asname| asname == &alias.node.name)
{
Some((
self.scopes[*(self
@ -2341,8 +2339,7 @@ impl<'a> Checker<'a> {
.current_scope()
.values
.get(id)
.map(|binding| matches!(binding.kind, BindingKind::Global))
.unwrap_or(false)
.map_or(false, |binding| matches!(binding.kind, BindingKind::Global))
{
pep8_naming::plugins::non_lowercase_variable_in_function(self, expr, parent, id)
}

View file

@ -17,8 +17,7 @@ fn is_abc_class(
.node
.arg
.as_ref()
.map(|a| a == "metaclass")
.unwrap_or(false)
.map_or(false, |a| a == "metaclass")
&& match_module_member(
&keyword.node.value,
"abc",

View file

@ -21,7 +21,7 @@ pub fn categorize(
known_third_party: &BTreeSet<String>,
extra_standard_library: &BTreeSet<String>,
) -> ImportType {
if level.map(|level| *level > 0).unwrap_or(false) {
if level.map_or(false, |level| *level > 0) {
ImportType::LocalFolder
} else if known_first_party.contains(module_base) {
ImportType::FirstParty

View file

@ -26,8 +26,7 @@ pub fn member_key<'a>(
} else if name
.chars()
.next()
.map(|char| char.is_uppercase())
.unwrap_or(false)
.map_or(false, |char| char.is_uppercase())
{
// Ex) `Class`
Prefix::Classes

View file

@ -11,13 +11,7 @@ use crate::python::string::{self};
/// N801
pub fn invalid_class_name(class_def: &Stmt, name: &str) -> Option<Check> {
let stripped = name.strip_prefix('_').unwrap_or(name);
if !stripped
.chars()
.next()
.map(|c| c.is_uppercase())
.unwrap_or(false)
|| stripped.contains('_')
{
if !stripped.chars().next().map_or(false, |c| c.is_uppercase()) || stripped.contains('_') {
return Some(Check::new(
CheckKind::InvalidClassName(name.to_string()),
Range::from_located(class_def),

View file

@ -1224,8 +1224,7 @@ fn common_section(
if context
.following_lines
.last()
.map(|line| !line.trim().is_empty())
.unwrap_or(true)
.map_or(true, |line| !line.trim().is_empty())
{
if context.is_last_section {
if checker.settings.enabled.contains(&CheckCode::D413) {
@ -1366,8 +1365,7 @@ fn args_section(checker: &mut Checker, definition: &Definition, context: &Sectio
if line
.chars()
.next()
.map(|char| char.is_whitespace())
.unwrap_or(true)
.map_or(true, |char| char.is_whitespace())
{
// This is a continuation of documentation for the last
// parameter because it does start with whitespace.

View file

@ -83,9 +83,14 @@ impl Configuration {
.map_err(|e| anyhow!("Invalid dummy-variable-rgx value: {e}"))?,
None => DEFAULT_DUMMY_VARIABLE_RGX.clone(),
},
src: options
.src
.map(|src| {
src: options.src.map_or_else(
|| {
vec![match project_root {
Some(project_root) => project_root.clone(),
None => path_dedot::CWD.clone(),
}]
},
|src| {
src.iter()
.map(|path| {
let path = Path::new(path);
@ -95,13 +100,8 @@ impl Configuration {
}
})
.collect()
})
.unwrap_or_else(|| {
vec![match project_root {
Some(project_root) => project_root.clone(),
None => path_dedot::CWD.clone(),
}]
}),
},
),
target_version: options.target_version.unwrap_or(PythonVersion::Py310),
exclude: options
.exclude