2

I am using flycheck for for Python. I want flycheck to detect any errors right away when any Python file is opened. Currently it can detect if there is a modification and save operation is performed.

Let's say I have following code in hello.py file:

#!/usr/bin/env python3

import os

print(os.getpid())

Than I have commented out print(os.getpid()) and close the file and reopened it. At this stage flycheck does not detect that 'os' imported but unused [F401]. I have to make some moditifications and save the file for it do detect it.


my setup:

(require 'flycheck)
(require 'flycheck-mypy)

(setq python-shell-interpreter "python3"
      python-shell-prompt-detect-failure-warning nil
      flycheck-python-pycompile-executable "python3"
      python-shell-completion-native-enable nil
      python-shell-completion-native-disabled-interpreters '("python3")
      elpy-shell-echo-output nil ; 
      )

(add-hook 'python-mode-hook
      (lambda ()
        ;; (setq flycheck-mypyrc "~/venv/bin/pylint")
        (setq flycheck-python-pylint-executable "~/venv/bin/pylint")
        (local-set-key (kbd "C-c C-b") 'break-point)
        (setq flycheck-pylintrc "~/.pylintrc")))

I am also using Getting flycheck “jump to next/previous error” to cycle, it won't also able to detect it till save is done.

alper
  • 1,238
  • 11
  • 30

1 Answers1

2

You can try the following:

(setq flycheck-check-syntax-automatically '(save idle-buffer-switch idle-change new-line mode-enabled)
      flycheck-idle-buffer-switch-delay 0)

This tells flycheck to run immediately "after you switch to a buffer". The other choices like save, idle-change, new-line, and mode-enabled are already configured as the default choices. The second option reduces the delay before the check is triggered. There is also flycheck-idle-change-delay which you can reduce if you want.

Swarnendu Biswas
  • 1,378
  • 1
  • 11
  • 24