koxudaxi / ruff-pycharm-plugin

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

Sometimes removes all contents of a file when the file is within an excluded directory #275

Closed mjakl closed 11 months ago

mjakl commented 11 months ago

Describe the bug I've excluded my tests via pyproject.toml from ruff scanning. The plugin seems to try to ignore this setting and runs into problems, causing the whole file content to vanish.

I've since moved to exclude only certain rules within the tests directory, this seems to have fixed it.

This is not related to the new formatting option, as I observed the behaviour with and without this feature enabled.

Example config used:

[tool.ruff]
line-length = 100
fix = true
select = [ ... ]
ignore-init-module-imports = true
# let's keep tests compact
exclude = ["tests"]

What seems to work:

[tool.ruff]
line-length = 100
fix = true
select = [ ... ]
ignore-init-module-imports = true

[tool.ruff.per-file-ignores]
"tests/**.py" = [ ... ]

To Reproduce Steps to reproduce the behavior:

  1. Create a project with src and tests next to each other
  2. Exclude tests from ruff processing fith exclude = ["tests"]
  3. Enable the ruff plugin in PyCharm
  4. Work with files in the tests directory

Expected behavior It should respect the configuration in pyproject.toml and not process files that are excluded. If that's hard, at least, don't delete the contents of the file.

Environments (please complete the following information):

Additional context Thank you for the fantastic plugin, and the quick addition of the formatting option! Not having to work with black and ruff at the same time helps to simplify the setup and reduces conflicts.

koxudaxi commented 11 months ago

@mjakl Thank you for creating the issue. I have released a fixed version 0.0.24 If you see the same problem, please reopen the issue.