File tree Expand file tree Collapse file tree 2 files changed +22
-11
lines changed Expand file tree Collapse file tree 2 files changed +22
-11
lines changed Original file line number Diff line number Diff line change 1- import { RuleTester } from 'eslint' ;
1+ import { TSESLint } from '@typescript- eslint/experimental-utils ' ;
22import 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
68ruleTester . run ( 'no-test-prefixes' , rule , {
79 valid : [
Original file line number Diff line number Diff line change 1- import { getDocsUrl , isFunction , isTestCase } from './util' ;
1+ import { createRule , isFunction , isTestCase } from './tsUtils' ;
2+ import { TSESTree } from '@typescript-eslint/experimental-utils' ;
23
34const RETURN_STATEMENT = 'ReturnStatement' ;
45const 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+ } ) ;
You can’t perform that action at this time.
0 commit comments