Vimjas / vint

Fast and Highly Extensible Vim script Language Lint implemented in Python.
MIT License
702 stars 33 forks source link

False error for optional function argument #383

Closed rottencandy closed 1 year ago

rottencandy commented 2 years ago

Vint gives an error for optional arguments in functions. For the example from :h optional-function-argument:

function Something(key, value = 10)
   echo a:key .. ": " .. a:value
endfunction

Error:

test.vim:1:31: unexpected token: = (see vim-jp/vim-vimlparser)
qadzek commented 1 year ago

EDIT: Forget what I wrote below, @rottencandy. This bug has been fixed, so I would suggest closing this issue.

You just need to install the latest commit. Uninstall the default pip version (pip uninstall vim-vint) and then run pip install git+https://github.com/Vimjas/vint.git.


I encountered the same bug. Optional function arguments have been supported since Vim 8.1.1310.

A workaround is described on Stack Overflow. Rewriting your example:

function Something(key, ...)
  let l:value = get(a:, 1, 10)
  echo a:key .. ": " .. l:value
endfunction
rottencandy commented 1 year ago

@infinitewhileloop thank you! Installing the git version does solve the issue!