Skip to content

Commit

Permalink
feedback - I
Browse files Browse the repository at this point in the history
changed name of test
and added more tests
with other requested changes.
  • Loading branch information
rahgurung committed May 5, 2019
1 parent 827ad45 commit 41fafa4
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 39 deletions.
File renamed without changes.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ module.exports = {
'ava/no-statement-after-end': 'error',
'ava/no-todo-implementation': 'error',
'ava/no-todo-test': 'warn',
'ava/no-typeerror-with-notthrows': 'error',
'ava/no-unknown-modifiers': 'error',
'ava/prefer-async-await': 'error',
'ava/prefer-power-assert': 'off',
'ava/prevent-errortype': 'error',
'ava/test-ended': 'error',
'ava/test-title': [
'error',
Expand Down
2 changes: 2 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ Configure it in `package.json`.
"ava/no-statement-after-end": "error",
"ava/no-todo-implementation": "error",
"ava/no-todo-test": "warn",
"ava/no-typeerror-with-notthrows": "error",
"ava/no-unknown-modifiers": "error",
"ava/prefer-async-await": "error",
"ava/prefer-power-assert": "off",
Expand Down Expand Up @@ -90,6 +91,7 @@ The rules will only activate in test files.
- [no-statement-after-end](docs/rules/no-statement-after-end.md) - Ensure `t.end()` is the last statement executed.
- [no-todo-implementation](docs/rules/no-todo-implementation.md) - Ensure `test.todo()` is not given an implementation function.
- [no-todo-test](docs/rules/no-todo-test.md) - Ensure no `test.todo()` is used.
- [no-typeerror-with-notthrows](docs/rules/no-typeerror-with-notthrows.md) - Prevent use of typerror with notthrows.
- [no-unknown-modifiers](docs/rules/no-unknown-modifiers.md) - Prevent the use of unknown test modifiers.
- [prefer-async-await](docs/rules/prefer-async-await.md) - Prefer using async/await instead of returning a Promise.
- [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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const {visitIf} = require('enhance-visitors');
const util = require('../util');
const createAvaRule = require('../create-ava-rule');

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

const create = context => {
const ava = createAvaRule();
Expand All @@ -14,22 +14,21 @@ const create = context => {
ava.isInTestNode
])(node => {
const functionArgIndex = node.arguments.length - 1;
let functionArgName;

if (typeof node.callee.property === 'undefined') {
return;
}

const calleeProperty = node.callee.property.name;

if (functionArgIndex === 1) {
functionArgName = node.arguments[1].name;
} else {
if (functionArgIndex !== 1) {
return;
}

const functionArgName = node.arguments[1].name;

if (calleeProperty === 'notThrows') {
if (nameRegexp.test(functionArgName)) {
if (errorNameRegex.test(functionArgName)) {
context.report({
node,
message: 'Do not specify Error in t.notThrows()'
Expand Down
35 changes: 35 additions & 0 deletions test/no-typeerror-with-notthrows.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import test from 'ava';
import avaRuleTester from 'eslint-ava-rule-tester';
import rule from '../rules/no-typeerror-with-notthrows';

const ruleTester = avaRuleTester(test, {
env: {
es6: true
}
});

const errors = [{ruleId: 'no-typerror-with-notthrows'}];

const header = `const test = require('ava');\n`; // eslint-disable-line quotes

ruleTester.run('no-typeerror-with-notthrows', rule, {
valid: [
`${header} test('some test',t => {t.notThrows(() => {t.pass();});});`,
`${header} test(t => {t.notThrows(() => {t.pass();});});`,
`${header} test(t => {t.throws(() => {t.pass();}, TypeError);});`,
`${header} test(t => {t.end(); })`,
`${header} test('some test',t => {t.notThrows(() => {t.pass();}, true);});`,
`${header} test('some test',t => {t.notThrows(() => {t.pass();}, 'some string');});`,
`${header} test('some test',t => {t.notThrows(() => {t.pass();}, {firstName:'some', lastName: 'object'});});`
],
invalid: [
{
code: `${header} test(t => {t.notThrows(() => {t.pass();}, TypeError);});`,
errors
},
{
code: `${header} test('some test',t => {t.notThrows(() => {t.pass();}, TypeError);});`,
errors
}
]
});
32 changes: 0 additions & 32 deletions test/prevent-errortype.js

This file was deleted.

0 comments on commit 41fafa4

Please sign in to comment.