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

sh checker for ksh93 on AIX shows fizsh shell like behaviour #2358

Closed XSven closed 3 years ago

XSven commented 3 years ago

This issue refers to _syntaxcheckers/sh/sh.vim. The issue considers 3 topics errorformat, login shell vs. shebang shell, and shellredir. It is not yet an option to use shellcheck on AIX because it is somewhat hard to build it.

A command-line check of a broken.sh script using the shells

bash (version 5.0.0(2)-release) ksh93 (Version M 93t+ 2009-05-01) ksh (Version M-11/16/88f)

has the output

./broken.sh: line 6: syntax error: unexpected end of file
./broken.sh: syntax error at line 6: `{' unmatched
./broken.sh[3]: 0403-057 Syntax error at line 3 : `{' is not matched.

Two items have to be added to the errorformat!

let errorformat =
     \ '%f: line %l: %m,' .
     \ '%f: syntax error at line %l: %m,' .
     \ '%f[%l]: %m'

If I am using ksh as my login shell and inside broken.sh bash as shebang shell, syntastic sh checker works.

If I am using ksh as my login shell and inside broken.sh ksh93 as shebang shell (#!/usr/bin/ksh93), syntastic sh checker works, but it uses the login shell ksh instead the shebang shell ksh93 to run the check

SyntasticMake: called with options: {'errorformat': '%f: line %l: %m,%f: syntax error at line %l: %m,%f[%l]: %m', 'makeprg': 'ksh -n ./broken.sh'}

If I am using ksh93 as my login shell and inside broken.sh ksh93 as shebang shell (#!/usr/bin/ksh93), syntastic sh checker does not work.

SyntasticMake: called with options: {'errorformat': '%f: line %l: %m,%f: syntax error at line %l: %m,%f[%l]: %m', 'makeprg': 'ksh93 -n ./broken.sh'} ksh93 runs the check. That is correct but the vim shellredir option is set to '>'. After change it with

set shellredir=>%s\ 2>&1

syntastic sh checking works.

lcd047 commented 3 years ago

Two items have to be added to the errorformat!

I have updated errorformat to match ksh93 messages.

If I am using ksh as my login shell and inside broken.sh ksh93 as shebang shell (#!/usr/bin/ksh93), syntastic sh checker works, but it uses the login shell ksh instead the shebang shell ksh93 to run the check

Syntastic only recognizes bash, zsh, and sh in the shebang, then fall back to the login shell. It's a half-assed attempt, but there is no point in trying to use the actual shebang for checks because there is no guarantee random shells will produce errors in a known format (as you already found out). You can override this by setting:

let g:syntastic_sh_sh_exe = 'ksh93'

(but you don't get autodetection).

That is correct but the vim shellredir option is set to '>'.

The default is Vim's doing, and syntastic doesn't try to find out if it's appropriate or not. It's up to you to make sure you have a working system() and that calling it doesn't lose error messages. Syntastic is a Vim script (and a dead one at that), not a full OS. It won't try to accommodate everything you could possibly throw at it. shrug