mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-14 05:53:59 +00: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
1 changed files with 14 additions and 7 deletions
|
@ -74,13 +74,20 @@ if set -q c_files[1]
|
||||||
else if type -q clang-format
|
else if type -q clang-format
|
||||||
echo === Running "$red"clang-format"$normal"
|
echo === Running "$red"clang-format"$normal"
|
||||||
for file in $c_files
|
for file in $c_files
|
||||||
cp $file $file.new # preserves mode bits
|
if clang-format --dry-run -Werror $file
|
||||||
clang-format $file >$file.new
|
# file was clean, remove it from the list
|
||||||
if cmp --quiet $file $file.new
|
set -e c_files[(contains -i $file $c_files)]
|
||||||
rm $file.new
|
end
|
||||||
else
|
end
|
||||||
echo $file was NOT correctly formatted
|
if set -q c_files[1]
|
||||||
mv $file.new $file
|
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
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in a new issue