mirror of
https://github.com/fish-shell/fish-shell.git
synced 2024-11-23 01:24:23 +08:00
improve the style.fish script
If there are uncommitted changes use `git-clang-format` to limit the style fixups to the lines being modified. Refuse to do a `make style-all` if there are uncommitted changes. Include a fix for the parsing of `git status` output that was recently incorporated into the lint.fish script.
This commit is contained in:
parent
8e103c231e
commit
706bfa70c1
|
@ -40,7 +40,9 @@ The following sections discuss the specific rules for the style that should be u
|
||||||
make style
|
make style
|
||||||
```
|
```
|
||||||
|
|
||||||
before commiting your change. If you've already committed your changes that's okay since it will then check the files in the most recent commit. This can be useful after you've merged someone elses change and want to check that it's style is acceptable.
|
before commiting your change. That will run `git-clang-format` to rewrite just the lines you're modifying.
|
||||||
|
|
||||||
|
If you've already committed your changes that's okay since it will then check the files in the most recent commit. This can be useful after you've merged someone elses change and want to check that it's style is acceptable. However, in that case it will run `clang-format` to ensure the entire file, not just the lines modified by the commit, conform to the style.
|
||||||
|
|
||||||
If you want to check the style of the entire code base run
|
If you want to check the style of the entire code base run
|
||||||
|
|
||||||
|
@ -48,6 +50,8 @@ If you want to check the style of the entire code base run
|
||||||
make style-all
|
make style-all
|
||||||
```
|
```
|
||||||
|
|
||||||
|
That command will refuse to restyle any files if you have uncommitted changes.
|
||||||
|
|
||||||
### Suppressing Reformatting of the Code
|
### Suppressing Reformatting of the Code
|
||||||
|
|
||||||
If you have a good reason for doing so you can tell `clang-format` to not reformat a block of code by enclosing it in comments like this:
|
If you have a good reason for doing so you can tell `clang-format` to not reformat a block of code by enclosing it in comments like this:
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
# This runs C++ files and fish scripts (*.fish) through their respective code
|
# This runs C++ files and fish scripts (*.fish) through their respective code
|
||||||
# formatting programs.
|
# formatting programs.
|
||||||
#
|
#
|
||||||
|
set git_clang_format no
|
||||||
set c_files
|
set c_files
|
||||||
set f_files
|
set f_files
|
||||||
set all no
|
set all no
|
||||||
|
@ -21,17 +22,21 @@ if set -q argv[1]
|
||||||
end
|
end
|
||||||
|
|
||||||
if test $all = yes
|
if test $all = yes
|
||||||
|
set files (git status --porcelain --short --untracked-files=all | sed -e 's/^ *[^ ]* *//')
|
||||||
|
if set -q files[1]
|
||||||
|
echo
|
||||||
|
echo You have uncommited changes. Cowardly refusing to restyle the entire code base.
|
||||||
|
echo
|
||||||
|
exit 1
|
||||||
|
end
|
||||||
set c_files src/*.h src/*.cpp
|
set c_files src/*.h src/*.cpp
|
||||||
set f_files ***.fish
|
set f_files ***.fish
|
||||||
else
|
else
|
||||||
# We haven't been asked to reformat all the source. If there are uncommitted
|
# We haven't been asked to reformat all the source. If there are uncommitted changes reformat
|
||||||
# changes reformat those, else reformat the files in the most recent commit.
|
# those using `git clang-format`. Else reformat the files in the most recent commit.
|
||||||
set pending (git status --porcelain --short --untracked-files=all | sed -e 's/^ *//')
|
set files (git status --porcelain --short --untracked-files=all | sed -e 's/^ *[^ ]* *//')
|
||||||
if count $pending > /dev/null
|
if set -q files[1]
|
||||||
# There are pending changes so lint those files.
|
set git_clang_format yes
|
||||||
for arg in $pending
|
|
||||||
set files $files (string split -m 1 ' ' $arg)[2]
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
# No pending changes so lint the files in the most recent commit.
|
# No pending changes so lint the files in the most recent commit.
|
||||||
set files (git show --name-only --pretty=oneline head | tail --lines=+2)
|
set files (git show --name-only --pretty=oneline head | tail --lines=+2)
|
||||||
|
@ -45,18 +50,32 @@ end
|
||||||
|
|
||||||
# Run the C++ reformatter if we have any C++ files.
|
# Run the C++ reformatter if we have any C++ files.
|
||||||
if set -q c_files[1]
|
if set -q c_files[1]
|
||||||
if type -q clang-format
|
if test $git_clang_format = yes
|
||||||
|
if type -q git-clang-format
|
||||||
|
echo
|
||||||
|
echo ========================================
|
||||||
|
echo Running git-clang-format
|
||||||
|
echo ========================================
|
||||||
|
git add $c_files
|
||||||
|
git-clang-format
|
||||||
|
else
|
||||||
|
echo
|
||||||
|
echo 'WARNING: Cannot find git-clang-format command'
|
||||||
|
echo
|
||||||
|
end
|
||||||
|
else if type -q clang-format
|
||||||
echo
|
echo
|
||||||
echo ========================================
|
echo ========================================
|
||||||
echo Running clang-format
|
echo Running clang-format
|
||||||
echo ========================================
|
echo ========================================
|
||||||
for file in $c_files
|
for file in $c_files
|
||||||
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 was correctly formatted
|
||||||
rm $file.new
|
rm $file.new
|
||||||
else
|
else
|
||||||
echo $file was NOT correctly formatted
|
echo $file was NOT correctly formatted
|
||||||
|
chmod --reference=$file $file.new
|
||||||
mv $file.new $file
|
mv $file.new $file
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -78,12 +97,13 @@ if set -q f_files[1]
|
||||||
echo Running fish_indent
|
echo Running fish_indent
|
||||||
echo ========================================
|
echo ========================================
|
||||||
for file in $f_files
|
for file in $f_files
|
||||||
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 was correctly formatted
|
||||||
rm $file.new
|
rm $file.new
|
||||||
else
|
else
|
||||||
echo $file was NOT correctly formatted
|
echo $file was NOT correctly formatted
|
||||||
|
chmod --reference=$file $file.new
|
||||||
mv $file.new $file
|
mv $file.new $file
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user