snowplow/snowplow-javascript-tracker

View on GitHub
plugins/browser-plugin-media-tracking/src/findElem.ts

Summary

Maintainability
B
4 hrs
Test Coverage

Function waitForElement has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
Open

export function waitForElement(config: StringConfig, callback: (element: ElementConfig) => void) {
  const { el, err } = findMediaElement(config.video);
  if (err) {
    LOG.info(`${err}. Waiting for element to be added to the DOM.`);
  }
Severity: Minor
Found in plugins/browser-plugin-media-tracking/src/findElem.ts - 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 findMediaElementChild has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

function findMediaElementChild(el: Element): SearchResult {
  for (let tag of ['VIDEO', 'AUDIO']) {
    let descendentTags = el.getElementsByTagName(tag);
    if (descendentTags.length === 1) {
      const el = descendentTags[0];
Severity: Minor
Found in plugins/browser-plugin-media-tracking/src/findElem.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

Avoid too many return statements within this function.
Open

  return findMediaElementChild(el);
Severity: Major
Found in plugins/browser-plugin-media-tracking/src/findElem.ts - About 30 mins to fix

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

    export function findMediaElement(id: string): SearchResult {
      let el: HTMLElement | null = document.getElementById(id);
    
      if (!el) return { err: SEARCH_ERROR.NOT_FOUND };
      if (isHtmlAudioElement(el)) return { el };
    Severity: Minor
    Found in plugins/browser-plugin-media-tracking/src/findElem.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