Skip to content

Commit 3ddc315

Browse files
authored
Format comparisons, functions, and redirections to be consistent (#1201)
* Format comparisons and functions to be consistent * Add `checkstyle.py` script and add check to CI * Fix Ruff lints
1 parent c63b46a commit 3ddc315

File tree

16 files changed

+306
-42
lines changed

16 files changed

+306
-42
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ jobs:
3636
env:
3737
# NOTE: use env to pass the output in order to avoid possible injection attacks
3838
FILES: "${{ steps.files.outputs.added_modified }}"
39+
- name: checkstyle
40+
run: ./scripts/checkstyle.py
3941
- name: Shellcheck
4042
run: shellcheck --severity=error bin/* ./*.sh
4143
- name: Lint and format Python with Ruff

bin/git-abort

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
set -euo pipefail
44

5-
function discover_op() {
5+
discover_op() {
66
local gitdir
77
# git rev-parse emits an error if not in a git repo so only need to bail out
88
gitdir="$(git rev-parse --git-dir)" || exit
@@ -14,7 +14,7 @@ function discover_op() {
1414
done
1515
}
1616

17-
function validate_op() {
17+
validate_op() {
1818
local op="$1"
1919
if [ -z "$op" ]; then
2020
echo "No active operation found" >&2
@@ -26,7 +26,7 @@ function validate_op() {
2626
fi
2727
}
2828

29-
function discover_action() {
29+
discover_action() {
3030
local action=${1/git-/}
3131
if [ "$action" != "abort" ] && [ "$action" != "continue" ]; then
3232
echo "Invalid action: $1" >&2

bin/git-bulk

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ cdfail() {
3030
}
3131

3232
# add another workspace to global git config
33-
function addworkspace {
33+
addworkspace() {
3434
git config --global bulkworkspaces."$wsname" "$wsdir";
3535
if [ -n "$source" ]; then
3636
if [ ! -d "$wsdir" ]; then echo 1>&2 "Path of workspace doesn't exist, make it first."; exit 1; fi
@@ -59,19 +59,19 @@ function addworkspace {
5959
}
6060

6161
# add current directory
62-
function addcurrent { git config --global bulkworkspaces."$wsname" "$PWD"; }
62+
addcurrent() { git config --global bulkworkspaces."$wsname" "$PWD"; }
6363

6464
# remove workspace from global git config
65-
function removeworkspace { checkWSName && git config --global --unset bulkworkspaces."$wsname"; }
65+
removeworkspace() { checkWSName && git config --global --unset bulkworkspaces."$wsname"; }
6666

6767
# remove workspace from global git config
68-
function purge { git config --global --remove-section bulkworkspaces; }
68+
purge() { git config --global --remove-section bulkworkspaces; }
6969

7070
# list all current workspace locations defined
71-
function listall { git config --global --get-regexp bulkworkspaces; }
71+
listall() { git config --global --get-regexp bulkworkspaces; }
7272

7373
# guarded execution of a git command in one specific repository
74-
function guardedExecution () {
74+
guardedExecution () {
7575
if [ "${quiet?}" != "true" ] || $guardedmode; then
7676
echo 1>&2 "${bldred}->${reset} executing ${inverse}git $gitcommand${reset} in repository ${leadingpath%/*}/${bldred}${curdir##*/}${reset}"
7777
fi
@@ -88,7 +88,7 @@ function guardedExecution () {
8888
}
8989

