packages/babel-traverse/src/path/inference/inferer-reference.js

Summary

Maintainability
D
1 day
Test Coverage

Function getConditionalAnnotation has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
Open

function getConditionalAnnotation(binding, path, name) {
  const ifStatement = getParentConditionalPath(binding, path, name);
  if (!ifStatement) return;

  const test = ifStatement.get("test");
Severity: Minor
Found in packages/babel-traverse/src/path/inference/inferer-reference.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 inferAnnotationFromBinaryExpression has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
Open

function inferAnnotationFromBinaryExpression(name, path) {
  const operator = path.node.operator;

  const right = path.get("right").resolve();
  const left = path.get("left").resolve();
Severity: Minor
Found in packages/babel-traverse/src/path/inference/inferer-reference.js - About 1 hr 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 getConditionalAnnotation has 36 lines of code (exceeds 25 allowed). Consider refactoring.
Open

function getConditionalAnnotation(binding, path, name) {
  const ifStatement = getParentConditionalPath(binding, path, name);
  if (!ifStatement) return;

  const test = ifStatement.get("test");
Severity: Minor
Found in packages/babel-traverse/src/path/inference/inferer-reference.js - About 1 hr to fix

    Function getParentConditionalPath has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

    function getParentConditionalPath(binding, path, name) {
      let parentPath;
      while ((parentPath = path.parentPath)) {
        if (parentPath.isIfStatement() || parentPath.isConditionalExpression()) {
          if (path.key === "test") {
    Severity: Minor
    Found in packages/babel-traverse/src/path/inference/inferer-reference.js - About 1 hr 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 inferAnnotationFromBinaryExpression has 35 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    function inferAnnotationFromBinaryExpression(name, path) {
      const operator = path.node.operator;
    
      const right = path.get("right").resolve();
      const left = path.get("left").resolve();
    Severity: Minor
    Found in packages/babel-traverse/src/path/inference/inferer-reference.js - About 1 hr to fix

      Function getTypeAnnotationBindingConstantViolations has 34 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      function getTypeAnnotationBindingConstantViolations(binding, path, name) {
        const types = [];
      
        const functionConstantViolations = [];
        let constantViolations = getConstantViolationsBefore(
      Severity: Minor
      Found in packages/babel-traverse/src/path/inference/inferer-reference.js - About 1 hr to fix

        Function default has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

        export default function (node: Object) {
          if (!this.isReferenced()) return;
        
          // check if a binding exists of this value and if so then return a union type of all
          // possible types that the binding could be
        Severity: Minor
        Found in packages/babel-traverse/src/path/inference/inferer-reference.js - About 55 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

        Function getTypeAnnotationBindingConstantViolations has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

        function getTypeAnnotationBindingConstantViolations(binding, path, name) {
          const types = [];
        
          const functionConstantViolations = [];
          let constantViolations = getConstantViolationsBefore(
        Severity: Minor
        Found in packages/babel-traverse/src/path/inference/inferer-reference.js - About 45 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

          if (!typeofPath.get("argument").isIdentifier({ name })) return;
        Severity: Major
        Found in packages/babel-traverse/src/path/inference/inferer-reference.js - About 30 mins to fix

          Avoid too many return statements within this function.
          Open

              return t.numberTypeAnnotation();
          Severity: Major
          Found in packages/babel-traverse/src/path/inference/inferer-reference.js - About 30 mins to fix

            Avoid too many return statements within this function.
            Open

              if (!typePath.isLiteral()) return;
            Severity: Major
            Found in packages/babel-traverse/src/path/inference/inferer-reference.js - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                return t.createTypeAnnotationBasedOnTypeof(typeValue);
              Severity: Major
              Found in packages/babel-traverse/src/path/inference/inferer-reference.js - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                  if (typeof typeValue !== "string") return;
                Severity: Major
                Found in packages/babel-traverse/src/path/inference/inferer-reference.js - About 30 mins to fix

                  Avoid too many return statements within this function.
                  Open

                    if (!typeofPath) return;
                  Severity: Major
                  Found in packages/babel-traverse/src/path/inference/inferer-reference.js - About 30 mins to fix

                    Avoid too many return statements within this function.
                    Open

                      return getConditionalAnnotation(ifStatement, name);
                    Severity: Major
                    Found in packages/babel-traverse/src/path/inference/inferer-reference.js - About 30 mins to fix

                      There are no issues that match your filters.

                      Category
                      Status