teableio/teable

View on GitHub
packages/core/src/formula/visitor.ts

Summary

Maintainability
C
7 hrs
Test Coverage

File visitor.ts has 319 lines of code (exceeds 300 allowed). Consider refactoring.
Open

/* eslint-disable @typescript-eslint/no-non-null-assertion */
/* eslint-disable @typescript-eslint/no-explicit-any */
import { AbstractParseTreeVisitor } from 'antlr4ts/tree/AbstractParseTreeVisitor';
import { CellValueType } from '../models/field/constant';
import type { FieldCore } from '../models/field/field';
Severity: Minor
Found in packages/core/src/formula/visitor.ts - About 2 hrs to fix

    Function visitBinaryOp has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

      visitBinaryOp(ctx: BinaryOpContext) {
        const leftNode = ctx.expr(0);
        const rightNode = ctx.expr(1);
        const left = this.visit(leftNode)!;
        const right = this.visit(rightNode)!;
    Severity: Minor
    Found in packages/core/src/formula/visitor.ts - 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 transformNodeValue has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

      private transformNodeValue(typedValue: TypedValue, ctx: BinaryOpContext) {
        // A Node with a field value type requires dedicated string conversion logic to be executed.
        if (!typedValue.field) {
          return typedValue;
        }
    Severity: Minor
    Found in packages/core/src/formula/visitor.ts - 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 transformUnaryNodeValue has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

      private transformUnaryNodeValue(typedValue: TypedValue) {
        if (!typedValue.field) {
          return typedValue;
        }
    
    
    Severity: Minor
    Found in packages/core/src/formula/visitor.ts - 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 CellValueType.String;
    Severity: Major
    Found in packages/core/src/formula/visitor.ts - About 30 mins to fix

      Avoid too many return statements within this function.
      Open

          return new TypedValue(field.cellValue2String(typedValue.value), CellValueType.String);
      Severity: Major
      Found in packages/core/src/formula/visitor.ts - About 30 mins to fix

        Avoid too many return statements within this function.
        Open

              return typedValue;
        Severity: Major
        Found in packages/core/src/formula/visitor.ts - About 30 mins to fix

          Avoid too many return statements within this function.
          Open

              return typedValue;
          Severity: Major
          Found in packages/core/src/formula/visitor.ts - About 30 mins to fix

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

              visitFunctionCall(ctx: FunctionCallContext) {
                const fnName = ctx.func_name().text.toUpperCase() as FunctionName;
                const func = FUNCTIONS[fnName];
                if (!func) {
                  throw new TypeError(`Function name ${func} is not found`);
            Severity: Minor
            Found in packages/core/src/formula/visitor.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