在vscode和lvim上配置ruff

ruff

ruff是用 Rust 编写的一个非常快的 Python linter 和代码格式化的程序。

Linting the CPython codebase from scratch.

命令行使用

# install
pip install ruff

# linter
ruff check .          # Lint all files in the current directory.
ruff check . --fix    # Lint all files in the current directory, and fix any fixable errors.
ruff check . --watch  # Lint all files in the current directory, and re-lint on change.
# formatter
ruff format .  # Format all files in the current directory.

ruff配置

参考这个视频 [Ruff] 是 {Python} 开发的未来 和他的 pyproject.toml 配置文件

lsp配置

lvim

LunarVim 中使用 ruff-lsp 需要一些配置。

  • 安装:
    :LspInstall ruff_lsp
    
    或者在mason面板找到ruff-lsp,按 i 键安装。
  • 按照官网给的例子进行配置。
    我使用下来发现需要额外配置的功能是formathover,其他功能像codeaction使用lvim原本的配置就能使用,即<space>la
    但是format无法正常使用,我按照官网的配置设置过一次,能正常使用了,注释之后还能使用,可能这个设置没有被覆盖把。
  • 效果
    我是联合pyrighe一起用的,最后在打开python文件时右下角的会显示 [pyright, ruff_lsp]

vscode

在vscode里使用插件ruff-vscode

ruff-vscode.png

可以参考视频typing 标准库,让 IDE 重新拥有提示对vscode打开类型提示。

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容