Skip to content

Conversation

@marcoroth
Copy link
Owner

@marcoroth marcoroth commented Oct 8, 2025

This pull request implements linter test helpers to reduce the verbosity in the linter rule tests. The new createLinterTest() helper provides a cleaner API with expectError(), expectWarning(), expectNoOffenses(), and assertOffenses() functions.

Example:

import { SomeRule } from "../../src/rules/some-rule.js"
import { createLinterTest } from "../helpers/linter-test-helper.js"

const { expectNoOffenses, expectError, assertOffenses } = createLinterTest(SomeRule)

describe("SomeRule", () => {
  test("no offenses", () => {
    expectNoOffenses(`<div></div>`)
  })

  test("with offenses", () => {
    expectError("Error message.")
    expectWarning("Warning message.")

    assertOffenses(`<div></div>`)
  })
})

Resolves #461

@marcoroth marcoroth force-pushed the linter-test-helpers branch from 414828f to 7978955 Compare October 8, 2025 12:02
@marcoroth marcoroth merged commit 230dcf4 into main Oct 8, 2025
7 checks passed
@marcoroth marcoroth deleted the linter-test-helpers branch October 8, 2025 12:08
asilano pushed a commit to fac/herb that referenced this pull request Oct 21, 2025
This pull request implements linter test helpers to reduce the verbosity
in the linter rule tests. The new `createLinterTest()` helper provides a
cleaner API with `expectError()`, `expectWarning()`,
`expectNoOffenses()`, and `assertOffenses()` functions.

Example:

```ts
import { SomeRule } from "../../src/rules/some-rule.js"
import { createLinterTest } from "../helpers/linter-test-helper.js"

const { expectNoOffenses, expectError, assertOffenses } = createLinterTest(SomeRule)

describe("SomeRule", () => {
  test("no offenses", () => {
    expectNoOffenses(`<div></div>`)
  })

  test("with offenses", () => {
    expectError("Error message.")
    expectWarning("Warning message.")

    assertOffenses(`<div></div>`)
  })
})
```

Resolves marcoroth#461
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Linter: Introduce linter test helper that make the linter tests less verbose

2 participants