number-data-type

Try in Playground
js-rulesBest PracticeWarning

0

No tags

No CWE or CVE

This rule states that a variable with a value of 5 must be declared as a number data type. An error will be thrown if it is not declared as a number data type.

Ast Rule: try block


number-data-type

How to write a rule
function visit() {
//Rule

var num = 5;

if (typeof num !== 'number') {
  throw new Error('The variable must be declared as a number data type');
}
}

test-1.py

Expected test result: no error

let testNum = 'string';

function testNumDataType() {
  if (typeof testNum !== 'number') {
    try {
      throw new Error('The variable must be declared as a number data type');
      return true;
    } catch (e) {
      return false;
    }
  }
}

let result = testNumDataType();

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.