koxudaxi / ruff-pycharm-plugin

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

Config file is ignored when run ruff from the plugin #291

Open koxudaxi opened 1 year ago

koxudaxi commented 1 year ago

Describe the bug Several users have pointed out a problem with config information in pyproject.toml and ruff.toml not being read. However, the config information is applied when the ruff command is invoked directly from the terminal.

I could not reproduce the problem in my environment, so I have created this issue to sort out and resolve the issue.

To Reproduce Steps to reproduce the behavior:

  1. Add configs as pyproject.toml or ruff.toml in a project.
  2. Write code that violates the rules.
  3. See wrong warning

Expected behavior The plugin doesn't show wrong waring (respect configs)

Screenshots I can't reproduce the problem

Environments (please complete the following information):

Related Issues https://github.com/koxudaxi/ruff-pycharm-plugin/issues/277 https://plugins.jetbrains.com/plugin/20574-ruff/reviews#review=91176-91183 https://plugins.jetbrains.com/plugin/20574-ruff/reviews#review=90927-91184

ghost commented 1 year ago

Hi @koxudaxi ,

could you please try with my exact same ruff config in pyproject.toml?

[tool.ruff]
line-length = 120
target-version = "py37"
select = ["A", "B", "C4", "D", "E", "EXE", "F", "FBT", "G", "I", "ICN", "ISC", "N", "PIE", "PL", "Q003", "PT", "Q", "RSE", "RUF", "S", "SIM", "T10", "T20", "TID", "UP", "W", "YTT"]
ignore = ["D100", "D101", "D102", "D103", "D104", "D105", "D106","D107",  "G003", "G004", "PLR0913", "PLR2004", "S113", "SIM108"]
format = "grouped"

[tool.ruff.pydocstyle]
convention = "google"

[tool.ruff.flake8-tidy-imports]
ban-relative-imports = "all"

[tool.ruff.flake8-quotes]
inline-quotes = "double"
docstring-quotes = "double"
multiline-quotes = "double"

Apart from the ignored files section I've copied the complete ruff config from one of the projects affected by this.

ghost commented 1 year ago

Just added an error in the code and noticed that the ruff plugin is working on this project now. I'll post again if I notice anything.

koxudaxi commented 1 year ago

@xyxz-web Thank you for sharing the example. I have tried the config. But, It works fine in my local.

Could you please share the plugin version, ruff version, and ruff config?

my environment are IDE: PyCharm 2023.2.1 (Professional Edition) OS: macOS 14 Ruff Version 0.1.1 Plugin version 0.0.24

ghost commented 1 year ago

Hi @koxudaxi ,

as mentioned in my second comment it is actually working now. The only change between when it did not work was that I did upgrade several dependencies and restart PyCharm after activating the ruff-lsp option.

Best regards

koxudaxi commented 1 year ago

I did upgrade several dependencies

After the dependencies are installed, and PyCharm has re-detected the package, the plugin will re-set the path to the ruff.

restart PyCharm after activating the ruff-lsp option.

ruff-lsp is not enabled before restarting PyCharm. Should we show a popup dialog to restart? :thinking:

ghost commented 1 year ago

Yes I think it might be a good Idea to show a popup that a restart is needed.

ttrei commented 1 year ago

I think the pyproject.toml discovery differs between the plugin and running ruff via command-line. https://docs.astral.sh/ruff/configuration/#config-file-discovery (permalink) (Note that passing the configuration file explicitly via --config disables the intelligent auto-discovery of the closest configuration file to the subject python file)

I observed the subject issue within a Pycharm project where the content root doesn't contain the .idea directory. Something like this:

~/PycharmProjects/foo-project/.idea/
~/dev/foo/ # this is the content root
~/dev/foo/.venv/ # virtual environment with ruff binary used by the Ruff plugin

"Ruff config file" was left empty in the plugin configuration. I placed ruff.toml both in ~/PycharmProjects/foo-project/ and in ~/dev/foo/, and tried to format some python files in ~/dev/foo/:

Note that there may be many content roots in a PyCharm project.

kamilos956 commented 5 months ago

I have the same issue. In the pyproject.toml file in the section tool.ruff.lint.per-file-ignores I have an entry "__init__.py" = ["PLC0414"], which in the Pycharm show me an error PLC0414. But when I run ruff with CLI everything is ok. Is it any update to this issue? I'm running on the WSL2 env. Feel free to ask me about project information, I would like to help to trace this error.

bradenneal1 commented 1 week ago

I am also having the same issue as above i.e. [tool.ruff.lint.per-file-ignores] rules are being ignored from pyproject.toml when using the PyCharm plugin, where other settings are working correctly e.g. [tool.ruff.lint].

Running ruff via the command-line detects the [tool.ruff.lint.per-file-ignores] settings and hence the issue appears isolated to (1) the ruff-plugin and (2) per-file-ignores settings specifically.

Environment: OS: RHEL9 PyCharm: 2024.2.3 (Community Edition) ruff version: ruff 0.6.9 ruff-plugin: 0.0.41