src/shapes/Text.ts
Function _setTextData
has a Cognitive Complexity of 67 (exceeds 5 allowed). Consider refactoring. Open
Open
_setTextData() {
var lines = this.text().split('\n'),
fontSize = +this.fontSize(),
textWidth = 0,
lineHeightPx = this.lineHeight() * fontSize,
- Read upRead up
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 541 lines of code (exceeds 250 allowed). Consider refactoring. Open
Open
import { Util } from '../Util';
import { Context } from '../Context';
import { Factory } from '../Factory';
import { Shape, ShapeConfig } from '../Shape';
import { Konva } from '../Global';
Function _sceneFunc
has a Cognitive Complexity of 48 (exceeds 5 allowed). Consider refactoring. Open
Open
_sceneFunc(context: Context) {
var textArr = this.textArr,
textArrLen = textArr.length;
if (!this.text()) {
- Read upRead up
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 128 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
_sceneFunc(context: Context) {
var textArr = this.textArr,
textArrLen = textArr.length;
if (!this.text()) {
Function _setTextData
has 100 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
_setTextData() {
var lines = this.text().split('\n'),
fontSize = +this.fontSize(),
textWidth = 0,
lineHeightPx = this.lineHeight() * fontSize,
Avoid deeply nested control flow statements. Open
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;
Avoid deeply nested control flow statements. Open
Open
if (shouldHandleEllipsis) {
this._tryToAddEllipsisToLastLine();
/*
* stop wrapping if wrapping is disabled or if adding
* one more line would overflow the fixed height
Avoid deeply nested control flow statements. Open
Open
if (substrWidth <= maxWidth) {
low = mid + 1;
match = substr;
matchWidth = substrWidth;
} else {
Avoid deeply nested control flow statements. Open
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