Skip to content

Commit

Permalink
chore(no-test-return-statement): convert to typescript (#320)
Browse files Browse the repository at this point in the history
  • Loading branch information
G-Rath authored and SimenB committed Jul 20, 2019
1 parent cb021e7 commit e878665
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
@@ -1,7 +1,9 @@
import { RuleTester } from 'eslint';
import { TSESLint } from '@typescript-eslint/experimental-utils';
import rule from '../no-test-return-statement';

const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 2015 } });
const ruleTester = new TSESLint.RuleTester({
parserOptions: { ecmaVersion: 2015 },
});

ruleTester.run('no-test-prefixes', rule, {
valid: [
Expand Down
@@ -1,29 +1,38 @@
import { getDocsUrl, isFunction, isTestCase } from './util';
import { createRule, isFunction, isTestCase } from './tsUtils';
import { TSESTree } from '@typescript-eslint/experimental-utils';

const RETURN_STATEMENT = 'ReturnStatement';
const BLOCK_STATEMENT = 'BlockStatement';

const getBody = args => {
const getBody = (args: TSESTree.Expression[]) => {
const [, secondArg] = args;

if (
args.length > 1 &&
isFunction(args[1]) &&
args[1].body.type === BLOCK_STATEMENT
secondArg &&
isFunction(secondArg) &&
secondArg.body &&
secondArg.body.type === BLOCK_STATEMENT
) {
return args[1].body.body;
return secondArg.body.body;
}
return [];
};

export default {
export default createRule({
name: __filename,
meta: {
docs: {
url: getDocsUrl(__filename),
category: 'Best Practices',
description: 'Disallow explicitly returning from tests',
recommended: false,
},
messages: {
noReturnValue: 'Jest tests should not return a value.',
},
schema: [],
type: 'suggestion',
},
defaultOptions: [],
create(context) {
return {
CallExpression(node) {
Expand All @@ -36,4 +45,4 @@ export default {
},
};
},
};
});

0 comments on commit e878665

Please sign in to comment.