0

My goal is to configure lsp in order to ignore warning messages for flycheck in Python version.

When lsp is not in use, flycheck reads from my ~/.pylintrc file in order to ignore warning messsages. But when I enable lsp-mode it does not ignore the warning messages that I set in ~/.pylintrc file.

minimal.el:

(defun flycheck-python-setup ()
  (flycheck-mode))
(require 'flycheck)
(require 'flycheck-mypy)
(add-hook 'after-init-hook #'global-flycheck-mode)
(add-hook 'after-init-hook #'global-flycheck-mode)
(add-to-list 'flycheck-disabled-checkers 'python-flake8)
(add-hook 'python-mode-hook
          (lambda ()
            (setq flycheck-python-pylint-executable "~/venv/bin/pylint")
            (setq flycheck-pylintrc "~/.pylintrc")
            (setq indent-tabs-mode  nil
                  python-indent-offset  4
                  tab-width         4)
            (let ((inhibit-message  t))
              )))
(use-package python :ensure nil)
(add-hook 'python-mode-hook #'flycheck-python-setup)
(flycheck-add-next-checker 'python-flake8 'python-pylint 'python-mypy)

Having following lines in order to enable lsp-mode, changes the result for helm-flycheck.

(add-hook 'python-mode-hook 'lsp)
(add-hook 'python-mode-hook #'lsp-deferred)

❯ cat ~/.pylintrc
disable=D100,  C0305, C0303, W291,  C0111, R0801, W0703, C0103,

Related: flycheck cannot find module for pylint, https://www.reddit.com/r/emacs/comments/b5lvx6/how_do_i_force_lspui_to_use_flake8/

(add-hook 'python-mode-hook
  (lambda ()
    (setq flycheck-python-pylint-executable "<your path to>/pylint")
    (setq flycheck-pylintrc "/home/tools/.pylintrc"))) 
2
  • What python lsp server do you have installed?
    – Ian
    Aug 27 at 14:05
  • @Ian its python-lsp-server==1.0.1
    – alper
    Aug 27 at 22:13
1
+50

Your python-lsp-server, named further pylsp as in lsp-pylsp.el file, can use pylint if it is enabled - you need the following code lines to be added to your lsp configuration block:

  ;; Adding pylint as linter for pylsp
  (require 'lsp-pylsp)
  (setq lsp-pylsp-plugins-pylint-enabled t)
  (setq lsp-pylsp-plugins-pylint-args ["--rcfile=/<absolute-path-to-home-dir/.pylintrc"]) ;; or path to your project.

Please note the lsp servers have their own checkers, and consequently when used, flycheck module should not be configured/used in any specific way - you should remove your posted configuration.

One note: your item D100 posted in your .pylintrc file belongs to flake8 - you may have a .flake8rc file in your path.

This can be corrected also at the lsp-pylsp level, see this: https://emacs-lsp.github.io/lsp-mode/page/lsp-pylsp/#lsp-pylsp-plugins-flake8-filename - configure the variable lsp-pylsp-plugins-flake8-ignore.

14
  • I have added (setq lsp-pylsp-plugins-flake8-ignore t) into my init file, as I understand that will ignore flake8rc file. Should I also make changes in ~/.config/flake8 file as well?
    – alper
    Aug 28 at 17:05
  • That variable is of type lsp-string-vector, which means you must write (setq-lsp-pylsp-plugins-flake8-ignore ["D100"]) - aka add to this list instead of .flake8rc file; but for other cases (aka if lsp is not in use) the error code should be also added in .flake8rc.
    – Ian
    Aug 29 at 5:41
  • Everything works fine on my end, but I haven't define any setq-lsp-pylsp-plugins-flake8-ignore ["D100"]) (should I also put it into .emacs file? sorry I just get lost for this line), I just put everything into .pylintrc under disable= and I did not also create any flake8rc file.
    – alper
    Aug 29 at 20:37
  • I want to apply flycheck after each save. For that should I do flycheck-compile and select python-pylint?
    – alper
    Aug 30 at 11:52
  • 2
    To remove the D100 error, add a ~/.pydocstyle file to your home dir, with the content: [pydocstyle] ignore = D100 . The same error is also generated by pylint, but with the code C0114, so you need to add this code to your .pylintrc file.
    – Ian
    Sep 1 at 7:37

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.