Skip to content

Commit 7c239bd

Browse files
JS-1995 reject wrapped block try bodies
1 parent 9008a7c commit 7c239bd

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

packages/analysis/src/jsts/rules/S2486/cb.fixture.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,17 @@ function switchBody() {
108108
}
109109
}
110110

111+
function blockBody() {
112+
try {
113+
{
114+
doSomething();
115+
doSomethingElse();
116+
}
117+
} catch (err) { // Noncompliant {{Handle this exception or don't catch it at all.}}
118+
119+
}
120+
}
121+
111122
function labeledLoopBody() {
112123
try {
113124
outer: for (const x of xs) {

packages/analysis/src/jsts/rules/S2486/rule.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ import { generateMeta } from '../helpers/generate-meta.js';
2323
import { getVariableFromScope } from '../helpers/ast.js';
2424
import * as meta from './generated-meta.js';
2525

26-
const LOOP_OR_SWITCH_TYPES = new Set([
26+
const NON_SIMPLE_STATEMENT_TYPES = new Set([
27+
'BlockStatement',
2728
'ForStatement',
2829
'ForInStatement',
2930
'ForOfStatement',
@@ -40,7 +41,7 @@ function isSingleSimpleStatement(body: estree.Statement[]): boolean {
4041
while (stmt.type === 'LabeledStatement') {
4142
stmt = (stmt as estree.LabeledStatement).body;
4243
}
43-
return !LOOP_OR_SWITCH_TYPES.has(stmt.type);
44+
return !NON_SIMPLE_STATEMENT_TYPES.has(stmt.type);
4445
}
4546

4647
export const rule: Rule.RuleModule = {

0 commit comments

Comments
 (0)