pythonvisual-studio-coderuff

Using Ruff Linter with Python in VS Code


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

Solution

  • 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