• Stars
    star
    405
  • Rank 106,656 (Top 3 %)
  • Language
    TypeScript
  • License
    Other
  • Created about 2 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A Visual Studio Code extension with support for the Ruff linter.

Ruff extension for Visual Studio Code

Ruff image image image Actions status

A Visual Studio Code extension with support for the Ruff linter. Available on the Visual Studio Marketplace.

The extension ships with ruff==0.0.287.

(Interested in using Ruff with another editor? Check out ruff-lsp.)

Highlights

"Quick Fix" actions for auto-fixable violations (like unused imports)

Demo of Ruff's "Quick Fix" action

"Fix all": automatically fix all auto-fixable violations

Demo of Ruff's "Fix all" action

"Organize Imports": isort-compatible import sorting

Demo of Ruff's "Organize Imports" action

Usage

Once installed in Visual Studio Code, ruff will automatically execute when you open or edit a Python file.

If you want to disable Ruff, you can disable this extension per workspace in Visual Studio Code.

Settings

Settings Default Description
args [] Additional command-line arguments to pass to ruff, e.g., "args": ["--config=/path/to/pyproject.toml"]. Supports a subset of Ruff's command-line arguments, ignoring those that are required to operate the LSP, like --force-exclude and --verbose.
path [] Path to a custom ruff executable, e.g., ["/path/to/ruff"].
interpreter [] Path to a Python interpreter to use to run the linter server.
importStrategy fromEnvironment Strategy for loading the ruff executable. fromEnvironment picks up Ruff from the environment, falling back to the bundled version if needed. useBundled uses the version bundled with the extension.
run onType Run Ruff on every keystroke (onType) or on save (onSave).
enable true Whether to enable the Ruff extension. Modifying this setting requires restarting VS Code to take effect.
organizeImports true Whether to register Ruff as capable of handling source.organizeImports actions.
fixAll true Whether to register Ruff as capable of handling source.fixAll actions.
codeAction.fixViolation.enable true Whether to display Quick Fix actions to autofix violations.
codeAction.disableRuleComment.enable true Whether to display Quick Fix actions to disable rules via noqa suppression comments.
showNotification off Setting to control when a notification is shown: off, onError, onWarning, always.

Example configurations

You can configure Ruff to autofix violations on-save by enabling the source.fixAll action in settings.json:

{
  "[python]": {
    "editor.codeActionsOnSave": {
      "source.fixAll": true
    }
  }
}

You can configure Ruff to organize imports on-save by enabling the source.organizeImports action in settings.json:

{
  "[python]": {
    "editor.codeActionsOnSave": {
      "source.organizeImports": true
    }
  }
}

If you're using the VS Code Python extension, you can configure VS Code to autofix violations on-save using Ruff, then re-format with Black, via the following settings.json:

{
  "[python]": {
    "editor.formatOnSave": true,
    "editor.codeActionsOnSave": {
      "source.fixAll": true
    }
  },
  "python.formatting.provider": "black"
}

If you'd like to use Ruff as an autofix linter, but continue to sort imports with the isort VS Code extension, you can disable Ruff's import-sorting capabilities via the following settings.json:

{
  "[python]": {
    "editor.codeActionsOnSave": {
      "source.fixAll": true,
      "source.organizeImports": true
    }
  },
  "ruff.organizeImports": false
}

If you'd like to run Ruff on-save, but avoid enabling other extensions to run on-save, you can use Ruff's scoped source.fixAll and source.organizeImports actions via the following settings.json:

{
  "[python]": {
    "editor.codeActionsOnSave": {
      "source.fixAll.ruff": true,
      "source.organizeImports.ruff": true
    }
  }
}

If you'd like to run Ruff in lieu of another formatter altogether, be sure to unset the editor.defaultFormatter in settings.json:

{
  "[python]": {
    "editor.defaultFormatter": null,
    "editor.codeActionsOnSave": {
      "source.fixAll": true
    }
  }
}

Commands

Command Description
Ruff: Fix all auto-fixable problems Fix all auto-fixable problems.
Ruff: Restart Server Force restart the linter server.

Requirements

This extension requires a version of the VSCode Python extension that supports Python 3.7+. Ruff itself is compatible with Python 3.7 to 3.11.

Development

This extension is based on the Template for VS Code Python tools extensions.

Getting Started

  • Install just, or see the justfile for corresponding commands.
  • Create and activate a virtual environment (e.g., python -m venv .venv && source .venv/bin/activate).
  • Install development dependencies (just install).
  • To automatically format the codebase, run: just fmt.
  • To run lint and type checks, run: just check.
  • To run tests, run: just test.

To run the extension, navigate to src/extension.ts and run (F5). You should see the LSP output and Python log messages in the debug console under "Python Server".

Modifying the LSP

  • Clone ruff-lsp to, e.g., ../ruff-lsp.
  • In ../ruff-lsp, run: pip install -t ../ruff-vscode/bundled/libs/ -e ..

Using a custom version of ruff

  • Clone ruff to, e.g., /home/ferris/ruff.
  • Run cargo build in the Ruff repository.
  • Set "Ruff: Path" to /home/ferris/ruff/target/debug/ruff in the VS Code settings.

License

MIT

More Repositories

1

ruff

An extremely fast Python linter, written in Rust.
Rust
15,164
star
2

whisper.cpp-cli

Packages whisper.cpp into pre-built, pip-installable wheels, for macOS and Linux.
Python
157
star
3

ruff-lsp

A Language Server Protocol implementation for Ruff.
Python
142
star
4

ruff-pre-commit

A pre-commit hook for Ruff.
Python
134
star
5

script

JavaScript implementation of Script, Bitcoin's scripting language.
JavaScript
118
star
6

semantic

A Python library for extracting semantic information from text, such as dates and numbers.
Python
74
star
7

autobot

GitHub Copilot, for your existing codebase.
Python
71
star
8

point-location

Kirkpatrick's Algorithm for Log(n) point location in planar subdivisions.
Python
68
star
9

online_boosting

A suite of boosting algorithms for the online learning setting.
Python
61
star
10

java-ml

Java implementations of several Machine Learning classification algorithms.
Java
54
star
11

trellis

Write Dockerfiles and CI pipelines in TypeScript.
TypeScript
35
star
12

android-lite

A 26 KB-take on the Khan Android app.
Java
23
star
13

OCaml-SAT-Solvers

An OCaml implementation of the DPLL algorithm for solving SAT instances. Uses nothing beyond the OCaml List library.
OCaml
18
star
14

altcoin-analysis

Quantitative analysis of altcoins, or "Bitcoin alternatives."
Python
10
star
15

ocaml-futures

True OCaml futures using UNIX processes and pipes.
OCaml
9
star
16

graph-matching

An implementation of the 'Matching with our Eyes Closed' algorithm for generating a randomized matching for a non-bipartite graph in an online manner.
Python
7
star
17

es6-npm-boilerplate

Boilerplate for authoring in ES6 and publishing in ES5.
JavaScript
6
star
18

mongoose-proptypes

Generate React PropTypes for your Mongoose schema.
JavaScript
6
star
19

notes

LaTeX notes from a variety of Princeton Computer Science courses.
TeX
4
star
20

charliermarsh

4
star
21

ruff-action

GitHub Action for Ruff
3
star
22

valid-media-queries

Validates CSS media queries.
JavaScript
3
star
23

sweet-rcss

A quick experiment in sweeting your JavaScript for use with RCSS.
JavaScript
1
star
24

pycon-us-2024

1
star
25

iOS-Elements

Some iOS modules and UI elements pulled together over various projects.
Objective-C
1
star