snowplow/snowplow-javascript-tracker

View on GitHub

Showing 353 of 353 total issues

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

export const DefaultEvents: EventGroup = [
  SnowplowEvent.READY,
  MediaEvent.PAUSE,
  MediaEvent.PLAY,
  MediaEvent.SEEKED,
Severity: Major
Found in plugins/browser-plugin-media-tracking/src/eventGroups.ts and 1 other location - About 1 hr to fix
plugins/browser-plugin-youtube-tracking/src/eventGroups.ts on lines 12..22

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 62.

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

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

export const DefaultEvents: EventGroup = [
  YTEvent.READY,
  YTState.PAUSED,
  YTState.PLAYING,
  YTState.ENDED,
Severity: Major
Found in plugins/browser-plugin-youtube-tracking/src/eventGroups.ts and 1 other location - About 1 hr to fix
plugins/browser-plugin-media-tracking/src/eventGroups.ts on lines 14..24

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 62.

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

Consider simplifying this complex logical expression.
Open

  if (
    plugins.optimizely &&
    (optimizelySummary ||
      optimizelyExperiments ||
      optimizelyStates ||
Severity: Critical
Found in trackers/javascript-tracker/src/features.ts - About 1 hr to fix

    Function _run has 33 lines of code (exceeds 25 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

      Function processClick has 33 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      function processClick(tracker: BrowserTracker, sourceElement: Element, context?: DynamicContext | null) {
        let parentElement, tag, elementId, elementClasses, elementTarget, elementContent;
      
        while (
          (parentElement = sourceElement.parentElement) !== null &&
      Severity: Minor
      Found in plugins/browser-plugin-link-click-tracking/src/index.ts - About 1 hr to fix

        Function track has 33 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            function track(
              pb: PayloadBuilder,
              context?: Array<SelfDescribingJson> | null,
              timestamp?: Timestamp | null
            ): Payload {
        Severity: Minor
        Found in libraries/tracker-core/src/core.ts - About 1 hr to fix

          Function enableMediaTracking has 32 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          export function enableMediaTracking(args: { id: string; options?: MediaTrackingOptions }) {
            const conf: TrackingOptions = trackingOptionsParser(args.id, args.options);
          
            // Some events have additional effects/need to perform checks before running mediaPlayerEvent
            const eventsWithOtherFunctions: Record<string, Function> = {
          Severity: Minor
          Found in plugins/browser-plugin-media-tracking/src/index.ts - About 1 hr to fix

            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 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 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 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 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 _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 enableMediaTracking has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
              Open

              export function enableMediaTracking(args: { id: string; options?: MediaTrackingOptions }) {
                const conf: TrackingOptions = trackingOptionsParser(args.id, args.options);
              
                // Some events have additional effects/need to perform checks before running mediaPlayerEvent
                const eventsWithOtherFunctions: Record<string, Function> = {
              Severity: Minor
              Found in plugins/browser-plugin-media-tracking/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 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

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

                export function setOptOutCookie(name?: string | null, trackers?: Array<string>) {
                  dispatchToTrackers(trackers, (t) => {
                    t.setOptOutCookie(name);
                  });
                }
                Severity: Major
                Found in trackers/browser-tracker/src/api.ts and 1 other location - About 1 hr to fix
                trackers/browser-tracker/src/api.ts on lines 284..288

                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 59.

                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

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

                export function setUserId(userId?: string | null, trackers?: Array<string>) {
                  dispatchToTrackers(trackers, (t) => {
                    t.setUserId(userId);
                  });
                }
                Severity: Major
                Found in trackers/browser-tracker/src/api.ts and 1 other location - About 1 hr to fix
                trackers/browser-tracker/src/api.ts on lines 272..276

                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 59.

                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 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

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

                    export function clearUserData(configuration?: ClearUserDataConfiguration, trackers?: Array<string>) {
                      dispatchToTrackers(trackers, (t) => {
                        t.clearUserData(configuration);
                      });
                    }
                    Severity: Major
                    Found in trackers/browser-tracker/src/api.ts and 4 other locations - About 1 hr to fix
                    trackers/browser-tracker/src/api.ts on lines 212..216
                    trackers/browser-tracker/src/api.ts on lines 360..364
                    trackers/browser-tracker/src/api.ts on lines 467..474
                    trackers/browser-tracker/src/api.ts on lines 482..489

                    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 58.

                    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

                    Severity
                    Category
                    Status
                    Source
                    Language