'Force flycheck mode to turn off in emacs when working with remote (tramp) python files but not locally

I am trying to make flycheck run locally for Python files, but not have flycheck run when working with python files on a remote machine. I have the problem that flycheck slows down saving and it seems to send a second file that sometimes ends up freezing up emacs. I wrote the two functions below but it doesn't seem to work correctly. I want it to disable fly-check if it is a remote file (connected through tramp) or enable flycheck-mode for all other python files. Currently, it just enables flycheck mode for all files.

(when (require 'flycheck nil t)
  (setq elpy-modules (delq 'elpy-module-flymake elpy-modules))
  (add-hook 'elpy-mode-hook 'jj/flycheck-mode))
(defun jj/flycheck-mode ()
  "Don't enable flycheck mode for remote buffers."
  (interactive)
  (if (file-remote-p default-directory)
      (flycheck-mode nil)
    (flycheck-mode t)))

Any way to fix this script? Or another approach?



Solution 1:[1]

To fix this script just replace (flycheck-mode nil) by (flycheck-mode -1).

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 nil