snowplow/snowplow-javascript-tracker

View on GitHub

Showing 153 of 352 total issues

Function FocalMeterPlugin has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

export function FocalMeterPlugin(): BrowserPlugin {
  let LOG: Logger;
  let lastUserId: string | undefined | null;
  let trackerId: string;

Severity: Minor
Found in plugins/browser-plugin-focalmeter/src/index.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 payloadBuilder has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

export function payloadBuilder(): PayloadBuilder {
  const dict: Payload = {},
    allJson: EventJson = [],
    jsonForProcessing: EventJson = [],
    contextEntitiesForProcessing: SelfDescribingJson[] = [];
Severity: Minor
Found in libraries/tracker-core/src/payload.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 gotEmitter has 10 arguments (exceeds 4 allowed). Consider refactoring.
Open

  endpoint: string,
  protocol: HttpProtocol = HttpProtocol.HTTPS,
  port?: number,
  method?: HttpMethod,
  bufferSize?: number,
Severity: Major
Found in trackers/node-tracker/src/got_emitter.ts - About 1 hr to fix

    Function _run has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

    function _run() {
        const [nodePath /* Ex: /bin/node */, scriptPath /* /repo/common/scripts/install-run-rush.js */, ...packageBinArgs /* [build, --to, myproject] */] = process.argv;
        // Detect if this script was directly invoked, or if the install-run-rushx script was invokved to select the
        // appropriate binary inside the rush package to run
        const scriptName = path.basename(scriptPath);
    Severity: Minor
    Found in common/scripts/install-run-rush.js - 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 WebVitalsPlugin has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

    export function WebVitalsPlugin(pluginOptions: WebVitalsPluginOptions = defaultPluginOptions): BrowserPlugin {
      const webVitalsObject: Record<string, unknown> = {};
      const options = { ...defaultPluginOptions, ...pluginOptions };
      let trackerId: string;
      let webVitalsScript: HTMLScriptElement | undefined;
    Severity: Minor
    Found in plugins/browser-plugin-web-vitals/src/index.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 _resolvePackageVersion has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

    function _resolvePackageVersion(logger, rushCommonFolder, { name, version }) {
        if (!version) {
            version = '*'; // If no version is specified, use the latest version
        }
        if (version.match(/^[a-zA-Z0-9\-\+\.]+$/)) {
    Severity: Minor
    Found in common/scripts/install-run.js - 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 activateBrowserPlugin has 31 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        activateBrowserPlugin: (tracker) => {
          trackerId = tracker.id;
          _trackers[trackerId] = tracker;
    
          function sendWebVitals() {
    Severity: Minor
    Found in plugins/browser-plugin-web-vitals/src/index.ts - About 1 hr to fix

      Function base64encode has 29 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      export function base64encode(data: string): string {
        // discuss at: http://phpjs.org/functions/base64_encode/
        // original by: Tyler Akins (http://rumkin.com)
        // improved by: Bayron Guevara
        // improved by: Thunder.m
      Severity: Minor
      Found in libraries/tracker-core/src/base64.ts - About 1 hr to fix

        Function _copyAndTrimNpmrcFile has 29 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        function _copyAndTrimNpmrcFile(logger, sourceNpmrcPath, targetNpmrcPath) {
            logger.info(`Transforming ${sourceNpmrcPath}`); // Verbose
            logger.info(`  --> "${targetNpmrcPath}"`);
            let npmrcFileLines = fs.readFileSync(sourceNpmrcPath).toString().split('\n');
            npmrcFileLines = npmrcFileLines.map((line) => (line || '').trim());
        Severity: Minor
        Found in common/scripts/install-run.js - About 1 hr to fix

          Function matchSchemaAgainstRuleSet has 28 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          export function matchSchemaAgainstRuleSet(ruleSet: RuleSet, schema: string): boolean {
            let rejectCount = 0;
            let acceptCount = 0;
            const acceptRules = ruleSet['accept'];
            if (Array.isArray(acceptRules)) {
          Severity: Minor
          Found in libraries/tracker-core/src/contexts.ts - About 1 hr to fix

            Function getHTMLMediaElementEntities has 28 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            function getHTMLMediaElementEntities(el: HTMLAudioElement | HTMLVideoElement, conf: TrackingOptions): MediaEntities {
              // In cases where the media does not have explicit id, we use the container id passed from the configuration.
              const htmlId = el.id || conf.id;
              const data: MediaElement = {
                htmlId,
            Severity: Minor
            Found in plugins/browser-plugin-media-tracking/src/buildMediaEvent.ts - About 1 hr to fix

              Function enableGeolocationContext has 28 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              export function enableGeolocationContext(trackers: Array<string> = Object.keys(_trackers)) {
                const navigatorAlias = navigator;
              
                trackers.forEach((t) => {
                  //Mark as enabled
              Severity: Minor
              Found in plugins/browser-plugin-geolocation/src/index.ts - About 1 hr to fix

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

                export function DebuggerPlugin(logLevel: LOG_LEVEL = LOG_LEVEL.debug): BrowserPlugin {
                  let LOG: Logger;
                  let tracker: BrowserTracker;
                  let eventColour: string;
                
                
                Severity: Minor
                Found in plugins/browser-plugin-debugger/src/index.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 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 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 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 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 getInnerFormElements has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                  function getInnerFormElements(trackingMarker: string, elt: HTMLFormElement) {
                    var innerElements: Array<ElementDataWrapper> = [];
                    Array.prototype.slice.call(innerElementTags).forEach((tagname: 'textarea' | 'input' | 'select') => {
                      let trackedChildren = Array.prototype.slice.call(elt.getElementsByTagName(tagname)).filter(function (child) {
                        return child.hasOwnProperty(trackingMarker);
                  Severity: Minor
                  Found in plugins/browser-plugin-form-tracking/src/helpers.ts - About 1 hr to fix

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

                      function getOptimizelyVisitorContexts() {
                        var visitor = getOptimizelyData('visitor');
                        if (visitor) {
                          var context: Visitor = {};
                          context.browser = visitor.browser;
                    Severity: Minor
                    Found in plugins/browser-plugin-optimizely/src/index.ts - About 1 hr to fix
                      Severity
                      Category
                      Status
                      Source
                      Language