Skip to content

Commit 805e894

Browse files
dbarnettsnu5mumr1k
authored andcommitted
ruff formatter: Fix bug running non-stdin version
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.
1 parent 123b4de commit 805e894

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

autoload/codefmt/ruff.vim

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ let s:plugin = maktaba#plugin#Get('codefmt')
1919
function! s:FormatWithArgs(args) abort
2020
let l:executable = s:plugin.Flag('ruff_executable')
2121
let l:lines = getline(1, line('$'))
22-
let l:cmd = [l:executable, 'format'] + a:args
22+
let l:cmd = [l:executable, 'format'] + a:args + ['-']
2323
if !empty(@%)
2424
let l:cmd += ['--stdin-filename=' . @%]
2525
endif

vroom/ruff.vroom

+4-4
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ system.
2121
:silent file somefile.py
2222
% f()
2323
:FormatCode ruff
24-
! ruff format --stdin-filename=somefile.py.*
24+
! ruff format - --stdin-filename=somefile.py.*
2525
$ f()
2626

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

3030
:Glaive codefmt ruff_executable='/somepath/ruff'
3131
:FormatCode ruff
32-
! /somepath/ruff format.*
32+
! /somepath/ruff format -.*
3333
$ f()
3434
:Glaive codefmt ruff_executable='ruff'
3535

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

4242
:FormatCode ruff
43-
! ruff format.*
43+
! ruff format -.*
4444
$ if True:
4545
$ pass
4646
if True:
@@ -55,7 +55,7 @@ It can format specific line ranges of code using :FormatLines.
5555
|else: bar-=1;
5656

5757
:2,3FormatLines ruff
58-
! ruff format .*--range=2:3.*
58+
! ruff format .*--range=2:3 -.*
5959
$ some_tuple=( 1,2, 3,'a' );
6060
$ if bar:
6161
$ bar += 1

0 commit comments

Comments
 (0)