Skip to content

Commit 02a2c8f

Browse files
committed
feedback
added more checks as guided
1 parent dcd4357 commit 02a2c8f

File tree

4 files changed

+31
-13
lines changed

4 files changed

+31
-13
lines changed

index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ module.exports = {
4444
'ava/prefer-async-await': 'error',
4545
'ava/prefer-power-assert': 'off',
4646
'ava/prefer-t-regex': 'error',
47-
'ava/prevent-errortype': 'error',
4847
'ava/test-ended': 'error',
4948
'ava/test-title': 'error',
5049
'ava/test-title-format': 'off',

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
"ava": {
6363
"files": [
6464
"!rules",
65-
"test/*js"
65+
"test/*js"
6666
]
6767
},
6868
"xo": {

rules/no-error-ctor-with-notthrows.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,16 @@ const create = context => {
1111
ava.isInTestFile,
1212
ava.isInTestNode
1313
])(node => {
14-
1514
const functionArgIndex = node.arguments.length - 1;
1615

17-
if (typeof node.callee.property === 'undefined' || functionArgIndex !== 1 || node.callee.type !== 'MemberExpression' || node.arguments[1].type !== 'Identifier') {
16+
if (typeof node.callee.property === 'undefined' || functionArgIndex !== 1 || node.callee.type !== 'MemberExpression' || node.arguments[1].type !== 'Identifier' || util.getNameOfRootNodeObject(node.callee) !== 't') {
1817
return;
1918
}
2019

2120
const calleeProperty = node.callee.property.name;
2221
const functionArgName = node.arguments[1].name;
2322
if (calleeProperty === 'notThrows' || calleeProperty === 'notThrowsAsync') {
24-
if (functionArgName.endsWith("Error")) {
23+
if (functionArgName.endsWith('Error')) {
2524
context.report({
2625
node,
2726
message: `Do not specify an error constructor in the second argument of \`t.${calleeProperty}()\``

test/no-error-ctor-with-notthrows.js

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import rule from '../rules/no-error-ctor-with-notthrows';
55
const ruleTester = avaRuleTester(test, {
66
env: {
77
es6: true
8+
},
9+
parserOptions: {
10+
ecmaVersion: 2019
811
}
912
});
1013

@@ -81,19 +84,27 @@ ruleTester.run('no-error-ctor-with-notthrows', rule, {
8184
}, {firstName:'some', lastName: 'object'});
8285
});`,
8386

87+
`${header}
88+
test('some test',t => {
89+
notThrows(foo);
90+
});`,
91+
92+
`${header}
93+
test('some test',t => {
94+
myCustomNotThrows.notThrows(foo);
95+
});`,
96+
97+
`${header}
98+
t.notThrows(() => {
99+
t.pass();
100+
}, void 0);`,
101+
84102
// Shouldn't be triggered since it's not a test file
85103
`test('some test',t => {
86104
t.notThrowsAsync(() => {
87105
t.pass();
88106
}, TypeError);
89-
});`,
90-
{
91-
code: `const { notThrows } = require("./my-custom-not-throws")
92-
${header}
93-
test('some test',t => {
94-
notThrows(foo);
95-
});`
96-
},
107+
});`
97108
],
98109
invalid: [
99110
{
@@ -185,6 +196,15 @@ ruleTester.run('no-error-ctor-with-notthrows', rule, {
185196
}, SystemError);
186197
});`,
187198
errors
199+
},
200+
{
201+
code: `${header}
202+
test('some test',t => {
203+
t.notThrowsAsync(() => {
204+
t.pass();
205+
}, $DOMError);
206+
});`,
207+
errors
188208
}
189209
]
190210
});

0 commit comments

Comments
 (0)