brma
(Brian W Matthews)
May 18, 2022, 3:10am
1
Must-share information (formatted with Markdown ):
which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension)
what are you trying to achieve
what have you tried so far to achieve this
SonarQube 9.3 and SonarLint 7.4
the error "remove the unused local variable’ is raised when a dummy local variable is used.
Sometimes this is unavoidable, as in
for _i in Range(10):
the workaround is to just use “_” but we already have a global _() used for translation purposes (gettext) so we get UnbouldLocalVariable warnings.
Is it possible to specify a regex to define ignored unused locals? In pylint for example it may be anything beginning with _, or dummy.
Hello @brma ,
Thank you for reporting this. It is true that the current implementation only silences issues for variables named “_” and that this is a bit too narrow. Unfortunately, at this time it is not possible to specify a regex to define allowed names.
I created the following ticket to improve this.
Though I know this is not a very satisfying workaround, in the meantime, you can silence the issue by using the NOSONAR
pragma comment:
for _i in range(10): # NOSONAR
print("Hello")
Cheers,
Guillaume
system
(system)
Closed
June 16, 2022, 12:50pm
5
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.