Is there an existing such new check request for this?
Explain
Assigning twice to a variable in global scope is a serious code smell and is likely a typo:
SRC_URI="https://example.com/foo.tar.gz"
S="${WORKDIR}/x"
LICENSE="..."
S="${WORKDIR}"
src_compile() {
:;
}
We could also restrict the check to just eclass variables, although I'd like to try it without that restriction first.
C more or less calls this -Wshadow (not quite as there's some interaction w/ scoping which bash lacks).
Examples:
- Double-assignment to
S (perhaps once under SRC_URI and another way below above phases, might not be easy to see in a long ebuild)
- Setting
PYTHON_COMPAT twice in an ebuild
Examples
pecl-pttp (https://github.com/gentoo/gentoo/pull/32762/files#diff-c95f1d4880dbd4fd60024792709466e4113c4a06fe6d46b5b660c00e55f5440a, https://github.com/gentoo/gentoo/blob/4463a8bd59a49bdba73880461f3cedccf6b8cdb6/dev-php/pecl-http/pecl-http-3.3.0.ebuild#L16C5-L16C5) has USE_PHP defined twice
Output message
VariableShadowed
Documentation
Variable is shadowed / repeatedly declared. This is a possible typo.
Result level
warning
Is there an existing such new check request for this?
Explain
Assigning twice to a variable in global scope is a serious code smell and is likely a typo:
We could also restrict the check to just eclass variables, although I'd like to try it without that restriction first.
C more or less calls this
-Wshadow(not quite as there's some interaction w/ scoping which bash lacks).Examples:
S(perhaps once underSRC_URIand another way below above phases, might not be easy to see in a long ebuild)PYTHON_COMPATtwice in an ebuildExamples
pecl-pttp (https://github.com/gentoo/gentoo/pull/32762/files#diff-c95f1d4880dbd4fd60024792709466e4113c4a06fe6d46b5b660c00e55f5440a, https://github.com/gentoo/gentoo/blob/4463a8bd59a49bdba73880461f3cedccf6b8cdb6/dev-php/pecl-http/pecl-http-3.3.0.ebuild#L16C5-L16C5) has
USE_PHPdefined twiceOutput message
VariableShadowed
Documentation
Variable is shadowed / repeatedly declared. This is a possible typo.
Result level
warning