Vimjas / vint

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

Feature request: warn about missing `autocmd!` from `augroup` #126

Open lencioni opened 9 years ago

lencioni commented 9 years ago

Usually when defining an augroup, you want to include autocmd! at the top to clear any old autocommands before defining new ones. More info: http://learnvimscriptthehardway.stevelosh.com/chapters/14.html

It might be nice for vint to warn about augroups that are missing an autocmd! at the top. What do you think?

Kuniwak commented 9 years ago

Sound good.

How about these examples?

Examples

Good:

augroup Foo
  autocmd!
  autocmd BufNewFile * put ='Nyan'
augroup END
augroup Foo
  autocmd! BufNewFile * put ='Nyan'
  " :au[tocmd]! [group] {event} {pat} [nested] {cmd} should be allowed,
  " because this command is a short-hand equivalent to the first case.
augroup END
augroup Foo
  " Comment node placed before autocmd! should be allowed.
  autocmd!
  autocmd BufNewFile * put ='Nyan'
augroup END

Bad:

augroup Foo
  autocmd BufNewFile * put ='Nyan'
  " autocmd! not found.
augroup END
augroup Foo
  autocmd! BufNewFile *
  " Partial removing should not be allowed.
augroup END
autocmd! Foo
augroup Foo
  autocmd BufNewFile * put ='Nyan'
augroup END
" It should not allowed because there are many similar cases.
" I want to keep allowed notations lean.
augroup Foo
  autocmd! Foo
  autocmd BufNewFile * put ='Nyan'
augroup END
" Same reason.

Limitation

We cannot check the case:

lencioni commented 9 years ago

:+1: