Skip to content

Disable composite warnings #2502

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
AckslD opened this issue Sep 20, 2019 · 4 comments
Closed

Disable composite warnings #2502

AckslD opened this issue Sep 20, 2019 · 4 comments

Comments

@AckslD
Copy link

AckslD commented Sep 20, 2019

What did you do? (required: The issue will be closed when not provided)

After updating to latest version (031b81c) vim-go has become unusable for me. It keeps warning about composites: xxx composite literal uses unkeyed fields (govet) every 10 seconds or so and jumping to a line with this warning, without me executing any command or saving the file.

What did you expect to happen?

Not to continuously jump to a line with a composite warning every 10 seconds without the file being saved.

Configuration (MUST fill this out):

vim-go version:

I'm using Plug and am at hash 031b81c

vimrc you used to reproduce (use a minimal vimrc with other plugins disabled; do not link to a 2,000 line vimrc):

" All lists are of type quickfix                                                                         
let g:go_list_type = "quickfix"                                                                              
                                                                                                                   
" Auto import when saving                                                            
let g:go_fmt_command = "goimports"                                                                                                                  
                                                                                                    
" More highlighting                                                                                                                                 
let g:go_hightlight_types = 1                                                        
let g:go_hightlight_fields = 1                                                                                       
let g:go_hightlight_functions = 1                                                                                   
let g:go_hightlight_function_calls = 1                                                                                           
let g:go_hightlight_operators = 1                                                                             
let g:go_hightlight_extra_types = 1                                                                                    
                                                                                     
" Go linter on save                                                                                     
let g:go_metalinter_autosave = 1                                                                                  
                                                                                                                   
" Auto type info                                                                                                      
let g:go_auto_type_info = 1
                                                                                                                      
" Auto identifier highlight                                                                                             
let g:go_auto_sameids = 1

au FileType go nmap <leader>b <Plug>(go-build)                                                                  
au FileType go nmap <leader>r <Plug>(go-run)                                                  
au FileType go nmap <leader>c <Plug>(go-coverage-toggle)                                                                                 
au FileType go nmap <leader>t <Plug>(go-test)                                                                                                       
au BufNewFile,BufRead *.go setlocal expandtab tabstop=4 shiftwidth=4

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Plugins (vim-plug)
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Install if needed
if empty(glob('~/.local/share/nvim/site/autoload/plug.vim'))
  silent !curl -fLo ~/.local/share/nvim/site/autoload/plug.vim --create-dirs
    \ https://github.com/raw/junegunn/vim-plug/master/plug.vim
  autocmd VimEnter * PlugInstall --sync | source ~/.config/nvim/init.vim
endif

call plug#begin('~/.local/share/nvim/plugged')

" Go
Plug 'fatih/vim-go'
" Python
Plug 'davidhalter/jedi-vim'
" Autocomplete
Plug 'Shougo/deoplete.nvim', { 'do': ':UpdateRemotePlugins' }
" Autocomplete python
Plug 'zchee/deoplete-jedi'
" TabNine autocomplete
Plug 'tbodt/deoplete-tabnine', { 'do': './install.sh' }
" Latex
Plug 'lervag/vimtex'
" Airline for vim
Plug 'vim-airline/vim-airline'
" Comment with gcc
Plug 'tpope/vim-commentary'
Plug 'nvie/vim-flake8'
" Git merge conflicts
Plug 'tpope/vim-fugitive'

call plug#end()

Vim version (first three lines from :version):

NVIM v0.3.8

Go version (go version):

go version go1.12.6 linux/amd64

@bhcleek
Copy link
Collaborator

bhcleek commented Sep 20, 2019

Since you have g:go_metalinter_autosave=1, the most likely culprit is that you have something that's saving the file regularly. Since you're using Plug, but there's no Plug calls in your vimrc, I presume that you've elided some relevant bits from your vimrc.

Short of figuring out what's causing your file to be saved every 10 seconds (if that's what's happening), then you may also try any or all of these that you prefer:

  • set those fields in struct literals (:GoKeyify makes this pretty easy)
  • disable the vet check for the metalinter on save (see :help g:go_metalinter_autosave_enabled)
  • set g:go_jump_to_error to avoid jumping to the errors

@AckslD
Copy link
Author

AckslD commented Sep 21, 2019

@bhcleek Thanks for your reply! I update the vimrc with the Plug calls I have. I like the linting on save, I just don't see why not setting the field-names should be a linting error and if there is a way to keep the linter on save but not check for this warning. I don't know what might be saving continuously, I could try to investigate whether this is actually the case.

@bhcleek
Copy link
Collaborator

bhcleek commented Sep 21, 2019

Checking for unkeyed fields in struct literals is default go vet behavior. The linting you're seeing is coming from golangci-lint, and there's an open issue there to be able to disable the composite check: golangci/golangci-lint#446.

go vet added this check quite some time ago, because using unkeyed literals is a bug waiting to happen. Imagine that you have this code:

type Foo struct {
    Bar string
    Baz string
}

and some other place that uses it:

foo := Foo {
    "bar",
    "baz",
}

and later you refactor the type by swapping the position of the fields:

type Foo struct {
    Baz string
    Bar string
}

Suddenly, foo is putting the values "bar" and "baz" into the wrong fields of the struct.

@AckslD
Copy link
Author

AckslD commented Sep 21, 2019

@bhcleek Thanks again for being responsive! I might try to refactor my code. Otherwise I'll checkout the issue you linked for the golangci-lint.

@AckslD AckslD closed this as completed Sep 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants