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"))) 
Drew
  • 75,699
  • 9
  • 109
  • 225
alper
  • 1,238
  • 11
  • 30

1 Answers1

2

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.

Ian
  • 1,321
  • 10
  • 12
  • 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 '21 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 '21 at 05: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 '21 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 '21 at 11:52
  • To answer you the question about "flake8rc": if it works for you as its is now, then it is OK. For the second one - you do not need to mix with flycheck-compile or pylint; with lsp they are all *live* enabled and used automatically; just use a buggy file and you will see the results from all tools enabled. – Ian Aug 30 '21 at 12:12
  • Ah I miss checked, warnings show up few seconds later still I am not able to disable warnings for `D100` :( I have tried adding `(setq lsp-pylsp-plugins-flake8-ignore ["D100"])` into emacs file and also added it into `~/.pylintrc`, ~/. flake8rc `, `/project/setup.cfg` but warning message does not goes way – alper Aug 30 '21 at 18:30
  • Try to run from terminal ```flake8``` on your buggy file - if error is still unrecognised, then check your ```flake8rc``` file or your ```flake8``` installation (dependencies: ```flake8-docstrings```?); if the error is recognised , then in emacs : C-h v ```flycheck-flake8rc``` or ```lip-diagnostic-flycheck-default-level```. – Ian Aug 31 '21 at 07:40
  • It would be helpful to try also doom-emacs, a lot of things to learn from. – Ian Aug 31 '21 at 07:42
  • Sorry for keep asking questions related to this. Emacs disables all the definitions I have in my `.pylintrc`(https://gist.github.com/avatar-lavventura/00317b01ee84f2b073dea378999386aa) but only `D100` is not detected to be disaabled :-( `flycheck-flake8rc => Local in buffer Driver.py; global value is "~/.config/flake8"` and `lip-diagnostic-flycheck-default-level` variable does not exist – alper Aug 31 '21 at 12:23
  • Where did you find out this "D100"? the only reference I can find out on Google is related to the Atom editor; if you know the real doc for this message please tell me. What is the text message associated to this code? (read it in emacs) - and post it. – Ian Aug 31 '21 at 16:04
  • I keep seeing: `D100: Missing docstring in public module [D100]` for not having doc under `#!/usr/bin/env python3` – alper Aug 31 '21 at 16:08
  • 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 01 '21 at 07:37
  • ```[pydocstyle]``` should be on single row. – Ian Sep 01 '21 at 08:05
  • I added `[pydocstyle] ignore = D100 ` into `setup.cfg` and the warning is gone! Thank you for your patient responses – alper Sep 01 '21 at 09:58