Skip to content
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

Don't require explicit scoping on function variables #381

Open
idbrii opened this issue Sep 28, 2022 · 0 comments
Open

Don't require explicit scoping on function variables #381

idbrii opened this issue Sep 28, 2022 · 0 comments

Comments

@idbrii
Copy link

idbrii commented Sep 28, 2022

I don't understand why vint encourages people to make their vimscript less readable by including extra decoration on variables.

I often have code like this:

function! health#lsp#check() abort
    call health#report_start('server status')
    let server_status = lsp#collect_server_status()
    " ...
endf

And I get this warning:

Make the scope explicit like l:server_status (see Anti-pattern of vimrc (Scope of identifier))

However, Anti-pattern of vimrc (Scope of identifier) says:

When you use a variable without a scope outside a function, implicitly its scope is global scope(g:). Generally when you use a variable outside a function, you have to define it with script scope(s:).

The variable isn't used outside a function, so it's implicitly locally scoped. See :help local-variable:

Inside functions local variables are accessed without prepending anything. But you can also prepend "l:" if you like. However, without prepending "l:" you may run into reserved variable names. For example "count". By itself it refers to "v:count". Using "l:count" you can have a local variable with the same name.

vint should definitely warn if you use any reserved variable name without l: but I think generally being able to recognize undecorated variable names --> local is helpful and it makes g: or s: stand out more.

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

1 participant