mirror of
https://github.com/junegunn/fzf.git
synced 2025-11-08 11:23:47 -05:00
make lint: Perform bash script linting
This commit is contained in:
@@ -1,2 +1,3 @@
|
|||||||
golang 1.23
|
golang 1.23
|
||||||
ruby 3.4
|
ruby 3.4
|
||||||
|
shfmt 3.12
|
||||||
|
|||||||
16
Makefile
16
Makefile
@@ -10,8 +10,8 @@ BASH_SCRIPTS := $(ROOT_DIR)/bin/fzf-preview.sh \
|
|||||||
$(ROOT_DIR)/install \
|
$(ROOT_DIR)/install \
|
||||||
$(ROOT_DIR)/uninstall \
|
$(ROOT_DIR)/uninstall \
|
||||||
$(ROOT_DIR)/shell/common.sh \
|
$(ROOT_DIR)/shell/common.sh \
|
||||||
$(ROOT_DIR)/shell/update-common.sh
|
$(ROOT_DIR)/shell/update.sh \
|
||||||
BASH_SCRIPTS_INDENT_LEFT := $(ROOT_DIR)/shell/completion.bash \
|
$(ROOT_DIR)/shell/completion.bash \
|
||||||
$(ROOT_DIR)/shell/key-bindings.bash
|
$(ROOT_DIR)/shell/key-bindings.bash
|
||||||
|
|
||||||
ifdef FZF_VERSION
|
ifdef FZF_VERSION
|
||||||
@@ -100,17 +100,11 @@ bench:
|
|||||||
lint: $(SOURCES) test/*.rb test/lib/*.rb ${BASH_SCRIPTS}
|
lint: $(SOURCES) test/*.rb test/lib/*.rb ${BASH_SCRIPTS}
|
||||||
[ -z "$$(gofmt -s -d src)" ] || (gofmt -s -d src; exit 1)
|
[ -z "$$(gofmt -s -d src)" ] || (gofmt -s -d src; exit 1)
|
||||||
bundle exec rubocop -a --require rubocop-minitest --require rubocop-performance
|
bundle exec rubocop -a --require rubocop-minitest --require rubocop-performance
|
||||||
[ -z "$$(shfmt -d $(BASH_SCRIPTS))" ] || (echo "format bash files by (make fmt)"; exit 1)
|
shell/update.sh --check ${BASH_SCRIPTS}
|
||||||
|
|
||||||
fmt: $(SOURCES) $(BASH_SCRIPTS) $(BASH_SCRIPTS_INDENT_LEFT)
|
fmt: $(SOURCES) $(BASH_SCRIPTS)
|
||||||
gofmt -s -w src
|
gofmt -s -w src
|
||||||
shfmt -w $(BASH_SCRIPTS)
|
shell/update.sh ${BASH_SCRIPTS}
|
||||||
# shift left because we have an outermost if block for historical reasons.
|
|
||||||
for f in $(BASH_SCRIPTS_INDENT_LEFT); do \
|
|
||||||
shfmt -w "$$f"; \
|
|
||||||
tmp=$$(mktemp); \
|
|
||||||
sed 's/^ //' "$$f" > "$$tmp" && mv "$$tmp" "$$f"; \
|
|
||||||
done
|
|
||||||
|
|
||||||
install: bin/fzf
|
install: bin/fzf
|
||||||
|
|
||||||
|
|||||||
@@ -31,9 +31,10 @@ if [[ $- =~ i ]]; then
|
|||||||
|
|
||||||
###########################################################
|
###########################################################
|
||||||
|
|
||||||
|
#----BEGIN shfmt
|
||||||
#----BEGIN INCLUDE common.sh
|
#----BEGIN INCLUDE common.sh
|
||||||
# NOTE: Do not directly edit this section, which is copied from "common.sh".
|
# NOTE: Do not directly edit this section, which is copied from "common.sh".
|
||||||
# To modify it, one can edit "common.sh" and run "./update-common.sh" to apply
|
# To modify it, one can edit "common.sh" and run "./update.sh" to apply
|
||||||
# the changes. See code comments in "common.sh" for the implementation details.
|
# the changes. See code comments in "common.sh" for the implementation details.
|
||||||
|
|
||||||
__fzf_defaults() {
|
__fzf_defaults() {
|
||||||
@@ -683,5 +684,6 @@ _fzf_setup_completion() {
|
|||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
#----END shfmt
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ if [[ -o interactive ]]; then
|
|||||||
|
|
||||||
#----BEGIN INCLUDE common.sh
|
#----BEGIN INCLUDE common.sh
|
||||||
# NOTE: Do not directly edit this section, which is copied from "common.sh".
|
# NOTE: Do not directly edit this section, which is copied from "common.sh".
|
||||||
# To modify it, one can edit "common.sh" and run "./update-common.sh" to apply
|
# To modify it, one can edit "common.sh" and run "./update.sh" to apply
|
||||||
# the changes. See code comments in "common.sh" for the implementation details.
|
# the changes. See code comments in "common.sh" for the implementation details.
|
||||||
|
|
||||||
__fzf_defaults() {
|
__fzf_defaults() {
|
||||||
|
|||||||
@@ -17,9 +17,10 @@ if [[ $- =~ i ]]; then
|
|||||||
# Key bindings
|
# Key bindings
|
||||||
# ------------
|
# ------------
|
||||||
|
|
||||||
|
#----BEGIN shfmt
|
||||||
#----BEGIN INCLUDE common.sh
|
#----BEGIN INCLUDE common.sh
|
||||||
# NOTE: Do not directly edit this section, which is copied from "common.sh".
|
# NOTE: Do not directly edit this section, which is copied from "common.sh".
|
||||||
# To modify it, one can edit "common.sh" and run "./update-common.sh" to apply
|
# To modify it, one can edit "common.sh" and run "./update.sh" to apply
|
||||||
# the changes. See code comments in "common.sh" for the implementation details.
|
# the changes. See code comments in "common.sh" for the implementation details.
|
||||||
|
|
||||||
__fzf_defaults() {
|
__fzf_defaults() {
|
||||||
@@ -154,5 +155,6 @@ if [[ "${FZF_ALT_C_COMMAND-x}" != "" ]]; then
|
|||||||
bind -m vi-command '"\ec": "\C-z\ec\C-z"'
|
bind -m vi-command '"\ec": "\C-z\ec\C-z"'
|
||||||
bind -m vi-insert '"\ec": "\C-z\ec\C-z"'
|
bind -m vi-insert '"\ec": "\C-z\ec\C-z"'
|
||||||
fi
|
fi
|
||||||
|
#----END shfmt
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ if [[ -o interactive ]]; then
|
|||||||
|
|
||||||
#----BEGIN INCLUDE common.sh
|
#----BEGIN INCLUDE common.sh
|
||||||
# NOTE: Do not directly edit this section, which is copied from "common.sh".
|
# NOTE: Do not directly edit this section, which is copied from "common.sh".
|
||||||
# To modify it, one can edit "common.sh" and run "./update-common.sh" to apply
|
# To modify it, one can edit "common.sh" and run "./update.sh" to apply
|
||||||
# the changes. See code comments in "common.sh" for the implementation details.
|
# the changes. See code comments in "common.sh" for the implementation details.
|
||||||
|
|
||||||
__fzf_defaults() {
|
__fzf_defaults() {
|
||||||
|
|||||||
@@ -1,31 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
|
|
||||||
# This script applies the contents of "common.sh" to the other files.
|
|
||||||
|
|
||||||
set -e
|
|
||||||
|
|
||||||
# Go to the directory that contains this script
|
|
||||||
dir=${0%"${0##*/}"}
|
|
||||||
if [ -n "$dir" ]; then
|
|
||||||
cd "$dir"
|
|
||||||
fi
|
|
||||||
|
|
||||||
update() {
|
|
||||||
{
|
|
||||||
sed -n '1,/^#----BEGIN INCLUDE common\.sh/p' "$1"
|
|
||||||
cat <<EOF
|
|
||||||
# NOTE: Do not directly edit this section, which is copied from "common.sh".
|
|
||||||
# To modify it, one can edit "common.sh" and run "./update-common.sh" to apply
|
|
||||||
# the changes. See code comments in "common.sh" for the implementation details.
|
|
||||||
EOF
|
|
||||||
grep -v '^[[:blank:]]*#' common.sh # remove code comments in common.sh
|
|
||||||
sed -n '/^#----END INCLUDE/,$p' "$1"
|
|
||||||
} > "$1.part"
|
|
||||||
|
|
||||||
mv -f "$1.part" "$1"
|
|
||||||
}
|
|
||||||
|
|
||||||
update completion.bash
|
|
||||||
update completion.zsh
|
|
||||||
update key-bindings.bash
|
|
||||||
update key-bindings.zsh
|
|
||||||
67
shell/update.sh
Executable file
67
shell/update.sh
Executable file
@@ -0,0 +1,67 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# This script applies the contents of "common.sh" to the other files.
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
dir=${0%"${0##*/}"}
|
||||||
|
|
||||||
|
update() {
|
||||||
|
{
|
||||||
|
sed -n '1,/^#----BEGIN INCLUDE common\.sh/p' "$1"
|
||||||
|
cat <<EOF
|
||||||
|
# NOTE: Do not directly edit this section, which is copied from "common.sh".
|
||||||
|
# To modify it, one can edit "common.sh" and run "./update.sh" to apply
|
||||||
|
# the changes. See code comments in "common.sh" for the implementation details.
|
||||||
|
EOF
|
||||||
|
grep -v '^[[:blank:]]*#' "$dir/common.sh" # remove code comments in common.sh
|
||||||
|
sed -n '/^#----END INCLUDE/,$p' "$1"
|
||||||
|
} > "$1.part"
|
||||||
|
|
||||||
|
mv -f "$1.part" "$1"
|
||||||
|
}
|
||||||
|
|
||||||
|
update "$dir/completion.bash"
|
||||||
|
update "$dir/completion.zsh"
|
||||||
|
update "$dir/key-bindings.bash"
|
||||||
|
update "$dir/key-bindings.zsh"
|
||||||
|
|
||||||
|
# Check if --check is in ARGV
|
||||||
|
check=0
|
||||||
|
rest=()
|
||||||
|
for arg in "$@"; do
|
||||||
|
case $arg in
|
||||||
|
--check) check=1 ;;
|
||||||
|
*) rest+=("$arg") ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
fmt() {
|
||||||
|
if ! grep -q "^#----BEGIN shfmt" "$1"; then
|
||||||
|
if [[ $check == 1 ]]; then
|
||||||
|
shfmt -d "$1"
|
||||||
|
return $?
|
||||||
|
else
|
||||||
|
shfmt -w "$1"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sed -n '1,/^#----BEGIN shfmt/p' "$1" | sed '$d'
|
||||||
|
sed -n '/^#----BEGIN shfmt/,/^#----END shfmt/p' "$1" | shfmt --filename "$1"
|
||||||
|
sed -n '/^#----END shfmt/,$p' "$1" | sed '1d'
|
||||||
|
} > "$1.part"
|
||||||
|
|
||||||
|
if [[ $check == 1 ]]; then
|
||||||
|
diff -q "$1" "$1.part"
|
||||||
|
ret=$?
|
||||||
|
rm -f "$1.part"
|
||||||
|
return $ret
|
||||||
|
fi
|
||||||
|
|
||||||
|
mv -f "$1.part" "$1"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
for file in "${rest[@]}"; do
|
||||||
|
fmt "$file" || exit $?
|
||||||
|
done
|
||||||
Reference in New Issue
Block a user