Skip to content

Commit 69144d8

Browse files
committed
feat: add fixer to no-inline-assertions
1 parent b07ccb5 commit 69144d8

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

rules/no-inline-assertions.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,6 @@ const {visitIf} = require('enhance-visitors');
33
const createAvaRule = require('../create-ava-rule');
44
const util = require('../util');
55

6-
function report({node, context}) {
7-
context.report({
8-
node,
9-
message: 'The test implementation should not be an inline arrow function.'
10-
});
11-
}
12-
136
const create = context => {
147
const ava = createAvaRule();
158

@@ -31,7 +24,11 @@ const create = context => {
3124

3225
const {body} = functionArg;
3326
if (body.type === 'CallExpression') {
34-
report({node, context});
27+
context.report({
28+
node,
29+
message: 'The test implementation should not be an inline arrow function.',
30+
fix: fixer => [fixer.insertTextBefore(body, '{'), fixer.insertTextAfter(body, '}')]
31+
});
3532
}
3633
})
3734
});
@@ -43,6 +40,7 @@ module.exports = {
4340
docs: {
4441
url: util.getDocsUrl(__filename)
4542
},
46-
type: 'suggestion'
43+
type: 'suggestion',
44+
fixable: 'code'
4745
}
4846
};

test/no-inline-assertions.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,18 @@ ruleTester.run('no-todo-test', rule, {
3030
invalid: [
3131
{
3232
code: header + 'test("my test name", t => t.skip());',
33-
errors
33+
errors,
34+
output: header + 'test("my test name", t => {t.skip()});'
3435
},
3536
{
3637
code: header + 'test("my test name", t => t.true(fn()));',
37-
errors
38+
errors,
39+
output: header + 'test("my test name", t => {t.true(fn())});'
3840
},
3941
{
4042
code: header + 'test("my test name", t => \n t.true(fn()));',
41-
errors
43+
errors,
44+
output: header + 'test("my test name", t => \n {t.true(fn())});'
4245
}
4346
]
4447
});

0 commit comments

Comments
 (0)