Reputation: 131
I have a JavaScript project that consists of several source files. These files are referenced in <script>
tags in index.html
page. There are functions and variables defined in those source files and used in other source files. The problem is that Sonar treats those files as independent and I got
Non-existent variables should not be referenced (javascript:S3827)
issue. Can anybody help how to avoid this?
Thanks
Pavel
Upvotes: 2
Views: 1934
Reputation: 149
For anyone also landing here looking to avoid warnings from globals in vscode's SonarQube plugin locally, you need to add a comma separated string with all your globals in your user/workspace settings like so:
{
"sonarlint.analyzerProperties": {
"sonar.javascript.globals": "__ctx,clock,_DEBUG"
}
}
The file can be easily accessed through vscode's command palette: (Ctrl+Shift+P), Preferences: Open Workspace Settings (JSON), Enter.
Upvotes: 0
Reputation: 177
If your variable is a global variable, you can choose to invoke the variable from the window object like window.variable
. Sonarqube will no longer flag that variable as undefined.
Upvotes: 1
Reputation: 1090
This rule requires configuration. List names of variables and functions shared across files in "sonar.javascript.globals" project property.
Upvotes: 4