1 |
commit: f3d618057391b7de5bd7b26f65ce25a726d2d072 |
2 |
Author: Arthur Zamarin <arthurzam <AT> gentoo <DOT> org> |
3 |
AuthorDate: Wed Nov 2 19:22:48 2022 +0000 |
4 |
Commit: Arthur Zamarin <arthurzam <AT> gentoo <DOT> org> |
5 |
CommitDate: Wed Nov 2 19:26:57 2022 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/pkgcore/pkgcheck.git/commit/?id=f3d61805 |
7 |
|
8 |
UnquotedVariable: fix false positives with declaration_command |
9 |
|
10 |
Caught on app-admin/salt, it was incorrectly reporting for TMPDIR |
11 |
declared with `local` or `export`. This creates different parse tree |
12 |
with tree-sitter, so it was flagging this wrongly. Fix it, update tests. |
13 |
With this, the diff for gentoo repo is only for app-admin/salt. |
14 |
|
15 |
Reported-by: Patrick McLean <chutzpah <AT> gentoo.org> |
16 |
Resolves: https://github.com/pkgcore/pkgcheck/issues/490 |
17 |
Signed-off-by: Arthur Zamarin <arthurzam <AT> gentoo.org> |
18 |
|
19 |
src/pkgcheck/checks/codingstyle.py | 3 +++ |
20 |
.../EbuildUnquotedVariable/fix.patch | 19 ++++++++++--------- |
21 |
.../EbuildUnquotedVariable-0.ebuild | 4 ++++ |
22 |
3 files changed, 17 insertions(+), 9 deletions(-) |
23 |
|
24 |
diff --git a/src/pkgcheck/checks/codingstyle.py b/src/pkgcheck/checks/codingstyle.py |
25 |
index 4bf9932d..30e7f9f9 100644 |
26 |
--- a/src/pkgcheck/checks/codingstyle.py |
27 |
+++ b/src/pkgcheck/checks/codingstyle.py |
28 |
@@ -1019,6 +1019,9 @@ class _UnquotedVariablesCheck(Check): |
29 |
# Variable is part of a shell assignment, and does not need to be |
30 |
# quoted. for example S=${WORKDIR}/${PN} is ok. |
31 |
'variable_assignment', |
32 |
+ # Variable is part of declaring variables, and does not need to be |
33 |
+ # quoted. for example local TMPDIR is ok. |
34 |
+ 'declaration_command', |
35 |
# Variable sits inside a [[ ]] test command and it's OK not to be quoted |
36 |
'test_command', |
37 |
# Variable is being used in a heredoc body, no need to specify quotes. |
38 |
|
39 |
diff --git a/testdata/data/repos/standalone/EbuildUnquotedVariablesCheck/EbuildUnquotedVariable/fix.patch b/testdata/data/repos/standalone/EbuildUnquotedVariablesCheck/EbuildUnquotedVariable/fix.patch |
40 |
index a89ad5c4..d1172534 100644 |
41 |
--- a/testdata/data/repos/standalone/EbuildUnquotedVariablesCheck/EbuildUnquotedVariable/fix.patch |
42 |
+++ b/testdata/data/repos/standalone/EbuildUnquotedVariablesCheck/EbuildUnquotedVariable/fix.patch |
43 |
@@ -2,7 +2,7 @@ |
44 |
+++ fixed/EbuildUnquotedVariablesCheck/EbuildUnquotedVariable/EbuildUnquotedVariable-0.ebuild 2022-05-18 20:50:00.271294657 +0200 |
45 |
@@ -6,7 +6,7 @@ |
46 |
S=${WORKDIR}/${PV} # ok |
47 |
- |
48 |
+ |
49 |
PATCHES=( |
50 |
- ${FILESDIR}/foo.patch # FAIL |
51 |
+ "${FILESDIR}"/foo.patch # FAIL |
52 |
@@ -12,35 +12,36 @@ |
53 |
@@ -16,28 +16,28 @@ |
54 |
: |
55 |
fi |
56 |
- |
57 |
+ |
58 |
- if has "foo" ${FILESDIR} ; then # FAIL |
59 |
+ if has "foo" "${FILESDIR}" ; then # FAIL |
60 |
: |
61 |
fi |
62 |
- |
63 |
+ |
64 |
local t=${T} # ok |
65 |
local t=${T}/t # ok |
66 |
- emake CC=${T}; someotherfunc ${T} # FAIL |
67 |
+ emake CC="${T}"; someotherfunc "${T}" # FAIL |
68 |
- |
69 |
+ |
70 |
- local var=( TMP=${T} ) # FAIL |
71 |
+ local var=( TMP="${T}" ) # FAIL |
72 |
- |
73 |
+ |
74 |
cat > "${T}"/somefile <<- EOF || die |
75 |
PATH="${EPREFIX}${INSTALLDIR}/bin" |
76 |
EOF |
77 |
doenvd "${T}"/10stuffit # ok |
78 |
- |
79 |
+ |
80 |
- echo "InitiatorName=$(${WORKDIR}/usr/sbin/iscsi-iname)" # FAIL |
81 |
+ echo "InitiatorName=$("${WORKDIR}"/usr/sbin/iscsi-iname)" # FAIL |
82 |
einfo ${WORKDIR} # ok |
83 |
- |
84 |
+ |
85 |
if grep -qs '^ *sshd *:' "${WORKDIR}"/etc/hosts.{allow,deny} ; then # ok |
86 |
ewarn "something something ${WORKDIR} here" |
87 |
fi |
88 |
- |
89 |
+ |
90 |
- cat < ${T} # FAIL |
91 |
- cat >> ${T} # FAIL |
92 |
+ cat < "${T}" # FAIL |
93 |
+ cat >> "${T}" # FAIL |
94 |
- } |
95 |
+ |
96 |
+ local TMPDIR # ok |
97 |
|
98 |
diff --git a/testdata/repos/standalone/EbuildUnquotedVariablesCheck/EbuildUnquotedVariable/EbuildUnquotedVariable-0.ebuild b/testdata/repos/standalone/EbuildUnquotedVariablesCheck/EbuildUnquotedVariable/EbuildUnquotedVariable-0.ebuild |
99 |
index 83a381bf..0c382b1b 100644 |
100 |
--- a/testdata/repos/standalone/EbuildUnquotedVariablesCheck/EbuildUnquotedVariable/EbuildUnquotedVariable-0.ebuild |
101 |
+++ b/testdata/repos/standalone/EbuildUnquotedVariablesCheck/EbuildUnquotedVariable/EbuildUnquotedVariable-0.ebuild |
102 |
@@ -40,4 +40,8 @@ src_prepare() { |
103 |
|
104 |
cat < ${T} # FAIL |
105 |
cat >> ${T} # FAIL |
106 |
+ |
107 |
+ local TMPDIR # ok |
108 |
+ TMPDIR="$(mktemp --directory --tmpdir=/tmp ${PN}-XXXX)" # ok |
109 |
+ export TMPDIR # ok |
110 |
} |