Skip to content

Commit 81f7a63

Browse files
committed
Fix detecting mocha config calls in no-setup-in-describe
1 parent 7cea27f commit 81f7a63

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

.c8rc.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"all": true,
3-
"lines": 98.34,
4-
"statements": 98.34,
3+
"lines": 98.33,
4+
"statements": 98.33,
55
"functions": 99.6,
66
"branches": 94.8,
77
"check-coverage": true,

source/rules/no-setup-in-describe.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,16 @@ ruleTester.run('no-setup-in-describe', noSetupInDescribeRule, {
109109
],
110110

111111
invalid: [
112+
{
113+
code: 'suite("", function () { this.timeout(42); a(); });',
114+
errors: [
115+
{
116+
message: 'Unexpected function call in describe block.',
117+
line: 1,
118+
column: 43
119+
}
120+
]
121+
},
112122
{
113123
code: 'suite("", function () { a(); });',
114124
errors: [

source/rules/no-setup-in-describe.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,10 @@ import { isSuiteConfigCall } from '../mocha/config-call.js';
55

66
const FUNCTION = 1;
77
const DESCRIBE = 2;
8-
const PURE = 3;
98

109
function isNestedInDescribeBlock(nesting: readonly number[]): boolean {
1110
return (
1211
nesting.length > 0 &&
13-
!nesting.includes(PURE) &&
1412
nesting.lastIndexOf(FUNCTION) < nesting.lastIndexOf(DESCRIBE)
1513
);
1614
}
@@ -51,9 +49,7 @@ export const noSetupInDescribeRule: Readonly<Rule.RuleModule> = {
5149
const suiteNodes = new WeakSet();
5250

5351
function handleCallExpressionInDescribe(node: Readonly<CallExpression>): void {
54-
if (isSuiteConfigCall(node)) {
55-
nesting.push(PURE);
56-
} else if (isNestedInDescribeBlock(nesting)) {
52+
if (isNestedInDescribeBlock(nesting) && !isSuiteConfigCall(node)) {
5753
reportCallExpression(context, node);
5854
}
5955
}
@@ -78,7 +74,8 @@ export const noSetupInDescribeRule: Readonly<Rule.RuleModule> = {
7874
nonMochaMemberExpression(node) {
7975
if (
8076
!suiteNodes.has(node.parent) &&
81-
isNestedInDescribeBlock(nesting)
77+
isNestedInDescribeBlock(nesting) &&
78+
!isSuiteConfigCall(node.parent)
8279
) {
8380
reportMemberExpression(context, node);
8481
}

0 commit comments

Comments
 (0)