Skip to content

[New Check]: Multiple assignments to a variable (maybe just eclass vars?) in global scope #622

@thesamesam

Description

@thesamesam

Is there an existing such new check request for this?

  • I have searched the existing issues

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

Metadata

Metadata

Assignees

Labels

bashrequires bash-parsing supportcheck

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions