ntnyq/no-only-tests
Disallow use
.onlyblocks in tests.
- 🔧 The
--fixoption on the command line can automatically fix some of the problems reported by this rule.
📖 Rule Details
This rule reports while using .only blocks in tests.
Static computed access such as test['only']() and optional call chains are also checked. Dynamic computed access such as registry[key].test.only() is ignored because the root test function cannot be resolved statically.
describe('some describe block', () => {})
it('some assertion', () => {})
other.only('this is allowed by default', () => {})describe.only('focused suite', () => {})
it.only('focused case', () => {})
test.only('focused test', () => {})🔧 Options
export type Options = [
{
block?: string[]
focus?: string[]
functions?: string[]
fix?: boolean
},
]Defaults:
block:['describe', 'it', 'context', 'test', 'tape', 'fixture', 'serial', 'Feature', 'Scenario', 'Given', 'And', 'When', 'Then']focus:['only']functions:[]fix:false
block
List of block names that should not be focused. Wildcard suffix * is supported.
// options: [{ block: ['test*'] }]
testResource.only('resource test', () => {})focus
List of focus method names.
// options: [{ focus: ['focus'] }]
test.focus('focused test', () => {})functions
List of direct function names to disallow.
// options: [{ functions: ['fit', 'xit'] }]
xit('skipped test', () => {})fix
When true, the rule removes focus method usage such as .only or .focus. Direct optional calls retain short-circuiting: test?.only() becomes test?.(). Optional focus references and longer optional chains are reported without automatic fixes when removing the member would change that behavior.
🚀 Version
This rule was introduced in eslint-plugin-ntnyq v0.15.0