-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy pathuse-t-throws-async-well.js
50 lines (46 loc) · 1.16 KB
/
use-t-throws-async-well.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
'use strict';
const {visitIf} = require('enhance-visitors');
const util = require('../util');
const createAvaRule = require('../create-ava-rule');
const create = context => {
const ava = createAvaRule();
return ava.merge({
CallExpression: visitIf([
ava.isInTestFile,
ava.isInTestNode,
])(node => {
if (
node.parent.type === 'ExpressionStatement'
&& node.callee.type === 'MemberExpression'
&& (node.callee.property.name === 'throwsAsync' || node.callee.property.name === 'notThrowsAsync')
&& node.callee.object.name === 't'
) {
const message = `Use \`await\` with \`t.${node.callee.property.name}()\`.`;
if (ava.isInTestNode().arguments[0].async) {
context.report({
node,
message,
fix: fixer => fixer.replaceText(node.callee, `await ${context.getSourceCode().getText(node.callee)}`),
});
} else {
context.report({
node,
message,
});
}
}
}),
});
};
module.exports = {
create,
meta: {
type: 'problem',
docs: {
description: 'Ensure that `t.throwsAsync()` and `t.notThrowsAsync()` are awaited.',
url: util.getDocsUrl(__filename),
},
fixable: 'code',
schema: [],
},
};