Skip to content

Commit

Permalink
split no_lone_blocks_diagnostic
Browse files Browse the repository at this point in the history
  • Loading branch information
baseballyama committed Dec 27, 2024
1 parent 62f0f8b commit 41327f9
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions crates/oxc_linter/src/rules/eslint/no_lone_blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ use oxc_span::{GetSpan, Span};

use crate::{context::LintContext, rule::Rule, AstNode};

fn no_lone_blocks_diagnostic(span: Span, is_nested_block: bool) -> OxcDiagnostic {
let message =
if is_nested_block { "Nested block is redundant." } else { "Block is unnecessary." };
// See <https://oxc.rs/docs/contribute/linter/adding-rules.html#diagnostics> for details
OxcDiagnostic::warn(message).with_label(span)
fn no_lone_blocks_diagnostic(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Block is unnecessary.").with_label(span)
}

fn no_lone_blocks_diagnostic_nested(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Nested block is redundant.").with_label(span)
}

#[derive(Debug, Default, Clone)]
Expand Down Expand Up @@ -116,9 +117,9 @@ impl Rule for NoLoneBlocks {
fn report(ctx: &LintContext, node: &AstNode, parent_node: &AstNode) {
match parent_node.kind() {
AstKind::BlockStatement(_) | AstKind::StaticBlock(_) => {
ctx.diagnostic(no_lone_blocks_diagnostic(node.span(), true));
ctx.diagnostic(no_lone_blocks_diagnostic_nested(node.span()));
}
_ => ctx.diagnostic(no_lone_blocks_diagnostic(node.span(), false)),
_ => ctx.diagnostic(no_lone_blocks_diagnostic(node.span())),
};
}

Expand Down

0 comments on commit 41327f9

Please sign in to comment.