vim-syntastic / syntastic

Syntax checking hacks for vim
Do What The F*ck You Want To Public License
11.3k stars 1.14k forks source link

Use shebang to enable syntastic. #2272

Closed bartoszek closed 5 years ago

bartoszek commented 5 years ago

Would be nice if #!/hint also enable syntastic, not only file extension Or am I doing something wrong :thinking: asciicast

lcd047 commented 5 years ago

Syntastic doesn't know, nor particularly cares, about file extensions. What it does instead is run checkers based on the filetypes provided by Vim. Now, filetype detection is Vim's job, syntastic just uses the result without questioning where / how / why the current filetype came to be. So if you want syntastic to run properly you need to make sure the filetypes associated to your files are correct.

As far as I can tell the filetype for PKGBUILD should be sh. If automatic detection fails for your particular script for whatever reason, you can override it with a comment like this at the end of the file:

# vim: set filetype=sh

This will fix a number of things, and also tell syntastic your file is a shell script that can be checked as any other sh file.

bartoszek commented 5 years ago

Thanks for a clarifying, it makes a lot more sense now. I've noticed that vim has a defined filetype for a PKGBUILD (set filetype? > filetype=PKBUILD). Is there a way to incorporate a new filetype in syntastics configuration? I've treid leverage autocmd with b:syntastic_checkers but without success. asciicast

lcd047 commented 5 years ago

I've noticed that vim has a defined filetype for a PKGBUILD (set filetype? > filetype=PKBUILD).

As far as I can tell the PKGBUILD filetype is added by a standalone plugin (or some such), not by plain Vim. But yes, syntastic does have mechanisms to cope with that. F.i. like this:

let g:syntastic_filetype_map = { 'PKGBUILD': 'sh' }

(cf. :h 'syntastic_filetype_map').

bartoszek commented 5 years ago

Yep, works like a charm, appreciate your help :+1: