ruff-pycharm-plugin icon indicating copy to clipboard operation
ruff-pycharm-plugin copied to clipboard

(🎁) "organize imports" integration

Open KotlinIsland opened this issue 2 years ago • 5 comments

the vscode extension has options/commands for:

  • organize imports on save
  • fix all on save
  • a fix all command
  • format code

I think that it would be beneficial if this plugin had a separate "organise imports" option like the vscode extensions does.

See com.intellij.lang.ImportOptimizer

Funding

  • You can sponsor this specific effort via a Polar.sh pledge below
  • We receive the pledge once the issue is completed & verified
Fund with Polar

KotlinIsland avatar Apr 19 '23 04:04 KotlinIsland

This would be awesome.

My current work around is to run

$PyInterpreterDirectory$/python -m ruff check --select I --fix $FilePath$

as part of a File Watcher

  • https://github.com/johnthagen/python-blueprint#import-sorting

Having this be a simple option to "sort imports on save" built into the plugin would be save a lot of manual configuration for each user.

johnthagen avatar Dec 11 '23 15:12 johnthagen

Isn't this already possible? For me the following combination of options achieves this:

  • Run ruff when the python file is saved
  • Use ruff format (Experimental) for version 0.0.289 or later
  • Enabling auto-fixing imports in the projects' pyproject.toml file:
    [tool.ruff.lint]
    select = ['I']   # add more rules here as desired
    fixable = ['I']  # add more rules here as desired
    

urob avatar May 30 '24 17:05 urob

@urob that would lead to fixing everything, which is not desirable.

KotlinIsland avatar May 30 '24 23:05 KotlinIsland

@urob that would lead to fixing everything, which is not desirable.

Not sure I follow. The I rules are just for organizing the imports. You could be even more specific and only specify I001.

I'm using something very similar to this and there aren't any additional linter fixes that are automatically applied for me.

urob avatar May 31 '24 00:05 urob

Oh right, yeah, read that backwards.

Your solution would lead to nothing else being fixed, which is not desirable.

KotlinIsland avatar May 31 '24 00:05 KotlinIsland

@koxudaxi Did you complete this issue in

  • #570

johnthagen avatar Mar 20 '25 18:03 johnthagen