makepkg: lint empty arrays

Message ID 20220111150637.40543-1-morganamilo@archlinux.org
State New
Headers show
Series makepkg: lint empty arrays | expand

Commit Message

morganamilo Jan. 11, 2022, 3:06 p.m. UTC
While depend arrays are already linted, many array kinds are
still not. An empty string is never a valid array value so check
all arrays for it.
---
 .../libmakepkg/lint_pkgbuild/variable.sh.in   | 20 ++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

Comments

Allan McRae Jan. 13, 2022, 4:08 a.m. UTC | #1
On 12/1/22 01:06, morganamilo wrote:
> While depend arrays are already linted, many array kinds are
> still not. An empty string is never a valid array value so check
> all arrays for it.
> ---
>   .../libmakepkg/lint_pkgbuild/variable.sh.in   | 20 ++++++++++++++++++-
>   1 file changed, 19 insertions(+), 1 deletion(-)

I guess the depends check for empty values should also be removed to 
avoid double checking.

Allan

> diff --git a/scripts/libmakepkg/lint_pkgbuild/variable.sh.in b/scripts/libmakepkg/lint_pkgbuild/variable.sh.in
> index b4428344..d0951258 100644
> --- a/scripts/libmakepkg/lint_pkgbuild/variable.sh.in
> +++ b/scripts/libmakepkg/lint_pkgbuild/variable.sh.in
> @@ -28,7 +28,7 @@ source "$LIBRARY/util/pkgbuild.sh"
>   source "$LIBRARY/util/schema.sh"
>   
>   lint_pkgbuild_functions+=('lint_variable')
> -
> +lint_pkgbuild_functions+=('lint_array')
>   
>   lint_variable() {
>   	local i a pkg out bad ret=0
> @@ -95,3 +95,21 @@ lint_variable() {
>   
>   	return $ret
>   }
> +
> +lint_array() {
> +	local i var ret=0
> +
> +	for i in ${pkgbuild_schema_arrays[@]}; do
> +		local l=()
> +		get_pkgbuild_all_split_attributes $i l
> +
> +		for var in "${l[@]}"; do
> +			if [[ -z $var ]]; then
> +				error "$(gettext "%s does not allow empty values.")" "$i"
> +				ret=1
> +			fi
> +		done
> +	done
> +
> +	return $ret
> +}

Patch

diff --git a/scripts/libmakepkg/lint_pkgbuild/variable.sh.in b/scripts/libmakepkg/lint_pkgbuild/variable.sh.in
index b4428344..d0951258 100644
--- a/scripts/libmakepkg/lint_pkgbuild/variable.sh.in
+++ b/scripts/libmakepkg/lint_pkgbuild/variable.sh.in
@@ -28,7 +28,7 @@  source "$LIBRARY/util/pkgbuild.sh"
 source "$LIBRARY/util/schema.sh"
 
 lint_pkgbuild_functions+=('lint_variable')
-
+lint_pkgbuild_functions+=('lint_array')
 
 lint_variable() {
 	local i a pkg out bad ret=0
@@ -95,3 +95,21 @@  lint_variable() {
 
 	return $ret
 }
+
+lint_array() {
+	local i var ret=0
+
+	for i in ${pkgbuild_schema_arrays[@]}; do
+		local l=()
+		get_pkgbuild_all_split_attributes $i l
+
+		for var in "${l[@]}"; do
+			if [[ -z $var ]]; then
+				error "$(gettext "%s does not allow empty values.")" "$i"
+				ret=1
+			fi
+		done
+	done
+
+	return $ret
+}