sublimelsp / LSP-SonarLint

Linting from SonarSource

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Setting doesn't get passed to sonar

martijndeb opened this issue · comments

Hi, I have no clue how to check this properly. But in order to get a proper ruleset we have a given ruleset.
In the sonarlint settings it should be defined as followed; However some disabled rules still trigger. The projectKey is valid.

// Settings in here override those in "LSP-SonarLint/LSP-SonarLint.sublime-settings"
{
    "settings": {
    "sonarlint.connectedMode.connections.sonarqube":[
        {
            "serverUrl": "*snip*",
            "token": "*snip*"
        }
    ],
    "sonarlint.connectedMode.project": {
        "projectKey": "ISO-27001-LINT-DEFAULT"
    },
    "sonarlint.output.showAnalyzerLogs": true,
    "sonarlint.output.showVerboseLogs": true
	}
}

The projectKey as defined in Sonar;
image

A superset of the settings that the server understands is listed here: https://github.com/SonarSource/sonarlint-vscode/blob/master/package.json

Some settings are handled client-side. I don't know which ones, you would have to dig into the code of sonarlint-ascode for that.

Well I can say that the projectkey is submitted on vscode. But I'll go take a look around how to get this working. Thanks for your time (also on the other issues)

I found out that the lint plugin isn't getting to the connectmode at all. I don't see connections in the LSP debug panel;

SonarLint: Starting standalone SonarLint engine...
SonarLint: Using 5 analyzers
SonarLint: Create : C:\Users\<snip>\.sonarlint\plugins
SonarLint: Plugin cache: C:\Users\<snip>\.sonarlint\plugins
SonarLint: Create : C:\Users\<snip>\.sonarlint\plugins\_tmp
SonarLint: Load plugins
SonarLint: Load plugins (done) | time=15ms
SonarLint: Plugins:
SonarLint:   * PHP Code Quality and Security 3.9.0.6331 (php)
SonarLint:   * Python Code Quality and Security 3.9.0.9230 (python)
SonarLint:   * HTML Code Quality and Security 3.6.0.3106 (web)
SonarLint: Error while trying to inject SonarLintPythonIndexer
SonarLint: Error while trying to inject SonarLintPythonIndexer
SonarLint: Standalone SonarLint engine started
SonarLint: Error while trying to inject SonarLintPythonIndexer
SonarLint: Available languages:
SonarLint:   * PHP => "php"
SonarLint:   * Python => "py"
SonarLint:   * HTML => "web"
SonarLint:   * JSP => "jsp"
SonarLint: Start analysis
SonarLint: Declared extensions of language PHP were converted to php: **/*.php,**/*.php3,**/*.php4,**/*.php5,**/*.phtml,**/*.inc
SonarLint: Declared extensions of language Python were converted to py: **/*.py
SonarLint: Declared extensions of language HTML were converted to web: **/*.html,**/*.xhtml,**/*.cshtml,**/*.vbhtml,**/*.aspx,**/*.ascx,**/*.rhtml,**/*.erb,**/*.shtm,**/*.shtml,**/*.cmp,**/*.twig
SonarLint: Declared extensions of language JSP were converted to jsp: **/*.jsp,**/*.jspf,**/*.jspx
SonarLint: Index files
SonarLint: Language of file 'file:///C:/projects/<snip>/public_html/apps/<snip>/src/activities/graphql/<snip>.class.php' is set to 'php'
SonarLint: 1 file indexed
SonarLint: Execute Sensor: PHP sensor
SonarLint: Starting PHP symbol indexer
SonarLint: 1 source files to be analyzed
SonarLint: 1/1 source files have been analyzed
SonarLint: No workDir in SonarLint
SonarLint: Starting PHP rules
SonarLint: 1 source files to be analyzed
SonarLint: Initializing metadata of file file:///C:/projects/<snip>/public_html/apps/<snip>/src/activities/graphql/<snip>.class.php
SonarLint: 1/1 source files have been analyzed
SonarLint: Execute Sensor: Analyzer for "php.ini" files
SonarLint: 'Python Sensor' skipped because there is no related file in current project
SonarLint: Execute Sensor: HTML
SonarLint: Analysis triggered on file:///C:/projects/<snip>/public_html/apps/<snip>/src/activities/shopapi/<snip>.class.php with configuration: 
[
  baseDir: C:\projects\<snip>\public_html
  extraProperties: {}
  excludedRules: []
  includedRules: []
  inputFiles: [
    file:///C:/projects/<snip>/public_html/apps/<snip>/src/activities/shopapi/<snip>.class.php (UTF-8) [php]
  ]
]

