[python:S1481] Code Smell: Unused local variables should be removed - False-Positive with string interpolation

  • SonarQube 6.5
  • Application analyzed is using Python 3.6

Code:

def get_conn_string():
    database_user = os.getenv("DATABASE_USER")
    database_pass = os.getenv("DATABASE_PASS")
    database_host = os.getenv("DATABASE_HOST")
    database_port = os.getenv("DATABASE_PORT",  3306)
    database_schema = os.getenv("DATABASE_SCHEMA")

    return f"mysql+mysqlconnector://{database_user}:{database_pass}@{database_host}:{database_port}/{database_schema}"

The code above is showing the code smell Unused local variables should be removed for all local variables in the function, but all the variables are used in the string interpolation in the return statement.

Hi!

I believe that we fixed this issue in version 1.9 of the Python analyzer:
https://jira.sonarsource.com/browse/SONARPY-243

You will need to use SonarQube 6.7 (LTS) or any newer version.

Pierre-Yves

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.