9090
# check if the passed command is known as a core git command
91-
function checkGitCommand () {
91+
checkGitCommand () {
9292
if git help -a | grep -o -q "\b${corecommand}\b"; then
9393
echo 1>&2 "Core command \"$corecommand\" accepted."
9494
else
@@ -101,7 +101,7 @@ function checkGitCommand () {
101101
}
102102

103103
# check if workspace name is registered
104-
function checkWSName () {
104+
checkWSName () {
105105
while read -r workspace; do
106106
parseWsName "$workspace"
107107
if [[ $rwsname == "$wsname" ]]; then return; fi
@@ -111,7 +111,7 @@ function checkWSName () {
111111
}
112112

113113
# parse out wsname from workspacespec
114-
function parseWsName () {
114+
parseWsName () {
115115
local wsspec="$1"
116116
# Get the workspace value from its specification in the `.gitconfig`.
117117
# May be an absolute path or a variable name of the form: `$VARNAME`
@@ -128,7 +128,7 @@ function parseWsName () {
128128
}
129129

130130
# detects the wsname of the current directory
131-
function wsnameToCurrent () {
131+
wsnameToCurrent () {
132132
while read -r workspace; do
133133
if [ -z "$workspace" ]; then continue; fi
134134
parseWsName "$workspace"
@@ -140,15 +140,15 @@ function wsnameToCurrent () {
140140
}
141141

142142
# helper to check number of arguments.
143-
function allowedargcount () {
143+
allowedargcount () {
144144
if [ "$paramcount" -ne "${1:-0}" ] && [ "$paramcount" -ne "${2:-0}" ]; then
145145
echo 1>&2 "error: wrong number of arguments" && usage;
146146
exit 1;
147147
fi
148148
}
149149

150150
# execute the bulk operation
151-
function executBulkOp () {
151+
executBulkOp () {
152152
checkGitCommand
153153
if ! $allwsmode && ! $singlemode; then wsnameToCurrent; fi # by default git bulk works within the 'current' workspace
154154
listall | while read -r workspacespec; do
@@ -194,7 +194,7 @@ while [ "${#}" -ge 1 ] ; do
194194
--listall|--purge)
195195
butilcommand="${1:2}" && break ;;
196196
--removeworkspace|--addcurrent|--addworkspace)
197-
butilcommand="${1:2}" && wsname="$2" && wsdir="$3" && if [ "$4" == "--from" ]; then source="$5"; fi && break ;;
197+
butilcommand="${1:2}" && wsname="$2" && wsdir="$3" && if [ "$4" = "--from" ]; then source="$5"; fi && break ;;
198198
--no-follow-symlinks)
199199
no_follow_symlinks=true ;;
200200
--no-follow-hidden)

bin/git-clear

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
PROGNAME="git-clear"
33
FORCE=0
44

5-
function _usage() {
5+
_usage() {
66
cat << EOF
77
usage: $PROGNAME options
88
usage: $PROGNAME -h|help|?
@@ -38,6 +38,6 @@ else
3838
clean=y
3939
fi
4040

41-
if [ "$clean" == "y" ]; then
41+
if [ "$clean" = "y" ]; then
4242
git clean -d -f -x && git reset --hard
4343
fi

bin/git-clear-soft

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
echo -n "Sure? - This command may delete files that cannot be recovered. Files and directories in .gitignore will be preserved [y/N]: "
44
read -r answer
5-
if [ "$answer" == "y" ]
5+
if [ "$answer" = "y" ]
66
then git clean -d -f && git reset --hard
77
fi

bin/git-ignore

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
GIT_DIR=$(git rev-parse --git-dir 2>/dev/null)
44

5-
function show_contents {
5+
show_contents() {
66
local file="${2/#~/$HOME}"
77
if [ -f "$file" ]; then
88
echo "$1 gitignore: $2" && cat "$file"
@@ -11,7 +11,7 @@ function show_contents {
1111
fi
1212
}
1313

14-
function cd_to_git_root {
14+
cd_to_git_root() {
1515
local error_level="$1"
1616

1717
if ! git rev-parse --git-dir &>/dev/null; then
@@ -29,7 +29,7 @@ function cd_to_git_root {
2929
fi
3030
}
3131

32-
function global_ignore() {
32+
global_ignore() {
3333
if ! git config --global core.excludesFile 2>/dev/null; then
3434
if [ -f "$HOME/.gitignore" ]; then
3535
echo "$HOME/.gitignore"
@@ -39,11 +39,11 @@ function global_ignore() {
3939
fi
4040
}
4141

42-
function show_global {
42+
show_global() {
4343
show_contents Global "$(global_ignore)"
4444
}
4545

46-
function add_global {
46+
add_global() {
4747
local global_gitignore
4848
global_gitignore="$(global_ignore)"
4949
if [ -z "$global_gitignore" ]; then
@@ -56,28 +56,28 @@ function add_global {
5656
fi
5757
}
5858

59-
function show_local {
59+
show_local() {
6060
cd_to_git_root --warn
6161
show_contents Local .gitignore
6262
}
6363

64-
function add_local {
64+
add_local() {
6565
cd_to_git_root --warn
6666
add_patterns .gitignore "$@"
6767
}
6868

69-
function show_private {
69+
show_private() {
7070
cd_to_git_root --error
7171
show_contents Private "${GIT_DIR}/info/exclude"
7272
}
7373

74-
function add_private {
74+
add_private() {
7575
cd_to_git_root --error
7676
test -d "${GIT_DIR}/info" || mkdir -p "${GIT_DIR}/info"
7777
add_patterns "${GIT_DIR}/info/exclude" "$@"
7878
}
7979

80-
function add_patterns {
80+
add_patterns() {
8181
echo "Adding pattern(s) to: $1"
8282
local file="${1/#~/$HOME}"
8383
dir_name=$(dirname "$file")

bin/git-merge-into

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ then
1818
git stash
1919
fi
2020

21-
if [ "${!#}" == '--ff-only' ]; then
21+
if [ "${!#}" = '--ff-only' ]; then
2222
case $# in
2323
2 ) # dest --ff
2424
git push "$(git rev-parse --show-toplevel)" "$cur_branch":"$1";;

bin/git-paste

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
set -e
33
set -o pipefail
44

5-
if ! command -v pastebinit >/dev/null 2>&1; then
5+
if ! command -v pastebinit &>/dev/null; then
66
echo >&2 "To run 'git paste', you need to install pastebinit in your system"
77
exit 1
88
fi

bin/git-psykorebase

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ SECONDARY_BRANCH=""
55
FF="--ff"
66
CONTINUE="no"
77

8-
function current_branch() {
8+
current_branch() {
99
git rev-parse --abbrev-ref HEAD
1010
}
1111

bin/git-pull-request

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ if [ -z "$remote" ]; then
4343
echo 'no upstream found, push to origin as default'
4444
remote="origin"
4545
fi
46-
[ "$remote" == "." ] && abort "the upstream should be a remote branch."
46+
[ "$remote" = "." ] && abort "the upstream should be a remote branch."
4747

4848
# make sure it's pushed
4949

0 commit comments

Comments
 (0)