dleitee/valid.js

View on GitHub

Showing 10 of 20 total issues

Function isCnpj has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
Open

const isCnpj = cnpjNumber => {
    const cnpjRegex = /^(\d{2}[\.]?\d{3}[\.]?\d{3}[\/]?\d{4}[-]?\d{2})$/;
    if (cnpjRegex.test(cnpjNumber)) {
        const cnpj = cnpjNumber.replace(/\.|-|\//g, '');
        if (cnpj === '00000000000000' ||
Severity: Minor
Found in src/util.js - About 2 hrs to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function isCpf has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
Open

const isCpf = cpfNumber => {
    const cpfRegex = /^(\d{3}[\.]?\d{3}[\.]?\d{3}[-]?\d{2})$/;
    if (cpfRegex.test(cpfNumber)) {
        const cpf = cpfNumber.replace(/\.|-/g, '');
        if (cpf === '00000000000' ||
Severity: Minor
Found in src/util.js - About 2 hrs to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Consider simplifying this complex logical expression.
Open

        if (cnpj === '00000000000000' ||
            cnpj === '11111111111111' ||
            cnpj === '22222222222222' ||
            cnpj === '33333333333333' ||
            cnpj === '44444444444444' ||
Severity: Critical
Found in src/util.js - About 2 hrs to fix

    Consider simplifying this complex logical expression.
    Open

            if (cpf === '00000000000' ||
                cpf === '11111111111' ||
                cpf === '22222222222' ||
                cpf === '33333333333' ||
                cpf === '44444444444' ||
    Severity: Critical
    Found in src/util.js - About 2 hrs to fix

      Function isCnpj has 47 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      const isCnpj = cnpjNumber => {
          const cnpjRegex = /^(\d{2}[\.]?\d{3}[\.]?\d{3}[\/]?\d{4}[-]?\d{2})$/;
          if (cnpjRegex.test(cnpjNumber)) {
              const cnpj = cnpjNumber.replace(/\.|-|\//g, '');
              if (cnpj === '00000000000000' ||
      Severity: Minor
      Found in src/util.js - About 1 hr to fix

        Function isCpf has 41 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        const isCpf = cpfNumber => {
            const cpfRegex = /^(\d{3}[\.]?\d{3}[\.]?\d{3}[-]?\d{2})$/;
            if (cpfRegex.test(cpfNumber)) {
                const cpf = cpfNumber.replace(/\.|-/g, '');
                if (cpf === '00000000000' ||
        Severity: Minor
        Found in src/util.js - About 1 hr to fix

          Function validate has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

              (...fn) =>
                  value => {
                      if (isNil(value)) {
                          return false;
                      }
          Severity: Minor
          Found in src/validate.js - About 35 mins to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Avoid too many return statements within this function.
          Open

              return Boolean(value);
          Severity: Major
          Found in src/util.js - About 30 mins to fix

            Avoid too many return statements within this function.
            Open

                return false;
            Severity: Major
            Found in src/util.js - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                  return false;
              Severity: Major
              Found in src/util.js - About 30 mins to fix
                Severity
                Category
                Status
                Source
                Language