Skip to content

Commit

Permalink
ruff formatter: Fix bug running non-stdin version
Browse files Browse the repository at this point in the history
Forgot to pass the "-" placeholder for stdin. Apparently if you pass
--stdin-filename ruff assumes stdin, but if there's no filename it can
get confused and format everything in-place instead of formatting the
editor buffer.
  • Loading branch information
dbarnett authored and snu5mumr1k committed Aug 28, 2024
1 parent 123b4de commit 805e894
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion autoload/codefmt/ruff.vim
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ let s:plugin = maktaba#plugin#Get('codefmt')
function! s:FormatWithArgs(args) abort
let l:executable = s:plugin.Flag('ruff_executable')
let l:lines = getline(1, line('$'))
let l:cmd = [l:executable, 'format'] + a:args
let l:cmd = [l:executable, 'format'] + a:args + ['-']
if !empty(@%)
let l:cmd += ['--stdin-filename=' . @%]
endif
Expand Down
8 changes: 4 additions & 4 deletions vroom/ruff.vroom
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ system.
:silent file somefile.py
% f()
:FormatCode ruff
! ruff format --stdin-filename=somefile.py.*
! ruff format - --stdin-filename=somefile.py.*
$ f()

The name or path of the ruff executable can be configured via the
ruff_executable flag if the default of "ruff" doesn't work.

:Glaive codefmt ruff_executable='/somepath/ruff'
:FormatCode ruff
! /somepath/ruff format.*
! /somepath/ruff format -.*
$ f()
:Glaive codefmt ruff_executable='ruff'

Expand All @@ -40,7 +40,7 @@ You can format any buffer with ruff specifying the formatter explicitly.
% if True: pass

:FormatCode ruff
! ruff format.*
! ruff format -.*
$ if True:
$ pass
if True:
Expand All @@ -55,7 +55,7 @@ It can format specific line ranges of code using :FormatLines.
|else: bar-=1;

:2,3FormatLines ruff
! ruff format .*--range=2:3.*
! ruff format .*--range=2:3 -.*
$ some_tuple=( 1,2, 3,'a' );
$ if bar:
$ bar += 1
Expand Down

0 comments on commit 805e894

Please sign in to comment.