Загрузка данных


Adaptability issue | Not focused
Refactor this function to reduce its Cognitive Complexity from 22 to the 15 allowed.
Cognitive Complexity of functions should not be too hightypescript:S3776
Software qualities impacted:
Maintainability
Not assigned
Code Smell
Critical
Tags

brain-overload
+
Effort
12min
Introduced
45 minutes ago
Where is the issue?
Why is this an issue?
Activity
More Info
moex-chartsrc/core/Drawings/sliderPosition/sliderPosition.ts
See all issues in this file


      amount: this.settings.accountSize,
      settings: { ...this.settings },
    };
  }
  public setState(state: unknown): void {
Refactor this function to reduce its Cognitive Complexity from 22 to the 15 allowed.
    
if (!state 
|| typeof state !== 'object') {
      return;
    }
    const next = state as Partial<SliderPositionState>;
    this.hidden = next.hidden 
?? this.hidden;
    this.mode = next.mode 
?? this.mode;
    
if (next.startTime !== undefined) {
      this.startTime = next.startTime;
    }
    
if (next.endTime !== undefined) {
      this.endTime = next.endTime;
    }
    
if (next.entryPrice !== undefined) {
      this.entryPrice = next.entryPrice;
    }
    
if (next.stopPrice !== undefined) {
      this.stopPrice =
        next.stopPrice === null 
|| this.entryPrice === null
          
? next.stopPrice
          : this.normalizeStop(this.entryPrice, next.stopPrice);
    }
    
if (next.targetPrice !== undefined) {
      this.targetPrice =
        next.targetPrice === null 
|| this.entryPrice === null
          
? next.targetPrice
          : this.normalizeTarget(this.entryPrice, next.targetPrice);
    } else 
if (
      this.entryPrice !== null 
&&
      this.stopPrice !== null &&
      typeof next.riskRewardRatio === 'number' &&
      next.riskRewardRatio >= 0
    ) {
      const risk = Math.abs(this.entryPrice - this.stopPrice);
      const direction = this.side === 'long' 
? 1 : -1;
      this.targetPrice = this.normalizeTarget(
        this.entryPrice,
        this.entryPrice + risk * next.riskRewardRatio * direction,
      );
    }
    
if (next.settings) {
      this.settings = {
        ...createDefaultSettings(),
        ...next.settings,
      };
    }
Covered code
New Code
    
if (typeof next.amount === 'number' 
&& next.amount >= 0) {
      this.settings.accountSize = next.amount;
    }
    this.render();
  }







Adaptability issue | Not focused
Refactor this function to reduce its Cognitive Complexity from 16 to the 15 allowed.
Cognitive Complexity of functions should not be too hightypescript:S3776
Software qualities impacted:
Maintainability
Not assigned
Code Smell
Critical
Tags

brain-overload
+
Effort
6min
Introduced
47 minutes ago
Where is the issue?
Why is this an issue?
Activity
More Info
moex-chartsrc/core/Drawings/sliderPosition/sliderPosition.ts
See all issues in this file


    const formattedAmount = formatPrice(amount, 2) ?? '0';
    return `${t('Stop')}: ${formattedDiff} (${formatPercent(percent)}), ${t('Amount')}: ${formattedAmount}`;
  }
  private getHandleTarget(point: Point): DragTarget {
Refactor this function to reduce its Cognitive Complexity from 16 to the 15 allowed.
    const geometry = this.getGeometry();
    
if (!geometry) {
      return null;
    }
    
if (Math.abs(point.x - geometry.startX) <= HIT_TOLERANCE) {
      const entryDistance = Math.abs(point.y - geometry.entryY);
      
if (entryDistance < 1) {
        return 'entry';
      }
      const pointerSide = Math.sign(point.y - geometry.entryY);
      const targetSide = Math.sign(geometry.targetY - geometry.entryY) 
|| -Math.sign(geometry.stopY - geometry.entryY);
      const stopSide = Math.sign(geometry.stopY - geometry.entryY) 
|| -Math.sign(geometry.targetY - geometry.entryY);
      
if (pointerSide === targetSide 
&& Math.abs(point.y - geometry.targetY) <= HIT_TOLERANCE) {
        return 'target';
      }
      
if (pointerSide === stopSide 
&& Math.abs(point.y - geometry.stopY) <= HIT_TOLERANCE) {
        return 'stop';
      }
      
if (entryDistance <= HIT_TOLERANCE) {
        return 'entry';
      }
    }
    const handle = this.getDrawingHandleAtPoint(point);
    
if (handle) {
      return handle.id;
    }
    const bounds: Bounds = {
      left: geometry.leftX,
      right: geometry.rightX,
      top: Math.min(geometry.targetY, geometry.stopY),
      bottom: Math.max(geometry.targetY, geometry.stopY),
    };
    return isPointInBounds(point, bounds) 
? 'body' : null;
  }
  private containsPoint(point: Point): boolean {
    const geometry = this.getGeometry();



Intentionality issue | Not clear
Extract this nested ternary operation into an independent statement.
Ternary operators should not be nestedtypescript:S3358
Software qualities impacted:
Maintainability
Not assigned
Code Smell
Major
Tags

confusing
+
Effort
5min
Introduced
48 minutes ago
Where is the issue?
Why is this an issue?
Activity
moex-chartsrc/core/Drawings/sliderPosition/paneRenderer.ts
See all issues in this file


  viewportHeight: number,
): number {
  const targetSpace = Math.abs(targetY - entryY);
  const stopSpace = Math.abs(stopY - entryY);
  const direction = targetSpace < stopSpace ? (stopY < entryY ? -1 : 1) : targetY < entryY ? -1 : 1;
Extract this nested ternary operation into an independent statement.
Extract this nested ternary operation into an independent statement.
  return clampTextBoxCenter(entryY + direction * (labelOffset + boxHeight / 2), boxHeight, viewportHeight);
}
function clampTextBoxCenter(coordinate: number, boxHeight: number, viewportHeight: number): number {
  if (viewportHeight <= boxHeight) {
    return viewportHeight / 2;
  }




Intentionality issue | Not clear
Extract this nested ternary operation into an independent statement.
Ternary operators should not be nestedtypescript:S3358
Software qualities impacted:
Maintainability
Not assigned
Code Smell
Major
Tags

confusing
+
Effort
5min
Introduced
48 minutes ago
Where is the issue?
Why is this an issue?
Activity
moex-chartsrc/core/Drawings/sliderPosition/paneRenderer.ts
See all issues in this file


  viewportHeight: number,
): number {
  const targetSpace = Math.abs(targetY - entryY);
  const stopSpace = Math.abs(stopY - entryY);
  const direction = targetSpace < stopSpace ? (stopY < entryY ? -1 : 1) : targetY < entryY ? -1 : 1;
Extract this nested ternary operation into an independent statement.
Extract this nested ternary operation into an independent statement.
  return clampTextBoxCenter(entryY + direction * (labelOffset + boxHeight / 2), boxHeight, viewportHeight);
}
function clampTextBoxCenter(coordinate: number, boxHeight: number, viewportHeight: number): number {
  if (viewportHeight <= boxHeight) {
    return viewportHeight / 2;
  }