check-username

Try in Playground
js-rulesBest PracticeInformational

0

No tags

No CWE or CVE

This rule states that a username must include an "@" symbol. If it does not, an error will be thrown.

Ast Rule: try block


check-username

How to write a rule
function visit() {
	
let username = 'myusername';

if (!username.includes('@')) {
  throw new Error('The username must include an "@" symbol.');
}
}

test-1.js

Expected test result: no error

let testUsername = 'myusername';

function testUsernameSymbol() {
  if (!testUsername.includes('@')) {
    try {
      throw new Error('The username must include an "@" symbol.');
      return true;
    } catch(err) {
      return false;
    }
  }
}

let result = testUsernameSymbol();

if (result) {
  console.log("Test Passed");
} else {
  console.log("Test Failed");
}
Add comment

Log in to add a comment


    Be the first one to leave a comment!

Codiga Logo
Codiga Hub
  • Rulesets
  • Playground
  • Snippets
  • Cookbooks
soc-2 icon

We are SOC-2 Compliance Certified

G2 high performer medal

Codiga – All rights reserved 2022.