dense-analysis / ale

Check syntax in Vim/Neovim asynchronously and fix files, with Language Server Protocol (LSP) support
BSD 2-Clause "Simplified" License
13.51k stars 1.43k forks source link

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

Closed DancingPete closed 11 months ago

DancingPete commented 11 months ago

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 commented 11 months ago

I think this is a duplicate of #4633.

DancingPete commented 11 months ago

I think this is a duplicate of #4633.

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

DancingPete commented 11 months ago

As mentioned by @john-kurkowski, this is a duplicate of https://github.com/dense-analysis/ale/issues/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.