Coder Social home page Coder Social logo

simkimsia / ruff-vscode Goto Github PK

View Code? Open in Web Editor NEW

This project forked from astral-sh/ruff-vscode

0.0 1.0 0.0 1.03 MB

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

License: Other

Shell 3.15% JavaScript 2.45% Python 47.73% TypeScript 45.35% Just 1.32%

ruff-vscode's Introduction

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.289.

(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 the Black extension, via the following settings.json:

{
  "[python]": {
    "editor.formatOnSave": true,
    "editor.codeActionsOnSave": {
      "source.fixAll": true
    },
    "editor.defaultFormatter": "ms-python.black-formatter"
  }
}

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

ruff-vscode's People

Contributors

charliermarsh avatar harupy avatar konstin avatar akanz1 avatar cclauss avatar zanieb avatar eddyg avatar francescelies avatar kdeldycke avatar pamelafox avatar sjdemartini avatar messense avatar monosans avatar yaegassy avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.