Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

Commit

Permalink
Clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaReiser committed Sep 30, 2022
1 parent 1f581aa commit 8cee5d6
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ impl FormatFunction {
[
space(),
FormatMaybeCachedFunctionBody {
body: &body.clone().into(),
body: &body.into(),
mode: options.body_cache_mode
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ impl ArrowFunctionLayout {
middle,
tail: current,
expand_signatures: should_break,
options: options.clone(),
options: *options,
}),
}
}
Expand Down
32 changes: 14 additions & 18 deletions crates/rome_js_formatter/src/js/expressions/call_arguments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ enum FormatCallArgument {
impl FormatCallArgument {
/// Returns `true` if this argument contains any content that forces a group to [`break`](FormatElements::will_break).
fn will_break(&mut self, f: &mut JsFormatter) -> bool {
let breaks = match &self {
match &self {
FormatCallArgument::Default {
element,
leading_lines,
Expand All @@ -191,9 +191,7 @@ impl FormatCallArgument {
..
} => result.will_break(),
FormatCallArgument::Inspected { .. } => false,
};

breaks
}
}

fn cache_function_body(&mut self, f: &mut JsFormatter) {
Expand Down Expand Up @@ -621,7 +619,7 @@ impl Format<JsFormatContext> for FormatGroupedLastArgument<'_> {
)?;

if let Some(separator) = element.trailing_separator()? {
write!(f, [format_removed(&separator)])?;
write!(f, [format_removed(separator)])?;
}

Ok(())
Expand Down Expand Up @@ -734,7 +732,7 @@ fn arguments_grouped_layout(
) -> Option<GroupedCallArgumentLayout> {
if should_group_first_argument(args, comments).unwrap_or(false) {
Some(GroupedCallArgumentLayout::GroupedFirstArgument)
} else if should_group_last_argument(&args, comments).unwrap_or(false) {
} else if should_group_last_argument(args, comments).unwrap_or(false) {
Some(GroupedCallArgumentLayout::GroupedLastArgument)
} else {
None
Expand Down Expand Up @@ -1132,7 +1130,7 @@ pub(crate) fn is_test_call_expression(call_expression: &JsCallExpression) -> Syn
))),
Some(Ok(second)),
third,
) if arguments.args().len() <= 3 && contains_a_test_pattern(callee.clone())? => {
) if arguments.args().len() <= 3 && contains_a_test_pattern(&callee)? => {
// it('name', callback, duration)
if !matches!(
third,
Expand All @@ -1147,7 +1145,7 @@ pub(crate) fn is_test_call_expression(call_expression: &JsCallExpression) -> Syn

if second
.as_js_any_expression()
.map_or(false, |second| is_angular_test_wrapper(second))
.map_or(false, is_angular_test_wrapper)
{
return Ok(true);
}
Expand Down Expand Up @@ -1247,8 +1245,8 @@ fn is_unit_test_set_up_callee(callee: &JsAnyExpression) -> bool {
/// Based on this [article]
///
/// [article]: https://craftinginterpreters.com/scanning-on-demand.html#tries-and-state-machines
fn contains_a_test_pattern(callee: JsAnyExpression) -> SyntaxResult<bool> {
let mut members = CalleeNamesIterator::new(callee);
fn contains_a_test_pattern(callee: &JsAnyExpression) -> SyntaxResult<bool> {
let mut members = CalleeNamesIterator::new(callee.clone());

let texts: [Option<SyntaxTokenText>; 5] = [
members.next(),
Expand Down Expand Up @@ -1305,9 +1303,7 @@ struct CalleeNamesIterator {

impl CalleeNamesIterator {
fn new(callee: JsAnyExpression) -> Self {
Self {
next: Some(callee.into()),
}
Self { next: Some(callee) }
}
}

Expand Down Expand Up @@ -1374,13 +1370,13 @@ mod test {
fn matches_simple_call() {
let call_expression = extract_call_expression("test();");
assert_eq!(
contains_a_test_pattern(call_expression.callee().unwrap()),
contains_a_test_pattern(&call_expression.callee().unwrap()),
Ok(true)
);

let call_expression = extract_call_expression("it();");
assert_eq!(
contains_a_test_pattern(call_expression.callee().unwrap()),
contains_a_test_pattern(&call_expression.callee().unwrap()),
Ok(true)
);
}
Expand All @@ -1389,7 +1385,7 @@ mod test {
fn matches_static_member_expression() {
let call_expression = extract_call_expression("test.only();");
assert_eq!(
contains_a_test_pattern(call_expression.callee().unwrap()),
contains_a_test_pattern(&call_expression.callee().unwrap()),
Ok(true)
);
}
Expand All @@ -1398,7 +1394,7 @@ mod test {
fn matches_static_member_expression_deep() {
let call_expression = extract_call_expression("test.describe.parallel.only();");
assert_eq!(
contains_a_test_pattern(call_expression.callee().unwrap()),
contains_a_test_pattern(&call_expression.callee().unwrap()),
Ok(true)
);
}
Expand All @@ -1407,7 +1403,7 @@ mod test {
fn doesnt_static_member_expression_deep() {
let call_expression = extract_call_expression("test.describe.parallel.only.AHAHA();");
assert_eq!(
contains_a_test_pattern(call_expression.callee().unwrap()),
contains_a_test_pattern(&call_expression.callee().unwrap()),
Ok(false)
);
}
Expand Down
4 changes: 2 additions & 2 deletions crates/rome_js_formatter/src/utils/function_body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl Format<JsFormatContext> for FormatMaybeCachedFunctionBody<'_> {
}
FunctionBodyCacheMode::Cached => {
match f.context().get_cached_function_body(self.body) {
Some(cached) => f.write_element(cached.clone()),
Some(cached) => f.write_element(cached),
None => {
// This can happen in the unlikely event where a function has a parameter with
// an initializer that contains a call expression with a first or last function/arrow
Expand All @@ -51,7 +51,7 @@ impl Format<JsFormatContext> for FormatMaybeCachedFunctionBody<'_> {
Some(interned) => {
f.context_mut()
.set_cached_function_body(self.body, interned.clone());
f.write_element(interned.clone())
f.write_element(interned)
}
None => Ok(()),
},
Expand Down

0 comments on commit 8cee5d6

Please sign in to comment.