SonarLint: Error while trying to inject SonarLintPythonIndexer
SonarLint: Available languages:
SonarLint:   * PHP => "php"
SonarLint:   * Python => "py"
SonarLint:   * HTML => "web"
SonarLint:   * JSP => "jsp"
SonarLint: Start analysis
SonarLint: Declared extensions of language PHP were converted to php: **/*.php,**/*.php3,**/*.php4,**/*.php5,**/*.phtml,**/*.inc
SonarLint: Declared extensions of language Python were converted to py: **/*.py
SonarLint: Declared extensions of language HTML were converted to web: **/*.html,**/*.xhtml,**/*.cshtml,**/*.vbhtml,**/*.aspx,**/*.ascx,**/*.rhtml,**/*.erb,**/*.shtm,**/*.shtml,**/*.cmp,**/*.twig
SonarLint: Declared extensions of language JSP were converted to jsp: **/*.jsp,**/*.jspf,**/*.jspx
SonarLint: Index files
SonarLint: Language of file 'file:///C:/projects/<snip>/public_html/apps/<snip>/src/activities/shopapi/<snip>.class.php' is set to 'php'
SonarLint: 1 file indexed
SonarLint: Execute Sensor: PHP sensor
SonarLint: Starting PHP symbol indexer
SonarLint: 1 source files to be analyzed
SonarLint: No workDir in SonarLint
SonarLint: 1/1 source files have been analyzed
SonarLint: Starting PHP rules
SonarLint: 1 source files to be analyzed
SonarLint: Initializing metadata of file file:///C:/projects/<snip>/public_html/apps/<snip>/src/activities/shopapi/<snip>.class.php
SonarLint: Execute Sensor: Analyzer for "php.ini" files
SonarLint: 1/1 source files have been analyzed
SonarLint: 'Python Sensor' skipped because there is no related file in current project
SonarLint: Execute Sensor: HTML

Okay, so sorry for spamming :-) I think I've found the reason it's not working.
Upon reloading I get a connection error. I assume this is why it never connects.
Going to see how to debug this to provide the headers (or lack thereof) as replied by our server.

reloading settings Packages/User/LSP-SonarLint.sublime-settings
Unexpected exception
Unexpected exception
Traceback (most recent call last):
  File "C:\Users\<snip>\AppData\Roaming\Sublime Text\Installed Packages\LSP.sublime-package\plugin/core/transports.py", line 140, in _read_loop
    payload = self._processor.read_data(self._reader)
  File "C:\Users\<snip>\AppData\Roaming\Sublime Text\Installed Packages\LSP.sublime-package\plugin/core/transports.py", line 65, in read_data
    headers = http.client.parse_headers(reader)  # type: ignore
  File "./python3.3/http/client.py", line 262, in parse_headers
  File "./python3.3/socket.py", line 297, in readinto
ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote host

@martijndeb - it never gets passed, because there is no code handling it in the SonarLint plugin.
I mean, I cannot see anything even remotely handling user settings in the plugin file at https://github.com/sublimelsp/LSP-SonarLint/blob/master/plugin.py

So, I would suspect, if it has no code to handle it, it also cannot really do much. It seems to me very unfinished.
You can also confirm that it does not even read these settings by simply deleting them. It will still "work" - with whatever default SonarCloud rules it likes - but not with yours.

Can't speak for this particular issue but everything within the settings object is handled by the LSP client (ST package) itself since it's part of the LSP spec.

Got it... then that is what does not even attempt to connect.
Checking the logs you will see it never even attempts to connect to the SonarCloud, not to mention that the token in Sonar Cloud will show never as usage stat :( - and even not setting any cloud settings in the LSP settings does not "break" the little that works in the linter, so it is clearly never used.
(I also notice that it does not seem to follow the same syntax as the LSP main package, but I am really not knowledgeable on that area)