惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - 三生石上(FineUI控件)
MyScale Blog
MyScale Blog
爱范儿
爱范儿
Y
Y Combinator Blog
Last Week in AI
Last Week in AI
博客园 - Franky
MongoDB | Blog
MongoDB | Blog
aimingoo的专栏
aimingoo的专栏
T
Tailwind CSS Blog
Microsoft Azure Blog
Microsoft Azure Blog
Hugging Face - Blog
Hugging Face - Blog
博客园_首页
阮一峰的网络日志
阮一峰的网络日志
WordPress大学
WordPress大学
月光博客
月光博客
Martin Fowler
Martin Fowler
A
About on SuperTechFans
有赞技术团队
有赞技术团队
酷 壳 – CoolShell
酷 壳 – CoolShell
I
InfoQ
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
J
Java Code Geeks
博客园 - 聂微东
宝玉的分享
宝玉的分享

jdhao's digital space

Conversion between base64 and OpenCV or PIL Image 腾讯云对象存储博客图床开启 CDN 加速(不需要购买额外域名) Search and Replace in Multiple Files in Vim/Neovim Change Table Column Width in LaTeX Image or Table Side by Side in LaTeX LaTeX 并排显示图像或表格 Firenvim: Neovim inside Your Browser Content inside HTML tags missing in Latest Hugo? Creating Markdown Front Matter with Ultisnips Labelme JSON 标注格式转 voc XML 格式 Nifty Nvim Techniques That Make My Life Easier -- Series 6 macOS 下如何为视频制作字幕 Running Command Asynchronously inside Neovim Resolving Merge Conflict after Git Stash Pop Pylint: command not found? A Hands-on Experience with Neovim's Built-in LSP Support How to Convert PDF to Images with Imagemagick 互联网上常用缩略语集锦 File Backup in Neovim Converting PDF Pages to Images with Poppler Nifty Nvim Techniques That Make My Life Easier -- Series 5 Neovim Configuration for System-wide Use How to sort a list of tuple or list in Python -- lambda or itemgetter? Building A Vim Statusline from Scratch 人类第一颗原子弹爆炸始末 Distributed Training in PyTorch with Horovod Learning Expect Programming Essential Knowledge about SSH Nifty LaTeX Techniques -- Series 1 更改 Adsense 邮寄地址,重新寄送 PIN
Flake8 Config in Pyls for Code Linting.
2020-11-05 · via jdhao's digital space

Update 2021-07-15: Note that pyls has been deprecated. There is new fork of it called pylsp, which is maintained by the community.

In my previous post, I have go over the basic setup to make vim-lsp work. However, I haven’t touch on an important part of writing code: linting. It turns out that configure it correctly is harder than I thought.

I found the documentation of pyls to be vague and incomplete. It took me quite a few hours in order to understand how to configure flake8 correctly for pyls.

Pyls is a combination of different packages to form a unified workable language server. Flake8 is like a driver package for pycodestyle (former known as pep8 and got renamed) and pyflakes. In simple words, it uses pyflakes and pycodestyle and a few other packages to check your code for possible style issues and syntax errors.

By default, pyls disables flake8, and use pycodestyle and pyflakes for code checking directly. I do not want to configure two packages, I just want to configure flake8 for simplicity’s sake.

From here and the actual code, we can see that flake8 is indeed disabled. Also, if we use flake8, it makes sense to disable pycodestyle and pyflakes, otherwise we will get duplicated diagnostic messages.

if executable('pyls')
    " pip install python-language-server
    au User lsp_setup call lsp#register_server({
          \ 'name': 'pyls',
          \ 'cmd': {server_info->['pyls']},
          \ 'allowlist': ['python'],
          \ 'workspace_config': {
          \    'pyls':
          \        {'configurationSources': ['flake8'],
          \         'plugins': {'flake8': {'enabled': v:true},
          \                     'pyflakes': {'enabled': v:false},
          \                     'pycodestyle': {'enabled': v:false},
          \                    }
          \         }
          \ }})
endif

This is the correct config for pyls to use flake8 for linting, period.

config location#

According to flake8 documentation, the location of flake8 config varies based on systems, on Linux and Mac, it is ~/.config/flake8 , and for Windows, it is $HOME\.flake8 ($HOME is like C:\\Users\sigmavirus24). The content should be in INI format:

[flake8]
max-line-length = 100
max-complexity = 30
ignore =
    # missing whitespace around arithmetic operator
    E226,
    # line break before/after binary operator
    W503,
    W504,
    # expected 1 blank line, found 0
    E301,E302,

To suppress a single warning, it is also handy to add # noqa: F841-like (change the code to the actual code you want to use) comment string to suppress it.

References#