Ale: ALE does not show errors for cppcheck

Created on 9 Nov 2019  路  20Comments  路  Source: dense-analysis/ale

Information

VIM version

VIM - Vi IMproved 8.1 (2018 May 18, compiled May  2 2019 12:07:21)
macOS version
Included patches: 1-1189
Compiled by [email protected]
Huge version without GUI.  Features included (+) or not (-):
+acl               +extra_search      +mouse_netterm     -tag_old_static
+arabic            -farsi             +mouse_sgr         -tag_any_white
+autocmd           +file_in_path      -mouse_sysmouse    -tcl
+autochdir         +find_in_path      +mouse_urxvt       +termguicolors
-autoservername    +float             +mouse_xterm       +terminal
-balloon_eval      +folding           +multi_byte        +terminfo
+balloon_eval_term -footer            +multi_lang        +termresponse
-browse            +fork()            -mzscheme          +textobjects
++builtin_terms    -gettext           +netbeans_intg     +textprop
+byte_offset       -hangul_input      +num64             +timers
+channel           +iconv             +packages          +title
+cindent           +insert_expand     +path_extra        -toolbar
-clientserver      +job               -perl              +user_commands
+clipboard         +jumplist          +persistent_undo   +vartabs
+cmdline_compl     +keymap            +postscript        +vertsplit
+cmdline_hist      +lambda            +printer           +virtualedit
+cmdline_info      +langmap           +profile           +visual
+comments          +libcall           -python            +visualextra
+conceal           +linebreak         +python3           +viminfo
+cryptv            +lispindent        +quickfix          +vreplace
-cscope            +listcmds          +reltime           +wildignore
+cursorbind        +localmap          +rightleft         +wildmenu
+cursorshape       -lua               -ruby              +windows
+dialog_con        +menu              +scrollbind        +writebackup
+diff              +mksession         +signs             -X11
+digraphs          +modify_fname      +smartindent       -xfontset
-dnd               +mouse             +startuptime       -xim
-ebcdic            -mouseshape        +statusline        -xpm
+emacs_tags        +mouse_dec         -sun_workshop      -xsmp
+eval              -mouse_gpm         +syntax            -xterm_clipboard
+ex_extra          -mouse_jsbterm     +tag_binary        -xterm_save
   system vimrc file: "$VIM/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
       defaults file: "$VIMRUNTIME/defaults.vim"
  fall-back for $VIM: "/usr/local/share/vim"
Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H   -DMACOS_X -DMACOS_X_DARWIN  -g -O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
Linking: gcc   -L/usr/local/lib -o vim        -lm -lncurses  -liconv -framework AppKit     -L/usr/local/opt/python/Frameworks/Python.framework/Versions/3.7/lib/python3.7/config-3.7m-darwin -lpython3.7m -ldl -framework CoreFoundation

Operating System: macOS Mojave

What went wrong

:ALEInfo show all kinds of errors being detected for C++ code, but does not display them anywhere. I'm using the following vimrc:

if &compatible
    set nocompatible
endif

set runtimepath+=$HOME/.vim/bundle/repos/github.com/Shougo/dein.vim

call dein#begin('$HOME/.vim/bundle/')
" Let dein manage dein
call dein#add('$HOME/.vim/bundle/repos/github.com/Shougo/dein.vim')

if v:version >= 800
    call dein#add('w0rp/ale', {'on_ft': ['python', 'c', 'cpp']})
    let g:ale_python_pylint_executable = 'python'
    let g:ale_set_loclist = 0
    let g:ale_set_quickfix = 1
    let g:ale_lint_on_text_changed = 'never'
    let g:ale_lint_on_insert_leave = 0
    let g:ale_lint_on_enter = 0
    let g:ale_c_parse_compile_commands = 1

    let g:ale_linters = {
                \ 'python': ['pycodestyle', 'flake8', 'pylint', 'autopep8'],
                \ 'cpp': ['clang-format', 'cppcheck'],
                \}

    let g:ale_fixers = {
                \ 'python': ['add_blank_lines_for_python_control_statements',
                \            'autopep8', 'isort', 'yapf', 'black'],
                \ 'cpp': ['clang-format', 'cppcheck']
                \}

    let g:ale_linters_explicit=1
    let g:ale_sign_column_always = 1
    let g:ale_list_window_size = 15
