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

Ignoring per-file-ignores configuration

Open FieryDruid opened this issue 1 year ago • 10 comments

Describe the bug

After updating to version 0.0.29, the plugin began to highlight rules that are ignored for specific files using the per-file-ignores section in ruff.toml. If ruff is run from the console with the same config, it does not find any errors.

To Reproduce Steps to reproduce the behavior:

  1. create package with some module in project
  2. write any code that is recognized by ruff as an error
  3. add this error code with path to this file in per-file-ignores
  4. check this error highlighting

Expected behavior Since ruff itself ignores the rule, the plugin should also not highlight it

Screenshots

Test code with error: image

project structure with new folder project_tests: image

per-file-ignores section: image

ruff check resuilt from command line: image

Environments (please complete the following information):

  • IDE: PyCharm Professional 2023.3.2
  • OS: Windows 10 + WSL (Ubuntu 22.04)
  • Ruff Version: 0.1.9
  • Plugin version: 0.0.29

Additional context It is likely that this may be related to the path to the config file in Windows + WSL: https://github.com/koxudaxi/ruff-pycharm-plugin/issues/358

but i fix this error by editing ruff.xml in .idea/. Everything worked fine on the previous version without any changes.

FieryDruid avatar Jan 23 '24 12:01 FieryDruid

Same thing. @koxudaxi maybe it happen, because Ruff team moved "per-file-ignores" config from root into "lint" subsection:

[tool.ruff.lint.per-file-ignores]
"tests/**" = ["INP001", "S101"]

Skorpyon avatar Feb 26 '24 22:02 Skorpyon

@FieryDruid

I'm sorry for my late reply. I tested your example. I can't reproduce the issue.

It is likely that this may be related to the path to the config file in Windows + WSL: https://github.com/koxudaxi/ruff-pycharm-plugin/issues/358

Do you set your ruff.toml config path in the settings?

koxudaxi avatar Mar 27 '24 18:03 koxudaxi

@FieryDruid

I'm sorry for my late reply. I tested your example. I can't reproduce the issue.

It is likely that this may be related to the path to the config file in Windows + WSL: #358

Do you set your ruff.toml config path in the settings?

Yes, the config file is specified, but, due to the problem described in https://github.com/koxudaxi/ruff-pycharm-plugin/issues/358 I had to edit ruff.xml in .idea folder and specify a relative path in it

<option name="ruffConfigPath" value="ruff.toml" />

Could there be a problem due to such usage?

Still reproduced on this simple project: pythonProject.zip image

Pycharm: 2023.3.5 Ruff: 0.1.9 Plugin: 0.0.31/0.0.29

And I tested this case on Ruff 0.3.4 with updated config:

[lint]
select = ["S101"]

[lint.per-file-ignores]
"tests/*" = ["S101"]

Plugin show me only assert: image

Ruff from CLI says: image

FieryDruid avatar Mar 28 '24 17:03 FieryDruid

@koxudaxi

Thanks for 0.0.33 release!

Problem is actual with fixed https://github.com/koxudaxi/ruff-pycharm-plugin/issues/358

Pycharm: 2024.1 Ruff: 0.3.5 Plugin: 0.0.33

FieryDruid avatar Apr 08 '24 08:04 FieryDruid

@FieryDruid Thank you for checking it :)

koxudaxi avatar Apr 08 '24 15:04 koxudaxi

@koxudaxi

sorry, it is not completed :(

I meant that error is still being reproduced after release

FieryDruid avatar Apr 08 '24 18:04 FieryDruid

@FieryDruid I tested the toml file from settings, which means it may not be taking relative paths into account. Could you test the absolute path?

koxudaxi avatar Apr 09 '24 09:04 koxudaxi

@koxudaxi

I changed config settings: image

ruff.xml contains:

<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
  <component name="RuffConfigService">
    <option name="globalRuffExecutablePath" value="\\wsl.localhost\Ubuntu-22.04\home\fierydruid\.local\bin\ruff" />
    <option name="ruffConfigPath" value="\\wsl.localhost\Ubuntu-22.04\home\fierydruid\work\schedule\pythonProject\ruff.toml" />
  </component>
</project>

I test some cases on: Pycharm: 2024.1 Ruff: 0.3.5 Plugin: 0.0.33 OS: Windows 11 + WSL (Ubuntu 22.04) (My secondary computer on Windows 10 + WSL (Ubuntu 22.04) has same bug)

Use test project from my previous comment:

Still reproduced on this simple project: pythonProject.zip

1 case

Select all rules and check without ignores

  • Ruff toml:
    [lint]
    select = ["ALL"]
    
  • Errors in Pycharm with plugin: image
  • Errors in wsl terminal (run ruff check --config ruff.toml from root project directory): image

2 case

Select all rules and check with ignore S101

  • Ruff toml:
    [lint]
    select = ["ALL"]
    
    [lint.per-file-ignores]
    "tests/*" = ["S101"]
    
  • Errors in Pycharm with plugin: image
  • Errors in wsl terminal (run ruff check --config ruff.toml from root project directory): image

3 case

Select only S101 and check with ignore S101:

  • Ruff toml:
    [lint]
    select = ["S101"]
    
    [lint.per-file-ignores]
    "tests/*" = ["S101"]
    
  • Errors in Pycharm with plugin (no longer highlights function name with D100/D103/ANN101 rules): image
  • Errors in wsl terminal (run ruff check --config ruff.toml from root project directory): image

FieryDruid avatar Apr 09 '24 17:04 FieryDruid

Hi, This is happening for me as well.

However, unlike the other bug reporters, I am running on macOS, and I don't have a ruff.toml. I specify the per-file-ignores under [tool.ruff.lint.per-file-ignores] in pyproject.toml.

I've had different issues with PyCharm before because this (newer) Python project is not in the root of my Pycharm workspace. Perhaps this could be a reason this isn't working for me?

Here is my .idea/ruff.xml

<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
  <component name="RuffConfigService">
    <option name="globalRuffExecutablePath" value="$USER_HOME$/.pyenv/shims/ruff" />
    <option name="globalRuffLspExecutablePath" value="$USER_HOME$/.pyenv/shims/ruff" />
    <option name="projectRuffExecutablePath" value="$USER_HOME$/Library/Caches/pypoetry/virtualenvs/server-N8UJI-q9-py3.12/bin/ruff" />
    <option name="ruffConfigPath" value="$PROJECT_DIR$/server/pyproject.toml" />
    <option name="runRuffOnSave" value="true" />
    <option name="useRuffFormat" value="true" />
  </component>
</project>

mihirsamdarshi avatar May 06 '24 06:05 mihirsamdarshi

I did some source code spelunking and I suspect that this might be an error with ruff/working directories when it gets the --config option?

I have two projects, one which is known good (does not show annotations for lint codes are excluded in the [tool.ruff.lint.per-file-ignores]), and one which is known bad (does show annotations for lint codes are excluded in the [tool.ruff.lint.per-file-ignores]). The known bad one has the pyproject.toml file in a non-root project path.

The bad project:

folder1/ (root)
  └── backend
  │   ├── pyproject.toml
  │   └── src
  │   │    └── foo_package
  │   │        └── __init__.py
  │   └── tests
  │       ├── __init__.py
  │       └── test_foo.py
  └── frontend
      └── ...

The good project:

folder2/ (root)
  ├── pyproject.toml
  ├── src
  │   └── example_project
  │       └── __init__.py
  └── tests
      ├── __init__.py
      └── test_main.py

Both had the exact same config in pyproject.toml

[tool.ruff.lint.per-file-ignores]
"tests/*.py" = ["ANN201", "D100", "D102", "D103", "S101", "SLF001"]

I built and ran the plugin from scratch and enabled debug logging for the com.intellij.execution handler, which is where runRuff, then runCommand, then CapturingProcessHandler end up.

In the good project, I noticed that the command being run was: /Users/user/good_project/.venv/bin/ruff check --exit-zero --no-cache --force-exclude --no-fix --output-format json --stdin-filename tests/test__lib.py -, and the working directory was /Users/user/good_project. This produces a list of annotations, which (erroneously) get displayed in PyCharm. I verified that the output when running this command manually in the terminal (with the venv activated) is the exact same as the one logged in the application, listing errors that are excluded in the [tool.ruff.lint.per-file-ignores] key.

And in the bad project the command was: /Users/user/bad_project/server/.venv/bin/ruff check --exit-zero --no-cache --force-exclude --no-fix --output-format json --stdin-filename server/tests/test_app.py --config /Users/user/bad_project/server/pyproject.toml -, and the working directory was /Users/user/bad_project. Again, the output when run manually is the same as seen the output seen in the log.

I believe the working directory of the command is the issue, because when I cd into /Users/user/bad_project/server/ and run the exact same command manually, I see the expected output (no errors).

mihirsamdarshi avatar Jun 26 '24 23:06 mihirsamdarshi

For me, this bug is still an issue. I think it is due to the fact that I use WSL+Windows. After adding logs to the plugin, I noticed that the paths to files are incorrectly generated.

ElipsisD avatar Mar 16 '25 15:03 ElipsisD

@ElipsisD Thank you for the your comment. What is the incorrect path you get?

koxudaxi avatar Mar 17 '25 00:03 koxudaxi

Image

Using the same path to ruff. There are no errors when applied in the terminal. But ruff plugin shows errors by rules that are ignored. On the screenshot you can see that in the console in “filename” field the incorrect path to the file being checked is displayed.

ElipsisD avatar Mar 17 '25 03:03 ElipsisD

@koxudaxi fixed in 0.0.46, thanks! 🎉

FieryDruid avatar Mar 25 '25 18:03 FieryDruid