Configuring Ruff #6669
Replies: 23 comments 29 replies
-
Excited to have learned about Ruff today; going to have to play with it on some projects. :) |
Beta Was this translation helpful? Give feedback.
-
Is it possible to use it in addition to Black? It seems that it's not currently possible to use several formatter at the same time. |
Beta Was this translation helpful? Give feedback.
-
Isn't this implementation better?
Otherwise, how do I use ruff as a linter? Are there any configs for LSP maybe? |
Beta Was this translation helpful? Give feedback.
-
Would like to have it working in parallel with Black.
|
Beta Was this translation helpful? Give feedback.
-
Here's how I got ruff fix and format working: "language_overrides": {
"Python": {
"format_on_save": "on",
"formatter": {
"external": {
"command": "bash",
"arguments": [
"-c",
"ruff check --exit-zero --fix --unsafe-fixes --stdin-filename {buffer_path} | ruff format --stdin-filename {buffer_path}"
]
}
}
}
} |
Beta Was this translation helpful? Give feedback.
-
Sort imports and format with ruff {
"language_overrides": {
"Python": {
"format_on_save": "on",
"formatter": {
"external": {
"command": "bash",
"arguments": [
"-c",
"ruff check --select=I --fix --stdin-filename {buffer_path} | ruff format --stdin-filename {buffer_path}"
]
}
}
}
}
} |
Beta Was this translation helpful? Give feedback.
-
Configured the formatter as mentioned "language_overrides": {
"Python": {
"format_on_save": "off",
"formatter": {
"external": {
"command": "bash",
"arguments": ["-c", "ruff format --exit-zero --fix --stdin-filename {buffer_path}"]
}
}
}, But the content of my file is being replaced by the output of ruff. |
Beta Was this translation helpful? Give feedback.
-
I follow with current configure spec and use this: "languages": {
"Python": {
"format_on_save": {
"external": {
"command": "ruff",
"arguments": [
"format",
"--stdin-filename",
"{buffer_path}"
]
}
}
}
}, |
Beta Was this translation helpful? Give feedback.
-
this worked for formatting "languages": {
"Python": {
"formatter": {
"external": {
"command": "ruff",
"arguments": ["format", "-"]
}
},
"format_on_save": "on"
}
} |
Beta Was this translation helpful? Give feedback.
-
How do I get Ruff errors / linting integrated? Will that require an extension? If so, has work started on one? Got a URL for the project (or will it be done 1st party)? |
Beta Was this translation helpful? Give feedback.
-
hello! for example, if I do: Thanks! PS: This is my settings.json file
|
Beta Was this translation helpful? Give feedback.
-
Hi, I'm new to this whole zed thing and its setup. After reading some of the comments here, I stopped understanding what was going on. Ruff has two versions of the lsp server, the one written in Python — I'm sorry for my English, it's not my native language. |
Beta Was this translation helpful? Give feedback.
-
We need Ruff LSP + Pyright support |
Beta Was this translation helpful? Give feedback.
-
I wrote a custom #!/bin/bash
# Usage: ruff-combi file.py < file.py
set -eu
ruff --quiet check --exit-zero --fix --stdin-filename "$1" - \
| ruff format --stdin-filename "$1" - Used like this: {
"languages": {
"Python": {
"formatter": {
"external": {
"command": "ruff-combi",
"arguments": ["{buffer_path}"]
... This combines import sorting and formatting. I'd prefer a pylsp base solution with python-lsp-ruff. See #7296 |
Beta Was this translation helpful? Give feedback.
-
I'm a bit confused now since the release of the 0.146
I would like to sort import too when I save my file, how can I setup this with the new Zed language settings? |
Beta Was this translation helpful? Give feedback.
-
Using 0.146.0 on Linux. First, you need to install zed ruff extension before using ruff language server. ruff extension does not sort imports. |
Beta Was this translation helpful? Give feedback.
-
We've added a setup guide for using the Ruff extension in Zed at https://docs.astral.sh/ruff/editors/setup/#zed. It includes example configuration:
|
Beta Was this translation helpful? Give feedback.
-
👋 I'm trying to configure the Ruff extension, but the language server doesn't seem to work. It is not available in the
Any help would be appreciated. Thank you 🙏 |
Beta Was this translation helpful? Give feedback.
-
If you enable For anyone else who wants to retain this while still getting ruff's formatting, here's the latest config to do this (basically @davidagold 's but without {
"languages": {
"Python": {
"language_servers": ["pyright"], // Probably optional, but just to be explicit
"format_on_save": "on",
"formatter": [
{
"code_actions": {
"source.organizeImports.ruff": true,
"source.fixAll.ruff": true
}
},
{
"language_server": {
"name": "ruff"
}
}
]
}
}
} Note that this of course requires also installing the ruff extension in the extensions panel. |
Beta Was this translation helpful? Give feedback.
-
Zed version: 0.151.2 "languages": {
"Python": {
"language_servers": ["pyright", "ruff"],
"format_on_save": "on",
"formatter": [
{
"code_actions": {
"source.organizeImports.ruff": true
//"source.fixAll.ruff": false
}
},
{
"language_server": {
"name": "ruff"
}
}
]
}
},
"lsp": {
"pyright": {
"settings": {
"python.analysis": {
"diagnosticMode": "workspace",
"typeCheckingMode": "strict"
},
"python": {
"pythonPath": ".venv/bin/python"
}
}
},
"ruff": {
"initialization_options": {
"settings": {
// Ruff server settings goes here
"lineLength": 80,
"lint": {
"extendSelect": ["I"]
}
}
}
}
} However, when I brew installed ruff it all started to work! |
Beta Was this translation helpful? Give feedback.
-
That is how it works for most linters
…On Tue, Sep 10, 2024, 11:08 AM Jan Larres ***@***.***> wrote:
Okay, I finally discovered what the problem is. It is this issue:
astral-sh/ruff#12539 <astral-sh/ruff#12539>. In
short, the Ruff server doesn't check files that don't have .py extension,
and I was editing scripts without an extension the entire time. The same
problem happens in VS Code.
This is really unintuitive and essentially means that you can't use the
Ruff server for extension-less scripts unless you change the include
setting to include all files, which is obviously not desirable.
—
Reply to this email directly, view it on GitHub
<#6669 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AADGOFWAT5RJLSIVCDLH77DZVZWDRAVCNFSM6AAAAABCOLZQQKVHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTANJZG43TMNA>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
My current setup uses a poetry environment with ruff installed as a dev dependency and ruff config in Using Zed is it possible to use the installed version of ruff within my active poetry environment to format code on save and respect the config in |
Beta Was this translation helpful? Give feedback.
-
Can anyone spot anywhere in my Zed configuration that would lead to getting no in-editor Ruff lints? "Python": {
"language_servers": ["ruff", "pyright"],
"lsp": {
"pyright": {
"initialization_options": {
"settings": {
"python.analysis": {
"diagnosticMode": "workspace",
"typeCheckingMode": "strict"
}
}
}
},
"ruff": {
"initialization_options": {
"settings": {
"lineLength": 88,
"showSyntaxErrors": true,
"lint": {
"select": ["ALL"],
"ignore": ["D", "S101"]
}
}
}
}
} I've installed the Ruff Zed extension, brew installed ruff, and am working with the latest version of Zed. Ultimately, I'm trying to recreate these VSCode settings: "[python]": {
"editor.defaultFormatter": "charliermarsh.ruff",
"editor.codeActionsOnSave": {
"source.fixAll.ruff": "explicit",
"source.organizeImports.ruff": "explicit"
}
},
"ruff.lineLength": 88,
"ruff.lint.select": ["ALL"],
"ruff.lint.ignore": ["D", "S101", "E501"],
"ruff.nativeServer": "on", Any advice would be much appreciated! This is frankly one of the main reasons I keep falling back to VSCode for my mostly python day job. |
Beta Was this translation helpful? Give feedback.
-
If you're interested in using Ruff's autofix functionality within Zed, you can add it as an external formatter via the following settings snippet:
Here's a clip of it in action from Twitter. Thanks @JosephTLyons for encouraging this tip.
Beta Was this translation helpful? Give feedback.
All reactions