Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ruff python linter not respecting per-file-ignore in pyproject.toml #4411

Closed
dbatten5 opened this issue Jan 4, 2023 · 5 comments
Closed
Labels

Comments

@dbatten5
Copy link

dbatten5 commented Jan 4, 2023

Information

VIM version

NVIM v0.8.0
Build type: Release

Operating System: MacOSX 11.5.2

What went wrong

I have some configuration set for the ruff linter in my pyproject.toml like so

[tool.ruff]
ignore = ['D103', 'D100']
line-length = 80
select = ['S', 'F']

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

This should ignore error S101 for files in tests/ and surface the error elsewhere. However, when running
ruff through ALE on a file at path tests/test_ruff.py, I can see the error still appears

image

This is confirmed in the output for ALEInfo:

(finished - exit code 1) ['/bin/zsh', '-c', '''/Users/xxx/Library/Caches/pypoetry/virtualenvs/test-ruff-Xi6EnTdk-py3.11/bin/ruff'' --format text - < ''/var/folders/hr/_46cyfr51290z837bnrk9vjc0000gn/T/nvim.xxx/RxEmX2/22/test_ruff.py''']
<<<OUTPUT STARTS>>>
-:1:8: F401 `math` imported but unused
-:4:5: S101 Use of `assert` detected
Found 2 error(s).
1 potentially fixable with the --fix option.

If I add the S101 error to the ignore list then the error is correctly ignored by ALE/ruff.

When running ruff directly through :!ruff % only the F401 is shown as expected

image

Reproducing the bug

pyproject.toml:

[tool.poetry]
name = "test-ruff"
version = "0.1.0"
description = ""
authors = ["Your Name <you@example.com>"]
readme = "README.md"
packages = [{include = "test_ruff"}]

[tool.poetry.dependencies]
python = "^3.8"


[tool.poetry.group.dev.dependencies]
ruff = "^0.0.209"

[tool.ruff]
ignore = ['D103', 'D100']
line-length = 80
select = ['S', 'F']

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

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

tests/test_ruff.py:

import math

def test_ruff() -> None:
    assert True

Running :ALELint on the above test file returns an unwanted error

:ALEInfo

Expand

 Current Filetype: python
Available Linters: ['bandit', 'cspell', 'flake8', 'flakehell', 'jedils', 'mypy', 'prospector', 'pycodestyle', 'pydocstyle', 'pyflakes', 'pylama', 'pylint', 'pylsp', 'pyre', 'pyright', 'refurb', 'ruff', 'unimport', 'vulture']
  Enabled Linters: ['ruff']
  Ignored Linters: []
 Suggested Fixers: 
  'add_blank_lines_for_python_control_statements' - Add blank lines before control statements.
  'autoflake' - Fix flake issues with autoflake.
  'autoimport' - Fix import issues with autoimport.
  'autopep8' - Fix PEP8 issues with autopep8.
  'black' - Fix PEP8 issues with black.
  'isort' - Sort Python imports with isort.
  'pyflyby' - Tidy Python imports with pyflyby.
  'remove_trailing_lines' - Remove all blank lines at the end of a file.
  'reorder-python-imports' - Sort Python imports with reorder-python-imports.
  'ruff' - A python linter/fixer for Python written in Rust
  'trim_whitespace' - Remove all trailing whitespace characters at the end of every line.
  'yapf' - Fix Python files with yapf.
 Linter Variables:

let g:ale_python_auto_pipenv = 0
let g:ale_python_auto_poetry = 0
let g:ale_python_ruff_auto_pipenv = 0
let g:ale_python_ruff_auto_poetry = 0
let g:ale_python_ruff_change_directory = 0
let g:ale_python_ruff_executable = 'ruff'
let g:ale_python_ruff_options = ''
let g:ale_python_ruff_use_global = 0
 Global Variables:

let g:ale_cache_executable_check_failures = v:null
let g:ale_change_sign_column_color = 0
let g:ale_command_wrapper = ''
let g:ale_completion_delay = v:null
let g:ale_completion_enabled = 0
let g:ale_completion_max_suggestions = v:null
let g:ale_disable_lsp = 0
let g:ale_echo_cursor = 1
let g:ale_echo_msg_error_str = 'Error'
let g:ale_echo_msg_format = '%code: %%s'
let g:ale_echo_msg_info_str = 'Info'
let g:ale_echo_msg_warning_str = 'Warning'
let g:ale_enabled = 1
let g:ale_fix_on_save = 0
let g:ale_fixers = {}
let b:ale_fixers = {'python': ['autoimport', 'isort', 'black']}
let g:ale_history_enabled = 1
let g:ale_history_log_output = 1
let g:ale_keep_list_window_open = 0
let g:ale_lint_delay = 200
let g:ale_lint_on_enter = 1
let g:ale_lint_on_filetype_changed = 1
let g:ale_lint_on_insert_leave = 0
let g:ale_lint_on_save = 1
let g:ale_lint_on_text_changed = 0
let g:ale_linter_aliases = {}
let g:ale_linters = {}
let b:ale_linters = {'python': ['ruff']}
let g:ale_linters_explicit = 0
let g:ale_linters_ignore = {}
let g:ale_list_vertical = 0
let g:ale_list_window_size = 10
let g:ale_loclist_msg_format = '%code: %%s'
let g:ale_max_buffer_history_size = 20
let g:ale_max_signs = -1
let g:ale_maximum_file_size = v:null
let g:ale_open_list = 0
let g:ale_pattern_options = v:null
let g:ale_pattern_options_enabled = v:null
let g:ale_root = {}
let g:ale_set_balloons = 0
let g:ale_set_highlights = 1
let g:ale_set_loclist = 1
let g:ale_set_quickfix = 0
let g:ale_set_signs = 1
let g:ale_sign_column_always = 0
let g:ale_sign_error = '>>'
let g:ale_sign_info = '--'
let g:ale_sign_offset = 1000000
let g:ale_sign_style_error = '>>'
let g:ale_sign_style_warning = '--'
let g:ale_sign_warning = '--'
let g:ale_sign_highlight_linenrs = 0
let g:ale_statusline_format = v:null
let g:ale_type_map = {}
let g:ale_use_global_executables = v:null
let g:ale_virtualtext_cursor = 'all'
let g:ale_warn_about_trailing_blank_lines = 1
let g:ale_warn_about_trailing_whitespace = 1
  Command History:

(executable check - success) /Users/xxx/Library/Caches/pypoetry/virtualenvs/test-ruff-Xi6EnTdk-py3.11/bin/ruff
(finished - exit code 0) ['/bin/zsh', '-c', '''/Users/xxx/Library/Caches/pypoetry/virtualenvs/test-ruff-Xi6EnTdk-py3.11/bin/ruff'' --version']

<<<OUTPUT STARTS>>>
ruff 0.0.209
<<<OUTPUT ENDS>>>

(finished - exit code 1) ['/bin/zsh', '-c', '''/Users/xxx/Library/Caches/pypoetry/virtualenvs/test-ruff-Xi6EnTdk-py3.11/bin/ruff'' --format text - < ''/var/folders/hr/_46cyfr51290z837bnrk9vjc0000gn/T/nvim.xxx/iF20kJ/1/test_ruff.py''']

<<<OUTPUT STARTS>>>
-:1:8: F401 `math` imported but unused
-:4:5: S101 Use of `assert` detected
Found 2 error(s).
1 potentially fixable with the --fix option.
<<<OUTPUT ENDS>>>
@dbatten5 dbatten5 added the bug label Jan 4, 2023
@john-kurkowski
Copy link

This behavior will be improved with #4414. Since ALE passes file contents to Ruff on stdin, without the filename, Ruff doesn't know what file ignore rules to apply.

@john-kurkowski
Copy link

Although your directory glob "tests/*" may still have an upstream issue, astral-sh/ruff#1840.

@dbatten5
Copy link
Author

great, thanks for looking @john-kurkowski

@hsanson
Copy link
Contributor

hsanson commented Jan 27, 2023

#4414 has been merged so closing this issue. Feel free to re-open or create a new one if the problem still persists.

@hsanson hsanson closed this as completed Jan 27, 2023
@dbatten5
Copy link
Author

Yep that's fixed it, thanks v much

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants