koxudaxi / ruff-pycharm-plugin

PyCharm plugin for ruff. This plugin provides reformat code using ruff.
MIT License
173 stars 6 forks source link

Automatic import organisation inconsistent between type hints and action on save #443

Open KarimAED opened 1 month ago

KarimAED commented 1 month ago

Describe the bug Ruff runs as an action on save, even if I don't tell it to. I literally have all boxes in the Ruff settings page unchecked. Worst of all, however, the context action for organizing imports, and the action on save disagree on the correct import formatting for the snippet:

from pathlib import Path
from typing import Any

import click
import matplotlib.pyplot as plt
import numpy as np

from my_package.utils import MyObject

With one suggesting a line between numpy and my_package imports while the other keeps removing the line. This only happens when I use top-level imports from my_package, i.e. the issue is resolved with from .utils import.

To Reproduce Steps to reproduce the behavior:

  1. Install ruff plugin
  2. Deactivate all actions in the Settings>Tools>Ruff pane
  3. Still get Ruff actions on save
  4. Create a project structure where you import files from a top-level package
  5. Actions on save and code annotations disagree

Expected behavior When I turn off Run ruff on save and Run ruff when reformat code, Ruff should never run automatically to fix my code. Also, the action on save is incorrect in this case, I believe, in suggesting removing the line between imports from my_package and third party software. This should be fixed.

Screenshots

This is my ruff tool pane:

image

This is what the action on save formats it to (Ruff thinks this is wrong):

image

This is what it should look like:

image

Environments (please complete the following information):

Additional context Add any other context about the problem here.