Skip to content

Commit af53103

Browse files
G-RathSimenB
authored andcommitted
chore(no-test-return-statement): convert to typescript (#320)
1 parent c213f26 commit af53103

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

src/rules/__tests__/no-test-return-statement.test.js renamed to src/rules/__tests__/no-test-return-statement.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
import { RuleTester } from 'eslint';
1+
import { TSESLint } from '@typescript-eslint/experimental-utils';
22
import rule from '../no-test-return-statement';
33

4-
const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 2015 } });
4+
const ruleTester = new TSESLint.RuleTester({
5+
parserOptions: { ecmaVersion: 2015 },
6+
});
57

68
ruleTester.run('no-test-prefixes', rule, {
79
valid: [
Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,38 @@
1-
import { getDocsUrl, isFunction, isTestCase } from './util';
1+
import { createRule, isFunction, isTestCase } from './tsUtils';
2+
import { TSESTree } from '@typescript-eslint/experimental-utils';
23

34
const RETURN_STATEMENT = 'ReturnStatement';
45
const BLOCK_STATEMENT = 'BlockStatement';
56

6-
const getBody = args => {
7+
const getBody = (args: TSESTree.Expression[]) => {
8+
const [, secondArg] = args;
9+
710
if (
8-
args.length > 1 &&
9-
isFunction(args[1]) &&
10-
args[1].body.type === BLOCK_STATEMENT
11+
secondArg &&
12+
isFunction(secondArg) &&
13+
secondArg.body &&
14+
secondArg.body.type === BLOCK_STATEMENT
1115
) {
12-
return args[1].body.body;
16+
return secondArg.body.body;
1317
}
1418
return [];
1519
};
1620

17-
export default {
21+
export default createRule({
22+
name: __filename,
1823
meta: {
1924
docs: {
20-
url: getDocsUrl(__filename),
25+
category: 'Best Practices',
26+
description: 'Disallow explicitly returning from tests',
27+
recommended: false,
2128
},
2229
messages: {
2330
noReturnValue: 'Jest tests should not return a value.',
2431
},
2532
schema: [],
33+
type: 'suggestion',
2634
},
35+
defaultOptions: [],
2736
create(context) {
2837
return {
2938
CallExpression(node) {
@@ -36,4 +45,4 @@ export default {
3645
},
3746
};
3847
},
39-
};
48+
});

0 commit comments

Comments
 (0)