konvajs/konva

View on GitHub
src/shapes/Text.ts

Summary

Maintainability
F
4 days
Test Coverage

Function _setTextData has a Cognitive Complexity of 67 (exceeds 5 allowed). Consider refactoring.
Open

  _setTextData() {
    var lines = this.text().split('\n'),
      fontSize = +this.fontSize(),
      textWidth = 0,
      lineHeightPx = this.lineHeight() * fontSize,
Severity: Minor
Found in src/shapes/Text.ts - About 1 day 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

File Text.ts has 523 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import { Util } from '../Util';
import { Context } from '../Context';
import { Factory } from '../Factory';
import { Shape, ShapeConfig } from '../Shape';
import { Konva } from '../Global';
Severity: Major
Found in src/shapes/Text.ts - About 1 day to fix

    Function _sceneFunc has a Cognitive Complexity of 41 (exceeds 5 allowed). Consider refactoring.
    Open

      _sceneFunc(context: Context) {
        var textArr = this.textArr,
          textArrLen = textArr.length;
    
        if (!this.text()) {
    Severity: Minor
    Found in src/shapes/Text.ts - About 6 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 _sceneFunc has 121 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      _sceneFunc(context: Context) {
        var textArr = this.textArr,
          textArrLen = textArr.length;
    
        if (!this.text()) {
    Severity: Major
    Found in src/shapes/Text.ts - About 4 hrs to fix

      Function _setTextData has 100 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        _setTextData() {
          var lines = this.text().split('\n'),
            fontSize = +this.fontSize(),
            textWidth = 0,
            lineHeightPx = this.lineHeight() * fontSize,
      Severity: Major
      Found in src/shapes/Text.ts - About 4 hrs to fix

        Avoid deeply nested control flow statements.
        Open

                    if (shouldHandleEllipsis) {
                      this._tryToAddEllipsisToLastLine();
                      /*
                       * stop wrapping if wrapping is disabled or if adding
                       * one more line would overflow the fixed height
        Severity: Major
        Found in src/shapes/Text.ts - About 45 mins to fix

          Avoid deeply nested control flow statements.
          Open

                      if (substrWidth <= maxWidth) {
                        low = mid + 1;
                        match = substr;
                        matchWidth = substrWidth;
                      } else {
          Severity: Major
          Found in src/shapes/Text.ts - About 45 mins to fix

            Avoid deeply nested control flow statements.
            Open

                        if (wrapAtWord) {
                          // try to find a space or dash where wrapping could be done
                          var wrapIndex;
                          var nextChar = line[match.length];
                          var nextIsSpaceOrDash = nextChar === SPACE || nextChar === DASH;
            Severity: Major
            Found in src/shapes/Text.ts - About 45 mins to fix

              Avoid deeply nested control flow statements.
              Open

                          if (line.length > 0) {
                            // Check if the remaining text would fit on one line
                            lineWidth = this._getTextWidth(line);
                            if (lineWidth <= maxWidth) {
                              // if it does, add the line and break out of the loop
              Severity: Major
              Found in src/shapes/Text.ts - About 45 mins to fix

                There are no issues that match your filters.

                Category
                Status