epoberezkin/ajv

View on GitHub
lib/runtime/parseJson.ts

Summary

Maintainability
D
1 day
Test Coverage

Function parseJsonString has a Cognitive Complexity of 33 (exceeds 5 allowed). Consider refactoring.
Open

export function parseJsonString(s: string, pos: number): string | undefined {
  let str = ""
  let c: string | undefined
  parseJsonString.message = undefined
  // eslint-disable-next-line no-constant-condition, @typescript-eslint/no-unnecessary-condition
Severity: Minor
Found in lib/runtime/parseJson.ts - About 4 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 parseJsonNumber has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
Open

export function parseJsonNumber(s: string, pos: number, maxDigits?: number): number | undefined {
  let numStr = ""
  let c: string
  parseJsonNumber.message = undefined
  if (s[pos] === "-") {
Severity: Minor
Found in lib/runtime/parseJson.ts - About 3 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 parseJsonString has 56 lines of code (exceeds 25 allowed). Consider refactoring.
Open

export function parseJsonString(s: string, pos: number): string | undefined {
  let str = ""
  let c: string | undefined
  parseJsonString.message = undefined
  // eslint-disable-next-line no-constant-condition, @typescript-eslint/no-unnecessary-condition
Severity: Major
Found in lib/runtime/parseJson.ts - About 2 hrs to fix

    Function parseJsonNumber has 55 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    export function parseJsonNumber(s: string, pos: number, maxDigits?: number): number | undefined {
      let numStr = ""
      let c: string
      parseJsonNumber.message = undefined
      if (s[pos] === "-") {
    Severity: Major
    Found in lib/runtime/parseJson.ts - About 2 hrs to fix

      Avoid deeply nested control flow statements.
      Open

                if (c === undefined) {
                  errorMessage("unexpected end")
                  return undefined
                }
      Severity: Major
      Found in lib/runtime/parseJson.ts - About 45 mins to fix

        Avoid deeply nested control flow statements.
        Open

                  if (c >= "a" && c <= "f") {
                    code += c.charCodeAt(0) - CODE_A + 10
                  } else if (c >= "0" && c <= "9") {
                    code += c.charCodeAt(0) - CODE_0
                  } else {
        Severity: Major
        Found in lib/runtime/parseJson.ts - About 45 mins to fix

          Avoid too many return statements within this function.
          Open

            return str
          Severity: Major
          Found in lib/runtime/parseJson.ts - About 30 mins to fix

            Avoid too many return statements within this function.
            Open

              return +numStr
            Severity: Major
            Found in lib/runtime/parseJson.ts - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                      return undefined
              Severity: Major
              Found in lib/runtime/parseJson.ts - About 30 mins to fix

                Function parseJson has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                Open

                export function parseJson(s: string, pos: number): unknown {
                  let endPos: number | undefined
                  parseJson.message = undefined
                  let matches: RegExpExecArray | null
                  if (pos) s = s.slice(pos)
                Severity: Minor
                Found in lib/runtime/parseJson.ts - About 25 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

                There are no issues that match your filters.

                Category
                Status