0

我尝试在 Windows 上为Visual Studio Code设置SonarLint 扩展,并按照说明使用连接模式。我想我已经正确设置了它,因为在 SonarLint 输出日志中,显示了大约 200 个用于连接到我的组织服务器的状态代码(仅供参考,我在下面的日志中更改了 URL):

Connected SonarLint engine started for example-project
GET 200 http://example.com/sonar/api/qualityprofiles/search.protobuf?projectKey=example-project | time=152ms
GET 200 http://example.com/sonar/api/properties?format=json&resource=example-project | time=70ms
GET 200 http://example.com/sonar/api/components/tree.protobuf?qualifiers=BRC&baseComponentKey=example-project&ps=500&p=1 | time=78ms
GET 200 example.com/sonar/batch/issues?key=example-project | time=74ms

然后它显示它正在尝试分析我打开的文件:

Analysis triggered on file:///c%3A/Users/example/src/example/src/js/example.js with configuration: 
[
  moduleKey: example
  baseDir: c:\Users\example\src\example
  workDir: c:\Users\example\src\example\.sonarlint
  extraProperties: {}
  inputFiles: [
    c:\Users\example\src\example\src\js\example.js (UTF-8)
  ]
]

但是,它随后会显示以下错误消息:

Available languages:
  * JavaScript => "js"
  * Java => "java"
Start analysis
Declared extensions of language JavaScript were converted to js: **/*.js
Declared extensions of language Java were converted to java: **/*.java,**/*.jav
Quality profiles:
  * java: java-sonar-way-77058 (251 rules)
  * js: js-sonar-way-33138 (86 rules)
[Info  - 10:43:48 AM] Index files
Language of file 'file:///c:\Users\example\src\example\src\js\example.js' is set to 'js'
Setting filesystem encoding: UTF-8
[Info  - 10:43:48 AM] 1 files indexed
'JavaSquidSensor' skipped because there is no related file in current project
Execute Sensor: JavaScript Squid Sensor
[Info  - 10:43:49 AM] 1 source files to be analyzed
Initializing metadata of file file:///c:\Users\example\src\example\src\js\example.js
[Error - 10:43:50 AM] Analysis failed.
org.sonar.squidbridge.api.AnalysisException: Unable to analyse file: c:\Users\example\src\example\src\js\example.js
    at org.sonar.plugins.javascript.JavaScriptSquidSensor.analyse(JavaScriptSquidSensor.java:174)
    at org.sonar.plugins.javascript.JavaScriptSquidSensor.analyseFiles(JavaScriptSquidSensor.java:133)
    at org.sonar.plugins.javascript.JavaScriptSquidSensor.execute(JavaScriptSquidSensor.java:349)
    at org.sonarsource.sonarlint.core.analyzer.sensor.SensorWrapper.analyse(SensorWrapper.java:52)
    at org.sonarsource.sonarlint.core.analyzer.sensor.AllSensorsExecutor.executeSensor(AllSensorsExecutor.java:79)
    at org.sonarsource.sonarlint.core.analyzer.sensor.AllSensorsExecutor.execute(AllSensorsExecutor.java:67)
    at org.sonarsource.sonarlint.core.analyzer.sensor.PhaseExecutor.execute(PhaseExecutor.java:36)
    at org.sonarsource.sonarlint.core.container.analysis.AnalysisContainer.doAfterStart(AnalysisContainer.java:141)
    at org.sonarsource.sonarlint.core.container.ComponentContainer.startComponents(ComponentContainer.java:125)
    at org.sonarsource.sonarlint.core.container.ComponentContainer.execute(ComponentContainer.java:110)
    at org.sonarsource.sonarlint.core.container.storage.StorageAnalyzer.analyze(StorageAnalyzer.java:75)
    at org.sonarsource.sonarlint.core.container.storage.StorageContainerHandler.analyze(StorageContainerHandler.java:76)
    at org.sonarsource.sonarlint.core.ConnectedSonarLintEngineImpl.lambda$analyze$0(ConnectedSonarLintEngineImpl.java:152)
    at org.sonarsource.sonarlint.core.ConnectedSonarLintEngineImpl.withReadLock(ConnectedSonarLintEngineImpl.java:339)
    at org.sonarsource.sonarlint.core.ConnectedSonarLintEngineImpl.withReadLock(ConnectedSonarLintEngineImpl.java:329)
    at org.sonarsource.sonarlint.core.ConnectedSonarLintEngineImpl.analyze(ConnectedSonarLintEngineImpl.java:150)
    at org.sonarlint.languageserver.SonarLintLanguageServer$ConnectedAnalysisWrapper.analyze(SonarLintLanguageServer.java:718)
    at org.sonarlint.languageserver.SonarLintLanguageServer$ConnectedAnalysisWrapper.analyze(SonarLintLanguageServer.java:699)
    at org.sonarlint.languageserver.SonarLintLanguageServer.analyze(SonarLintLanguageServer.java:605)
    at org.sonarlint.languageserver.SonarLintLanguageServer.didOpen(SonarLintLanguageServer.java:539)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.eclipse.lsp4j.jsonrpc.services.GenericEndpoint.lambda$null$0(GenericEndpoint.java:61)
    at org.eclipse.lsp4j.jsonrpc.services.GenericEndpoint.notify(GenericEndpoint.java:148)
    at org.eclipse.lsp4j.jsonrpc.RemoteEndpoint.handleNotification(RemoteEndpoint.java:216)
    at org.eclipse.lsp4j.jsonrpc.RemoteEndpoint.consume(RemoteEndpoint.java:183)
    at org.eclipse.lsp4j.jsonrpc.Launcher$Builder.lambda$wrapMessageConsumer$0(Launcher.java:308)
    at org.eclipse.lsp4j.jsonrpc.validation.ReflectiveMessageValidator.consume(ReflectiveMessageValidator.java:71)
    at org.eclipse.lsp4j.jsonrpc.json.StreamMessageProducer.handleMessage(StreamMessageProducer.java:188)
    at org.eclipse.lsp4j.jsonrpc.json.StreamMessageProducer.listen(StreamMessageProducer.java:90)
    at org.eclipse.lsp4j.jsonrpc.json.ConcurrentMessageProcessor.run(ConcurrentMessageProcessor.java:95)
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.IllegalArgumentException: 12 is not a valid line offset for pointer. File [path=c:\Users\example\src\example\src\js\example.js] has 1 character(s) at line 105
    at org.sonar.api.internal.google.common.base.Preconditions.checkArgument(Preconditions.java:145)
    at org.sonar.api.batch.fs.internal.DefaultInputFile.checkValid(DefaultInputFile.java:312)
    at org.sonar.api.batch.fs.internal.DefaultInputFile.newPointer(DefaultInputFile.java:246)
    at org.sonar.api.batch.fs.internal.DefaultInputFile.newRange(DefaultInputFile.java:261)
    at org.sonar.javascript.cpd.CpdVisitor.visitNode(CpdVisitor.java:80)
    at org.sonar.plugins.javascript.api.visitors.SubscriptionVisitor.visit(SubscriptionVisitor.java:74)
    at org.sonar.plugins.javascript.api.visitors.SubscriptionVisitor.visitChildren(SubscriptionVisitor.java:94)
    at org.sonar.plugins.javascript.api.visitors.SubscriptionVisitor.visit(SubscriptionVisitor.java:76)
    at org.sonar.plugins.javascript.api.visitors.SubscriptionVisitor.visitChildren(SubscriptionVisitor.java:94)
    at org.sonar.plugins.javascript.api.visitors.SubscriptionVisitor.visit(SubscriptionVisitor.java:76)
    at org.sonar.plugins.javascript.api.visitors.SubscriptionVisitor.visitChildren(SubscriptionVisitor.java:94)
    at org.sonar.plugins.javascript.api.visitors.SubscriptionVisitor.visit(SubscriptionVisitor.java:76)
    at org.sonar.plugins.javascript.api.visitors.SubscriptionVisitor.visitChildren(SubscriptionVisitor.java:94)
    at org.sonar.plugins.javascript.api.visitors.SubscriptionVisitor.visit(SubscriptionVisitor.java:76)
    at org.sonar.plugins.javascript.api.visitors.SubscriptionVisitor.visitChildren(SubscriptionVisitor.java:94)
    at org.sonar.plugins.javascript.api.visitors.SubscriptionVisitor.visit(SubscriptionVisitor.java:76)
    at org.sonar.plugins.javascript.api.visitors.SubscriptionVisitor.visitChildren(SubscriptionVisitor.java:94)
    at org.sonar.plugins.javascript.api.visitors.SubscriptionVisitor.visit(SubscriptionVisitor.java:76)
    at org.sonar.plugins.javascript.api.visitors.SubscriptionVisitor.visitChildren(SubscriptionVisitor.java:94)
    at org.sonar.plugins.javascript.api.visitors.SubscriptionVisitor.visit(SubscriptionVisitor.java:76)
    at org.sonar.plugins.javascript.api.visitors.SubscriptionVisitor.visitChildren(SubscriptionVisitor.java:94)
    at org.sonar.plugins.javascript.api.visitors.SubscriptionVisitor.visit(SubscriptionVisitor.java:76)
    at org.sonar.plugins.javascript.api.visitors.SubscriptionVisitor.visitChildren(SubscriptionVisitor.java:94)
    at org.sonar.plugins.javascript.api.visitors.SubscriptionVisitor.visit(SubscriptionVisitor.java:76)
    at org.sonar.plugins.javascript.api.visitors.SubscriptionVisitor.visitChildren(SubscriptionVisitor.java:94)
    at org.sonar.plugins.javascript.api.visitors.SubscriptionVisitor.visit(SubscriptionVisitor.java:76)
    at org.sonar.plugins.javascript.api.visitors.SubscriptionVisitor.visitChildren(SubscriptionVisitor.java:94)
    at org.sonar.plugins.javascript.api.visitors.SubscriptionVisitor.visit(SubscriptionVisitor.java:76)
    at org.sonar.plugins.javascript.api.visitors.SubscriptionVisitor.visitChildren(SubscriptionVisitor.java:94)
    at org.sonar.plugins.javascript.api.visitors.SubscriptionVisitor.visit(SubscriptionVisitor.java:76)
    at org.sonar.plugins.javascript.api.visitors.SubscriptionVisitor.visitChildren(SubscriptionVisitor.java:94)
    at org.sonar.plugins.javascript.api.visitors.SubscriptionVisitor.visit(SubscriptionVisitor.java:76)
    at org.sonar.plugins.javascript.api.visitors.SubscriptionVisitor.visitChildren(SubscriptionVisitor.java:94)
    at org.sonar.plugins.javascript.api.visitors.SubscriptionVisitor.visit(SubscriptionVisitor.java:76)
    at org.sonar.plugins.javascript.api.visitors.SubscriptionVisitor.scanTree(SubscriptionVisitor.java:68)
    at org.sonar.plugins.javascript.api.visitors.SubscriptionVisitor.scanTree(SubscriptionVisitor.java:62)
    at org.sonar.plugins.javascript.JavaScriptSquidSensor.scanFile(JavaScriptSquidSensor.java:235)
    at org.sonar.plugins.javascript.JavaScriptSquidSensor.analyse(JavaScriptSquidSensor.java:163)
    ... 37 more
4

1 回答 1

0

正如评论中所建议的,问题在于它尝试连接的服务器位于旧版本的 SonarJS 上。我们将其更新为SonarJS: 5.0 Build 6962,现在 VS Code 的 SonarLint 扩展在连接模式下完美运行。

于 2018-11-26T14:23:58.733 回答