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-
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.