Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
172 changes: 172 additions & 0 deletions tests/rules/check-throws-tag-type.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1742,6 +1742,178 @@ ruleTester.run(
{ messageId: 'throwTypeMismatch' },
],
},
{
code: `
class TrueGetterError extends Error {}

Copilot AI Jun 23, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] This block duplicates the same class definitions and foo function from another test; refactoring into a shared helper would make the tests easier to maintain.

Copilot uses AI. Check for mistakes.
class TrueSetterError extends Error {}
class FalseGetterError extends Error {}
class FalseSetterError extends Error {}

function foo() {
if (Math.random() > 0.5) {
return {
flag: true,
/**
* @throws {TrueGetterError}
*/
get value() {
throw new TrueGetterError();
},
/**
* @throws {TrueSetterError}
*/
set value(v: any) {
throw new TrueSetterError();
},
} as const;
} else {
return {
flag: false,
/**
* @throws {FalseGetterError}
*/
get value() {
throw new FalseGetterError();
},
/**
* @throws {FalseSetterError}
*/
set value(v: any) {
throw new FalseSetterError();
},
} as const;
}
}

/**
* @throws {TrueGetterError}
*/
function bar() {
const result = foo();
if (!result.flag) {
result.value;
}
}

/**
* @throws {FalseGetterError}
*/
function baz() {
const result = foo();
if (result.flag) {
result.value;
}
}

/**
* @throws {TrueSetterError}
*/
function qux() {
const result = foo();
if (!result.flag) {
result.value = 42;
}
}

/**
* @throws {FalseSetterError}
*/
function quux() {
const result = foo();
if (result.flag) {
result.value = 42;
}
}
`,
output: `
class TrueGetterError extends Error {}
class TrueSetterError extends Error {}
class FalseGetterError extends Error {}
class FalseSetterError extends Error {}

function foo() {
if (Math.random() > 0.5) {
return {
flag: true,
/**
* @throws {TrueGetterError}
*/
get value() {
throw new TrueGetterError();
},
/**
* @throws {TrueSetterError}
*/
set value(v: any) {
throw new TrueSetterError();
},
} as const;
} else {
return {
flag: false,
/**
* @throws {FalseGetterError}
*/
get value() {
throw new FalseGetterError();
},
/**
* @throws {FalseSetterError}
*/
set value(v: any) {
throw new FalseSetterError();
},
} as const;
}
}

/**
* @throws {FalseGetterError}
*/
function bar() {
const result = foo();
if (!result.flag) {
result.value;
}
}

/**
* @throws {TrueGetterError}
*/
function baz() {
const result = foo();
if (result.flag) {
result.value;
}
}

/**
* @throws {FalseSetterError}
*/
function qux() {
const result = foo();
if (!result.flag) {
result.value = 42;
}
}

/**
* @throws {TrueSetterError}
*/
function quux() {
const result = foo();
if (result.flag) {
result.value = 42;
}
}
`,
errors: [
{ messageId: 'throwTypeMismatch' },
{ messageId: 'throwTypeMismatch' },
{ messageId: 'throwTypeMismatch' },
{ messageId: 'throwTypeMismatch' },
],
},
],
},
);
Expand Down
160 changes: 160 additions & 0 deletions tests/rules/no-undocumented-throws.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4023,6 +4023,166 @@ ruleTester.run(
{ messageId: 'missingThrowsTag' },
],
},
{
code: `
class TrueGetterError extends Error {}

Copilot AI Jun 23, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The error class and foo setup are duplicated in multiple test files; consider extracting shared fixtures or helper functions to reduce repetition and improve maintainability.

Copilot uses AI. Check for mistakes.
class TrueSetterError extends Error {}
class FalseGetterError extends Error {}
class FalseSetterError extends Error {}

function foo() {
if (Math.random() > 0.5) {
return {
flag: true,
/**
* @throws {TrueGetterError}
*/
get value() {
throw new TrueGetterError();
},
/**
* @throws {TrueSetterError}
*/
set value(v: any) {
throw new TrueSetterError();
},
} as const;
} else {
return {
flag: false,
/**
* @throws {FalseGetterError}
*/
get value() {
throw new FalseGetterError();
},
/**
* @throws {FalseSetterError}
*/
set value(v: any) {
throw new FalseSetterError();
},
} as const;
}
}

function bar() {
const result = foo();
if (!result.flag) {
result.value;
}
}

function baz() {
const result = foo();
if (result.flag) {
result.value;
}
}

function qux() {
const result = foo();
if (!result.flag) {
result.value = 42;
}
}

function quux() {
const result = foo();
if (result.flag) {
result.value = 42;
}
}
`,
output: `
class TrueGetterError extends Error {}
class TrueSetterError extends Error {}
class FalseGetterError extends Error {}
class FalseSetterError extends Error {}

function foo() {
if (Math.random() > 0.5) {
return {
flag: true,
/**
* @throws {TrueGetterError}
*/
get value() {
throw new TrueGetterError();
},
/**
* @throws {TrueSetterError}
*/
set value(v: any) {
throw new TrueSetterError();
},
} as const;
} else {
return {
flag: false,
/**
* @throws {FalseGetterError}
*/
get value() {
throw new FalseGetterError();
},
/**
* @throws {FalseSetterError}
*/
set value(v: any) {
throw new FalseSetterError();
},
} as const;
}
}

/**
* @throws {FalseGetterError}
*/
function bar() {
const result = foo();
if (!result.flag) {
result.value;
}
}

/**
* @throws {TrueGetterError}
*/
function baz() {
const result = foo();
if (result.flag) {
result.value;
}
}

/**
* @throws {FalseSetterError}
*/
function qux() {
const result = foo();
if (!result.flag) {
result.value = 42;
}
}

/**
* @throws {TrueSetterError}
*/
function quux() {
const result = foo();
if (result.flag) {
result.value = 42;
}
}
`,
errors: [
{ messageId: 'missingThrowsTag' },
{ messageId: 'missingThrowsTag' },
{ messageId: 'missingThrowsTag' },
{ messageId: 'missingThrowsTag' },
],
},
{
code: `
const foo = {
Expand Down