【问题标题】:cppcheck seems to work but no lint results appear (Subilme Text 3, Mac)cppcheck 似乎工作,但没有出现 lint 结果(Sublime Text 3,Mac)
【发布时间】:2018-12-01 16:55:54
【问题描述】:

我在 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)。是否与这种奇怪的行为有关?

【问题讨论】:

    标签: c++ macos sublimetext3 cppcheck sublimelinter


    【解决方案1】:

    在我的环境中,我终于解决了这个问题,从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": [],
        }
      },
    }
    

    【讨论】:

    • 我也遇到了同样的问题。你是如何解决这个问题的?我不明白您所说的“......从 SublimeLinter.sublime-settings 中删除以下部分”是什么意思。您的用户设置文件现在看起来如何?
    • 我更新了我的答案,所以请检查一下。我刚刚删除了cppcheck 部分。我认为这影响了正确的行为。
    • 好吧 thx.my 的问题是不同的。我通过 ubuntus 包管理器安装了 cppcheck。这给了我 cppcheck 1.8x 版本,显然这个版本没有提供“列”输出。下载并构建 cppcheck 1.90 版后一切正常
    猜你喜欢
    • 2015-06-01
    • 2015-12-31
    • 1970-01-01
    • 2016-11-29
    • 1970-01-01
    • 2017-07-16
    • 2013-10-15
    • 1970-01-01
    • 2015-05-01
    相关资源
    最近更新 更多