endif

syntax enable

Reproducing the bug

  1. Open Cpp file (compile_commands.json is working directory)
  2. Run ALELint
  3. Look at ALEInfo, which shows cppcheck output all kinds of issues
  4. Nothing in gutter, quickfix window or location list

:ALEInfo


 Current Filetype: cpp
Available Linters: ['ccls', 'clang', 'clangcheck', 'clangd', 'clangtidy', 'clazy', 'cppcheck', 'cpplint', 'cquery', 'flawfinder', 'gcc']
   Linter Aliases:
'gcc' -> ['g++']
  Enabled Linters: ['cppcheck']
 Suggested Fixers: 
  'clang-format' - Fix C/C++ and cuda files with clang-format.
  'clangtidy' - Fix C/C++ and ObjectiveC files with clang-tidy.
  'remove_trailing_lines' - Remove all blank lines at the end of a file.
  'trim_whitespace' - Remove all trailing whitespace characters at the end of every line.
  'uncrustify' - Fix C, C++, C#, ObjectiveC, ObjectiveC++, D, Java, Pawn, and VALA files with uncrustify.
 Linter Variables:

let g:ale_cpp_cppcheck_executable = 'cppcheck'
let g:ale_cpp_cppcheck_options = '--enable=style'
 Global Variables:

let g:ale_cache_executable_check_failures = v:null
let g:ale_change_sign_column_color = 0
let g:ale_command_wrapper = ''
let g:ale_completion_delay = v:null
let g:ale_completion_enabled = 0
let g:ale_completion_max_suggestions = v:null
let g:ale_echo_cursor = 1
let g:ale_echo_msg_error_str = 'Error'
let g:ale_echo_msg_format = '%code: %%s'
let g:ale_echo_msg_info_str = 'Info'
let g:ale_echo_msg_warning_str = 'Warning'
let g:ale_enabled = 1
let g:ale_fix_on_save = 0
let g:ale_fixers = {'cpp': ['clang-format', 'cppcheck'], 'python': ['add_blank_lines_for_python_control_statements', 'autopep8', 'isort', 'yapf', 'black']}
let g:ale_history_enabled = 1
let g:ale_history_log_output = 1
let g:ale_keep_list_window_open = 0
let g:ale_lint_delay = 200
let g:ale_lint_on_enter = 0
let g:ale_lint_on_filetype_changed = 1
let g:ale_lint_on_insert_leave = 0
let g:ale_lint_on_save = 1
let g:ale_lint_on_text_changed = 'never'
let g:ale_linter_aliases = {}
let g:ale_linters = {'cpp': ['clang-format', 'cppcheck'], 'python': ['pycodestyle', 'flake8', 'pylint', 'autopep8']}
let g:ale_linters_explicit = 1
let g:ale_list_vertical = 0
let g:ale_list_window_size = 15
let g:ale_loclist_msg_format = '%code: %%s'
let g:ale_lsp_root = {}
let g:ale_max_buffer_history_size = 20
let g:ale_max_signs = -1
let g:ale_maximum_file_size = v:null
let g:ale_open_list = 0
let g:ale_pattern_options = v:null
let g:ale_pattern_options_enabled = v:null
let g:ale_set_balloons = 0
let g:ale_set_highlights = 1
let g:ale_set_loclist = 0
let g:ale_set_quickfix = 1
let g:ale_set_signs = 1
let g:ale_sign_column_always = 1
let g:ale_sign_error = '>>'
let g:ale_sign_info = '--'
let g:ale_sign_offset = 1000000
let g:ale_sign_style_error = '>>'
let g:ale_sign_style_warning = '--'
let g:ale_sign_warning = '--'
let g:ale_sign_highlight_linenrs = 0
let g:ale_statusline_format = v:null
let g:ale_type_map = {}
let g:ale_use_global_executables = v:null
let g:ale_virtualtext_cursor = 0
let g:ale_warn_about_trailing_blank_lines = 1
let g:ale_warn_about_trailing_whitespace = 1
  Command History:

