Skip to content

linter: jest/padding-around-after-all-blocks miscounts padding when multiple comments precede the hook #21945

Description

@kapobajza

What version of Oxlint are you using?

1.62.0

What command did you run?

npx oxlint path/to/file.test.ts

What does your .oxlintrc.json (or oxlint.config.ts) config file look like?

{
  "$schema": "./node_modules/oxlint/configuration_schema.json",
  "plugins": ["jest"],
  "rules": {
    "jest/padding-around-after-all-blocks": "error"
  }
}

What happened?

jest/padding-around-after-all-blocks produces incorrect results when two or more comments sit between the previous statement and the afterAll block. The rule appears to misclassify whether the comment group is "attached to" the previous statement or to the hook, which causes both false negatives and a broken autofix.

1. False negative — invalid code is not reported

This input has no blank line anywhere between const thing = 123; and afterAll(...), so the rule should report it. It does not:

const thing = 123;
/* one */
/* two */
afterAll(() => {});

Expected: Missing padding before afterAll block.
Actual: no diagnostic.

2. Autofix is incorrect

For case 2 (the input that should be flagged), the expected autofix is to insert a blank line before the attached comment group, i.e.:

// input
const thing = 123;
/* one */
/* two */
afterAll(() => {});

// expected output
const thing = 123;

/* one */
/* two */
afterAll(() => {});

Even after forcing the diagnostic to fire, the fixer does not produce this output.

I've tested this with ESLint, trying out both the jest/padding-around-after-all-blocks rule and vitest/padding-around-after-all-blocks, and it works as mentioned in the "expected output" section in the aforementioned cases above.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Fields

    Priority

    None yet

    Effort

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions