Skip to content

Commit 41fafa4

Browse files
committed
feedback - I
changed name of test and added more tests with other requested changes.
1 parent 827ad45 commit 41fafa4

File tree

6 files changed

+43
-39
lines changed

6 files changed

+43
-39
lines changed

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ module.exports = {
3636
'ava/no-statement-after-end': 'error',
3737
'ava/no-todo-implementation': 'error',
3838
'ava/no-todo-test': 'warn',
39+
'ava/no-typeerror-with-notthrows': 'error',
3940
'ava/no-unknown-modifiers': 'error',
4041
'ava/prefer-async-await': 'error',
4142
'ava/prefer-power-assert': 'off',
42-
'ava/prevent-errortype': 'error',
4343
'ava/test-ended': 'error',
4444
'ava/test-title': [
4545
'error',

readme.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ Configure it in `package.json`.
5252
"ava/no-statement-after-end": "error",
5353
"ava/no-todo-implementation": "error",
5454
"ava/no-todo-test": "warn",
55+
"ava/no-typeerror-with-notthrows": "error",
5556
"ava/no-unknown-modifiers": "error",
5657
"ava/prefer-async-await": "error",
5758
"ava/prefer-power-assert": "off",
@@ -90,6 +91,7 @@ The rules will only activate in test files.
9091
- [no-statement-after-end](docs/rules/no-statement-after-end.md) - Ensure `t.end()` is the last statement executed.
9192
- [no-todo-implementation](docs/rules/no-todo-implementation.md) - Ensure `test.todo()` is not given an implementation function.
9293
- [no-todo-test](docs/rules/no-todo-test.md) - Ensure no `test.todo()` is used.
94+
- [no-typeerror-with-notthrows](docs/rules/no-typeerror-with-notthrows.md) - Prevent use of typerror with notthrows.
9395
- [no-unknown-modifiers](docs/rules/no-unknown-modifiers.md) - Prevent the use of unknown test modifiers.
9496
- [prefer-async-await](docs/rules/prefer-async-await.md) - Prefer using async/await instead of returning a Promise.
9597
- [prefer-power-assert](docs/rules/prefer-power-assert.md) - Allow only use of the asserts that have no [power-assert](https://github.com/power-assert-js/power-assert) alternative.

rules/prevent-errortype.js renamed to rules/no-typeerror-with-notthrows.js

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

6-
const nameRegexp = /^(?:[A-Z][a-z0-9]*)*Error$/;
6+
const errorNameRegex = /^(?:[A-Z][a-z\d]*)*Error$/;
77

88
const create = context => {
99
const ava = createAvaRule();
@@ -14,22 +14,21 @@ const create = context => {
1414
ava.isInTestNode
1515
])(node => {
1616
const functionArgIndex = node.arguments.length - 1;
17-
let functionArgName;
1817

1918
if (typeof node.callee.property === 'undefined') {
2019
return;
2120
}
2221

2322
const calleeProperty = node.callee.property.name;
2423

25-
if (functionArgIndex === 1) {
26-
functionArgName = node.arguments[1].name;
27-
} else {
24+
if (functionArgIndex !== 1) {
2825
return;
2926
}
3027

28+
const functionArgName = node.arguments[1].name;
29+
3130
if (calleeProperty === 'notThrows') {
32-
if (nameRegexp.test(functionArgName)) {
31+
if (errorNameRegex.test(functionArgName)) {
3332
context.report({
3433
node,
3534
message: 'Do not specify Error in t.notThrows()'

test/no-typeerror-with-notthrows.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import test from 'ava';
2+
import avaRuleTester from 'eslint-ava-rule-tester';
3+
import rule from '../rules/no-typeerror-with-notthrows';
4+
5+
const ruleTester = avaRuleTester(test, {
6+
env: {
7+
es6: true
8+
}
9+
});
10+
11+
const errors = [{ruleId: 'no-typerror-with-notthrows'}];
12+
13+
const header = `const test = require('ava');\n`; // eslint-disable-line quotes
14+
15+
ruleTester.run('no-typeerror-with-notthrows', rule, {
16+
valid: [
17+
`${header} test('some test',t => {t.notThrows(() => {t.pass();});});`,
18+
`${header} test(t => {t.notThrows(() => {t.pass();});});`,
19+
`${header} test(t => {t.throws(() => {t.pass();}, TypeError);});`,
20+
`${header} test(t => {t.end(); })`,
21+
`${header} test('some test',t => {t.notThrows(() => {t.pass();}, true);});`,
22+
`${header} test('some test',t => {t.notThrows(() => {t.pass();}, 'some string');});`,
23+
`${header} test('some test',t => {t.notThrows(() => {t.pass();}, {firstName:'some', lastName: 'object'});});`
24+
],
25+
invalid: [
26+
{
27+
code: `${header} test(t => {t.notThrows(() => {t.pass();}, TypeError);});`,
28+
errors
29+
},
30+
{
31+
code: `${header} test('some test',t => {t.notThrows(() => {t.pass();}, TypeError);});`,
32+
errors
33+
}
34+
]
35+
});

test/prevent-errortype.js

Lines changed: 0 additions & 32 deletions
This file was deleted.

0 commit comments

Comments
 (0)