Skip to content

Commit 73e7586

Browse files
committed
UnquotedVariablesCheck: report unquoted variables in [ ] tests
Signed-off-by: Arthur Zamarin <arthurzam@gentoo.org>
1 parent 4a7b9a4 commit 73e7586

5 files changed

Lines changed: 33 additions & 13 deletions

File tree

‎NEWS.rst‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ pkgcheck 0.10.47 (unreleased)
1818
- StableRequestCheck: count from the latest change to a version, not
1919
sometimes from when it was added (Arthur Zamarin)
2020

21+
- UnquotedVariable: also report variables unquoted inside ``[ ]`` tests (Arthur
22+
Zamarin)
23+
2124
-----------------------------
2225
pkgcheck 0.10.46 (2026-09-26)
2326
-----------------------------

‎src/pkgcheck/checks/codingstyle.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1391,8 +1391,6 @@ class _UnquotedVariablesCheck(Check):
13911391
# Variable is part of declaring variables, and does not need to be
13921392
# quoted. for example local TMPDIR is ok.
13931393
"declaration_command",
1394-
# Variable sits inside a [[ ]] test command and it's OK not to be quoted
1395-
"test_command",
13961394
# Variable is being used in a heredoc body, no need to specify quotes.
13971395
"heredoc_body",
13981396
}
@@ -1403,6 +1401,9 @@ def _var_needs_quotes(self, pkg, node):
14031401
while pnode is not None:
14041402
if pnode.type in self.node_types_ok:
14051403
return False
1404+
elif pnode.type == "test_command":
1405+
# Variable sits inside a [[ ]] test command and it's OK not to be quoted
1406+
return pnode.children[0].type != "[["
14061407
elif pnode.type == "command":
14071408
cmd = pkg.node_str(pnode.child_by_field_name("name"))
14081409
return cmd not in self.message_commands
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{"__class__": "EbuildUnquotedVariable", "category": "EbuildUnquotedVariablesCheck", "package": "EbuildUnquotedVariable", "version": "0", "variable": "FILESDIR", "lines": [12, 22]}
2+
{"__class__": "EbuildUnquotedVariable", "category": "EbuildUnquotedVariablesCheck", "package": "EbuildUnquotedVariable", "version": "0", "variable": "S", "lines": [53]}
23
{"__class__": "EbuildUnquotedVariable", "category": "EbuildUnquotedVariablesCheck", "package": "EbuildUnquotedVariable", "version": "0", "variable": "T", "lines": [28, 30, 44, 45]}
34
{"__class__": "EbuildUnquotedVariable", "category": "EbuildUnquotedVariablesCheck", "package": "EbuildUnquotedVariable", "version": "0", "variable": "WORKDIR", "lines": [37]}

‎testdata/data/repos/standalone/EbuildUnquotedVariablesCheck/EbuildUnquotedVariable/fix.patch‎

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,46 +2,56 @@
22
+++ fixed/EbuildUnquotedVariablesCheck/EbuildUnquotedVariable/EbuildUnquotedVariable-0.ebuild 2022-05-18 20:50:00.271294657 +0200
33
@@ -9,7 +9,7 @@
44
SLOT="0"
5-
5+
66
PATCHES=(
77
- ${FILESDIR}/foo.patch # FAIL
88
+ "${FILESDIR}"/foo.patch # FAIL
99
"${FILESDIR}"/foo.patch # ok
1010
"${FILESDIR}/foo.patch" # ok
1111
)
12-
@@ -17,28 +17,28 @@
12+
@@ -19,30 +19,30 @@
1313
:
1414
fi
15-
15+
1616
- if has "foo" ${FILESDIR} ; then # FAIL
1717
+ if has "foo" "${FILESDIR}" ; then # FAIL
1818
:
1919
fi
20-
20+
2121
local t=${T} # ok
2222
local t=${T}/t # ok
2323
- emake CC=${T}; someotherfunc ${T} # FAIL
2424
+ emake CC="${T}"; someotherfunc "${T}" # FAIL
25-
25+
2626
- local var=( TMP=${T} ) # FAIL
2727
+ local var=( TMP="${T}" ) # FAIL
28-
28+
2929
cat > "${T}"/somefile <<- EOF || die
3030
PATH="${EPREFIX}${INSTALLDIR}/bin"
3131
EOF
3232
doenvd "${T}"/10stuffit # ok
33-
33+
3434
- echo "InitiatorName=$(${WORKDIR}/usr/sbin/iscsi-iname)" # FAIL
3535
+ echo "InitiatorName=$("${WORKDIR}"/usr/sbin/iscsi-iname)" # FAIL
3636
einfo ${WORKDIR} # ok
37-
37+
3838
if grep -qs '^ *sshd *:' "${WORKDIR}"/etc/hosts.{allow,deny} ; then # ok
3939
ewarn "something something ${WORKDIR} here"
4040
fi
41-
41+
4242
- cat < ${T} # FAIL
4343
- cat >> ${T} # FAIL
4444
+ cat < "${T}" # FAIL
4545
+ cat >> "${T}" # FAIL
46-
47-
local TMPDIR # ok
46+
47+
local TMPDIR # ok
48+
TMPDIR="$(mktemp --directory --tmpdir=/tmp ${PN}-XXXX)" # ok
49+
@@ -50,7 +50,7 @@
50+
51+
unset TMPDIR # ok
52+
53+
- if [ -z ${S} ]; then # FAIL
54+
+ if [ -z "${S}" ]; then # FAIL
55+
:
56+
fi
57+
[ -d "${S}" ] && [[ -d ${S} ]] # ok

‎testdata/repos/standalone/EbuildUnquotedVariablesCheck/EbuildUnquotedVariable/EbuildUnquotedVariable-0.ebuild‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,9 @@ src_prepare() {
4949
export TMPDIR # ok
5050

5151
unset TMPDIR # ok
52+
53+
if [ -z ${S} ]; then # FAIL
54+
:
55+
fi
56+
[ -d "${S}" ] && [[ -d ${S} ]] # ok
5257
}

0 commit comments

Comments
 (0)