fix: resolve 10 SonarQube issues in metadata_routing example#634
Merged
Conversation
Fixed issues: - AZ45C0jTRXnEWm2Rf6J- for python:S117 rule - AZ45C0jTRXnEWm2Rf6J7 for python:S6711 rule - AZ45C0jTRXnEWm2Rf6J_ for python:S117 rule - AZ45C0jTRXnEWm2Rf6J9 for python:S1172 rule - AZ45C0jTRXnEWm2Rf6J8 for python:S1172 rule - AZ45C0jTRXnEWm2Rf6KE for python:S1172 rule - AZ45C0jTRXnEWm2Rf6KF for python:S1172 rule - AZ45C0jTRXnEWm2Rf6KC for python:S4487 rule - AZ45C0jTRXnEWm2Rf6KA for python:S1172 rule - AZ45C0jTRXnEWm2Rf6KB for python:S1172 rule Generated by SonarQube Agent (task: c66f3302-ea9e-45a7-a5e2-80cdc9908b81)
SonarQube reviewer guide
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.




This change fixes 10 SonarQube violations in the metadata routing example by renaming variables to match naming conventions, modernizing NumPy random API usage, documenting unused required parameters, and fixing a private attribute naming issue. These improvements enhance code quality and ensure compliance with project standards.
View Project in SonarCloud
Fixed Issues
python:S117 - Rename this local variable "X_transformed" to match the regular expression ^[_a-z][a-z0-9_]*$. • MINOR • View issue
Location:
examples/miscellaneous/plot_metadata_routing.py:501Why is this an issue?
A naming convention in software development is a set of guidelines for naming code elements like variables, functions, and classes.
Local variables and function parameters hold the meaning of the written code. Their names should be meaningful and follow a consistent and easily recognizable pattern.
Adhering to a consistent naming convention helps to make the code more readable and understandable, which makes it easier to maintain and debug. It also ensures consistency in the code, especially when multiple developers are working on the same project.
What changed
Renames the local variable
X_transformedtox_transformedin thefitmethod ofSimplePipeline, making it comply with the snake_case naming convention (matching the regex^[_a-z][a-z0-9_]*$). This fixes the naming convention violation at line 501.python:S117 - Rename this local variable "X_transformed" to match the regular expression ^[_a-z][a-z0-9_]*$. • MINOR • View issue
Location:
examples/miscellaneous/plot_metadata_routing.py:513Why is this an issue?
A naming convention in software development is a set of guidelines for naming code elements like variables, functions, and classes.
Local variables and function parameters hold the meaning of the written code. Their names should be meaningful and follow a consistent and easily recognizable pattern.
Adhering to a consistent naming convention helps to make the code more readable and understandable, which makes it easier to maintain and debug. It also ensures consistency in the code, especially when multiple developers are working on the same project.
What changed
Renames the local variable
X_transformedtox_transformedin thepredictmethod ofSimplePipeline, making it comply with the snake_case naming convention (matching the regex^[_a-z][a-z0-9_]*$). This fixes the naming convention violation at line 513.python:S6711 - Use a "numpy.random.Generator" here instead of this legacy function. • MAJOR • View issue
Location:
examples/miscellaneous/plot_metadata_routing.py:59Why is this an issue?
Using a predictable seed is a common best practice when using NumPy to create reproducible results. To that end, using
np.random.seed(number)to set the seed of the globalnumpy.random.RandomStatehas been the privileged solution for a long time.What changed
Replaces the legacy
np.random.RandomState(42)with the modernnp.random.default_rng(42), and updates all subsequent calls from legacy methods (rand,randint) to theirnumpy.random.Generatorequivalents (random,integers). This directly fixes the warning about using legacynumpy.random.RandomStateinstead ofnumpy.random.Generator.python:S1172 - Remove the unused function parameter "y". • MAJOR • View issue
Location:
examples/miscellaneous/plot_metadata_routing.py:99Why is this an issue?
A typical code smell known as unused function parameters refers to parameters declared in a function but not used anywhere within the function’s body. While this might seem harmless at first glance, it can lead to confusion and potential errors in your code. Disregarding the values passed to such parameters, the function’s behavior will be the same, but the programmer’s intention won’t be clearly expressed anymore. Therefore, removing function parameters that are not being utilized is considered best practice.
What changed
Adds a comment documenting that the
Xandyparameters are required by the scikit-learn API but not used in this example classifier'sfitmethod. This addresses the unused function parameter warnings forXandyin theExampleClassifier.fitmethod, since the rule exempts parameters that are referenced in a comment.python:S1172 - Remove the unused function parameter "X". • MAJOR • View issue
Location:
examples/miscellaneous/plot_metadata_routing.py:99Why is this an issue?
A typical code smell known as unused function parameters refers to parameters declared in a function but not used anywhere within the function’s body. While this might seem harmless at first glance, it can lead to confusion and potential errors in your code. Disregarding the values passed to such parameters, the function’s behavior will be the same, but the programmer’s intention won’t be clearly expressed anymore. Therefore, removing function parameters that are not being utilized is considered best practice.
What changed
Adds a comment documenting that the
Xandyparameters are required by the scikit-learn API but not used in this example classifier'sfitmethod. This addresses the unused function parameter warnings forXandyin theExampleClassifier.fitmethod, since the rule exempts parameters that are referenced in a comment.python:S1172 - Remove the unused function parameter "X". • MAJOR • View issue
Location:
examples/miscellaneous/plot_metadata_routing.py:541Why is this an issue?
A typical code smell known as unused function parameters refers to parameters declared in a function but not used anywhere within the function’s body. While this might seem harmless at first glance, it can lead to confusion and potential errors in your code. Disregarding the values passed to such parameters, the function’s behavior will be the same, but the programmer’s intention won’t be clearly expressed anymore. Therefore, removing function parameters that are not being utilized is considered best practice.
What changed
Adds a docstring to the
ExampleTransformer.fitmethod that references theX,y, andsample_weightparameters. This addresses the unused function parameter warnings forXandyin that method, since the rule exempts parameters that are referenced in a docstring.python:S1172 - Remove the unused function parameter "y". • MAJOR • View issue
Location:
examples/miscellaneous/plot_metadata_routing.py:541Why is this an issue?
A typical code smell known as unused function parameters refers to parameters declared in a function but not used anywhere within the function’s body. While this might seem harmless at first glance, it can lead to confusion and potential errors in your code. Disregarding the values passed to such parameters, the function’s behavior will be the same, but the programmer’s intention won’t be clearly expressed anymore. Therefore, removing function parameters that are not being utilized is considered best practice.
What changed
Adds a docstring to the
ExampleTransformer.fitmethod that references theX,y, andsample_weightparameters. This addresses the unused function parameter warnings forXandyin that method, since the rule exempts parameters that are referenced in a docstring.python:S4487 - Remove this unread private attribute '__metadata_request__fit' or refactor the code to use its value. • CRITICAL • View issue
Location:
examples/miscellaneous/plot_metadata_routing.py:626Why is this an issue?
Python has no real private attribute. Every attribute is accessible. There are however two conventions indicating that an attribute is not meant to be "public":
What changed
Renames the class attribute from
__metadata_request__fit(double-underscore prefix, making it a class-private/name-mangled attribute) to_metadata_request__fit(single-underscore prefix). This fixes the warning about an unread private attribute, since the attribute with double underscores was being name-mangled and thus appeared unread within the class. With a single underscore, it is no longer subject to the class-private attribute rule (S4487).python:S1172 - Remove the unused function parameter "X". • MAJOR • View issue
Location:
examples/miscellaneous/plot_metadata_routing.py:672Why is this an issue?
A typical code smell known as unused function parameters refers to parameters declared in a function but not used anywhere within the function’s body. While this might seem harmless at first glance, it can lead to confusion and potential errors in your code. Disregarding the values passed to such parameters, the function’s behavior will be the same, but the programmer’s intention won’t be clearly expressed anymore. Therefore, removing function parameters that are not being utilized is considered best practice.
What changed
Adds a docstring to the
ExampleRegressor.fitmethod that referencesX,y, andsample_weight. This addresses the unused function parameter warnings forXandyin that method, since the rule exempts parameters that are referenced in a docstring.python:S1172 - Remove the unused function parameter "y". • MAJOR • View issue
Location:
examples/miscellaneous/plot_metadata_routing.py:672Why is this an issue?
A typical code smell known as unused function parameters refers to parameters declared in a function but not used anywhere within the function’s body. While this might seem harmless at first glance, it can lead to confusion and potential errors in your code. Disregarding the values passed to such parameters, the function’s behavior will be the same, but the programmer’s intention won’t be clearly expressed anymore. Therefore, removing function parameters that are not being utilized is considered best practice.
What changed
Adds a docstring to the
ExampleRegressor.fitmethod that referencesX,y, andsample_weight. This addresses the unused function parameter warnings forXandyin that method, since the rule exempts parameters that are referenced in a docstring.SonarQube Remediation Agent uses AI. Check for mistakes.