Skip to content

Commit de3d766

Browse files
authored
Merge pull request #116 from Xvezda/feature/handle-constructor-exceptions
feature/handle constructor exceptions
2 parents aba98b9 + a39982f commit de3d766

File tree

8 files changed

+58
-2
lines changed

8 files changed

+58
-2
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"license": "MIT",
3838
"packageManager": "[email protected]",
3939
"devDependencies": {
40+
"@typescript/lib-es5": "npm:@types-with-exceptions/[email protected]",
4041
"@types-with-exceptions/node": "22.15.29-dev.0",
4142
"@typescript-eslint/parser": "^8.32.1",
4243
"@typescript-eslint/rule-tester": "^8.32.1",

pnpm-lock.yaml

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/rules/check-throws-tag-type.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -658,8 +658,9 @@ module.exports = createRule({
658658
throwStatementNodes.push(node);
659659
metadata.set(node, { pos: node.range[0] });
660660
},
661-
':function MemberExpression[property.type="Identifier"]': visitFunctionCallNode,
661+
':function NewExpression[callee.type="Identifier"]': visitFunctionCallNode,
662662
':function CallExpression[callee.type="Identifier"]': visitFunctionCallNode,
663+
':function MemberExpression[property.type="Identifier"]': visitFunctionCallNode,
663664
':function AssignmentExpression[left.type="MemberExpression"]': visitFunctionCallNode,
664665

665666
/**

src/rules/no-undocumented-throws.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,7 @@ module.exports = createRule({
540540

541541
throwStatementNodes.push(node);
542542
},
543+
':function NewExpression[callee.type="Identifier"]': visitFunctionCallNode,
543544
':function CallExpression[callee.type="Identifier"]': visitFunctionCallNode,
544545
':function MemberExpression[property.type="Identifier"]': visitFunctionCallNode,
545546
':function AssignmentExpression[left.type="MemberExpression"]': visitFunctionCallNode,

src/utils.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ const getCallSignatureDeclaration = (services, node) => {
281281
*/
282282
const getCallee = (node) => {
283283
switch (node.type) {
284+
case AST_NODE_TYPES.NewExpression:
284285
case AST_NODE_TYPES.CallExpression:
285286
return node.callee;
286287
// Setter
@@ -310,6 +311,7 @@ const getCalleeDeclaration = (services, node) => {
310311
/** @type {import('typescript').Declaration | null} */
311312
let declaration = null;
312313
if (
314+
node.type === AST_NODE_TYPES.NewExpression ||
313315
node.type === AST_NODE_TYPES.CallExpression ||
314316
node.type === AST_NODE_TYPES.MemberExpression &&
315317
node.parent?.type === AST_NODE_TYPES.CallExpression
@@ -390,6 +392,7 @@ const getCalleeDeclaration = (services, node) => {
390392
}
391393
return null;
392394
}
395+
case AST_NODE_TYPES.NewExpression:
393396
case AST_NODE_TYPES.CallExpression:
394397
return declaration;
395398
default:

tests/rules/check-throws-tag-type.test.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -969,6 +969,27 @@ ruleTester.run(
969969
{ messageId: 'throwTypeMismatch' },
970970
],
971971
},
972+
{
973+
code: `
974+
/**
975+
* @param {number} value
976+
* @throws {TypeError}
977+
*/
978+
function foo(value) {
979+
new ArrayBuffer(value);
980+
}
981+
`,
982+
output: `
983+
/**
984+
* @param {number} value
985+
* @throws {RangeError}
986+
*/
987+
function foo(value) {
988+
new ArrayBuffer(value);
989+
}
990+
`,
991+
errors: [{ messageId: 'throwTypeMismatch' }],
992+
},
972993
],
973994
},
974995
);

tests/rules/no-undocumented-throws.test.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2793,6 +2793,26 @@ ruleTester.run(
27932793
`,
27942794
errors: [{ messageId: 'missingThrowsTag' }],
27952795
},
2796+
{
2797+
code: `
2798+
/**
2799+
* @param {number} value
2800+
*/
2801+
function foo(value) {
2802+
new ArrayBuffer(value);
2803+
}
2804+
`,
2805+
output: `
2806+
/**
2807+
* @param {number} value
2808+
* @throws {RangeError}
2809+
*/
2810+
function foo(value) {
2811+
new ArrayBuffer(value);
2812+
}
2813+
`,
2814+
errors: [{ messageId: 'missingThrowsTag' }],
2815+
},
27962816
],
27972817
},
27982818
);

tests/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
/* Language and Environment */
1515
"target": "es2018", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
16-
"lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
16+
"lib": ["es5"], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
1717
// "jsx": "preserve", /* Specify what JSX code is generated. */
1818
"libReplacement": true, /* Enable lib replacement. */
1919
// "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */

0 commit comments

Comments
 (0)