mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-26 11:45:08 +00:00
Improve style script.
clang-format supports javascript and our 1 obj-c file. Also, let it pick up a handful of missed files of types we already inteded it to fix up. Improve formatting and output.
This commit is contained in:
parent
99351fcb44
commit
799d8ddfc4
1 changed files with 19 additions and 25 deletions
|
@ -24,13 +24,13 @@ end
|
||||||
if test $all = yes
|
if test $all = yes
|
||||||
set files (git status --porcelain --short --untracked-files=all | sed -e 's/^ *[^ ]* *//')
|
set files (git status --porcelain --short --untracked-files=all | sed -e 's/^ *[^ ]* *//')
|
||||||
if set -q files[1]
|
if set -q files[1]
|
||||||
echo
|
set_color --bold
|
||||||
echo You have uncommited changes. Cowardly refusing to restyle the entire code base.
|
echo "Will not proceed with style.fish --all as there are uncommited or untracked files."
|
||||||
echo
|
set_color normal
|
||||||
exit 1
|
echo "hint: git-clang-format can be ran directly"
|
||||||
|
exit 2
|
||||||
end
|
end
|
||||||
set c_files src/*.h src/*.cpp
|
set c_files {src,osx,build_tools,share}/{***.h,***.cpp,***.m,***.js}
|
||||||
set f_files share/***.fish
|
|
||||||
else
|
else
|
||||||
# We haven't been asked to reformat all the source. If there are uncommitted changes reformat
|
# We haven't been asked to reformat all the source. If there are uncommitted changes reformat
|
||||||
# those using `git clang-format`. Else reformat the files in the most recent commit.
|
# those using `git clang-format`. Else reformat the files in the most recent commit.
|
||||||
|
@ -43,50 +43,45 @@ else
|
||||||
set files (git diff-tree --no-commit-id --name-only -r HEAD)
|
set files (git diff-tree --no-commit-id --name-only -r HEAD)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Extract just the C/C++ files that exist.
|
# Extract just the C/C++/ObjC/js files that exist.
|
||||||
set c_files
|
set c_files
|
||||||
for file in (string match -r '^.*\.(?:c|cpp|h)$' -- $files)
|
for file in (string match -ri '^.*\.(?:c|cpp|h|m|js)$' -- $files)
|
||||||
test -f $file; and set c_files $c_files $file
|
test -f $file
|
||||||
|
and set c_files $c_files $file
|
||||||
end
|
end
|
||||||
# Extract just the fish files.
|
# Extract just the fish files.
|
||||||
set f_files (string match -r '^.*\.fish$' -- $files)
|
set f_files (string match -r '^.*\.fish$' -- $files)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Run the C++ reformatter if we have any C++ files.
|
# Run the git-clang-format if we have any C++ files.
|
||||||
if set -q c_files[1]
|
if set -q c_files[1]
|
||||||
if test $git_clang_format = yes
|
if test $git_clang_format = yes
|
||||||
if type -q git-clang-format
|
if type -q git-clang-format
|
||||||
echo
|
echo
|
||||||
echo ========================================
|
|
||||||
echo Running git-clang-format
|
echo Running git-clang-format
|
||||||
echo ========================================
|
echo ========================
|
||||||
git add $c_files
|
git add $c_files
|
||||||
git-clang-format
|
git-clang-format
|
||||||
else
|
else
|
||||||
echo
|
echo (set_color bold)'Warning: git-clang-format not installed or in $PATH'(set_color normal)
|
||||||
echo 'WARNING: Cannot find git-clang-format command'
|
|
||||||
echo
|
|
||||||
end
|
end
|
||||||
else if type -q clang-format
|
else if type -q clang-format
|
||||||
echo
|
echo
|
||||||
echo ========================================
|
|
||||||
echo Running clang-format
|
echo Running clang-format
|
||||||
echo ========================================
|
echo ====================
|
||||||
for file in $c_files
|
for file in $c_files
|
||||||
cp $file $file.new # preserves mode bits
|
cp $file $file.new # preserves mode bits
|
||||||
clang-format $file >$file.new
|
clang-format $file >$file.new
|
||||||
if cmp --quiet $file $file.new
|
if cmp --quiet $file $file.new
|
||||||
echo $file was correctly formatted
|
echo $file
|
||||||
rm $file.new
|
rm $file.new
|
||||||
else
|
else
|
||||||
echo $file was NOT correctly formatted
|
echo (set_color --underline)$file(set_color normal) is being reformatted
|
||||||
mv $file.new $file
|
mv $file.new $file
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
echo
|
|
||||||
echo 'WARNING: Cannot find clang-format command'
|
echo 'WARNING: Cannot find clang-format command'
|
||||||
echo
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -97,17 +92,16 @@ if set -q f_files[1]
|
||||||
set PATH . $PATH
|
set PATH . $PATH
|
||||||
end
|
end
|
||||||
echo
|
echo
|
||||||
echo ========================================
|
|
||||||
echo Running fish_indent
|
echo Running fish_indent
|
||||||
echo ========================================
|
echo ===================
|
||||||
for file in $f_files
|
for file in $f_files
|
||||||
cp $file $file.new # preserves mode bits
|
cp $file $file.new # preserves mode bits
|
||||||
fish_indent <$file >$file.new
|
fish_indent <$file >$file.new
|
||||||
if cmp --quiet $file $file.new
|
if cmp --quiet $file $file.new
|
||||||
echo $file was correctly formatted
|
echo $file
|
||||||
rm $file.new
|
rm $file.new
|
||||||
else
|
else
|
||||||
echo $file was NOT correctly formatted
|
echo (set_color --underline)$file(set_color normal)is being reformatted
|
||||||
mv $file.new $file
|
mv $file.new $file
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue