Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to solve- "<Something> is already declared in the upper scope" code smells?

I am getting following code smell in my sonarqube dashboard, and I am not sure how to resolve such issues.

‘isInitialized’ is already declared in the upper scope.

Here’s my code-

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

let _isInitialized = false;

/**
 * Getter for _isInitialized
 *
 * @return {Boolean} _isInitialized
 */
export const isInitialized = function() {
    return _isInitialized;
};

/**
 * Sets isInitialized
 * @param {Boolean} isInitialized new value for inititialized
 */
export const setIsInitialized = function( isInitialized ) {
    _isInitialized = isInitialized;
};

Can anyone please explain what’s the problem in my code?

Don’t know what to try as my code is working correctly but getting this issue on sonarqube dashboard.

>Solution :

Here you define a variable called isInitialized in the scope of the module using const

export const isInitialized = function() {

Here you define a variable with the same name in the scope of the function using an argument name.

export const setIsInitialized = function( isInitialized ) {

Don’t do that. Use unique names for variables.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading