6

When using the shellcheck checker, Flycheck will warn me that the "$@" in the following will be expanded on the client rather than the ssh server. Which is a helpful warning, but yeah I know and I'm good. So is it possible to suppress this warning; better yet if it's for just this one line.

function f(){ ssh foo "$@" ; }

  • Neither bash nor flycheck gives me that warning. Do you have any flags set in bash that will trigger the warning (so that I can test a potential answer)? – J David Smith Oct 8 '14 at 13:32
8

Thanks J David for forcing me to look more deeply.

flycheck.el defines sh-bash, the checker used for bash; and that has a next-checker known as sh-shellcheck. Ans, as Jordon is points out, that invokes shellcheck

Poking around in 2 reveals how to supress warning in a selective manner:

function f(){    
   # shellcheck disable=SC2029
   ssh foo "$@" 
}

ssh foo "$@"

Finding that number SC2029, was tedious and in the end I ran shellcheck directly.

If one is having this problem with other flycheck variations you need to track down, what checker(s) are being used, and then how that checker handles adjusting the checks.

After I get the pony I've been wishing for I'll wish for a command in flycheck that just adds a line like that based on it's awesome comprehension of the file mode, the checker, etc. etc.

  • 2
    M-x flycheck-compile will show the raw output of a checker, and you can use that to discover the ID of the warning. – Ben Hyde Oct 8 '14 at 15:04
5

As of 40469d5, Flycheck includes the warning code of ShellCheck in the messages, and provides a new option flycheck-shellcheck-excluded-warnings to exclude warnings from ShellCheck reports.

To suppress a ShellCheck warning for Flycheck, use the error list at C-c ! l to find out the corresponding error code (in square brackets at the end of the message), and add it to flycheck-shellcheck-excluded-warnings.

To globally suppress SC2029, add the following to your init.el:

(setq-default flycheck-shellcheck-excluded-warnings '("SC2029"))

To suppress this type just for a specific file, type M-x add-file-local-variable RET flycheck-shellcheck-excluded-warnings RET ("SC2029").

Note that these suppressions only work for Flycheck. The message still appears if you run ShellCheck from the terminal, or as part of your CI or testing system. To suppress a message for all instances of ShellCheck, as in this answer.

  • I upgraded to the latest flycheck, but still see no error code at the end of the message? Do you have any clue? – Lungang Fang Nov 5 '15 at 15:43
  • @lgfang Do you see error codes in the error list? Do you have the latest shellcheck? – lunaryorn Nov 6 '15 at 18:12
  • First of all, thank you. I cannot see error codes in error list. The shellcheck version is: 0.3.3, flycheck version is 0.25snapshot (package: 20151104.213) – Lungang Fang Nov 9 '15 at 4:36
  • Just found that it worked after restarting emacs. At first, I simply upgraded and reloaded flycheck but didn't restart emacs. Thank you. – Lungang Fang Nov 9 '15 at 4:47
4

The only way you would get that error is if you were using the shellcheck checker, in order to remove these warnings you need to customize the command flycheck is using for shellcheck, there is no built in way to customize the existing shellcheck checker, but you can create a new checker with that feature.

You'll need to create a new flycheck checker that is just like the existing shellcheck checker but makes use of the "-e" option that allows you to exclude errors types.

  (defvar shellcheck-exclude-types '("SC2029")
  "Shellcheck error types to exclude from flycheck")

(flycheck-define-checker sh-my-shellcheck
  "Custom shellcheck checker"
  :command ("shellcheck" "-f" "checkstyle"
        ;; here we join all the exclude types in the -e option
        ;; like: -e=SC2029,sc20xxx,...
        ;; this is the only NEW line to the existing shellcheck checker
        (eval (concat "-e=" (string-join shellcheck-exclude-types ",")))
        "-s" (eval (symbol-name sh-shell))
            source)
  :modes sh-mode
  :error-parser flycheck-parse-checkstyle
  :predicate (lambda () (memq sh-shell flycheck-shellcheck-supported-shells)))

I found that SC2029 is the code for that kind of error by running shellcheck from the command line on the file, I have no idea where all the codes are documented.

Once you have your checker defined, you'll need to activate it.

One way to do it is:

(add-hook 'sh-mode-hook (lambda () (flycheck-select-checker 'sh-my-shellcheck)))
  • 2
    Flycheck maintainer here. I was not aware that Shellcheck provides options to suppress certain warnings. Please open an issue, and I'll add corresponding defcustoms, so that you can use local variables to enable these supressions. – lunaryorn Oct 8 '14 at 14:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.