mirror of
https://github.com/fish-shell/fish-shell.git
synced 2024-11-25 09:39:52 +08:00
style.fish --all improvements
clang-format (since 10) can output diagnostics which indicate lines needing formatting with --dry-run and -Werror: the exit code indicates if a file is correctly formatted or not. We used to copy each .cpp file, run clang_format on the duplicate and then `cmp` to see if there were changes made, before just printing a line with the filename and moving the new ontop of the original. Now we show clang-format diagnostics which indicate which lines will be changed, prompt for confirmation and then let clang-format modify the files in-place without the juggling. Looks like this: https://user-images.githubusercontent.com/291142/184561633-c16754c8-179e-426b-ba15-345ba65b9cf9.png
This commit is contained in:
parent
2b2f772790
commit
c294c80214
|
@ -74,13 +74,20 @@ if set -q c_files[1]
|
|||
else if type -q clang-format
|
||||
echo === Running "$red"clang-format"$normal"
|
||||
for file in $c_files
|
||||
cp $file $file.new # preserves mode bits
|
||||
clang-format $file >$file.new
|
||||
if cmp --quiet $file $file.new
|
||||
rm $file.new
|
||||
else
|
||||
echo $file was NOT correctly formatted
|
||||
mv $file.new $file
|
||||
if clang-format --dry-run -Werror $file
|
||||
# file was clean, remove it from the list
|
||||
set -e c_files[(contains -i $file $c_files)]
|
||||
end
|
||||
end
|
||||
if set -q c_files[1]
|
||||
printf "Reformat those %d files?\n" (count $c_files)
|
||||
read -P 'y/N? ' -n1 -l ans
|
||||
if string match -qi "y" -- $ans
|
||||
clang-format -i --verbose $c_files
|
||||
else if string match -qi "n" -- $ans
|
||||
echo Skipping
|
||||
else # like they ctrl-C'd or something.
|
||||
exit 1
|
||||
end
|
||||
end
|
||||
else
|
||||
|
|
Loading…
Reference in New Issue
Block a user