Skip to content

Commit 28f112d

Browse files
committed
refactor(formatter): change mutable reference to immutable reference and remove global !clippy::needless_pass_by_ref_mut (#15940)
1 parent 034b275 commit 28f112d

File tree

18 files changed

+28
-39
lines changed

18 files changed

+28
-39
lines changed

crates/oxc_formatter/src/formatter/builders.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2365,7 +2365,7 @@ where
23652365
}
23662366

23672367
/// Finishes the output and returns any error encountered.
2368-
pub fn finish(&mut self) -> FormatResult<()> {
2368+
pub fn finish(&self) -> FormatResult<()> {
23692369
self.result
23702370
}
23712371
}
@@ -2444,7 +2444,7 @@ where
24442444
self
24452445
}
24462446

2447-
pub fn finish(&mut self) -> FormatResult<()> {
2447+
pub fn finish(&self) -> FormatResult<()> {
24482448
self.result
24492449
}
24502450

crates/oxc_formatter/src/formatter/format_element/document.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ impl Document<'_> {
3434
/// [`BestFitting`]'s content expands is not propagated past the [`BestFitting`] element.
3535
///
3636
/// [`BestFitting`]: FormatElement::BestFitting
37-
pub(crate) fn propagate_expand(&mut self) {
37+
pub(crate) fn propagate_expand(&self) {
3838
#[derive(Debug)]
3939
enum Enclosing<'a> {
4040
Group(&'a tag::Group),

crates/oxc_formatter/src/formatter/format_extensions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ where
134134
/// # }
135135
///
136136
/// ```
137-
pub fn inspect(&mut self, f: &mut Formatter<'_, 'ast>) -> FormatResult<&[FormatElement<'ast>]> {
137+
pub fn inspect(&self, f: &mut Formatter<'_, 'ast>) -> FormatResult<&[FormatElement<'ast>]> {
138138
let result = self.memory.get_or_init(|| f.intern(&self.inner));
139139

140140
match result.as_ref() {

crates/oxc_formatter/src/formatter/formatter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ impl<'buf, 'ast> Formatter<'buf, 'ast> {
243243

244244
#[expect(clippy::unused_self)] // Keep `self` the same as the original source
245245
pub fn intern_vec(
246-
&mut self,
246+
&self,
247247
mut elements: ArenaVec<'ast, FormatElement<'ast>>,
248248
) -> Option<FormatElement<'ast>> {
249249
match elements.len() {

crates/oxc_formatter/src/lib.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
#![allow(
2-
unused,
3-
clippy::inline_always,
4-
clippy::missing_panics_doc,
5-
clippy::needless_pass_by_ref_mut
6-
)] // FIXME: all these needs to be fixed.
1+
#![allow(unused, clippy::inline_always, clippy::missing_panics_doc)] // FIXME: all these needs to be fixed.
72

83
mod ast_nodes;
94
#[cfg(feature = "detect_code_removal")]

crates/oxc_formatter/src/utils/assignment_like.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ impl<'a> AssignmentLike<'a, '_> {
366366
&self,
367367
is_left_short: bool,
368368
left_may_break: bool,
369-
f: &mut Formatter<'_, 'a>,
369+
f: &Formatter<'_, 'a>,
370370
) -> AssignmentLikeLayout {
371371
if self.has_only_left_hand_side() {
372372
return AssignmentLikeLayout::OnlyLeft;

crates/oxc_formatter/src/utils/conditional.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ fn format_trailing_comments<'a>(
167167

168168
impl<'a> FormatConditionalLike<'a, '_> {
169169
/// Determines the layout of this conditional based on its parent
170-
fn layout(&self, f: &mut Formatter<'_, 'a>) -> ConditionalLayout {
170+
fn layout(&self, f: &Formatter<'_, 'a>) -> ConditionalLayout {
171171
let self_span = self.span();
172172

173173
match self.parent() {

crates/oxc_formatter/src/utils/member_chain/groups.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ impl<'a, 'b> TailChainGroups<'a, 'b> {
100100
}
101101

102102
/// Test if any group except the last group [break](FormatElements::will_break).
103-
pub(super) fn any_except_last_will_break(&self, f: &mut Formatter<'_, 'a>) -> bool {
103+
pub(super) fn any_except_last_will_break(&self, f: &Formatter<'_, 'a>) -> bool {
104104
for group in &self.groups[..self.groups.len().saturating_sub(1)] {
105105
if group.will_break(f) {
106106
return true;
@@ -170,7 +170,7 @@ impl<'a, 'b> MemberChainGroup<'a, 'b> {
170170
}
171171

172172
/// Tests if the formatted result of this group results in a [break](FormatElements::will_break).
173-
pub(super) fn will_break(&self, f: &mut Formatter<'_, 'a>) -> bool {
173+
pub(super) fn will_break(&self, f: &Formatter<'_, 'a>) -> bool {
174174
let mut cell = self.formatted.borrow_mut();
175175
if let Some(formatted) = cell.as_ref() {
176176
formatted.will_break()

crates/oxc_formatter/src/utils/member_chain/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ impl<'a, 'b> MemberChain<'a, 'b> {
122122
}
123123

124124
/// It tells if the groups should break on multiple lines
125-
fn groups_should_break(&self, f: &mut Formatter<'_, 'a>) -> bool {
125+
fn groups_should_break(&self, f: &Formatter<'_, 'a>) -> bool {
126126
let mut call_expressions = self
127127
.members()
128128
.filter_map(|member| match member {
@@ -163,7 +163,7 @@ impl<'a, 'b> MemberChain<'a, 'b> {
163163

164164
/// We retrieve all the call expressions inside the group and we check if
165165
/// their arguments are not simple.
166-
fn last_call_breaks(&self, f: &mut Formatter<'_, 'a>) -> bool {
166+
fn last_call_breaks(&self, f: &Formatter<'_, 'a>) -> bool {
167167
let last_group = self.last_group();
168168

169169
if matches!(last_group.members().last(), Some(ChainMember::CallExpression { .. })) {

crates/oxc_formatter/src/utils/string.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ impl<'a> LiteralStringNormalizer<'a> {
195195
Self { token, chosen_quote_style, chosen_quote_properties }
196196
}
197197

198-
fn normalize_text(&mut self, source_type: SourceType) -> Cow<'a, str> {
198+
fn normalize_text(&self, source_type: SourceType) -> Cow<'a, str> {
199199
let str_info = self.token.compute_string_information(self.chosen_quote_style);
200200
match self.token.parent_kind {
201201
StringLiteralParentKind::Expression => self.normalize_string_literal(str_info),
@@ -205,10 +205,7 @@ impl<'a> LiteralStringNormalizer<'a> {
205205
}
206206
}
207207

208-
fn normalize_import_attribute(
209-
&mut self,
210-
string_information: StringInformation,
211-
) -> Cow<'a, str> {
208+
fn normalize_import_attribute(&self, string_information: StringInformation) -> Cow<'a, str> {
212209
let quoteless = self.raw_content();
213210
let can_remove_quotes =
214211
!self.is_preserve_quote_properties() && is_identifier_name(quoteless);
@@ -219,7 +216,7 @@ impl<'a> LiteralStringNormalizer<'a> {
219216
}
220217
}
221218

222-
fn normalize_directive(&mut self, string_information: StringInformation) -> Cow<'a, str> {
219+
fn normalize_directive(&self, string_information: StringInformation) -> Cow<'a, str> {
223220
// In diretcives, unnecessary escapes should be preserved.
224221
// See https://github.com/prettier/prettier/issues/1555
225222
// Thus we don't normalize the string.
@@ -261,7 +258,7 @@ impl<'a> LiteralStringNormalizer<'a> {
261258
}
262259

263260
fn normalize_type_member(
264-
&mut self,
261+
&self,
265262
string_information: StringInformation,
266263
source_type: SourceType,
267264
) -> Cow<'a, str> {

0 commit comments

Comments
 (0)