oxc-project/oxc · warning · OxcDiagnostic

Missing padding before {name} block

Error message

Missing padding before {name} block

What it means

Diagnostic produced by the shared Jest helper `report_missing_padding_before_jest_block` (crates/oxc_linter/src/utils/jest/padding_around_block.rs), used by the `jest/*padding-around-*-blocks*` style rules (e.g. padding around describe/beforeEach/beforeAll/afterAll blocks). The helper finds the statement immediately before the block, examines the whitespace between them (walking backwards over any comments so a comment directly attached to the block counts as part of it), and reports when the source text between contains fewer than 2 newline characters — i.e. no empty line separates the previous statement from the block.

Source

Thrown at crates/oxc_linter/src/utils/jest/padding_around_block.rs:9

use oxc_ast::{AstKind, ast::Statement};
use oxc_diagnostics::OxcDiagnostic;
use oxc_semantic::AstNode;
use oxc_span::{GetSpan, Span};

use crate::context::LintContext;

fn padding_around_jest_block_diagnostic(span: Span, name: &str) -> OxcDiagnostic {
    OxcDiagnostic::warn(format!("Missing padding before {name} block"))
        .with_help(format!("Make sure there is an empty new line before the {name} block"))
        .with_label(span)
}

pub fn report_missing_padding_before_jest_block<'a>(
    node: &AstNode<'a>,
    ctx: &LintContext<'a>,
    name: &str,
) {
    let scope_node = ctx.nodes().get_node(ctx.scoping().get_node_id(node.scope_id()));
    let prev_statement_span = match scope_node.kind() {
        AstKind::Program(program) => get_statement_span_before_node(node, program.body.as_slice()),
        AstKind::ArrowFunctionExpression(arrow_func_expr) => {
            let Some(body) = arrow_func_expr.get_function_body() else { return };
            get_statement_span_before_node(node, body.statements.as_slice())
        }
        AstKind::Function(function) => {
            let Some(body) = &function.body else {

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Add an empty line before the flagged describe/beforeEach/it block.
  2. Run `oxlint --fix` — the rule's fixer rewrites the gap to `\n\n` preserving indentation.
  3. Configure your editor/format-on-save to keep blank lines around test blocks, or turn the specific padding rule off in .oxlintrc.json if the style is unwanted.

Example fix

// before
const helper = () => {}
describe('foo', () => {
  it('works', () => {})
})

// after
const helper = () => {}

describe('foo', () => {
  it('works', () => {})
})
Defensive patterns

Strategy: validation

Prevention

When it happens

Trigger: In a test file, a describe/hook/test block that starts on the line immediately after the previous statement with no blank line: `const x = 1;\ndescribe('foo', () => {})`. The comment loop adjusts boundaries: `const x = 1;\n// note\ndescribe(...)` still fails because the space before the comment has no newline; a blank line anywhere in the gap (2+ newlines in `span_between`) passes. Reported per block, with an auto-fix that replaces the in-between whitespace with `\n\n` plus the original indentation.

Common situations: Teams adopting `@stylistic/padding-around-test-blocks`-style rules for readable test files; new tests inserted quickly without blank lines; code generated by snippets or AI tools that omit blank lines.

Related errors


AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20). Data as JSON: /api/errors/adbe6a7947ac640f. Report an issue: GitHub.