eslint-bun-rule-tester
v0.1.0
Published
Explicit, type-safe ESLint rule testing with Bun
Downloads
147
Maintainers
Readme
eslint-bun-rule-tester
Explicit, type-safe ESLint rule testing with Bun.
Install
bun add --dev eslint-bun-rule-tester eslintUsage
import { test } from 'bun:test'
import { createRuleTester } from 'eslint-bun-rule-tester'
import { rule } from './rule.ts'
const { invalid, valid } = createRuleTester({
name: 'my-rule',
rule,
})
test('accepts valid code', () => {
valid('const value = true')
})
test('reports invalid code', () => {
invalid({
code: 'const value = false',
errors: ['invalidValue'],
})
})String error assertions are inferred from rule.meta.messages. The tester also accepts partial
ESLint diagnostics, filenames, working directories, default rule options, per-case rule options,
and custom language options.
This package executes rules with ESLint's Linter. ESLint-compatible rules intended for another
runtime, including Oxlint JS plugins, still need an integration test in that runtime.
API
createRuleTester(options)
Returns explicit valid(testCase) and invalid(testCase) assertion functions for use inside Bun
tests. A valid case may be a source string or an object. Invalid cases require an error count or
expected diagnostics.
License
MIT
