c++ - cppcheck 似乎可以工作,但没有出现 lint 结果(Sublime Text 3,Mac)

标签 c++ macos sublimetext3 cppcheck sublimelinter

我在 macOS High Sierra(版本 10.13.3)上使用 Sublime Text 3(版本 3.1.1,内部版本 3176)。

我想让 SublimeLinter-cppcheck 插件和 cppcheck 在我的 Sublime Text 3 中工作,所以我根据 this link 安装了它们和其他网站。

现在我的 SublimeLinter.sublime-settings 是这样的。 (我也是用Python的插件,所以有flake8的设置。)

{
  "debug": true,
  "linters": {
    "cppcheck": {
      "@disable": false,
      "source": "source.cpp",
      "lint_mode": "save",
      "args": [],
      "enable": "style",
      "excludes": [],
      "std": ["c++11"]
    },
    "flake8": {
      "@disable": false,
      "source": "source.py",
      "args": ["--ignore=E111"],
      "enable": "style",
      "excludes": [],
    }
  },
}

然后我用 test.cpp 检查它们是否安装成功,如下所示。

#include <iostream>

using namespace std;

int main()
{
    cout << "it works" << endl;

    return 0;

这段代码显然有错误,所以如果它们安装成功,代码中会出现一些 lint 结果。

在调试控制台中,cppcheck 似乎可以正常工作,所以我认为我安装成功了。这是调试控制台的输出。

SublimeLinter: sublime_linter.py:249: Delay buffer 28 for 0.1s
SublimeLinter: sublime_linter.py:249: Delay buffer 28 for 0.0s
SublimeLinter: linter.py:798: Checking lint mode background vs lint reason on_save
SublimeLinter: #98 linter.py:818: 'cppcheck' is linting 'test.cpp'
SublimeLinter: #98 linter.py:1174: Running ...

  /Users/ASHIJANKEN/Desktop  (working dir)
  $ /usr/local/bin/cppcheck --template=gcc --inline-suppr --quiet --std=c++11 --enable=style /Users/ASHIJANKEN/Desktop/test.cpp

SublimeLinter: #98 linter.py:866: cppcheck output:
    /Users/ASHIJANKEN/Desktop/test.cpp:6:0: warning: Invalid number of character '{' when no macros are defined. [syntaxError]
    {
    ^
SublimeLinter: #98 linter.py:906: cppcheck: No match for line: '{'
SublimeLinter: #98 linter.py:906: cppcheck: No match for line: '^'
SublimeLinter: sublime_linter.py:432: Linting buffer 28 took 0.03s

但是,在编辑窗口中没有出现 lint 结果。

An image of actual window when I editing test.cpp

我不知道为什么没有出现 lint 结果。我哪里出错了?

我知道当 lint_mode 为背景时,cppcheck 不起作用(Related issue)。是否与这种奇怪的行为有关?

最佳答案

在我的环境中,最后我通过从 SublimeLinter.sublime-settings 中删除以下部分解决了这个问题。

"cppcheck": {
  "@disable": false,
  "source": "source.cpp",
  "lint_mode": "save",
  "args": [],
  "enable": "style",
  "excludes": [],
  "std": ["c++11"]
},

现在我的 SublimeLinter.sublime-settings 如下所示。

{
  "debug": true,
  "linters": {
    "flake8": {
      "@disable": false,
      "source": "source.py",
      "args": ["--ignore=E111, E114"],
      "enable": "style",
      "excludes": [],
    }
  },
}

关于c++ - cppcheck 似乎可以工作,但没有出现 lint 结果(Sublime Text 3,Mac),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50984107/

相关文章:

c++ - 从构造函数传递给成员函数时,私有(private)成员变量为空

c++ - 如何在 Qt GUI 应用程序中附加 MS word 文档?

android - 错误:未设置ANDROID_HOME,并且PATH中没有 “android”命令。您必须至少满足以下条件之一。

objective-c - 在 Objective-C 中如何判断一个目录是否可写?

vim - 如何在 VIM 中将文件夹添加到项目(如 Sublime Text)?

sublimetext3 - Sublime3中的程序包控制不起作用?

c++ - WriteConsoleOutputCharacterW-我的新行在哪里?

ios - MacOS:以编程方式查找串口?

csv - 使用高级 CSV 对齐制表符分隔文件中的列

c++ - QT - 如何将文件名编码设置为西里尔文