* [PATCH V3 0/4] bash-completion:fix shellcheck error and warning
@ 2022-12-06 13:49 t.feng
2022-12-06 13:49 ` [PATCH V3 1/4] bash-completion:fix shellcheck error t.feng
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: t.feng @ 2022-12-06 13:49 UTC (permalink / raw)
To: grub-devel; +Cc: fengtao40, daniel.kiper, yanan, zhaowei23
Hi,
The patch set fix some warning and error in grub-completion.bash.in.
And shellcheck also provides 'info' and 'style' level check, i think
grub do not need to modify.
shellcheck -s bash -S warning grub-completion.bash.in
shellcheck:https://github.com/koalaman/shellcheck
V3:
change functions variables as local
V2:
split warnings patches
fix error '"'
************************
t.feng (4):
bash-completion:fix shellcheck error
bash-completion:fix shellcheck SC2207-Warning
bash-completion:fix shellcheck SC2155-Warning
bash-completion:disable shellcheck SC2120-Warning
.../bash-completion.d/grub-completion.bash.in | 47 ++++++++++++-------
1 file changed, 29 insertions(+), 18 deletions(-)
--
2.27.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH V3 1/4] bash-completion:fix shellcheck error
2022-12-06 13:49 [PATCH V3 0/4] bash-completion:fix shellcheck error and warning t.feng
@ 2022-12-06 13:49 ` t.feng
2022-12-06 13:49 ` [PATCH V3 2/4] bash-completion:fix shellcheck SC2207-Warning t.feng
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: t.feng @ 2022-12-06 13:49 UTC (permalink / raw)
To: grub-devel; +Cc: fengtao40, daniel.kiper, yanan, zhaowei23
SC2070 (error): -n doesn't work with unquoted arguments.
Quote or use [[ ]].
In grub-completion.bash.in line 130:
[ -n $tmp ] && {
^--^ SC2070 (error)
More: https://github.com/koalaman/shellcheck/wiki/SC2070
Signed-off-by: "t.feng" <fengtao40@huawei.com>
---
util/bash-completion.d/grub-completion.bash.in | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/util/bash-completion.d/grub-completion.bash.in b/util/bash-completion.d/grub-completion.bash.in
index 44bf135b9..93d143480 100644
--- a/util/bash-completion.d/grub-completion.bash.in
+++ b/util/bash-completion.d/grub-completion.bash.in
@@ -127,7 +127,7 @@ __grub_list_modules () {
local IFS=$'\n'
COMPREPLY=( $( compgen -f -X '!*/*.mod' -- "${grub_dir}/$cur" | {
while read -r tmp; do
- [ -n $tmp ] && {
+ [ -n "$tmp" ] && {
tmp=${tmp##*/}
printf '%s\n' ${tmp%.mod}
}
--
2.27.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH V3 2/4] bash-completion:fix shellcheck SC2207-Warning
2022-12-06 13:49 [PATCH V3 0/4] bash-completion:fix shellcheck error and warning t.feng
2022-12-06 13:49 ` [PATCH V3 1/4] bash-completion:fix shellcheck error t.feng
@ 2022-12-06 13:49 ` t.feng
2022-12-06 13:49 ` [PATCH V3 3/4] bash-completion:fix shellcheck SC2155-Warning t.feng
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: t.feng @ 2022-12-06 13:49 UTC (permalink / raw)
To: grub-devel; +Cc: fengtao40, daniel.kiper, yanan, zhaowei23
COMPREPLY=($(command)) are doing unquoted command expansion in an array.
This will invoke the shell's sloppy word splitting and glob expansion.
If we want to split the output into lines or words, use read -r and
loops will be better. This prevents the shell from doing unwanted
splitting and glob expansion, and therefore avoiding problems with
output containing spaces or special characters.
SC2207 (warning): Prefer mapfile or read -a to split
command output (or quote to avoid splitting).
In grub-completion.bash.in line 56:
COMPREPLY=($(compgen -P "${2-}" -W "${1-}" -S "${4-}" --
"$cur"))
^-- SC2207 (warning)
In grub-completion.bash.in line 119:
COMPREPLY=( $(compgen \
^-- SC2207 (warning)
In grub-completion.bash.in line 128:
COMPREPLY=( $( compgen -f -X '!*/*.mod' -- "${grub_dir}/$cur" | {
^-- SC2207 (warning)
More: https://github.com/koalaman/shellcheck/wiki/SC2207
Signed-off-by: "t.feng" <fengtao40@huawei.com>
---
.../bash-completion.d/grub-completion.bash.in | 40 +++++++++++--------
1 file changed, 24 insertions(+), 16 deletions(-)
diff --git a/util/bash-completion.d/grub-completion.bash.in b/util/bash-completion.d/grub-completion.bash.in
index 93d143480..d3399f0e1 100644
--- a/util/bash-completion.d/grub-completion.bash.in
+++ b/util/bash-completion.d/grub-completion.bash.in
@@ -52,8 +52,11 @@ __grubcomp () {
COMPREPLY=()
;;
*)
- local IFS=' '$'\t'$'\n'
- COMPREPLY=($(compgen -P "${2-}" -W "${1-}" -S "${4-}" -- "$cur"))
+ local line IFS=' '$'\t'$'\n'
+ COMPREPLY=()
+ while read -r line; do
+ COMPREPLY+=("${line}")
+ done < <(compgen -P "${2-}" -W "${1-}" -S "${4-}" -- "$cur")
;;
esac
}
@@ -115,25 +118,30 @@ __grub_list_menuentries () {
local config_file=$(__grub_dir)/grub.cfg
if [ -f "$config_file" ];then
- local IFS=$'\n'
- COMPREPLY=( $(compgen \
- -W "$( awk -F "[\"']" '/menuentry/ { print $2 }' $config_file )" \
- -- "$cur" )) #'# Help emacs syntax highlighting
+ local line IFS=$'\n'
+ COMPREPLY=()
+ while read -r line; do
+ COMPREPLY+=("${line}")
+ done < <(compgen \
+ -W "$( awk -F "[\"']" '/menuentry/ { print $2 }' $config_file )" \
+ -- "$cur" ) #'# Help emacs syntax highlighting
fi
}
__grub_list_modules () {
local grub_dir=$(__grub_dir)
- local IFS=$'\n'
- COMPREPLY=( $( compgen -f -X '!*/*.mod' -- "${grub_dir}/$cur" | {
- while read -r tmp; do
- [ -n "$tmp" ] && {
- tmp=${tmp##*/}
- printf '%s\n' ${tmp%.mod}
- }
- done
- }
- ))
+ local line tmp IFS=$'\n'
+ COMPREPLY=()
+ while read -r line; do
+ COMPREPLY+=("${line}")
+ done < <(compgen -f -X '!*/*.mod' -- "${grub_dir}/$cur" | {
+ while read -r tmp; do
+ [ -n "$tmp" ] && {
+ tmp=${tmp##*/}
+ printf '%s\n' ${tmp%.mod}
+ }
+ done
+ })
}
#
--
2.27.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH V3 3/4] bash-completion:fix shellcheck SC2155-Warning
2022-12-06 13:49 [PATCH V3 0/4] bash-completion:fix shellcheck error and warning t.feng
2022-12-06 13:49 ` [PATCH V3 1/4] bash-completion:fix shellcheck error t.feng
2022-12-06 13:49 ` [PATCH V3 2/4] bash-completion:fix shellcheck SC2207-Warning t.feng
@ 2022-12-06 13:49 ` t.feng
2022-12-06 13:49 ` [PATCH V3 4/4] bash-completion:disable shellcheck SC2120-Warning t.feng
2022-12-06 15:29 ` [PATCH V3 0/4] bash-completion:fix shellcheck error and warning Daniel Kiper
4 siblings, 0 replies; 6+ messages in thread
From: t.feng @ 2022-12-06 13:49 UTC (permalink / raw)
To: grub-devel; +Cc: fengtao40, daniel.kiper, yanan, zhaowei23
SC2155 (warning): Declare and assign separately to avoid masking return
values.
The exit status of the command is overridden by the exit status of the
creation of the local variable.
In grub-completion.bash.in line 115:
local config_file=$(__grub_dir)/grub.cfg
^---------^ SC2155 (warning)
In grub-completion.bash.in line 126:
local grub_dir=$(__grub_dir)
^------^ SC2155 (warning)
More: https://github.com/koalaman/shellcheck/wiki/SC2155
Signed-off-by: "t.feng" <fengtao40@huawei.com>
---
util/bash-completion.d/grub-completion.bash.in | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/util/bash-completion.d/grub-completion.bash.in b/util/bash-completion.d/grub-completion.bash.in
index d3399f0e1..a85f18f05 100644
--- a/util/bash-completion.d/grub-completion.bash.in
+++ b/util/bash-completion.d/grub-completion.bash.in
@@ -115,7 +115,8 @@ __grub_get_last_option () {
__grub_list_menuentries () {
local cur="${COMP_WORDS[COMP_CWORD]}"
- local config_file=$(__grub_dir)/grub.cfg
+ local config_file
+ config_file=$(__grub_dir)/grub.cfg
if [ -f "$config_file" ];then
local line IFS=$'\n'
@@ -129,7 +130,8 @@ __grub_list_menuentries () {
}
__grub_list_modules () {
- local grub_dir=$(__grub_dir)
+ local grub_dir
+ grub_dir=$(__grub_dir)
local line tmp IFS=$'\n'
COMPREPLY=()
while read -r line; do
--
2.27.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH V3 4/4] bash-completion:disable shellcheck SC2120-Warning
2022-12-06 13:49 [PATCH V3 0/4] bash-completion:fix shellcheck error and warning t.feng
` (2 preceding siblings ...)
2022-12-06 13:49 ` [PATCH V3 3/4] bash-completion:fix shellcheck SC2155-Warning t.feng
@ 2022-12-06 13:49 ` t.feng
2022-12-06 15:29 ` [PATCH V3 0/4] bash-completion:fix shellcheck error and warning Daniel Kiper
4 siblings, 0 replies; 6+ messages in thread
From: t.feng @ 2022-12-06 13:49 UTC (permalink / raw)
To: grub-devel; +Cc: fengtao40, daniel.kiper, yanan, zhaowei23
SC2120 (warning): function references arguments, but none are ever
passed.
In grub-completion.bash.in line 63:
__grub_get_options_from_help () {
^-- SC2120 (warning)
local prog
if [ $# -ge 1 ]; then
prog="$1"
The arg of __grub_get_options_from_help is optional, so the current code
meets the exception and does not need to be modified. Ignoring it.
More: https://github.com/koalaman/shellcheck/wiki/SC2120
Signed-off-by: "t.feng" <fengtao40@huawei.com>
---
util/bash-completion.d/grub-completion.bash.in | 1 +
1 file changed, 1 insertion(+)
diff --git a/util/bash-completion.d/grub-completion.bash.in b/util/bash-completion.d/grub-completion.bash.in
index a85f18f05..213ce1e57 100644
--- a/util/bash-completion.d/grub-completion.bash.in
+++ b/util/bash-completion.d/grub-completion.bash.in
@@ -63,6 +63,7 @@ __grubcomp () {
# Function that return long options from the help of the command
# - arg: $1 (optional) command to get the long options from
+# shellcheck disable=SC2120
__grub_get_options_from_help () {
local prog
--
2.27.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH V3 0/4] bash-completion:fix shellcheck error and warning
2022-12-06 13:49 [PATCH V3 0/4] bash-completion:fix shellcheck error and warning t.feng
` (3 preceding siblings ...)
2022-12-06 13:49 ` [PATCH V3 4/4] bash-completion:disable shellcheck SC2120-Warning t.feng
@ 2022-12-06 15:29 ` Daniel Kiper
4 siblings, 0 replies; 6+ messages in thread
From: Daniel Kiper @ 2022-12-06 15:29 UTC (permalink / raw)
To: t.feng via Grub-devel; +Cc: t.feng, daniel.kiper, yanan, zhaowei23
On Tue, Dec 06, 2022 at 09:49:27PM +0800, t.feng via Grub-devel wrote:
> Hi,
> The patch set fix some warning and error in grub-completion.bash.in.
> And shellcheck also provides 'info' and 'style' level check, i think
> grub do not need to modify.
>
> shellcheck -s bash -S warning grub-completion.bash.in
>
> shellcheck:https://github.com/koalaman/shellcheck
>
> V3:
> change functions variables as local
>
> V2:
> split warnings patches
> fix error '"'
>
> ************************
>
> t.feng (4):
> bash-completion:fix shellcheck error
> bash-completion:fix shellcheck SC2207-Warning
> bash-completion:fix shellcheck SC2155-Warning
> bash-completion:disable shellcheck SC2120-Warning
For all patches Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>...
Daniel
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2022-12-06 15:29 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-06 13:49 [PATCH V3 0/4] bash-completion:fix shellcheck error and warning t.feng
2022-12-06 13:49 ` [PATCH V3 1/4] bash-completion:fix shellcheck error t.feng
2022-12-06 13:49 ` [PATCH V3 2/4] bash-completion:fix shellcheck SC2207-Warning t.feng
2022-12-06 13:49 ` [PATCH V3 3/4] bash-completion:fix shellcheck SC2155-Warning t.feng
2022-12-06 13:49 ` [PATCH V3 4/4] bash-completion:disable shellcheck SC2120-Warning t.feng
2022-12-06 15:29 ` [PATCH V3 0/4] bash-completion:fix shellcheck error and warning Daniel Kiper
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.