dense-analysis / ale

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

Invalid golangci-lint typecheck errors reported by ale #4586

Closed milosgajdos closed 8 months ago

milosgajdos commented 1 year ago

Information

VIM version

$ vim --version
VIM - Vi IMproved 9.0 (2022 Jun 28, compiled Jun 23 2023 15:15:13)
macOS version - x86_64

Operating System:

What went wrong

ALE incorrectly marks golangci-lint typecheck errors in the source file which otherwise pass the linter when linter is run manually.

This happens when there is a Go package that contains more than one source file and the types defined in each of the source files are shared between them.

Reproducing the bug

Here are the Go source files where ALE incorrectly reports typecheck issues:

Create a new package

mkdir foo && cd foo && go mod init
touch foo.go && touch bar.go

These are the contents of foo/foo.go and foo/bar.go

// foo.go
package foo

type Foo struct {
    Bar Bar
}

// bar.go
package foo

type Bar struct {
    Msg string
}

open foo/foo.go and you get this golangci-lint error:

[golangci-lint] undefined: Bar (typecheck) [Error]

Running the linter manually on the cli works like charm

$ golangci-lint run

:ALEInfo

 Current Filetype:
Available Linters: []
  Enabled Linters: []
  Ignored Linters: []
 Suggested Fixers:
  '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.
 Linter Variables:
 Global Variables:
let g:ale_cache_executable_check_failures = v:null
let g:ale_change_sign_column_color = v:null
let g:ale_command_wrapper = v:null
let g:ale_completion_delay = 100
let g:ale_completion_enabled = 1
let g:ale_completion_max_suggestions = 50
let g:ale_disable_lsp = 0
let g:ale_echo_cursor = 1
let g:ale_echo_msg_error_str = 'Error'
let g:ale_echo_msg_format = '[%linter%] %s [%severity%]'
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 = 1
let g:ale_fixers = {'rust': ['rustfmt', 'trim_whitespace', 'remove_trailing_lines']}
let g:ale_history_enabled = 1
let g:ale_history_log_output = 1
let g:ale_keep_list_window_open = v:null
let g:ale_lint_delay = 200
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 = {'rust': ['analyzer']}
let g:ale_linters_explicit = 0
let g:ale_linters_ignore = {}
let g:ale_list_vertical = v:null
let g:ale_list_window_size = v:null
let g:ale_loclist_msg_format = v:null
let g:ale_max_buffer_history_size = v:null
let g:ale_max_signs = v:null
let g:ale_maximum_file_size = v:null
let g:ale_open_list = v:null
let g:ale_pattern_options = v:null
let g:ale_pattern_options_enabled = v:null
let g:ale_root = {}
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 = 1
let g:ale_sign_error = '✘'
let g:ale_sign_info = v:null
let g:ale_sign_offset = v:null
let g:ale_sign_style_error = v:null
let g:ale_sign_style_warning = v:null
let g:ale_sign_warning = '⚠'
let g:ale_sign_highlight_linenrs = v:null
let g:ale_statusline_format = ['✘ %d', '⚠ %d', '']
let g:ale_type_map = v:null
let g:ale_use_neovim_diagnostics_api = 0
let g:ale_use_global_executables = v:null
let g:ale_virtualtext_cursor = 'all'
let g:ale_warn_about_trailing_blank_lines = 1
let g:ale_warn_about_trailing_whitespace = 1
ghost commented 1 year ago

Same here. ale seems to do this: golangci-lint run file.go

ghost commented 1 year ago

Fixed that by adding let g:ale_go_golangci_lint_package=1 to my vimrc. This should be the default, honestly.

milosgajdos commented 1 year ago

Fixed that by adding let g:ale_go_golangci_lint_package=1 to my vimrc. This should be the default, honestly.

Ah, thanks, I did the same thing but forgot to come here to update this issue 😅

hsanson commented 8 months ago

g:ale_go_golangci_lint_package is now enabled by default: https://github.com/dense-analysis/ale/pull/4730