vint icon indicating copy to clipboard operation
vint copied to clipboard

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

Open lencioni opened this issue 10 years ago • 2 comments

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?

lencioni avatar Apr 14 '15 02:04 lencioni

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:

  • https://github.com/google/vim-maktaba/blob/a5f242b8566e15db97aed04df3beb42557900679/autoload/maktaba/autocmd.vim

Kuniwak avatar Apr 17 '15 03:04 Kuniwak

:+1:

lencioni avatar Apr 17 '15 23:04 lencioni