-
Notifications
You must be signed in to change notification settings - Fork 184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FP S4123 no-invalid-await
on JS file in SonarLint
#2636
Comments
Hi @peterpoliwoda, It seems I rushed to add the ticket to the milestone as I can't reproduce it. Could you share self contained code snippet reproducing FP? |
Hi @vilchik-elena I've updated the code above to reflect the two actual functions in case the code wasn't showing up for you. I updated to show that my underlined code is also wrapped within a try/catch block which might be the reason it's not handled. Please try now. The underlined part is the one with the comment |
I still fail to reproduce, even with |
I found there was a single quote after We are both speaking about the SonarLint VSCode Plugin BTW, right? I've set up a project with a single file where it also gives out here: |
thanks for reproducer! having it on my machine as well, investigating why I can't reproduce the same in unit test |
If it helps, it seems to only happen if the async function is in the same js file as the await. Awaits to imported async functions don't seem to throw the warning. |
Here is another example, no dependencies, only 8 lines: interface MyQuery<T> extends Pick<Promise<T>, keyof Promise<T>> {
toQuery(): string;
}
export async function demo(query: MyQuery<string>) {
const result = await query;
console.log(result);
} This is effectively what Knex is doing, which is a pretty popular SQL builder: interface ChainableInterface<T = any> extends Pick<Promise<T>, keyof Promise<T> & ExposedPromiseKeys>, StringTagSupport {
generateDdlCommands(): Promise<{ pre: string[], sql: string[], post: string[] }>;
toQuery(): string; |
It seems related to the way we do analysis of JavaScript files using TypeScript compiler. Hope to fix it soon @codyebberson Yet it seems that you have another problem, clearly you are using TypeScript itself and with some type |
Finally found the root problem, we are missing type information because in SonarLint context we are not able to generate tsconfig file ( Lines 141 to 145 in 1b593bd
We want to do a major rework so that this generated tsconfig file would not be required but until that we can provide a simple fix to not report if type of awaited argument is unknown. |
Wow, that's completely unrelated then hah. Of course that was the cause, what else haha. Thank you for looking into that Elena 🐺 ! |
no-invalid-await
on JS file in SonarLint
Same issue here, is there something we have to update in VSCode to make this fix active? |
@tr3ysmith yeah. If you are not using connected mode, then update SonarLint plugin |
@vilchik-elena We are using SonarQube Enterprise v8.9.0 and still this issue shows up on our dashboard as a Code Smell. Can you let me know with which version of SonarQube this false positive is not detected? Thanks. |
@kamesh95 you should update to latest SQ (9.2 as of now) |
This issue is a pain for our JavaScript project. Basically, any async function call always returns a Promise--even if the code does not indicate it. I have to turn this rule off because its implementation is naive and results in thousands of false positives... |
Would it be possible to get this backported into an LTS release? I'm seeing it actively cause the introduction of runtime-crash-causing bugs in code. |
Which version of SQ resolves this issue? Currently, I installed 9.6.1 version |
We still see it even in "Version 9.9.4 (build 87374)". Is there any update on this ? |
Reflecting on a forum issue spoken about here:
https://community.sonarsource.com/t/refactor-this-redundant-await-on-a-non-promise-is-not-correct/28800
My VSCode extension wrongly tells me that I don't need to await for a non-promise. Problem is, my function is an async function and by all means does return a promise as per ES6 standards.
This rule is causing some stir in my code and has caused some bugs. Please add support for async functions in JavaScript as this is a bug in linting at the moment.
The text was updated successfully, but these errors were encountered: