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 linter for Python has Problematic --format Option #4643

Closed
DancingPete opened this issue Oct 26, 2023 · 3 comments
Closed

Ruff linter for Python has Problematic --format Option #4643

DancingPete opened this issue Oct 26, 2023 · 3 comments
Labels

Comments

@DancingPete
Copy link

DancingPete commented Oct 26, 2023

Information

VIM version

VIM - Vi IMproved 9.0 (2022 Jun 28, compiled Oct 18 2023 00:00:00)
Included patches: 1-2048

Operating System

Linux pierre 6.5.7-200.fc38.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Oct 11 04:07:58 UTC 2023 x86_64 GNU/Linux

What went wrong

Please note that in the reproducing the bug section I've included a fix that works

Vim was unable to run ruff on a working python file. When run from the command line, ruff worked just fine. Using the VimInfo command, I noticed the following error in Ale's attempt to use the ruff linter:

finished - exit code 2) ['/usr/bin/zsh', '-c', 'cd ''/home/pierre/python_projects/budget'' &&
''ruff'' --format text --stdin-filename ''/home/pierre/python_projects/budget/src/budget/report
s.py'' - < ''/tmp/vwMb833/1/reports.py''']
<<>>
error: unexpected argument '--format' found
tip: to pass '--format' as a value, use '-- --format'
Usage: ruff check [OPTIONS] [FILES]...

Reproducing the Bug

After some experimentation with the ruff.vim file in your repository installed via vim Plug, I was able to get the error resolved by simply removing the --format option, which according to the ruff --help info, isn't actually available. There is a format subcommand, but treating the option as a subcommand by removing the double dash didn't yield a functioning linter.

Here is the function as installed and causing an error:

42 function! ale_linters#python#ruff#GetCommand(buffer, version) abort         
43     let l:executable = ale_linters#python#ruff#GetExecutable(a:buffer)      
44     let l:exec_args = l:executable =~? 'pipenv\|poetry$'                    
45     \   ? ' run ruff'                                                       
46     \   : ''                                                                
47                                                                             
48     " NOTE: ruff version `0.0.69` supports liniting input from stdin        
49     return ale#Escape(l:executable) . l:exec_args                           
50     \   . ale#Pad(ale#Var(a:buffer, 'python_ruff_options'))                 
51     \   . ' --format text'                                                  
52     \   .  (ale#semver#GTE(a:version, [0, 0, 69]) ? ' --stdin-filename %s -'
53 endfunction   

Here is the function amended as described yielding success (note the sole difference is on line 51):

 42 function! ale_linters#python#ruff#GetCommand(buffer, version) abort         
 43     let l:executable = ale_linters#python#ruff#GetExecutable(a:buffer)      
 44     let l:exec_args = l:executable =~? 'pipenv\|poetry$'                    
 45     \   ? ' run ruff'                                                       
 46     \   : ''                                                                
 47                                                                             
 48     " NOTE: ruff version `0.0.69` supports liniting input from stdin        
 49     return ale#Escape(l:executable) . l:exec_args                           
 50     \   . ale#Pad(ale#Var(a:buffer, 'python_ruff_options'))                 
 51     \   . ' text'                                                           
 52     \   .  (ale#semver#GTE(a:version, [0, 0, 69]) ? ' --stdin-filename %s -'
 53 endfunction

:ALEInfo

finished - exit code 2) ['/usr/bin/zsh', '-c', 'cd ''/home/pierre/python_projects/budget'' &&
''ruff'' --format text --stdin-filename ''/home/pierre/python_projects/budget/src/budget/report
s.py'' - < ''/tmp/vwMb833/1/reports.py''']
<<>>
error: unexpected argument '--format' found
tip: to pass '--format' as a value, use '-- --format'
Usage: ruff check [OPTIONS] [FILES]...

Thank you very much for the lovely plugin, and please forgive any errors in reporting the bug. This is my first attempt.

@john-kurkowski
Copy link

I think this is a duplicate of #4633.

@DancingPete
Copy link
Author

I think this is a duplicate of #4633.

Oh goodness, terribly sorry for the duplication. Thanks for the correction.

@DancingPete
Copy link
Author

As mentioned by @john-kurkowski, this is a duplicate of #4633. However, please note that I've added a workaround to the dicussion that may serve while the function of the --format option is dropped or amended.

@DancingPete DancingPete closed this as not planned Won't fix, can't repro, duplicate, stale Oct 27, 2023
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

2 participants