snowplow/snowplow-javascript-tracker

View on GitHub

Showing 352 of 352 total issues

Similar blocks of code found in 2 locations. Consider refactoring.
Open

  private clearFlushTimeout() {
    if (this.flushTimeout !== undefined) {
      clearTimeout(this.flushTimeout);
      this.flushTimeout = undefined;
    }
Severity: Minor
Found in plugins/browser-plugin-media/src/repeatedEventFilter.ts and 1 other location - About 30 mins to fix
plugins/browser-plugin-media/src/pingInterval.ts on lines 39..44

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 45.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

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

function installAndRun(logger, packageName, packageVersion, packageBinName, packageBinArgs) {
    const rushJsonFolder = findRushJsonFolder();
    const rushCommonFolder = path.join(rushJsonFolder, 'common');
    const rushTempFolder = _getRushTempFolder(rushCommonFolder);
    const packageInstallFolder = _ensureAndJoinPath(rushTempFolder, 'install-run', `${packageName}@${packageVersion}`);
Severity: Minor
Found in common/scripts/install-run.js - 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

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

function setUpListeners(id: string, conf: TrackingOptions, eventHandlers: Record<string, Function>) {
  // The element may not be loaded in time for this function to run, so we have a few goes at finding the element
  const result = findMediaElem(id);

  if (!trackedIds[id].retryCount) {
Severity: Minor
Found in plugins/browser-plugin-media-tracking/src/index.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

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

function getSpecifiedClassesSet<T>(criterion: FilterCriterion<T>) {
  // Convert the array of classes to an object of the form {class1: true, class2: true, ...}
  var specifiedClassesSet: Record<string, boolean> = {};
  var specifiedClasses = criterion.allowlist || criterion.denylist;

Severity: Minor
Found in libraries/browser-tracker-core/src/helpers/index.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

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

export function filterFunctionFromFilter(filter?: Filter): FilterFunction {
  // If a function is provided, return it as-is
  if (typeof filter === 'function') {
    return filter;
  }
Severity: Minor
Found in plugins/browser-plugin-button-click-tracking/src/util.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

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

function sendRequest(url: string, userId: string, LOG: Logger, successCallback: () => void): void {
  const xhr = new XMLHttpRequest();
  xhr.open('GET', getKantarURL(url, userId));
  xhr.timeout = 5000;

Severity: Minor
Found in plugins/browser-plugin-focalmeter/src/index.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

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

export function findRootDomain(sameSite: string, secure: boolean) {
  const windowLocationHostnameAlias = window.location.hostname,
    cookiePrefix = '_sp_root_domain_test_',
    cookieName = cookiePrefix + new Date().getTime(),
    cookieValue = '_test_value_' + new Date().getTime();
Severity: Minor
Found in libraries/browser-tracker-core/src/helpers/index.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

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

export function base64decode(encodedData: string): string {
  //  discuss at: http://locutus.io/php/base64_decode/
  // original by: Tyler Akins (http://rumkin.com)
  // improved by: Thunder.m
  // improved by: Kevin van Zonneveld (http://kvz.io)
Severity: Minor
Found in libraries/tracker-core/src/base64.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

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

export function findMediaElem(id: string): SearchResult {
  let el: HTMLVideoElement | HTMLAudioElement | HTMLElement | null = document.getElementById(id);

  if (!el) return { err: SEARCH_ERROR.NOT_FOUND };
  if (isAudioElement(el)) return { el: el };
Severity: Minor
Found in plugins/browser-plugin-media-tracking/src/findMediaElement.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

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

export function fixupUrl(hostName: string, href: string, referrer: string) {
  if (hostName === 'translate.googleusercontent.com') {
    // Google
    if (referrer === '') {
      referrer = href;
Severity: Minor
Found in libraries/browser-tracker-core/src/proxies.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

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

function getConfigurationForOptions(options?: FormTrackingOptions) {
  if (options) {
    let formFilter = (_: HTMLElement) => true;
    let forms: HTMLCollectionOf<HTMLFormElement> | NodeListOf<HTMLFormElement> | null = null;
    if (isCollectionOfHTMLFormElements(options.forms)) {
Severity: Minor
Found in plugins/browser-plugin-form-tracking/src/helpers.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

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

export function getReferrer(oldLocation?: string) {
  let windowAlias = window,
    fromQs =
      fromQuerystring('referrer', windowAlias.location.href) || fromQuerystring('referer', windowAlias.location.href);

Severity: Minor
Found in libraries/browser-tracker-core/src/helpers/index.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

Severity
Category
Status
Source
Language