Skip to content

Commit 5ca8c52

Browse files
authored
feat: correct stack tracking in max-nested-callbacks (#20973)
1 parent b565783 commit 5ca8c52

2 files changed

Lines changed: 33 additions & 2 deletions

File tree

‎lib/rules/max-nested-callbacks.js‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,14 @@ module.exports = {
109109

110110
/**
111111
* Pops the call stack.
112+
* @param {ASTNode} node The node to check.
112113
* @returns {void}
113114
* @private
114115
*/
115-
function popStack() {
116-
callbackStack.pop();
116+
function popStack(node) {
117+
if (callbackStack.at(-1) === node) {
118+
callbackStack.pop();
119+
}
117120
}
118121

119122
//--------------------------------------------------------------------------

‎tests/lib/rules/max-nested-callbacks.js‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,34 @@ ruleTester.run("max-nested-callbacks", rule, {
8080
},
8181
],
8282
},
83+
{
84+
code: "foo(function() { const helper = function() {}; bar(function() { baz(function() {}); }); });",
85+
options: [2],
86+
errors: [
87+
{
88+
messageId: "exceed",
89+
data: { num: 3, max: 2 },
90+
line: 1,
91+
column: 69,
92+
endLine: 1,
93+
endColumn: 77,
94+
},
95+
],
96+
},
97+
{
98+
code: "foo(function() { const helper = () => {}; bar(function() { baz(function() {}); }); });",
99+
options: [2],
100+
errors: [
101+
{
102+
messageId: "exceed",
103+
data: { num: 3, max: 2 },
104+
line: 1,
105+
column: 64,
106+
endLine: 1,
107+
endColumn: 72,
108+
},
109+
],
110+
},
83111
{
84112
code: "foo(function() { bar(thing, (data) => { baz(function() {}); }); });",
85113
options: [2],

0 commit comments

Comments
 (0)