Skip to content

Commit

Permalink
Add test to confirm that S4123 honors JSDoc directive
Browse files Browse the repository at this point in the history
  • Loading branch information
ericmorand-sonarsource committed Jan 30, 2024
1 parent be59341 commit bff7454
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion packages/jsts/src/rules/S4123/unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*/
import { rule } from './';
import { RuleTester } from 'eslint';
import { TypeScriptRuleTester } from '../tools';
import { JavaScriptRuleTester, TypeScriptRuleTester } from '../tools';

const ruleTester = new TypeScriptRuleTester();
ruleTester.run('await should only be used with promises.', rule, {
Expand Down Expand Up @@ -231,3 +231,40 @@ ruleTesterWithNoFullTypeInfo.run('await should only be used with promises.', rul
],
invalid: [],
});

const javaScriptRuleTester = new JavaScriptRuleTester();
javaScriptRuleTester.run(
'await should only be used with promises: honors JSDoc @return directive.',
rule,
{
valid: [
{
code: `
async function foo () {
await bar()
}
/**
* @return {Promise<number>}
*/
async function bar () {
return 5;
}`,
},
],
invalid: [
{
code: `
async function foo () {
await bar() // FP
}
/**
* @return {number}
*/
async function bar () {
return Promise.resolve(5);
}`,
errors: 1,
},
],
},
);

0 comments on commit bff7454

Please sign in to comment.