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

define constant instead of duplicating 3 times

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 :

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

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

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