(executable check - success) cppcheck
(finished - exit code 0) ['/bin/bash', '-c', 'cd ''/Users/rasmus/foobar'' && ''cppcheck'' -q --language=c++ --project=''compile_commands.json'' --enable=style ''/var/folders/_p/j1qf8m7x31g3g_c6kvnbgp840000gp/T/vNL0Itz/1/main.cpp''']

<<<OUTPUT STARTS>>>
/Users/rasmus/foobar/Class.hpp:120:3: style: 'ConfigNode::operator=' should return 'ConfigNode &'. [operatorEq]
  ConfigNode operator=(const ConfigNode& other) {
  ^
[鈥
<<<OUTPUT ENDS>>>

(I obfuscated and truncated the error list, but there's a whole lot)

bug

Most helpful comment

Re-opening as this was auto-closed by a commit relating to eslint. Will need to investigate cppcheck output format more.

All 20 comments

I'm seeing a very similar issue, except with eslint. i.e. :ALEInfo displays errors but they're not being highlighted, or displayed in any way.

Also the errors do get fixed on save, so ALE is still working to some extent.

I recently updated ALE (with Vundle :PluginUpdate) so I'm wondering if this caused the issue?

I was able to fix this by manually reverting to commit ddb3e6d5 Handle failing to connect to eslint_d.

Commit ddb3e6d5 is over a year old. Is it possible the output of eslint for your version is only compatible with that version of ALE?

Possibly, although it seemed like the interface to eslint was working since ALE was getting the linting errors (in ALEInfo) and fixing them (on save), .

But I will try updating eslint at some point.

By the way I used that commit because it happened to be the last one I pulled, not for any particular reason.

@j-oshb that commit has nothing to do with ALE linter. It changes the ALEFixer for eslint. Would be great if you can investigate the exact commit that caused the issue using git bisect since you have a good and a bad commit.

@hsanson Hey i had the exact same problem (and thanks soo much for git bisect. i didn't know it before and its awesome) and narrowed it down to this commit: 79d1b99067878bbec129cfd29a7c9587c276dec6

I think this line is at fault. From eslint --json i get the following data:

a = [
  '[{"filePath":"/home/jonas/projects/e-learning/frontend/app/admin/notifications/index/controller.js","messages":[{"ruleId":null,"fatal":true,"severity":2 ,"message":"Parsing error: Unexpected token Controller","line":1,"column":9}],"errorCount":1,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount": 0,"source":"i:mport Controller from \"@ember/controller\";\nimport listViewControllerMixin from \"elearning/mixins/list-view-controller\";\nimport { inject as service } from \"@ember/service\";\n\nexport default Controller.extend(listViewControllerMixin(), {\n  modelName: \"notification\",\n  intl: service(),\n\n  flatpickrLocale: computed(\"intl.locale\", function() {\n    return this.intl.locale.firstObject.split(\"-\")[0];\n  })\n});\n"}]',
  '(node:616989) [ESLINT_LEGACY_OBJECT_REST_SPREAD] DeprecationWarning: The ''parserOptions.ecmaFeatures.experimentalObjectRestSpread'' option is deprecated. Use ''parser Options.ecmaVersion'' instead. (found in "node_modules/eslint-plugin-ember/lib/config/base.js")'
]

but since we read

let l:parsed = json_decode(a:lines[-1])

from the eslint output, the deprecation warning is actually parsed. If this line were changed to:

let l:parsed = json_decode(a:lines[0])

the actual json would be parsed and everything works as expected.

@velrest thanks for the bisect, that is very useful. I created a fix #2910 that tries to parse all rows in the errors array instead of only the last one.

Note that I do work with javascript nor eslint so I have not tested this extensively. The fix is based on the error output you provided.

Note that #2910 fixed the problem for eslint and not for C++ that is the original issue here. Most probably the problem is the same and the C++ error parser must be updated.

@themightyoarfish please re-open the issue if still relevant. If possible providing the exact commit that caused the issue using git bisect.

Still seeing the same problem on 4afbf2f25dc0ce86b118261b0cfb904c80ae6ba0.

Furthermore, ALEInfo shows a lot of errors for other files, but nothing for the file that is actually open.

I seem to have the same problem with any commit though, so maybe it's not an ale problem.

I only see the problem with cppcheck for some reason

I have used the latest version of cppcheck from git hub, and I believe they changed their error format, not sure how it was before.

This will match their format as of now (from git hub):
file: autoload/ale/handlers/cppcheck.vim
let l:pattern = '\v^(.+):(\d+):(\d+): ([a-z]+): (.+)$'
instead of
let l:pattern = '\v^[(.+):(\d+)]: (([a-z]+)) (.+)$'

add text match should be incremented by 1
\ 'text': l:match[5],
instead of:
\ 'text': l:match[4],
after this change, i could see output of cppcheck in quickfix window, and on the sign bar.

Re-opening as this was auto-closed by a commit relating to eslint. Will need to investigate cppcheck output format more.

oh, hey. I fixed the cppcheck formatting. Waiting for a review

3030

I have used the latest version of cppcheck from git hub, and I believe they changed their error format, not sure how it was before.

This will match their format as of now (from git hub):
file: autoload/ale/handlers/cppcheck.vim
let l:pattern = '\v^(.+):(\d+):(\d+): ([a-z]+): (.+)$'
instead of
let l:pattern = '\v^[(.+):(\d+)]: (([a-z]+)) (.+)$'

add text match should be incremented by 1
\ 'text': l:match[5],
instead of:
\ 'text': l:match[4],
after this change, i could see output of cppcheck in quickfix window, and on the sign bar.

Thank you, it works for me.

My current cppcheck version is 19.0, and ale works on my Ubuntu with cppcheck 18.2.

Here is the example code:

int main() {
        FILE *fp = fopen("a", "w");
        return 0;
}

Cppcheck 1.90:

Checking test.c ...
test.c:5:2: error: Resource leak: fp [resourceLeak]
 return 0;
 ^

Cppcheck 1.82:

Checking test.c ...
[test.c:5]: (error) Resource leak: fp

It turns out that for me, the following YouCompleteMe setting lead to ALE not showing errors.

let g:ycm_show_diagnostics_ui = 0

without this, it works with current master. Presumably, this disables features which ALE also uses.

I don't use YCM, but I have this same issue! A temporary workaround is to pass the option --template=cppcheck1 to cppcheck , i.e. set let g:ale_cpp_cppcheck_options = '--enable=all --template=cppcheck1'

I am on cppcheck v2.1.

I don't use YCM, but I have this same issue! A temporary workaroundd is to pass the option --template=cppcheck1 to cppcheck , i.e. set let g:ale_cpp_cppcheck_options = '--enable=all --template=cppcheck1'

Using cppcheck version 1.90 which is the currently distributed version on Linux Mint 20 (Ubuntu 20.04), that workaround also fixed the issue for me. The linter file should probably be adjusted to specify the --template parameter to match the expected error format (and/or adjust the error format to the new default template).

I've merged the pull request now which fixes the formatting of the messages output by cppcheck, and how we parse them.

Was this page helpful?
0 / 5 - 0 ratings