Skip to content

Commit

Permalink
Rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
rahgurung authored and GMartigny committed Mar 24, 2021
1 parent fcdb7e1 commit 1ec54fe
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 12 deletions.
1 change: 0 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ module.exports = {
'ava/prefer-async-await': 'error',
'ava/prefer-power-assert': 'off',
'ava/prefer-t-regex': 'error',
'ava/prevent-errortype': 'error',
'ava/test-ended': 'error',
'ava/test-title': 'error',
'ava/test-title-format': 'off',
Expand Down
5 changes: 2 additions & 3 deletions rules/no-error-ctor-with-notthrows.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,16 @@ const create = context => {
ava.isInTestFile,
ava.isInTestNode
])(node => {

const functionArgIndex = node.arguments.length - 1;

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

const calleeProperty = node.callee.property.name;
const functionArgName = node.arguments[1].name;
if (calleeProperty === 'notThrows' || calleeProperty === 'notThrowsAsync') {
if (functionArgName.endsWith("Error")) {
if (functionArgName.endsWith('Error')) {
context.report({
node,
message: `Do not specify an error constructor in the second argument of \`t.${calleeProperty}()\``
Expand Down
36 changes: 28 additions & 8 deletions test/no-error-ctor-with-notthrows.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import rule from '../rules/no-error-ctor-with-notthrows';
const ruleTester = avaRuleTester(test, {
env: {
es6: true
},
parserOptions: {
ecmaVersion: 2019
}
});

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

`${header}
test('some test',t => {
notThrows(foo);
});`,

`${header}
test('some test',t => {
myCustomNotThrows.notThrows(foo);
});`,

`${header}
t.notThrows(() => {
t.pass();
}, void 0);`,

// Shouldn't be triggered since it's not a test file
`test('some test',t => {
t.notThrowsAsync(() => {
t.pass();
}, TypeError);
});`,
{
code: `const { notThrows } = require("./my-custom-not-throws")
${header}
test('some test',t => {
notThrows(foo);
});`
},
});`
],
invalid: [
{
Expand Down Expand Up @@ -185,6 +196,15 @@ ruleTester.run('no-error-ctor-with-notthrows', rule, {
}, SystemError);
});`,
errors
},
{
code: `${header}
test('some test',t => {
t.notThrowsAsync(() => {
t.pass();
}, $DOMError);
});`,
errors
}
]
});

0 comments on commit 1ec54fe

Please sign in to comment.