我在 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 结果。
我不知道为什么没有出现 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/