commit: f3d618057391b7de5bd7b26f65ce25a726d2d072 Author: Arthur Zamarin <arthurzam <AT> gentoo <DOT> org> AuthorDate: Wed Nov 2 19:22:48 2022 +0000 Commit: Arthur Zamarin <arthurzam <AT> gentoo <DOT> org> CommitDate: Wed Nov 2 19:26:57 2022 +0000 URL: https://gitweb.gentoo.org/proj/pkgcore/pkgcheck.git/commit/?id=f3d61805
UnquotedVariable: fix false positives with declaration_command Caught on app-admin/salt, it was incorrectly reporting for TMPDIR declared with `local` or `export`. This creates different parse tree with tree-sitter, so it was flagging this wrongly. Fix it, update tests. With this, the diff for gentoo repo is only for app-admin/salt. Reported-by: Patrick McLean <chutzpah <AT> gentoo.org> Resolves: https://github.com/pkgcore/pkgcheck/issues/490 Signed-off-by: Arthur Zamarin <arthurzam <AT> gentoo.org> src/pkgcheck/checks/codingstyle.py | 3 +++ .../EbuildUnquotedVariable/fix.patch | 19 ++++++++++--------- .../EbuildUnquotedVariable-0.ebuild | 4 ++++ 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/pkgcheck/checks/codingstyle.py b/src/pkgcheck/checks/codingstyle.py index 4bf9932d..30e7f9f9 100644 --- a/src/pkgcheck/checks/codingstyle.py +++ b/src/pkgcheck/checks/codingstyle.py @@ -1019,6 +1019,9 @@ class _UnquotedVariablesCheck(Check): # Variable is part of a shell assignment, and does not need to be # quoted. for example S=${WORKDIR}/${PN} is ok. 'variable_assignment', + # Variable is part of declaring variables, and does not need to be + # quoted. for example local TMPDIR is ok. + 'declaration_command', # Variable sits inside a [[ ]] test command and it's OK not to be quoted 'test_command', # Variable is being used in a heredoc body, no need to specify quotes. diff --git a/testdata/data/repos/standalone/EbuildUnquotedVariablesCheck/EbuildUnquotedVariable/fix.patch b/testdata/data/repos/standalone/EbuildUnquotedVariablesCheck/EbuildUnquotedVariable/fix.patch index a89ad5c4..d1172534 100644 --- a/testdata/data/repos/standalone/EbuildUnquotedVariablesCheck/EbuildUnquotedVariable/fix.patch +++ b/testdata/data/repos/standalone/EbuildUnquotedVariablesCheck/EbuildUnquotedVariable/fix.patch @@ -2,7 +2,7 @@ +++ fixed/EbuildUnquotedVariablesCheck/EbuildUnquotedVariable/EbuildUnquotedVariable-0.ebuild 2022-05-18 20:50:00.271294657 +0200 @@ -6,7 +6,7 @@ S=${WORKDIR}/${PV} # ok - + PATCHES=( - ${FILESDIR}/foo.patch # FAIL + "${FILESDIR}"/foo.patch # FAIL @@ -12,35 +12,36 @@ @@ -16,28 +16,28 @@ : fi - + - if has "foo" ${FILESDIR} ; then # FAIL + if has "foo" "${FILESDIR}" ; then # FAIL : fi - + local t=${T} # ok local t=${T}/t # ok - emake CC=${T}; someotherfunc ${T} # FAIL + emake CC="${T}"; someotherfunc "${T}" # FAIL - + - local var=( TMP=${T} ) # FAIL + local var=( TMP="${T}" ) # FAIL - + cat > "${T}"/somefile <<- EOF || die PATH="${EPREFIX}${INSTALLDIR}/bin" EOF doenvd "${T}"/10stuffit # ok - + - echo "InitiatorName=$(${WORKDIR}/usr/sbin/iscsi-iname)" # FAIL + echo "InitiatorName=$("${WORKDIR}"/usr/sbin/iscsi-iname)" # FAIL einfo ${WORKDIR} # ok - + if grep -qs '^ *sshd *:' "${WORKDIR}"/etc/hosts.{allow,deny} ; then # ok ewarn "something something ${WORKDIR} here" fi - + - cat < ${T} # FAIL - cat >> ${T} # FAIL + cat < "${T}" # FAIL + cat >> "${T}" # FAIL - } + + local TMPDIR # ok diff --git a/testdata/repos/standalone/EbuildUnquotedVariablesCheck/EbuildUnquotedVariable/EbuildUnquotedVariable-0.ebuild b/testdata/repos/standalone/EbuildUnquotedVariablesCheck/EbuildUnquotedVariable/EbuildUnquotedVariable-0.ebuild index 83a381bf..0c382b1b 100644 --- a/testdata/repos/standalone/EbuildUnquotedVariablesCheck/EbuildUnquotedVariable/EbuildUnquotedVariable-0.ebuild +++ b/testdata/repos/standalone/EbuildUnquotedVariablesCheck/EbuildUnquotedVariable/EbuildUnquotedVariable-0.ebuild @@ -40,4 +40,8 @@ src_prepare() { cat < ${T} # FAIL cat >> ${T} # FAIL + + local TMPDIR # ok + TMPDIR="$(mktemp --directory --tmpdir=/tmp ${PN}-XXXX)" # ok + export TMPDIR # ok }
