Skip to content

Commit 4160751

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

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

rules/no-inline-assertions.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +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-
}
126

137
const create = context => {
148
const ava = createAvaRule();
@@ -31,7 +25,11 @@ const create = context => {
3125

3226
const {body} = functionArg;
3327
if (body.type === 'CallExpression') {
34-
report({node, context});
28+
context.report({
29+
node,
30+
message: 'The test implementation should not be an inline arrow function.',
31+
fix: fixer => [fixer.insertTextBefore(body, "{"), fixer.insertTextAfter(body, "}")]
32+
});
3533
}
3634
})
3735
});
@@ -43,6 +41,7 @@ module.exports = {
4341
docs: {
4442
url: util.getDocsUrl(__filename)
4543
},
46-
type: 'suggestion'
44+
type: 'suggestion',
45+
fixable: 'code'
4746
}
4847
};

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)