dense-analysis / ale

Check syntax in Vim/Neovim asynchronously and fix files, with Language Server Protocol (LSP) support
BSD 2-Clause "Simplified" License
13.55k stars 1.43k forks source link

Cppcheck 1.89 breaks ALE linter parser #2994

Closed tsjordan-eng closed 4 years ago

tsjordan-eng commented 4 years ago

Cppcheck 1.89 changes the warning output to match gcc better, but this breaks ALE's linter parser.

Information

VIM version

NVIM v0.4.3 Build type: RelWithDebInfo

RHEL7

What went wrong

Warnings and Errors wouldn't show up in the gutter.

Reproducing the bug

Use cppcheck linter with Cppcheck v1.89+

: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 = '-I/usr/local/include --inline-suppr --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 = 500
let g:ale_completion_enabled = 1
let g:ale_completion_max_suggestions = 50
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 = {'*': ['remove_trailing_lines', 'trim_whitespace']}
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 = 1000
let g:ale_lint_on_enter = 1
let g:ale_lint_on_filetype_changed = 1
let g:ale_lint_on_insert_leave = 1
let g:ale_lint_on_save = 1
let g:ale_lint_on_text_changed = 'normal'
let g:ale_linter_aliases = {}
let g:ale_linters = {'yaml': ['yamllint'], 'cmake': ['cmakelint'], 'c': ['cppcheck'], 'vhdl': ['xvhdl'], 'dockerfile': ['dockerfile_lint'], 'cpp': ['cppcheck']}
let g:ale_linters_explicit = 1
let g:ale_list_vertical = 0
let g:ale_list_window_size = 10
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 = 1
let g:ale_set_quickfix = 0
let g:ale_set_signs = 1
let g:ale_sign_column_always = 0
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', '''cppcheck'' -q --language=c++ -I/usr/local/include --inline-suppr --enable=style -I''/tmp/TextFileParser.cpp'' ''/tmp/nvimmH1M15/2/TextFileParser.cpp''']
<<<OUTPUT STARTS>>>
/tmp/nvimmH1M15/2/TextFileParser.cpp:47:29: error: Resource leak: fid [resourceLeak]
    if (contents == NULL) { return NULL; }
                            ^
<<<OUTPUT ENDS>>>

Proposed Fix

I'm not sure where to fix this. I have changed my:

let g:ale_cpp_cppcheck_options = '-I/usr/local/include --inline-suppr --enable=style --template=cppcheck1'

according to https://github.com/danmar/cppcheck/releases/tag/1.89 In my configuration, but I think it should be fixed in either:

mrbeardad commented 4 years ago

Based on your analysis, I made the following changes in ale/ale_linters/cpp/cppcheck.vim to solve this problem: \ 'callback': 'ale#handlers#cppcheck#HandleCppCheckFormat', instead of \ 'callback': 'ale#handlers#gcc#HandleGCCFormatWithIncludes',

tsjordan-eng commented 4 years ago

Clever! Now is there a way for ALE to conditionally set the later based on the cppcheck version?

w0rp commented 4 years ago

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