Using Ruff Linter with Python in VS Code

2.7k Views Asked by At

I have installed the Ruff extension and enabled it in VS Code, but it doesn't seem to be underlining my code at all and providing suggestions like my previous linters did.

I did a clean install of VS Code, so most of the Python/Ruff extension settings are default. Is there an additional step I need to take to get it to start underlining my code and providing recommendations?

Here is a screenshot:

enter image description here

It's highlighting the imports for not being used, but I would expect other things to be highlighted like the line length, the additional spaces at the end of the file, not having 2 spaces before function declaration, etc.

Here is the sample code as requested:

import pandas as pd
import numpy as np

print('kkkkkkkkjlskdjflksdjflsdjflkdsjflksdjflkjdslkfjsdlkjflsdjflsdjfldsjflsdkjflsdjflksdjflksdjflksdjflskdjflsdkjfklsdjkl')
def test_func(x):
    y=x+1
    return y
2

There are 2 best solutions below

2
On BEST ANSWER

Take another look at the ruff documentation. You must enable or disable your desired linter rules and/or your formatting rules. For example, if you create a ruff.toml configuration in the root of your project with

[lint]
select = ["ALL"]

the output looks more like what you expect.

enter image description here

0
On

Based on the answer by @anit3res, I had to use something like this in my pyproject.toml to get ruff going in vsc:

[tool.ruff.lint]
select = ["ALL"]

[tool.ruff]
line-length = 120

I also needed to restart the ruff server for this to take effect.