Skip to content

Commit 5c52975

Browse files
committed
refactor(linter): remove redundant rule comments (#27830)
Remove comments that restate the adjacent checks and operations in lint rule implementations.
1 parent 329c583 commit 5c52975

11 files changed

Lines changed: 19 additions & 54 deletions

File tree

‎crates/oxc_linter/src/rules/eslint/array_callback_return/mod.rs‎

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -389,38 +389,33 @@ pub fn get_array_method_info<'a>(
389389
};
390390

391391
// Array.from
392-
if callee.is_specific_member_access("Array", "from") {
393-
// Check that current node is parent's second argument
394-
if call.arguments.len() == 2
395-
&& let Some(call_arg) = call.arguments[1].as_expression()
396-
&& call_arg.span() == current_node.kind().span()
397-
{
398-
return Some((callee.span(), "from"));
399-
}
392+
if callee.is_specific_member_access("Array", "from")
393+
&& call.arguments.len() == 2
394+
&& let Some(call_arg) = call.arguments[1].as_expression()
395+
&& call_arg.span() == current_node.kind().span()
396+
{
397+
return Some((callee.span(), "from"));
400398
}
401399

402400
// Array.fromAsync
403-
if callee.is_specific_member_access("Array", "fromAsync") {
404-
// Check that current node is parent's second argument
405-
if call.arguments.len() == 2
406-
&& let Some(call_arg) = call.arguments[1].as_expression()
407-
&& call_arg.span() == current_node.kind().span()
408-
{
409-
return Some((callee.span(), "fromAsync"));
410-
}
401+
if callee.is_specific_member_access("Array", "fromAsync")
402+
&& call.arguments.len() == 2
403+
&& let Some(call_arg) = call.arguments[1].as_expression()
404+
&& call_arg.span() == current_node.kind().span()
405+
{
406+
return Some((callee.span(), "fromAsync"));
411407
}
412408

413409
// "methods",
414410
let (array_method_span, array_method) = callee.static_property_info()?;
415411
let array_method = array_method.as_str()?;
416412

417413
if TARGET_METHODS.contains(&array_method)
418-
// Check that current node is parent's first argument
419414
&& call.arguments.len() == 1
420415
&& let Some(call_arg) = call.arguments.first()
421-
&& call_arg
422-
.as_expression()
423-
.is_some_and(|arg| arg.span() == current_node.kind().span())
416+
&& call_arg
417+
.as_expression()
418+
.is_some_and(|arg| arg.span() == current_node.kind().span())
424419
{
425420
return Some((array_method_span, array_method));
426421
}

‎crates/oxc_linter/src/rules/eslint/arrow_body_style.rs‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,6 @@ impl ArrowBodyStyle {
273273
}
274274
Mode::AsNeeded if body.directives.is_empty() && body.statements.len() == 1 => {
275275
if let Statement::ReturnStatement(return_statement) = &body.statements[0] {
276-
// Skip if requireReturnForObjectLiteral and returning an object
277276
if self.1.require_return_for_object_literal
278277
&& matches!(
279278
return_statement.argument,
@@ -315,7 +314,6 @@ impl ArrowBodyStyle {
315314
) -> RuleFix {
316315
let body = &arrow_func_expr.body;
317316

318-
// Get the expression from the concise body
319317
let Some(expr) = arrow_func_expr.get_expression() else {
320318
return fixer.noop();
321319
};
@@ -420,12 +418,10 @@ impl ArrowBodyStyle {
420418
node: &AstNode<'a>,
421419
ctx: &LintContext<'a>,
422420
) -> bool {
423-
// Check if the expression contains an `in` operator
424421
if !Self::contains_in_operator(return_arg) {
425422
return false;
426423
}
427424

428-
// Check if the arrow function is inside a for-loop initializer
429425
Self::is_inside_for_loop_init(node, ctx)
430426
}
431427

@@ -459,7 +455,6 @@ impl ArrowBodyStyle {
459455
for ancestor in ctx.nodes().ancestors(node.id()).skip(1) {
460456
match ancestor.kind() {
461457
AstKind::ForStatement(for_stmt) => {
462-
// Check if the arrow function is in the init part
463458
if let Some(init) = &for_stmt.init
464459
&& let AstKind::ArrowFunctionExpression(arrow) = node.kind()
465460
&& init.span().contains_inclusive(arrow.span)

‎crates/oxc_linter/src/rules/import/named.rs‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,10 @@ impl Rule for Named {
125125
let module_record = ctx.module_record();
126126

127127
for import_entry in &module_record.import_entries {
128-
// Get named import
129128
let ImportImportName::Name(import_name) = &import_entry.import_name else {
130129
continue;
131130
};
132131
let specifier = import_entry.module_request.name();
133-
// Get remote module record
134132
let Some(remote_module_record) = module_record.get_loaded_module(specifier) else {
135133
continue;
136134
};
@@ -143,7 +141,6 @@ impl Rule for Named {
143141
if name == "default" && remote_module_record.export_default.is_some() {
144142
continue;
145143
}
146-
// Check remote bindings
147144
if remote_module_record.exported_bindings.contains_key(name) {
148145
continue;
149146
}
@@ -167,14 +164,12 @@ impl Rule for Named {
167164
continue;
168165
};
169166
let specifier = module_request.name();
170-
// Get remote module record
171167
let Some(remote_module_record) = module_record.get_loaded_module(specifier) else {
172168
continue;
173169
};
174170
if !remote_module_record.has_module_syntax {
175171
continue;
176172
}
177-
// Check remote bindings
178173
let name = import_name.name();
179174
// `export { default as foo } from './source'` <> `export default xxx`
180175
if name == "default" && has_default_export(&remote_module_record) {

‎crates/oxc_linter/src/rules/jest/prefer_to_have_been_called.rs‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ impl PreferToHaveBeenCalled {
9191
return;
9292
}
9393

94-
// check if first argument is 0
9594
let Some(arg) = parsed_expect_call.args.first() else { return };
9695
let Some(arg_expr) = arg.as_expression() else {
9796
return;
@@ -101,7 +100,6 @@ impl PreferToHaveBeenCalled {
101100
}
102101

103102
ctx.diagnostic_with_fix(prefer_to_have_been_called_diagnostic(call_expr.span), |fixer| {
104-
// check if there is a `not` modifier
105103
let not_modifier =
106104
parsed_expect_call.modifiers().find(|modifier| modifier.is_name_equal("not"));
107105

‎crates/oxc_linter/src/rules/jsx_a11y/no_noninteractive_element_to_interactive_role.rs‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,14 +186,12 @@ impl Rule for NoNoninteractiveElementToInteractiveRole {
186186
return;
187187
}
188188

189-
// Skip if this element-role combination is allowed by config.
190189
if let Some(allowed) = self.0.allowed_roles.get(element_type.as_ref())
191190
&& allowed.iter().any(|r: &CompactStr| r.as_str() == first_role)
192191
{
193192
return;
194193
}
195194

196-
// Report if the element is non-interactive AND the role is interactive.
197195
if is_non_interactive_element(&element_type, jsx_el) && is_interactive_role(first_role) {
198196
ctx.diagnostic(no_noninteractive_element_to_interactive_role_diagnostic(
199197
role_attr.span,

‎crates/oxc_linter/src/rules/promise/no_callback_in_promise.rs‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,6 @@ impl NoCallbackInPromise {
157157
// Check if the parent is a CallExpression with then/catch
158158
let parent = ctx.nodes().parent_node(node.id());
159159
if let Some(call_expr) = parent.kind().as_call_expression() {
160-
// Check if this function is one of the arguments
161160
let is_argument = call_expr
162161
.arguments
163162
.iter()

‎crates/oxc_linter/src/rules/promise/no_nesting.rs‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ fn is_inside_promise(node: &AstNode, ctx: &LintContext) -> bool {
8080
// Check if the parent is a CallExpression with then/catch
8181
let parent = ctx.nodes().parent_node(node.id());
8282
if let Some(call_expr) = parent.kind().as_call_expression() {
83-
// Check if this function is one of the arguments
8483
let is_argument = call_expr
8584
.arguments
8685
.iter()

‎crates/oxc_linter/src/rules/promise/no_promise_in_callback.rs‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,6 @@ fn is_within_promise_handler<'a>(node: &AstNode<'a>, ctx: &LintContext<'a>) -> b
139139
return false;
140140
}
141141

142-
// Check if the parent is a CallExpression
143142
let parent = ctx.nodes().parent_node(node.id());
144143
let AstKind::CallExpression(call_expr) = parent.kind() else {
145144
return false;

‎crates/oxc_linter/src/rules/react/display_name.rs‎

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,6 @@ impl Rule for DisplayName {
179179
continue; // Name is valid displayName
180180
}
181181

182-
// Check if this symbol has a displayName assignment via semantic references
183182
if !has_display_name_via_semantic(symbol_id, component_info.name.as_ref(), ctx) {
184183
components_to_report.push((component_info.span, component_info.is_context));
185184
}
@@ -192,12 +191,10 @@ impl Rule for DisplayName {
192191
check_context_assignment_references(symbol_id, decl_node, ctx)
193192
});
194193

195-
if let Some(component_info) = context_assignment_info {
196-
// Check if this symbol has a displayName assignment
197-
if !has_display_name_via_semantic(symbol_id, component_info.name.as_ref(), ctx)
198-
{
199-
components_to_report.push((component_info.span, component_info.is_context));
200-
}
194+
if let Some(component_info) = context_assignment_info
195+
&& !has_display_name_via_semantic(symbol_id, component_info.name.as_ref(), ctx)
196+
{
197+
components_to_report.push((component_info.span, component_info.is_context));
201198
}
202199
}
203200
}
@@ -355,7 +352,6 @@ fn has_display_name_via_semantic(
355352
) -> bool {
356353
let component_name_str = component_name.map(CompactStr::as_str);
357354

358-
// Check all references to this symbol
359355
for reference in ctx.scoping().get_resolved_references(symbol_id) {
360356
if is_display_name_assignment_for_reference(reference, component_name_str, ctx) {
361357
return true;
@@ -383,7 +379,6 @@ fn check_context_assignment_references(
383379
None
384380
};
385381

386-
// Check all write references to this symbol
387382
for reference in ctx.scoping().get_resolved_references(symbol_id) {
388383
if !reference.is_write() {
389384
continue;
@@ -426,7 +421,6 @@ fn is_react_component_node<'a>(
426421
// That will be handled by checking write references in Phase 1
427422
decl.init.as_ref()?;
428423

429-
// Check for createContext
430424
if let Some(Expression::CallExpression(call)) = &decl.init
431425
&& is_create_context_call(call)
432426
{
@@ -477,7 +471,6 @@ fn is_react_component_node<'a>(
477471
});
478472
}
479473

480-
// Check for createReactClass
481474
if callee_name == "createClass" || callee_name == "createReactClass" {
482475
if !has_create_react_class_display_name(call, ignore_transpiler_name) {
483476
return Some(ReactComponentInfo {

‎crates/oxc_linter/src/rules/typescript/consistent_generic_constructors.rs‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,11 +209,9 @@ impl ConsistentGenericConstructors {
209209
let fixer = fixer.for_multifix();
210210
let source_text = ctx.source_text();
211211

212-
// Get the type arguments text
213212
let type_params_text =
214213
&source_text[type_params.span.start as usize..type_params.span.end as usize];
215214

216-
// Find the position where the binding pattern ends (before the colon)
217215
let binding_end = Self::find_binding_end_position(node);
218216

219217
// Find the colon position by searching only between the binding end and type annotation.
@@ -292,7 +290,6 @@ impl ConsistentGenericConstructors {
292290
let fixer = fixer.for_multifix();
293291
let source_text = ctx.source_text();
294292

295-
// Get the callee name (constructor name)
296293
let Expression::Identifier(callee_ident) = &new_expression.callee else {
297294
return fixer.noop();
298295
};
@@ -305,7 +302,6 @@ impl ConsistentGenericConstructors {
305302
// Build the type annotation to insert (no comments between name and type args)
306303
let type_annotation = format!(": {callee_name}{type_args_text}");
307304

308-
// Find the position to insert the type annotation (after the binding pattern/identifier)
309305
let Some(insert_pos) = Self::find_type_annotation_insert_position(node, ctx) else {
310306
return fixer.noop();
311307
};

0 commit comments

Comments
 (0)