Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: replace map_or with is_ok_and and is_some_and #4969

Merged
merged 1 commit into from
Jan 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ cargo_common_metadata = "allow"
empty_docs = "allow" # there are some false positives inside biome_wasm
multiple_crate_versions = "allow"
needless_lifetimes = "allow"
unnecessary_map_or = "allow"

# pedantic
assigning_clones = "warn"
Expand Down
4 changes: 2 additions & 2 deletions crates/biome_aria/src/roles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,10 @@ impl AriaRoles {
.find_attribute_by_name(|n| n == "type")
.as_ref()
.and_then(|attr| attr.value())
.map_or(false, |value| value.as_ref() == "hidden"),
.is_some_and(|value| value.as_ref() == "hidden"),
_ => self
.get_implicit_role(element)
.map_or(false, |implicit_role| implicit_role.is_non_interactive()),
.is_some_and(|implicit_role| implicit_role.is_non_interactive()),
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/biome_cli/src/commands/daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ pub(crate) fn read_most_recent_log_file(

let most_recent = fs::read_dir(biome_log_path)?
.flatten()
.filter(|file| file.file_type().map_or(false, |ty| ty.is_file()))
.filter(|file| file.file_type().is_ok_and(|ty| ty.is_file()))
.filter_map(|file| {
match file
.file_name()
Expand Down
2 changes: 1 addition & 1 deletion crates/biome_cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ impl BiomeCommand {

pub fn is_verbose(&self) -> bool {
self.cli_options()
.map_or(false, |cli_options| cli_options.verbose)
.is_some_and(|cli_options| cli_options.verbose)
}

pub fn log_level(&self) -> LoggingLevel {
Expand Down
2 changes: 1 addition & 1 deletion crates/biome_cli/src/execute/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ impl Execution {
// Ref: https://docs.github.com/actions/learn-github-actions/variables#default-environment-variables
let is_github = std::env::var("GITHUB_ACTIONS")
.ok()
.map_or(false, |value| value == "true");
.is_some_and(|value| value == "true");

Self {
report_mode: ReportMode::default(),
Expand Down
8 changes: 4 additions & 4 deletions crates/biome_configuration/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,15 +240,15 @@ impl Configuration {
}

pub fn is_formatter_enabled(&self) -> bool {
self.formatter.as_ref().map_or(false, |f| f.is_enabled())
self.formatter.as_ref().is_some_and(|f| f.is_enabled())
}

pub fn is_linter_enabled(&self) -> bool {
self.linter.as_ref().map_or(false, |f| f.is_enabled())
self.linter.as_ref().is_some_and(|f| f.is_enabled())
}

pub fn is_assist_enabled(&self) -> bool {
self.assist.as_ref().map_or(false, |f| f.is_enabled())
self.assist.as_ref().is_some_and(|f| f.is_enabled())
}

pub fn get_linter_rules(&self) -> Rules {
Expand All @@ -266,7 +266,7 @@ impl Configuration {
}

pub fn is_vcs_enabled(&self) -> bool {
self.assist.as_ref().map_or(false, |f| f.is_enabled())
self.assist.as_ref().is_some_and(|f| f.is_enabled())
}

/// Whether Biome should check for `.editorconfig` file
Expand Down
7 changes: 4 additions & 3 deletions crates/biome_css_formatter/src/comments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,10 @@ fn handle_declaration_name_comment(
) -> CommentPlacement<CssLanguage> {
match comment.preceding_node() {
Some(following_node) if AnyCssDeclarationName::can_cast(following_node.kind()) => {
if following_node.parent().map_or(false, |p| {
p.kind() == CssSyntaxKind::CSS_GENERIC_COMPONENT_VALUE_LIST
}) {
if following_node
.parent()
.is_some_and(|p| p.kind() == CssSyntaxKind::CSS_GENERIC_COMPONENT_VALUE_LIST)
{
CommentPlacement::Default(comment)
} else {
CommentPlacement::leading(following_node.clone(), comment)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ impl FormatNodeRule<CssUnknownBlockAtRule> for FormatCssUnknownBlockAtRule {

write!(f, [name.format(), space(), components.format()])?;

if components.map_or(false, |components| components.items().next().is_some()) {
if components.is_ok_and(|components| components.items().next().is_some()) {
write!(f, [space()])?;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ where
name.as_css_identifier()
.map(|name| name.to_trimmed_string())
})
.map_or(false, |name| {
.is_some_and(|name| {
let name = name.to_ascii_lowercase_cow();

name.starts_with("grid-template") || name == "grid"
Expand Down
4 changes: 2 additions & 2 deletions crates/biome_css_parser/src/lexer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ impl<'src> CssLexer<'src> {
// U+002E FULL STOP (.) followed by a digit...
if self
.current_byte()
.map_or(false, |byte| byte.is_ascii_digit())
.is_some_and(|byte| byte.is_ascii_digit())
{
// While the next input code point is a digit, consume it.
self.consume_number_sequence();
Expand Down Expand Up @@ -1244,7 +1244,7 @@ impl<'src> CssLexer<'src> {
Some(byte) if byte.is_ascii_digit() => true,
// Otherwise, if the second code point is a U+002E FULL STOP (.) and the
// third code point is a digit, return true.
Some(b'.') if self.byte_at(2).map_or(false, |byte| byte.is_ascii_digit()) => true,
Some(b'.') if self.byte_at(2).is_some_and(|byte| byte.is_ascii_digit()) => true,
_ => false,
},
Some(b'.') => match self.peek_byte() {
Expand Down
4 changes: 2 additions & 2 deletions crates/biome_diagnostics/src/display/backtrace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ impl NativeBacktrace {
frame.symbols().iter().any(|symbol| {
symbol
.addr()
.map_or(false, |addr| addr as usize == self.top_frame)
.is_some_and(|addr| addr as usize == self.top_frame)
})
});

Expand All @@ -173,7 +173,7 @@ impl NativeBacktrace {
frame.symbols().iter().any(|symbol| {
symbol
.addr()
.map_or(false, |addr| addr as usize == self.bottom_frame)
.is_some_and(|addr| addr as usize == self.bottom_frame)
})
});

Expand Down
4 changes: 2 additions & 2 deletions crates/biome_diagnostics/src/display/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ pub(super) fn print_invisibles(

let next_char_is_whitespace = iter
.peek()
.map_or(false, |(_, char)| char.is_ascii_whitespace());
.is_some_and(|(_, char)| char.is_ascii_whitespace());

if prev_char_was_whitespace || next_char_is_whitespace {
show_invisible = false;
Expand All @@ -436,7 +436,7 @@ pub(super) fn print_invisibles(

// If we are a carriage return next to a \n then don't show the character as visible
if options.ignore_trailing_carriage_return && char == '\r' {
let next_char_is_line_feed = iter.peek().map_or(false, |(_, char)| *char == '\n');
let next_char_is_line_feed = iter.peek().is_some_and(|(_, char)| *char == '\n');
if next_char_is_line_feed {
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion crates/biome_formatter/src/builders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ impl<Context> Format<Context> for LineSuffixBoundary {
///
/// let recorded = recording.stop();
///
/// let is_labelled = recorded.first().map_or(false, |element| element.has_label(LabelId::of(MyLabels::Main)));
/// let is_labelled = recorded.first().is_some_and(|element| element.has_label(LabelId::of(MyLabels::Main)));
///
/// if is_labelled {
/// write!(f, [text(" has label `Main`")])
Expand Down
4 changes: 2 additions & 2 deletions crates/biome_formatter/src/format_element/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ impl Format<IrFormatContext> for &[FormatElement] {
_ => unreachable!(),
}

let is_next_text = iter.peek().map_or(false, |e| e.is_text() || e.is_space());
let is_next_text = iter.peek().is_some_and(|e| e.is_text() || e.is_space());

if !is_next_text {
write!(f, [text("\"")])?;
Expand Down Expand Up @@ -687,7 +687,7 @@ impl FormatElements for [FormatElement] {

fn has_label(&self, expected: LabelId) -> bool {
self.first()
.map_or(false, |element| element.has_label(expected))
.is_some_and(|element| element.has_label(expected))
}

fn start_tag(&self, kind: TagKind) -> Option<&Tag> {
Expand Down
2 changes: 1 addition & 1 deletion crates/biome_formatter/src/source_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ impl TransformSourceMap {
// It can, therefore, be necessary to navigate backwards again.
// In this case, do a binary search for the index of the next deleted range (`O(log(n)`).
let out_of_order_marker =
previous_marker.map_or(false, |previous| previous.source > marker.source);
previous_marker.is_some_and(|previous| previous.source > marker.source);

if out_of_order_marker {
let index = self
Expand Down
10 changes: 5 additions & 5 deletions crates/biome_formatter/src/trivia.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ where
match comment.lines_after() {
0 => {
let should_nestle =
leading_comments_iter.peek().map_or(false, |next_comment| {
leading_comments_iter.peek().is_some_and(|next_comment| {
should_nestle_adjacent_doc_comments(comment, next_comment)
});

Expand Down Expand Up @@ -138,7 +138,7 @@ where

let format_comment = FormatRefWithRule::new(comment, Context::CommentRule::default());

let should_nestle = previous_comment.map_or(false, |previous_comment| {
let should_nestle = previous_comment.is_some_and(|previous_comment| {
should_nestle_adjacent_doc_comments(previous_comment, comment)
});

Expand Down Expand Up @@ -169,7 +169,7 @@ where
// /**
// * docs
// */ /* still on the same line */
if previous_comment.map_or(false, |previous_comment| {
if previous_comment.is_some_and(|previous_comment| {
previous_comment.kind().is_line()
}) {
write!(f, [hard_line_break()])?;
Expand Down Expand Up @@ -315,7 +315,7 @@ where
let format_comment =
FormatRefWithRule::new(comment, Context::CommentRule::default());

let should_nestle = previous_comment.map_or(false, |previous_comment| {
let should_nestle = previous_comment.is_some_and(|previous_comment| {
should_nestle_adjacent_doc_comments(previous_comment, comment)
});

Expand All @@ -334,7 +334,7 @@ where
if matches!(self.indent(), DanglingIndentMode::Soft)
&& dangling_comments
.last()
.map_or(false, |comment| comment.kind().is_line())
.is_some_and(|comment| comment.kind().is_line())
{
write!(f, [hard_line_break()])?;
}
Expand Down
6 changes: 3 additions & 3 deletions crates/biome_fs/src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ pub trait FileSystem: Send + Sync + RefUnwindSafe {
/// [Self::path_is_symlink()] and this method to return `true` for the same
/// path.
fn path_is_file(&self, path: &Utf8Path) -> bool {
Self::path_kind(self, path).map_or(false, |kind| matches!(kind, PathKind::File { .. }))
Self::path_kind(self, path).is_ok_and(|kind| matches!(kind, PathKind::File { .. }))
}

/// Checks if the given path is a directory
Expand All @@ -104,12 +104,12 @@ pub trait FileSystem: Send + Sync + RefUnwindSafe {
/// [Self::path_is_symlink()] and this method to return `true` for the same
/// path.
fn path_is_dir(&self, path: &Utf8Path) -> bool {
Self::path_kind(self, path).map_or(false, |kind| matches!(kind, PathKind::Directory { .. }))
Self::path_kind(self, path).is_ok_and(|kind| matches!(kind, PathKind::Directory { .. }))
}

/// Checks if the given path is a symlink
fn path_is_symlink(&self, path: &Utf8Path) -> bool {
Self::path_kind(self, path).map_or(false, PathKind::is_symlink)
Self::path_kind(self, path).is_ok_and(PathKind::is_symlink)
}

/// Returns metadata about the path.
Expand Down
2 changes: 1 addition & 1 deletion crates/biome_graphql_formatter/src/utils/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ where
let node = element.node();

if index != 0 {
if node.map_or(false, |node| node.syntax().has_leading_comments()) {
if node.is_ok_and(|node| node.syntax().has_leading_comments()) {
write!(f, [soft_line_break_or_space()])?;
} else {
write!(f, [space()])?;
Expand Down
2 changes: 1 addition & 1 deletion crates/biome_graphql_syntax/src/string_value_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ impl GraphqlStringValue {
/// ```
pub fn is_block(&self) -> bool {
self.graphql_string_literal_token()
.map_or(false, |token| token.text_trimmed().starts_with("\"\"\""))
.is_ok_and(|token| token.text_trimmed().starts_with("\"\"\""))
}
}
4 changes: 2 additions & 2 deletions crates/biome_grit_patterns/src/grit_binding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,11 @@ impl<'a> Binding<'a, GritQueryContext> for GritBinding<'a> {
Self::Empty(node2, sort2) => node1.kind() == node2.kind() && sort1 == sort2,
Self::Range(..) | Self::File(_) | Self::Node(..) | Self::Constant(_) => false,
},
Self::Constant(c1) => other.as_constant().map_or(false, |c2| *c1 == c2),
Self::Constant(c1) => other.as_constant().is_some_and(|c2| *c1 == c2),
Self::Range(range, source) => other
.text(language)
.is_ok_and(|t| t == source[range.start().into()..range.end().into()]),
Self::File(path1) => other.as_filename().map_or(false, |path2| *path1 == path2),
Self::File(path1) => other.as_filename().is_some_and(|path2| *path1 == path2),
}
}

Expand Down
4 changes: 2 additions & 2 deletions crates/biome_grit_patterns/src/grit_resolved_pattern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ impl<'a> ResolvedPattern<'a, GritQueryContext> for GritResolvedPattern<'a> {
language: &GritTargetLanguage,
) -> GritResult<bool> {
let truthiness = match self {
Self::Binding(bindings) => bindings.last().map_or(false, Binding::is_truthy),
Self::Binding(bindings) => bindings.last().is_some_and(Binding::is_truthy),
Self::List(elements) => !elements.is_empty(),
Self::Map(map) => !map.is_empty(),
Self::Constant(c) => c.is_truthy(),
Expand Down Expand Up @@ -532,7 +532,7 @@ impl<'a> ResolvedPattern<'a, GritQueryContext> for GritResolvedPattern<'a> {
Self::Binding(b) => b
.last()
.and_then(Binding::as_constant)
.map_or(false, Constant::is_undefined),
.is_some_and(Constant::is_undefined),
Self::Constant(Constant::Undefined) => true,
Self::Constant(_)
| Self::Snippets(_)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ impl GritTargetLanguageImpl for CssTargetLanguage {

fn is_comment_kind(kind: GritTargetSyntaxKind) -> bool {
kind.as_css_kind()
.map_or(false, |kind| COMMENT_KINDS.matches(kind))
.is_some_and(|kind| COMMENT_KINDS.matches(kind))
}

fn metavariable_kind() -> Self::Kind {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,15 @@ impl GritTargetLanguageImpl for JsTargetLanguage {

fn is_comment_kind(kind: GritTargetSyntaxKind) -> bool {
kind.as_js_kind()
.map_or(false, |kind| COMMENT_KINDS.matches(kind))
.is_some_and(|kind| COMMENT_KINDS.matches(kind))
}

fn metavariable_kind() -> Self::Kind {
JsSyntaxKind::JS_METAVARIABLE
}

fn is_alternative_metavariable_kind(kind: GritTargetSyntaxKind) -> bool {
kind.as_js_kind().map_or(false, |kind| {
kind.as_js_kind().is_some_and(|kind| {
kind == JsSyntaxKind::JS_TEMPLATE_ELEMENT_LIST
|| kind == JsSyntaxKind::TS_TEMPLATE_ELEMENT_LIST
})
Expand Down
6 changes: 3 additions & 3 deletions crates/biome_html_formatter/src/html/lists/element_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ impl FormatHtmlElementList {
None => None,
};

child_breaks = separator.map_or(false, |separator| separator.will_break());
child_breaks = separator.is_some_and(|separator| separator.will_break());

flat.write(&format_args![word, separator], f);

Expand Down Expand Up @@ -302,7 +302,7 @@ impl FormatHtmlElementList {
None => None,
};

child_breaks = line_mode.map_or(false, |mode| mode.is_hard());
child_breaks = line_mode.is_some_and(|mode| mode.is_hard());

let format_separator = line_mode.map(|mode| {
format_with(move |f| f.write_element(FormatElement::Line(mode)))
Expand Down Expand Up @@ -412,7 +412,7 @@ impl FormatHtmlElementList {
meta.meaningful_text = meta.meaningful_text
|| text
.value_token()
.map_or(false, |token| is_meaningful_html_text(token.text()));
.is_ok_and(|token| is_meaningful_html_text(token.text()));
}
_ => {}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ impl ImportNode {
let will_need_newline = sep
.trailing_trivia()
.last()
.map_or(false, |piece| piece.kind().is_single_line_comment());
.is_some_and(|piece| piece.kind().is_single_line_comment());

(sep.clone(), will_need_newline)
} else {
Expand Down Expand Up @@ -474,7 +474,7 @@ fn prepend_leading_newline(
let leading_trivia = prev_token.leading_trivia();
let has_leading_newline = leading_trivia
.first()
.map_or(false, |piece| piece.is_newline());
.is_some_and(|piece| piece.is_newline());

if has_leading_newline {
return None;
Expand Down
2 changes: 1 addition & 1 deletion crates/biome_js_analyze/src/lint/a11y/no_redundant_alt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ impl Rule for NoRedundantAlt {
expr.elements().into_iter().any(|template_element| {
match template_element {
AnyJsTemplateElement::JsTemplateChunkElement(node) => {
node.template_chunk_token().ok().map_or(false, |token| {
node.template_chunk_token().ok().is_some_and(|token| {
is_redundant_alt(token.text_trimmed())
})
}
Expand Down
Loading
Loading