Skip to content

Commit 71c5299

Browse files
authored
fix(valid-describe): report on concise-body arrow functions (#863)
1 parent 38f8436 commit 71c5299

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

docs/rules/valid-describe.md

+6
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ describe('myFunction', () => {
4343
});
4444
});
4545
});
46+
47+
// Returning a value from a describe block is not allowed
48+
describe('myFunction', () =>
49+
it('returns a truthy value', () => {
50+
expect(myFunction()).toBeTruthy();
51+
}));
4652
```
4753

4854
The following patterns are not considered warnings:

src/rules/__tests__/valid-describe.test.ts

+10-5
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,6 @@ ruleTester.run('valid-describe', rule, {
3636
})
3737
})
3838
`,
39-
dedent`
40-
describe('foo', () =>
41-
test('bar', () => {})
42-
)
43-
`,
4439
dedent`
4540
if (hasOwnProperty(obj, key)) {
4641
}
@@ -196,6 +191,16 @@ ruleTester.run('valid-describe', rule, {
196191
{ messageId: 'unexpectedReturnInDescribe', line: 5, column: 5 },
197192
],
198193
},
194+
{
195+
code: dedent`
196+
describe('foo', () =>
197+
test('bar', () => {})
198+
)
199+
`,
200+
errors: [
201+
{ messageId: 'unexpectedReturnInDescribe', line: 1, column: 17 },
202+
],
203+
},
199204
{
200205
code: 'describe("foo", done => {})',
201206
errors: [

src/rules/valid-describe.ts

+7
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,13 @@ export default createRule({
8484
});
8585
}
8686

87+
if (callback.body.type === AST_NODE_TYPES.CallExpression) {
88+
context.report({
89+
messageId: 'unexpectedReturnInDescribe',
90+
node: callback,
91+
});
92+
}
93+
8794
if (callback.body.type === AST_NODE_TYPES.BlockStatement) {
8895
callback.body.body.forEach(node => {
8996
if (node.type === AST_NODE_TYPES.ReturnStatement) {

0 commit comments

Comments
 (0)