snowplow/snowplow-javascript-tracker

View on GitHub

Showing 145 of 325 total issues

Function toSessionContextEntity has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

  toSessionContextEntity(): MediaSessionStats {
    return {
      timePaused: this.pausedDuration > 0 ? this.round(this.pausedDuration) : undefined,
      timePlayed: this.playbackDuration > 0 ? this.round(this.playbackDuration) : undefined,
      timePlayedMuted: this.playbackDurationMuted > 0 ? this.round(this.playbackDurationMuted) : undefined,
Severity: Minor
Found in plugins/browser-plugin-media/src/sessionStats.ts - About 1 hr 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 createCrossDomainParameterValue has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

export function createCrossDomainParameterValue(
  isExtendedFormat: boolean,
  attributeConfiguration: ExtendedCrossDomainLinkerAttributes | undefined,
  attributeValues: ExtendedCrossDomainLinkerValues & {
    /* As `reason` might be a callback, we also need to pass the event to calculate the reason value. */
Severity: Minor
Found in libraries/browser-tracker-core/src/helpers/cross_domain.ts - About 1 hr 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 updateAdStats has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

  private updateAdStats(log: Log) {
    // only works with ad event types
    if (log.eventType === undefined) {
      return;
    }
Severity: Minor
Found in plugins/browser-plugin-media/src/sessionStats.ts - About 1 hr 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 validateVendorParts has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

export function validateVendorParts(parts: Array<string>): boolean {
  if (parts[0] === '*' || parts[1] === '*') {
    return false; // no wildcard in first or second part
  }
  if (parts.slice(2).length > 0) {
Severity: Minor
Found in libraries/tracker-core/src/contexts.ts - About 1 hr 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 syncNpmrc has 27 lines of code (exceeds 25 allowed). Consider refactoring.
Open

function syncNpmrc(options) {
    const { sourceNpmrcFolder, targetNpmrcFolder, useNpmrcPublish, logger = {
        // eslint-disable-next-line no-console
        info: console.log,
        // eslint-disable-next-line no-console
Severity: Minor
Found in common/scripts/install-run.js - About 1 hr to fix

    Function updateDurationStats has 27 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      private updateDurationStats(log: Log) {
        // if ad was playing until now and it was a linear ad, don't add the duration stats
        let wasPlayingAd = this.lastAdUpdateAt !== undefined;
        const shouldCountStats = (!wasPlayingAd || !log.linearAd) ?? true;
        if (!shouldCountStats) {
    Severity: Minor
    Found in plugins/browser-plugin-media/src/sessionStats.ts - About 1 hr to fix

      Function buildHTMLMediaElementEntity has 27 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      export function buildHTMLMediaElementEntity(el: HTMLAudioElement | HTMLVideoElement): SelfDescribingJson {
        const data: MediaElement = {
          // htmlId is a required property in the schema, but may not be present if
          // the user provided the element themselves
          htmlId: el.id || '',
      Severity: Minor
      Found in plugins/browser-plugin-media-tracking/src/entities.ts - About 1 hr to fix

        Function clearUserDataAndCookies has 26 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            function clearUserDataAndCookies(configuration?: ClearUserDataConfiguration) {
              const idname = getSnowplowCookieName('id');
              const sesname = getSnowplowCookieName('ses');
              attemptDeleteLocalStorage(idname);
              attemptDeleteLocalStorage(sesname);
        Severity: Minor
        Found in libraries/browser-tracker-core/src/tracker/index.ts - About 1 hr to fix

          Function decorateQuerystring has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

          export function decorateQuerystring(url: string, name: string, value: string) {
            var initialQsParams = name + '=' + value;
            var hashSplit = url.split('#');
            var qsSplit = hashSplit[0].split('?');
            var beforeQuerystring = qsSplit.shift();
          Severity: Minor
          Found in libraries/browser-tracker-core/src/helpers/index.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

          Function matchSchemaAgainstRule has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

          export function matchSchemaAgainstRule(rule: string, schema: string): boolean {
            if (!isValidRule(rule)) return false;
            const ruleParts = getRuleParts(rule);
            const schemaParts = getSchemaParts(schema);
            if (ruleParts && schemaParts) {
          Severity: Minor
          Found in libraries/tracker-core/src/contexts.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

          Function eventHandler has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

          function eventHandler(event: MouseEvent, trackerId: string, filter: FilterFunction, context?: DynamicContext) {
            let elem = (event.composed ? event.composedPath()[0] : event.target) as HTMLElement | null;
            while (elem) {
              if (elem instanceof HTMLButtonElement || (elem instanceof HTMLInputElement && elem.type === 'button')) {
                if (filter(elem)) {
          Severity: Minor
          Found in plugins/browser-plugin-button-click-tracking/src/api.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

          Function constructor has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

            constructor(configuration?: FilterOutRepeatedEvents) {
              let allFiltersEnabled = configuration === undefined || configuration === true;
              if (allFiltersEnabled || (typeof configuration === 'object' && configuration.seekEvents !== false)) {
                this.aggregateEventsWithOrder[getMediaEventSchema(MediaEventType.SeekStart)] = true;
                this.aggregateEventsWithOrder[getMediaEventSchema(MediaEventType.SeekEnd)] = false;
          Severity: Minor
          Found in plugins/browser-plugin-media/src/repeatedEventFilter.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

          Function initializeResizeObserver has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

          function initializeResizeObserver() {
            if (resizeObserverInitialized) {
              return;
            }
            if(!document || !document.body || !document.documentElement) {
          Severity: Minor
          Found in libraries/browser-tracker-core/src/helpers/browser_props.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

          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

          Function newLocalStorageEventStore has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

          export function newLocalStorageEventStore({
            trackerId,
            maxLocalStorageQueueSize = 1000,
            useLocalStorage = true,
          }: LocalStorageEventStoreConfiguration): LocalStorageEventStore {
          Severity: Minor
          Found in libraries/browser-tracker-core/src/tracker/local_storage_event_store.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

          Function update has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

            update(
              trackEvent: (event: EventWithContext) => void,
              mediaEvent?: MediaEvent,
              customEvent?: SelfDescribingJson,
              player?: MediaPlayerUpdate,
          Severity: Minor
          Found in plugins/browser-plugin-media/src/mediaTracking.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

          Function cookie has 7 arguments (exceeds 4 allowed). Consider refactoring.
          Open

            name: string,
            value?: string,
            ttl?: number,
            path?: string,
            domain?: string,
          Severity: Major
          Found in libraries/browser-tracker-core/src/helpers/index.ts - About 50 mins to fix

            Function setCookie has 7 arguments (exceeds 4 allowed). Consider refactoring.
            Open

                name: string,
                value?: string,
                ttl?: number,
                path?: string,
                domain?: string,
            Severity: Major
            Found in libraries/browser-tracker-core/src/tracker/cookie_storage.ts - About 50 mins to fix

              Function installAndRun has 6 arguments (exceeds 4 allowed). Consider refactoring.
              Open

              function installAndRun(logger, packageName, packageVersion, packageBinName, packageBinArgs, lockFilePath = process.env[INSTALL_RUN_LOCKFILE_PATH_VARIABLE]) {
              Severity: Minor
              Found in common/scripts/install-run.js - About 45 mins to fix

                Function evaluateProvider has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                Open

                function evaluateProvider(
                  provider: ConditionalContextProvider,
                  event: PayloadBuilder,
                  eventType: string,
                  eventSchema: string
                Severity: Minor
                Found in libraries/tracker-core/src/contexts.ts - About 45 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