0

In sh-mode I am getting following flycheck-error message:

File   Line [v]ColLevel   ID     Message (Checker)
config.sh  2     error           Syntax error: "(" unexpected (sh-posix-dash)

for the following line: strings=("hello" "world") . But this is actually a valid expression in bash.

complete file:

#!/bin/bash

strings=("hello" "world")

init.el file has following lines, reference:

(define-derived-mode my-cfg-mode sh-mode "My CFg Mode"
 "A mode for my CFg files."
 (sh-set-shell "bash"))

Is it possible to suppress this warning message?

alper
  • 1,238
  • 11
  • 30
  • Can't reproduce it: `flycheck` is happy with it. What does the complete file look like? Is there a shebang on line 1? And what is `sh-posix-dash`? – NickD Dec 06 '22 at 22:32
  • @NickD `sh-posix-dash` is one of the shell checkers in `flycheck` – nega Dec 06 '22 at 23:00
  • 2
    @alper if you're using bash, use the bash checker. – nega Dec 06 '22 at 23:00
  • @NickD Yes sir there is `#!/bin/bash` line (updated on my question). `flycheck-sh-posix-dash-executable` is set to `nil` – alper Dec 07 '22 at 09:51
  • @nega How can I set `bash checker` from the init.el file? – alper Dec 07 '22 at 09:52
  • I have no idea where did `sh-posix-dash` come from, `(with-eval-after-load 'flycheck (setq-default flycheck-disabled-checkers '(sh-posix-dash)))` solved the problem – alper Dec 07 '22 at 14:45
  • @alper great! feel free to post that as an answer and accept it – nega Dec 07 '22 at 15:41

1 Answers1

0

As checker sh-posix-dash was enabled. When I add following lines into my init.el file the problem is solved.

(with-eval-after-load 'flycheck   
    (setq-default flycheck-disabled-checkers '(sh-posix-dash)))

As @Ian mention core cause was due to following lines, hence also removing those lines from my init.el file was also resolved the conflict:

(define-derived-mode my-cfg-mode sh-mode "My CFg Mode"
"A mode for my CFg files."
(sh-set-shell "bash"))
alper
  • 1,238
  • 11
  • 30
  • 1
    I think you have a chicken-egg problem: why did you added those three lines in your ```init.el``` file? You did not copied the whole example, which defines a derived mode for a ```.cfg``` file, while your file is still a ```.sh``` file, so you created yourself a problem. Try to remove those lines, you do not need them to have correct behavior. Neither to disable a checker. – Ian Dec 08 '22 at 09:06
  • @Ian Honestly I couldn't remember why I added those three lines(indicated in my question) in my `init.el` file :-( I was thinking they are required for something I was using but instead they were causing conflict like you mentioned. I updated my answer, please feel free to edit – alper Dec 08 '22 at 10:27