Skip to content

Commit 4fabdd6

Browse files
committed
fix(require-returns-check): allow for missing catch or finalizer and missing case contents; fixes #924
1 parent c1f21f8 commit 4fabdd6

File tree

3 files changed

+83
-3
lines changed

3 files changed

+83
-3
lines changed

README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18094,6 +18094,42 @@ function foo() {
1809418094
return "baz";
1809518095
}
1809618096
};
18097+
18098+
/**
18099+
* Return a V1 style query identifier.
18100+
*
18101+
* @param {string} id - The query identifier.
18102+
* @returns {string} V1 style query identifier.
18103+
*/
18104+
function v1QueryId(id) {
18105+
switch (id) {
18106+
case 'addq':
18107+
case 'aliq':
18108+
case 'locq':
18109+
return id.substring(3);
18110+
case 'lost':
18111+
return id.substring(4);
18112+
default:
18113+
return id;
18114+
}
18115+
}
18116+
18117+
/**
18118+
* Parses the required header fields for the given SIP message.
18119+
*
18120+
* @param {string} logPrefix - The log prefix.
18121+
* @param {string} sipMessage - The SIP message.
18122+
* @param {string[]} headers - The header fields to be parsed.
18123+
* @returns {object} Object with parsed header fields.
18124+
*/
18125+
function parseSipHeaders(logPrefix, sipMessage, headers) {
18126+
try {
18127+
return esappSip.parseHeaders(sipMessage, headers);
18128+
} catch (err) {
18129+
logger.error(logPrefix, 'Failed to parse');
18130+
return {};
18131+
}
18132+
}
1809718133
````
1809818134

1809918135

src/utils/hasReturnValue.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,15 +163,17 @@ const allBrancheshaveReturnValues = (node, promFilter) => {
163163

164164
case 'TryStatement': {
165165
return allBrancheshaveReturnValues(node.block, promFilter) &&
166-
allBrancheshaveReturnValues(node.handler && node.handler.body, promFilter) &&
167-
allBrancheshaveReturnValues(node.finalizer, promFilter);
166+
(!node.handler ||
167+
allBrancheshaveReturnValues(node.handler && node.handler.body, promFilter)) &&
168+
(!node.finalizer ||
169+
allBrancheshaveReturnValues(node.finalizer, promFilter));
168170
}
169171

170172
case 'SwitchStatement': {
171173
return node.cases.every(
172174
(someCase) => {
173175
const nde = someCase.consequent.slice(-1)[0];
174-
return allBrancheshaveReturnValues(nde, promFilter);
176+
return !nde || allBrancheshaveReturnValues(nde, promFilter);
175177
},
176178
);
177179
}

test/rules/assertions/requireReturnsCheck.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1375,5 +1375,47 @@ export default {
13751375
};
13761376
`,
13771377
},
1378+
{
1379+
code: `
1380+
/**
1381+
* Return a V1 style query identifier.
1382+
*
1383+
* @param {string} id - The query identifier.
1384+
* @returns {string} V1 style query identifier.
1385+
*/
1386+
function v1QueryId(id) {
1387+
switch (id) {
1388+
case 'addq':
1389+
case 'aliq':
1390+
case 'locq':
1391+
return id.substring(3);
1392+
case 'lost':
1393+
return id.substring(4);
1394+
default:
1395+
return id;
1396+
}
1397+
}
1398+
`,
1399+
},
1400+
{
1401+
code: `
1402+
/**
1403+
* Parses the required header fields for the given SIP message.
1404+
*
1405+
* @param {string} logPrefix - The log prefix.
1406+
* @param {string} sipMessage - The SIP message.
1407+
* @param {string[]} headers - The header fields to be parsed.
1408+
* @returns {object} Object with parsed header fields.
1409+
*/
1410+
function parseSipHeaders(logPrefix, sipMessage, headers) {
1411+
try {
1412+
return esappSip.parseHeaders(sipMessage, headers);
1413+
} catch (err) {
1414+
logger.error(logPrefix, 'Failed to parse');
1415+
return {};
1416+
}
1417+
}
1418+
`,
1419+
},
13781420
],
13791421
};

0 commit comments

Comments
 (0)