I’m fairly new to Node.js and I am having some issues. I received error in sonarqube as define a constant instead of duplicating 3 times for "Invalid Password". how can i resolved this issue.
export const MessageCodeMapping = {
REQUEST_COMPLETED_SUCCESSFULLY: {
code: "1",
description: "REQUEST_COMPLETED_SUCCESSFULLY",
detailedDescription: "REQUEST_COMPLETED_SUCCESSFULLY",
},
INVALID_CREATE_PASSWORD: {
code: "4",
description: "Invalid Password",
detailedDescription: `Invalid password.
Minimum of 8 characters and a maximum of 16.
Must have at least three of the following: uppercase letter, lowercase letter, number (0-9) and/or special character/symbol.
Password is case-sensitive.`,
},
INVALID_PSWRD: {
code: "2",
description: "Invalid Password",
detailedDescription: `Minimum of 8 and max of 16 characters - Requires 3 out of the following 4 options:
1. Lowercase characters
2. Uppercase characters
3. Numbers
4. Special characters.
Password is case sensitive.`,
},
INVALID_PASSWORD: {
code: "3",
description: "Invalid Password",
detailedDescription: `Minimum of 8 and max of 16 characters - Requires 3 out of the following 4 options:
1. Lowercase characters
2. Uppercase characters
3. Numbers
4. Special characters.
Password is case sensitive.`,
},
>Solution :
Exactly what it says on the tin: declare, say, const invalidPassword = "Invalid Password", and use that instead of the string. More resistant to typos, for starters. Easier to change, should you want to change the short decription in the future.
Also, even if SonarQube doesn’t object, I’d declare a constant for the repeated – long – detailedDescription for codes "2" and "3".