1

我在我的 Eclipse 中安装了一个 SonarLint 插件,现在我正在尝试在我的玩具 C++ 项目上对其进行测试。我没有看到关于我的代码的错误/警告/警报,即使我故意让它真的坏了。有没有办法检查或确认 SonarLint 确实试图验证我的源代码?

这是我的测试程序源:

struct C
{
    bool x;
    bool y;
};

int f(C c)
{
    int * p = nullptr;
    *p = 3;
    if (c.x)
        if (c.x)
            return true;
    if (c.x)
            return false;

    return *p;
}

int main()
{
    C c;
    int i = f(c);
}

我确信我已经安装了 SonarLint 插件,因为每当我启动 Eclipse 时,我都会收到一条错误消息“SonarLint - 规则不可用”:“某些规则在满足某些要求之前不可用”。当我单击“详细信息”时,我得到“无法加载某些分析器。”。

控制台输出如下:

Starting SonarLint for Eclipse 5.6.0.25634
Trigger: STARTUP
Clear markers on 0 excluded files
SonarLint processing file /AK GCC Test/main.cpp...
Wrote build info to: /home/andrzej/workspace/.metadata/.plugins/org.eclipse.core.resources/.projects/AK GCC Test/org.sonarlint.eclipse.core/sonarlint18042127755659198027/build-wrapper-dump.json
Standalone mode (project not bound)
Starting analysis with configuration:
[
  baseDir: /home/andrzej/workspace/AK GCC Test
  extraProperties: {sonar.cfamily.useCache=false, sonar.cfamily.build-wrapper-output=/home/andrzej/workspace/.metadata/.plugins/org.eclipse.core.resources/.projects/AK GCC Test/org.sonarlint.eclipse.core/sonarlint18042127755659198027}
  excludedRules: []
  includedRules: []
  ruleParameters: {}
  inputFiles: [
    file:/home/andrzej/workspace/AK%20GCC%20Test/main.cpp (UTF-8) [cpp]
  ]
]

Starting standalone SonarLint engine 5.6.0.25634...
Loading embedded analyzers...
  - /plugins/sonar-html-plugin-3.3.0.2534.jar
  - /plugins/sonar-javascript-plugin-7.0.1.14561.jar
  - /plugins/sonar-python-plugin-3.1.0.7619.jar
  - /plugins/sonar-java-plugin-6.10.0.24201.jar
  - /plugins/sonar-php-plugin-3.13.0.6849.jar
Create : /home/andrzej/.sonarlint/plugins
Plugin cache: /home/andrzej/.sonarlint/plugins
Create : /home/andrzej/.sonarlint/plugins/_tmp
Load plugins
Plugin 'JavaScript/TypeScript Code Quality and Security' requires Node.js 8.0.0. Skip loading it.
Plugin 'Java Code Quality and Security' is excluded because language 'Java' is not enabled. Skip loading it.
Load plugins (done) | time=15ms
Plugins:
  * Python Code Quality and Security 3.1.0.7619 (python)
  * HTML Code Quality and Security 3.3.0.2534 (web)
  * PHP Code Quality and Security 3.13.0.6849 (php)
Start analysis
Index files
Language of file 'file:/home/andrzej/workspace/AK%20GCC%20Test/main.cpp' is set to 'C++'
1 file indexed
'PHP sensor' skipped because there is no related file in current project
'Analyzer for "php.ini" files' skipped because there is no related file in current project
'Python Sensor' skipped because there is no related file in current project
Execute Sensor: HTML
Found 0 issue(s)
0 entries removed from the store
Done in 1384 ms

基于 [this bug report][1] 我认为这不会影响 SolarLint 分析我的 C++ 代码的能力。

但是当我更改代码并编译上面的代码时,我没有收到来自 SonarLint 的任何警告。当我右键单击我的项目名称时,我会在上下文菜单中看到“SonarLint”项;当我展开它时,我有项目“分析”;当我选择它时,“SonarLint 报告”窗口打开,但它包含零消息。肯定至少应该为我的上述代码找到一个错误?

有没有办法验证什么是错的?或者如果我的期望不正确?



  [1]: https://community.sonarsource.com/t/sonarlint-eclipse-warning-at-startup/29150
4

1 回答 1

1

好的,我知道。SonarLint 不支持 C++。使用 C++ 的是其他 SonarSource 工具。

于 2020-12-19T16:59:17.457 回答